Vergil Cola
/
MQTTGateway2
Fork of my original MQTTGateway
XbeeMonitor/XBeeLib/XBeeZB/XBeeZB.h@0:a1734fe1ec4b, 2017-04-08 (annotated)
- Committer:
- vpcola
- Date:
- Sat Apr 08 14:43:14 2017 +0000
- Revision:
- 0:a1734fe1ec4b
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vpcola | 0:a1734fe1ec4b | 1 | /** |
vpcola | 0:a1734fe1ec4b | 2 | * Copyright (c) 2015 Digi International Inc., |
vpcola | 0:a1734fe1ec4b | 3 | * All rights not expressly granted are reserved. |
vpcola | 0:a1734fe1ec4b | 4 | * |
vpcola | 0:a1734fe1ec4b | 5 | * This Source Code Form is subject to the terms of the Mozilla Public |
vpcola | 0:a1734fe1ec4b | 6 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
vpcola | 0:a1734fe1ec4b | 7 | * You can obtain one at http://mozilla.org/MPL/2.0/. |
vpcola | 0:a1734fe1ec4b | 8 | * |
vpcola | 0:a1734fe1ec4b | 9 | * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343 |
vpcola | 0:a1734fe1ec4b | 10 | * ======================================================================= |
vpcola | 0:a1734fe1ec4b | 11 | */ |
vpcola | 0:a1734fe1ec4b | 12 | |
vpcola | 0:a1734fe1ec4b | 13 | #if !defined(__XBEE_ZB_H_) |
vpcola | 0:a1734fe1ec4b | 14 | #define __XBEE_ZB_H_ |
vpcola | 0:a1734fe1ec4b | 15 | |
vpcola | 0:a1734fe1ec4b | 16 | #include "XBee/XBee.h" |
vpcola | 0:a1734fe1ec4b | 17 | #include "FrameHandlers/FH_AtCmdResp.h" |
vpcola | 0:a1734fe1ec4b | 18 | #include "FrameHandlers/FH_RxPacketZB.h" |
vpcola | 0:a1734fe1ec4b | 19 | #include "FrameHandlers/FH_IoDataSampleZB.h" |
vpcola | 0:a1734fe1ec4b | 20 | #include "RemoteXBee/RemoteXBee.h" |
vpcola | 0:a1734fe1ec4b | 21 | |
vpcola | 0:a1734fe1ec4b | 22 | namespace XBeeLib { |
vpcola | 0:a1734fe1ec4b | 23 | |
vpcola | 0:a1734fe1ec4b | 24 | /** Class for XBee ZigBee modules, derived from XBee */ |
vpcola | 0:a1734fe1ec4b | 25 | class XBeeZB : public XBee |
vpcola | 0:a1734fe1ec4b | 26 | { |
vpcola | 0:a1734fe1ec4b | 27 | public: |
vpcola | 0:a1734fe1ec4b | 28 | |
vpcola | 0:a1734fe1ec4b | 29 | /** |
vpcola | 0:a1734fe1ec4b | 30 | * IoLine for XBeeZB Modules |
vpcola | 0:a1734fe1ec4b | 31 | */ |
vpcola | 0:a1734fe1ec4b | 32 | enum IoLine { |
vpcola | 0:a1734fe1ec4b | 33 | DIO0_AD0 = 0, /**< DIO0_AD0 pin */ |
vpcola | 0:a1734fe1ec4b | 34 | DIO1_AD1 = 1, /**< DIO1_AD1 pin */ |
vpcola | 0:a1734fe1ec4b | 35 | DIO2_AD2 = 2, /**< DIO2_AD2 pin */ |
vpcola | 0:a1734fe1ec4b | 36 | DIO3_AD3 = 3, /**< DIO3_AD3 pin */ |
vpcola | 0:a1734fe1ec4b | 37 | DIO4 = 4, /**< DIO4 pin */ |
vpcola | 0:a1734fe1ec4b | 38 | DIO5 = 5, /**< DIO5 pin */ |
vpcola | 0:a1734fe1ec4b | 39 | DIO6 = 6, /**< DIO6 pin */ |
vpcola | 0:a1734fe1ec4b | 40 | DIO7 = 7, /**< DIO7 pin */ |
vpcola | 0:a1734fe1ec4b | 41 | DIO10 = 10, /**< DIO10 pin */ |
vpcola | 0:a1734fe1ec4b | 42 | DIO11 = 11, /**< DIO11 pin */ |
vpcola | 0:a1734fe1ec4b | 43 | DIO12 = 12, /**< DIO12 pin */ |
vpcola | 0:a1734fe1ec4b | 44 | SUPPLY_VOLTAGE = 7, /**< SUPPLY_VOLTAGE is not a real pin */ |
vpcola | 0:a1734fe1ec4b | 45 | }; |
vpcola | 0:a1734fe1ec4b | 46 | |
vpcola | 0:a1734fe1ec4b | 47 | enum AssocStatus { |
vpcola | 0:a1734fe1ec4b | 48 | ErrorReading = -1, /**< Error occurred when reading parameter. */ |
vpcola | 0:a1734fe1ec4b | 49 | Joined = 0x00, /**< Successfully formed or joined a network. (Coordinators form a network, routers and end devices join a network.) */ |
vpcola | 0:a1734fe1ec4b | 50 | NoPANs = 0x21, /**< Scan found no PANs */ |
vpcola | 0:a1734fe1ec4b | 51 | NoValidPAN = 0x22, /**< Scan found no valid PANs based on current SC and ID settings */ |
vpcola | 0:a1734fe1ec4b | 52 | JoinNotAllowed = 0x23, /**< Valid Coordinator or Routers found, but they are not allowing joining (NJ expired). */ |
vpcola | 0:a1734fe1ec4b | 53 | NoBeacons = 0x24, /**< No joinable beacons were found. */ |
vpcola | 0:a1734fe1ec4b | 54 | Unexpected = 0x25, /**< Unexpected state, node should not be attempting to join at this time. */ |
vpcola | 0:a1734fe1ec4b | 55 | JoinFailed = 0x27, /**< Node Joining attempt failed (typically due to incompatible security settings). */ |
vpcola | 0:a1734fe1ec4b | 56 | CoordStartFail = 0x2A, /**< Coordinator start attempt failed */ |
vpcola | 0:a1734fe1ec4b | 57 | CheckingCoord = 0x2B, /**< Checking for an existing coordinator. */ |
vpcola | 0:a1734fe1ec4b | 58 | LeaveFail = 0x2C, /**< Attempt to leave the network failed. */ |
vpcola | 0:a1734fe1ec4b | 59 | JoinNoResponse = 0xAB, /**< Attempted to join a device that did not respond. */ |
vpcola | 0:a1734fe1ec4b | 60 | SecKeyUnsec = 0xAC, /**< Secure join error - network security key received unsecured. */ |
vpcola | 0:a1734fe1ec4b | 61 | SecKeyNotRec = 0xAD, /**< Secure join error - network security key not received. */ |
vpcola | 0:a1734fe1ec4b | 62 | SecBadKey = 0xAF, /**< Secure join error - joining device does not have the right preconfigured link key. */ |
vpcola | 0:a1734fe1ec4b | 63 | Scanning = 0xFF /**< Scanning for a ZigBee network (routers and end devices). */ |
vpcola | 0:a1734fe1ec4b | 64 | }; |
vpcola | 0:a1734fe1ec4b | 65 | |
vpcola | 0:a1734fe1ec4b | 66 | /** Class constructor |
vpcola | 0:a1734fe1ec4b | 67 | * @param tx the TX pin of the UART that will interface the XBee module |
vpcola | 0:a1734fe1ec4b | 68 | * @param rx the RX pin of the UART that will interface the XBee module |
vpcola | 0:a1734fe1ec4b | 69 | * @param reset the pin to which the XBee's reset line is attached to, use NC if not available |
vpcola | 0:a1734fe1ec4b | 70 | * @param rts the RTS pin for the UART that will interface the XBee module, use NC if not available |
vpcola | 0:a1734fe1ec4b | 71 | * @param cts the CTS pin for the UART that will interface the XBee module, use NC if not available |
vpcola | 0:a1734fe1ec4b | 72 | * @param baud the baudrate for the UART that will interface the XBee module. Note that the module has to be already configured |
vpcola | 0:a1734fe1ec4b | 73 | * to this baud rate (ATBD parameter). By default it is configured to 9600 bps |
vpcola | 0:a1734fe1ec4b | 74 | */ |
vpcola | 0:a1734fe1ec4b | 75 | XBeeZB(PinName tx, PinName rx, PinName reset = NC, PinName rts = NC, PinName cts = NC, int baud = 9600); |
vpcola | 0:a1734fe1ec4b | 76 | |
vpcola | 0:a1734fe1ec4b | 77 | /** Class destructor */ |
vpcola | 0:a1734fe1ec4b | 78 | virtual ~XBeeZB(); |
vpcola | 0:a1734fe1ec4b | 79 | |
vpcola | 0:a1734fe1ec4b | 80 | /** init- initializes object |
vpcola | 0:a1734fe1ec4b | 81 | * This function must be called just after creating the object so it initializes internal data. |
vpcola | 0:a1734fe1ec4b | 82 | * @returns |
vpcola | 0:a1734fe1ec4b | 83 | * Success if the module has been properly initialized and is ready to process data. |
vpcola | 0:a1734fe1ec4b | 84 | * Failure otherwise. |
vpcola | 0:a1734fe1ec4b | 85 | */ |
vpcola | 0:a1734fe1ec4b | 86 | RadioStatus init(); |
vpcola | 0:a1734fe1ec4b | 87 | |
vpcola | 0:a1734fe1ec4b | 88 | /** set_panid - sets the 64bit extended PAN ID. |
vpcola | 0:a1734fe1ec4b | 89 | * |
vpcola | 0:a1734fe1ec4b | 90 | * @note on ZigBee devices, if set to 0, the coordinator will select a random PAN ID |
vpcola | 0:a1734fe1ec4b | 91 | * and the routers will join any extended PAN ID |
vpcola | 0:a1734fe1ec4b | 92 | * @param panid the PAN ID value that will be set on the radio |
vpcola | 0:a1734fe1ec4b | 93 | * @returns |
vpcola | 0:a1734fe1ec4b | 94 | * Success if the operation was successful, |
vpcola | 0:a1734fe1ec4b | 95 | * Failure otherwise |
vpcola | 0:a1734fe1ec4b | 96 | */ |
vpcola | 0:a1734fe1ec4b | 97 | RadioStatus set_panid(uint64_t panid); |
vpcola | 0:a1734fe1ec4b | 98 | |
vpcola | 0:a1734fe1ec4b | 99 | /** get_configured_panid - gets the configured PAN ID, as it was set by @ref set_panid(). |
vpcola | 0:a1734fe1ec4b | 100 | * |
vpcola | 0:a1734fe1ec4b | 101 | * @note on ZigBee devices, if set to 0, the coordinator will select a random PAN ID |
vpcola | 0:a1734fe1ec4b | 102 | * and the routers will join any extended PAN ID |
vpcola | 0:a1734fe1ec4b | 103 | * @param panid pointer where the configured PAN ID will be stored |
vpcola | 0:a1734fe1ec4b | 104 | * @returns |
vpcola | 0:a1734fe1ec4b | 105 | * Success if the operation was successful, |
vpcola | 0:a1734fe1ec4b | 106 | * Failure otherwise |
vpcola | 0:a1734fe1ec4b | 107 | */ |
vpcola | 0:a1734fe1ec4b | 108 | RadioStatus get_configured_panid(uint64_t * const panid); |
vpcola | 0:a1734fe1ec4b | 109 | |
vpcola | 0:a1734fe1ec4b | 110 | /** 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. |
vpcola | 0:a1734fe1ec4b | 111 | * |
vpcola | 0:a1734fe1ec4b | 112 | * @param panid pointer where the operating PAN ID will be stored |
vpcola | 0:a1734fe1ec4b | 113 | * @returns |
vpcola | 0:a1734fe1ec4b | 114 | * Success if the operation was successful, |
vpcola | 0:a1734fe1ec4b | 115 | * Failure otherwise |
vpcola | 0:a1734fe1ec4b | 116 | */ |
vpcola | 0:a1734fe1ec4b | 117 | RadioStatus get_operating_panid(uint64_t * const panid); |
vpcola | 0:a1734fe1ec4b | 118 | |
vpcola | 0:a1734fe1ec4b | 119 | /** set_panid - sets the 64bit extended PAN ID. |
vpcola | 0:a1734fe1ec4b | 120 | * |
vpcola | 0:a1734fe1ec4b | 121 | * @note on ZigBee devices, if set to 0, the coordinator will select a random PAN ID |
vpcola | 0:a1734fe1ec4b | 122 | * and the routers will join any extended PAN ID |
vpcola | 0:a1734fe1ec4b | 123 | * @param remote remote device |
vpcola | 0:a1734fe1ec4b | 124 | * @param panid the PAN ID value that will be set on the radio |
vpcola | 0:a1734fe1ec4b | 125 | * @returns |
vpcola | 0:a1734fe1ec4b | 126 | * Success if the operation was successful, |
vpcola | 0:a1734fe1ec4b | 127 | * Failure otherwise |
vpcola | 0:a1734fe1ec4b | 128 | */ |
vpcola | 0:a1734fe1ec4b | 129 | RadioStatus set_panid(const RemoteXBee& remote, uint64_t panid); |
vpcola | 0:a1734fe1ec4b | 130 | |
vpcola | 0:a1734fe1ec4b | 131 | /** get_configured_panid - gets the configured PAN ID in a remote node, as it was set by @ref set_panid() |
vpcola | 0:a1734fe1ec4b | 132 | * |
vpcola | 0:a1734fe1ec4b | 133 | * @note on ZigBee devices, if set to 0, the coordinator will select a random PAN ID |
vpcola | 0:a1734fe1ec4b | 134 | * and the routers will join any extended PAN ID |
vpcola | 0:a1734fe1ec4b | 135 | * |
vpcola | 0:a1734fe1ec4b | 136 | * @param remote remote device |
vpcola | 0:a1734fe1ec4b | 137 | * @param panid pointer where the configured PAN ID will be stored |
vpcola | 0:a1734fe1ec4b | 138 | * @returns |
vpcola | 0:a1734fe1ec4b | 139 | * Success if the operation was successful, |
vpcola | 0:a1734fe1ec4b | 140 | * Failure otherwise |
vpcola | 0:a1734fe1ec4b | 141 | */ |
vpcola | 0:a1734fe1ec4b | 142 | RadioStatus get_configured_panid(const RemoteXBee& remote, uint64_t * const panid); |
vpcola | 0:a1734fe1ec4b | 143 | |
vpcola | 0:a1734fe1ec4b | 144 | /** 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. |
vpcola | 0:a1734fe1ec4b | 145 | * |
vpcola | 0:a1734fe1ec4b | 146 | * @param remote remote device |
vpcola | 0:a1734fe1ec4b | 147 | * @param panid pointer where the operating PAN ID will be stored |
vpcola | 0:a1734fe1ec4b | 148 | * @returns |
vpcola | 0:a1734fe1ec4b | 149 | * Success if the operation was successful, |
vpcola | 0:a1734fe1ec4b | 150 | * Failure otherwise |
vpcola | 0:a1734fe1ec4b | 151 | */ |
vpcola | 0:a1734fe1ec4b | 152 | RadioStatus get_operating_panid(const RemoteXBee& remote, uint64_t * const panid); |
vpcola | 0:a1734fe1ec4b | 153 | |
vpcola | 0:a1734fe1ec4b | 154 | /** 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). |
vpcola | 0:a1734fe1ec4b | 155 | * 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. |
vpcola | 0:a1734fe1ec4b | 156 | * |
vpcola | 0:a1734fe1ec4b | 157 | * @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. |
vpcola | 0:a1734fe1ec4b | 158 | * @returns |
vpcola | 0:a1734fe1ec4b | 159 | * Success if the operation was successful, |
vpcola | 0:a1734fe1ec4b | 160 | * Failure otherwise |
vpcola | 0:a1734fe1ec4b | 161 | */ |
vpcola | 0:a1734fe1ec4b | 162 | RadioStatus set_channel_mask(uint16_t const chmask); |
vpcola | 0:a1734fe1ec4b | 163 | |
vpcola | 0:a1734fe1ec4b | 164 | /** 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). |
vpcola | 0:a1734fe1ec4b | 165 | * |
vpcola | 0:a1734fe1ec4b | 166 | * @param chmask pointer to where the configured channel mask will be stored |
vpcola | 0:a1734fe1ec4b | 167 | * @returns |
vpcola | 0:a1734fe1ec4b | 168 | * Success if the operation was successful, |
vpcola | 0:a1734fe1ec4b | 169 | * Failure otherwise |
vpcola | 0:a1734fe1ec4b | 170 | */ |
vpcola | 0:a1734fe1ec4b | 171 | RadioStatus get_channel_mask(uint16_t * const chmask); |
vpcola | 0:a1734fe1ec4b | 172 | |
vpcola | 0:a1734fe1ec4b | 173 | /** get_network_address - gets the 16bit network address of the device |
vpcola | 0:a1734fe1ec4b | 174 | * |
vpcola | 0:a1734fe1ec4b | 175 | * @param addr pointer where the device 16bit network address will be stored |
vpcola | 0:a1734fe1ec4b | 176 | * @returns |
vpcola | 0:a1734fe1ec4b | 177 | * Success if the operation was successful, |
vpcola | 0:a1734fe1ec4b | 178 | * Failure otherwise |
vpcola | 0:a1734fe1ec4b | 179 | */ |
vpcola | 0:a1734fe1ec4b | 180 | RadioStatus get_network_address(uint16_t * const addr); |
vpcola | 0:a1734fe1ec4b | 181 | |
vpcola | 0:a1734fe1ec4b | 182 | /** 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. |
vpcola | 0:a1734fe1ec4b | 183 | * 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. |
vpcola | 0:a1734fe1ec4b | 184 | * |
vpcola | 0:a1734fe1ec4b | 185 | * @param enable whether to enable this feature or not |
vpcola | 0:a1734fe1ec4b | 186 | * @returns |
vpcola | 0:a1734fe1ec4b | 187 | * Success if the operation was successful, |
vpcola | 0:a1734fe1ec4b | 188 | * Failure otherwise |
vpcola | 0:a1734fe1ec4b | 189 | */ |
vpcola | 0:a1734fe1ec4b | 190 | RadioStatus check_for_coordinator_at_start(bool enable); |
vpcola | 0:a1734fe1ec4b | 191 | |
vpcola | 0:a1734fe1ec4b | 192 | /** set_network_security_key - (Coordinator only) Set the 128-bit AES network encryption key. If set to 0 (default), the module will select a random network key. |
vpcola | 0:a1734fe1ec4b | 193 | * It is not recommended to set the key programmatically, because it could be read through the raw serial port bits. |
vpcola | 0:a1734fe1ec4b | 194 | * @param key pointer to the 128-bit AES key |
vpcola | 0:a1734fe1ec4b | 195 | * @param length size of the buffer pointed by 'key' |
vpcola | 0:a1734fe1ec4b | 196 | * @returns |
vpcola | 0:a1734fe1ec4b | 197 | * Success if the operation was successful, |
vpcola | 0:a1734fe1ec4b | 198 | * Failure otherwise |
vpcola | 0:a1734fe1ec4b | 199 | */ |
vpcola | 0:a1734fe1ec4b | 200 | RadioStatus set_network_security_key(const uint8_t * const key, const uint16_t length); |
vpcola | 0:a1734fe1ec4b | 201 | |
vpcola | 0:a1734fe1ec4b | 202 | #define XBEE_ZB_ENC_OPT_SEND_KEY_ON_JOIN 0x01 |
vpcola | 0:a1734fe1ec4b | 203 | #define XBEE_ZB_ENC_OPT_USE_TRUST_CENTER 0x02 |
vpcola | 0:a1734fe1ec4b | 204 | /** set_encryption_options - Configure options for encryption. Unused option bits should be set to 0. Options include: |
vpcola | 0:a1734fe1ec4b | 205 | * - XBEE_ZB_ENC_OPT_SEND_KEY_ON_JOIN - Send the security key unsecured over-the-air during joins |
vpcola | 0:a1734fe1ec4b | 206 | * - XBEE_ZB_ENC_OPT_USE_TRUST_CENTER - Use trust center (coordinator only) |
vpcola | 0:a1734fe1ec4b | 207 | * @param options bit mask with the encryption options |
vpcola | 0:a1734fe1ec4b | 208 | * @returns |
vpcola | 0:a1734fe1ec4b | 209 | * Success if the operation was successful, |
vpcola | 0:a1734fe1ec4b | 210 | * Failure otherwise |
vpcola | 0:a1734fe1ec4b | 211 | */ |
vpcola | 0:a1734fe1ec4b | 212 | RadioStatus set_encryption_options(const uint8_t options); |
vpcola | 0:a1734fe1ec4b | 213 | |
vpcola | 0:a1734fe1ec4b | 214 | /** register_node_discovery_cb - registers the callback function that will be called |
vpcola | 0:a1734fe1ec4b | 215 | * when the responses to the node discovery command arrive |
vpcola | 0:a1734fe1ec4b | 216 | * |
vpcola | 0:a1734fe1ec4b | 217 | * @param function function pointer with the callback function |
vpcola | 0:a1734fe1ec4b | 218 | */ |
vpcola | 0:a1734fe1ec4b | 219 | void register_node_discovery_cb(node_discovery_zb_cb_t function); |
vpcola | 0:a1734fe1ec4b | 220 | |
vpcola | 0:a1734fe1ec4b | 221 | /** unregister_node_discovery_cb - removes the node discovery callback */ |
vpcola | 0:a1734fe1ec4b | 222 | void unregister_node_discovery_cb(); |
vpcola | 0:a1734fe1ec4b | 223 | |
vpcola | 0:a1734fe1ec4b | 224 | /** register_receive_cb - registers the callback function that will be called |
vpcola | 0:a1734fe1ec4b | 225 | * when a data packet is received |
vpcola | 0:a1734fe1ec4b | 226 | * |
vpcola | 0:a1734fe1ec4b | 227 | * @param function function pointer with the callback function |
vpcola | 0:a1734fe1ec4b | 228 | */ |
vpcola | 0:a1734fe1ec4b | 229 | void register_receive_cb(receive_zb_cb_t function); |
vpcola | 0:a1734fe1ec4b | 230 | |
vpcola | 0:a1734fe1ec4b | 231 | /** unregister_receive_cb - removes the rx packet callback */ |
vpcola | 0:a1734fe1ec4b | 232 | void unregister_receive_cb(); |
vpcola | 0:a1734fe1ec4b | 233 | |
vpcola | 0:a1734fe1ec4b | 234 | /** register_io_sample_cb - registers the callback function that will be called |
vpcola | 0:a1734fe1ec4b | 235 | * when a IO Sample Data packet is received |
vpcola | 0:a1734fe1ec4b | 236 | * |
vpcola | 0:a1734fe1ec4b | 237 | * @param function function pointer with the callback function |
vpcola | 0:a1734fe1ec4b | 238 | */ |
vpcola | 0:a1734fe1ec4b | 239 | void register_io_sample_cb(io_data_cb_zb_t function); |
vpcola | 0:a1734fe1ec4b | 240 | |
vpcola | 0:a1734fe1ec4b | 241 | /** unregister_io_sample_cb - removes the IO Sample Data reception callback */ |
vpcola | 0:a1734fe1ec4b | 242 | void unregister_io_sample_cb(); |
vpcola | 0:a1734fe1ec4b | 243 | |
vpcola | 0:a1734fe1ec4b | 244 | /*********************** send_data member methods ************************/ |
vpcola | 0:a1734fe1ec4b | 245 | /** send_data - sends data to a remote device |
vpcola | 0:a1734fe1ec4b | 246 | * |
vpcola | 0:a1734fe1ec4b | 247 | * @param remote remote device |
vpcola | 0:a1734fe1ec4b | 248 | * @param data pointer to the data that will be sent |
vpcola | 0:a1734fe1ec4b | 249 | * @param len number of bytes that will be transmitted |
vpcola | 0:a1734fe1ec4b | 250 | * @param syncr if true, method waits for the packet answer with the result of the operation |
vpcola | 0:a1734fe1ec4b | 251 | * @returns the result of the data transfer |
vpcola | 0:a1734fe1ec4b | 252 | * TxStatusSuccess if the operation was successful, |
vpcola | 0:a1734fe1ec4b | 253 | * the error code otherwise |
vpcola | 0:a1734fe1ec4b | 254 | */ |
vpcola | 0:a1734fe1ec4b | 255 | virtual TxStatus send_data(const RemoteXBee& remote, const uint8_t *const data, uint16_t len, bool syncr = true); |
vpcola | 0:a1734fe1ec4b | 256 | |
vpcola | 0:a1734fe1ec4b | 257 | /** send_data - sends data to a remote device. This method uses |
vpcola | 0:a1734fe1ec4b | 258 | * the explicit addressing frame, allowing to use source and |
vpcola | 0:a1734fe1ec4b | 259 | * destination end points and cluster and profile IDs |
vpcola | 0:a1734fe1ec4b | 260 | * |
vpcola | 0:a1734fe1ec4b | 261 | * @param remote remote device |
vpcola | 0:a1734fe1ec4b | 262 | * @param source_ep source end point |
vpcola | 0:a1734fe1ec4b | 263 | * @param dest_ep destination end point |
vpcola | 0:a1734fe1ec4b | 264 | * @param cluster_id cluster ID |
vpcola | 0:a1734fe1ec4b | 265 | * @param profile_id profile ID |
vpcola | 0:a1734fe1ec4b | 266 | * @param data pointer to the data that will be sent |
vpcola | 0:a1734fe1ec4b | 267 | * @param len number of bytes that will be transmitted |
vpcola | 0:a1734fe1ec4b | 268 | * @param syncr if true, method waits for the packet answer with the result of the operation |
vpcola | 0:a1734fe1ec4b | 269 | * @returns the result of the data transfer |
vpcola | 0:a1734fe1ec4b | 270 | * TxStatusSuccess if the operation was successful, |
vpcola | 0:a1734fe1ec4b | 271 | * the error code otherwise |
vpcola | 0:a1734fe1ec4b | 272 | */ |
vpcola | 0:a1734fe1ec4b | 273 | TxStatus send_data(const RemoteXBee& remote, uint8_t source_ep, |
vpcola | 0:a1734fe1ec4b | 274 | uint8_t dest_ep, uint16_t cluster_id, uint16_t profile_id, |
vpcola | 0:a1734fe1ec4b | 275 | const uint8_t *const data, uint16_t len, bool syncr = true); |
vpcola | 0:a1734fe1ec4b | 276 | |
vpcola | 0:a1734fe1ec4b | 277 | /** send_data_to_coordinator - sends data to the ZigBee coordinator |
vpcola | 0:a1734fe1ec4b | 278 | * |
vpcola | 0:a1734fe1ec4b | 279 | * @param data pointer to the data that will be sent |
vpcola | 0:a1734fe1ec4b | 280 | * @param len number of bytes that will be transmitted |
vpcola | 0:a1734fe1ec4b | 281 | * @param syncr if true, method waits for the packet answer with the result of the operation |
vpcola | 0:a1734fe1ec4b | 282 | * @returns the result of the data transfer |
vpcola | 0:a1734fe1ec4b | 283 | * TxStatusSuccess if the operation was successful, |
vpcola | 0:a1734fe1ec4b | 284 | * the error code otherwise |
vpcola | 0:a1734fe1ec4b | 285 | */ |
vpcola | 0:a1734fe1ec4b | 286 | TxStatus send_data_to_coordinator(const uint8_t *const data, uint16_t len, bool syncr = true); |
vpcola | 0:a1734fe1ec4b | 287 | |
vpcola | 0:a1734fe1ec4b | 288 | /** get_assoc_status - returns current network association status. This wraps AI parameter, for more information refer to moudle's Reference Manual. |
vpcola | 0:a1734fe1ec4b | 289 | * |
vpcola | 0:a1734fe1ec4b | 290 | * @returns an AssocStatus with current network association status. |
vpcola | 0:a1734fe1ec4b | 291 | */ |
vpcola | 0:a1734fe1ec4b | 292 | AssocStatus get_assoc_status(void); |
vpcola | 0:a1734fe1ec4b | 293 | |
vpcola | 0:a1734fe1ec4b | 294 | /** is_joined - checks if the device is joined to ZigBee network |
vpcola | 0:a1734fe1ec4b | 295 | * @returns true if joined, false otherwise |
vpcola | 0:a1734fe1ec4b | 296 | */ |
vpcola | 0:a1734fe1ec4b | 297 | bool is_joined(); |
vpcola | 0:a1734fe1ec4b | 298 | |
vpcola | 0:a1734fe1ec4b | 299 | /** get_remote_node_by_id - searches for a device in the network with the specified Node Identifier. |
vpcola | 0:a1734fe1ec4b | 300 | * |
vpcola | 0:a1734fe1ec4b | 301 | * @param node_id node id of the device we are looking for |
vpcola | 0:a1734fe1ec4b | 302 | * @returns a RemoteXBeeZB with the 16-bit and 64-bit address of the remote device whose node id matches with the parameter. |
vpcola | 0:a1734fe1ec4b | 303 | * If node is not found, the returned object will have invalid addresses (RemoteXBeeZB::is_valid() will return false). |
vpcola | 0:a1734fe1ec4b | 304 | */ |
vpcola | 0:a1734fe1ec4b | 305 | RemoteXBeeZB get_remote_node_by_id(const char * const node_id); |
vpcola | 0:a1734fe1ec4b | 306 | |
vpcola | 0:a1734fe1ec4b | 307 | /* Allow using XBee::set_param() methods for local radio from this class */ |
vpcola | 0:a1734fe1ec4b | 308 | using XBee::set_param; |
vpcola | 0:a1734fe1ec4b | 309 | |
vpcola | 0:a1734fe1ec4b | 310 | /** set_param - sets a parameter in a remote radio by sending an AT command and waiting for the response. |
vpcola | 0:a1734fe1ec4b | 311 | * |
vpcola | 0:a1734fe1ec4b | 312 | * @param remote remote device |
vpcola | 0:a1734fe1ec4b | 313 | * @param param parameter to be set. |
vpcola | 0:a1734fe1ec4b | 314 | * @param data the parameter value (4 bytes) to be set. |
vpcola | 0:a1734fe1ec4b | 315 | * @returns the command response status. |
vpcola | 0:a1734fe1ec4b | 316 | */ |
vpcola | 0:a1734fe1ec4b | 317 | virtual AtCmdFrame::AtCmdResp set_param(const RemoteXBee& remote, const char * const param, uint32_t data); |
vpcola | 0:a1734fe1ec4b | 318 | |
vpcola | 0:a1734fe1ec4b | 319 | /** set_param - sets a parameter in a remote radio by sending an AT command and waiting for the response. |
vpcola | 0:a1734fe1ec4b | 320 | * |
vpcola | 0:a1734fe1ec4b | 321 | * @param remote remote device |
vpcola | 0:a1734fe1ec4b | 322 | * @param param parameter to be set. |
vpcola | 0:a1734fe1ec4b | 323 | * @param data the parameter value byte array (len bytes) to be set. |
vpcola | 0:a1734fe1ec4b | 324 | * @param len number of bytes of the parameter value. |
vpcola | 0:a1734fe1ec4b | 325 | * @returns the command response status. |
vpcola | 0:a1734fe1ec4b | 326 | */ |
vpcola | 0:a1734fe1ec4b | 327 | virtual AtCmdFrame::AtCmdResp set_param(const RemoteXBee& remote, const char * const param, const uint8_t * data = NULL, uint16_t len = 0); |
vpcola | 0:a1734fe1ec4b | 328 | |
vpcola | 0:a1734fe1ec4b | 329 | /* Allow using XBee::get_param() methods for local radio from this class */ |
vpcola | 0:a1734fe1ec4b | 330 | using XBee::get_param; |
vpcola | 0:a1734fe1ec4b | 331 | |
vpcola | 0:a1734fe1ec4b | 332 | /** get_param - gets a parameter from a remote radio by sending an AT command and waiting for the response. |
vpcola | 0:a1734fe1ec4b | 333 | * |
vpcola | 0:a1734fe1ec4b | 334 | * @param remote remote device |
vpcola | 0:a1734fe1ec4b | 335 | * @param param parameter to be get. |
vpcola | 0:a1734fe1ec4b | 336 | * @param data pointer where the param value (4 bytes) will be stored. |
vpcola | 0:a1734fe1ec4b | 337 | * @returns the command response status. |
vpcola | 0:a1734fe1ec4b | 338 | */ |
vpcola | 0:a1734fe1ec4b | 339 | virtual AtCmdFrame::AtCmdResp get_param(const RemoteXBee& remote, const char * const param, uint32_t * const data); |
vpcola | 0:a1734fe1ec4b | 340 | |
vpcola | 0:a1734fe1ec4b | 341 | /** get_param - gets a parameter from a remote radio by sending an AT command and waiting for the response. |
vpcola | 0:a1734fe1ec4b | 342 | * |
vpcola | 0:a1734fe1ec4b | 343 | * @param remote remote device |
vpcola | 0:a1734fe1ec4b | 344 | * @param param parameter to be get. |
vpcola | 0:a1734fe1ec4b | 345 | * @param data pointer where the param value (n bytes) will be stored. |
vpcola | 0:a1734fe1ec4b | 346 | * @param len pointer where the number of bytes of the param value will be stored. |
vpcola | 0:a1734fe1ec4b | 347 | * @returns the command response status. |
vpcola | 0:a1734fe1ec4b | 348 | */ |
vpcola | 0:a1734fe1ec4b | 349 | virtual AtCmdFrame::AtCmdResp get_param(const RemoteXBee& remote, const char * const param, uint8_t * const data, uint16_t * const len); |
vpcola | 0:a1734fe1ec4b | 350 | |
vpcola | 0:a1734fe1ec4b | 351 | /************************* IO member methods **************************/ |
vpcola | 0:a1734fe1ec4b | 352 | /** set_pin_config - configures a radio IO line |
vpcola | 0:a1734fe1ec4b | 353 | * |
vpcola | 0:a1734fe1ec4b | 354 | * @param remote remote device |
vpcola | 0:a1734fe1ec4b | 355 | * @param line IO line being configured |
vpcola | 0:a1734fe1ec4b | 356 | * @param mode configuration mode for the selected line |
vpcola | 0:a1734fe1ec4b | 357 | * @returns |
vpcola | 0:a1734fe1ec4b | 358 | * Success if the operation was successful, |
vpcola | 0:a1734fe1ec4b | 359 | * Failure otherwise |
vpcola | 0:a1734fe1ec4b | 360 | */ |
vpcola | 0:a1734fe1ec4b | 361 | RadioStatus set_pin_config(const RemoteXBee& remote, IoLine line, IoMode mode); |
vpcola | 0:a1734fe1ec4b | 362 | |
vpcola | 0:a1734fe1ec4b | 363 | /** get_pin_config - gets the configuration of a radio IO line |
vpcola | 0:a1734fe1ec4b | 364 | * |
vpcola | 0:a1734fe1ec4b | 365 | * @param remote remote device |
vpcola | 0:a1734fe1ec4b | 366 | * @param line IO line being read to get its configuration |
vpcola | 0:a1734fe1ec4b | 367 | * @param mode pointer where the configuration will be stored |
vpcola | 0:a1734fe1ec4b | 368 | * @returns |
vpcola | 0:a1734fe1ec4b | 369 | * Success if the operation was successful, |
vpcola | 0:a1734fe1ec4b | 370 | * Failure otherwise |
vpcola | 0:a1734fe1ec4b | 371 | */ |
vpcola | 0:a1734fe1ec4b | 372 | RadioStatus get_pin_config(const RemoteXBee& remote, IoLine line, IoMode * const mode); |
vpcola | 0:a1734fe1ec4b | 373 | |
vpcola | 0:a1734fe1ec4b | 374 | /** set_dio - sets to low/high a DIO line |
vpcola | 0:a1734fe1ec4b | 375 | * |
vpcola | 0:a1734fe1ec4b | 376 | * @param remote remote device |
vpcola | 0:a1734fe1ec4b | 377 | * @param line DIO line being set |
vpcola | 0:a1734fe1ec4b | 378 | * @param val value that will be set in the DIO line |
vpcola | 0:a1734fe1ec4b | 379 | * @returns |
vpcola | 0:a1734fe1ec4b | 380 | * Success if the operation was successful, |
vpcola | 0:a1734fe1ec4b | 381 | * Failure otherwise |
vpcola | 0:a1734fe1ec4b | 382 | */ |
vpcola | 0:a1734fe1ec4b | 383 | RadioStatus set_dio(const RemoteXBee& remote, IoLine line, DioVal val); |
vpcola | 0:a1734fe1ec4b | 384 | |
vpcola | 0:a1734fe1ec4b | 385 | /** get_dio - read the value of a DIO configured as digital input |
vpcola | 0:a1734fe1ec4b | 386 | * |
vpcola | 0:a1734fe1ec4b | 387 | * @param remote remote device |
vpcola | 0:a1734fe1ec4b | 388 | * @param line DIO line being read |
vpcola | 0:a1734fe1ec4b | 389 | * @param val pointer where the DIO value read will be stored |
vpcola | 0:a1734fe1ec4b | 390 | * @returns |
vpcola | 0:a1734fe1ec4b | 391 | * Success if the operation was successful, |
vpcola | 0:a1734fe1ec4b | 392 | * Failure otherwise |
vpcola | 0:a1734fe1ec4b | 393 | */ |
vpcola | 0:a1734fe1ec4b | 394 | RadioStatus get_dio(const RemoteXBee& remote, IoLine line, DioVal * const val); |
vpcola | 0:a1734fe1ec4b | 395 | |
vpcola | 0:a1734fe1ec4b | 396 | /** get_adc - read the value of the espcified ADC line |
vpcola | 0:a1734fe1ec4b | 397 | * |
vpcola | 0:a1734fe1ec4b | 398 | * @param remote remote device |
vpcola | 0:a1734fe1ec4b | 399 | * @param line ADC line being read |
vpcola | 0:a1734fe1ec4b | 400 | * @param val pointer where the value read from hte ADC will be stored |
vpcola | 0:a1734fe1ec4b | 401 | * @returns |
vpcola | 0:a1734fe1ec4b | 402 | * Success if the operation was successful, |
vpcola | 0:a1734fe1ec4b | 403 | * Failure otherwise |
vpcola | 0:a1734fe1ec4b | 404 | */ |
vpcola | 0:a1734fe1ec4b | 405 | RadioStatus get_adc(const RemoteXBee& remote, IoLine line, uint16_t * const val); |
vpcola | 0:a1734fe1ec4b | 406 | |
vpcola | 0:a1734fe1ec4b | 407 | /** get_iosample - retrieves an @ref IOSampleZB from a remote node. This object can be used to get the remote node's ADC and DIO values. |
vpcola | 0:a1734fe1ec4b | 408 | * |
vpcola | 0:a1734fe1ec4b | 409 | * @param remote remote device |
vpcola | 0:a1734fe1ec4b | 410 | * @returns IOSampleZB object with the remote node's DIO and ADC values. |
vpcola | 0:a1734fe1ec4b | 411 | */ |
vpcola | 0:a1734fe1ec4b | 412 | IOSampleZB get_iosample(const RemoteXBee& remote); |
vpcola | 0:a1734fe1ec4b | 413 | |
vpcola | 0:a1734fe1ec4b | 414 | /** set_pin_pull_up - enables or disables the internal pull-up resistor of a line |
vpcola | 0:a1734fe1ec4b | 415 | * |
vpcola | 0:a1734fe1ec4b | 416 | * @param remote remote device |
vpcola | 0:a1734fe1ec4b | 417 | * @param line line being configured for pull-up |
vpcola | 0:a1734fe1ec4b | 418 | * @param enable whether to enable the internal pull-up resistor. |
vpcola | 0:a1734fe1ec4b | 419 | * @returns |
vpcola | 0:a1734fe1ec4b | 420 | * Success if the operation was successful, |
vpcola | 0:a1734fe1ec4b | 421 | * Failure otherwise |
vpcola | 0:a1734fe1ec4b | 422 | */ |
vpcola | 0:a1734fe1ec4b | 423 | RadioStatus set_pin_pull_up(const RemoteXBee& remote, IoLine line, bool enable); |
vpcola | 0:a1734fe1ec4b | 424 | |
vpcola | 0:a1734fe1ec4b | 425 | /** enable_dio_change_detection - enables or disables the notification when a change is detected in a digital input line. |
vpcola | 0:a1734fe1ec4b | 426 | * In other words, it will force an IO Sample transmission when the DIO state changes. Only for DIO0 to DIO11. |
vpcola | 0:a1734fe1ec4b | 427 | * |
vpcola | 0:a1734fe1ec4b | 428 | * @param remote remote device |
vpcola | 0:a1734fe1ec4b | 429 | * @param line line being configured for pull-up |
vpcola | 0:a1734fe1ec4b | 430 | * @param enable whether to enable the internal pull-up resistor. |
vpcola | 0:a1734fe1ec4b | 431 | * @returns |
vpcola | 0:a1734fe1ec4b | 432 | * Success if the operation was successful, |
vpcola | 0:a1734fe1ec4b | 433 | * Failure otherwise |
vpcola | 0:a1734fe1ec4b | 434 | */ |
vpcola | 0:a1734fe1ec4b | 435 | RadioStatus enable_dio_change_detection(const RemoteXBee& remote, IoLine line, bool enable); |
vpcola | 0:a1734fe1ec4b | 436 | |
vpcola | 0:a1734fe1ec4b | 437 | protected: |
vpcola | 0:a1734fe1ec4b | 438 | |
vpcola | 0:a1734fe1ec4b | 439 | /** Frame handler used for the node discovery. Registered when a callback function |
vpcola | 0:a1734fe1ec4b | 440 | * is registered */ |
vpcola | 0:a1734fe1ec4b | 441 | FH_NodeDiscoveryZB *_nd_handler; |
vpcola | 0:a1734fe1ec4b | 442 | |
vpcola | 0:a1734fe1ec4b | 443 | /** Frame handler used for the rx packets. Automatically registered when a callback |
vpcola | 0:a1734fe1ec4b | 444 | * function is registered */ |
vpcola | 0:a1734fe1ec4b | 445 | FH_RxPacketZB *_rx_pkt_handler; |
vpcola | 0:a1734fe1ec4b | 446 | |
vpcola | 0:a1734fe1ec4b | 447 | /** Frame handler used for the IO Data Sample packets. Automatically registered when a callback |
vpcola | 0:a1734fe1ec4b | 448 | * function is registered */ |
vpcola | 0:a1734fe1ec4b | 449 | FH_IoDataSampeZB *_io_data_handler; |
vpcola | 0:a1734fe1ec4b | 450 | |
vpcola | 0:a1734fe1ec4b | 451 | /** Method called directly by the library when a modem status frame is received to |
vpcola | 0:a1734fe1ec4b | 452 | * update the internal status variables */ |
vpcola | 0:a1734fe1ec4b | 453 | virtual void radio_status_update(AtCmdFrame::ModemStatus modem_status); |
vpcola | 0:a1734fe1ec4b | 454 | |
vpcola | 0:a1734fe1ec4b | 455 | /* Allow using XBee::send_data() methods from this class */ |
vpcola | 0:a1734fe1ec4b | 456 | using XBee::send_data; |
vpcola | 0:a1734fe1ec4b | 457 | |
vpcola | 0:a1734fe1ec4b | 458 | /** get_node_discovery_timeout - gets the node discovery timeout |
vpcola | 0:a1734fe1ec4b | 459 | * |
vpcola | 0:a1734fe1ec4b | 460 | * @param timeout_ms pointer where the node discovery timeout value will be stored |
vpcola | 0:a1734fe1ec4b | 461 | * @param wait_for_complete_timeout pointer where the function will store if the operator |
vpcola | 0:a1734fe1ec4b | 462 | * has to wait for the complete nd timeout after issuing |
vpcola | 0:a1734fe1ec4b | 463 | * a directed nd request |
vpcola | 0:a1734fe1ec4b | 464 | * @returns |
vpcola | 0:a1734fe1ec4b | 465 | * Success if the operation was successful, |
vpcola | 0:a1734fe1ec4b | 466 | * Failure otherwise |
vpcola | 0:a1734fe1ec4b | 467 | */ |
vpcola | 0:a1734fe1ec4b | 468 | virtual RadioStatus get_node_discovery_timeout(uint16_t * const timeout_ms); |
vpcola | 0:a1734fe1ec4b | 469 | virtual RadioStatus get_node_discovery_timeout(uint16_t * const timeout_ms, bool * const wait_for_complete_timeout); |
vpcola | 0:a1734fe1ec4b | 470 | }; |
vpcola | 0:a1734fe1ec4b | 471 | |
vpcola | 0:a1734fe1ec4b | 472 | } /* namespace XBeeLib */ |
vpcola | 0:a1734fe1ec4b | 473 | |
vpcola | 0:a1734fe1ec4b | 474 | #endif /* __XBEE_ZB_H_ */ |