Home automation using Xbee radios

Dependencies:   EthernetNetIf HTTPServer RPCInterface mbed C12832_lcd

Link to Notebook Page

Revision:
2:9503a713b648
Parent:
1:230c1ec1c9bb
Child:
3:c4bec8e7cc07
--- a/main.cpp	Tue Nov 26 01:40:05 2013 +0000
+++ b/main.cpp	Wed Nov 27 18:36:31 2013 +0000
@@ -1,12 +1,105 @@
 #include "mbed.h"
 
-DigitalOut myled(LED1);
+DigitalIn pb(p8);
+
+
+
+struct xbee {              // radio prototype with addresss, location, pointer to sensor list
+    unsigned int addrHigh;        // upper 16 bits address of sensor
+    unsigned int addrLow;         // lower  address of sensor
+    unsigned short digitalData;
+    unsigned short digitalDataOutput;
+    int digitalType[10];
+    float analogData[4];
+    int analogType[4];
+    struct xbee * next;    // pointer to next struct
+};
+
+struct xbee* addnode(struct xbee*,unsigned int,unsigned int );
+int getDigitalValue(int , short );
+void digitalInputHandle(struct xbee* ,unsigned int , unsigned int , unsigned short );
+void analogInputHandle(struct xbee* ,unsigned int , unsigned int , int , float );
 
 int main() {
-    while(1) {
-        myled = 0;
-        wait(0.2);
-        myled = 0;
-        wait(0.2);
+ /* This won't change, or we would lose the list in memory */
+    struct xbee *root;
+    root->next = NULL; 
+    /* The node root points to has its next pointer equal to a null pointer 
+       set */
+     struct xbee* xbee1;
+     struct xbee* xbee2;
+     struct xbee* xbee3;
+ 
+     xbee1 = addnode(root,0,1);
+     xbee2 = addnode(root,0,2);
+     xbee3 = addnode(root,0,3);
+}
+
+struct xbee* addnode(struct xbee* root,unsigned int addrhigh,unsigned int addrlow){
+
+ struct xbee* node;
+ node = root;
+ 
+    if ( node != 0 ) {
+        while ( node->next != 0)
+        {
+           node = node->next;
+        }
     }
+node = (struct xbee *) malloc( sizeof(struct xbee) );
+node->next = NULL;
+node->addrHigh =addrhigh;
+node->addrLow =addrlow;
+   return node;
 }
+int getDigitalValue(int i, short pins){
+return ((pins>>i)&1);
+}
+float analogInputFormat(float data, int type){
+    switch (type){
+    case 1:
+    data = data;
+    break;
+    case 2:
+    data = data;
+    break;
+    case 3:
+    data = data;
+    break;
+    default:
+    data = data;
+    break;
+    }
+return(data);
+}
+
+void digitalInputHandle(struct xbee* root,unsigned int addrhigh, unsigned int addrlow, unsigned short data){
+struct xbee* node;
+node = root;
+ 
+    if ( node != 0 ) {
+        while ( node->addrHigh != addrhigh)
+        {          
+           node = node->next;
+           while(node->addrLow !=addrlow){
+           node = node->next;
+           }
+        }
+    }
+    node->digitalData = data;
+}
+void analogInputHandle(struct xbee* root,unsigned int addrhigh, unsigned int addrlow, int index, float data){
+struct xbee* node;
+node = root;
+ 
+    if ( node != 0 ) {
+        while ( node->addrHigh != addrhigh)
+        {          
+           node = node->next;
+           while(node->addrLow !=addrlow){
+           node = node->next;
+           }
+        }
+    }
+ node->analogData[index] = data;
+}
\ No newline at end of file