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 #if !defined(__DIGI_RADIO_H_)
vpcola 0:f1d3878b8dd9 14 #define __DIGI_RADIO_H_
vpcola 0:f1d3878b8dd9 15
vpcola 0:f1d3878b8dd9 16 #include <stdint.h>
vpcola 0:f1d3878b8dd9 17 #include "config.h"
vpcola 0:f1d3878b8dd9 18 #include "Utils/Debug.h"
vpcola 0:f1d3878b8dd9 19 #include "Frames/AtCmdFrame.h"
vpcola 0:f1d3878b8dd9 20 #include "FrameHandlers/FrameHandler.h"
vpcola 0:f1d3878b8dd9 21 #include "FrameHandlers/FH_ModemStatus.h"
vpcola 0:f1d3878b8dd9 22 #include "FrameBuffer/FrameBuffer.h"
vpcola 0:f1d3878b8dd9 23 #include "Addresses.h"
vpcola 0:f1d3878b8dd9 24 #include "RemoteXBee/RemoteXBee.h"
vpcola 0:f1d3878b8dd9 25 #include "IO/IO.h"
vpcola 0:f1d3878b8dd9 26
vpcola 0:f1d3878b8dd9 27 #define MAX_FRAME_HANDLERS 4
vpcola 0:f1d3878b8dd9 28 #define RESET_TIMEOUT_MS 5000
vpcola 0:f1d3878b8dd9 29
vpcola 0:f1d3878b8dd9 30 #define DR_API_FRAME_OVERHEAD 4 /* Start of frame + frame len + checksum */
vpcola 0:f1d3878b8dd9 31 #define DR_MIN_API_FRAME_LEN 4
vpcola 0:f1d3878b8dd9 32 #define DR_START_OF_FRAME 0x7E
vpcola 0:f1d3878b8dd9 33 #define DR_ESCAPE_BYTE 0x7D
vpcola 0:f1d3878b8dd9 34 #define DR_XON_BYTE 0x11
vpcola 0:f1d3878b8dd9 35 #define DR_XOFF_BYTE 0x13
vpcola 0:f1d3878b8dd9 36 #define DR_ESCAPE_XOR_BYTE 0x20
vpcola 0:f1d3878b8dd9 37
vpcola 0:f1d3878b8dd9 38 /* TODO, verify these flags work in all modules */
vpcola 0:f1d3878b8dd9 39 #define DISABLE_RETRIES_AND_ROUTE_REPAIR 0x01
vpcola 0:f1d3878b8dd9 40 #define ENABLE_APS_ENCRYPTION 0x20
vpcola 0:f1d3878b8dd9 41 #define USE_EXTENDED_TX_TIMEOUT 0x40
vpcola 0:f1d3878b8dd9 42
vpcola 0:f1d3878b8dd9 43 namespace XBeeLib {
vpcola 0:f1d3878b8dd9 44
vpcola 0:f1d3878b8dd9 45 /**
vpcola 0:f1d3878b8dd9 46 * @defgroup RadioStatus
vpcola 0:f1d3878b8dd9 47 * @{
vpcola 0:f1d3878b8dd9 48 */
vpcola 0:f1d3878b8dd9 49 /**
vpcola 0:f1d3878b8dd9 50 * RadioStatus
vpcola 0:f1d3878b8dd9 51 */
vpcola 0:f1d3878b8dd9 52 enum RadioStatus {
vpcola 0:f1d3878b8dd9 53 Success = 0, /**< Success */
vpcola 0:f1d3878b8dd9 54 Failure = -1, /**< Failure */
vpcola 0:f1d3878b8dd9 55 };
vpcola 0:f1d3878b8dd9 56 /**
vpcola 0:f1d3878b8dd9 57 * @}
vpcola 0:f1d3878b8dd9 58 */
vpcola 0:f1d3878b8dd9 59
vpcola 0:f1d3878b8dd9 60 /**
vpcola 0:f1d3878b8dd9 61 * @defgroup TxStatus
vpcola 0:f1d3878b8dd9 62 * @{
vpcola 0:f1d3878b8dd9 63 */
vpcola 0:f1d3878b8dd9 64 /**
vpcola 0:f1d3878b8dd9 65 * TxStatus
vpcola 0:f1d3878b8dd9 66 */
vpcola 0:f1d3878b8dd9 67 enum TxStatus {
vpcola 0:f1d3878b8dd9 68 TxStatusSuccess = 0, /**< Success */
vpcola 0:f1d3878b8dd9 69 TxStatusAckFail = 1, /**< MAC ACK Failure */
vpcola 0:f1d3878b8dd9 70 TxStatusCCAFail = 2, /**< CCA Failure */
vpcola 0:f1d3878b8dd9 71 TxStatusInvDestEP = 0x15, /**< Invalid destination endpoint */
vpcola 0:f1d3878b8dd9 72 TxStatusNwAckFail = 0x21, /**< Network ACK Failure */
vpcola 0:f1d3878b8dd9 73 TxStatusNotJoinNw = 0x22, /**< Not Joined to Network */
vpcola 0:f1d3878b8dd9 74 TxStatusSelfAddr = 0x23, /**< Self-addressed */
vpcola 0:f1d3878b8dd9 75 TxStatusAddrNotFound = 0x24, /**< Address Not Found */
vpcola 0:f1d3878b8dd9 76 TxStatusRouteNotFound = 0x25, /**< Route Not Found */
vpcola 0:f1d3878b8dd9 77 TxStatusBroadSrcFail2Heard = 0x26, /**< Broadcast source failed to hear a neighbor relay the message */
vpcola 0:f1d3878b8dd9 78 TxStatusInvBindTableIdx = 0x2B, /**< Invalid binding table index */
vpcola 0:f1d3878b8dd9 79 TxStatusResourceError = 0x2C, /**< Resource error lack of free buffers, timers, etc. */
vpcola 0:f1d3878b8dd9 80 TxStatusAttBroadcWithAPS = 0x2D, /**< Attempted broadcast with APS transmission */
vpcola 0:f1d3878b8dd9 81 TxStatusAttUnicWithAPSEE0 = 0x2E, /**< Attempted unicast with APS transmission, but EE=0 */
vpcola 0:f1d3878b8dd9 82 TxStatusResourceError2 = 0x31, /**< TxStatusResourceError2 */
vpcola 0:f1d3878b8dd9 83 TxStatusInternalError = 0x32, /**< Resource error lack of free buffers, timers, etc. */
vpcola 0:f1d3878b8dd9 84 TxStatusPayloadTooLarge = 0x74, /**< Data payload too large */
vpcola 0:f1d3878b8dd9 85 TxStatusIndirectMsgUnReq = 0x75, /**< Indirect message unrequested */
vpcola 0:f1d3878b8dd9 86 TxStatusInvalidAddr = 0xfe, /**< Invalid Address (Error generated by the library) */
vpcola 0:f1d3878b8dd9 87 TxStatusTimeout = 0xff, /**< Timeout (Error generated by the library) */
vpcola 0:f1d3878b8dd9 88 };
vpcola 0:f1d3878b8dd9 89 /**
vpcola 0:f1d3878b8dd9 90 * @}
vpcola 0:f1d3878b8dd9 91 */
vpcola 0:f1d3878b8dd9 92
vpcola 0:f1d3878b8dd9 93 /**
vpcola 0:f1d3878b8dd9 94 * @defgroup RadioLocation
vpcola 0:f1d3878b8dd9 95 * @{
vpcola 0:f1d3878b8dd9 96 */
vpcola 0:f1d3878b8dd9 97 /**
vpcola 0:f1d3878b8dd9 98 * RadioLocation
vpcola 0:f1d3878b8dd9 99 */
vpcola 0:f1d3878b8dd9 100 enum RadioLocation {
vpcola 0:f1d3878b8dd9 101 RadioLocal = 0, /**< Local Radio */
vpcola 0:f1d3878b8dd9 102 RadioRemote = 1, /**< Remote Radio */
vpcola 0:f1d3878b8dd9 103 };
vpcola 0:f1d3878b8dd9 104 /**
vpcola 0:f1d3878b8dd9 105 * @}
vpcola 0:f1d3878b8dd9 106 */
vpcola 0:f1d3878b8dd9 107
vpcola 0:f1d3878b8dd9 108 /** Parent Class for XBee modules, not to be directly used */
vpcola 0:f1d3878b8dd9 109 class XBee
vpcola 0:f1d3878b8dd9 110 {
vpcola 0:f1d3878b8dd9 111 private:
vpcola 0:f1d3878b8dd9 112 /** wait_for_module_to_reset - waits until a Modem Status packet with a reset status
vpcola 0:f1d3878b8dd9 113 * is received, or the timeout expires.
vpcola 0:f1d3878b8dd9 114 *
vpcola 0:f1d3878b8dd9 115 * @returns
vpcola 0:f1d3878b8dd9 116 * Success if a Modem Status was received,
vpcola 0:f1d3878b8dd9 117 * Failure otherwise
vpcola 0:f1d3878b8dd9 118 */
vpcola 0:f1d3878b8dd9 119 RadioStatus wait_for_module_to_reset(volatile uint16_t *rst_cnt_p, uint16_t init_rst_cnt);
vpcola 0:f1d3878b8dd9 120
vpcola 0:f1d3878b8dd9 121 protected:
vpcola 0:f1d3878b8dd9 122 /** buffer to store the received frames */
vpcola 0:f1d3878b8dd9 123 static FrameBuffer _framebuf_app;
vpcola 0:f1d3878b8dd9 124 static FrameBuffer _framebuf_syncr;
vpcola 0:f1d3878b8dd9 125
vpcola 0:f1d3878b8dd9 126 public:
vpcola 0:f1d3878b8dd9 127
vpcola 0:f1d3878b8dd9 128 /**
vpcola 0:f1d3878b8dd9 129 * RadioMode
vpcola 0:f1d3878b8dd9 130 */
vpcola 0:f1d3878b8dd9 131 enum RadioMode {
vpcola 0:f1d3878b8dd9 132 ModeUnknown = 0, /**< Unknown */
vpcola 0:f1d3878b8dd9 133 ModeAPI1 = 1, /**< API1 */
vpcola 0:f1d3878b8dd9 134 ModeAPI2 = 2, /**< API2 */
vpcola 0:f1d3878b8dd9 135 ModeTransparent = 3, /**< Transparent */
vpcola 0:f1d3878b8dd9 136 ModeBootloader = 4, /**< Bootloader */
vpcola 0:f1d3878b8dd9 137 };
vpcola 0:f1d3878b8dd9 138
vpcola 0:f1d3878b8dd9 139 /** Class constructor
vpcola 0:f1d3878b8dd9 140 * @param tx the TX pin of the UART that will interface the XBee module
vpcola 0:f1d3878b8dd9 141 * @param rx the RX pin of the UART that will interface the XBee module
vpcola 0:f1d3878b8dd9 142 * @param reset the pin to which the XBee's reset line is attached to, use NC if not available
vpcola 0:f1d3878b8dd9 143 * @param rts the RTS pin for the UART that will interface the XBee module, use NC if not available
vpcola 0:f1d3878b8dd9 144 * @param cts the CTS pin for the UART that will interface the XBee module, use NC if not available
vpcola 0:f1d3878b8dd9 145 * @param baud the baudrate for the UART that will interface the XBee module. Note that the module has to be already configured
vpcola 0:f1d3878b8dd9 146 * to this baud rate (ATBD parameter). By default it is configured to 9600 bps
vpcola 0:f1d3878b8dd9 147 * */
vpcola 0:f1d3878b8dd9 148 XBee(PinName tx, PinName rx, PinName reset = NC, PinName rts = NC, PinName cts = NC, int baud = 9600);
vpcola 0:f1d3878b8dd9 149
vpcola 0:f1d3878b8dd9 150 XBee(const XBee& other); /* Intentionally not implemented */
vpcola 0:f1d3878b8dd9 151 /** Class destructor */
vpcola 0:f1d3878b8dd9 152 virtual ~XBee();
vpcola 0:f1d3878b8dd9 153
vpcola 0:f1d3878b8dd9 154 /** init- initializes object
vpcola 0:f1d3878b8dd9 155 * This function must be called just after creating the object so it initializes internal data.
vpcola 0:f1d3878b8dd9 156 * @returns
vpcola 0:f1d3878b8dd9 157 * Success if the module has been properly initialized and is ready to process data.
vpcola 0:f1d3878b8dd9 158 * Failure otherwise.
vpcola 0:f1d3878b8dd9 159 */
vpcola 0:f1d3878b8dd9 160 RadioStatus init();
vpcola 0:f1d3878b8dd9 161
vpcola 0:f1d3878b8dd9 162 /** get_addr64 - returns the 64bit address of the local device
vpcola 0:f1d3878b8dd9 163 *
vpcola 0:f1d3878b8dd9 164 * @returns the 64bit address of the local device
vpcola 0:f1d3878b8dd9 165 */
vpcola 0:f1d3878b8dd9 166 uint64_t get_addr64() const;
vpcola 0:f1d3878b8dd9 167
vpcola 0:f1d3878b8dd9 168 /** hardware_reset - performs a hardware reset. The reset GPIO must have
vpcola 0:f1d3878b8dd9 169 * been provided to the constructor
vpcola 0:f1d3878b8dd9 170 *
vpcola 0:f1d3878b8dd9 171 * @returns
vpcola 0:f1d3878b8dd9 172 * Success if the operation was successful,
vpcola 0:f1d3878b8dd9 173 * Failure otherwise
vpcola 0:f1d3878b8dd9 174 */
vpcola 0:f1d3878b8dd9 175 RadioStatus hardware_reset();
vpcola 0:f1d3878b8dd9 176
vpcola 0:f1d3878b8dd9 177 /** software_reset - performs a firmware reset
vpcola 0:f1d3878b8dd9 178 *
vpcola 0:f1d3878b8dd9 179 * @returns
vpcola 0:f1d3878b8dd9 180 * Success if the operation was successful,
vpcola 0:f1d3878b8dd9 181 * Failure otherwise
vpcola 0:f1d3878b8dd9 182 */
vpcola 0:f1d3878b8dd9 183 RadioStatus software_reset();
vpcola 0:f1d3878b8dd9 184
vpcola 0:f1d3878b8dd9 185 /** device_reset - performs a hardware reset if there is a GPIO connected to the
vpcola 0:f1d3878b8dd9 186 * reset line of the device. Otherwise, performs a firmware reset.
vpcola 0:f1d3878b8dd9 187 *
vpcola 0:f1d3878b8dd9 188 * @returns
vpcola 0:f1d3878b8dd9 189 * Success if the operation was successful,
vpcola 0:f1d3878b8dd9 190 * Failure otherwise
vpcola 0:f1d3878b8dd9 191 */
vpcola 0:f1d3878b8dd9 192 #if defined(UNIT_TEST)
vpcola 0:f1d3878b8dd9 193 virtual
vpcola 0:f1d3878b8dd9 194 #endif
vpcola 0:f1d3878b8dd9 195 RadioStatus device_reset();
vpcola 0:f1d3878b8dd9 196
vpcola 0:f1d3878b8dd9 197 /** set_tx_options - sets the transmit options byte, used with the transmit frames.
vpcola 0:f1d3878b8dd9 198 * Valid flags are:
vpcola 0:f1d3878b8dd9 199 * - DISABLE_RETRIES_AND_ROUTE_REPAIR
vpcola 0:f1d3878b8dd9 200 * - ENABLE_APS_ENCRYPTION
vpcola 0:f1d3878b8dd9 201 * - USE_EXTENDED_TX_TIMEOUT
vpcola 0:f1d3878b8dd9 202 *
vpcola 0:f1d3878b8dd9 203 * @param options variable with the option flags
vpcola 0:f1d3878b8dd9 204 */
vpcola 0:f1d3878b8dd9 205 void set_tx_options(uint8_t options);
vpcola 0:f1d3878b8dd9 206
vpcola 0:f1d3878b8dd9 207 /** get_tx_options - returns the tx options byte configured in the library.
vpcola 0:f1d3878b8dd9 208 *
vpcola 0:f1d3878b8dd9 209 * @returns the tx options byte configured in the library.
vpcola 0:f1d3878b8dd9 210 */
vpcola 0:f1d3878b8dd9 211 uint8_t get_tx_options() const;
vpcola 0:f1d3878b8dd9 212
vpcola 0:f1d3878b8dd9 213 /************************ Configuration member methods *************************/
vpcola 0:f1d3878b8dd9 214 /** write_config - write settings to non volatile memory
vpcola 0:f1d3878b8dd9 215 *
vpcola 0:f1d3878b8dd9 216 * @returns
vpcola 0:f1d3878b8dd9 217 * Success if the operation was successful,
vpcola 0:f1d3878b8dd9 218 * Failure otherwise
vpcola 0:f1d3878b8dd9 219 */
vpcola 0:f1d3878b8dd9 220 RadioStatus write_config();
vpcola 0:f1d3878b8dd9 221
vpcola 0:f1d3878b8dd9 222 /** config_io_sample_destination - configures to which node a remote module will send its IO Samples to.
vpcola 0:f1d3878b8dd9 223 * @Note: this will modify 'remote' DH and DL parameters, if the remote node is configured in transparent mode this could lead to unwanted behavior.
vpcola 0:f1d3878b8dd9 224 * Consult the module's reference manual for more information.
vpcola 0:f1d3878b8dd9 225 *
vpcola 0:f1d3878b8dd9 226 * @param remote remote device that will be sending the IO Samples
vpcola 0:f1d3878b8dd9 227 * @param destination remote device that will be receiving the IO Samples sent by 'remote'
vpcola 0:f1d3878b8dd9 228 * @returns the result of the data transfer
vpcola 0:f1d3878b8dd9 229 * Success if the operation was successful,
vpcola 0:f1d3878b8dd9 230 * Failure otherwise
vpcola 0:f1d3878b8dd9 231 */
vpcola 0:f1d3878b8dd9 232 RadioStatus config_io_sample_destination(const RemoteXBee& remote, const RemoteXBee& destination);
vpcola 0:f1d3878b8dd9 233
vpcola 0:f1d3878b8dd9 234 /** set_io_sample_rate - configures how often the IO Samples should be sent to the destination (see @ref send_io_sample_to).
vpcola 0:f1d3878b8dd9 235 *
vpcola 0:f1d3878b8dd9 236 * @param remote remote device that will be sending the IO Samples
vpcola 0:f1d3878b8dd9 237 * @param seconds the IO Sample sending rate in seconds (granularity is of 1 millisecond). Maximum is 65.535 seconds.
vpcola 0:f1d3878b8dd9 238 * @returns the result of the data transfer
vpcola 0:f1d3878b8dd9 239 * Success if the operation was successful,
vpcola 0:f1d3878b8dd9 240 * Failure otherwise
vpcola 0:f1d3878b8dd9 241 */
vpcola 0:f1d3878b8dd9 242 RadioStatus set_io_sample_rate(const RemoteXBee& remote, float seconds);
vpcola 0:f1d3878b8dd9 243
vpcola 0:f1d3878b8dd9 244 /** set_power_level - sets the power level at which the radio will transmit
vpcola 0:f1d3878b8dd9 245 *
vpcola 0:f1d3878b8dd9 246 * @param level power level at which the radio will transmit
vpcola 0:f1d3878b8dd9 247 * @returns
vpcola 0:f1d3878b8dd9 248 * Success if the operation was successful,
vpcola 0:f1d3878b8dd9 249 * Failure otherwise
vpcola 0:f1d3878b8dd9 250 */
vpcola 0:f1d3878b8dd9 251 RadioStatus set_power_level(uint8_t level);
vpcola 0:f1d3878b8dd9 252
vpcola 0:f1d3878b8dd9 253 /** get_power_level - reads the power level configured in the radio
vpcola 0:f1d3878b8dd9 254 *
vpcola 0:f1d3878b8dd9 255 * @param level pointer where the read power level will be stored
vpcola 0:f1d3878b8dd9 256 * @returns
vpcola 0:f1d3878b8dd9 257 * Success if the operation was successful,
vpcola 0:f1d3878b8dd9 258 * Failure otherwise
vpcola 0:f1d3878b8dd9 259 */
vpcola 0:f1d3878b8dd9 260 RadioStatus get_power_level(uint8_t * const level);
vpcola 0:f1d3878b8dd9 261
vpcola 0:f1d3878b8dd9 262 /** get_hw_version - gets the hardware version of the radio
vpcola 0:f1d3878b8dd9 263 *
vpcola 0:f1d3878b8dd9 264 * @returns the hardware version of the radio
vpcola 0:f1d3878b8dd9 265 */
vpcola 0:f1d3878b8dd9 266 uint16_t get_hw_version() const;
vpcola 0:f1d3878b8dd9 267
vpcola 0:f1d3878b8dd9 268 /** get_fw_version - gets the firmware version of the radio
vpcola 0:f1d3878b8dd9 269 *
vpcola 0:f1d3878b8dd9 270 * @returns the firmware version of the radio
vpcola 0:f1d3878b8dd9 271 */
vpcola 0:f1d3878b8dd9 272 uint16_t get_fw_version() const;
vpcola 0:f1d3878b8dd9 273
vpcola 0:f1d3878b8dd9 274 /** set_node_identifier - configures the Node Identifier string
vpcola 0:f1d3878b8dd9 275 *
vpcola 0:f1d3878b8dd9 276 * @param node_id NULL-terminated string with the Node Identifier that will be set on the module. Up to 20 characters length (21 with NULL-terminator).
vpcola 0:f1d3878b8dd9 277 * @returns
vpcola 0:f1d3878b8dd9 278 * Success if the operation was successful,
vpcola 0:f1d3878b8dd9 279 * Failure otherwise
vpcola 0:f1d3878b8dd9 280 */
vpcola 0:f1d3878b8dd9 281 RadioStatus set_node_identifier(const char * const node_id);
vpcola 0:f1d3878b8dd9 282
vpcola 0:f1d3878b8dd9 283 /** get_node_identifier - reads the configured Node Identifier string
vpcola 0:f1d3878b8dd9 284 *
vpcola 0:f1d3878b8dd9 285 * @param node_id Pointer to where to store the read Node Identifier, it must point to a buffer with at least 21-bytes length.
vpcola 0:f1d3878b8dd9 286 * @returns
vpcola 0:f1d3878b8dd9 287 * Success if the operation was successful,
vpcola 0:f1d3878b8dd9 288 * Failure otherwise
vpcola 0:f1d3878b8dd9 289 */
vpcola 0:f1d3878b8dd9 290 RadioStatus get_node_identifier(char * const node_id);
vpcola 0:f1d3878b8dd9 291
vpcola 0:f1d3878b8dd9 292 /** enable_network_encryption - Enable network encryption.
vpcola 0:f1d3878b8dd9 293 *
vpcola 0:f1d3878b8dd9 294 * @param enable whether to enable this feature or not
vpcola 0:f1d3878b8dd9 295 * @returns
vpcola 0:f1d3878b8dd9 296 * Success if the operation was successful,
vpcola 0:f1d3878b8dd9 297 * Failure otherwise
vpcola 0:f1d3878b8dd9 298 */
vpcola 0:f1d3878b8dd9 299 RadioStatus enable_network_encryption(bool enable);
vpcola 0:f1d3878b8dd9 300
vpcola 0:f1d3878b8dd9 301 /** set_network_encryption_key - Sets the 128-bit AES key used for encryption and decryption. Setting it to 0 will cause the coordinator to transmit the network key in the clear to joining devices, and will cause joining devices to acquire the network key in the clear when joining.
vpcola 0:f1d3878b8dd9 302 * It is not recommended to set the key programmatically, because it could be read through the raw serial port bits.
vpcola 0:f1d3878b8dd9 303 * @param key pointer to the 128-bit AES key
vpcola 0:f1d3878b8dd9 304 * @param length size of the buffer pointed by 'key'
vpcola 0:f1d3878b8dd9 305 * @returns
vpcola 0:f1d3878b8dd9 306 * Success if the operation was successful,
vpcola 0:f1d3878b8dd9 307 * Failure otherwise
vpcola 0:f1d3878b8dd9 308 */
vpcola 0:f1d3878b8dd9 309 RadioStatus set_network_encryption_key(const uint8_t * const key, const uint16_t length);
vpcola 0:f1d3878b8dd9 310
vpcola 0:f1d3878b8dd9 311 /** start_node_discovery - starts a node discovery operation. The responses
vpcola 0:f1d3878b8dd9 312 * have to be processes on the callback function that have to be registered
vpcola 0:f1d3878b8dd9 313 * for that purpose.
vpcola 0:f1d3878b8dd9 314 *
vpcola 0:f1d3878b8dd9 315 * @returns
vpcola 0:f1d3878b8dd9 316 * Success if the operation was successful,
vpcola 0:f1d3878b8dd9 317 * Failure otherwise
vpcola 0:f1d3878b8dd9 318 */
vpcola 0:f1d3878b8dd9 319 RadioStatus start_node_discovery();
vpcola 0:f1d3878b8dd9 320
vpcola 0:f1d3878b8dd9 321 /** is_node_discovery_in_progress - checks if node discovery is in progress.
vpcola 0:f1d3878b8dd9 322 * @returns true if node discovery is in progress, false otherwise
vpcola 0:f1d3878b8dd9 323 */
vpcola 0:f1d3878b8dd9 324 bool is_node_discovery_in_progress();
vpcola 0:f1d3878b8dd9 325
vpcola 0:f1d3878b8dd9 326 #define XBEEZB_ND_OPTION_APPEND_DD (1 << 0)
vpcola 0:f1d3878b8dd9 327 #define XBEEZB_ND_OPTION_SELF_RESPONSE (1 << 1)
vpcola 0:f1d3878b8dd9 328 #define XBEE802_ND_OPTION_SELF_RESPONSE (1 << 0)
vpcola 0:f1d3878b8dd9 329 #define XBEEDM_ND_OPTION_APPEND_DD (1 << 0)
vpcola 0:f1d3878b8dd9 330 #define XBEEDM_ND_OPTION_SELF_RESPONSE (1 << 1)
vpcola 0:f1d3878b8dd9 331 #define XBEEDM_ND_OPTION_INCLUDE_RSSI (1 << 2)
vpcola 0:f1d3878b8dd9 332
vpcola 0:f1d3878b8dd9 333 /** config_node_discovery - configures the node discovery operation
vpcola 0:f1d3878b8dd9 334 *
vpcola 0:f1d3878b8dd9 335 * @param backoff_ms max allowed time for devices in the network to answer
vpcola 0:f1d3878b8dd9 336 * to the Node Discovery request
vpcola 0:f1d3878b8dd9 337 * @param options node discovery options (flags)
vpcola 0:f1d3878b8dd9 338 * XBEE802_ND_OPTION_SELF_RESPONSE - to allow the module self responding (802.15.4 only)
vpcola 0:f1d3878b8dd9 339 * XBEEZB_ND_OPTION_SELF_RESPONSE - to allow the module self responding (ZigBee only)
vpcola 0:f1d3878b8dd9 340 * XBEEZB_ND_OPTION_APPEND_DD - to append the DD value to the response (ZigBee only)
vpcola 0:f1d3878b8dd9 341 * XBEEDM_ND_OPTION_INCLUDE_RSSI - to include RSSI information in response (DigiMesh only)
vpcola 0:f1d3878b8dd9 342 * XBEEDM_ND_OPTION_SELF_RESPONSE - to allow the module self responding (DigiMesh only)
vpcola 0:f1d3878b8dd9 343 * XBEEDM_ND_OPTION_APPEND_DD - to append the DD value to the response (DigiMesh only)
vpcola 0:f1d3878b8dd9 344 * @returns
vpcola 0:f1d3878b8dd9 345 * Success if the operation was successful,
vpcola 0:f1d3878b8dd9 346 * Failure otherwise
vpcola 0:f1d3878b8dd9 347 */
vpcola 0:f1d3878b8dd9 348 RadioStatus config_node_discovery(uint16_t backoff_ms, uint8_t options = 0);
vpcola 0:f1d3878b8dd9 349
vpcola 0:f1d3878b8dd9 350 /** get_config_node_discovery - reads the configuration of the node discovery
vpcola 0:f1d3878b8dd9 351 * settings
vpcola 0:f1d3878b8dd9 352 *
vpcola 0:f1d3878b8dd9 353 * @param backoff_ms pointer where the configured node discovery back-off time value will be stored
vpcola 0:f1d3878b8dd9 354 * @param options pointer whre the node discovery options (flags) will be saved
vpcola 0:f1d3878b8dd9 355 * @returns
vpcola 0:f1d3878b8dd9 356 * Success if the operation was successful,
vpcola 0:f1d3878b8dd9 357 * Failure otherwise
vpcola 0:f1d3878b8dd9 358 */
vpcola 0:f1d3878b8dd9 359 RadioStatus get_config_node_discovery(uint16_t * const backoff_ms, uint8_t * const options);
vpcola 0:f1d3878b8dd9 360
vpcola 0:f1d3878b8dd9 361 /** set_timeout - sets the timeout in ms, used by sync methods
vpcola 0:f1d3878b8dd9 362 *
vpcola 0:f1d3878b8dd9 363 * @param timeout_ms new timeout in ms
vpcola 0:f1d3878b8dd9 364 */
vpcola 0:f1d3878b8dd9 365 void set_timeout(uint16_t timeout_ms);
vpcola 0:f1d3878b8dd9 366
vpcola 0:f1d3878b8dd9 367 /** get_timeout - gets the timeout in ms configured in the library. This value
vpcola 0:f1d3878b8dd9 368 * is used in sync commands
vpcola 0:f1d3878b8dd9 369 *
vpcola 0:f1d3878b8dd9 370 * @returns the configured timeout value in ms
vpcola 0:f1d3878b8dd9 371 */
vpcola 0:f1d3878b8dd9 372 uint16_t get_timeout() const;
vpcola 0:f1d3878b8dd9 373
vpcola 0:f1d3878b8dd9 374 /* ... */
vpcola 0:f1d3878b8dd9 375
vpcola 0:f1d3878b8dd9 376 /*********************** send_data member methods ************************/
vpcola 0:f1d3878b8dd9 377 /** send_data - sends data to a remote device
vpcola 0:f1d3878b8dd9 378 *
vpcola 0:f1d3878b8dd9 379 * @param remote remote device
vpcola 0:f1d3878b8dd9 380 * @param data pointer to the data that will be sent
vpcola 0:f1d3878b8dd9 381 * @param len number of bytes that will be transmitted
vpcola 0:f1d3878b8dd9 382 * @param syncr if true, method waits for the packet answer with the result of the operation
vpcola 0:f1d3878b8dd9 383 * @returns the result of the data transfer
vpcola 0:f1d3878b8dd9 384 * TxStatusSuccess if the operation was successful,
vpcola 0:f1d3878b8dd9 385 * the error code otherwise
vpcola 0:f1d3878b8dd9 386 */
vpcola 0:f1d3878b8dd9 387 virtual TxStatus send_data(const RemoteXBee& remote, const uint8_t *const data, uint16_t len, bool syncr = true) = 0;
vpcola 0:f1d3878b8dd9 388
vpcola 0:f1d3878b8dd9 389 /** send_data_broadcast - sends data to all devices in the network, using the broadcast address.
vpcola 0:f1d3878b8dd9 390 *
vpcola 0:f1d3878b8dd9 391 * @param data pointer to the data that will be sent
vpcola 0:f1d3878b8dd9 392 * @param len number of bytes that will be transmitted
vpcola 0:f1d3878b8dd9 393 * @param syncr if true, method waits for the packet answer with the result of the operation
vpcola 0:f1d3878b8dd9 394 * @returns the result of the data transfer
vpcola 0:f1d3878b8dd9 395 * TxStatusSuccess if the operation was successful,
vpcola 0:f1d3878b8dd9 396 * the error code otherwise
vpcola 0:f1d3878b8dd9 397 */
vpcola 0:f1d3878b8dd9 398 TxStatus send_data_broadcast(const uint8_t *const data, uint16_t len, bool syncr = true);
vpcola 0:f1d3878b8dd9 399
vpcola 0:f1d3878b8dd9 400 /** set_param - sets a parameter in the local radio by sending an AT command and waiting for the response.
vpcola 0:f1d3878b8dd9 401 *
vpcola 0:f1d3878b8dd9 402 * @param param parameter to be set.
vpcola 0:f1d3878b8dd9 403 * @param data the parameter value (4 bytes) to be set.
vpcola 0:f1d3878b8dd9 404 * @returns the command response status.
vpcola 0:f1d3878b8dd9 405 */
vpcola 0:f1d3878b8dd9 406 AtCmdFrame::AtCmdResp set_param(const char * const param, uint32_t data);
vpcola 0:f1d3878b8dd9 407
vpcola 0:f1d3878b8dd9 408 /** set_param - sets a parameter in the local radio by sending an AT command and waiting for the response.
vpcola 0:f1d3878b8dd9 409 *
vpcola 0:f1d3878b8dd9 410 * @param param parameter to be set.
vpcola 0:f1d3878b8dd9 411 * @param data the parameter value byte array (len bytes) to be set.
vpcola 0:f1d3878b8dd9 412 * @param len number of bytes of the parameter value.
vpcola 0:f1d3878b8dd9 413 * @returns the command response status.
vpcola 0:f1d3878b8dd9 414 */
vpcola 0:f1d3878b8dd9 415 AtCmdFrame::AtCmdResp set_param(const char * const param, const uint8_t * data = NULL, uint16_t len = 0);
vpcola 0:f1d3878b8dd9 416
vpcola 0:f1d3878b8dd9 417 /** get_param - gets a parameter from the local radio by sending an AT command and waiting for the response.
vpcola 0:f1d3878b8dd9 418 *
vpcola 0:f1d3878b8dd9 419 * @param param parameter to be get.
vpcola 0:f1d3878b8dd9 420 * @param data pointer where the param value (4 bytes) will be stored.
vpcola 0:f1d3878b8dd9 421 * @returns the command response status.
vpcola 0:f1d3878b8dd9 422 */
vpcola 0:f1d3878b8dd9 423 AtCmdFrame::AtCmdResp get_param(const char * const param, uint32_t * const data);
vpcola 0:f1d3878b8dd9 424
vpcola 0:f1d3878b8dd9 425 /** get_param - gets a parameter from the local radio by sending an AT command and waiting for the response.
vpcola 0:f1d3878b8dd9 426 *
vpcola 0:f1d3878b8dd9 427 * @param param parameter to be get.
vpcola 0:f1d3878b8dd9 428 * @param data pointer where the param value (n bytes) will be stored.
vpcola 0:f1d3878b8dd9 429 * @param len pointer where the number of bytes of the param value will be stored.
vpcola 0:f1d3878b8dd9 430 * @returns the command response status.
vpcola 0:f1d3878b8dd9 431 */
vpcola 0:f1d3878b8dd9 432 AtCmdFrame::AtCmdResp get_param(const char * const param, uint8_t * const data, uint16_t * const len);
vpcola 0:f1d3878b8dd9 433
vpcola 0:f1d3878b8dd9 434 /** set_param - sets a parameter in a remote radio by sending an AT command and waiting for the response.
vpcola 0:f1d3878b8dd9 435 *
vpcola 0:f1d3878b8dd9 436 * @param remote remote device
vpcola 0:f1d3878b8dd9 437 * @param param parameter to be set.
vpcola 0:f1d3878b8dd9 438 * @param data the parameter value (4 bytes) to be set.
vpcola 0:f1d3878b8dd9 439 * @returns the command response status.
vpcola 0:f1d3878b8dd9 440 */
vpcola 0:f1d3878b8dd9 441 virtual AtCmdFrame::AtCmdResp set_param(const RemoteXBee& remote, const char * const param, uint32_t data) = 0;
vpcola 0:f1d3878b8dd9 442
vpcola 0:f1d3878b8dd9 443 /** set_param - sets a parameter in a remote radio by sending an AT command and waiting for the response.
vpcola 0:f1d3878b8dd9 444 *
vpcola 0:f1d3878b8dd9 445 * @param remote remote device
vpcola 0:f1d3878b8dd9 446 * @param param parameter to be set.
vpcola 0:f1d3878b8dd9 447 * @param data the parameter value byte array (len bytes) to be set.
vpcola 0:f1d3878b8dd9 448 * @param len number of bytes of the parameter value.
vpcola 0:f1d3878b8dd9 449 * @returns the command response status.
vpcola 0:f1d3878b8dd9 450 */
vpcola 0:f1d3878b8dd9 451 virtual AtCmdFrame::AtCmdResp set_param(const RemoteXBee& remote, const char * const param, const uint8_t * data = NULL, uint16_t len = 0) = 0;
vpcola 0:f1d3878b8dd9 452
vpcola 0:f1d3878b8dd9 453 /** get_param - gets a parameter from a remote radio by sending an AT command and waiting for the response.
vpcola 0:f1d3878b8dd9 454 *
vpcola 0:f1d3878b8dd9 455 * @param remote remote device
vpcola 0:f1d3878b8dd9 456 * @param param parameter to be get.
vpcola 0:f1d3878b8dd9 457 * @param data pointer where the param value (4 bytes) will be stored.
vpcola 0:f1d3878b8dd9 458 * @returns the command response status.
vpcola 0:f1d3878b8dd9 459 */
vpcola 0:f1d3878b8dd9 460 virtual AtCmdFrame::AtCmdResp get_param(const RemoteXBee& remote, const char * const param, uint32_t * const data) = 0;
vpcola 0:f1d3878b8dd9 461
vpcola 0:f1d3878b8dd9 462 /** get_param - gets a parameter from a remote radio by sending an AT command and waiting for the response.
vpcola 0:f1d3878b8dd9 463 *
vpcola 0:f1d3878b8dd9 464 * @param remote remote device
vpcola 0:f1d3878b8dd9 465 * @param param parameter to be get.
vpcola 0:f1d3878b8dd9 466 * @param data pointer where the param value (n bytes) will be stored.
vpcola 0:f1d3878b8dd9 467 * @param len pointer where the number of bytes of the param value will be stored.
vpcola 0:f1d3878b8dd9 468 * @returns the command response status.
vpcola 0:f1d3878b8dd9 469 */
vpcola 0:f1d3878b8dd9 470 virtual AtCmdFrame::AtCmdResp get_param(const RemoteXBee& remote, const char * const param, uint8_t * const data, uint16_t * const len) = 0;
vpcola 0:f1d3878b8dd9 471
vpcola 0:f1d3878b8dd9 472 /** process_rx_frames - method that processes the frames queued in the reception
vpcola 0:f1d3878b8dd9 473 * buffer. Calls the process_frame_data method of the frame
vpcola 0:f1d3878b8dd9 474 * handlers registered
vpcola 0:f1d3878b8dd9 475 *
vpcola 0:f1d3878b8dd9 476 * @returns Number of dropped frames since latest call to this method.
vpcola 0:f1d3878b8dd9 477 */
vpcola 0:f1d3878b8dd9 478 uint32_t process_rx_frames();
vpcola 0:f1d3878b8dd9 479
vpcola 0:f1d3878b8dd9 480 /** register_modem_status_cb - registers the callback function that will be called
vpcola 0:f1d3878b8dd9 481 * when a Modem Status packet is received
vpcola 0:f1d3878b8dd9 482 *
vpcola 0:f1d3878b8dd9 483 * @param function function pointer with the callback function
vpcola 0:f1d3878b8dd9 484 */
vpcola 0:f1d3878b8dd9 485 void register_modem_status_cb(modem_status_cb_t function);
vpcola 0:f1d3878b8dd9 486
vpcola 0:f1d3878b8dd9 487 /** unregister_modem_status_cb - removes the Modem Status reception callback */
vpcola 0:f1d3878b8dd9 488 void unregister_modem_status_cb();
vpcola 0:f1d3878b8dd9 489
vpcola 0:f1d3878b8dd9 490 protected:
vpcola 0:f1d3878b8dd9 491
vpcola 0:f1d3878b8dd9 492 #define EXTRA_XBEE_PROTOCOLS
vpcola 0:f1d3878b8dd9 493
vpcola 0:f1d3878b8dd9 494 enum RadioProtocol {
vpcola 0:f1d3878b8dd9 495 None,
vpcola 0:f1d3878b8dd9 496 ZigBee,
vpcola 0:f1d3878b8dd9 497 Raw_802_15_4,
vpcola 0:f1d3878b8dd9 498 #ifdef EXTRA_XBEE_PROTOCOLS
vpcola 0:f1d3878b8dd9 499 XBeeWiFi,
vpcola 0:f1d3878b8dd9 500 DigiMesh,
vpcola 0:f1d3878b8dd9 501 SmartEnergy,
vpcola 0:f1d3878b8dd9 502 DigiPoint,
vpcola 0:f1d3878b8dd9 503 ZNet,
vpcola 0:f1d3878b8dd9 504 #endif
vpcola 0:f1d3878b8dd9 505 };
vpcola 0:f1d3878b8dd9 506 /** send_byte_escaping_if - sends a byte, through the serial interface, to
vpcola 0:f1d3878b8dd9 507 * the radio, escaping the byte if the working mode of the radio is API2.
vpcola 0:f1d3878b8dd9 508 *
vpcola 0:f1d3878b8dd9 509 * @param line PWM line being set
vpcola 0:f1d3878b8dd9 510 * @param data the byte that will be send to radio
vpcola 0:f1d3878b8dd9 511 */
vpcola 0:f1d3878b8dd9 512 void send_byte_escaping_if(uint8_t data);
vpcola 0:f1d3878b8dd9 513
vpcola 0:f1d3878b8dd9 514 /** uart_read_cb - serial interface callback, called when data is received on
vpcola 0:f1d3878b8dd9 515 * the serial port. The function parses the incoming data and, when a good
vpcola 0:f1d3878b8dd9 516 * frame is detected, saves it in the frame list
vpcola 0:f1d3878b8dd9 517 */
vpcola 0:f1d3878b8dd9 518 void uart_read_cb();
vpcola 0:f1d3878b8dd9 519
vpcola 0:f1d3878b8dd9 520 /** get_this_api_frame - searches in the FrameBuffer for an incoming frame
vpcola 0:f1d3878b8dd9 521 * with frameid equal to id and frame type equal to type
vpcola 0:f1d3878b8dd9 522 * or type2. If after timeout the frame hast not been found,
vpcola 0:f1d3878b8dd9 523 * returns.
vpcola 0:f1d3878b8dd9 524 *
vpcola 0:f1d3878b8dd9 525 * @param id id of the frame we are looking for.
vpcola 0:f1d3878b8dd9 526 * @param type tye type we expect the frame to be.
vpcola 0:f1d3878b8dd9 527 * @param type2 alternative valid type, if provided.
vpcola 0:f1d3878b8dd9 528 * @returns a pointer to the frame found in the FrameBuffer or a null pointer if
vpcola 0:f1d3878b8dd9 529 * the frame has not been found and the timeout expired.
vpcola 0:f1d3878b8dd9 530 */
vpcola 0:f1d3878b8dd9 531 ApiFrame * get_this_api_frame(uint8_t id, ApiFrame::ApiFrameType type,
vpcola 0:f1d3878b8dd9 532 ApiFrame::ApiFrameType type2 = ApiFrame::Invalid);
vpcola 0:f1d3878b8dd9 533
vpcola 0:f1d3878b8dd9 534 /** send_api_frame - method to send, over the serial port, an API frame
vpcola 0:f1d3878b8dd9 535 *
vpcola 0:f1d3878b8dd9 536 * @param frame pointer to the frame that will be sent.
vpcola 0:f1d3878b8dd9 537 */
vpcola 0:f1d3878b8dd9 538 #if defined(UNIT_TEST)
vpcola 0:f1d3878b8dd9 539 virtual
vpcola 0:f1d3878b8dd9 540 #endif
vpcola 0:f1d3878b8dd9 541 void send_api_frame(ApiFrame *frame);
vpcola 0:f1d3878b8dd9 542
vpcola 0:f1d3878b8dd9 543 /** update_radio_status - method called when a modem status frame is received
vpcola 0:f1d3878b8dd9 544 * to update the internal status variables of the library.
vpcola 0:f1d3878b8dd9 545 * @note This is not a pure virtual function because it can be called while
vpcola 0:f1d3878b8dd9 546 * the object is being constructed and we need the implementation of the
vpcola 0:f1d3878b8dd9 547 * base class.
vpcola 0:f1d3878b8dd9 548 *
vpcola 0:f1d3878b8dd9 549 * @param status byte with the status received in the modem status frame
vpcola 0:f1d3878b8dd9 550 */
vpcola 0:f1d3878b8dd9 551 virtual void radio_status_update(AtCmdFrame::ModemStatus modem_status);
vpcola 0:f1d3878b8dd9 552
vpcola 0:f1d3878b8dd9 553 /** Method used internaly by the derived classes to transmit data to
vpcola 0:f1d3878b8dd9 554 * remote nodes, waiting for the answer from the device
vpcola 0:f1d3878b8dd9 555 *
vpcola 0:f1d3878b8dd9 556 * @param frame frame that will be sent to the radio (have to be a
vpcola 0:f1d3878b8dd9 557 * proper transmit frame
vpcola 0:f1d3878b8dd9 558 * @returns the result of the data transfer
vpcola 0:f1d3878b8dd9 559 * TxStatusSuccess if the operation was successful,
vpcola 0:f1d3878b8dd9 560 * the error code otherwise
vpcola 0:f1d3878b8dd9 561 */
vpcola 0:f1d3878b8dd9 562 TxStatus send_data(ApiFrame *frame);
vpcola 0:f1d3878b8dd9 563
vpcola 0:f1d3878b8dd9 564 /** send_at_cmd - sends an AT command to the radio and waits for the response.
vpcola 0:f1d3878b8dd9 565 *
vpcola 0:f1d3878b8dd9 566 * @param frame api frame with the command and command params.
vpcola 0:f1d3878b8dd9 567 * @param buf pointer where the param response (n bytes) will be stored.
vpcola 0:f1d3878b8dd9 568 * @param len pointer where the number of bytes of the param response will be stored.
vpcola 0:f1d3878b8dd9 569 * @param radio_location radio location, either RadioLocal or RadioRemote.
vpcola 0:f1d3878b8dd9 570 * @param reverse reverse the byte ordering of the response saved in buf.
vpcola 0:f1d3878b8dd9 571 * @returns the command response status.
vpcola 0:f1d3878b8dd9 572 */
vpcola 0:f1d3878b8dd9 573 AtCmdFrame::AtCmdResp send_at_cmd(AtCmdFrame *frame,
vpcola 0:f1d3878b8dd9 574 uint8_t *const buf, uint16_t *const len, RadioLocation radio_location = RadioLocal, bool reverse = true);
vpcola 0:f1d3878b8dd9 575
vpcola 0:f1d3878b8dd9 576 /* send_at_cmd - methods used internally by other methods */
vpcola 0:f1d3878b8dd9 577 AtCmdFrame::AtCmdResp send_at_cmd(AtCmdFrame *frame);
vpcola 0:f1d3878b8dd9 578 AtCmdFrame::AtCmdResp send_at_cmd(AtCmdFrame *frame, uint8_t *data);
vpcola 0:f1d3878b8dd9 579 AtCmdFrame::AtCmdResp send_at_cmd(AtCmdFrame *frame, uint16_t *data);
vpcola 0:f1d3878b8dd9 580 AtCmdFrame::AtCmdResp send_at_cmd(AtCmdFrame *frame, uint32_t *data);
vpcola 0:f1d3878b8dd9 581
vpcola 0:f1d3878b8dd9 582 /** register_frame_handler - registers an object to handle incoming frames from
vpcola 0:f1d3878b8dd9 583 * the radio.
vpcola 0:f1d3878b8dd9 584 * @note For any type of frame more than one handler can be registered and all
vpcola 0:f1d3878b8dd9 585 * of them are called, sequentially, when a frame of that type arrives.
vpcola 0:f1d3878b8dd9 586 *
vpcola 0:f1d3878b8dd9 587 * @param handler pointer to the frame handler object
vpcola 0:f1d3878b8dd9 588 * @returns the result of the registration
vpcola 0:f1d3878b8dd9 589 * Success if the operation was successful,
vpcola 0:f1d3878b8dd9 590 * Failure otherwise
vpcola 0:f1d3878b8dd9 591 */
vpcola 0:f1d3878b8dd9 592 RadioStatus register_frame_handler(FrameHandler *const handler);
vpcola 0:f1d3878b8dd9 593
vpcola 0:f1d3878b8dd9 594 /** unregister_frame_handler - removes a previously registered frame handler
vpcola 0:f1d3878b8dd9 595 *
vpcola 0:f1d3878b8dd9 596 * @param handler pointer to the frame handler object
vpcola 0:f1d3878b8dd9 597 * @returns the result of the unregister operation
vpcola 0:f1d3878b8dd9 598 * Success if the operation was successful,
vpcola 0:f1d3878b8dd9 599 * Failure otherwise
vpcola 0:f1d3878b8dd9 600 */
vpcola 0:f1d3878b8dd9 601 RadioStatus unregister_frame_handler(FrameHandler *const handler);
vpcola 0:f1d3878b8dd9 602
vpcola 0:f1d3878b8dd9 603 /** get_radio_protocol - returns the RF protocol that the connected module uses
vpcola 0:f1d3878b8dd9 604 * based on its firmware and hardware versions
vpcola 0:f1d3878b8dd9 605 *
vpcola 0:f1d3878b8dd9 606 * @returns a RadioProtocol enum.
vpcola 0:f1d3878b8dd9 607 */
vpcola 0:f1d3878b8dd9 608 RadioProtocol get_radio_protocol(void) const;
vpcola 0:f1d3878b8dd9 609
vpcola 0:f1d3878b8dd9 610 /** _get_iosample - forces an io_sample read (reads all digital and analog inputs)
vpcola 0:f1d3878b8dd9 611 *
vpcola 0:f1d3878b8dd9 612 * @param remote remote device
vpcola 0:f1d3878b8dd9 613 * @param io_sample buffer where the io_sample response is copied
vpcola 0:f1d3878b8dd9 614 * @param len pointer where the length of the io_sample response is stored
vpcola 0:f1d3878b8dd9 615 * @returns
vpcola 0:f1d3878b8dd9 616 * Success if the operation was successful,
vpcola 0:f1d3878b8dd9 617 * Failure otherwise
vpcola 0:f1d3878b8dd9 618 */
vpcola 0:f1d3878b8dd9 619 RadioStatus _get_iosample(const RemoteXBee& remote, uint8_t * const io_sample, uint16_t * const len);
vpcola 0:f1d3878b8dd9 620
vpcola 0:f1d3878b8dd9 621 void _get_remote_node_by_id(const char * const node_id, uint64_t * addr64, uint16_t * addr16);
vpcola 0:f1d3878b8dd9 622
vpcola 0:f1d3878b8dd9 623 /** check_radio_flow_control - checks that the radio has the CTS "D7" and RTS "D6" pins configured
vpcola 0:f1d3878b8dd9 624 * according to the serial hardware flow control selected by the user
vpcola 0:f1d3878b8dd9 625 *
vpcola 0:f1d3878b8dd9 626 * @returns true if check success.
vpcola 0:f1d3878b8dd9 627 */
vpcola 0:f1d3878b8dd9 628 bool check_radio_flow_control();
vpcola 0:f1d3878b8dd9 629
vpcola 0:f1d3878b8dd9 630 /** get_AI - reads the AI parameter.
vpcola 0:f1d3878b8dd9 631 *
vpcola 0:f1d3878b8dd9 632 * @returns
vpcola 0:f1d3878b8dd9 633 * -1 if an error occurred when reading AI.
vpcola 0:f1d3878b8dd9 634 * 0-0xFF the AI value.
vpcola 0:f1d3878b8dd9 635 */
vpcola 0:f1d3878b8dd9 636 int get_AI(void);
vpcola 0:f1d3878b8dd9 637
vpcola 0:f1d3878b8dd9 638 /** get_node_discovery_timeout - gets the node discovery timeout
vpcola 0:f1d3878b8dd9 639 *
vpcola 0:f1d3878b8dd9 640 * @param timeout_ms pointer where the node discovery timeout value will be stored
vpcola 0:f1d3878b8dd9 641 * @param wait_for_complete_timeout pointer where the function will store if the operator
vpcola 0:f1d3878b8dd9 642 * has to wait for the complete nd timeout after issuing
vpcola 0:f1d3878b8dd9 643 * a directed nd request
vpcola 0:f1d3878b8dd9 644 * @returns
vpcola 0:f1d3878b8dd9 645 * Success if the operation was successful,
vpcola 0:f1d3878b8dd9 646 * Failure otherwise
vpcola 0:f1d3878b8dd9 647 */
vpcola 0:f1d3878b8dd9 648 virtual RadioStatus get_node_discovery_timeout(uint16_t * const timeout_ms) = 0;
vpcola 0:f1d3878b8dd9 649 virtual RadioStatus get_node_discovery_timeout(uint16_t * const timeout_ms, bool * const wait_for_complete_timeout) = 0;
vpcola 0:f1d3878b8dd9 650
vpcola 0:f1d3878b8dd9 651 /** serial hardware flow control selected by the user (RTSCTS, RTS,CTS) */
vpcola 0:f1d3878b8dd9 652 SerialBase::Flow _serial_flow_type;
vpcola 0:f1d3878b8dd9 653
vpcola 0:f1d3878b8dd9 654 /** Operating mode of the module (API1, API2,...) */
vpcola 0:f1d3878b8dd9 655 RadioMode _mode;
vpcola 0:f1d3878b8dd9 656
vpcola 0:f1d3878b8dd9 657 /** Hardware version value of the radio */
vpcola 0:f1d3878b8dd9 658 uint16_t _hw_version;
vpcola 0:f1d3878b8dd9 659
vpcola 0:f1d3878b8dd9 660 /** Firmware version value of the radio */
vpcola 0:f1d3878b8dd9 661 uint16_t _fw_version;
vpcola 0:f1d3878b8dd9 662
vpcola 0:f1d3878b8dd9 663 /** Timeout in ms for sync operations (when we wait for a response) */
vpcola 0:f1d3878b8dd9 664 uint16_t _timeout_ms;
vpcola 0:f1d3878b8dd9 665
vpcola 0:f1d3878b8dd9 666 /** Device 64 bit address (SH, SL) */
vpcola 0:f1d3878b8dd9 667 uint64_t _dev_addr64;
vpcola 0:f1d3878b8dd9 668
vpcola 0:f1d3878b8dd9 669 /** Serial Interface, use RawSerial as we dont use the streams */
vpcola 0:f1d3878b8dd9 670 RawSerial *_uart;
vpcola 0:f1d3878b8dd9 671
vpcola 0:f1d3878b8dd9 672 /** IO connected to the radio reset line */
vpcola 0:f1d3878b8dd9 673 DigitalOut *_reset;
vpcola 0:f1d3878b8dd9 674
vpcola 0:f1d3878b8dd9 675 /** Transmit options byte */
vpcola 0:f1d3878b8dd9 676 uint8_t _tx_options;
vpcola 0:f1d3878b8dd9 677
vpcola 0:f1d3878b8dd9 678 /** Array of frame handler pointers. We use an array instead of a vector or other
vpcola 0:f1d3878b8dd9 679 * data structure to save memory and avoid dynamic memory allocation, to avoid
vpcola 0:f1d3878b8dd9 680 * memory fragmentation */
vpcola 0:f1d3878b8dd9 681 FrameHandler *_fhandlers[MAX_FRAME_HANDLERS];
vpcola 0:f1d3878b8dd9 682
vpcola 0:f1d3878b8dd9 683 /** Hardware reset counter, automatically updated by the library */
vpcola 0:f1d3878b8dd9 684 volatile uint16_t _hw_reset_cnt;
vpcola 0:f1d3878b8dd9 685
vpcola 0:f1d3878b8dd9 686 /** Watchdog reset counter, automatically updated by the library */
vpcola 0:f1d3878b8dd9 687 volatile uint16_t _wd_reset_cnt;
vpcola 0:f1d3878b8dd9 688
vpcola 0:f1d3878b8dd9 689 /** Frame handler used for the Modem Status packets. Automatically registered when a callback
vpcola 0:f1d3878b8dd9 690 * function is registered */
vpcola 0:f1d3878b8dd9 691 FH_ModemStatus *_modem_status_handler;
vpcola 0:f1d3878b8dd9 692
vpcola 0:f1d3878b8dd9 693 /** Latest modem status received */
vpcola 0:f1d3878b8dd9 694 AtCmdFrame::ModemStatus _modem_status;
vpcola 0:f1d3878b8dd9 695
vpcola 0:f1d3878b8dd9 696 /** Library is initializing */
vpcola 0:f1d3878b8dd9 697 bool _initializing;
vpcola 0:f1d3878b8dd9 698
vpcola 0:f1d3878b8dd9 699 /** Timer used for node discovery */
vpcola 0:f1d3878b8dd9 700 Timer _nd_timer;
vpcola 0:f1d3878b8dd9 701
vpcola 0:f1d3878b8dd9 702 /** node discovery timeout */
vpcola 0:f1d3878b8dd9 703 int _nd_timeout;
vpcola 0:f1d3878b8dd9 704
vpcola 0:f1d3878b8dd9 705 /** If a _get_remote_node_by_id() is in progress, this keeps the expected frame id */
vpcola 0:f1d3878b8dd9 706 uint8_t _node_by_ni_frame_id;
vpcola 0:f1d3878b8dd9 707 };
vpcola 0:f1d3878b8dd9 708
vpcola 0:f1d3878b8dd9 709 } /* namespace XBeeLib */
vpcola 0:f1d3878b8dd9 710
vpcola 0:f1d3878b8dd9 711 #endif /* defined(__DIGI_RADIO_H_) */
vpcola 0:f1d3878b8dd9 712
vpcola 0:f1d3878b8dd9 713
vpcola 0:f1d3878b8dd9 714