]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - apps/MultihopOscilloscope/MultihopOscilloscopeC.nc
Merge TinyOS 2.1.1 into master.
[tinyos-2.x.git] / apps / MultihopOscilloscope / MultihopOscilloscopeC.nc
index fff54d7ca7bc5f9988dd17022332573ed6845f9d..5179b3500d46aa8a37c9c3ba2a40a0e1a22d8687 100644 (file)
@@ -19,7 +19,7 @@
 #include "Timer.h"
 #include "MultihopOscilloscope.h"
 
-module MultihopOscilloscopeC {
+module MultihopOscilloscopeC @safe(){
   uses {
     // Interfaces for initialization:
     interface Boot;
@@ -128,8 +128,8 @@ implementation {
     oscilloscope_t* in = (oscilloscope_t*)payload;
     oscilloscope_t* out;
     if (uartbusy == FALSE) {
-      out = (oscilloscope_t*)call SerialSend.getPayload(&uartbuf);
-      if (len != sizeof(oscilloscope_t)) {
+      out = (oscilloscope_t*)call SerialSend.getPayload(&uartbuf, sizeof(oscilloscope_t));
+      if (len != sizeof(oscilloscope_t) || out == NULL) {
        return msg;
       }
       else {
@@ -147,8 +147,11 @@ implementation {
         return msg;
       }
 
-      //Prepare message to be sent over the uart
-      out = (oscilloscope_t*)call SerialSend.getPayload(newmsg);
+      //Serial port busy, so enqueue.
+      out = (oscilloscope_t*)call SerialSend.getPayload(newmsg, sizeof(oscilloscope_t));
+      if (out == NULL) {
+       return msg;
+      }
       memcpy(out, in, sizeof(oscilloscope_t));
 
       if (call UARTQueue.enqueue(newmsg) != SUCCESS) {
@@ -224,7 +227,11 @@ implementation {
   event void Timer.fired() {
     if (reading == NREADINGS) {
       if (!sendbusy) {
-       oscilloscope_t *o = (oscilloscope_t *)call Send.getPayload(&sendbuf);
+       oscilloscope_t *o = (oscilloscope_t *)call Send.getPayload(&sendbuf, sizeof(oscilloscope_t));
+       if (o == NULL) {
+         fatal_problem();
+         return;
+       }
        memcpy(o, &local, sizeof(local));
        if (call Send.send(&sendbuf, sizeof(local)) == SUCCESS)
          sendbusy = TRUE;