UDPversion
Dependencies: XBee mbed NetServicesMin
xbee/xbee_rec_route.cpp@0:84a3b029656e, 2012-04-14 (annotated)
- Committer:
- recotana
- Date:
- Sat Apr 14 03:53:45 2012 +0000
- Revision:
- 0:84a3b029656e
- Child:
- 1:3a46d2725374
UDPversion
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 | 0:84a3b029656e | 11 | extern XBee xbee; |
recotana | 0:84a3b029656e | 12 | extern ZBRxResponse zbRx; |
recotana | 0:84a3b029656e | 13 | |
recotana | 0:84a3b029656e | 14 | |
recotana | 0:84a3b029656e | 15 | void xbeeRecieveRouting(void) |
recotana | 0:84a3b029656e | 16 | { |
recotana | 0:84a3b029656e | 17 | |
recotana | 0:84a3b029656e | 18 | xbeeReadPacket(); |
recotana | 0:84a3b029656e | 19 | |
recotana | 0:84a3b029656e | 20 | |
recotana | 0:84a3b029656e | 21 | if (isXbeeAvaiable()) { |
recotana | 0:84a3b029656e | 22 | |
recotana | 0:84a3b029656e | 23 | |
recotana | 0:84a3b029656e | 24 | |
recotana | 0:84a3b029656e | 25 | DBGF("xbee aviable!\r\n"); |
recotana | 0:84a3b029656e | 26 | |
recotana | 0:84a3b029656e | 27 | if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) { |
recotana | 0:84a3b029656e | 28 | |
recotana | 0:84a3b029656e | 29 | ledXBeeRx(); |
recotana | 0:84a3b029656e | 30 | |
recotana | 0:84a3b029656e | 31 | xbee.getResponse().getZBRxResponse(zbRx); |
recotana | 0:84a3b029656e | 32 | |
recotana | 0:84a3b029656e | 33 | Payload payload; |
recotana | 0:84a3b029656e | 34 | |
recotana | 0:84a3b029656e | 35 | uint16_t length = (unsigned char)zbRx.getData()[0]; |
recotana | 0:84a3b029656e | 36 | length =(length<<8) + (unsigned char)zbRx.getData()[1]; |
recotana | 0:84a3b029656e | 37 | |
recotana | 0:84a3b029656e | 38 | DBGV("length=%04X\r\n",length); |
recotana | 0:84a3b029656e | 39 | |
recotana | 0:84a3b029656e | 40 | memcpy(&payload, (unsigned char *)zbRx.getData(), length); |
recotana | 0:84a3b029656e | 41 | |
recotana | 0:84a3b029656e | 42 | |
recotana | 0:84a3b029656e | 43 | |
recotana | 0:84a3b029656e | 44 | networkToPayload(&payload); |
recotana | 0:84a3b029656e | 45 | |
recotana | 0:84a3b029656e | 46 | routing(&payload); |
recotana | 0:84a3b029656e | 47 | /* |
recotana | 0:84a3b029656e | 48 | pc.printf("xbee recieve!! size:%d\r\n",length); |
recotana | 0:84a3b029656e | 49 | |
recotana | 0:84a3b029656e | 50 | pc.printf("---------dump end\r\n"); |
recotana | 0:84a3b029656e | 51 | */ |
recotana | 0:84a3b029656e | 52 | |
recotana | 0:84a3b029656e | 53 | |
recotana | 0:84a3b029656e | 54 | |
recotana | 0:84a3b029656e | 55 | } |
recotana | 0:84a3b029656e | 56 | // pc.printf("\r\n"); |
recotana | 0:84a3b029656e | 57 | } |
recotana | 0:84a3b029656e | 58 | |
recotana | 0:84a3b029656e | 59 | |
recotana | 0:84a3b029656e | 60 | } |
recotana | 0:84a3b029656e | 61 | |
recotana | 0:84a3b029656e | 62 | void routing(Payload *_payload) |
recotana | 0:84a3b029656e | 63 | { |
recotana | 0:84a3b029656e | 64 | // dumpPayload(_payload); |
recotana | 0:84a3b029656e | 65 | switch(_payload->frame.message.command) |
recotana | 0:84a3b029656e | 66 | { |
recotana | 0:84a3b029656e | 67 | case SEND_SINGLE: |
recotana | 0:84a3b029656e | 68 | { |
recotana | 0:84a3b029656e | 69 | // _payload->frame.message.command=ACK; |
recotana | 0:84a3b029656e | 70 | // xbeeSend(0x4086B0D5,_payload); |
recotana | 0:84a3b029656e | 71 | DBGF("******* send! *******\r\n"); |
recotana | 0:84a3b029656e | 72 | } |
recotana | 0:84a3b029656e | 73 | break; |
recotana | 0:84a3b029656e | 74 | |
recotana | 0:84a3b029656e | 75 | case RECIEVE: |
recotana | 0:84a3b029656e | 76 | { |
recotana | 0:84a3b029656e | 77 | udpSendPayload(_payload); |
recotana | 0:84a3b029656e | 78 | DBGF("****** recieve! *******\r\n"); |
recotana | 0:84a3b029656e | 79 | } |
recotana | 0:84a3b029656e | 80 | break; |
recotana | 0:84a3b029656e | 81 | |
recotana | 0:84a3b029656e | 82 | case PING: |
recotana | 0:84a3b029656e | 83 | { |
recotana | 0:84a3b029656e | 84 | |
recotana | 0:84a3b029656e | 85 | udpSendPayload(_payload); |
recotana | 0:84a3b029656e | 86 | DBGF("******* ping! **************\r\n"); |
recotana | 0:84a3b029656e | 87 | } |
recotana | 0:84a3b029656e | 88 | break; |
recotana | 0:84a3b029656e | 89 | |
recotana | 0:84a3b029656e | 90 | case ACK: |
recotana | 0:84a3b029656e | 91 | { |
recotana | 0:84a3b029656e | 92 | udpSendPayload(_payload); |
recotana | 0:84a3b029656e | 93 | DBGF("******* ACK! **************\r\n"); |
recotana | 0:84a3b029656e | 94 | } |
recotana | 0:84a3b029656e | 95 | |
recotana | 0:84a3b029656e | 96 | case SET_TX_GAIN: |
recotana | 0:84a3b029656e | 97 | case SET_LIGHT_CONTROL: |
recotana | 0:84a3b029656e | 98 | { |
recotana | 0:84a3b029656e | 99 | udpSendPayload(_payload); |
recotana | 0:84a3b029656e | 100 | } |
recotana | 0:84a3b029656e | 101 | break; |
recotana | 0:84a3b029656e | 102 | } |
recotana | 0:84a3b029656e | 103 | |
recotana | 0:84a3b029656e | 104 | } |