]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - apps/tosthreads/capps/SenseAndSend/SenseAndSend.c
Merge TinyOS 2.1.1 into master.
[tinyos-2.x.git] / apps / tosthreads / capps / SenseAndSend / SenseAndSend.c
index 9546781da8ed0df958d21630ad3b5752bf18abb7..c49a761e62955ca4c0dbbd62ee6d18c2531639eb 100644 (file)
  */
 
 /**
+ * SenseAndSend is a threaded implementation of an application that takes various
+ * sensor readings in parallel (by dedicating one thread to each reading), and
+ * assembling them into a packet to be sent out over the radio.  It 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 sent out over the radio
+ * interface in an infinite loop.  Upon successful transmission, LED0 is toggled,
+ * and the process starts over again.
+ * 
+ * A successful test will result in LED0 toggling periodically 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). 
+ * 
+ * Additionally, a base station application should be run to verify the reception
+ * of packets sent from a SenseAndSend mote, with reasonable looking sensor data.
+ *
  * @author Kevin Klues <klueska@cs.stanford.edu>
  */
 
@@ -78,8 +95,7 @@ void tosthread_main(void* arg) {
   barrier_reset(&send_barrier, NUM_SENSORS+1);
   barrier_reset(&sense_barrier, NUM_SENSORS+1);
   sensor_data = radioGetPayload(&send_msg, sizeof(sensor_data_t));
-  //sensor_data->seq_no = 0;
-  __nesc_hton_uint32((unsigned char *)&sensor_data->seq_no, (unsigned long )0);
+  sensor_data->seq_no = 0;
 
   amRadioStart();
   tosthread_create(&humidity, humidity_thread, NULL, 200);
@@ -94,8 +110,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);
@@ -115,17 +130,12 @@ void photo_active_thread(void* arg) {
   read_sensor(hamamatsuS1087_par_read, &(sensor_data->par));
 }
 void send_thread(void* arg) {
-  //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);
     
     if(amRadioSend(AM_BROADCAST_ADDR, &send_msg, sizeof(sensor_data_t), AM_SENSOR_DATA_MSG) == SUCCESS) {
-      //sensor_data->seq_no++;
-      (__nesc_temp42 = (unsigned char *)&sensor_data->seq_no, __nesc_hton_uint32(__nesc_temp42, (__nesc_temp43 = __nesc_ntoh_uint32(__nesc_temp42)) + 1), __nesc_temp43);
+      sensor_data->seq_no++;
       led0Toggle();
     }
     //tosthread_sleep(SAMPLING_PERIOD);