*/
/**
+ * TestCollection is a reimplementation of the Multihop Oscilloscope application
+ * using TOSThreads. It periodically samples a universal software-based SineSensor
+ * and broadcasts a message every few readings. These readings can be displayed by
+ * the Java "Oscilloscope" application found in the the TestCollection/java
+ * subdirectory. The sampling rate starts at 4Hz, but can be changed from the Java
+ * application.
+ *
+ * At least two motes must be used by this application, with one of them installed
+ * as a base station. Base station motes can be created by installing them with
+ * NODE_ID % 500 == 0.
+ * i.e. make <platform> threads install.0
+ * make <platform> threads install.500
+ * make <platform> threads install.1000
+ *
+ * All other nodes can be installed with arbitrary NODE_IDs.
+ * make <platform> threads install.123
+ *
+ * Successful running of this application is verified by all NON-base station motes
+ * periodically flashing LED1 upon sending a message, and the base station mote,
+ * flashing LED2 upon successful reception of a message. Additionally, correct
+ * operation should be verified by running the java tool described in the following
+ * section.
+ *
* @author Kevin Klues <klueska@cs.stanford.edu>
*/
#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 = o;
- o = (oscilloscope_t *) collectionGetPayload(&sendbuf, sizeof(oscilloscope_t));
+ oscilloscope_t *o = (oscilloscope_t *) collectionGetPayload(&sendbuf, sizeof(oscilloscope_t));
if (o == NULL) {
fatal_problem();
return;
}
memcpy(o, &local, sizeof(local));
if (collectionSend(&sendbuf, sizeof(local), AM_OSCILLOSCOPE) == SUCCESS) {
+ local.count++;
report_sent();
} else {
report_problem();
reading = 0;
}
-
+
if (sinesensor_read(&var) == SUCCESS) {
local.readings[reading++] = var;
}
-
+
tosthread_sleep(local.interval);
}
}