Library to easily communicate with XBee modules.

Dependencies:   DigiLogger

Dependents:   WaterLogger XbeeGateway XBee_Cooker ProjetReceiver ... more

Use XBee radio modules to easily improve your project with wireless connectivity. You can enable entire networks of connected devices. XBees can exchange data with other modules in the network and configure remote modules as well as trigger actions or collect sensor data on XBee nodes without needing additional external microcontrollers. Using this documentation and configuration tools with XBee modules, it is easy to develop these types of applications and more.

/media/uploads/spastor/xbee-xbeepro-series1.jpg

The XBee mbed Library is a ready-to-import mbed extension that dramatically reduces development time for XBee projects on the mbed platforms. There are many modular examples, making it an easy and smooth process to add wireless networking to a whole range of useful applications.

Info

Currently 802.15.4 (Series 1 and 2), ZigBee (Series 2) and DigiMesh (Series 1 and 2) modules are supported. The libraries can be extended to support other protocols like DigiMesh point-to-point, WiFi, etc.

User manual

The user manual can be found at this project's Wiki pages:

  1. Configuring the library
  2. Debugging the library
  3. Initializing modules
  4. Resetting the local module
  5. Receiving Data from other module
  6. Sending data to another module
  7. Discovering nodes in the network
  8. Configuring local and remote modules
  9. Handling modem status changes
  10. Handling remote modules DIOs, ADCs and PWMs
  11. Handling IO Data Samples from other module
  12. Radio Power Management

Ready to use examples

There are a lot of ready to use examples to get started quickly.
Make sure you have a valid example setup before running the examples:

Examples for ZigBee modules

Import programXBeeZB_Receive_Data

ZigBee Receive Data example for mbed XBeeLib By Digi

Import programXBeeZB_Send_Data

ZigBee Send Data example for mbed XBeeLib By Digi

Import programXBeeZB_module_config

ZigBee network configuration example for mbed XBeeLib By Digi

Import programXBeeZB_AT_Commands

ZigBee AT Commands example for mbed XBeeLib By Digi

Import programXBeeZB_dio_adc

ZigBee DIOs and ADCs example for mbed XBeeLib By Digi

Import programXBeeZB_IO_Sample_Callback

ZigBee IO Sampling Callback example for mbed XBeeLib By Digi

Import programXBeeZB_modem_status

ZigBee Modem Status example for mbed XBeeLib By Digi

Import programXBeeZB_node_discovery

ZigBee Node Discovery example for mbed XBeeLib By Digi

Import programXBeeZB_power_mngmnt_cyclic_sleep

ZigBee Power Management using Cyclic Sleep example for mbed XBeeLib By Digi

Import programXBeeZB_power_mngmnt_pin_sleep

ZigBee Power Management using Pin Sleep example for mbed XBeeLib By Digi

Examples for 802.15.4 modules

Import programXBee802_Receive_Data

802.15.4 Receive Data example for mbed XBeeLib By Digi

Import programXBee802_Send_Data

802.15.4 Send Data example for mbed XBeeLib By Digi

Import programXBee802_module_config

802.15.4 network configuration example for mbed XBeeLib By Digi

Import programXBee802_AT_Commands

802.15.4 AT Commands example for mbed XBeeLib By Digi

Import programXBee802_dio_adc_pwm

802.15.4 DIOs, ADCs and PWM example for mbed XBeeLib By Digi

Import programXBee802_IO_Sample_Callback

802.15.4 IO Sampling Callback example for mbed XBeeLib By Digi

Import programXBee802_node_discovery

802.15.4 Node Discovery example for mbed XBeeLib By Digi

Import programXBee802_power_mngmnt_cyclic_sleep

802.15.4 Power Management using Cyclic Sleep example for mbed XBeeLib By Digi

Import programXBee802_power_mngmnt_pin_sleep

802.15.4 Power Management using Pin Sleep example for mbed XBeeLib By Digi

Examples for DigiMesh modules

Import programXBeeDM_Receive_Data

DigiMesh Receive Data example for mbed XBeeLib By Digi

Import programXBeeDM_Send_Data

DigiMesh Send Data example for mbed XBeeLib By Digi

Import programXBeeDM_module_config

DigiMesh network configuration example for mbed XBeeLib By Digi

Import programXBeeDM_AT_Commands

DigiMesh AT Commands example for mbed XBeeLib By Digi

Import programXBeeDM_dio_adc_pwm

DigiMEsh DIOs, ADCs and PWMs example for mbed XBeeLib By Digi

Import programXBeeDM_IO_Sample_Callback

DigiMesh IO Sampling Callback example for mbed XBeeLib By Digi

Import programXBeeDM_modem_status

DigiMesh Modem Status example for mbed XBeeLib By Digi

Import programXBeeDM_node_discovery

DigiMesh Node Discovery example for mbed XBeeLib By Digi

Import programXBeeDM_power_mngmnt_asyncr_cyclic_sleep

DigiMesh Power Management using Asynchronous Cyclic Sleep example for mbed XBeeLib By Digi

Import programXBeeDM_power_mngmnt_pin_sleep

DigiMesh Power Management using Pin Sleep example for mbed XBeeLib By Digi

Committer:
spastor
Date:
Mon May 18 13:16:55 2015 +0200
Revision:
3:8662ebe83570
Parent:
2:2ee1b6d51df2
Child:
4:629712865107
Automatic upload

Who changed what in which revision?

UserRevisionLine numberNew contents of line
spastor 0:fcaad0dfa051 1 /**
spastor 0:fcaad0dfa051 2 * Copyright (c) 2015 Digi International Inc.,
spastor 0:fcaad0dfa051 3 * All rights not expressly granted are reserved.
spastor 0:fcaad0dfa051 4 *
spastor 0:fcaad0dfa051 5 * This Source Code Form is subject to the terms of the Mozilla Public
spastor 0:fcaad0dfa051 6 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
spastor 0:fcaad0dfa051 7 * You can obtain one at http://mozilla.org/MPL/2.0/.
spastor 0:fcaad0dfa051 8 *
spastor 0:fcaad0dfa051 9 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
spastor 0:fcaad0dfa051 10 * =======================================================================
spastor 0:fcaad0dfa051 11 */
spastor 0:fcaad0dfa051 12
spastor 0:fcaad0dfa051 13 #include "XBeeLib.h"
spastor 0:fcaad0dfa051 14 #include "Frames/ApiFrame.h"
spastor 0:fcaad0dfa051 15
spastor 0:fcaad0dfa051 16 using namespace XBeeLib;
spastor 0:fcaad0dfa051 17
spastor 0:fcaad0dfa051 18 RadioStatus XBee::write_config(void)
spastor 0:fcaad0dfa051 19 {
spastor 0:fcaad0dfa051 20 AtCmdFrame::AtCmdResp cmdresp;
spastor 0:fcaad0dfa051 21
spastor 0:fcaad0dfa051 22 cmdresp = set_param("WR");
spastor 0:fcaad0dfa051 23 if (cmdresp != AtCmdFrame::AtCmdRespOk) {
spastor 0:fcaad0dfa051 24 return Failure;
spastor 0:fcaad0dfa051 25 }
spastor 0:fcaad0dfa051 26 return Success;
spastor 0:fcaad0dfa051 27 }
spastor 0:fcaad0dfa051 28
spastor 0:fcaad0dfa051 29 RadioStatus XBee::sleep_now(void)
spastor 0:fcaad0dfa051 30 {
spastor 0:fcaad0dfa051 31 AtCmdFrame::AtCmdResp cmdresp;
spastor 0:fcaad0dfa051 32
spastor 0:fcaad0dfa051 33 cmdresp = set_param("SI");
spastor 0:fcaad0dfa051 34 if (cmdresp != AtCmdFrame::AtCmdRespOk) {
spastor 0:fcaad0dfa051 35 return Failure;
spastor 0:fcaad0dfa051 36 }
spastor 0:fcaad0dfa051 37 return Success;
spastor 0:fcaad0dfa051 38 }
spastor 0:fcaad0dfa051 39
spastor 0:fcaad0dfa051 40 RadioStatus XBee::set_power_level(uint8_t level)
spastor 0:fcaad0dfa051 41 {
spastor 0:fcaad0dfa051 42 AtCmdFrame::AtCmdResp cmdresp;
spastor 0:fcaad0dfa051 43
spastor 0:fcaad0dfa051 44 if (level > 4) {
spastor 0:fcaad0dfa051 45 return Failure;
spastor 0:fcaad0dfa051 46 }
spastor 0:fcaad0dfa051 47
spastor 0:fcaad0dfa051 48 cmdresp = set_param("PL", level);
spastor 0:fcaad0dfa051 49 if (cmdresp != AtCmdFrame::AtCmdRespOk) {
spastor 0:fcaad0dfa051 50 return Failure;
spastor 0:fcaad0dfa051 51 }
spastor 0:fcaad0dfa051 52
spastor 0:fcaad0dfa051 53 return Success;
spastor 0:fcaad0dfa051 54 }
spastor 0:fcaad0dfa051 55
spastor 0:fcaad0dfa051 56 RadioStatus XBee::get_power_level(uint8_t * const level)
spastor 0:fcaad0dfa051 57 {
spastor 0:fcaad0dfa051 58 if (level == NULL) {
spastor 0:fcaad0dfa051 59 return Failure;
spastor 0:fcaad0dfa051 60 }
spastor 0:fcaad0dfa051 61 AtCmdFrame::AtCmdResp cmdresp;
spastor 0:fcaad0dfa051 62
spastor 0:fcaad0dfa051 63 uint32_t var32;
spastor 0:fcaad0dfa051 64 cmdresp = get_param("PL", &var32);
spastor 0:fcaad0dfa051 65 if (cmdresp != AtCmdFrame::AtCmdRespOk) {
spastor 0:fcaad0dfa051 66 return Failure;
spastor 0:fcaad0dfa051 67 }
spastor 0:fcaad0dfa051 68 *level = var32;
spastor 0:fcaad0dfa051 69 return Success;
spastor 0:fcaad0dfa051 70 }
spastor 0:fcaad0dfa051 71
spastor 0:fcaad0dfa051 72 RadioStatus XBee::get_network_address(uint16_t * const addr16)
spastor 0:fcaad0dfa051 73 {
spastor 0:fcaad0dfa051 74 if (addr16 == NULL) {
spastor 0:fcaad0dfa051 75 return Failure;
spastor 0:fcaad0dfa051 76 }
spastor 0:fcaad0dfa051 77 AtCmdFrame::AtCmdResp cmdresp;
spastor 0:fcaad0dfa051 78
spastor 0:fcaad0dfa051 79 uint32_t var32;
spastor 0:fcaad0dfa051 80 cmdresp = get_param("MY", &var32);
spastor 0:fcaad0dfa051 81 if (cmdresp != AtCmdFrame::AtCmdRespOk) {
spastor 0:fcaad0dfa051 82 return Failure;
spastor 0:fcaad0dfa051 83 }
spastor 0:fcaad0dfa051 84 *addr16 = var32;
spastor 0:fcaad0dfa051 85 return Success;
spastor 0:fcaad0dfa051 86 }
spastor 0:fcaad0dfa051 87
spastor 0:fcaad0dfa051 88 RadioStatus XBee::software_reset(void)
spastor 0:fcaad0dfa051 89 {
spastor 0:fcaad0dfa051 90 volatile uint16_t * const rst_cnt_p = &_wd_reset_cnt;
spastor 0:fcaad0dfa051 91 const uint16_t init_rst_cnt = *rst_cnt_p;
spastor 0:fcaad0dfa051 92
spastor 0:fcaad0dfa051 93 AtCmdFrame::AtCmdResp cmdresp;
spastor 0:fcaad0dfa051 94
spastor 0:fcaad0dfa051 95 cmdresp = set_param("FR");
spastor 0:fcaad0dfa051 96 if (cmdresp != AtCmdFrame::AtCmdRespOk) {
hbujanda 1:794d1d3e4a08 97 digi_log(LogLevelError, "software_reset failed!\r\n");
spastor 0:fcaad0dfa051 98 return Failure;
spastor 0:fcaad0dfa051 99 }
spastor 0:fcaad0dfa051 100
spastor 0:fcaad0dfa051 101 return wait_for_module_to_reset(rst_cnt_p, init_rst_cnt);
spastor 0:fcaad0dfa051 102 }
spastor 0:fcaad0dfa051 103
spastor 0:fcaad0dfa051 104 RadioStatus XBee::set_node_identifier(const char * const node_id)
spastor 0:fcaad0dfa051 105 {
spastor 0:fcaad0dfa051 106 if (node_id == NULL) {
spastor 0:fcaad0dfa051 107 return Failure;
spastor 0:fcaad0dfa051 108 }
spastor 0:fcaad0dfa051 109
spastor 0:fcaad0dfa051 110 AtCmdFrame::AtCmdResp cmdresp;
spastor 0:fcaad0dfa051 111 const size_t str_len = strlen(node_id);
spastor 0:fcaad0dfa051 112
spastor 0:fcaad0dfa051 113 if(str_len > 20 || str_len < 1) {
spastor 0:fcaad0dfa051 114 return Failure;
spastor 0:fcaad0dfa051 115 }
spastor 0:fcaad0dfa051 116
spastor 0:fcaad0dfa051 117 cmdresp = set_param("NI", (const uint8_t *)node_id, str_len);
spastor 0:fcaad0dfa051 118 if (cmdresp != AtCmdFrame::AtCmdRespOk) {
spastor 0:fcaad0dfa051 119 return Failure;
spastor 0:fcaad0dfa051 120 }
spastor 0:fcaad0dfa051 121 return Success;
spastor 0:fcaad0dfa051 122 }
spastor 0:fcaad0dfa051 123
spastor 0:fcaad0dfa051 124 RadioStatus XBee::get_node_identifier(char * const node_id)
spastor 0:fcaad0dfa051 125 {
spastor 0:fcaad0dfa051 126 if (node_id == NULL) {
spastor 0:fcaad0dfa051 127 return Failure;
spastor 0:fcaad0dfa051 128 }
spastor 0:fcaad0dfa051 129
spastor 0:fcaad0dfa051 130 uint16_t max_ni_length = 20;
spastor 0:fcaad0dfa051 131 AtCmdFrame::AtCmdResp cmdresp;
spastor 0:fcaad0dfa051 132
spastor 0:fcaad0dfa051 133 cmdresp = get_param("NI", (uint8_t *)node_id, &max_ni_length);
spastor 0:fcaad0dfa051 134 if (cmdresp != AtCmdFrame::AtCmdRespOk) {
spastor 0:fcaad0dfa051 135 return Failure;
spastor 0:fcaad0dfa051 136 }
spastor 0:fcaad0dfa051 137 node_id[max_ni_length] = '\0';
spastor 0:fcaad0dfa051 138 return Success;
spastor 0:fcaad0dfa051 139 }
spastor 0:fcaad0dfa051 140
spastor 0:fcaad0dfa051 141 uint16_t XBee::get_hw_version() const
spastor 0:fcaad0dfa051 142 {
spastor 0:fcaad0dfa051 143 return _hw_version;
spastor 0:fcaad0dfa051 144 }
spastor 0:fcaad0dfa051 145
spastor 0:fcaad0dfa051 146 uint16_t XBee::get_fw_version() const
spastor 0:fcaad0dfa051 147 {
spastor 0:fcaad0dfa051 148 return _fw_version;
spastor 0:fcaad0dfa051 149 }
spastor 0:fcaad0dfa051 150
spastor 0:fcaad0dfa051 151 void XBee::set_tx_options(uint8_t options)
spastor 0:fcaad0dfa051 152 {
spastor 0:fcaad0dfa051 153 _tx_options = options;
spastor 0:fcaad0dfa051 154 }
spastor 0:fcaad0dfa051 155
spastor 0:fcaad0dfa051 156 uint8_t XBee::get_tx_options() const
spastor 0:fcaad0dfa051 157 {
spastor 0:fcaad0dfa051 158 return _tx_options;
spastor 0:fcaad0dfa051 159 }
spastor 0:fcaad0dfa051 160
spastor 0:fcaad0dfa051 161 void XBee::set_broadcast_radius(uint8_t bc_radius)
spastor 0:fcaad0dfa051 162 {
spastor 0:fcaad0dfa051 163 _bc_radius = bc_radius;
spastor 0:fcaad0dfa051 164 }
spastor 0:fcaad0dfa051 165
spastor 0:fcaad0dfa051 166 uint8_t XBee::get_bc_radius() const
spastor 0:fcaad0dfa051 167 {
spastor 0:fcaad0dfa051 168 return _bc_radius;
spastor 0:fcaad0dfa051 169 }
spastor 0:fcaad0dfa051 170
spastor 0:fcaad0dfa051 171 RadioStatus XBee::start_node_discovery()
spastor 0:fcaad0dfa051 172 {
spastor 0:fcaad0dfa051 173 AtCmdFrame cmd_frame = AtCmdFrame("ND");
spastor 0:fcaad0dfa051 174 send_api_frame(&cmd_frame);
spastor 0:fcaad0dfa051 175
spastor 0:fcaad0dfa051 176 return Success;
spastor 0:fcaad0dfa051 177 }
spastor 0:fcaad0dfa051 178
hbujanda 2:2ee1b6d51df2 179 void XBee::_get_remote_node_by_id(const char * const node_id, uint64_t * const addr64, uint16_t * const addr16)
hbujanda 2:2ee1b6d51df2 180 {
hbujanda 2:2ee1b6d51df2 181 *addr64 = ADDR64_UNASSIGNED;
hbujanda 2:2ee1b6d51df2 182 *addr16 = ADDR16_UNKNOWN;
hbujanda 2:2ee1b6d51df2 183 if (node_id == NULL) {
hbujanda 2:2ee1b6d51df2 184 return;
hbujanda 2:2ee1b6d51df2 185 }
hbujanda 2:2ee1b6d51df2 186 const size_t node_id_len = strlen(node_id);
hbujanda 2:2ee1b6d51df2 187 if (node_id_len == 0 || node_id_len > MAX_NI_PARAM_LEN) {
hbujanda 2:2ee1b6d51df2 188 return;
hbujanda 2:2ee1b6d51df2 189 }
hbujanda 2:2ee1b6d51df2 190
hbujanda 2:2ee1b6d51df2 191 const uint16_t old_timeout = _timeout_ms;
hbujanda 2:2ee1b6d51df2 192
hbujanda 2:2ee1b6d51df2 193 uint32_t nd_timeout_100msec;
hbujanda 2:2ee1b6d51df2 194 const AtCmdFrame::AtCmdResp nt_resp = get_param("NT", &nd_timeout_100msec);
hbujanda 2:2ee1b6d51df2 195 if (nt_resp != AtCmdFrame::AtCmdRespOk) {
hbujanda 2:2ee1b6d51df2 196 _timeout_ms = 10000;
hbujanda 2:2ee1b6d51df2 197 } else {
hbujanda 2:2ee1b6d51df2 198 _timeout_ms = (uint16_t)nd_timeout_100msec * 100 + 1000;
hbujanda 2:2ee1b6d51df2 199 }
hbujanda 2:2ee1b6d51df2 200
hbujanda 2:2ee1b6d51df2 201 const AtCmdFrame::AtCmdResp cmdresp = set_param("ND", (const uint8_t *)node_id, strlen(node_id));
hbujanda 2:2ee1b6d51df2 202 if (cmdresp != AtCmdFrame::AtCmdRespOk) {
hbujanda 2:2ee1b6d51df2 203 _timeout_ms = old_timeout;
hbujanda 2:2ee1b6d51df2 204 return;
hbujanda 2:2ee1b6d51df2 205 }
hbujanda 2:2ee1b6d51df2 206
hbujanda 2:2ee1b6d51df2 207 const int nd_start_time = _timer.read_ms();
hbujanda 2:2ee1b6d51df2 208 const int nd_end_time = nd_start_time + _timeout_ms;
hbujanda 2:2ee1b6d51df2 209
hbujanda 2:2ee1b6d51df2 210 AtCmdFrame atnd_frame = AtCmdFrame("ND", (const uint8_t *)node_id, strlen(node_id));
hbujanda 2:2ee1b6d51df2 211 send_api_frame(&atnd_frame);
hbujanda 2:2ee1b6d51df2 212
hbujanda 2:2ee1b6d51df2 213 ApiFrame * const resp_frame = get_this_api_frame(atnd_frame.get_frame_id(), ApiFrame::AtCmdResp);
hbujanda 2:2ee1b6d51df2 214 _timeout_ms = old_timeout;
hbujanda 2:2ee1b6d51df2 215
hbujanda 2:2ee1b6d51df2 216 while (_timer.read_ms() < nd_end_time) {
hbujanda 2:2ee1b6d51df2 217 wait_ms(10);
hbujanda 2:2ee1b6d51df2 218 }
hbujanda 2:2ee1b6d51df2 219
hbujanda 2:2ee1b6d51df2 220 if (resp_frame == NULL) {
hbujanda 2:2ee1b6d51df2 221 digi_log(LogLevelWarning, "XBeeZB::get_remote_node_by_id timeout when waiting for ATND response");
hbujanda 2:2ee1b6d51df2 222 return;
hbujanda 2:2ee1b6d51df2 223 }
hbujanda 2:2ee1b6d51df2 224
hbujanda 2:2ee1b6d51df2 225 const AtCmdFrame::AtCmdResp resp = (AtCmdFrame::AtCmdResp)resp_frame->get_data_at(ATCMD_RESP_STATUS_OFFSET);
hbujanda 2:2ee1b6d51df2 226 if (resp != AtCmdFrame::AtCmdRespOk) {
hbujanda 2:2ee1b6d51df2 227 digi_log(LogLevelWarning, "send_at_cmd bad response: 0x%x\r\n", resp);
hbujanda 2:2ee1b6d51df2 228 _framebuf.free_frame(resp_frame);
hbujanda 2:2ee1b6d51df2 229 return;
hbujanda 2:2ee1b6d51df2 230 }
hbujanda 2:2ee1b6d51df2 231
hbujanda 2:2ee1b6d51df2 232 rmemcpy((uint8_t *)addr16, resp_frame->get_data() + ATCMD_RESP_DATA_OFFSET, sizeof *addr16);
hbujanda 2:2ee1b6d51df2 233 rmemcpy((uint8_t *)addr64, resp_frame->get_data() + ATCMD_RESP_DATA_OFFSET + sizeof *addr16, sizeof *addr64);
hbujanda 2:2ee1b6d51df2 234 _framebuf.free_frame(resp_frame);
hbujanda 2:2ee1b6d51df2 235 return;
hbujanda 2:2ee1b6d51df2 236 }
hbujanda 2:2ee1b6d51df2 237
spastor 0:fcaad0dfa051 238 RadioStatus XBee::config_node_discovery(uint16_t timeout_ms, uint8_t options)
spastor 0:fcaad0dfa051 239 {
spastor 0:fcaad0dfa051 240 AtCmdFrame::AtCmdResp cmdresp;
spastor 0:fcaad0dfa051 241
spastor 0:fcaad0dfa051 242 cmdresp = set_param("NT", (uint8_t)(timeout_ms / 100));
spastor 0:fcaad0dfa051 243 if (cmdresp != AtCmdFrame::AtCmdRespOk) {
spastor 0:fcaad0dfa051 244 return Failure;
spastor 0:fcaad0dfa051 245 }
spastor 0:fcaad0dfa051 246
spastor 0:fcaad0dfa051 247 cmdresp = set_param("NO", (uint8_t)options);
spastor 0:fcaad0dfa051 248 if (cmdresp != AtCmdFrame::AtCmdRespOk) {
spastor 0:fcaad0dfa051 249 return Failure;
spastor 0:fcaad0dfa051 250 }
spastor 0:fcaad0dfa051 251 cmdresp = set_param("AC");
spastor 0:fcaad0dfa051 252 if (cmdresp != AtCmdFrame::AtCmdRespOk) {
spastor 0:fcaad0dfa051 253 return Failure;
spastor 0:fcaad0dfa051 254 }
spastor 0:fcaad0dfa051 255
spastor 0:fcaad0dfa051 256 return Success;
spastor 0:fcaad0dfa051 257 }
spastor 0:fcaad0dfa051 258
spastor 0:fcaad0dfa051 259 RadioStatus XBee::get_config_node_discovery(uint16_t * const timeout_ms, uint8_t * const options)
spastor 0:fcaad0dfa051 260 {
spastor 0:fcaad0dfa051 261 AtCmdFrame::AtCmdResp cmdresp;
spastor 0:fcaad0dfa051 262 uint32_t var32;
spastor 0:fcaad0dfa051 263
spastor 0:fcaad0dfa051 264 cmdresp = get_param("NT", &var32);
spastor 0:fcaad0dfa051 265 if (cmdresp != AtCmdFrame::AtCmdRespOk) {
spastor 0:fcaad0dfa051 266 return Failure;
spastor 0:fcaad0dfa051 267 }
spastor 0:fcaad0dfa051 268 *timeout_ms = var32;
spastor 0:fcaad0dfa051 269
spastor 0:fcaad0dfa051 270 cmdresp = get_param("NO", &var32);
spastor 0:fcaad0dfa051 271 if (cmdresp != AtCmdFrame::AtCmdRespOk) {
spastor 0:fcaad0dfa051 272 return Failure;
spastor 0:fcaad0dfa051 273 }
spastor 0:fcaad0dfa051 274 *options = var32;
spastor 0:fcaad0dfa051 275 return Success;
spastor 0:fcaad0dfa051 276 }
spastor 0:fcaad0dfa051 277
spastor 3:8662ebe83570 278 RadioStatus XBee::_get_iosample(const RemoteXBee& remote, uint8_t * const io_sample, uint16_t * const len)
spastor 0:fcaad0dfa051 279 {
spastor 0:fcaad0dfa051 280 AtCmdFrame::AtCmdResp cmdresp;
spastor 0:fcaad0dfa051 281
spastor 0:fcaad0dfa051 282 /* Force a sample read */
spastor 0:fcaad0dfa051 283 cmdresp = get_param(remote, "IS", io_sample, len);
spastor 0:fcaad0dfa051 284 if (cmdresp != AtCmdFrame::AtCmdRespOk) {
spastor 3:8662ebe83570 285 digi_log(LogLevelError, "_get_iosample error %d:\r\n", cmdresp);
spastor 0:fcaad0dfa051 286 return Failure;
spastor 0:fcaad0dfa051 287 }
spastor 0:fcaad0dfa051 288
spastor 0:fcaad0dfa051 289 return Success;
spastor 0:fcaad0dfa051 290 }
spastor 0:fcaad0dfa051 291
spastor 0:fcaad0dfa051 292 RadioStatus XBee::config_io_sample_destination(const RemoteXBee& remote, const RemoteXBee& destination)
spastor 0:fcaad0dfa051 293 {
spastor 0:fcaad0dfa051 294 uint32_t dh;
spastor 0:fcaad0dfa051 295 uint32_t dl;
spastor 0:fcaad0dfa051 296
spastor 0:fcaad0dfa051 297 if (destination.is_valid_addr64b()) {
spastor 0:fcaad0dfa051 298 const uint64_t dest64 = destination.get_addr64();
spastor 0:fcaad0dfa051 299 dh = (uint32_t)((dest64 >> 32) & 0xFFFFFFFF);
spastor 0:fcaad0dfa051 300 dl = (uint32_t)((dest64 & 0xFFFFFFFF));
spastor 0:fcaad0dfa051 301 } else if (destination.is_valid_addr16b()) {
spastor 0:fcaad0dfa051 302 const uint16_t destAddr16 = destination.get_addr16();
spastor 0:fcaad0dfa051 303 dh = 0;
spastor 0:fcaad0dfa051 304 dl = destAddr16;
spastor 0:fcaad0dfa051 305 } else {
spastor 0:fcaad0dfa051 306 digi_log(LogLevelError, "send_io_sample_to: Invalid destination");
spastor 0:fcaad0dfa051 307 return Failure;
spastor 0:fcaad0dfa051 308 }
spastor 0:fcaad0dfa051 309
spastor 0:fcaad0dfa051 310 AtCmdFrame::AtCmdResp cmdresp;
spastor 0:fcaad0dfa051 311
spastor 0:fcaad0dfa051 312 cmdresp = set_param(remote, "DH", dh);
spastor 0:fcaad0dfa051 313 if (cmdresp != AtCmdFrame::AtCmdRespOk) {
spastor 0:fcaad0dfa051 314 digi_log(LogLevelError, "send_io_sample_to error %d:\r\n", cmdresp);
spastor 0:fcaad0dfa051 315 return Failure;
spastor 0:fcaad0dfa051 316 }
spastor 0:fcaad0dfa051 317
spastor 0:fcaad0dfa051 318 cmdresp = set_param(remote, "DL", dl);
spastor 0:fcaad0dfa051 319 if (cmdresp != AtCmdFrame::AtCmdRespOk) {
spastor 0:fcaad0dfa051 320 digi_log(LogLevelError, "send_io_sample_to error %d:\r\n", cmdresp);
spastor 0:fcaad0dfa051 321 return Failure;
spastor 0:fcaad0dfa051 322 }
spastor 0:fcaad0dfa051 323
spastor 0:fcaad0dfa051 324 return Success;
spastor 0:fcaad0dfa051 325 }
spastor 0:fcaad0dfa051 326
spastor 0:fcaad0dfa051 327 RadioStatus XBee::set_io_sample_rate(const RemoteXBee& remote, const float seconds)
spastor 0:fcaad0dfa051 328 {
spastor 0:fcaad0dfa051 329 const float max_seconds = 65.535;
spastor 0:fcaad0dfa051 330
spastor 0:fcaad0dfa051 331 if (seconds > max_seconds) {
spastor 0:fcaad0dfa051 332 digi_log(LogLevelError, "XBee::set_io_sample_rate error seconds rate exceeds maximum %d:\r\n", max_seconds);
spastor 0:fcaad0dfa051 333 return Failure;
spastor 0:fcaad0dfa051 334 }
spastor 0:fcaad0dfa051 335
spastor 0:fcaad0dfa051 336 AtCmdFrame::AtCmdResp cmdresp;
spastor 0:fcaad0dfa051 337 const uint16_t milliseconds = seconds * 1000;
spastor 0:fcaad0dfa051 338
spastor 0:fcaad0dfa051 339 cmdresp = set_param(remote, "IR", milliseconds);
spastor 0:fcaad0dfa051 340 if (cmdresp != AtCmdFrame::AtCmdRespOk) {
spastor 0:fcaad0dfa051 341 digi_log(LogLevelError, "XBee::set_io_sample_rate error %d:\r\n", cmdresp);
spastor 0:fcaad0dfa051 342 return Failure;
spastor 0:fcaad0dfa051 343 }
spastor 0:fcaad0dfa051 344
spastor 0:fcaad0dfa051 345 return Success;
spastor 0:fcaad0dfa051 346 }