Kyle Lemons
/
XBeeLib
main.cpp@2:2a826741387f, 2010-12-01 (annotated)
- Committer:
- etherealflaim
- Date:
- Wed Dec 01 21:41:52 2010 +0000
- Revision:
- 2:2a826741387f
- Parent:
- 0:86ff0a55c978
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
etherealflaim | 0:86ff0a55c978 | 1 | #define _XBEE_DEBUG 0 |
etherealflaim | 0:86ff0a55c978 | 2 | #if _XBEE_DEBUG > 0 |
etherealflaim | 0:86ff0a55c978 | 3 | |
etherealflaim | 0:86ff0a55c978 | 4 | #include "mbed.h" |
etherealflaim | 0:86ff0a55c978 | 5 | |
etherealflaim | 0:86ff0a55c978 | 6 | #include "XBee.hpp" |
etherealflaim | 0:86ff0a55c978 | 7 | |
etherealflaim | 0:86ff0a55c978 | 8 | XBee xb("TEST_UID", p28, p27, p26, p21); |
etherealflaim | 0:86ff0a55c978 | 9 | Serial usb(USBTX, USBRX); |
etherealflaim | 0:86ff0a55c978 | 10 | |
etherealflaim | 0:86ff0a55c978 | 11 | void usbrx() { |
etherealflaim | 0:86ff0a55c978 | 12 | static string msg; |
etherealflaim | 0:86ff0a55c978 | 13 | |
etherealflaim | 0:86ff0a55c978 | 14 | while (usb.readable()) |
etherealflaim | 0:86ff0a55c978 | 15 | { |
etherealflaim | 0:86ff0a55c978 | 16 | int ch = usb.getc(); |
etherealflaim | 0:86ff0a55c978 | 17 | switch (ch) |
etherealflaim | 0:86ff0a55c978 | 18 | { |
etherealflaim | 0:86ff0a55c978 | 19 | case '\r': |
etherealflaim | 0:86ff0a55c978 | 20 | case '\n': |
etherealflaim | 0:86ff0a55c978 | 21 | if (msg.length() == 0) break; |
etherealflaim | 0:86ff0a55c978 | 22 | xb.broadcast(msg); |
etherealflaim | 0:86ff0a55c978 | 23 | msg = ""; |
etherealflaim | 0:86ff0a55c978 | 24 | usb.printf("<sent>\r\n"); |
etherealflaim | 0:86ff0a55c978 | 25 | break; |
etherealflaim | 0:86ff0a55c978 | 26 | |
etherealflaim | 0:86ff0a55c978 | 27 | default: |
etherealflaim | 0:86ff0a55c978 | 28 | msg += string(1, ch); |
etherealflaim | 0:86ff0a55c978 | 29 | usb.putc(ch); // echo |
etherealflaim | 0:86ff0a55c978 | 30 | break; |
etherealflaim | 0:86ff0a55c978 | 31 | } |
etherealflaim | 0:86ff0a55c978 | 32 | } |
etherealflaim | 0:86ff0a55c978 | 33 | } |
etherealflaim | 0:86ff0a55c978 | 34 | |
etherealflaim | 0:86ff0a55c978 | 35 | void xbrx() { |
etherealflaim | 0:86ff0a55c978 | 36 | while (xb.readable()) |
etherealflaim | 0:86ff0a55c978 | 37 | { |
etherealflaim | 0:86ff0a55c978 | 38 | usb.printf("XBEE RX\r\n"); |
etherealflaim | 0:86ff0a55c978 | 39 | XBeePacket pkt = xb.read(); |
etherealflaim | 0:86ff0a55c978 | 40 | vector<string> data = pkt.split_data(); |
etherealflaim | 0:86ff0a55c978 | 41 | for (int i = 0; i < data.size(); ++i) |
etherealflaim | 0:86ff0a55c978 | 42 | usb.printf("> %s\r\n", data[i].c_str()); |
etherealflaim | 0:86ff0a55c978 | 43 | } |
etherealflaim | 0:86ff0a55c978 | 44 | } |
etherealflaim | 0:86ff0a55c978 | 45 | |
etherealflaim | 0:86ff0a55c978 | 46 | int main() { |
etherealflaim | 0:86ff0a55c978 | 47 | usb.attach(usbrx); |
etherealflaim | 0:86ff0a55c978 | 48 | xb.attach(xbrx); |
etherealflaim | 0:86ff0a55c978 | 49 | |
etherealflaim | 0:86ff0a55c978 | 50 | while(1) |
etherealflaim | 0:86ff0a55c978 | 51 | { |
etherealflaim | 0:86ff0a55c978 | 52 | wait(1); |
etherealflaim | 0:86ff0a55c978 | 53 | } |
etherealflaim | 0:86ff0a55c978 | 54 | } |
etherealflaim | 0:86ff0a55c978 | 55 | |
etherealflaim | 0:86ff0a55c978 | 56 | #endif |