Fork of my MQTTGateway

Dependencies:   mbed-http

Committer:
vpcola
Date:
Sat Apr 08 14:45:51 2017 +0000
Revision:
0:f1d3878b8dd9
Initial commit

Who changed what in which revision?

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