Fork of my original MQTTGateway

Dependencies:   mbed-http

Committer:
vpcola
Date:
Sat Apr 08 14:43:14 2017 +0000
Revision:
0:a1734fe1ec4b
Initial commit

Who changed what in which revision?

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