Hiroshi Yamaguchi / Mbed 2 deprecated XBeeExamples

Dependencies:   mbed XBee mbed-rtos

Revision:
7:39deffbdcae4
Parent:
5:d01cf03058f6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/xbee_network_reset.cpp	Wed Sep 26 06:13:30 2012 +0000
@@ -0,0 +1,48 @@
+#include "XBee.h"
+
+void printNetInfo(XBee& xbee) {
+    printf("OP: %s\n", (char *) XBeeAddress64(*(uint64_t *) xbee.executeCommand("OP")));
+    printf("OI: %s\n", (char *) XBeeAddress16(*(uint16_t *) xbee.executeCommand("OI")));
+    printf("CH: %d\n", *(uint8_t *) xbee.executeCommand("CH"));
+}
+
+int receiveModemStatus(XBee& xbee) {
+    if (xbee.receive() == XBee::ModemStatus) {
+        XBeeStatus status;
+        if (xbee.scan(status)) {
+            const char *modemStatus[] = {
+                "Hardware reset", // 0
+                "Watchdog timer reset", // 1
+                "Joined network (routers and end devices)", // 2
+                "Disassociated", // 3
+                "?", "?",  // 4, 5
+                "Coordinator started" // 6
+            };
+            printf("Modem Status = %s\n", status < 7 ? modemStatus[status] : "?");
+        }
+        return status;
+    }
+    return -1;
+}
+
+void xbee_network_reset() {
+    XBee xbee(p9, p10);
+    xbee.baud(115200);
+
+    printf("*** Network Reset ***\n");
+
+    if (xbee.init()) {
+        printNetInfo(xbee);
+
+        printf("Issuing NR0 command...\n");
+        xbee.sendCommand("NR", 0);
+
+        // wait for XBee to join network
+        while (receiveModemStatus(xbee) != 2)
+            ;
+        printNetInfo(xbee);
+    } else {
+        printf("XBee connection error");
+    }
+
+}
\ No newline at end of file