]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Allows a cthreads application to set the collection ID for a client ID
authorliang_mike <liang_mike>
Fri, 22 Aug 2008 02:38:33 +0000 (02:38 +0000)
committerliang_mike <liang_mike>
Fri, 22 Aug 2008 02:38:33 +0000 (02:38 +0000)
apps/tosthreads/capps/TestCollection/MultihopOscilloscope.h
apps/tosthreads/capps/TestCollection/TestCollection.c
tos/lib/tosthreads/lib/net/CCollectionId.nc [new file with mode: 0644]
tos/lib/tosthreads/lib/net/CCollectionP.nc
tos/lib/tosthreads/lib/net/ctp/CCollectionC.nc
tos/lib/tosthreads/lib/net/ctp/CCollectionIdP.nc [new file with mode: 0644]
tos/lib/tosthreads/lib/net/ctp/ccollection.h
tos/lib/tosthreads/lib/net/lqi/CCollectionC.nc
tos/lib/tosthreads/lib/net/lqi/CCollectionIdP.nc [new file with mode: 0644]
tos/lib/tosthreads/lib/net/lqi/ccollection.h
tos/lib/tosthreads/lib/net/tosthread_collection.h

index 437bd510e7ca4edaf1b79e51e042dab8c6ee60aa..41d8885cca2ed3b82718a25c1ffcc1508f909c12 100644 (file)
@@ -24,7 +24,7 @@ enum {
   NREADINGS = 5,
   /* Default sampling period. */
   DEFAULT_INTERVAL = 1024,
-  AM_OSCILLOSCOPE = NEW_COLLECTION_ID(),
+  AM_OSCILLOSCOPE = NEW_COLLECTION_CLIENT_ID(),
 };
 
 typedef nx_struct oscilloscope {
index 21aca5a0ff6426540ae2a9afaf3f04cb8da9d3fb..aaf811db233e0e9ead4a0f785261cd08135f8f98 100644 (file)
@@ -41,6 +41,8 @@
 #include "tosthread_sinesensor.h"
 #include "MultihopOscilloscope.h"
 
+#define MY_COLLECTION_ID 0x02
+
 void fatal_problem();
 void report_problem();
 void report_sent();
@@ -58,12 +60,14 @@ void tosthread_main(void* arg) {
   
   while ( amRadioStart() != SUCCESS );
   while ( collectionRoutingStart() != SUCCESS );
+  
+  collectionSetCollectionId(AM_OSCILLOSCOPE, MY_COLLECTION_ID);
+  
   if (local.id % 500 == 0) {
-    while ( amSerialStart() != SUCCESS);
+    while ( amSerialStart() != SUCCESS );
     collectionSetRoot();
     for (;;) {
-      if ( collectionReceive(&recvbuf, 0, AM_OSCILLOSCOPE) == SUCCESS) {
+      if (collectionReceive(&recvbuf, 0, MY_COLLECTION_ID) == SUCCESS) {
         oscilloscope_t *recv_o = (oscilloscope_t *) collectionGetPayload(&recvbuf, sizeof(oscilloscope_t));
         oscilloscope_t *send_o = (oscilloscope_t *) serialGetPayload(&sendbuf, sizeof(oscilloscope_t));
         memcpy(send_o, recv_o, sizeof(oscilloscope_t));
@@ -73,7 +77,7 @@ void tosthread_main(void* arg) {
     }
   } else {
     uint16_t var;
-      
+
     for (;;) {
       if (reading == NREADINGS) {
         oscilloscope_t *o = (oscilloscope_t *) collectionGetPayload(&sendbuf, sizeof(oscilloscope_t));
@@ -91,11 +95,11 @@ void tosthread_main(void* arg) {
         
         reading = 0;
       }
-          
+        
       if (sinesensor_read(&var) == SUCCESS) {
         local.readings[reading++] = var;
       }
-        
+      
       tosthread_sleep(local.interval);
     }
   }
diff --git a/tos/lib/tosthreads/lib/net/CCollectionId.nc b/tos/lib/tosthreads/lib/net/CCollectionId.nc
new file mode 100644 (file)
index 0000000..7e13b6a
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written
+ * agreement is hereby granted, provided that the above copyright
+ * notice, the (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/*
+ * @author Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ */
+
+interface CCollectionId {
+  command collection_id_t fetch(uint8_t clientid);
+  command error_t set(uint8_t clientid, collection_id_t collectionid);
+}
index 52878a515abb536aeff5c782362002c500934336..8b5fbdf2ac3c47cddcbfd112d42f25fcd0747db3 100644 (file)
@@ -31,6 +31,7 @@
 
 /**
  * @author Kevin Klues <klueska@cs.stanford.edu>
+ * @author Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
  */
 
 module CCollectionP {
@@ -38,10 +39,11 @@ module CCollectionP {
     interface BlockingStdControl as RoutingControl;
     interface BlockingReceive[collection_id_t id];
     interface BlockingReceive as BlockingSnoop[collection_id_t id];
-    interface BlockingSend[am_id_t id];
+    interface BlockingSend[uint8_t id];
     interface Packet;
     interface CollectionPacket;
     interface RootControl;
+    interface CCollectionId;
   }
   provides {
     interface CollectionId[uint8_t client];
@@ -49,7 +51,11 @@ module CCollectionP {
 }
 implementation {
   command collection_id_t CollectionId.fetch[uint8_t id]() {
-    return id;
+    return call CCollectionId.fetch(id);
+  }
+
+  error_t collectionSetCollectionId(uint8_t clientid, collection_id_t collectionid) @C() @spontaneous() {
+    return call CCollectionId.set(clientid, collectionid);
   }
   
   error_t collectionRoutingStart() @C() @spontaneous() {
@@ -65,7 +71,7 @@ implementation {
   error_t collectionSnoop(message_t* m, uint32_t timeout, collection_id_t id) @C() @spontaneous() {
     return call BlockingSnoop.receive[id](m, timeout);
   }
-  error_t collectionSend(message_t* msg, uint8_t len, collection_id_t id) @C() @spontaneous() {
+  error_t collectionSend(message_t* msg, uint8_t len, uint8_t id) @C() @spontaneous() {
     return call BlockingSend.send[id](msg, len);
   }
  
index 6e17b7a0d2334e80c9b12c1492f061d869c733f0..5bee546cca05782d29a429fac32f2acfa8d95370 100644 (file)
@@ -44,11 +44,13 @@ implementation {
   components BlockingCollectionSnooperP;
   components BlockingCollectionSenderP;
   components BlockingCollectionControlC;
+  components CCollectionIdP;
   
   CCP.BlockingReceive -> BlockingCollectionReceiverP;
   CCP.BlockingSnoop -> BlockingCollectionSnooperP;
   CCP.BlockingSend -> BlockingCollectionSenderP;
   CCP.RoutingControl -> BlockingCollectionControlC;
+  CCP.CCollectionId -> CCollectionIdP;
   
   components CollectionC;
   CCP.Packet -> CollectionC;
diff --git a/tos/lib/tosthreads/lib/net/ctp/CCollectionIdP.nc b/tos/lib/tosthreads/lib/net/ctp/CCollectionIdP.nc
new file mode 100644 (file)
index 0000000..93cabca
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written
+ * agreement is hereby granted, provided that the above copyright
+ * notice, the (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/*
+ * @author Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ */
+
+module CCollectionIdP
+{
+  provides {
+    interface CCollectionId;
+  }
+}
+
+implementation {
+  collection_id_t clientCollectionIds[uniqueCount(UQ_CTP_CLIENT)];
+  
+  command collection_id_t CCollectionId.fetch(uint8_t clientid)
+  {
+    return clientCollectionIds[clientid];
+  }
+  
+  command error_t CCollectionId.set(uint8_t clientid, collection_id_t collectionid)
+  {
+    if (clientid < uniqueCount(UQ_CTP_CLIENT)) {
+      clientCollectionIds[clientid] = collectionid;
+      
+      return SUCCESS;
+    }
+    
+    return FAIL;
+  }
+}
index 4c8f9d2483b3107e1807c9ebe2c599222fa840aa..6ef74d0011c7916bcfb8de022912c1ba7183d108 100644 (file)
@@ -41,6 +41,6 @@
 #include "Collection.h"
 #include "Ctp.h"
 
-#define  NEW_COLLECTION_ID() ((collection_id_t)unique(UQ_CTP_CLIENT))
+#define  NEW_COLLECTION_CLIENT_ID() ((uint8_t)unique(UQ_CTP_CLIENT))
 
 #endif //CCOLLECTION_H
index 1b1dca26430270aaf4672c22c49ea79f993b5e32..527d7a629e6c9e37d4f4d76fd39e0d81679d5f94 100644 (file)
@@ -44,11 +44,13 @@ implementation {
   components BlockingCollectionSnooperP;
   components BlockingCollectionSenderP;
   components BlockingCollectionControlC;
+  components CCollectionIdP;
   
   CCP.BlockingReceive -> BlockingCollectionReceiverP;
   CCP.BlockingSnoop -> BlockingCollectionSnooperP;
   CCP.BlockingSend -> BlockingCollectionSenderP;
   CCP.RoutingControl -> BlockingCollectionControlC;
+  CCP.CCollectionId -> CCollectionIdP;
   
   components CollectionC;
   CCP.Packet -> CollectionC;
diff --git a/tos/lib/tosthreads/lib/net/lqi/CCollectionIdP.nc b/tos/lib/tosthreads/lib/net/lqi/CCollectionIdP.nc
new file mode 100644 (file)
index 0000000..bc8a9e7
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written
+ * agreement is hereby granted, provided that the above copyright
+ * notice, the (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/*
+ * @author Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ */
+
+module CCollectionIdP
+{
+  provides {
+    interface CCollectionId;
+  }
+}
+
+implementation {
+  collection_id_t clientCollectionIds[uniqueCount(UQ_LQI_CLIENT)];
+  
+  command collection_id_t CCollectionId.fetch(uint8_t clientid)
+  {
+    return clientCollectionIds[clientid];
+  }
+  
+  command error_t CCollectionId.set(uint8_t clientid, collection_id_t collectionid)
+  {
+    if (clientid < uniqueCount(UQ_LQI_CLIENT)) {
+      clientCollectionIds[clientid] = collectionid;
+      
+      return SUCCESS;
+    }
+    
+    return FAIL;
+  }
+}
index c18e2636c27155c2d2603cb2251de0c13cf30ca6..e0937ec5a96facfc84b09df5ef63485e6476e760 100644 (file)
@@ -41,6 +41,6 @@
 #include "Collection.h"
 #include "MultiHopLqi.h"
 
-#define  NEW_COLLECTION_ID() ((collection_id_t)unique(UQ_LQI_CLIENT))
+#define  NEW_COLLECTION_CLIENT_ID() ((uint8_t)unique(UQ_LQI_CLIENT))
 
 #endif //CCOLLECTION_H
index 9941ac078e1ec8253aaeebb44f76c48f77918124..b3967c4e02cc99e9a042c408aaab36a5fe67f909 100644 (file)
@@ -31,6 +31,7 @@
 
 /**
  * @author Kevin Klues <klueska@cs.stanford.edu>
+ * @author Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
  */
  
 #ifndef TOSTHREAD_COLLECTION_H
@@ -41,6 +42,8 @@
 extern error_t collectionRoutingStart();
 extern error_t collectionRoutingStop();
 
+extern error_t collectionSetCollectionId(uint8_t clientid, collection_id_t collectionid);
+
 extern error_t collectionReceive(message_t* m, uint32_t timeout, collection_id_t id);
 extern error_t collectionSnoop(message_t* m, uint32_t timeout, collection_id_t id);
 extern error_t collectionSend(message_t* msg, uint8_t len, collection_id_t id);