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(__XBEE_ZB_H_)
spastor 0:fcaad0dfa051 14 #define __XBEE_ZB_H_
spastor 0:fcaad0dfa051 15
spastor 0:fcaad0dfa051 16 #include "XBee/XBee.h"
spastor 0:fcaad0dfa051 17 #include "FrameHandlers/FH_AtCmdResp.h"
spastor 0:fcaad0dfa051 18 #include "FrameHandlers/FH_RxPacketZB.h"
spastor 0:fcaad0dfa051 19 #include "FrameHandlers/FH_IoDataSampleZB.h"
spastor 0:fcaad0dfa051 20 #include "RemoteXBee/RemoteXBee.h"
spastor 0:fcaad0dfa051 21
spastor 0:fcaad0dfa051 22 namespace XBeeLib {
spastor 0:fcaad0dfa051 23
hbujanda 1:794d1d3e4a08 24 #define ND_OPTION_APPEND_DD (1 << 0)
hbujanda 1:794d1d3e4a08 25 #define ND_OPTION_SELF_RESPONSE (1 << 1)
hbujanda 1:794d1d3e4a08 26
spastor 0:fcaad0dfa051 27 /** Class for XBee ZigBee modules, derived from XBee */
spastor 0:fcaad0dfa051 28 class XBeeZB : public XBee
spastor 0:fcaad0dfa051 29 {
spastor 0:fcaad0dfa051 30 public:
spastor 0:fcaad0dfa051 31
spastor 0:fcaad0dfa051 32 /**
spastor 0:fcaad0dfa051 33 * IoLine for XBeeZB Modules
spastor 0:fcaad0dfa051 34 */
spastor 0:fcaad0dfa051 35 enum IoLine {
spastor 0:fcaad0dfa051 36 DIO0_AD0 = 0, /**< DIO0_AD0 pin */
spastor 0:fcaad0dfa051 37 DIO1_AD1 = 1, /**< DIO1_AD1 pin */
spastor 0:fcaad0dfa051 38 DIO2_AD2 = 2, /**< DIO2_AD2 pin */
spastor 0:fcaad0dfa051 39 DIO3_AD3 = 3, /**< DIO3_AD3 pin */
spastor 0:fcaad0dfa051 40 DIO4 = 4, /**< DIO4 pin */
spastor 0:fcaad0dfa051 41 DIO5 = 5, /**< DIO5 pin */
spastor 0:fcaad0dfa051 42 DIO6 = 6, /**< DIO6 pin */
spastor 0:fcaad0dfa051 43 DIO7 = 7, /**< DIO7 pin */
spastor 0:fcaad0dfa051 44 DIO10 = 10, /**< DIO10 pin */
spastor 0:fcaad0dfa051 45 DIO11 = 11, /**< DIO11 pin */
spastor 0:fcaad0dfa051 46 DIO12 = 12, /**< DIO12 pin */
spastor 0:fcaad0dfa051 47 SUPPLY_VOLTAGE = 7, /**< SUPPLY_VOLTAGE is not a real pin */
spastor 0:fcaad0dfa051 48 };
spastor 0:fcaad0dfa051 49
spastor 0:fcaad0dfa051 50 /** Class constructor
spastor 0:fcaad0dfa051 51 * @param tx the TX pin of the UART that will interface the XBee module
spastor 0:fcaad0dfa051 52 * @param rx the RX pin of the UART that will interface the XBee module
spastor 0:fcaad0dfa051 53 * @param reset the pin to which the XBee's reset line is attached to, use NC if not available
spastor 0:fcaad0dfa051 54 * @param rts the RTS pin for the UART that will interface the XBee module, use NC if not available
spastor 0:fcaad0dfa051 55 * @param cts the CTS pin for the UART that will interface the XBee module, use NC if not available
spastor 0:fcaad0dfa051 56 * @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 57 * to this baud rate (ATBD parameter). By default it is configured to 9600 bps
spastor 0:fcaad0dfa051 58 */
spastor 0:fcaad0dfa051 59 XBeeZB(PinName tx, PinName rx, PinName reset = NC, PinName rts = NC, PinName cts = NC, int baud = 9600);
spastor 0:fcaad0dfa051 60
spastor 0:fcaad0dfa051 61 /** Class destructor */
spastor 0:fcaad0dfa051 62 virtual ~XBeeZB();
spastor 0:fcaad0dfa051 63
spastor 0:fcaad0dfa051 64 /** init- initializes object
spastor 0:fcaad0dfa051 65 * This function must be called just after creating the object so it initializes internal data.
spastor 0:fcaad0dfa051 66 * @returns
spastor 0:fcaad0dfa051 67 * Success if the module has been properly initialized and is ready to process data.
spastor 0:fcaad0dfa051 68 * Failure otherwise.
spastor 0:fcaad0dfa051 69 */
spastor 0:fcaad0dfa051 70 RadioStatus init();
spastor 0:fcaad0dfa051 71
spastor 0:fcaad0dfa051 72 /** set_panid - sets the 64bit extended PAN ID.
spastor 0:fcaad0dfa051 73 *
spastor 0:fcaad0dfa051 74 * @note on ZigBee devices, if set to 0, the coordinator will select a random PAN ID
spastor 0:fcaad0dfa051 75 * and the routers will join any extended PAN ID
spastor 0:fcaad0dfa051 76 * @param panid the PAN ID value that will be set on the radio
spastor 0:fcaad0dfa051 77 * @returns
spastor 0:fcaad0dfa051 78 * Success if the operation was successful,
spastor 0:fcaad0dfa051 79 * Failure otherwise
spastor 0:fcaad0dfa051 80 */
spastor 0:fcaad0dfa051 81 RadioStatus set_panid(uint64_t panid);
spastor 0:fcaad0dfa051 82
spastor 0:fcaad0dfa051 83 /** get_configured_panid - gets the configured PAN ID, as it was set by @ref set_panid().
spastor 0:fcaad0dfa051 84 *
spastor 0:fcaad0dfa051 85 * @note on ZigBee devices, if set to 0, the coordinator will select a random PAN ID
spastor 0:fcaad0dfa051 86 * and the routers will join any extended PAN ID
spastor 0:fcaad0dfa051 87 * @param panid pointer where the configured PAN ID will be stored
spastor 0:fcaad0dfa051 88 * @returns
spastor 0:fcaad0dfa051 89 * Success if the operation was successful,
spastor 0:fcaad0dfa051 90 * Failure otherwise
spastor 0:fcaad0dfa051 91 */
spastor 0:fcaad0dfa051 92 RadioStatus get_configured_panid(uint64_t * const panid);
spastor 0:fcaad0dfa051 93
spastor 0:fcaad0dfa051 94 /** get_operating_panid - gets the operating 64bit extended PAN ID the module is running on. This is useful to determine the PAN ID when the ID parameter (@ref set_panid) is set to 0x00.
spastor 0:fcaad0dfa051 95 *
spastor 0:fcaad0dfa051 96 * @param panid pointer where the operating PAN ID will be stored
spastor 0:fcaad0dfa051 97 * @returns
spastor 0:fcaad0dfa051 98 * Success if the operation was successful,
spastor 0:fcaad0dfa051 99 * Failure otherwise
spastor 0:fcaad0dfa051 100 */
spastor 0:fcaad0dfa051 101 RadioStatus get_operating_panid(uint64_t * const panid);
spastor 0:fcaad0dfa051 102
spastor 0:fcaad0dfa051 103 /** set_panid - sets the 64bit extended PAN ID.
spastor 0:fcaad0dfa051 104 *
spastor 0:fcaad0dfa051 105 * @note on ZigBee devices, if set to 0, the coordinator will select a random PAN ID
spastor 0:fcaad0dfa051 106 * and the routers will join any extended PAN ID
spastor 0:fcaad0dfa051 107 * @param remote remote device
spastor 0:fcaad0dfa051 108 * @param panid the PAN ID value that will be set on the radio
spastor 0:fcaad0dfa051 109 * @returns
spastor 0:fcaad0dfa051 110 * Success if the operation was successful,
spastor 0:fcaad0dfa051 111 * Failure otherwise
spastor 0:fcaad0dfa051 112 */
spastor 0:fcaad0dfa051 113 RadioStatus set_panid(const RemoteXBee& remote, uint64_t panid);
spastor 0:fcaad0dfa051 114
spastor 0:fcaad0dfa051 115 /** get_configured_panid - gets the configured PAN ID in a remote node, as it was set by @ref set_panid()
spastor 0:fcaad0dfa051 116 *
spastor 0:fcaad0dfa051 117 * @note on ZigBee devices, if set to 0, the coordinator will select a random PAN ID
spastor 0:fcaad0dfa051 118 * and the routers will join any extended PAN ID
spastor 0:fcaad0dfa051 119 *
spastor 0:fcaad0dfa051 120 * @param remote remote device
spastor 0:fcaad0dfa051 121 * @param panid pointer where the configured PAN ID will be stored
spastor 0:fcaad0dfa051 122 * @returns
spastor 0:fcaad0dfa051 123 * Success if the operation was successful,
spastor 0:fcaad0dfa051 124 * Failure otherwise
spastor 0:fcaad0dfa051 125 */
spastor 0:fcaad0dfa051 126 RadioStatus get_configured_panid(const RemoteXBee& remote, uint64_t * const panid);
spastor 0:fcaad0dfa051 127
spastor 0:fcaad0dfa051 128 /** get_operating_panid - gets the operating 64bit extended PAN ID in which a remote node is running on. This is useful to determine the PAN ID when the ID parameter (@ref set_panid) is set to 0x00.
spastor 0:fcaad0dfa051 129 *
spastor 0:fcaad0dfa051 130 * @param remote remote device
spastor 0:fcaad0dfa051 131 * @param panid pointer where the operating PAN ID will be stored
spastor 0:fcaad0dfa051 132 * @returns
spastor 0:fcaad0dfa051 133 * Success if the operation was successful,
spastor 0:fcaad0dfa051 134 * Failure otherwise
spastor 0:fcaad0dfa051 135 */
spastor 0:fcaad0dfa051 136 RadioStatus get_operating_panid(const RemoteXBee& remote, uint64_t * const panid);
spastor 0:fcaad0dfa051 137
spastor 0:fcaad0dfa051 138 /** set_channel_mask - sets the channel mask in which the module will scan for the PAN ID (if it is a router or end-device) or start the network (if it is a coordinator).
spastor 0:fcaad0dfa051 139 * It should be set to the minimum available set of channels of all nodes in the network. Refer to "SC" parameter in the product manual for more information.
spastor 0:fcaad0dfa051 140 *
spastor 0:fcaad0dfa051 141 * @param chmask bit field list of channels to scan (router/end-devices) or to choose when starting a network (coordinator). Bit 0 is for channel 0x0B and bit 15 for channel 0x1A.
spastor 0:fcaad0dfa051 142 * @returns
spastor 0:fcaad0dfa051 143 * Success if the operation was successful,
spastor 0:fcaad0dfa051 144 * Failure otherwise
spastor 0:fcaad0dfa051 145 */
spastor 0:fcaad0dfa051 146 RadioStatus set_channel_mask(uint16_t const chmask);
spastor 0:fcaad0dfa051 147
spastor 0:fcaad0dfa051 148 /** get_channel_mask - gets the channel mask in which the module will scan for the PAN ID (if it is a router or end-device) or start the network (if it is a coordinator).
spastor 0:fcaad0dfa051 149 *
spastor 0:fcaad0dfa051 150 * @param chmask pointer to where the configured channel mask will be stored
spastor 0:fcaad0dfa051 151 * @returns
spastor 0:fcaad0dfa051 152 * Success if the operation was successful,
spastor 0:fcaad0dfa051 153 * Failure otherwise
spastor 0:fcaad0dfa051 154 */
spastor 0:fcaad0dfa051 155 RadioStatus get_channel_mask(uint16_t * const chmask);
spastor 0:fcaad0dfa051 156
spastor 0:fcaad0dfa051 157 /** check_for_coordinator_at_start - (Routers only) If enabled, a router will verify the coordinator is on its operating channel when joining or coming up from a power cycle.
spastor 0:fcaad0dfa051 158 * If a coordinator is not detected, the router will leave its current channel and attempt to join a new PAN. If JV=0, the router will continue operating on its current channel even if a coordinator is not detected.
spastor 0:fcaad0dfa051 159 *
spastor 0:fcaad0dfa051 160 * @param enable whether to enable this feature or not
spastor 0:fcaad0dfa051 161 * @returns
spastor 0:fcaad0dfa051 162 * Success if the operation was successful,
spastor 0:fcaad0dfa051 163 * Failure otherwise
spastor 0:fcaad0dfa051 164 */
spastor 0:fcaad0dfa051 165 RadioStatus check_for_coordinator_at_start(bool enable);
spastor 0:fcaad0dfa051 166
spastor 0:fcaad0dfa051 167 /** enable_network_encryption - Enable network encryption.
spastor 0:fcaad0dfa051 168 *
spastor 0:fcaad0dfa051 169 * @param enable whether to enable this feature or not
spastor 0:fcaad0dfa051 170 * @returns
spastor 0:fcaad0dfa051 171 * Success if the operation was successful,
spastor 0:fcaad0dfa051 172 * Failure otherwise
spastor 0:fcaad0dfa051 173 */
spastor 0:fcaad0dfa051 174 RadioStatus enable_network_encryption(bool enable);
spastor 0:fcaad0dfa051 175
spastor 0:fcaad0dfa051 176 /** set_encryption_key - Set the 128-bit AES network encryption key. If set to 0 (default), the module will select a random network key.
spastor 0:fcaad0dfa051 177 * It is not recommended to set the key programmatically, because it could be read through the raw serial port bits.
spastor 0:fcaad0dfa051 178 * @param key pointer to the 128-bit AES key
spastor 0:fcaad0dfa051 179 * @param length size of the buffer pointed by 'key'
spastor 0:fcaad0dfa051 180 * @returns
spastor 0:fcaad0dfa051 181 * Success if the operation was successful,
spastor 0:fcaad0dfa051 182 * Failure otherwise
spastor 0:fcaad0dfa051 183 */
spastor 0:fcaad0dfa051 184 RadioStatus set_encryption_key(const uint8_t * const key, const uint16_t length);
spastor 0:fcaad0dfa051 185
spastor 0:fcaad0dfa051 186 /** set_tc_link_key - Set the Trust Center 128-bit AES link key. 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 0:fcaad0dfa051 187 * It is not recommended to set the key programmatically, because it could be read through the raw serial port bits.
spastor 0:fcaad0dfa051 188 * @param key pointer to the 128-bit AES key
spastor 0:fcaad0dfa051 189 * @param length size of the buffer pointed by 'key'
spastor 0:fcaad0dfa051 190 * @returns
spastor 0:fcaad0dfa051 191 * Success if the operation was successful,
spastor 0:fcaad0dfa051 192 * Failure otherwise
spastor 0:fcaad0dfa051 193 */
spastor 0:fcaad0dfa051 194 RadioStatus set_tc_link_key(const uint8_t * const key, const uint16_t length);
spastor 0:fcaad0dfa051 195
spastor 0:fcaad0dfa051 196 #define XBEE_ZB_ENC_OPT_SEND_KEY_ON_JOIN 0x01
spastor 0:fcaad0dfa051 197 #define XBEE_ZB_ENC_OPT_USE_TRUST_CENTER 0x02
spastor 0:fcaad0dfa051 198 /** set_encryption_options - Configure options for encryption. Unused option bits should be set to 0. Options include:
spastor 0:fcaad0dfa051 199 * - XBEE_ZB_ENC_OPT_SEND_KEY_ON_JOIN - Send the security key unsecured over-the-air during joins
spastor 0:fcaad0dfa051 200 * - XBEE_ZB_ENC_OPT_USE_TRUST_CENTER - Use trust center (coordinator only)
spastor 0:fcaad0dfa051 201 * @param options bit mask with the encryption options
spastor 0:fcaad0dfa051 202 * @returns
spastor 0:fcaad0dfa051 203 * Success if the operation was successful,
spastor 0:fcaad0dfa051 204 * Failure otherwise
spastor 0:fcaad0dfa051 205 */
spastor 0:fcaad0dfa051 206 RadioStatus set_encryption_options(const uint8_t options);
spastor 0:fcaad0dfa051 207
spastor 0:fcaad0dfa051 208 /** register_node_discovery_cb - registers the callback function that will be called
spastor 0:fcaad0dfa051 209 * when the responses to the node discovery command arrive
spastor 0:fcaad0dfa051 210 *
spastor 0:fcaad0dfa051 211 * @param function function pointer with the callback function
spastor 0:fcaad0dfa051 212 */
spastor 0:fcaad0dfa051 213 void register_node_discovery_cb(node_discovery_zb_cb_t function);
spastor 0:fcaad0dfa051 214
spastor 0:fcaad0dfa051 215 /** unregister_node_discovery_cb - removes the node discovery callback */
spastor 0:fcaad0dfa051 216 void unregister_node_discovery_cb();
spastor 0:fcaad0dfa051 217
spastor 0:fcaad0dfa051 218 /** register_receive_cb - registers the callback function that will be called
spastor 0:fcaad0dfa051 219 * when a data packet is received
spastor 0:fcaad0dfa051 220 *
spastor 0:fcaad0dfa051 221 * @param function function pointer with the callback function
spastor 0:fcaad0dfa051 222 */
spastor 0:fcaad0dfa051 223 void register_receive_cb(receive_zb_cb_t function);
spastor 0:fcaad0dfa051 224
spastor 0:fcaad0dfa051 225 /** unregister_receive_cb - removes the rx packet callback */
spastor 0:fcaad0dfa051 226 void unregister_receive_cb();
spastor 0:fcaad0dfa051 227
spastor 0:fcaad0dfa051 228 /** register_io_sample_cb - registers the callback function that will be called
spastor 0:fcaad0dfa051 229 * when a IO Sample Data packet is received
spastor 0:fcaad0dfa051 230 *
spastor 0:fcaad0dfa051 231 * @param function function pointer with the callback function
spastor 0:fcaad0dfa051 232 */
spastor 0:fcaad0dfa051 233 void register_io_sample_cb(io_data_cb_zb_t function);
spastor 0:fcaad0dfa051 234
spastor 0:fcaad0dfa051 235 /** unregister_io_sample_cb - removes the IO Sample Data reception callback */
spastor 0:fcaad0dfa051 236 void unregister_io_sample_cb();
spastor 0:fcaad0dfa051 237
spastor 0:fcaad0dfa051 238 /** get_network_role - returns the role of this device in the ZigBee network
spastor 0:fcaad0dfa051 239 *
spastor 0:fcaad0dfa051 240 * @returns the role of this device
spastor 0:fcaad0dfa051 241 */
spastor 0:fcaad0dfa051 242 NetworkRole get_network_role();
spastor 0:fcaad0dfa051 243 /** */
spastor 0:fcaad0dfa051 244
spastor 0:fcaad0dfa051 245 /*********************** send_data member methods ************************/
spastor 0:fcaad0dfa051 246 /** send_data - sends data to a remote device waiting for the packet
spastor 0:fcaad0dfa051 247 * answer with the result of the operation
spastor 0:fcaad0dfa051 248 *
spastor 0:fcaad0dfa051 249 * @param remote remote device
spastor 0:fcaad0dfa051 250 * @param data pointer to the data that will be sent
spastor 0:fcaad0dfa051 251 * @param len number of bytes that will be transmitted
spastor 0:fcaad0dfa051 252 * @returns the result of the data transfer
spastor 0:fcaad0dfa051 253 * TxStatusSuccess if the operation was successful,
spastor 0:fcaad0dfa051 254 * the error code otherwise
spastor 0:fcaad0dfa051 255 */
spastor 0:fcaad0dfa051 256 virtual TxStatus send_data(const RemoteXBee& remote, const uint8_t *const data, uint16_t len);
spastor 0:fcaad0dfa051 257
spastor 0:fcaad0dfa051 258 /** send_data - sends data to a remote device waiting for the packet
spastor 0:fcaad0dfa051 259 * answer with the result of the operation
spastor 0:fcaad0dfa051 260 *
spastor 0:fcaad0dfa051 261 * @param remote64 64bit address of the remote device
spastor 0:fcaad0dfa051 262 * @param data pointer to the data that will be sent
spastor 0:fcaad0dfa051 263 * @param len number of bytes that will be transmitted
spastor 0:fcaad0dfa051 264 * @returns the result of the data transfer
spastor 0:fcaad0dfa051 265 * TxStatusSuccess if the operation was successful,
spastor 0:fcaad0dfa051 266 * the error code otherwise
spastor 0:fcaad0dfa051 267 */
spastor 0:fcaad0dfa051 268 TxStatus send_data(uint64_t remote64, const uint8_t *const data, uint16_t len);
spastor 0:fcaad0dfa051 269
spastor 0:fcaad0dfa051 270 /** send_data - sends data to a remote device waiting for the packet
spastor 0:fcaad0dfa051 271 * answer with the result of the operation. The main difference
spastor 0:fcaad0dfa051 272 * with the previous method is that includes the network address
spastor 0:fcaad0dfa051 273 * being more effective, not being neccesary to discover it
spastor 0:fcaad0dfa051 274 *
spastor 0:fcaad0dfa051 275 * @param remote64 64bit address of the remote device
spastor 0:fcaad0dfa051 276 * @param remote16 16bit network address of the remote device
spastor 0:fcaad0dfa051 277 * @param data pointer to the data that will be sent
spastor 0:fcaad0dfa051 278 * @param len number of bytes that will be transmitted
spastor 0:fcaad0dfa051 279 * @returns the result of the data transfer
spastor 0:fcaad0dfa051 280 * TxStatusSuccess if the operation was successful,
spastor 0:fcaad0dfa051 281 * the error code otherwise
spastor 0:fcaad0dfa051 282 */
spastor 0:fcaad0dfa051 283 TxStatus send_data(uint64_t remote64, uint16_t remote16,
spastor 0:fcaad0dfa051 284 const uint8_t *const data, uint16_t len);
spastor 0:fcaad0dfa051 285
spastor 0:fcaad0dfa051 286 /** send_data - sends data to a remote device waiting for the packet
spastor 0:fcaad0dfa051 287 * answer with the result of the operation. This method uses
spastor 0:fcaad0dfa051 288 * the explicit addressing frame, allowing to use source and
spastor 0:fcaad0dfa051 289 * destination end points and cluster and profile IDs
spastor 0:fcaad0dfa051 290 *
spastor 0:fcaad0dfa051 291 * @param remote remote device
spastor 0:fcaad0dfa051 292 * @param source_ep source end point
spastor 0:fcaad0dfa051 293 * @param dest_ep destination end point
spastor 0:fcaad0dfa051 294 * @param cluster_id cluster ID
spastor 0:fcaad0dfa051 295 * @param profile_id profile ID
spastor 0:fcaad0dfa051 296 * @param data pointer to the data that will be sent
spastor 0:fcaad0dfa051 297 * @param len number of bytes that will be transmitted
spastor 0:fcaad0dfa051 298 * @returns the result of the data transfer
spastor 0:fcaad0dfa051 299 * TxStatusSuccess if the operation was successful,
spastor 0:fcaad0dfa051 300 * the error code otherwise
spastor 0:fcaad0dfa051 301 */
spastor 0:fcaad0dfa051 302 TxStatus send_data(const RemoteXBee& remote, uint8_t source_ep,
spastor 0:fcaad0dfa051 303 uint8_t dest_ep, uint16_t cluster_id, uint16_t profile_id,
spastor 0:fcaad0dfa051 304 const uint8_t *const data, uint16_t len);
spastor 0:fcaad0dfa051 305
spastor 0:fcaad0dfa051 306 /** send_data - sends data to a remote device waiting for the packet
spastor 0:fcaad0dfa051 307 * answer with the result of the operation. This method uses
spastor 0:fcaad0dfa051 308 * the explicit addressing frame, allowing to use source and
spastor 0:fcaad0dfa051 309 * destination end points and cluster and profile IDs
spastor 0:fcaad0dfa051 310 *
spastor 0:fcaad0dfa051 311 * @param remote64 64bit address of the remote device
spastor 0:fcaad0dfa051 312 * @param remote16 16bit network address of the remote device
spastor 0:fcaad0dfa051 313 * @param source_ep source end point
spastor 0:fcaad0dfa051 314 * @param dest_ep destination end point
spastor 0:fcaad0dfa051 315 * @param cluster_id cluster ID
spastor 0:fcaad0dfa051 316 * @param profile_id profile ID
spastor 0:fcaad0dfa051 317 * @param data pointer to the data that will be sent
spastor 0:fcaad0dfa051 318 * @param len number of bytes that will be transmitted
spastor 0:fcaad0dfa051 319 * @returns the result of the data transfer
spastor 0:fcaad0dfa051 320 * TxStatusSuccess if the operation was successful,
spastor 0:fcaad0dfa051 321 * the error code otherwise
spastor 0:fcaad0dfa051 322 */
spastor 0:fcaad0dfa051 323 TxStatus send_data(uint64_t remote64, uint16_t remote16, uint8_t source_ep,
spastor 0:fcaad0dfa051 324 uint8_t dest_ep, uint16_t cluster_id, uint16_t profile_id,
spastor 0:fcaad0dfa051 325 const uint8_t *const data, uint16_t len);
spastor 0:fcaad0dfa051 326
spastor 0:fcaad0dfa051 327 /** send_data_to_coordinator - sends data to the ZigBee coordinator waiting for the
spastor 0:fcaad0dfa051 328 * packet answer with the result of the operation
spastor 0:fcaad0dfa051 329 *
spastor 0:fcaad0dfa051 330 * @param data pointer to the data that will be sent
spastor 0:fcaad0dfa051 331 * @param len number of bytes that will be transmitted
spastor 0:fcaad0dfa051 332 * @returns the result of the data transfer
spastor 0:fcaad0dfa051 333 * TxStatusSuccess if the operation was successful,
spastor 0:fcaad0dfa051 334 * the error code otherwise
spastor 0:fcaad0dfa051 335 */
spastor 0:fcaad0dfa051 336 TxStatus send_data_to_coordinator(const uint8_t *const data, uint16_t len);
spastor 0:fcaad0dfa051 337
spastor 0:fcaad0dfa051 338 /** is_joined - checks if the device is joined to ZigBee network
spastor 0:fcaad0dfa051 339 * @returns true if joined, false otherwise
spastor 0:fcaad0dfa051 340 */
spastor 0:fcaad0dfa051 341 bool is_joined();
spastor 0:fcaad0dfa051 342
hbujanda 1:794d1d3e4a08 343 /** get_device_by_id - finds and retrieves a pointer to the remote device in
hbujanda 1:794d1d3e4a08 344 * the network whose device id matches with the parameter
spastor 0:fcaad0dfa051 345 *
spastor 0:fcaad0dfa051 346 * @param node_id node id of the device we are looking for
hbujanda 1:794d1d3e4a08 347 * @returns a pointer to the remote object device created or NULL if the device
hbujanda 1:794d1d3e4a08 348 * was not found
spastor 0:fcaad0dfa051 349 */
hbujanda 1:794d1d3e4a08 350 XBeeZB * get_device_by_id(const char * const node_id);
hbujanda 1:794d1d3e4a08 351
hbujanda 1:794d1d3e4a08 352 /** get_device_by_id - searches for a device in the network with the especified
hbujanda 1:794d1d3e4a08 353 * node id, if found, returns its 64 bit address
hbujanda 1:794d1d3e4a08 354 *
hbujanda 1:794d1d3e4a08 355 * @param node_id node id of the device we are looking for
hbujanda 1:794d1d3e4a08 356 * @returns an object with the 64 bit address of the remote device whose node id
hbujanda 1:794d1d3e4a08 357 * matches with the parameter
hbujanda 1:794d1d3e4a08 358 */
hbujanda 1:794d1d3e4a08 359 RadioStatus get_device_by_id(const char * const node_id, uint64_t * const dev_addr);
spastor 0:fcaad0dfa051 360
spastor 0:fcaad0dfa051 361 /* Allow using XBee::set_param() methods for local radio from this class */
spastor 0:fcaad0dfa051 362 using XBee::set_param;
spastor 0:fcaad0dfa051 363
spastor 0:fcaad0dfa051 364 /** set_param - sets a parameter in a remote radio by sending an AT command and waiting for the response.
spastor 0:fcaad0dfa051 365 *
spastor 0:fcaad0dfa051 366 * @param remote remote device
spastor 0:fcaad0dfa051 367 * @param param parameter to be set.
spastor 0:fcaad0dfa051 368 * @param data the parameter value (4 bytes) to be set.
spastor 0:fcaad0dfa051 369 * @returns the command response status.
spastor 0:fcaad0dfa051 370 */
spastor 0:fcaad0dfa051 371 virtual AtCmdFrame::AtCmdResp set_param(const RemoteXBee& remote, const char * const param, uint32_t data);
spastor 0:fcaad0dfa051 372
spastor 0:fcaad0dfa051 373 /** set_param - sets a parameter in a remote radio by sending an AT command and waiting for the response.
spastor 0:fcaad0dfa051 374 *
spastor 0:fcaad0dfa051 375 * @param remote remote device
spastor 0:fcaad0dfa051 376 * @param param parameter to be set.
spastor 0:fcaad0dfa051 377 * @param data the parameter value byte array (len bytes) to be set.
spastor 0:fcaad0dfa051 378 * @param len number of bytes of the parameter value.
spastor 0:fcaad0dfa051 379 * @returns the command response status.
spastor 0:fcaad0dfa051 380 */
spastor 0:fcaad0dfa051 381 virtual AtCmdFrame::AtCmdResp set_param(const RemoteXBee& remote, const char * const param, const uint8_t * data = NULL, uint16_t len = 0);
spastor 0:fcaad0dfa051 382
spastor 0:fcaad0dfa051 383 /* Allow using XBee::get_param() methods for local radio from this class */
spastor 0:fcaad0dfa051 384 using XBee::get_param;
spastor 0:fcaad0dfa051 385
spastor 0:fcaad0dfa051 386 /** get_param - gets a parameter from a remote radio by sending an AT command and waiting for the response.
spastor 0:fcaad0dfa051 387 *
spastor 0:fcaad0dfa051 388 * @param remote remote device
spastor 0:fcaad0dfa051 389 * @param param parameter to be get.
spastor 0:fcaad0dfa051 390 * @param data pointer where the param value (4 bytes) will be stored.
spastor 0:fcaad0dfa051 391 * @returns the command response status.
spastor 0:fcaad0dfa051 392 */
spastor 0:fcaad0dfa051 393 virtual AtCmdFrame::AtCmdResp get_param(const RemoteXBee& remote, const char * const param, uint32_t * const data);
spastor 0:fcaad0dfa051 394
spastor 0:fcaad0dfa051 395 /** get_param - gets a parameter from a remote radio by sending an AT command and waiting for the response.
spastor 0:fcaad0dfa051 396 *
spastor 0:fcaad0dfa051 397 * @param remote remote device
spastor 0:fcaad0dfa051 398 * @param param parameter to be get.
spastor 0:fcaad0dfa051 399 * @param data pointer where the param value (n bytes) will be stored.
spastor 0:fcaad0dfa051 400 * @param len pointer where the number of bytes of the param value will be stored.
spastor 0:fcaad0dfa051 401 * @returns the command response status.
spastor 0:fcaad0dfa051 402 */
spastor 0:fcaad0dfa051 403 virtual AtCmdFrame::AtCmdResp get_param(const RemoteXBee& remote, const char * const param, uint8_t * const data, uint16_t * const len);
spastor 0:fcaad0dfa051 404
spastor 0:fcaad0dfa051 405 /************************* IO member methods **************************/
spastor 0:fcaad0dfa051 406 /** set_pin_config - configures a radio IO line
spastor 0:fcaad0dfa051 407 *
spastor 0:fcaad0dfa051 408 * @param remote remote device
spastor 0:fcaad0dfa051 409 * @param line IO line being configured
spastor 0:fcaad0dfa051 410 * @param mode configuration mode for the selected line
spastor 0:fcaad0dfa051 411 * @returns
spastor 0:fcaad0dfa051 412 * Success if the operation was successful,
spastor 0:fcaad0dfa051 413 * Failure otherwise
spastor 0:fcaad0dfa051 414 */
spastor 0:fcaad0dfa051 415 RadioStatus set_pin_config(const RemoteXBee& remote, IoLine line, IoMode mode);
spastor 0:fcaad0dfa051 416
spastor 0:fcaad0dfa051 417 /** get_pin_config - gets the configuration of a radio IO line
spastor 0:fcaad0dfa051 418 *
spastor 0:fcaad0dfa051 419 * @param remote remote device
spastor 0:fcaad0dfa051 420 * @param line IO line being read to get its configuration
spastor 0:fcaad0dfa051 421 * @param mode pointer where the configuration will be stored
spastor 0:fcaad0dfa051 422 * @returns
spastor 0:fcaad0dfa051 423 * Success if the operation was successful,
spastor 0:fcaad0dfa051 424 * Failure otherwise
spastor 0:fcaad0dfa051 425 */
spastor 0:fcaad0dfa051 426 RadioStatus get_pin_config(const RemoteXBee& remote, IoLine line, IoMode * const mode);
spastor 0:fcaad0dfa051 427
spastor 0:fcaad0dfa051 428 /** set_dio - sets to low/high a DIO line
spastor 0:fcaad0dfa051 429 *
spastor 0:fcaad0dfa051 430 * @param remote remote device
spastor 0:fcaad0dfa051 431 * @param line DIO line being set
spastor 0:fcaad0dfa051 432 * @param val value that will be set in the DIO line
spastor 0:fcaad0dfa051 433 * @returns
spastor 0:fcaad0dfa051 434 * Success if the operation was successful,
spastor 0:fcaad0dfa051 435 * Failure otherwise
spastor 0:fcaad0dfa051 436 */
spastor 0:fcaad0dfa051 437 RadioStatus set_dio(const RemoteXBee& remote, IoLine line, DioVal val);
spastor 0:fcaad0dfa051 438
spastor 0:fcaad0dfa051 439 /** get_dio - read the value of a DIO configured as digital input
spastor 0:fcaad0dfa051 440 *
spastor 0:fcaad0dfa051 441 * @param remote remote device
spastor 0:fcaad0dfa051 442 * @param line DIO line being read
spastor 0:fcaad0dfa051 443 * @param val pointer where the DIO value read will be stored
spastor 0:fcaad0dfa051 444 * @returns
spastor 0:fcaad0dfa051 445 * Success if the operation was successful,
spastor 0:fcaad0dfa051 446 * Failure otherwise
spastor 0:fcaad0dfa051 447 */
spastor 0:fcaad0dfa051 448 RadioStatus get_dio(const RemoteXBee& remote, IoLine line, DioVal * const val);
spastor 0:fcaad0dfa051 449
spastor 0:fcaad0dfa051 450 /** get_adc - read the value of the espcified ADC line
spastor 0:fcaad0dfa051 451 *
spastor 0:fcaad0dfa051 452 * @param remote remote device
spastor 0:fcaad0dfa051 453 * @param line ADC line being read
spastor 0:fcaad0dfa051 454 * @param val pointer where the value read from hte ADC will be stored
spastor 0:fcaad0dfa051 455 * @returns
spastor 0:fcaad0dfa051 456 * Success if the operation was successful,
spastor 0:fcaad0dfa051 457 * Failure otherwise
spastor 0:fcaad0dfa051 458 */
spastor 0:fcaad0dfa051 459 RadioStatus get_adc(const RemoteXBee& remote, IoLine line, uint16_t * const val);
spastor 0:fcaad0dfa051 460
spastor 0:fcaad0dfa051 461 /** set_pin_pull_up - enables or disables the internal pull-up resistor of a line
spastor 0:fcaad0dfa051 462 *
spastor 0:fcaad0dfa051 463 * @param remote remote device
spastor 0:fcaad0dfa051 464 * @param line line being configured for pull-up
spastor 0:fcaad0dfa051 465 * @param enable whether to enable the internal pull-up resistor.
spastor 0:fcaad0dfa051 466 * @returns
spastor 0:fcaad0dfa051 467 * Success if the operation was successful,
spastor 0:fcaad0dfa051 468 * Failure otherwise
spastor 0:fcaad0dfa051 469 */
spastor 0:fcaad0dfa051 470 RadioStatus set_pin_pull_up(const RemoteXBee& remote, IoLine line, bool enable);
spastor 0:fcaad0dfa051 471
spastor 0:fcaad0dfa051 472 /** enable_dio_change_detection - enables or disables the notification when a change is detected in a digital input line.
spastor 0:fcaad0dfa051 473 * In other words, it will force an IO Sample transmission when the DIO state changes. Only for DIO0 to DIO11.
spastor 0:fcaad0dfa051 474 *
spastor 0:fcaad0dfa051 475 * @param remote remote device
spastor 0:fcaad0dfa051 476 * @param line line being configured for pull-up
spastor 0:fcaad0dfa051 477 * @param enable whether to enable the internal pull-up resistor.
spastor 0:fcaad0dfa051 478 * @returns
spastor 0:fcaad0dfa051 479 * Success if the operation was successful,
spastor 0:fcaad0dfa051 480 * Failure otherwise
spastor 0:fcaad0dfa051 481 */
spastor 0:fcaad0dfa051 482 RadioStatus enable_dio_change_detection(const RemoteXBee& remote, IoLine line, bool enable);
spastor 0:fcaad0dfa051 483
spastor 0:fcaad0dfa051 484 protected:
spastor 0:fcaad0dfa051 485 /** Role of this device in the ZigBee network (coord, router or end device) */
spastor 0:fcaad0dfa051 486 NetworkRole _nw_role;
spastor 0:fcaad0dfa051 487
spastor 0:fcaad0dfa051 488 /** Indicates if the device is joined to a network. This variable is automatically updated
spastor 0:fcaad0dfa051 489 * by the library. If the device is acting as coordinator, its value its true */
spastor 0:fcaad0dfa051 490 volatile bool _joined_network;
spastor 0:fcaad0dfa051 491
spastor 0:fcaad0dfa051 492 /** Vcc exceeded counter, automatically updated by the library */
spastor 0:fcaad0dfa051 493 volatile uint16_t _vcc_exceeded_cnt;
spastor 0:fcaad0dfa051 494
spastor 0:fcaad0dfa051 495 /* TODO, add setter/getter */
spastor 0:fcaad0dfa051 496 uint8_t _broadcast_radious;
spastor 0:fcaad0dfa051 497
spastor 0:fcaad0dfa051 498 /** Frame handler used for the node discovery. Registered when a callback function
spastor 0:fcaad0dfa051 499 * is registered */
spastor 0:fcaad0dfa051 500 FH_NodeDiscoveryZB *_nd_handler;
spastor 0:fcaad0dfa051 501
spastor 0:fcaad0dfa051 502 /** Frame handler used for the rx packets. Automatically registered when a callback
spastor 0:fcaad0dfa051 503 * function is registered */
spastor 0:fcaad0dfa051 504 FH_RxPacketZB *_rx_pkt_handler;
spastor 0:fcaad0dfa051 505
spastor 0:fcaad0dfa051 506 /** Frame handler used for the IO Data Sample packets. Automatically registered when a callback
spastor 0:fcaad0dfa051 507 * function is registered */
spastor 0:fcaad0dfa051 508 FH_IoDataSampeZB *_io_data_handler;
spastor 0:fcaad0dfa051 509
spastor 0:fcaad0dfa051 510 /** Method called directly by the library when a modem status frame is received to
spastor 0:fcaad0dfa051 511 * update the internal status variables */
spastor 0:fcaad0dfa051 512 virtual void radio_status_update(AtCmdFrame::ModemStatus modem_status);
spastor 0:fcaad0dfa051 513
spastor 0:fcaad0dfa051 514 /* Allow using XBee::send_data() methods from this class */
spastor 0:fcaad0dfa051 515 using XBee::send_data;
spastor 0:fcaad0dfa051 516 };
spastor 0:fcaad0dfa051 517
spastor 0:fcaad0dfa051 518 } /* namespace XBeeLib */
spastor 0:fcaad0dfa051 519
spastor 0:fcaad0dfa051 520 #endif /* __XBEE_ZB_H_ */
spastor 0:fcaad0dfa051 521
spastor 0:fcaad0dfa051 522