project de marde si tu touch le no-homo s'applique pas
Fork of XBeeLib by
XBee/RadioConfig.cpp@0:fcaad0dfa051, 2015-05-08 (annotated)
- 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?
User | Revision | Line number | New 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 | } |