Home automation using Xbee radios

Dependencies:   EthernetNetIf HTTPServer RPCInterface mbed C12832_lcd

Link to Notebook Page

main.cpp

Committer:
hpham33
Date:
2013-11-28
Revision:
4:6091cb494e73
Parent:
3:c4bec8e7cc07
Child:
5:ae3cbcf75d78

File content as of revision 4:6091cb494e73:

#include "mbed.h"

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() {
 /* 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;
           }
    }
    else {
    printf("There is no node in the list");
    }
    if(node !=0){
    node->digitalData = data;
    }
    else{
 printf("Node is not in the list");
 }
}
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;
        }
    }else {
    printf("There is no node in the list");
    }
    if(node !=0){
 node->analogData[index] = data;
 }
 else{
 printf("Node is not in the list");
 }
}