NREADINGS = 5,
/* Default sampling period. */
DEFAULT_INTERVAL = 1024,
- AM_OSCILLOSCOPE = NEW_COLLECTION_ID(),
+ AM_OSCILLOSCOPE = NEW_COLLECTION_CLIENT_ID(),
};
typedef nx_struct oscilloscope {
#include "tosthread_sinesensor.h"
#include "MultihopOscilloscope.h"
+#define MY_COLLECTION_ID 0x02
+
void fatal_problem();
void report_problem();
void report_sent();
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));
}
} else {
uint16_t var;
-
+
for (;;) {
if (reading == NREADINGS) {
oscilloscope_t *o = (oscilloscope_t *) collectionGetPayload(&sendbuf, sizeof(oscilloscope_t));
reading = 0;
}
-
+
if (sinesensor_read(&var) == SUCCESS) {
local.readings[reading++] = var;
}
-
+
tosthread_sleep(local.interval);
}
}
--- /dev/null
+/*
+ * 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);
+}
/**
* @author Kevin Klues <klueska@cs.stanford.edu>
+ * @author Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
*/
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];
}
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() {
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);
}
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;
--- /dev/null
+/*
+ * 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;
+ }
+}
#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
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;
--- /dev/null
+/*
+ * 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;
+ }
+}
#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
/**
* @author Kevin Klues <klueska@cs.stanford.edu>
+ * @author Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
*/
#ifndef TOSTHREAD_COLLECTION_H
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);