Home automation using Xbee radios

Dependencies:   EthernetNetIf HTTPServer RPCInterface mbed C12832_lcd

Link to Notebook Page

Revision:
10:de0be690b3c0
Parent:
9:4b1e3531dd00
diff -r 4b1e3531dd00 -r de0be690b3c0 XbeeCommLib.cpp
--- a/XbeeCommLib.cpp	Wed Dec 04 02:35:47 2013 +0000
+++ b/XbeeCommLib.cpp	Fri Dec 06 07:05:49 2013 +0000
@@ -17,9 +17,10 @@
     int addrSum = 0;
     unsigned char data = 0;
 
-    //led3 = 1;
+    led3 = 1;
     
-    printf(" - Sending...");
+    if(DEBUG)
+        printf(" - Sending...");
     
     dataToSend[counter++] = 0x7E;   // Start of packet
     dataToSend[counter++] = 0x0;    // Length MSB (always 0)
@@ -63,9 +64,10 @@
         //printf("%x ", dataToSend[i]);
     }
     
-    printf("Sent\n");
+    if(DEBUG)
+        printf("Sent\n");
     
-    //led3 = 0;
+    led3 = 0;
 }
 
 
@@ -91,6 +93,7 @@
     
     if(dataCounter > 0){                // Do we have any input data at all?
         if(data[0] == 0x7E){            // Valid start byte?
+            led4 = 1;
             if(dataCounter > 3){
                 if(data[3] !=  0x92)
                     clear = true;
@@ -137,8 +140,8 @@
                             printf("\n\nReceived packet from %x %x\n", addrHigh, addrLow);
                         
                         if(analogInBytes){
-                            if(DEBUG)
-                                printf("Analog Data Present\n");
+                            //if(DEBUG)
+//                                printf("Analog Data Present\n");
                             //Figure out where the analog bytes start
                             if(digitalInBytes)
                                 startingPacket = 21;
@@ -164,19 +167,20 @@
                                 analogData = getAnalogVoltage(startingPacket, i, totalPacketBytes);
                                 if(DEBUG)
                                     printf("Analog Data Input Index %d = %f\n", analogPortNumbers[i], analogData);
-                                analogInputHandle(root, addrHigh, addrLow, analogPortNumbers[i], analogData);
+                                analogInputHandle(addrHigh, addrLow, analogPortNumbers[i], analogData);
                             }
                         }
                         
                         if(digitalInBytes){
-                            if(DEBUG)
-                                printf("Digital Data Present\n");
+                            //if(DEBUG)
+//                                printf("Digital Data Present\n");
 //                            unsigned short digitalMask = (data[16] << 8) | data[17];
                             unsigned short digitalData = (data[19] << 8) | data[20];
                             
-                            digitalInputHandle(root, addrHigh, addrLow, digitalData);
-                            //printf("Digital Mask = %x\nDigital Data = %x\n", digitalMask, digitalData);
-
+                            if(digitalData < 1024){
+                                digitalInputHandle(addrHigh, addrLow, digitalData);
+                                //printf("Digital Mask = %x\nDigital Data = %x\n", digitalMask, digitalData);
+                            }
                         }
                         
                         dataCounter = 0;
@@ -185,6 +189,7 @@
                         digitalInBytes = 0;
                         analogInBytes = 0;
                         totalPacketBytes = 0;
+                        led4 = 0;
                     }
                 }
             }
@@ -194,6 +199,7 @@
             clear = true;
             lengthCalculated = false;
             dataCounter = 0;
+            led4 = 0;
         }
     }
 }
\ No newline at end of file