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