first commit

Dependencies:   C12832_lcd DigiLogger LM75B XBeeLib2 mbed

Fork of XBee802_Send_Data by Digi International Inc.

Revision:
5:1b2d489605b1
Child:
7:ab86cae2e208
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu May 14 16:22:41 2015 +0200
@@ -0,0 +1,83 @@
+/**
+ * Copyright (c) 2015 Digi International Inc.,
+ * All rights not expressly granted are reserved.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
+ * =======================================================================
+ */
+
+#include "mbed.h"
+#include "XBeeLib.h"
+#if defined(ENABLE_LOGGING)
+#include "DigiLoggerMbedSerial.h"
+using namespace DigiLog;
+#endif
+
+// TODO Replace with the MSB of the remote module's 64-bit address (SH parameter)
+#define REMOTE_NODE_ADDR64_MSB  ((uint32_t)0x0013A200)
+// TODO Replace with the LSB of the remote module's 64-bit address (SL parameter)
+#define REMOTE_NODE_ADDR64_LSB  ((uint32_t)0x40D2B03E)
+// TODO Replace with the remote module's 16-bit address (MY parameter)
+#define REMOTE_NODE_ADDR16      ((uint16_t)0x1111)
+
+#define REMOTE_NODE_ADDR64      UINT64(REMOTE_NODE_ADDR64_MSB, REMOTE_NODE_ADDR64_LSB)
+
+using namespace XBeeLib;
+
+Serial *log_serial;
+
+static void send_broadcast_data(XBee802& xbee)
+{
+    const char data[] = "send_broadcast_data";
+    const uint16_t data_len = strlen(data);
+
+    const TxStatus txStatus = xbee.send_data_broadcast((const uint8_t *)data, data_len);
+
+    if (txStatus == TxStatusSuccess)
+        log_serial->printf("send_broadcast_data OK\r\n");
+    else
+        log_serial->printf("send_broadcast_data failed with %d\r\n", (int) txStatus);
+}
+
+static void send_data_to_remote_node(XBee802& xbee, const RemoteXBee802& RemoteDevice)
+{
+    const char data[] = "send_data_to_remote_node";
+    const uint16_t data_len = strlen(data);
+
+    const TxStatus txStatus = xbee.send_data(RemoteDevice, (const uint8_t *)data, data_len);
+
+    if (txStatus == TxStatusSuccess)
+        log_serial->printf("send_data_to_remote_node OK\r\n");
+    else
+        log_serial->printf("send_data_to_remote_node failed with %d\r\n", (int) txStatus);
+}
+
+int main()
+{
+    log_serial = new Serial(DEBUG_TX, DEBUG_RX);
+    log_serial->baud(9600);
+    log_serial->printf("Sample application to demo how to send unicast and broadcast data with the XBee802\r\n\r\n");
+    log_serial->printf(XB_LIB_BANNER);
+
+#if defined(ENABLE_LOGGING)
+    new DigiLoggerMbedSerial(log_serial, LogLevelInfo);
+#endif
+
+    XBee802 xbee = XBee802(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600);
+
+    RadioStatus radioStatus = xbee.init();
+    MBED_ASSERT(radioStatus == Success);
+
+    const RemoteXBee802 remoteDevice64b = RemoteXBee802(REMOTE_NODE_ADDR64);
+    const RemoteXBee802 remoteDevice16b = RemoteXBee802(REMOTE_NODE_ADDR16);
+
+    send_broadcast_data(xbee);
+    send_data_to_remote_node(xbee, remoteDevice64b);
+    send_data_to_remote_node(xbee, remoteDevice16b);
+
+    delete(log_serial);
+}