![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
UDPversion
Dependencies: XBee mbed NetServicesMin
xbee/xbee_lib.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 "mbed.h" |
recotana | 0:84a3b029656e | 2 | #include "types.h" |
recotana | 0:84a3b029656e | 3 | #include "config.h" |
recotana | 0:84a3b029656e | 4 | #include "XBee.h" |
recotana | 0:84a3b029656e | 5 | #include "xbee_lib.h" |
recotana | 0:84a3b029656e | 6 | |
recotana | 0:84a3b029656e | 7 | #include "leds.h" |
recotana | 0:84a3b029656e | 8 | extern Serial pc; |
recotana | 0:84a3b029656e | 9 | |
recotana | 0:84a3b029656e | 10 | XBee xbee(p13, p14); |
recotana | 0:84a3b029656e | 11 | ZBRxResponse zbRx = ZBRxResponse(); |
recotana | 0:84a3b029656e | 12 | |
recotana | 0:84a3b029656e | 13 | extern PrefServer pref; |
recotana | 1:3a46d2725374 | 14 | extern PrefSender spref; |
recotana | 1:3a46d2725374 | 15 | extern PrefReciever rpref; |
recotana | 0:84a3b029656e | 16 | |
recotana | 0:84a3b029656e | 17 | void xbeeInit(void) |
recotana | 0:84a3b029656e | 18 | { |
recotana | 1:3a46d2725374 | 19 | |
recotana | 1:3a46d2725374 | 20 | pref.xbeeAdress = kMyXBeeAddress; |
recotana | 1:3a46d2725374 | 21 | spref.xbeeAdress = kLedSender; |
recotana | 1:3a46d2725374 | 22 | rpref.xbeeAdress = kLedReciever; |
recotana | 1:3a46d2725374 | 23 | |
recotana | 1:3a46d2725374 | 24 | #ifdef _SERVER_TEST_MODE_ |
recotana | 1:3a46d2725374 | 25 | return; |
recotana | 1:3a46d2725374 | 26 | #else |
recotana | 1:3a46d2725374 | 27 | |
recotana | 0:84a3b029656e | 28 | LPC_UART1->MCR |= (1<<7); // CTSEN |
recotana | 0:84a3b029656e | 29 | LPC_PINCON->PINSEL1 &= ~(3 << 2); |
recotana | 0:84a3b029656e | 30 | LPC_PINCON->PINSEL1 |= (1 << 2); // UART CTS |
recotana | 0:84a3b029656e | 31 | xbee.begin(kXBeeBoudRate); |
recotana | 1:3a46d2725374 | 32 | |
recotana | 1:3a46d2725374 | 33 | |
recotana | 1:3a46d2725374 | 34 | |
recotana | 0:84a3b029656e | 35 | pc.printf("XBee setup OK! XBee serial boudrate:%d address:%04X\r\n",kXBeeBoudRate,pref.xbeeAdress); |
recotana | 1:3a46d2725374 | 36 | #endif |
recotana | 0:84a3b029656e | 37 | } |
recotana | 0:84a3b029656e | 38 | |
recotana | 0:84a3b029656e | 39 | void xbeeSend(uint32_t addr , Payload *_payload) |
recotana | 0:84a3b029656e | 40 | { |
recotana | 1:3a46d2725374 | 41 | #ifdef _SERVER_TEST_MODE_ |
recotana | 1:3a46d2725374 | 42 | return; |
recotana | 1:3a46d2725374 | 43 | #else |
recotana | 0:84a3b029656e | 44 | ledXBeeTx(); |
recotana | 0:84a3b029656e | 45 | |
recotana | 0:84a3b029656e | 46 | XBeeAddress64 deviceAdr = XBeeAddress64(0x0013a200, addr); |
recotana | 0:84a3b029656e | 47 | |
recotana | 0:84a3b029656e | 48 | uint16_t length = sizeof(Payload); |
recotana | 0:84a3b029656e | 49 | _payload->size = length; |
recotana | 0:84a3b029656e | 50 | uint8_t tmp[length]; |
recotana | 0:84a3b029656e | 51 | |
recotana | 0:84a3b029656e | 52 | memcpy(tmp , (uint8_t*)_payload , length); |
recotana | 0:84a3b029656e | 53 | |
recotana | 0:84a3b029656e | 54 | payloadToNetwork((Payload*)tmp); |
recotana | 0:84a3b029656e | 55 | ZBTxRequest zbTx = ZBTxRequest(deviceAdr , tmp , length ); |
recotana | 0:84a3b029656e | 56 | |
recotana | 0:84a3b029656e | 57 | xbee.send(zbTx); |
recotana | 1:3a46d2725374 | 58 | DBGF("+++++ xbee send!!\r\n"); |
recotana | 1:3a46d2725374 | 59 | #endif |
recotana | 0:84a3b029656e | 60 | } |
recotana | 0:84a3b029656e | 61 | |
recotana | 0:84a3b029656e | 62 | void xbeeReadPacket(void) |
recotana | 0:84a3b029656e | 63 | { |
recotana | 1:3a46d2725374 | 64 | #ifndef _SERVER_TEST_MODE_ |
recotana | 0:84a3b029656e | 65 | xbee.readPacket(); |
recotana | 1:3a46d2725374 | 66 | #endif |
recotana | 1:3a46d2725374 | 67 | |
recotana | 0:84a3b029656e | 68 | } |
recotana | 0:84a3b029656e | 69 | bool isXbeeAvaiable(void) |
recotana | 0:84a3b029656e | 70 | { |
recotana | 1:3a46d2725374 | 71 | #ifdef _SERVER_TEST_MODE_ |
recotana | 1:3a46d2725374 | 72 | return false; |
recotana | 1:3a46d2725374 | 73 | #else |
recotana | 0:84a3b029656e | 74 | return xbee.getResponse().isAvailable(); |
recotana | 1:3a46d2725374 | 75 | #endif |
recotana | 0:84a3b029656e | 76 | } |