first commit

Dependencies:   C12832_lcd DigiLogger LM75B XBeeLib2 mbed

Fork of XBee802_Send_Data by Digi International Inc.

Committer:
hbujanda
Date:
Wed Apr 29 17:58:22 2015 +0200
Revision:
0:a8cde1e2de5b
Child:
2:60581ca6978e
Automatic upload

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hbujanda 0:a8cde1e2de5b 1 /**
hbujanda 0:a8cde1e2de5b 2 * Copyright (c) 2015 Digi International Inc.,
hbujanda 0:a8cde1e2de5b 3 * All rights not expressly granted are reserved.
hbujanda 0:a8cde1e2de5b 4 *
hbujanda 0:a8cde1e2de5b 5 * This Source Code Form is subject to the terms of the Mozilla Public
hbujanda 0:a8cde1e2de5b 6 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
hbujanda 0:a8cde1e2de5b 7 * You can obtain one at http://mozilla.org/MPL/2.0/.
hbujanda 0:a8cde1e2de5b 8 *
hbujanda 0:a8cde1e2de5b 9 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
hbujanda 0:a8cde1e2de5b 10 * =======================================================================
hbujanda 0:a8cde1e2de5b 11 */
hbujanda 0:a8cde1e2de5b 12
hbujanda 0:a8cde1e2de5b 13 #include "mbed.h"
hbujanda 0:a8cde1e2de5b 14 #include "XBeeLib.h"
hbujanda 0:a8cde1e2de5b 15 #if defined(ENABLE_LOGGING)
hbujanda 0:a8cde1e2de5b 16 #include "DigiLoggerMbedSerial.h"
hbujanda 0:a8cde1e2de5b 17 using namespace DigiLog;
hbujanda 0:a8cde1e2de5b 18 #endif
hbujanda 0:a8cde1e2de5b 19
hbujanda 0:a8cde1e2de5b 20 // TODO Replace with the MSB of the remote module's 64-bit address (SH parameter)
hbujanda 0:a8cde1e2de5b 21 #define REMOTE_NODE_ADDR64_MSB ((uint32_t)0x0013A200)
hbujanda 0:a8cde1e2de5b 22 // TODO Replace with the LSB of the remote module's 64-bit address (SL parameter)
hbujanda 0:a8cde1e2de5b 23 #define REMOTE_NODE_ADDR64_LSB ((uint32_t)0x40D2B03E)
hbujanda 0:a8cde1e2de5b 24 // TODO Replace with the remote module's 16-bit address (MY parameter)
hbujanda 0:a8cde1e2de5b 25 #define REMOTE_NODE_ADDR16 ((uint16_t)0x1111)
hbujanda 0:a8cde1e2de5b 26
hbujanda 0:a8cde1e2de5b 27 using namespace XBeeLib;
hbujanda 0:a8cde1e2de5b 28
hbujanda 0:a8cde1e2de5b 29 Serial *log_serial;
hbujanda 0:a8cde1e2de5b 30
hbujanda 0:a8cde1e2de5b 31 static void send_broadcast_data(XBee802& xbee)
hbujanda 0:a8cde1e2de5b 32 {
hbujanda 0:a8cde1e2de5b 33 const char data[] = "send_broadcast_data";
hbujanda 0:a8cde1e2de5b 34 const uint16_t data_len = strlen(data);
hbujanda 0:a8cde1e2de5b 35
hbujanda 0:a8cde1e2de5b 36 const TxStatus txStatus = xbee.send_data_broadcast((const uint8_t *)data, data_len);
hbujanda 0:a8cde1e2de5b 37
hbujanda 0:a8cde1e2de5b 38 if (txStatus == TxStatusSuccess)
hbujanda 0:a8cde1e2de5b 39 log_serial->printf("send_broadcast_data OK\r\n");
hbujanda 0:a8cde1e2de5b 40 else
hbujanda 0:a8cde1e2de5b 41 log_serial->printf("send_broadcast_data failed with %d\r\n", (int) txStatus);
hbujanda 0:a8cde1e2de5b 42 }
hbujanda 0:a8cde1e2de5b 43
hbujanda 0:a8cde1e2de5b 44 static void send_data_to_remote_node(XBee802& xbee, const RemoteXBee802& RemoteDevice)
hbujanda 0:a8cde1e2de5b 45 {
hbujanda 0:a8cde1e2de5b 46 const char data[] = "send_data_to_remote_node";
hbujanda 0:a8cde1e2de5b 47 const uint16_t data_len = strlen(data);
hbujanda 0:a8cde1e2de5b 48
hbujanda 0:a8cde1e2de5b 49 const TxStatus txStatus = xbee.send_data(RemoteDevice, (const uint8_t *)data, data_len);
hbujanda 0:a8cde1e2de5b 50
hbujanda 0:a8cde1e2de5b 51 if (txStatus == TxStatusSuccess)
hbujanda 0:a8cde1e2de5b 52 log_serial->printf("send_data_to_remote_node OK\r\n");
hbujanda 0:a8cde1e2de5b 53 else
hbujanda 0:a8cde1e2de5b 54 log_serial->printf("send_data_to_remote_node failed with %d\r\n", (int) txStatus);
hbujanda 0:a8cde1e2de5b 55 }
hbujanda 0:a8cde1e2de5b 56
hbujanda 0:a8cde1e2de5b 57 int main()
hbujanda 0:a8cde1e2de5b 58 {
hbujanda 0:a8cde1e2de5b 59 log_serial = new Serial(DEBUG_TX, DEBUG_RX);
hbujanda 0:a8cde1e2de5b 60 log_serial->baud(9600);
hbujanda 0:a8cde1e2de5b 61 log_serial->printf("Sample application to demo how to send unicast and broadcast data with the XBee802\r\n\r\n");
hbujanda 0:a8cde1e2de5b 62 log_serial->printf(XB_LIB_BANNER);
hbujanda 0:a8cde1e2de5b 63
hbujanda 0:a8cde1e2de5b 64 #if defined(ENABLE_LOGGING)
hbujanda 0:a8cde1e2de5b 65 new DigiLoggerMbedSerial(log_serial, LogLevelInfo);
hbujanda 0:a8cde1e2de5b 66 #endif
hbujanda 0:a8cde1e2de5b 67
hbujanda 0:a8cde1e2de5b 68 XBee802 xbee = XBee802(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600);
hbujanda 0:a8cde1e2de5b 69
hbujanda 0:a8cde1e2de5b 70 RadioStatus radioStatus = xbee.init();
hbujanda 0:a8cde1e2de5b 71 MBED_ASSERT(radioStatus == Success);
hbujanda 0:a8cde1e2de5b 72
hbujanda 0:a8cde1e2de5b 73 const RemoteXBee802 remoteDevice64b = RemoteXBee802(Addr64(REMOTE_NODE_ADDR64_MSB, REMOTE_NODE_ADDR64_LSB));
hbujanda 0:a8cde1e2de5b 74 const RemoteXBee802 remoteDevice16b = RemoteXBee802(REMOTE_NODE_ADDR16);
hbujanda 0:a8cde1e2de5b 75
hbujanda 0:a8cde1e2de5b 76 send_broadcast_data(xbee);
hbujanda 0:a8cde1e2de5b 77 send_data_to_remote_node(xbee, remoteDevice64b);
hbujanda 0:a8cde1e2de5b 78 send_data_to_remote_node(xbee, remoteDevice16b);
hbujanda 0:a8cde1e2de5b 79
hbujanda 0:a8cde1e2de5b 80 delete(log_serial);
hbujanda 0:a8cde1e2de5b 81 }