UDPversion
Dependencies: XBee mbed NetServicesMin
xbee/xbee_rec_route.cpp@1:3a46d2725374, 2012-04-15 (annotated)
- Committer:
- recotana
- Date:
- Sun Apr 15 10:49:08 2012 +0000
- Revision:
- 1:3a46d2725374
- Parent:
- 0:84a3b029656e
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
recotana | 0:84a3b029656e | 1 | #include "xbee_rec_route.h" |
recotana | 0:84a3b029656e | 2 | #include "config.h" |
recotana | 0:84a3b029656e | 3 | #include "XBee.h" |
recotana | 0:84a3b029656e | 4 | |
recotana | 0:84a3b029656e | 5 | #include "types.h" |
recotana | 0:84a3b029656e | 6 | |
recotana | 0:84a3b029656e | 7 | #include "xbee_lib.h" |
recotana | 0:84a3b029656e | 8 | #include "tcp_client.h" |
recotana | 0:84a3b029656e | 9 | #include "leds.h" |
recotana | 0:84a3b029656e | 10 | |
recotana | 1:3a46d2725374 | 11 | extern Serial pc; |
recotana | 1:3a46d2725374 | 12 | |
recotana | 0:84a3b029656e | 13 | extern XBee xbee; |
recotana | 0:84a3b029656e | 14 | extern ZBRxResponse zbRx; |
recotana | 0:84a3b029656e | 15 | |
recotana | 0:84a3b029656e | 16 | |
recotana | 0:84a3b029656e | 17 | void xbeeRecieveRouting(void) |
recotana | 0:84a3b029656e | 18 | { |
recotana | 1:3a46d2725374 | 19 | #ifdef _SERVER_TEST_MODE_ |
recotana | 1:3a46d2725374 | 20 | return; |
recotana | 1:3a46d2725374 | 21 | #else |
recotana | 0:84a3b029656e | 22 | xbeeReadPacket(); |
recotana | 0:84a3b029656e | 23 | |
recotana | 0:84a3b029656e | 24 | |
recotana | 0:84a3b029656e | 25 | if (isXbeeAvaiable()) { |
recotana | 0:84a3b029656e | 26 | |
recotana | 0:84a3b029656e | 27 | |
recotana | 0:84a3b029656e | 28 | |
recotana | 0:84a3b029656e | 29 | DBGF("xbee aviable!\r\n"); |
recotana | 0:84a3b029656e | 30 | |
recotana | 0:84a3b029656e | 31 | if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) { |
recotana | 0:84a3b029656e | 32 | |
recotana | 0:84a3b029656e | 33 | ledXBeeRx(); |
recotana | 0:84a3b029656e | 34 | |
recotana | 0:84a3b029656e | 35 | xbee.getResponse().getZBRxResponse(zbRx); |
recotana | 0:84a3b029656e | 36 | |
recotana | 0:84a3b029656e | 37 | Payload payload; |
recotana | 0:84a3b029656e | 38 | |
recotana | 0:84a3b029656e | 39 | uint16_t length = (unsigned char)zbRx.getData()[0]; |
recotana | 0:84a3b029656e | 40 | length =(length<<8) + (unsigned char)zbRx.getData()[1]; |
recotana | 0:84a3b029656e | 41 | |
recotana | 0:84a3b029656e | 42 | DBGV("length=%04X\r\n",length); |
recotana | 0:84a3b029656e | 43 | |
recotana | 0:84a3b029656e | 44 | memcpy(&payload, (unsigned char *)zbRx.getData(), length); |
recotana | 0:84a3b029656e | 45 | |
recotana | 0:84a3b029656e | 46 | |
recotana | 0:84a3b029656e | 47 | |
recotana | 0:84a3b029656e | 48 | networkToPayload(&payload); |
recotana | 0:84a3b029656e | 49 | |
recotana | 0:84a3b029656e | 50 | routing(&payload); |
recotana | 0:84a3b029656e | 51 | /* |
recotana | 0:84a3b029656e | 52 | pc.printf("xbee recieve!! size:%d\r\n",length); |
recotana | 0:84a3b029656e | 53 | |
recotana | 0:84a3b029656e | 54 | pc.printf("---------dump end\r\n"); |
recotana | 0:84a3b029656e | 55 | */ |
recotana | 0:84a3b029656e | 56 | |
recotana | 0:84a3b029656e | 57 | |
recotana | 0:84a3b029656e | 58 | |
recotana | 0:84a3b029656e | 59 | } |
recotana | 0:84a3b029656e | 60 | // pc.printf("\r\n"); |
recotana | 0:84a3b029656e | 61 | } |
recotana | 0:84a3b029656e | 62 | |
recotana | 1:3a46d2725374 | 63 | #endif |
recotana | 0:84a3b029656e | 64 | } |
recotana | 0:84a3b029656e | 65 | |
recotana | 0:84a3b029656e | 66 | void routing(Payload *_payload) |
recotana | 0:84a3b029656e | 67 | { |
recotana | 0:84a3b029656e | 68 | // dumpPayload(_payload); |
recotana | 0:84a3b029656e | 69 | switch(_payload->frame.message.command) |
recotana | 0:84a3b029656e | 70 | { |
recotana | 0:84a3b029656e | 71 | case SEND_SINGLE: |
recotana | 0:84a3b029656e | 72 | { |
recotana | 0:84a3b029656e | 73 | // _payload->frame.message.command=ACK; |
recotana | 0:84a3b029656e | 74 | // xbeeSend(0x4086B0D5,_payload); |
recotana | 1:3a46d2725374 | 75 | DBGF("*******[XBeeRec] send! *******\r\n"); |
recotana | 0:84a3b029656e | 76 | } |
recotana | 0:84a3b029656e | 77 | break; |
recotana | 0:84a3b029656e | 78 | |
recotana | 0:84a3b029656e | 79 | case RECIEVE: |
recotana | 0:84a3b029656e | 80 | { |
recotana | 0:84a3b029656e | 81 | udpSendPayload(_payload); |
recotana | 1:3a46d2725374 | 82 | DBGF("******[XBeeRec] recieve! *******\r\n"); |
recotana | 0:84a3b029656e | 83 | } |
recotana | 0:84a3b029656e | 84 | break; |
recotana | 0:84a3b029656e | 85 | |
recotana | 0:84a3b029656e | 86 | case PING: |
recotana | 0:84a3b029656e | 87 | { |
recotana | 0:84a3b029656e | 88 | |
recotana | 0:84a3b029656e | 89 | udpSendPayload(_payload); |
recotana | 1:3a46d2725374 | 90 | DBGF("*******[XBeeRec] ping! **************\r\n"); |
recotana | 0:84a3b029656e | 91 | } |
recotana | 0:84a3b029656e | 92 | break; |
recotana | 0:84a3b029656e | 93 | |
recotana | 0:84a3b029656e | 94 | case ACK: |
recotana | 0:84a3b029656e | 95 | { |
recotana | 0:84a3b029656e | 96 | udpSendPayload(_payload); |
recotana | 1:3a46d2725374 | 97 | DBGF("*******[XBeeRec] ACK! **************\r\n"); |
recotana | 0:84a3b029656e | 98 | } |
recotana | 0:84a3b029656e | 99 | |
recotana | 0:84a3b029656e | 100 | case SET_TX_GAIN: |
recotana | 1:3a46d2725374 | 101 | { |
recotana | 1:3a46d2725374 | 102 | udpSendPayload(_payload); |
recotana | 1:3a46d2725374 | 103 | DBGF("*******[XBeeRec] SET_TX_GAIN! **************\r\n"); |
recotana | 1:3a46d2725374 | 104 | } |
recotana | 1:3a46d2725374 | 105 | break; |
recotana | 0:84a3b029656e | 106 | case SET_LIGHT_CONTROL: |
recotana | 0:84a3b029656e | 107 | { |
recotana | 0:84a3b029656e | 108 | udpSendPayload(_payload); |
recotana | 1:3a46d2725374 | 109 | DBGF("*******[XBeeRec] SET_LIGHT_CONTROL! **************\r\n"); |
recotana | 0:84a3b029656e | 110 | } |
recotana | 0:84a3b029656e | 111 | break; |
recotana | 0:84a3b029656e | 112 | } |
recotana | 0:84a3b029656e | 113 | |
recotana | 0:84a3b029656e | 114 | } |