Hiroshi Yamaguchi / Mbed 2 deprecated XBeeExamples

Dependencies:   mbed XBee mbed-rtos

Committer:
yamaguch
Date:
Thu Mar 21 07:16:44 2013 +0000
Revision:
14:50ee389d681f
Parent:
11:25a790b8feb0
updated to use new XBee lib

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yamaguch 11:25a790b8feb0 1 #include "XBee.h"
yamaguch 11:25a790b8feb0 2
yamaguch 11:25a790b8feb0 3 void printNetInfo(XBee& xbee) {
yamaguch 11:25a790b8feb0 4 printf("OP: %s\n", (char *) XBeeAddress64(*(uint64_t *) xbee.executeCommand("OP")));
yamaguch 11:25a790b8feb0 5 printf("OI: %s\n", (char *) XBeeAddress16(*(uint16_t *) xbee.executeCommand("OI")));
yamaguch 11:25a790b8feb0 6 printf("CH: %d\n", *(uint8_t *) xbee.executeCommand("CH"));
yamaguch 11:25a790b8feb0 7 }
yamaguch 11:25a790b8feb0 8
yamaguch 11:25a790b8feb0 9 int receiveModemStatus(XBee& xbee) {
yamaguch 11:25a790b8feb0 10 if (xbee.receive() == XBee::ModemStatus) {
yamaguch 11:25a790b8feb0 11 XBeeStatus status;
yamaguch 11:25a790b8feb0 12 if (xbee.scan(status)) {
yamaguch 11:25a790b8feb0 13 const char *modemStatus[] = {
yamaguch 11:25a790b8feb0 14 "Hardware reset", // 0
yamaguch 11:25a790b8feb0 15 "Watchdog timer reset", // 1
yamaguch 11:25a790b8feb0 16 "Joined network (routers and end devices)", // 2
yamaguch 11:25a790b8feb0 17 "Disassociated", // 3
yamaguch 11:25a790b8feb0 18 "?", "?", // 4, 5
yamaguch 11:25a790b8feb0 19 "Coordinator started" // 6
yamaguch 11:25a790b8feb0 20 };
yamaguch 11:25a790b8feb0 21 printf("Modem Status = %s\n", status < 7 ? modemStatus[status] : "?");
yamaguch 11:25a790b8feb0 22 }
yamaguch 11:25a790b8feb0 23 return status;
yamaguch 11:25a790b8feb0 24 }
yamaguch 11:25a790b8feb0 25 return -1;
yamaguch 11:25a790b8feb0 26 }
yamaguch 11:25a790b8feb0 27
yamaguch 11:25a790b8feb0 28 void xbee_network_reset() {
yamaguch 11:25a790b8feb0 29 XBee xbee(p9, p10);
yamaguch 14:50ee389d681f 30 xbee.baud(9600);
yamaguch 11:25a790b8feb0 31
yamaguch 11:25a790b8feb0 32 printf("*** Network Reset ***\n");
yamaguch 11:25a790b8feb0 33
yamaguch 11:25a790b8feb0 34 if (xbee.init()) {
yamaguch 11:25a790b8feb0 35 printNetInfo(xbee);
yamaguch 11:25a790b8feb0 36
yamaguch 11:25a790b8feb0 37 printf("Issuing NR0 command...\n");
yamaguch 11:25a790b8feb0 38 xbee.sendCommand("NR", 0);
yamaguch 11:25a790b8feb0 39
yamaguch 11:25a790b8feb0 40 // wait for XBee to join network
yamaguch 11:25a790b8feb0 41 while (receiveModemStatus(xbee) != 2)
yamaguch 11:25a790b8feb0 42 ;
yamaguch 11:25a790b8feb0 43 printNetInfo(xbee);
yamaguch 11:25a790b8feb0 44 } else {
yamaguch 11:25a790b8feb0 45 printf("XBee connection error");
yamaguch 11:25a790b8feb0 46 }
yamaguch 11:25a790b8feb0 47
yamaguch 11:25a790b8feb0 48 }