project de marde si tu touch le no-homo s'applique pas

Fork of XBeeLib by Digi International Inc.

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