server/client
Dependencies: mbed NetServicesMin
xbee_lib.cpp@1:6e61ee662fd3, 2012-02-23 (annotated)
- Committer:
- recotana
- Date:
- Thu Feb 23 02:38:05 2012 +0000
- Revision:
- 1:6e61ee662fd3
added standalone test mode
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
recotana | 1:6e61ee662fd3 | 1 | #include "mbed.h" |
recotana | 1:6e61ee662fd3 | 2 | #include "types.h" |
recotana | 1:6e61ee662fd3 | 3 | #include "config.h" |
recotana | 1:6e61ee662fd3 | 4 | #include "XBee.h" |
recotana | 1:6e61ee662fd3 | 5 | #include "xbee_lib.h" |
recotana | 1:6e61ee662fd3 | 6 | |
recotana | 1:6e61ee662fd3 | 7 | #include "leds.h" |
recotana | 1:6e61ee662fd3 | 8 | |
recotana | 1:6e61ee662fd3 | 9 | XBee xbee(p13, p14); |
recotana | 1:6e61ee662fd3 | 10 | ZBRxResponse zbRx = ZBRxResponse(); |
recotana | 1:6e61ee662fd3 | 11 | |
recotana | 1:6e61ee662fd3 | 12 | void xbeeInit(void) |
recotana | 1:6e61ee662fd3 | 13 | { |
recotana | 1:6e61ee662fd3 | 14 | xbee.begin(9800); |
recotana | 1:6e61ee662fd3 | 15 | } |
recotana | 1:6e61ee662fd3 | 16 | |
recotana | 1:6e61ee662fd3 | 17 | void xbeeSend(uint32_t addr , Payload *_payload) |
recotana | 1:6e61ee662fd3 | 18 | { |
recotana | 1:6e61ee662fd3 | 19 | ledXBee(); |
recotana | 1:6e61ee662fd3 | 20 | |
recotana | 1:6e61ee662fd3 | 21 | XBeeAddress64 deviceAdr = XBeeAddress64(0x0013a200, addr); |
recotana | 1:6e61ee662fd3 | 22 | |
recotana | 1:6e61ee662fd3 | 23 | uint16_t length = sizeof(Payload); |
recotana | 1:6e61ee662fd3 | 24 | _payload->size = length; |
recotana | 1:6e61ee662fd3 | 25 | uint8_t tmp[length]; |
recotana | 1:6e61ee662fd3 | 26 | |
recotana | 1:6e61ee662fd3 | 27 | memcpy(tmp , (uint8_t*)_payload , length); |
recotana | 1:6e61ee662fd3 | 28 | |
recotana | 1:6e61ee662fd3 | 29 | payloadToNetwork((Payload*)tmp); |
recotana | 1:6e61ee662fd3 | 30 | ZBTxRequest zbTx = ZBTxRequest(deviceAdr , tmp , length ); |
recotana | 1:6e61ee662fd3 | 31 | |
recotana | 1:6e61ee662fd3 | 32 | xbee.send(zbTx); |
recotana | 1:6e61ee662fd3 | 33 | DBGF("+++++ xbee send!!\r\n"); |
recotana | 1:6e61ee662fd3 | 34 | |
recotana | 1:6e61ee662fd3 | 35 | |
recotana | 1:6e61ee662fd3 | 36 | } |
recotana | 1:6e61ee662fd3 | 37 | |
recotana | 1:6e61ee662fd3 | 38 | void xbeeReadPacket(void) |
recotana | 1:6e61ee662fd3 | 39 | { |
recotana | 1:6e61ee662fd3 | 40 | xbee.readPacket(); |
recotana | 1:6e61ee662fd3 | 41 | } |
recotana | 1:6e61ee662fd3 | 42 | bool isXbeeAvaiable(void) |
recotana | 1:6e61ee662fd3 | 43 | { |
recotana | 1:6e61ee662fd3 | 44 | return xbee.getResponse().isAvailable(); |
recotana | 1:6e61ee662fd3 | 45 | } |