Library to easily communicate with XBee modules.

Dependencies:   DigiLogger

Dependents:   WaterLogger XbeeGateway XBee_Cooker ProjetReceiver ... more

Use XBee radio modules to easily improve your project with wireless connectivity. You can enable entire networks of connected devices. XBees can exchange data with other modules in the network and configure remote modules as well as trigger actions or collect sensor data on XBee nodes without needing additional external microcontrollers. Using this documentation and configuration tools with XBee modules, it is easy to develop these types of applications and more.

/media/uploads/spastor/xbee-xbeepro-series1.jpg

The XBee mbed Library is a ready-to-import mbed extension that dramatically reduces development time for XBee projects on the mbed platforms. There are many modular examples, making it an easy and smooth process to add wireless networking to a whole range of useful applications.

Info

Currently 802.15.4 (Series 1 and 2), ZigBee (Series 2) and DigiMesh (Series 1 and 2) modules are supported. The libraries can be extended to support other protocols like DigiMesh point-to-point, WiFi, etc.

User manual

The user manual can be found at this project's Wiki pages:

  1. Configuring the library
  2. Debugging the library
  3. Initializing modules
  4. Resetting the local module
  5. Receiving Data from other module
  6. Sending data to another module
  7. Discovering nodes in the network
  8. Configuring local and remote modules
  9. Handling modem status changes
  10. Handling remote modules DIOs, ADCs and PWMs
  11. Handling IO Data Samples from other module
  12. Radio Power Management

Ready to use examples

There are a lot of ready to use examples to get started quickly.
Make sure you have a valid example setup before running the examples:

Examples for ZigBee modules

Import programXBeeZB_Receive_Data

ZigBee Receive Data example for mbed XBeeLib By Digi

Import programXBeeZB_Send_Data

ZigBee Send Data example for mbed XBeeLib By Digi

Import programXBeeZB_module_config

ZigBee network configuration example for mbed XBeeLib By Digi

Import programXBeeZB_AT_Commands

ZigBee AT Commands example for mbed XBeeLib By Digi

Import programXBeeZB_dio_adc

ZigBee DIOs and ADCs example for mbed XBeeLib By Digi

Import programXBeeZB_IO_Sample_Callback

ZigBee IO Sampling Callback example for mbed XBeeLib By Digi

Import programXBeeZB_modem_status

ZigBee Modem Status example for mbed XBeeLib By Digi

Import programXBeeZB_node_discovery

ZigBee Node Discovery example for mbed XBeeLib By Digi

Import programXBeeZB_power_mngmnt_cyclic_sleep

ZigBee Power Management using Cyclic Sleep example for mbed XBeeLib By Digi

Import programXBeeZB_power_mngmnt_pin_sleep

ZigBee Power Management using Pin Sleep example for mbed XBeeLib By Digi

Examples for 802.15.4 modules

Import programXBee802_Receive_Data

802.15.4 Receive Data example for mbed XBeeLib By Digi

Import programXBee802_Send_Data

802.15.4 Send Data example for mbed XBeeLib By Digi

Import programXBee802_module_config

802.15.4 network configuration example for mbed XBeeLib By Digi

Import programXBee802_AT_Commands

802.15.4 AT Commands example for mbed XBeeLib By Digi

Import programXBee802_dio_adc_pwm

802.15.4 DIOs, ADCs and PWM example for mbed XBeeLib By Digi

Import programXBee802_IO_Sample_Callback

802.15.4 IO Sampling Callback example for mbed XBeeLib By Digi

Import programXBee802_node_discovery

802.15.4 Node Discovery example for mbed XBeeLib By Digi

Import programXBee802_power_mngmnt_cyclic_sleep

802.15.4 Power Management using Cyclic Sleep example for mbed XBeeLib By Digi

Import programXBee802_power_mngmnt_pin_sleep

802.15.4 Power Management using Pin Sleep example for mbed XBeeLib By Digi

Examples for DigiMesh modules

Import programXBeeDM_Receive_Data

DigiMesh Receive Data example for mbed XBeeLib By Digi

Import programXBeeDM_Send_Data

DigiMesh Send Data example for mbed XBeeLib By Digi

Import programXBeeDM_module_config

DigiMesh network configuration example for mbed XBeeLib By Digi

Import programXBeeDM_AT_Commands

DigiMesh AT Commands example for mbed XBeeLib By Digi

Import programXBeeDM_dio_adc_pwm

DigiMEsh DIOs, ADCs and PWMs example for mbed XBeeLib By Digi

Import programXBeeDM_IO_Sample_Callback

DigiMesh IO Sampling Callback example for mbed XBeeLib By Digi

Import programXBeeDM_modem_status

DigiMesh Modem Status example for mbed XBeeLib By Digi

Import programXBeeDM_node_discovery

DigiMesh Node Discovery example for mbed XBeeLib By Digi

Import programXBeeDM_power_mngmnt_asyncr_cyclic_sleep

DigiMesh Power Management using Asynchronous Cyclic Sleep example for mbed XBeeLib By Digi

Import programXBeeDM_power_mngmnt_pin_sleep

DigiMesh Power Management using Pin Sleep example for mbed XBeeLib By Digi

Committer:
hbujanda
Date:
Mon May 11 17:58:00 2015 +0200
Revision:
1:794d1d3e4a08
Parent:
0:fcaad0dfa051
Child:
2:2ee1b6d51df2
Automatic upload

Who changed what in which revision?

UserRevisionLine numberNew 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 0:fcaad0dfa051 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 OpNotSupported = -2, /**< Option Not Supported */
spastor 0:fcaad0dfa051 56 };
spastor 0:fcaad0dfa051 57 /**
spastor 0:fcaad0dfa051 58 * @}
spastor 0:fcaad0dfa051 59 */
spastor 0:fcaad0dfa051 60
spastor 0:fcaad0dfa051 61 /**
spastor 0:fcaad0dfa051 62 * @defgroup RadioType
spastor 0:fcaad0dfa051 63 * @{
spastor 0:fcaad0dfa051 64 */
spastor 0:fcaad0dfa051 65 /**
spastor 0:fcaad0dfa051 66 * RadioType
spastor 0:fcaad0dfa051 67 */
spastor 0:fcaad0dfa051 68 enum RadioType {
spastor 0:fcaad0dfa051 69 Unknown = 0, /**< Not detected yet */
spastor 0:fcaad0dfa051 70 XB24_A_S1 = 0x17, /**< S1 */
spastor 0:fcaad0dfa051 71 XBP24_A_S1 = 0x18, /**< S1 */
spastor 0:fcaad0dfa051 72 XB24_B_S2 = 0x19, /**< S2 */
spastor 0:fcaad0dfa051 73 XBP24_B_S2 = 0x1A, /**< S2 */
spastor 0:fcaad0dfa051 74 XBP09_D = 0x1B, /**< S4 */
spastor 0:fcaad0dfa051 75 XBP09_XC = 0x1C, /**< S3 */
spastor 0:fcaad0dfa051 76 XBP08_D = 0x1D, /**< 868MHz S5 */
spastor 0:fcaad0dfa051 77 XBP24_B_S2B = 0x1E, /**< S2B */
spastor 0:fcaad0dfa051 78 XB24_WF = 0x1F, /**< S6 */
spastor 0:fcaad0dfa051 79 XBP24_C_SMT = 0x21, /**< XBee PRO SMT S2C */
spastor 0:fcaad0dfa051 80 XB24_C_SMT = 0x22, /**< XBee SMT S2C */
spastor 0:fcaad0dfa051 81 XBP09_XC_B = 0x23, /**< S3B */
spastor 0:fcaad0dfa051 82 XBP09_B = 0x23, /**< S3B */
spastor 0:fcaad0dfa051 83 XB8 = 0x24, /**< S8 */
spastor 0:fcaad0dfa051 84 XB2B_WF_TH = 0x27, /**< S6B TH */
spastor 0:fcaad0dfa051 85 XB2B_WF_SMT = 0x28, /**< S6B SMT */
spastor 0:fcaad0dfa051 86 XBP24_C_TH = 0x2D, /**< S2C TH */
spastor 0:fcaad0dfa051 87 XB24_C_TH = 0x2E, /**< S2C TH */
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 TxStatus
spastor 0:fcaad0dfa051 95 * @{
spastor 0:fcaad0dfa051 96 */
spastor 0:fcaad0dfa051 97 /**
spastor 0:fcaad0dfa051 98 * TxStatus
spastor 0:fcaad0dfa051 99 */
spastor 0:fcaad0dfa051 100 enum TxStatus {
spastor 0:fcaad0dfa051 101 TxStatusSuccess = 0, /**< Success */
spastor 0:fcaad0dfa051 102 TxStatusAckFail = 1, /**< MAC ACK Failure */
spastor 0:fcaad0dfa051 103 TxStatusCCAFail = 2, /**< CCA Failure */
spastor 0:fcaad0dfa051 104 TxStatusInvDestEP = 0x15, /**< Invalid destination endpoint */
spastor 0:fcaad0dfa051 105 TxStatusNwAckFail = 0x21, /**< Network ACK Failure */
spastor 0:fcaad0dfa051 106 TxStatusNotJoinNw = 0x22, /**< Not Joined to Network */
spastor 0:fcaad0dfa051 107 TxStatusSelfAddr = 0x23, /**< Self-addressed */
spastor 0:fcaad0dfa051 108 TxStatusAddrNotFound = 0x24, /**< Address Not Found */
spastor 0:fcaad0dfa051 109 TxStatusRouteNotFound = 0x25, /**< Route Not Found */
spastor 0:fcaad0dfa051 110 TxStatusBroadSrcFail2Heard = 0x26, /**< Broadcast source failed to hear a neighbor relay the message */
spastor 0:fcaad0dfa051 111 TxStatusInvBindTableIdx = 0x2B, /**< Invalid binding table index */
spastor 0:fcaad0dfa051 112 TxStatusResourceError = 0x2C, /**< Resource error lack of free buffers, timers, etc. */
spastor 0:fcaad0dfa051 113 TxStatusAttBroadcWithAPS = 0x2D, /**< Attempted broadcast with APS transmission */
spastor 0:fcaad0dfa051 114 TxStatusAttUnicWithAPSEE0 = 0x2E, /**< Attempted unicast with APS transmission, but EE=0 */
spastor 0:fcaad0dfa051 115 TxStatusResourceError2 = 0x31, /**< TxStatusResourceError2 */
spastor 0:fcaad0dfa051 116 TxStatusInternalError = 0x32, /**< Resource error lack of free buffers, timers, etc. */
spastor 0:fcaad0dfa051 117 TxStatusPayloadTooLarge = 0x74, /**< Data payload too large */
spastor 0:fcaad0dfa051 118 TxStatusIndirectMsgUnReq = 0x75, /**< Indirect message unrequested */
spastor 0:fcaad0dfa051 119 TxStatusInvalidAddr = 0xfe, /**< Invalid Address (Error generated by the library) */
spastor 0:fcaad0dfa051 120 TxStatusTimeout = 0xff, /**< Timeout (Error generated by the library) */
spastor 0:fcaad0dfa051 121 };
spastor 0:fcaad0dfa051 122 /**
spastor 0:fcaad0dfa051 123 * @}
spastor 0:fcaad0dfa051 124 */
spastor 0:fcaad0dfa051 125
spastor 0:fcaad0dfa051 126 /**
spastor 0:fcaad0dfa051 127 * @defgroup PmMode
spastor 0:fcaad0dfa051 128 * @{
spastor 0:fcaad0dfa051 129 */
spastor 0:fcaad0dfa051 130 /**
spastor 0:fcaad0dfa051 131 * PmMode
spastor 0:fcaad0dfa051 132 */
spastor 0:fcaad0dfa051 133 enum PmMode {
spastor 0:fcaad0dfa051 134 SleepDisabled = 0, /**< SleepDisabled */
spastor 0:fcaad0dfa051 135 PinSleep = 1, /**< PinSleep */
spastor 0:fcaad0dfa051 136 PinDoze = 2, /**< PinDoze */
spastor 0:fcaad0dfa051 137 CyclicSeleep = 4, /**< CyclicSeleep */
spastor 0:fcaad0dfa051 138 CyclicSeleepPinW = 5, /**< CyclicSeleepPinW */
spastor 0:fcaad0dfa051 139 };
spastor 0:fcaad0dfa051 140 /**
spastor 0:fcaad0dfa051 141 * @}
spastor 0:fcaad0dfa051 142 */
spastor 0:fcaad0dfa051 143
spastor 0:fcaad0dfa051 144 /**
spastor 0:fcaad0dfa051 145 * @defgroup NetworkRole
spastor 0:fcaad0dfa051 146 * @{
spastor 0:fcaad0dfa051 147 */
spastor 0:fcaad0dfa051 148 /**
spastor 0:fcaad0dfa051 149 * NetworkRole
spastor 0:fcaad0dfa051 150 */
spastor 0:fcaad0dfa051 151 enum NetworkRole {
spastor 0:fcaad0dfa051 152 UnknownRole, /**< Unknown Role */
spastor 0:fcaad0dfa051 153 Coordinator, /**< Coordinator */
spastor 0:fcaad0dfa051 154 Router, /**< Router */
spastor 0:fcaad0dfa051 155 EndDevice, /**< EndDevice */
spastor 0:fcaad0dfa051 156 };
spastor 0:fcaad0dfa051 157 /**
spastor 0:fcaad0dfa051 158 * @}
spastor 0:fcaad0dfa051 159 */
spastor 0:fcaad0dfa051 160
spastor 0:fcaad0dfa051 161 /**
spastor 0:fcaad0dfa051 162 * @defgroup RadioLocation
spastor 0:fcaad0dfa051 163 * @{
spastor 0:fcaad0dfa051 164 */
spastor 0:fcaad0dfa051 165 /**
spastor 0:fcaad0dfa051 166 * RadioLocation
spastor 0:fcaad0dfa051 167 */
spastor 0:fcaad0dfa051 168 enum RadioLocation {
spastor 0:fcaad0dfa051 169 RadioLocal = 0, /**< Local Radio */
spastor 0:fcaad0dfa051 170 RadioRemote = 1, /**< Remote Radio */
spastor 0:fcaad0dfa051 171 };
spastor 0:fcaad0dfa051 172 /**
spastor 0:fcaad0dfa051 173 * @}
spastor 0:fcaad0dfa051 174 */
spastor 0:fcaad0dfa051 175
spastor 0:fcaad0dfa051 176 /** Parent Class for XBee modules, not to be directly used */
spastor 0:fcaad0dfa051 177 class XBee
spastor 0:fcaad0dfa051 178 {
spastor 0:fcaad0dfa051 179 private:
spastor 0:fcaad0dfa051 180 /** wait_for_module_to_reset - waits until a Modem Status packet with a reset status
spastor 0:fcaad0dfa051 181 * is received, or the timeout expires.
spastor 0:fcaad0dfa051 182 *
spastor 0:fcaad0dfa051 183 * @returns
spastor 0:fcaad0dfa051 184 * Success if a Modem Status was received,
spastor 0:fcaad0dfa051 185 * Failure otherwise
spastor 0:fcaad0dfa051 186 */
spastor 0:fcaad0dfa051 187 RadioStatus wait_for_module_to_reset(volatile uint16_t *rst_cnt_p, uint16_t init_rst_cnt);
spastor 0:fcaad0dfa051 188
spastor 0:fcaad0dfa051 189 protected:
spastor 0:fcaad0dfa051 190 /** timer used by local and remote objects */
spastor 0:fcaad0dfa051 191 static Timer _timer;
spastor 0:fcaad0dfa051 192
spastor 0:fcaad0dfa051 193 /** buffer to store the received frames */
spastor 0:fcaad0dfa051 194 static FrameBuffer _framebuf;
spastor 0:fcaad0dfa051 195
spastor 0:fcaad0dfa051 196 public:
spastor 0:fcaad0dfa051 197
spastor 0:fcaad0dfa051 198 /**
spastor 0:fcaad0dfa051 199 * RadioMode
spastor 0:fcaad0dfa051 200 */
spastor 0:fcaad0dfa051 201 enum RadioMode {
spastor 0:fcaad0dfa051 202 ModeUnknown = 0, /**< Unknown */
spastor 0:fcaad0dfa051 203 ModeAPI1 = 1, /**< API1 */
spastor 0:fcaad0dfa051 204 ModeAPI2 = 2, /**< API2 */
spastor 0:fcaad0dfa051 205 ModeTransparent = 3, /**< Transparent */
spastor 0:fcaad0dfa051 206 ModeBootloader = 4, /**< Bootloader */
spastor 0:fcaad0dfa051 207 };
spastor 0:fcaad0dfa051 208
spastor 0:fcaad0dfa051 209 /** Class constructor
spastor 0:fcaad0dfa051 210 * @param tx the TX pin of the UART that will interface the XBee module
spastor 0:fcaad0dfa051 211 * @param rx the RX pin of the UART that will interface the XBee module
spastor 0:fcaad0dfa051 212 * @param reset the pin to which the XBee's reset line is attached to, use NC if not available
spastor 0:fcaad0dfa051 213 * @param rts the RTS pin for the UART that will interface the XBee module, use NC if not available
spastor 0:fcaad0dfa051 214 * @param cts the CTS pin for the UART that will interface the XBee module, use NC if not available
spastor 0:fcaad0dfa051 215 * @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 216 * to this baud rate (ATBD parameter). By default it is configured to 9600 bps
spastor 0:fcaad0dfa051 217 * */
spastor 0:fcaad0dfa051 218 XBee(PinName tx, PinName rx, PinName reset = NC, PinName rts = NC, PinName cts = NC, int baud = 9600);
spastor 0:fcaad0dfa051 219
spastor 0:fcaad0dfa051 220 XBee(const XBee& other); /* Intentionally not implemented */
spastor 0:fcaad0dfa051 221 /** Class destructor */
spastor 0:fcaad0dfa051 222 virtual ~XBee();
spastor 0:fcaad0dfa051 223
spastor 0:fcaad0dfa051 224 /** init- initializes object
spastor 0:fcaad0dfa051 225 * This function must be called just after creating the object so it initializes internal data.
spastor 0:fcaad0dfa051 226 * @returns
spastor 0:fcaad0dfa051 227 * Success if the module has been properly initialized and is ready to process data.
spastor 0:fcaad0dfa051 228 * Failure otherwise.
spastor 0:fcaad0dfa051 229 */
spastor 0:fcaad0dfa051 230 RadioStatus init();
spastor 0:fcaad0dfa051 231
spastor 0:fcaad0dfa051 232 /** get_addr64 - returns the 64bit address of the local device
spastor 0:fcaad0dfa051 233 *
spastor 0:fcaad0dfa051 234 * @returns the 64bit address of the local device
spastor 0:fcaad0dfa051 235 */
spastor 0:fcaad0dfa051 236 uint64_t get_addr64() const;
spastor 0:fcaad0dfa051 237
spastor 0:fcaad0dfa051 238 /** get_addr16 - returns the 16bit address of the local device
spastor 0:fcaad0dfa051 239 *
spastor 0:fcaad0dfa051 240 * @returns the 16-bit address of the local device.
spastor 0:fcaad0dfa051 241 */
spastor 0:fcaad0dfa051 242 uint16_t get_addr16() const;
spastor 0:fcaad0dfa051 243
spastor 0:fcaad0dfa051 244 /** get_network_address - gets the 16bit network address of the device
spastor 0:fcaad0dfa051 245 *
spastor 0:fcaad0dfa051 246 * @param addr pointer where the device 16bit network address will be stored
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 get_network_address(uint16_t * const addr);
spastor 0:fcaad0dfa051 252
spastor 0:fcaad0dfa051 253 /** hardware_reset - performs a hardware reset. The reset GPIO must have
spastor 0:fcaad0dfa051 254 * been provided to the constructor
spastor 0:fcaad0dfa051 255 *
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 hardware_reset();
spastor 0:fcaad0dfa051 261
spastor 0:fcaad0dfa051 262 /** software_reset - performs a firmware reset
spastor 0:fcaad0dfa051 263 *
spastor 0:fcaad0dfa051 264 * @returns
spastor 0:fcaad0dfa051 265 * Success if the operation was successful,
spastor 0:fcaad0dfa051 266 * Failure otherwise
spastor 0:fcaad0dfa051 267 */
spastor 0:fcaad0dfa051 268 RadioStatus software_reset();
spastor 0:fcaad0dfa051 269
spastor 0:fcaad0dfa051 270 /** device_reset - performs a hardware reset if there is a GPIO connected to the
spastor 0:fcaad0dfa051 271 * reset line of the device. Otherwise, performs a firmware reset.
spastor 0:fcaad0dfa051 272 *
spastor 0:fcaad0dfa051 273 * @returns
spastor 0:fcaad0dfa051 274 * Success if the operation was successful,
spastor 0:fcaad0dfa051 275 * Failure otherwise
spastor 0:fcaad0dfa051 276 */
spastor 0:fcaad0dfa051 277 #if defined(UNIT_TEST)
spastor 0:fcaad0dfa051 278 virtual
spastor 0:fcaad0dfa051 279 #endif
spastor 0:fcaad0dfa051 280 RadioStatus device_reset();
spastor 0:fcaad0dfa051 281
spastor 0:fcaad0dfa051 282 /** get_radio_type - returns the type of radio, in most cases the hardware version
spastor 0:fcaad0dfa051 283 *
spastor 0:fcaad0dfa051 284 * @returns the radio type
spastor 0:fcaad0dfa051 285 */
spastor 0:fcaad0dfa051 286 RadioType get_radio_type() const;
spastor 0:fcaad0dfa051 287
spastor 0:fcaad0dfa051 288 /** set_tx_options - sets the transmit options byte, used with the transmit frames.
spastor 0:fcaad0dfa051 289 * Valid flags are:
spastor 0:fcaad0dfa051 290 * - DISABLE_RETRIES_AND_ROUTE_REPAIR
spastor 0:fcaad0dfa051 291 * - ENABLE_APS_ENCRYPTION
spastor 0:fcaad0dfa051 292 * - USE_EXTENDED_TX_TIMEOUT
spastor 0:fcaad0dfa051 293 *
spastor 0:fcaad0dfa051 294 * @param options variable with the option flags
spastor 0:fcaad0dfa051 295 */
spastor 0:fcaad0dfa051 296 void set_tx_options(uint8_t options);
spastor 0:fcaad0dfa051 297
spastor 0:fcaad0dfa051 298 /** set_broadcast_radius - sets the max number of hops for a broadcast msg.
spastor 0:fcaad0dfa051 299 * When set to 0 uses the maximum possible.
spastor 0:fcaad0dfa051 300 *
spastor 0:fcaad0dfa051 301 * @param bc_radius variable with the broadcast radious
spastor 0:fcaad0dfa051 302 */
spastor 0:fcaad0dfa051 303 void set_broadcast_radius(uint8_t bc_radius);
spastor 0:fcaad0dfa051 304
spastor 0:fcaad0dfa051 305 /** get_tx_options - returns the tx options byte configured in the library.
spastor 0:fcaad0dfa051 306 *
spastor 0:fcaad0dfa051 307 * @returns the tx options byte configured in the library.
spastor 0:fcaad0dfa051 308 */
spastor 0:fcaad0dfa051 309 uint8_t get_tx_options() const;
spastor 0:fcaad0dfa051 310
spastor 0:fcaad0dfa051 311 /** get_bc_radius - returns the broadcast radius configured in the library.
spastor 0:fcaad0dfa051 312 *
spastor 0:fcaad0dfa051 313 * @returns the broadcast radius configured in the library.
spastor 0:fcaad0dfa051 314 */
spastor 0:fcaad0dfa051 315 uint8_t get_bc_radius() const;
spastor 0:fcaad0dfa051 316
spastor 0:fcaad0dfa051 317 /************************ Configuration member methods *************************/
spastor 0:fcaad0dfa051 318 /** write_config - write settings to non volatile memory
spastor 0:fcaad0dfa051 319 *
spastor 0:fcaad0dfa051 320 * @returns
spastor 0:fcaad0dfa051 321 * Success if the operation was successful,
spastor 0:fcaad0dfa051 322 * Failure otherwise
spastor 0:fcaad0dfa051 323 */
spastor 0:fcaad0dfa051 324 RadioStatus write_config();
spastor 0:fcaad0dfa051 325
spastor 0:fcaad0dfa051 326 /** config_io_sample_destination - configures to which node a remote module will send its IO Samples to.
spastor 0:fcaad0dfa051 327 * @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 328 * Consult the module's reference manual for more information.
spastor 0:fcaad0dfa051 329 *
spastor 0:fcaad0dfa051 330 * @param remote remote device that will be sending the IO Samples
spastor 0:fcaad0dfa051 331 * @param destination remote device that will be receiving the IO Samples sent by 'remote'
spastor 0:fcaad0dfa051 332 * @returns the result of the data transfer
spastor 0:fcaad0dfa051 333 * Success if the operation was successful,
spastor 0:fcaad0dfa051 334 * Failure otherwise
spastor 0:fcaad0dfa051 335 */
spastor 0:fcaad0dfa051 336 RadioStatus config_io_sample_destination(const RemoteXBee& remote, const RemoteXBee& destination);
spastor 0:fcaad0dfa051 337
spastor 0:fcaad0dfa051 338 /** 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 339 *
spastor 0:fcaad0dfa051 340 * @param remote remote device that will be sending the IO Samples
spastor 0:fcaad0dfa051 341 * @param seconds the IO Sample sending rate in seconds (granularity is of 1 millisecond). Maximum is 65.535 seconds.
spastor 0:fcaad0dfa051 342 * @returns the result of the data transfer
spastor 0:fcaad0dfa051 343 * Success if the operation was successful,
spastor 0:fcaad0dfa051 344 * Failure otherwise
spastor 0:fcaad0dfa051 345 */
spastor 0:fcaad0dfa051 346 RadioStatus set_io_sample_rate(const RemoteXBee& remote, float seconds);
spastor 0:fcaad0dfa051 347
spastor 0:fcaad0dfa051 348 /** set_power_level - sets the power level at which the radio will transmit
spastor 0:fcaad0dfa051 349 *
spastor 0:fcaad0dfa051 350 * @param level power level at which the radio will transmit
spastor 0:fcaad0dfa051 351 * @returns
spastor 0:fcaad0dfa051 352 * Success if the operation was successful,
spastor 0:fcaad0dfa051 353 * Failure otherwise
spastor 0:fcaad0dfa051 354 */
spastor 0:fcaad0dfa051 355 RadioStatus set_power_level(uint8_t level);
spastor 0:fcaad0dfa051 356
spastor 0:fcaad0dfa051 357 /** get_power_level - reads the power level configured in the radio
spastor 0:fcaad0dfa051 358 *
spastor 0:fcaad0dfa051 359 * @param level pointer where the read power level will be stored
spastor 0:fcaad0dfa051 360 * @returns
spastor 0:fcaad0dfa051 361 * Success if the operation was successful,
spastor 0:fcaad0dfa051 362 * Failure otherwise
spastor 0:fcaad0dfa051 363 */
spastor 0:fcaad0dfa051 364 RadioStatus get_power_level(uint8_t * const level);
spastor 0:fcaad0dfa051 365
spastor 0:fcaad0dfa051 366 /** get_hw_version - gets the hardware version of the radio
spastor 0:fcaad0dfa051 367 *
spastor 0:fcaad0dfa051 368 * @returns the hardware version of the radio
spastor 0:fcaad0dfa051 369 */
spastor 0:fcaad0dfa051 370 uint16_t get_hw_version() const;
spastor 0:fcaad0dfa051 371
spastor 0:fcaad0dfa051 372 /** get_fw_version - gets the firmware version of the radio
spastor 0:fcaad0dfa051 373 *
spastor 0:fcaad0dfa051 374 * @returns the firmware version of the radio
spastor 0:fcaad0dfa051 375 */
spastor 0:fcaad0dfa051 376 uint16_t get_fw_version() const;
spastor 0:fcaad0dfa051 377
spastor 0:fcaad0dfa051 378 /** set_node_identifier - configures the Node Identifier string
spastor 0:fcaad0dfa051 379 *
spastor 0:fcaad0dfa051 380 * @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 381 * @returns
spastor 0:fcaad0dfa051 382 * Success if the operation was successful,
spastor 0:fcaad0dfa051 383 * Failure otherwise
spastor 0:fcaad0dfa051 384 */
spastor 0:fcaad0dfa051 385 RadioStatus set_node_identifier(const char * const node_id);
spastor 0:fcaad0dfa051 386
spastor 0:fcaad0dfa051 387 /** get_node_identifier - reads the configured Node Identifier string
spastor 0:fcaad0dfa051 388 *
spastor 0:fcaad0dfa051 389 * @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 390 * @returns
spastor 0:fcaad0dfa051 391 * Success if the operation was successful,
spastor 0:fcaad0dfa051 392 * Failure otherwise
spastor 0:fcaad0dfa051 393 */
spastor 0:fcaad0dfa051 394 RadioStatus get_node_identifier(char * const node_id);
spastor 0:fcaad0dfa051 395
spastor 0:fcaad0dfa051 396 /** start_node_discovery - starts a node discovery operation. The responses
spastor 0:fcaad0dfa051 397 * have to be processes on the callback function that have to be registered
spastor 0:fcaad0dfa051 398 * for that purpose
spastor 0:fcaad0dfa051 399 *
spastor 0:fcaad0dfa051 400 * @returns
spastor 0:fcaad0dfa051 401 * Success if the operation was successful,
spastor 0:fcaad0dfa051 402 * Failure otherwise
spastor 0:fcaad0dfa051 403 */
spastor 0:fcaad0dfa051 404 RadioStatus start_node_discovery();
spastor 0:fcaad0dfa051 405
spastor 0:fcaad0dfa051 406 /** config_node_discovery - configures the node discovery operation
spastor 0:fcaad0dfa051 407 *
spastor 0:fcaad0dfa051 408 * @param timeout_ms max allowed time for devices in the network to answer
spastor 0:fcaad0dfa051 409 * to the Node Discovery request
spastor 0:fcaad0dfa051 410 * @param options node discovery options (flags)
hbujanda 1:794d1d3e4a08 411 * ND_OPTION_APPEND_DD - to append the DD value to the response
hbujanda 1:794d1d3e4a08 412 * ND_OPTION_SELF_RESPONSE - to allow the module self responding
spastor 0:fcaad0dfa051 413 * @returns
spastor 0:fcaad0dfa051 414 * Success if the operation was successful,
spastor 0:fcaad0dfa051 415 * Failure otherwise
spastor 0:fcaad0dfa051 416 */
spastor 0:fcaad0dfa051 417 RadioStatus config_node_discovery(uint16_t timeout_ms, uint8_t options = 0);
spastor 0:fcaad0dfa051 418
spastor 0:fcaad0dfa051 419 /** get_config_node_discovery - reads the configuration of the node discovery
spastor 0:fcaad0dfa051 420 * settings
spastor 0:fcaad0dfa051 421 *
spastor 0:fcaad0dfa051 422 * @param timeout_ms pointer where the node discovery time out value will be stored
spastor 0:fcaad0dfa051 423 * @param options pointer whre the node discovery options (flags) will be saved
spastor 0:fcaad0dfa051 424 * @returns
spastor 0:fcaad0dfa051 425 * Success if the operation was successful,
spastor 0:fcaad0dfa051 426 * Failure otherwise
spastor 0:fcaad0dfa051 427 */
spastor 0:fcaad0dfa051 428 RadioStatus get_config_node_discovery(uint16_t * const timeout_ms, uint8_t * const options);
spastor 0:fcaad0dfa051 429
spastor 0:fcaad0dfa051 430 /** set_timeout - sets the timeout in ms, used by sync methods
spastor 0:fcaad0dfa051 431 *
spastor 0:fcaad0dfa051 432 * @param timeout_ms new timeout in ms
spastor 0:fcaad0dfa051 433 */
spastor 0:fcaad0dfa051 434 void set_timeout(uint16_t timeout_ms);
spastor 0:fcaad0dfa051 435
spastor 0:fcaad0dfa051 436 /** get_timeout - gets the timeout in ms configured in the library. This value
spastor 0:fcaad0dfa051 437 * is used in sync commands
spastor 0:fcaad0dfa051 438 *
spastor 0:fcaad0dfa051 439 * @returns the configured timeout value in ms
spastor 0:fcaad0dfa051 440 */
spastor 0:fcaad0dfa051 441 uint16_t get_timeout() const;
spastor 0:fcaad0dfa051 442
spastor 0:fcaad0dfa051 443 /* ... */
spastor 0:fcaad0dfa051 444
spastor 0:fcaad0dfa051 445 /*********************** send_data member methods ************************/
spastor 0:fcaad0dfa051 446 /** send_data - sends data to a remote device waiting for the packet
spastor 0:fcaad0dfa051 447 * answer with the result of the operation
spastor 0:fcaad0dfa051 448 *
spastor 0:fcaad0dfa051 449 * @param remote remote device
spastor 0:fcaad0dfa051 450 * @param data pointer to the data that will be sent
spastor 0:fcaad0dfa051 451 * @param len number of bytes that will be transmitted
spastor 0:fcaad0dfa051 452 * @returns the result of the data transfer
spastor 0:fcaad0dfa051 453 * TxStatusSuccess if the operation was successful,
spastor 0:fcaad0dfa051 454 * the error code otherwise
spastor 0:fcaad0dfa051 455 */
spastor 0:fcaad0dfa051 456 virtual TxStatus send_data(const RemoteXBee& remote, const uint8_t *const data, uint16_t len) = 0;
spastor 0:fcaad0dfa051 457
spastor 0:fcaad0dfa051 458 /** send_data_broadcast - sends data to all devices in the network, using the
spastor 0:fcaad0dfa051 459 * broadcast address. The method waits for the packet
spastor 0:fcaad0dfa051 460 * answer with the result of the operation
spastor 0:fcaad0dfa051 461 *
spastor 0:fcaad0dfa051 462 * @param data pointer to the data that will be sent
spastor 0:fcaad0dfa051 463 * @param len number of bytes that will be transmitted
spastor 0:fcaad0dfa051 464 * @returns the result of the data transfer
spastor 0:fcaad0dfa051 465 * TxStatusSuccess if the operation was successful,
spastor 0:fcaad0dfa051 466 * the error code otherwise
spastor 0:fcaad0dfa051 467 */
spastor 0:fcaad0dfa051 468 TxStatus send_data_broadcast(const uint8_t *const data, uint16_t len);
spastor 0:fcaad0dfa051 469
spastor 0:fcaad0dfa051 470 /** set_param - sets a parameter in the local radio by sending an AT command and waiting for the response.
spastor 0:fcaad0dfa051 471 *
spastor 0:fcaad0dfa051 472 * @param param parameter to be set.
spastor 0:fcaad0dfa051 473 * @param data the parameter value (4 bytes) to be set.
spastor 0:fcaad0dfa051 474 * @returns the command response status.
spastor 0:fcaad0dfa051 475 */
spastor 0:fcaad0dfa051 476 AtCmdFrame::AtCmdResp set_param(const char * const param, uint32_t data);
spastor 0:fcaad0dfa051 477
spastor 0:fcaad0dfa051 478 /** set_param - sets a parameter in the local radio by sending an AT command and waiting for the response.
spastor 0:fcaad0dfa051 479 *
spastor 0:fcaad0dfa051 480 * @param param parameter to be set.
spastor 0:fcaad0dfa051 481 * @param data the parameter value byte array (len bytes) to be set.
spastor 0:fcaad0dfa051 482 * @param len number of bytes of the parameter value.
spastor 0:fcaad0dfa051 483 * @returns the command response status.
spastor 0:fcaad0dfa051 484 */
spastor 0:fcaad0dfa051 485 AtCmdFrame::AtCmdResp set_param(const char * const param, const uint8_t * data = NULL, uint16_t len = 0);
spastor 0:fcaad0dfa051 486
spastor 0:fcaad0dfa051 487 /** get_param - gets a parameter from the local radio by sending an AT command and waiting for the response.
spastor 0:fcaad0dfa051 488 *
spastor 0:fcaad0dfa051 489 * @param param parameter to be get.
spastor 0:fcaad0dfa051 490 * @param data pointer where the param value (4 bytes) will be stored.
spastor 0:fcaad0dfa051 491 * @returns the command response status.
spastor 0:fcaad0dfa051 492 */
spastor 0:fcaad0dfa051 493 AtCmdFrame::AtCmdResp get_param(const char * const param, uint32_t * const data);
spastor 0:fcaad0dfa051 494
spastor 0:fcaad0dfa051 495 /** get_param - gets a parameter from the local radio by sending an AT command and waiting for the response.
spastor 0:fcaad0dfa051 496 *
spastor 0:fcaad0dfa051 497 * @param param parameter to be get.
spastor 0:fcaad0dfa051 498 * @param data pointer where the param value (n bytes) will be stored.
spastor 0:fcaad0dfa051 499 * @param len pointer where the number of bytes of the param value will be stored.
spastor 0:fcaad0dfa051 500 * @returns the command response status.
spastor 0:fcaad0dfa051 501 */
spastor 0:fcaad0dfa051 502 AtCmdFrame::AtCmdResp get_param(const char * const param, uint8_t * const data, uint16_t * const len);
spastor 0:fcaad0dfa051 503
spastor 0:fcaad0dfa051 504 /** set_param - sets a parameter in a remote radio by sending an AT command and waiting for the response.
spastor 0:fcaad0dfa051 505 *
spastor 0:fcaad0dfa051 506 * @param remote remote device
spastor 0:fcaad0dfa051 507 * @param param parameter to be set.
spastor 0:fcaad0dfa051 508 * @param data the parameter value (4 bytes) to be set.
spastor 0:fcaad0dfa051 509 * @returns the command response status.
spastor 0:fcaad0dfa051 510 */
spastor 0:fcaad0dfa051 511 virtual AtCmdFrame::AtCmdResp set_param(const RemoteXBee& remote, const char * const param, uint32_t data) = 0;
spastor 0:fcaad0dfa051 512
spastor 0:fcaad0dfa051 513 /** set_param - sets a parameter in a remote radio by sending an AT command and waiting for the response.
spastor 0:fcaad0dfa051 514 *
spastor 0:fcaad0dfa051 515 * @param remote remote device
spastor 0:fcaad0dfa051 516 * @param param parameter to be set.
spastor 0:fcaad0dfa051 517 * @param data the parameter value byte array (len bytes) to be set.
spastor 0:fcaad0dfa051 518 * @param len number of bytes of the parameter value.
spastor 0:fcaad0dfa051 519 * @returns the command response status.
spastor 0:fcaad0dfa051 520 */
spastor 0:fcaad0dfa051 521 virtual AtCmdFrame::AtCmdResp set_param(const RemoteXBee& remote, const char * const param, const uint8_t * data = NULL, uint16_t len = 0) = 0;
spastor 0:fcaad0dfa051 522
spastor 0:fcaad0dfa051 523 /** get_param - gets a parameter from a remote radio by sending an AT command and waiting for the response.
spastor 0:fcaad0dfa051 524 *
spastor 0:fcaad0dfa051 525 * @param remote remote device
spastor 0:fcaad0dfa051 526 * @param param parameter to be get.
spastor 0:fcaad0dfa051 527 * @param data pointer where the param value (4 bytes) will be stored.
spastor 0:fcaad0dfa051 528 * @returns the command response status.
spastor 0:fcaad0dfa051 529 */
spastor 0:fcaad0dfa051 530 virtual AtCmdFrame::AtCmdResp get_param(const RemoteXBee& remote, const char * const param, uint32_t * const data) = 0;
spastor 0:fcaad0dfa051 531
spastor 0:fcaad0dfa051 532 /** get_param - gets a parameter from a remote radio by sending an AT command and waiting for the response.
spastor 0:fcaad0dfa051 533 *
spastor 0:fcaad0dfa051 534 * @param remote remote device
spastor 0:fcaad0dfa051 535 * @param param parameter to be get.
spastor 0:fcaad0dfa051 536 * @param data pointer where the param value (n bytes) will be stored.
spastor 0:fcaad0dfa051 537 * @param len pointer where the number of bytes of the param value will be stored.
spastor 0:fcaad0dfa051 538 * @returns the command response status.
spastor 0:fcaad0dfa051 539 */
spastor 0:fcaad0dfa051 540 virtual AtCmdFrame::AtCmdResp get_param(const RemoteXBee& remote, const char * const param, uint8_t * const data, uint16_t * const len) = 0;
spastor 0:fcaad0dfa051 541
spastor 0:fcaad0dfa051 542 #if defined(ENABLE_PM_SUPPORT)
spastor 0:fcaad0dfa051 543 /** set_pm_control - sets the operational mode of the Power Management on
spastor 0:fcaad0dfa051 544 * the radio and registers the GPIOs used to handle the
spastor 0:fcaad0dfa051 545 * Power Management
spastor 0:fcaad0dfa051 546 *
spastor 0:fcaad0dfa051 547 * @param mode operational mode of the power management
spastor 0:fcaad0dfa051 548 * @param on_sleep pin used to detect the on/sleep status of the module
spastor 0:fcaad0dfa051 549 * @param sleep_rq pin used to request the module to go to sleep (when pin
spastor 0:fcaad0dfa051 550 * sleep mode is used
spastor 0:fcaad0dfa051 551 * @returns the result of the configuration operation
spastor 0:fcaad0dfa051 552 * Success if the operation was successful,
spastor 0:fcaad0dfa051 553 * Failure otherwise
spastor 0:fcaad0dfa051 554 */
spastor 0:fcaad0dfa051 555 RadioStatus set_pm_control(PmMode mode, PinName on_sleep = NC, PinName sleep_rq = NC);
spastor 0:fcaad0dfa051 556
spastor 0:fcaad0dfa051 557 /** get_pm_mode - gets the power management mode programmed in the radio.
spastor 0:fcaad0dfa051 558 *
spastor 0:fcaad0dfa051 559 * @param mode pointer where the read mode will be stored.
spastor 0:fcaad0dfa051 560 * @returns the result of the configuration operation
spastor 0:fcaad0dfa051 561 * Success if the operation was successful,
spastor 0:fcaad0dfa051 562 * Failure otherwise
spastor 0:fcaad0dfa051 563 */
spastor 0:fcaad0dfa051 564 RadioStatus get_pm_mode(PmMode *mode);
spastor 0:fcaad0dfa051 565
spastor 0:fcaad0dfa051 566 /** config_pm_timing - configures the power management timing parameters.
spastor 0:fcaad0dfa051 567 *
spastor 0:fcaad0dfa051 568 * @param before_sleep_ms number of miliseconds of inactivity before the radio will
spastor 0:fcaad0dfa051 569 * automatically go to sleep again (when using cyclic sleep).
spastor 0:fcaad0dfa051 570 * @param total_sleep_period_ms time interval in ms the radio will be sleeping. Once
spastor 0:fcaad0dfa051 571 * this time passes, the radio will wakeup, will check for
spastor 0:fcaad0dfa051 572 * packets and will wait before_sleep_ms of inactivity
spastor 0:fcaad0dfa051 573 * before entering again in sleep mode.
spastor 0:fcaad0dfa051 574 * @returns the result of the configuration operation
spastor 0:fcaad0dfa051 575 * Success if the operation was successful,
spastor 0:fcaad0dfa051 576 * Failure otherwise
spastor 0:fcaad0dfa051 577 */
spastor 0:fcaad0dfa051 578 RadioStatus config_pm_timing(uint32_t before_sleep_ms, uint32_t total_sleep_period_ms);
spastor 0:fcaad0dfa051 579
spastor 0:fcaad0dfa051 580 /** enter_sleep_mode - sets the radio into low power mode. If the pm working mode
spastor 0:fcaad0dfa051 581 * is pin-sleep, then it will use the GPIO, otherwise, it will
spastor 0:fcaad0dfa051 582 * use the serial interface.
spastor 0:fcaad0dfa051 583 *
spastor 0:fcaad0dfa051 584 * @note the method does not wait until the radio enters in sleep mode, it returns
spastor 0:fcaad0dfa051 585 * without making any verification.
spastor 0:fcaad0dfa051 586 * @returns the result of the operation
spastor 0:fcaad0dfa051 587 * Success if the operation was successful,
spastor 0:fcaad0dfa051 588 * Failure otherwise
spastor 0:fcaad0dfa051 589 */
spastor 0:fcaad0dfa051 590 RadioStatus enter_sleep_mode();
spastor 0:fcaad0dfa051 591
spastor 0:fcaad0dfa051 592 /** exit_sleep_mode - for the pm mode called pin-sleep, sets the radio into active power
spastor 0:fcaad0dfa051 593 * using the corresponding GPIO.
spastor 0:fcaad0dfa051 594 *
spastor 0:fcaad0dfa051 595 */
spastor 0:fcaad0dfa051 596 void exit_sleep_mode();
spastor 0:fcaad0dfa051 597
spastor 0:fcaad0dfa051 598 /** is_sleeping - checks if the radio is sleeping or if its active.
spastor 0:fcaad0dfa051 599 *
spastor 0:fcaad0dfa051 600 * @returns true if the radio is sleeping, false otherwisw
spastor 0:fcaad0dfa051 601 */
spastor 0:fcaad0dfa051 602 bool is_sleeping();
spastor 0:fcaad0dfa051 603
spastor 0:fcaad0dfa051 604 /** register_wakeup_cb - registers the callback function that will be called
spastor 0:fcaad0dfa051 605 * when the radio wakes up from sleep mode.
spastor 0:fcaad0dfa051 606 *
spastor 0:fcaad0dfa051 607 * @param f function pointer with the callback function
spastor 0:fcaad0dfa051 608 */
spastor 0:fcaad0dfa051 609 void register_wakeup_cb(void (*f)(void));
spastor 0:fcaad0dfa051 610
spastor 0:fcaad0dfa051 611 /** unregister_wakeup_cb - removes the wakeup callback */
spastor 0:fcaad0dfa051 612 void unregister_wakeup_cb();
spastor 0:fcaad0dfa051 613 #endif /* defined(ENABLE_PM_SUPPORT) */
spastor 0:fcaad0dfa051 614
spastor 0:fcaad0dfa051 615 /** process_rx_frames - method that process the frames queued in the reception
spastor 0:fcaad0dfa051 616 * buffer. Calls the process_frame_data method of the frame
spastor 0:fcaad0dfa051 617 * handlers registered
spastor 0:fcaad0dfa051 618 *
spastor 0:fcaad0dfa051 619 * @returns Number of dropped frames since latest call to this method.
spastor 0:fcaad0dfa051 620 */
spastor 0:fcaad0dfa051 621 uint32_t process_rx_frames();
spastor 0:fcaad0dfa051 622
spastor 0:fcaad0dfa051 623 /** register_modem_status_cb - registers the callback function that will be called
spastor 0:fcaad0dfa051 624 * when a Modem Status packet is received
spastor 0:fcaad0dfa051 625 *
spastor 0:fcaad0dfa051 626 * @param function function pointer with the callback function
spastor 0:fcaad0dfa051 627 */
spastor 0:fcaad0dfa051 628 void register_modem_status_cb(modem_status_cb_t function);
spastor 0:fcaad0dfa051 629
spastor 0:fcaad0dfa051 630 /** unregister_modem_status_cb - removes the Modem Status reception callback */
spastor 0:fcaad0dfa051 631 void unregister_modem_status_cb();
spastor 0:fcaad0dfa051 632
spastor 0:fcaad0dfa051 633 protected:
spastor 0:fcaad0dfa051 634
spastor 0:fcaad0dfa051 635 enum RadioProtocol {
spastor 0:fcaad0dfa051 636 None,
spastor 0:fcaad0dfa051 637 ZigBee,
spastor 0:fcaad0dfa051 638 Raw_802_15_4,
spastor 0:fcaad0dfa051 639 #ifdef EXTRA_XBEE_PROTOCOLS
spastor 0:fcaad0dfa051 640 XBeeWiFi,
spastor 0:fcaad0dfa051 641 DigiMesh,
spastor 0:fcaad0dfa051 642 SmartEnergy,
spastor 0:fcaad0dfa051 643 DigiPoint,
spastor 0:fcaad0dfa051 644 ZNet,
spastor 0:fcaad0dfa051 645 #endif
spastor 0:fcaad0dfa051 646 };
spastor 0:fcaad0dfa051 647 /** send_byte_escaping_if - sends a byte, through the serial interface, to
spastor 0:fcaad0dfa051 648 * the radio, escaping the byte if the working mode of the radio is API2.
spastor 0:fcaad0dfa051 649 *
spastor 0:fcaad0dfa051 650 * @param line PWM line being set
spastor 0:fcaad0dfa051 651 * @param data the byte that will be send to radio
spastor 0:fcaad0dfa051 652 */
spastor 0:fcaad0dfa051 653 void send_byte_escaping_if(uint8_t data);
spastor 0:fcaad0dfa051 654
spastor 0:fcaad0dfa051 655 /** uart_read_cb - serial interface callback, called when data is received on
spastor 0:fcaad0dfa051 656 * the serial port. The function parses the incoming data and, when a good
spastor 0:fcaad0dfa051 657 * frame is detected, saves it in the frame list
spastor 0:fcaad0dfa051 658 */
spastor 0:fcaad0dfa051 659 void uart_read_cb();
spastor 0:fcaad0dfa051 660
spastor 0:fcaad0dfa051 661 /** get_this_api_frame - searches in the FrameBuffer for an incoming frame
spastor 0:fcaad0dfa051 662 * with frameid equal to id and frame type equal to type
spastor 0:fcaad0dfa051 663 * or type2. If after timeout the frame hast not been found,
spastor 0:fcaad0dfa051 664 * returns.
spastor 0:fcaad0dfa051 665 *
spastor 0:fcaad0dfa051 666 * @param id id of the frame we are looking for.
spastor 0:fcaad0dfa051 667 * @param type tye type we expect the frame to be.
spastor 0:fcaad0dfa051 668 * @param type2 alternative valid type, if provided.
spastor 0:fcaad0dfa051 669 * @returns a pointer to the frame found in the FrameBuffer or a null pointer if
spastor 0:fcaad0dfa051 670 * the frame has not been found and the timeout expired.
spastor 0:fcaad0dfa051 671 */
spastor 0:fcaad0dfa051 672 ApiFrame * get_this_api_frame(uint8_t id, ApiFrame::ApiFrameType type,
spastor 0:fcaad0dfa051 673 ApiFrame::ApiFrameType type2 = ApiFrame::Invalid);
spastor 0:fcaad0dfa051 674
spastor 0:fcaad0dfa051 675 /** send_api_frame - method to send, over the serial port, an API frame
spastor 0:fcaad0dfa051 676 *
spastor 0:fcaad0dfa051 677 * @param frame pointer to the frame that will be sent.
spastor 0:fcaad0dfa051 678 */
spastor 0:fcaad0dfa051 679 #if defined(UNIT_TEST)
spastor 0:fcaad0dfa051 680 virtual
spastor 0:fcaad0dfa051 681 #endif
spastor 0:fcaad0dfa051 682 void send_api_frame(ApiFrame *frame);
spastor 0:fcaad0dfa051 683
spastor 0:fcaad0dfa051 684 /** update_radio_status - method called when a modem status frame is received
spastor 0:fcaad0dfa051 685 * to update the internal status variables of the library.
spastor 0:fcaad0dfa051 686 * @note This is not a pure virtual function because it can be called while
spastor 0:fcaad0dfa051 687 * the object is being constructed and we need the implementation of the
spastor 0:fcaad0dfa051 688 * base class.
spastor 0:fcaad0dfa051 689 *
spastor 0:fcaad0dfa051 690 * @param status byte with the status received in the modem status frame
spastor 0:fcaad0dfa051 691 */
spastor 0:fcaad0dfa051 692 virtual void radio_status_update(AtCmdFrame::ModemStatus modem_status);
spastor 0:fcaad0dfa051 693
spastor 0:fcaad0dfa051 694 /** Method used internaly by the derived classes to transmit data to
spastor 0:fcaad0dfa051 695 * remote nodes, waiting for the answer from the device
spastor 0:fcaad0dfa051 696 *
spastor 0:fcaad0dfa051 697 * @param frame frame that will be sent to the radio (have to be a
spastor 0:fcaad0dfa051 698 * proper transmit frame
spastor 0:fcaad0dfa051 699 * @returns the result of the data transfer
spastor 0:fcaad0dfa051 700 * TxStatusSuccess if the operation was successful,
spastor 0:fcaad0dfa051 701 * the error code otherwise
spastor 0:fcaad0dfa051 702 */
spastor 0:fcaad0dfa051 703 TxStatus send_data(ApiFrame *frame);
spastor 0:fcaad0dfa051 704
spastor 0:fcaad0dfa051 705 /** send_at_cmd - sends an AT command to the radio and waits for the response.
spastor 0:fcaad0dfa051 706 *
spastor 0:fcaad0dfa051 707 * @param frame api frame with the command and command params.
spastor 0:fcaad0dfa051 708 * @param buf pointer where the param response (n bytes) will be stored.
spastor 0:fcaad0dfa051 709 * @param len pointer where the number of bytes of the param response will be stored.
spastor 0:fcaad0dfa051 710 * @param radio_location radio location, either RadioLocal or RadioRemote.
spastor 0:fcaad0dfa051 711 * @param reverse reverse the byte ordering of the response saved in buf.
spastor 0:fcaad0dfa051 712 * @returns the command response status.
spastor 0:fcaad0dfa051 713 */
spastor 0:fcaad0dfa051 714 AtCmdFrame::AtCmdResp send_at_cmd(AtCmdFrame *frame,
spastor 0:fcaad0dfa051 715 uint8_t *const buf, uint16_t *const len, RadioLocation radio_location = RadioLocal, bool reverse = true);
spastor 0:fcaad0dfa051 716
spastor 0:fcaad0dfa051 717 /* send_at_cmd - methods used internally by other methods */
spastor 0:fcaad0dfa051 718 AtCmdFrame::AtCmdResp send_at_cmd(AtCmdFrame *frame);
spastor 0:fcaad0dfa051 719 AtCmdFrame::AtCmdResp send_at_cmd(AtCmdFrame *frame, uint8_t *data);
spastor 0:fcaad0dfa051 720 AtCmdFrame::AtCmdResp send_at_cmd(AtCmdFrame *frame, uint16_t *data);
spastor 0:fcaad0dfa051 721 AtCmdFrame::AtCmdResp send_at_cmd(AtCmdFrame *frame, uint32_t *data);
spastor 0:fcaad0dfa051 722
spastor 0:fcaad0dfa051 723 #if defined(ENABLE_PM_SUPPORT)
spastor 0:fcaad0dfa051 724 /** Sets the radio into low power mode. This method is used by enter_sleep_mode() */
spastor 0:fcaad0dfa051 725 RadioStatus sleep_now();
spastor 0:fcaad0dfa051 726 #endif /* defined(ENABLE_PM_SUPPORT) */
spastor 0:fcaad0dfa051 727
spastor 0:fcaad0dfa051 728 /** register_frame_handler - registers an object to handle incoming frames from
spastor 0:fcaad0dfa051 729 * the radio.
spastor 0:fcaad0dfa051 730 * @note For any type of frame more than one handler can be registered and all
spastor 0:fcaad0dfa051 731 * of them are called, sequentially, when a frame of that type arrives.
spastor 0:fcaad0dfa051 732 *
spastor 0:fcaad0dfa051 733 * @param handler pointer to the frame handler object
spastor 0:fcaad0dfa051 734 * @returns the result of the registration
spastor 0:fcaad0dfa051 735 * Success if the operation was successful,
spastor 0:fcaad0dfa051 736 * Failure otherwise
spastor 0:fcaad0dfa051 737 */
spastor 0:fcaad0dfa051 738 RadioStatus register_frame_handler(FrameHandler *const handler);
spastor 0:fcaad0dfa051 739
spastor 0:fcaad0dfa051 740 /** unregister_frame_handler - removes a previously registered frame handler
spastor 0:fcaad0dfa051 741 *
spastor 0:fcaad0dfa051 742 * @param handler pointer to the frame handler object
spastor 0:fcaad0dfa051 743 * @returns the result of the unregister operation
spastor 0:fcaad0dfa051 744 * Success if the operation was successful,
spastor 0:fcaad0dfa051 745 * Failure otherwise
spastor 0:fcaad0dfa051 746 */
spastor 0:fcaad0dfa051 747 RadioStatus unregister_frame_handler(FrameHandler *const handler);
spastor 0:fcaad0dfa051 748
spastor 0:fcaad0dfa051 749 /** get_radio_protocol - returns the RF protocol that the connected module uses
spastor 0:fcaad0dfa051 750 * based on its firmware and hardware versions
spastor 0:fcaad0dfa051 751 *
spastor 0:fcaad0dfa051 752 * @returns a RadioProtocol enum.
spastor 0:fcaad0dfa051 753 */
spastor 0:fcaad0dfa051 754 RadioProtocol get_radio_protocol(void) const;
spastor 0:fcaad0dfa051 755
spastor 0:fcaad0dfa051 756 /** get_iosample - forces an io_sample read (reads all digital and analog inputs)
spastor 0:fcaad0dfa051 757 *
spastor 0:fcaad0dfa051 758 * @param remote remote device
spastor 0:fcaad0dfa051 759 * @param io_sample buffer where the io_sample response is copied
spastor 0:fcaad0dfa051 760 * @param len pointer where the length of the io_sample response is stored
spastor 0:fcaad0dfa051 761 * @returns
spastor 0:fcaad0dfa051 762 * Success if the operation was successful,
spastor 0:fcaad0dfa051 763 * Failure otherwise
spastor 0:fcaad0dfa051 764 */
spastor 0:fcaad0dfa051 765 RadioStatus get_iosample(const RemoteXBee& remote, uint8_t * const io_sample, uint16_t * const len);
spastor 0:fcaad0dfa051 766
hbujanda 1:794d1d3e4a08 767 /** serial hardware flow control selected by the user (RTSCTS, RTS,CTS) */
hbujanda 1:794d1d3e4a08 768 SerialBase::Flow _serial_flow_type;
spastor 0:fcaad0dfa051 769
spastor 0:fcaad0dfa051 770 /** Operating mode of the module (API1, API2,...) */
spastor 0:fcaad0dfa051 771 RadioMode _mode;
spastor 0:fcaad0dfa051 772
spastor 0:fcaad0dfa051 773 /** Type of radio, mainly the hardware version, but may differ in some cases */
spastor 0:fcaad0dfa051 774 RadioType _type;
spastor 0:fcaad0dfa051 775
spastor 0:fcaad0dfa051 776 /** Hardware version value of the radio */
spastor 0:fcaad0dfa051 777 uint16_t _hw_version;
spastor 0:fcaad0dfa051 778
spastor 0:fcaad0dfa051 779 /** Firmware version value of the radio */
spastor 0:fcaad0dfa051 780 uint16_t _fw_version;
spastor 0:fcaad0dfa051 781
spastor 0:fcaad0dfa051 782 /** Timeout in ms for sync operations (when we wait for a response) */
spastor 0:fcaad0dfa051 783 uint16_t _timeout_ms;
spastor 0:fcaad0dfa051 784
spastor 0:fcaad0dfa051 785 /** Device 64 bit address (SH, SL) */
spastor 0:fcaad0dfa051 786 uint64_t _dev_addr64;
spastor 0:fcaad0dfa051 787
spastor 0:fcaad0dfa051 788 /** Device 16 bit address (MY) */
spastor 0:fcaad0dfa051 789 uint16_t _dev_addr16;
spastor 0:fcaad0dfa051 790
spastor 0:fcaad0dfa051 791 /** Serial Interface, use RawSerial as we dont use the streams */
spastor 0:fcaad0dfa051 792 RawSerial *_uart;
spastor 0:fcaad0dfa051 793
spastor 0:fcaad0dfa051 794 /** IO connected to the radio reset line */
spastor 0:fcaad0dfa051 795 DigitalOut *_reset;
spastor 0:fcaad0dfa051 796
spastor 0:fcaad0dfa051 797 /** Transmit options byte */
spastor 0:fcaad0dfa051 798 uint8_t _tx_options;
spastor 0:fcaad0dfa051 799
spastor 0:fcaad0dfa051 800 /** Broadcast radius, number of hops a broadcast transmission can occur.
spastor 0:fcaad0dfa051 801 * When set to 0 it will use the maximum */
spastor 0:fcaad0dfa051 802 uint8_t _bc_radius;
spastor 0:fcaad0dfa051 803 /** Array of frame handler pointers. We use an array instead of a vector or other
spastor 0:fcaad0dfa051 804 * data structure to save memory and avoid dynamic memory allocation, to avoid
spastor 0:fcaad0dfa051 805 * memory fragmentation */
spastor 0:fcaad0dfa051 806 FrameHandler *_fhandlers[MAX_FRAME_HANDLERS];
spastor 0:fcaad0dfa051 807
spastor 0:fcaad0dfa051 808 /** Hardware reset counter, automatically updated by the library */
spastor 0:fcaad0dfa051 809 volatile uint16_t _hw_reset_cnt;
spastor 0:fcaad0dfa051 810
spastor 0:fcaad0dfa051 811 /** Watchdog reset counter, automatically updated by the library */
spastor 0:fcaad0dfa051 812 volatile uint16_t _wd_reset_cnt;
spastor 0:fcaad0dfa051 813
spastor 0:fcaad0dfa051 814 uint16_t _reset_timeout;
spastor 0:fcaad0dfa051 815
spastor 0:fcaad0dfa051 816 /** Frame handler used for the Modem Status packets. Automatically registered when a callback
spastor 0:fcaad0dfa051 817 * function is registered */
spastor 0:fcaad0dfa051 818 FH_ModemStatus *_modem_status_handler;
spastor 0:fcaad0dfa051 819
spastor 0:fcaad0dfa051 820 /** Latest modem status received */
spastor 0:fcaad0dfa051 821 AtCmdFrame::ModemStatus _modem_status;
spastor 0:fcaad0dfa051 822
spastor 0:fcaad0dfa051 823 /** Library is initializing */
spastor 0:fcaad0dfa051 824 bool _initializing;
spastor 0:fcaad0dfa051 825
spastor 0:fcaad0dfa051 826 #if defined(ENABLE_PM_SUPPORT)
spastor 0:fcaad0dfa051 827 /* Power Management mode used by the radio */
spastor 0:fcaad0dfa051 828 PmMode _pm_mode;
spastor 0:fcaad0dfa051 829 /** IO connected to the radio on_sleep line */
spastor 0:fcaad0dfa051 830 InterruptIn *_on_sleep;
spastor 0:fcaad0dfa051 831 /** IO connected to the radio sleep_req line */
spastor 0:fcaad0dfa051 832 DigitalOut *_sleep_req;
spastor 0:fcaad0dfa051 833 #endif
spastor 0:fcaad0dfa051 834 };
spastor 0:fcaad0dfa051 835
spastor 0:fcaad0dfa051 836 } /* namespace XBeeLib */
spastor 0:fcaad0dfa051 837
spastor 0:fcaad0dfa051 838 #endif /* defined(__DIGI_RADIO_H_) */
spastor 0:fcaad0dfa051 839
spastor 0:fcaad0dfa051 840
spastor 0:fcaad0dfa051 841