Digi International Inc. / Mbed 2 deprecated XBeeDM_AT_Commands

Dependencies:   XBeeLib mbed

Fork of XBeeZB_AT_Commands by Digi International Inc.

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /**
00002  * Copyright (c) 2015 Digi International Inc.,
00003  * All rights not expressly granted are reserved.
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
00007  * You can obtain one at http://mozilla.org/MPL/2.0/.
00008  *
00009  * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
00010  * =======================================================================
00011  */
00012 
00013 #include "mbed.h"
00014 #include "XBeeLib.h"
00015 #if defined(ENABLE_LOGGING)
00016 #include "DigiLoggerMbedSerial.h"
00017 using namespace DigiLog;
00018 #endif
00019 
00020 #define REMOTE_NODE_ADDR64_MSB  ((uint32_t)0x0013A200)
00021 
00022 #error "Replace next define with the LSB of the remote module's 64-bit address (SL parameter)"
00023 #define REMOTE_NODE_ADDR64_LSB  ((uint32_t)0x01234567)
00024 
00025 #define REMOTE_NODE_ADDR64      UINT64(REMOTE_NODE_ADDR64_MSB, REMOTE_NODE_ADDR64_LSB)
00026 
00027 using namespace XBeeLib;
00028 
00029 Serial *log_serial;
00030 
00031 int main()
00032 {
00033     log_serial = new Serial(DEBUG_TX, DEBUG_RX);
00034     log_serial->baud(9600);
00035     log_serial->printf("Sample application to demo how to read and set local and remote AT parameters with XBeeDM\r\n\r\n");
00036     log_serial->printf(XB_LIB_BANNER);
00037 
00038 #if defined(ENABLE_LOGGING)
00039     new DigiLoggerMbedSerial(log_serial, LogLevelInfo);
00040 #endif
00041 
00042     XBeeDM xbee = XBeeDM(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600);
00043 
00044     RadioStatus radioStatus = xbee.init();
00045     MBED_ASSERT(radioStatus == Success);
00046 
00047     AtCmdFrame::AtCmdResp cmdresp;
00048 
00049     uint32_t value;
00050 
00051     /* Read local device SL parameter */
00052     log_serial->printf("\r\nReading local device SL parameter:\r\n");
00053     cmdresp = xbee.get_param("SL", &value);
00054     if (cmdresp == AtCmdFrame::AtCmdRespOk) {
00055         log_serial->printf("OK. Local SL=%08x\r\n", value);
00056 
00057         /* Get the local device 64 bit address to compare */
00058         const uint64_t LocalDeviceAddr64 = xbee.get_addr64();
00059         MBED_ASSERT(value == (LocalDeviceAddr64 & 0xFFFFFFFF));
00060     } else {
00061         log_serial->printf("FAILED with %d\r\n", (int) cmdresp);
00062     }
00063 
00064     /* Set local device NI parameter */
00065     char ni_local[] = "ni_example_local";
00066     log_serial->printf("\r\nSetting local device NI parameter to '%s':\r\n", ni_local);
00067     cmdresp = xbee.set_param("NI", (uint8_t*)ni_local, strlen(ni_local));
00068     if (cmdresp == AtCmdFrame::AtCmdRespOk) {
00069         log_serial->printf("OK\r\n");
00070     } else {
00071         log_serial->printf("FAILED with %d\r\n", (int) cmdresp);
00072     }
00073 
00074     const RemoteXBeeDM remoteDevice = RemoteXBeeDM(REMOTE_NODE_ADDR64);
00075 
00076     /* Read remote device SL parameter */
00077     log_serial->printf("\r\nReading remote device SL parameter:\r\n");
00078     cmdresp = xbee.get_param(remoteDevice, "SL", &value);
00079     if (cmdresp == AtCmdFrame::AtCmdRespOk) {
00080         log_serial->printf("OK. Remote SL=%08x\r\n", value);
00081         MBED_ASSERT(value == REMOTE_NODE_ADDR64_LSB);
00082     } else {
00083         log_serial->printf("FAILED with %d\r\n", (int) cmdresp);
00084     }
00085 
00086     /* Set remote device NI parameter */
00087     char ni_remote[] = "ni_example_remote";
00088     log_serial->printf("\r\nSetting remote device NI parameter to '%s':\r\n", ni_remote);
00089     cmdresp = xbee.set_param(remoteDevice, "NI", (uint8_t*)ni_remote, strlen(ni_remote));
00090     if (cmdresp == AtCmdFrame::AtCmdRespOk) {
00091         log_serial->printf("OK\r\n");
00092     } else {
00093         log_serial->printf("FAILED with %d\r\n", (int) cmdresp);
00094     }
00095 
00096     delete(log_serial);
00097 }