UDPversion

Dependencies:   XBee mbed NetServicesMin

xbee/xbee_rec_route.cpp

Committer:
recotana
Date:
2012-04-14
Revision:
0:84a3b029656e
Child:
1:3a46d2725374

File content as of revision 0:84a3b029656e:

#include "xbee_rec_route.h"
#include "config.h"
#include "XBee.h"

#include "types.h"

#include "xbee_lib.h"
#include "tcp_client.h"
#include "leds.h"

extern XBee xbee;
extern ZBRxResponse zbRx;


void xbeeRecieveRouting(void)
{

     xbeeReadPacket();
    
   
        if (isXbeeAvaiable()) {
            
            
    
            DBGF("xbee aviable!\r\n");
        
            if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
                
                ledXBeeRx();
                
                xbee.getResponse().getZBRxResponse(zbRx);
                
                Payload payload;

                uint16_t length = (unsigned char)zbRx.getData()[0];
                length =(length<<8) + (unsigned char)zbRx.getData()[1];
                
                DBGV("length=%04X\r\n",length);
                
                memcpy(&payload, (unsigned char *)zbRx.getData(), length);

                
                
                networkToPayload(&payload);
               
                routing(&payload);
                /*
                pc.printf("xbee recieve!! size:%d\r\n",length);
                
                pc.printf("---------dump end\r\n");
                */
                
                
           
            }
        //    pc.printf("\r\n");
        }
    
    
}

void routing(Payload *_payload)
{
//     dumpPayload(_payload);
    switch(_payload->frame.message.command)
    {
        case SEND_SINGLE:
        {
        //    _payload->frame.message.command=ACK;
        //    xbeeSend(0x4086B0D5,_payload);
            DBGF("*******  send!  *******\r\n");
        }
        break;
        
        case RECIEVE:
        {
            udpSendPayload(_payload);
            DBGF("******  recieve!  *******\r\n");
        }
        break;
        
        case PING:
        {   
            
            udpSendPayload(_payload);
            DBGF("*******  ping!  **************\r\n");
        }
        break;
        
        case ACK:
        {   
            udpSendPayload(_payload);
            DBGF("*******  ACK!  **************\r\n");
        }
        
        case SET_TX_GAIN:
        case SET_LIGHT_CONTROL:
        {
            udpSendPayload(_payload);
        }
        break;
    }

}