Home automation using Xbee radios

Dependencies:   EthernetNetIf HTTPServer RPCInterface mbed C12832_lcd

Link to Notebook Page

Revision:
9:4b1e3531dd00
Parent:
8:e32fcca16102
Child:
10:de0be690b3c0
--- a/XbeeCommLib.cpp	Mon Dec 02 22:25:29 2013 +0000
+++ b/XbeeCommLib.cpp	Wed Dec 04 02:35:47 2013 +0000
@@ -118,6 +118,13 @@
                     if(lengthCalculated && (dataCounter == totalPacketBytes)){
                         //Do packet handling here...
                         
+                        /*printf("Printing packet - %d bytes:\n", dataCounter);
+                        for(i = 0; i < dataCounter; i++){
+                            printf("%x\n", data[i]);
+                        }
+                        printf("End of packet\n");*/
+                        
+                        
                         //Determine source address
                         for(i = 0; i < 4; i++){
                             addrHigh = addrHigh | (data[4 + i] << (3-i)*8);
@@ -125,9 +132,13 @@
                             
                             //Hijack this loop to initialize the analogPortNumbers array
                             analogPortNumbers[i] = -1;
-                        }    
+                        }
+                        if(DEBUG)
+                            printf("\n\nReceived packet from %x %x\n", addrHigh, addrLow);
                         
                         if(analogInBytes){
+                            if(DEBUG)
+                                printf("Analog Data Present\n");
                             //Figure out where the analog bytes start
                             if(digitalInBytes)
                                 startingPacket = 21;
@@ -135,25 +146,37 @@
                                 startingPacket = 19;
                             
                             //Determine how many analog inputs are active, and which pins they use
+//                            printf("Analog inputs ");
                             for(i = 0; i < 4; i++){
                                 if( ((data[18] & 0xF) >> i) & 1 ){
+//                                    printf("%d ", i);
                                     analogPortNumbers[analogCount] = i;
                                     analogCount++;
                                 }
                             }
+//                            printf("active\n");
+                            
+                            if(DEBUG)
+                                printf("%d Ananlog inputs total\n", analogCount);
                             
                             //Decode analog data and push into appropriate struct
                             for(i = 0; i < analogCount; i++){
                                 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);
                             }
                         }
                         
                         if(digitalInBytes){
-                            //unsigned short digitalMask = (data[16] << 8) | data[17];
+                            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);
+
                         }
                         
                         dataCounter = 0;