![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
UDPversion
Dependencies: XBee mbed NetServicesMin
xbee/xbee_lib.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 "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 | 0:84a3b029656e | 14 | |
recotana | 0:84a3b029656e | 15 | void xbeeInit(void) |
recotana | 0:84a3b029656e | 16 | { |
recotana | 0:84a3b029656e | 17 | LPC_UART1->MCR |= (1<<7); // CTSEN |
recotana | 0:84a3b029656e | 18 | LPC_PINCON->PINSEL1 &= ~(3 << 2); |
recotana | 0:84a3b029656e | 19 | LPC_PINCON->PINSEL1 |= (1 << 2); // UART CTS |
recotana | 0:84a3b029656e | 20 | xbee.begin(kXBeeBoudRate); |
recotana | 0:84a3b029656e | 21 | pref.xbeeAdress = kMyXBeeAddress; |
recotana | 0:84a3b029656e | 22 | pc.printf("XBee setup OK! XBee serial boudrate:%d address:%04X\r\n",kXBeeBoudRate,pref.xbeeAdress); |
recotana | 0:84a3b029656e | 23 | } |
recotana | 0:84a3b029656e | 24 | |
recotana | 0:84a3b029656e | 25 | void xbeeSend(uint32_t addr , Payload *_payload) |
recotana | 0:84a3b029656e | 26 | { |
recotana | 0:84a3b029656e | 27 | ledXBeeTx(); |
recotana | 0:84a3b029656e | 28 | |
recotana | 0:84a3b029656e | 29 | XBeeAddress64 deviceAdr = XBeeAddress64(0x0013a200, addr); |
recotana | 0:84a3b029656e | 30 | |
recotana | 0:84a3b029656e | 31 | uint16_t length = sizeof(Payload); |
recotana | 0:84a3b029656e | 32 | _payload->size = length; |
recotana | 0:84a3b029656e | 33 | uint8_t tmp[length]; |
recotana | 0:84a3b029656e | 34 | |
recotana | 0:84a3b029656e | 35 | memcpy(tmp , (uint8_t*)_payload , length); |
recotana | 0:84a3b029656e | 36 | |
recotana | 0:84a3b029656e | 37 | payloadToNetwork((Payload*)tmp); |
recotana | 0:84a3b029656e | 38 | ZBTxRequest zbTx = ZBTxRequest(deviceAdr , tmp , length ); |
recotana | 0:84a3b029656e | 39 | |
recotana | 0:84a3b029656e | 40 | xbee.send(zbTx); |
recotana | 0:84a3b029656e | 41 | DBGF("+++++ xbee send!!\r\n"); |
recotana | 0:84a3b029656e | 42 | |
recotana | 0:84a3b029656e | 43 | |
recotana | 0:84a3b029656e | 44 | } |
recotana | 0:84a3b029656e | 45 | |
recotana | 0:84a3b029656e | 46 | void xbeeReadPacket(void) |
recotana | 0:84a3b029656e | 47 | { |
recotana | 0:84a3b029656e | 48 | xbee.readPacket(); |
recotana | 0:84a3b029656e | 49 | } |
recotana | 0:84a3b029656e | 50 | bool isXbeeAvaiable(void) |
recotana | 0:84a3b029656e | 51 | { |
recotana | 0:84a3b029656e | 52 | return xbee.getResponse().isAvailable(); |
recotana | 0:84a3b029656e | 53 | } |