From: liang_mike Date: Fri, 22 Aug 2008 02:38:33 +0000 (+0000) Subject: Allows a cthreads application to set the collection ID for a client ID X-Git-Tag: rc_6_tinyos_2_1_1~643 X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=tinyos-2.x.git;a=commitdiff_plain;h=c5b798cd21ab503fcbad0b4d145301589975a0d2 Allows a cthreads application to set the collection ID for a client ID --- diff --git a/apps/tosthreads/capps/TestCollection/MultihopOscilloscope.h b/apps/tosthreads/capps/TestCollection/MultihopOscilloscope.h index 437bd510..41d8885c 100644 --- a/apps/tosthreads/capps/TestCollection/MultihopOscilloscope.h +++ b/apps/tosthreads/capps/TestCollection/MultihopOscilloscope.h @@ -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 { diff --git a/apps/tosthreads/capps/TestCollection/TestCollection.c b/apps/tosthreads/capps/TestCollection/TestCollection.c index 21aca5a0..aaf811db 100644 --- a/apps/tosthreads/capps/TestCollection/TestCollection.c +++ b/apps/tosthreads/capps/TestCollection/TestCollection.c @@ -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 index 00000000..7e13b6ac --- /dev/null +++ b/tos/lib/tosthreads/lib/net/CCollectionId.nc @@ -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 + */ + +interface CCollectionId { + command collection_id_t fetch(uint8_t clientid); + command error_t set(uint8_t clientid, collection_id_t collectionid); +} diff --git a/tos/lib/tosthreads/lib/net/CCollectionP.nc b/tos/lib/tosthreads/lib/net/CCollectionP.nc index 52878a51..8b5fbdf2 100644 --- a/tos/lib/tosthreads/lib/net/CCollectionP.nc +++ b/tos/lib/tosthreads/lib/net/CCollectionP.nc @@ -31,6 +31,7 @@ /** * @author Kevin Klues + * @author Chieh-Jan Mike Liang */ 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); } diff --git a/tos/lib/tosthreads/lib/net/ctp/CCollectionC.nc b/tos/lib/tosthreads/lib/net/ctp/CCollectionC.nc index 6e17b7a0..5bee546c 100644 --- a/tos/lib/tosthreads/lib/net/ctp/CCollectionC.nc +++ b/tos/lib/tosthreads/lib/net/ctp/CCollectionC.nc @@ -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 index 00000000..93cabcab --- /dev/null +++ b/tos/lib/tosthreads/lib/net/ctp/CCollectionIdP.nc @@ -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 + */ + +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; + } +} diff --git a/tos/lib/tosthreads/lib/net/ctp/ccollection.h b/tos/lib/tosthreads/lib/net/ctp/ccollection.h index 4c8f9d24..6ef74d00 100644 --- a/tos/lib/tosthreads/lib/net/ctp/ccollection.h +++ b/tos/lib/tosthreads/lib/net/ctp/ccollection.h @@ -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 diff --git a/tos/lib/tosthreads/lib/net/lqi/CCollectionC.nc b/tos/lib/tosthreads/lib/net/lqi/CCollectionC.nc index 1b1dca26..527d7a62 100644 --- a/tos/lib/tosthreads/lib/net/lqi/CCollectionC.nc +++ b/tos/lib/tosthreads/lib/net/lqi/CCollectionC.nc @@ -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 index 00000000..bc8a9e76 --- /dev/null +++ b/tos/lib/tosthreads/lib/net/lqi/CCollectionIdP.nc @@ -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 + */ + +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; + } +} diff --git a/tos/lib/tosthreads/lib/net/lqi/ccollection.h b/tos/lib/tosthreads/lib/net/lqi/ccollection.h index c18e2636..e0937ec5 100644 --- a/tos/lib/tosthreads/lib/net/lqi/ccollection.h +++ b/tos/lib/tosthreads/lib/net/lqi/ccollection.h @@ -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 diff --git a/tos/lib/tosthreads/lib/net/tosthread_collection.h b/tos/lib/tosthreads/lib/net/tosthread_collection.h index 9941ac07..b3967c4e 100644 --- a/tos/lib/tosthreads/lib/net/tosthread_collection.h +++ b/tos/lib/tosthreads/lib/net/tosthread_collection.h @@ -31,6 +31,7 @@ /** * @author Kevin Klues + * @author Chieh-Jan Mike Liang */ #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);