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:
Fri May 08 11:50:56 2015 +0200
Revision:
0:fcaad0dfa051
Child:
1:794d1d3e4a08
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) {
spastor 0:fcaad0dfa051 97 return Failure;
spastor 0:fcaad0dfa051 98 }
spastor 0:fcaad0dfa051 99
spastor 0:fcaad0dfa051 100 return wait_for_module_to_reset(rst_cnt_p, init_rst_cnt);
spastor 0:fcaad0dfa051 101 }
spastor 0:fcaad0dfa051 102
spastor 0:fcaad0dfa051 103 RadioStatus XBee::set_node_identifier(const char * const node_id)
spastor 0:fcaad0dfa051 104 {
spastor 0:fcaad0dfa051 105 if (node_id == NULL) {
spastor 0:fcaad0dfa051 106 return Failure;
spastor 0:fcaad0dfa051 107 }
spastor 0:fcaad0dfa051 108
spastor 0:fcaad0dfa051 109 AtCmdFrame::AtCmdResp cmdresp;
spastor 0:fcaad0dfa051 110 const size_t str_len = strlen(node_id);
spastor 0:fcaad0dfa051 111
spastor 0:fcaad0dfa051 112 if(str_len > 20 || str_len < 1) {
spastor 0:fcaad0dfa051 113 return Failure;
spastor 0:fcaad0dfa051 114 }
spastor 0:fcaad0dfa051 115
spastor 0:fcaad0dfa051 116 cmdresp = set_param("NI", (const uint8_t *)node_id, str_len);
spastor 0:fcaad0dfa051 117 if (cmdresp != AtCmdFrame::AtCmdRespOk) {
spastor 0:fcaad0dfa051 118 return Failure;
spastor 0:fcaad0dfa051 119 }
spastor 0:fcaad0dfa051 120 return Success;
spastor 0:fcaad0dfa051 121 }
spastor 0:fcaad0dfa051 122
spastor 0:fcaad0dfa051 123 RadioStatus XBee::get_node_identifier(char * const node_id)
spastor 0:fcaad0dfa051 124 {
spastor 0:fcaad0dfa051 125 if (node_id == NULL) {
spastor 0:fcaad0dfa051 126 return Failure;
spastor 0:fcaad0dfa051 127 }
spastor 0:fcaad0dfa051 128
spastor 0:fcaad0dfa051 129 uint16_t max_ni_length = 20;
spastor 0:fcaad0dfa051 130 AtCmdFrame::AtCmdResp cmdresp;
spastor 0:fcaad0dfa051 131
spastor 0:fcaad0dfa051 132 cmdresp = get_param("NI", (uint8_t *)node_id, &max_ni_length);
spastor 0:fcaad0dfa051 133 if (cmdresp != AtCmdFrame::AtCmdRespOk) {
spastor 0:fcaad0dfa051 134 return Failure;
spastor 0:fcaad0dfa051 135 }
spastor 0:fcaad0dfa051 136 node_id[max_ni_length] = '\0';
spastor 0:fcaad0dfa051 137 return Success;
spastor 0:fcaad0dfa051 138 }
spastor 0:fcaad0dfa051 139
spastor 0:fcaad0dfa051 140 uint16_t XBee::get_hw_version() const
spastor 0:fcaad0dfa051 141 {
spastor 0:fcaad0dfa051 142 return _hw_version;
spastor 0:fcaad0dfa051 143 }
spastor 0:fcaad0dfa051 144
spastor 0:fcaad0dfa051 145 uint16_t XBee::get_fw_version() const
spastor 0:fcaad0dfa051 146 {
spastor 0:fcaad0dfa051 147 return _fw_version;
spastor 0:fcaad0dfa051 148 }
spastor 0:fcaad0dfa051 149
spastor 0:fcaad0dfa051 150 void XBee::set_tx_options(uint8_t options)
spastor 0:fcaad0dfa051 151 {
spastor 0:fcaad0dfa051 152 _tx_options = options;
spastor 0:fcaad0dfa051 153 }
spastor 0:fcaad0dfa051 154
spastor 0:fcaad0dfa051 155 uint8_t XBee::get_tx_options() const
spastor 0:fcaad0dfa051 156 {
spastor 0:fcaad0dfa051 157 return _tx_options;
spastor 0:fcaad0dfa051 158 }
spastor 0:fcaad0dfa051 159
spastor 0:fcaad0dfa051 160 void XBee::set_broadcast_radius(uint8_t bc_radius)
spastor 0:fcaad0dfa051 161 {
spastor 0:fcaad0dfa051 162 _bc_radius = bc_radius;
spastor 0:fcaad0dfa051 163 }
spastor 0:fcaad0dfa051 164
spastor 0:fcaad0dfa051 165 uint8_t XBee::get_bc_radius() const
spastor 0:fcaad0dfa051 166 {
spastor 0:fcaad0dfa051 167 return _bc_radius;
spastor 0:fcaad0dfa051 168 }
spastor 0:fcaad0dfa051 169
spastor 0:fcaad0dfa051 170 RadioStatus XBee::start_node_discovery()
spastor 0:fcaad0dfa051 171 {
spastor 0:fcaad0dfa051 172 AtCmdFrame cmd_frame = AtCmdFrame("ND");
spastor 0:fcaad0dfa051 173 send_api_frame(&cmd_frame);
spastor 0:fcaad0dfa051 174
spastor 0:fcaad0dfa051 175 return Success;
spastor 0:fcaad0dfa051 176 }
spastor 0:fcaad0dfa051 177
spastor 0:fcaad0dfa051 178 void XBee::_get_remote_node_by_id(const char * const node_id, uint64_t * const addr64, uint16_t * const addr16)
spastor 0:fcaad0dfa051 179 {
spastor 0:fcaad0dfa051 180 *addr64 = ADDR64_UNASSIGNED;
spastor 0:fcaad0dfa051 181 *addr16 = ADDR16_UNKNOWN;
spastor 0:fcaad0dfa051 182 if (node_id == NULL) {
spastor 0:fcaad0dfa051 183 return;
spastor 0:fcaad0dfa051 184 }
spastor 0:fcaad0dfa051 185 const size_t node_id_len = strlen(node_id);
spastor 0:fcaad0dfa051 186 if (node_id_len == 0 || node_id_len > MAX_NI_PARAM_LEN) {
spastor 0:fcaad0dfa051 187 return;
spastor 0:fcaad0dfa051 188 }
spastor 0:fcaad0dfa051 189
spastor 0:fcaad0dfa051 190 const uint16_t old_timeout = _timeout_ms;
spastor 0:fcaad0dfa051 191
spastor 0:fcaad0dfa051 192 uint32_t nd_timeout_100msec;
spastor 0:fcaad0dfa051 193 const AtCmdFrame::AtCmdResp nt_resp = get_param("NT", &nd_timeout_100msec);
spastor 0:fcaad0dfa051 194 if (nt_resp != AtCmdFrame::AtCmdRespOk) {
spastor 0:fcaad0dfa051 195 _timeout_ms = 10000;
spastor 0:fcaad0dfa051 196 } else {
spastor 0:fcaad0dfa051 197 _timeout_ms = (uint16_t)nd_timeout_100msec * 100 + 1000;
spastor 0:fcaad0dfa051 198 }
spastor 0:fcaad0dfa051 199
spastor 0:fcaad0dfa051 200 const AtCmdFrame::AtCmdResp cmdresp = set_param("ND", (const uint8_t *)node_id, strlen(node_id));
spastor 0:fcaad0dfa051 201 if (cmdresp != AtCmdFrame::AtCmdRespOk) {
spastor 0:fcaad0dfa051 202 _timeout_ms = old_timeout;
spastor 0:fcaad0dfa051 203 return;
spastor 0:fcaad0dfa051 204 }
spastor 0:fcaad0dfa051 205
spastor 0:fcaad0dfa051 206 const int nd_start_time = _timer.read_ms();
spastor 0:fcaad0dfa051 207 const int nd_end_time = nd_start_time + _timeout_ms;
spastor 0:fcaad0dfa051 208
spastor 0:fcaad0dfa051 209 AtCmdFrame atnd_frame = AtCmdFrame("ND", (const uint8_t *)node_id, strlen(node_id));
spastor 0:fcaad0dfa051 210 send_api_frame(&atnd_frame);
spastor 0:fcaad0dfa051 211
spastor 0:fcaad0dfa051 212 ApiFrame * const resp_frame = get_this_api_frame(atnd_frame.get_frame_id(), ApiFrame::AtCmdResp);
spastor 0:fcaad0dfa051 213 _timeout_ms = old_timeout;
spastor 0:fcaad0dfa051 214
spastor 0:fcaad0dfa051 215 while (_timer.read_ms() < nd_end_time) {
spastor 0:fcaad0dfa051 216 wait_ms(10);
spastor 0:fcaad0dfa051 217 }
spastor 0:fcaad0dfa051 218
spastor 0:fcaad0dfa051 219 if (resp_frame == NULL) {
spastor 0:fcaad0dfa051 220 digi_log(LogLevelWarning, "XBeeZB::get_remote_node_by_id timeout when waiting for ATND response");
spastor 0:fcaad0dfa051 221 return;
spastor 0:fcaad0dfa051 222 }
spastor 0:fcaad0dfa051 223
spastor 0:fcaad0dfa051 224 const AtCmdFrame::AtCmdResp resp = (AtCmdFrame::AtCmdResp)resp_frame->get_data_at(ATCMD_RESP_STATUS_OFFSET);
spastor 0:fcaad0dfa051 225 if (resp != AtCmdFrame::AtCmdRespOk) {
spastor 0:fcaad0dfa051 226 digi_log(LogLevelWarning, "send_at_cmd bad response: 0x%x\r\n", resp);
spastor 0:fcaad0dfa051 227 _framebuf.free_frame(resp_frame);
spastor 0:fcaad0dfa051 228 return;
spastor 0:fcaad0dfa051 229 }
spastor 0:fcaad0dfa051 230
spastor 0:fcaad0dfa051 231 rmemcpy((uint8_t *)addr16, resp_frame->get_data() + ATCMD_RESP_DATA_OFFSET, sizeof *addr16);
spastor 0:fcaad0dfa051 232 rmemcpy((uint8_t *)addr64, resp_frame->get_data() + ATCMD_RESP_DATA_OFFSET + sizeof *addr16, sizeof *addr64);
spastor 0:fcaad0dfa051 233 _framebuf.free_frame(resp_frame);
spastor 0:fcaad0dfa051 234 return;
spastor 0:fcaad0dfa051 235 }
spastor 0:fcaad0dfa051 236
spastor 0:fcaad0dfa051 237 RadioStatus XBee::config_node_discovery(uint16_t timeout_ms, uint8_t options)
spastor 0:fcaad0dfa051 238 {
spastor 0:fcaad0dfa051 239 AtCmdFrame::AtCmdResp cmdresp;
spastor 0:fcaad0dfa051 240
spastor 0:fcaad0dfa051 241 cmdresp = set_param("NT", (uint8_t)(timeout_ms / 100));
spastor 0:fcaad0dfa051 242 if (cmdresp != AtCmdFrame::AtCmdRespOk) {
spastor 0:fcaad0dfa051 243 return Failure;
spastor 0:fcaad0dfa051 244 }
spastor 0:fcaad0dfa051 245
spastor 0:fcaad0dfa051 246 cmdresp = set_param("NO", (uint8_t)options);
spastor 0:fcaad0dfa051 247 if (cmdresp != AtCmdFrame::AtCmdRespOk) {
spastor 0:fcaad0dfa051 248 return Failure;
spastor 0:fcaad0dfa051 249 }
spastor 0:fcaad0dfa051 250 cmdresp = set_param("AC");
spastor 0:fcaad0dfa051 251 if (cmdresp != AtCmdFrame::AtCmdRespOk) {
spastor 0:fcaad0dfa051 252 return Failure;
spastor 0:fcaad0dfa051 253 }
spastor 0:fcaad0dfa051 254
spastor 0:fcaad0dfa051 255 return Success;
spastor 0:fcaad0dfa051 256 }
spastor 0:fcaad0dfa051 257
spastor 0:fcaad0dfa051 258 RadioStatus XBee::get_config_node_discovery(uint16_t * const timeout_ms, uint8_t * const options)
spastor 0:fcaad0dfa051 259 {
spastor 0:fcaad0dfa051 260 AtCmdFrame::AtCmdResp cmdresp;
spastor 0:fcaad0dfa051 261 uint32_t var32;
spastor 0:fcaad0dfa051 262
spastor 0:fcaad0dfa051 263 cmdresp = get_param("NT", &var32);
spastor 0:fcaad0dfa051 264 if (cmdresp != AtCmdFrame::AtCmdRespOk) {
spastor 0:fcaad0dfa051 265 return Failure;
spastor 0:fcaad0dfa051 266 }
spastor 0:fcaad0dfa051 267 *timeout_ms = var32;
spastor 0:fcaad0dfa051 268
spastor 0:fcaad0dfa051 269 cmdresp = get_param("NO", &var32);
spastor 0:fcaad0dfa051 270 if (cmdresp != AtCmdFrame::AtCmdRespOk) {
spastor 0:fcaad0dfa051 271 return Failure;
spastor 0:fcaad0dfa051 272 }
spastor 0:fcaad0dfa051 273 *options = var32;
spastor 0:fcaad0dfa051 274 return Success;
spastor 0:fcaad0dfa051 275 }
spastor 0:fcaad0dfa051 276
spastor 0:fcaad0dfa051 277 RadioStatus XBee::get_iosample(const RemoteXBee& remote, uint8_t * const io_sample, uint16_t * const len)
spastor 0:fcaad0dfa051 278 {
spastor 0:fcaad0dfa051 279 AtCmdFrame::AtCmdResp cmdresp;
spastor 0:fcaad0dfa051 280 *len = MAX_IO_SAMPLE_BUF_LEN;
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 0:fcaad0dfa051 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 }