]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - apps/tosthreads/capps/SenseStoreAndForward/SenseStoreAndForward.c
Merge TinyOS 2.1.1 into master.
[tinyos-2.x.git] / apps / tosthreads / capps / SenseStoreAndForward / SenseStoreAndForward.c
index 2aa52d174335810260e3a1319ee4faa09bb670c8..93a75a4043c90ed64bbbe8d51dc465705a8fb9b5 100644 (file)
  */
 
 /**
+ * SenseStoreAndForward is a threaded implementation of an application that takes
+ * various sensor readings in parallel (by dedicating one thread to each reading),
+ * logs them to flash, and then sends them out over the radio at some later time. 
+ * In the current implementation, sensor readings are taken as quickly as possible,
+ * and records containing a set of readings from each iteration are batched out
+ * over the radio every 10000ms.  This application is written specifically for use
+ * with the tmote onboard sensor package, and will not compile for any other
+ * platforms.
+ *
+ * Readings are taken from each of the 4 oboard sensors and logged to flash as one
+ * record in an infinite loop. Records are then read out of flash and and sent out
+ * over the radio interface in separate infinite loop. Before the application
+ * starts running, the entire contents of the flash drive are erased.
+ * 
+ * A successful test will result in LED0 remaining solid for approximately 6s while
+ * the flash is being erased.  After that LED0 will toggle with each successful set
+ * of sensor readings logged to flash, at a rate of approximately 220ms (the time
+ * it takes to take a humidity + temperature sensor reading since they share the
+ * same hardware and cannot be taken in parallel).  Also, LED1 will begin toggling
+ * in rapid succession once every 10000ms as records are successfully read from
+ * flash and sent out over the radio.  Once all of the records currently recorded
+ * to flash since the last batch of sends have been sent out, LED2 Toggles to
+ * indicate completion.  This process continues in an infinite loop forever.
+ * 
+ * Additionally, a base station application should be run to verify the reception
+ * of packets sent from a SenseStoreAndForward mote, with reasonable looking sensor 
+ * data.
+ *
  * @author Kevin Klues <klueska@cs.stanford.edu>
  */
 
@@ -84,8 +112,7 @@ void tosthread_main(void* arg) {
   barrier_reset(&send_barrier, NUM_SENSORS+1);
   barrier_reset(&sense_barrier, NUM_SENSORS+1);
   sending_sensor_data = radioGetPayload(&send_msg, sizeof(sensor_data_t));
-  //storing_sensor_data->seq_no = 0;
-  __nesc_hton_uint32((unsigned char *)&storing_sensor_data.seq_no, (unsigned long )0);
+  storing_sensor_data.seq_no = 0;
 
   amRadioStart();
   led0Toggle();
@@ -104,8 +131,7 @@ void read_sensor(error_t (*read)(uint16_t*), nx_uint16_t* nx_val) {
   for(;;) {
     (*read)(&val);
     mutex_lock(&data_mutex);
-    //  *nx_val = val;
-    __nesc_hton_uint16((unsigned char *)&*nx_val, val);
+    *nx_val = val;
     mutex_unlock(&data_mutex);
     barrier_block(&send_barrier);
     barrier_block(&sense_barrier);
@@ -128,10 +154,6 @@ void store_thread(void* arg) {
   storage_len_t sensor_data_len;
   bool sensor_records_lost;
   
-  //Only needed for nesC magic.... I hate this hack.....
-  unsigned long __nesc_temp43;
-  unsigned char *__nesc_temp42;
-  
   for(;;) {
     barrier_block(&send_barrier);
     barrier_reset(&send_barrier, NUM_SENSORS + 1);
@@ -141,8 +163,7 @@ void store_thread(void* arg) {
       while( volumeLogAppend(VOLUME_SENSORLOG, &storing_sensor_data, &sensor_data_len, &sensor_records_lost) != SUCCESS );
     mutex_unlock(&log_mutex);
     
-    //storing_sensor_data.seq_no++
-    (__nesc_temp42 = (unsigned char *)&storing_sensor_data.seq_no, __nesc_hton_uint32(__nesc_temp42, (__nesc_temp43 = __nesc_ntoh_uint32(__nesc_temp42)) + 1), __nesc_temp43);
+    storing_sensor_data.seq_no++;
     led0Toggle();
 
     //tosthread_sleep(SAMPLING_PERIOD);