MBED code for Xbee module running on solar car

Dependencies:   XBeeLib mbed CUER_CAN

Fork of XBee802_Send_Data by Digi International Inc.

Committer:
hbujanda
Date:
Thu May 14 16:22:41 2015 +0200
Revision:
5:1b2d489605b1
Child:
7:ab86cae2e208
Automatic upload

Who changed what in which revision?

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