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