no changes
Fork of XBee by
XBee.h@0:c4ca662ef73e, 2010-11-22 (annotated)
- Committer:
- okini3939
- Date:
- Mon Nov 22 10:51:06 2010 +0000
- Revision:
- 0:c4ca662ef73e
- Child:
- 1:e3b2027e685c
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okini3939 | 0:c4ca662ef73e | 1 | /** |
okini3939 | 0:c4ca662ef73e | 2 | * XBee-mbed library |
okini3939 | 0:c4ca662ef73e | 3 | * Modified for mbed, 2010 Suga. |
okini3939 | 0:c4ca662ef73e | 4 | * |
okini3939 | 0:c4ca662ef73e | 5 | * |
okini3939 | 0:c4ca662ef73e | 6 | * Copyright (c) 2009 Andrew Rapp. All rights reserved. |
okini3939 | 0:c4ca662ef73e | 7 | * |
okini3939 | 0:c4ca662ef73e | 8 | * This file is part of XBee-Arduino. |
okini3939 | 0:c4ca662ef73e | 9 | * |
okini3939 | 0:c4ca662ef73e | 10 | * XBee-Arduino is free software: you can redistribute it and/or modify |
okini3939 | 0:c4ca662ef73e | 11 | * it under the terms of the GNU General Public License as published by |
okini3939 | 0:c4ca662ef73e | 12 | * the Free Software Foundation, either version 3 of the License, or |
okini3939 | 0:c4ca662ef73e | 13 | * (at your option) any later version. |
okini3939 | 0:c4ca662ef73e | 14 | * |
okini3939 | 0:c4ca662ef73e | 15 | * XBee-Arduino is distributed in the hope that it will be useful, |
okini3939 | 0:c4ca662ef73e | 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
okini3939 | 0:c4ca662ef73e | 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
okini3939 | 0:c4ca662ef73e | 18 | * GNU General Public License for more details. |
okini3939 | 0:c4ca662ef73e | 19 | * |
okini3939 | 0:c4ca662ef73e | 20 | * You should have received a copy of the GNU General Public License |
okini3939 | 0:c4ca662ef73e | 21 | * along with XBee-Arduino. If not, see <http://www.gnu.org/licenses/>. |
okini3939 | 0:c4ca662ef73e | 22 | */ |
okini3939 | 0:c4ca662ef73e | 23 | |
okini3939 | 0:c4ca662ef73e | 24 | #ifndef XBee_h |
okini3939 | 0:c4ca662ef73e | 25 | #define XBee_h |
okini3939 | 0:c4ca662ef73e | 26 | |
okini3939 | 0:c4ca662ef73e | 27 | #include "mbed.h" |
okini3939 | 0:c4ca662ef73e | 28 | #include <inttypes.h> |
okini3939 | 0:c4ca662ef73e | 29 | |
okini3939 | 0:c4ca662ef73e | 30 | #define SERIES_1 |
okini3939 | 0:c4ca662ef73e | 31 | #define SERIES_2 |
okini3939 | 0:c4ca662ef73e | 32 | |
okini3939 | 0:c4ca662ef73e | 33 | // set to ATAP value of XBee. AP=2 is recommended |
okini3939 | 0:c4ca662ef73e | 34 | #define ATAP 2 |
okini3939 | 0:c4ca662ef73e | 35 | |
okini3939 | 0:c4ca662ef73e | 36 | #define START_BYTE 0x7e |
okini3939 | 0:c4ca662ef73e | 37 | #define ESCAPE 0x7d |
okini3939 | 0:c4ca662ef73e | 38 | #define XON 0x11 |
okini3939 | 0:c4ca662ef73e | 39 | #define XOFF 0x13 |
okini3939 | 0:c4ca662ef73e | 40 | |
okini3939 | 0:c4ca662ef73e | 41 | // This value determines the size of the byte array for receiving RX packets |
okini3939 | 0:c4ca662ef73e | 42 | // Most users won't be dealing with packets this large so you can adjust this |
okini3939 | 0:c4ca662ef73e | 43 | // value to reduce memory consumption. But, remember that |
okini3939 | 0:c4ca662ef73e | 44 | // if a RX packet exceeds this size, it cannot be parsed! |
okini3939 | 0:c4ca662ef73e | 45 | |
okini3939 | 0:c4ca662ef73e | 46 | // This value is determined by the largest packet size (100 byte payload + 64-bit address + option byte and rssi byte) of a series 1 radio |
okini3939 | 0:c4ca662ef73e | 47 | #define MAX_FRAME_DATA_SIZE 110 |
okini3939 | 0:c4ca662ef73e | 48 | |
okini3939 | 0:c4ca662ef73e | 49 | #define BROADCAST_ADDRESS 0xffff |
okini3939 | 0:c4ca662ef73e | 50 | #define ZB_BROADCAST_ADDRESS 0xfffe |
okini3939 | 0:c4ca662ef73e | 51 | |
okini3939 | 0:c4ca662ef73e | 52 | // the non-variable length of the frame data (not including frame id or api id or variable data size (e.g. payload, at command set value) |
okini3939 | 0:c4ca662ef73e | 53 | #define ZB_TX_API_LENGTH 12 |
okini3939 | 0:c4ca662ef73e | 54 | #define TX_16_API_LENGTH 3 |
okini3939 | 0:c4ca662ef73e | 55 | #define TX_64_API_LENGTH 9 |
okini3939 | 0:c4ca662ef73e | 56 | #define AT_COMMAND_API_LENGTH 2 |
okini3939 | 0:c4ca662ef73e | 57 | #define REMOTE_AT_COMMAND_API_LENGTH 13 |
okini3939 | 0:c4ca662ef73e | 58 | // start/length(2)/api/frameid/checksum bytes |
okini3939 | 0:c4ca662ef73e | 59 | #define PACKET_OVERHEAD_LENGTH 6 |
okini3939 | 0:c4ca662ef73e | 60 | // api is always the third byte in packet |
okini3939 | 0:c4ca662ef73e | 61 | #define API_ID_INDEX 3 |
okini3939 | 0:c4ca662ef73e | 62 | |
okini3939 | 0:c4ca662ef73e | 63 | // frame position of rssi byte |
okini3939 | 0:c4ca662ef73e | 64 | #define RX_16_RSSI_OFFSET 2 |
okini3939 | 0:c4ca662ef73e | 65 | #define RX_64_RSSI_OFFSET 8 |
okini3939 | 0:c4ca662ef73e | 66 | |
okini3939 | 0:c4ca662ef73e | 67 | #define DEFAULT_FRAME_ID 1 |
okini3939 | 0:c4ca662ef73e | 68 | #define NO_RESPONSE_FRAME_ID 0 |
okini3939 | 0:c4ca662ef73e | 69 | |
okini3939 | 0:c4ca662ef73e | 70 | // TODO put in tx16 class |
okini3939 | 0:c4ca662ef73e | 71 | #define ACK_OPTION 0 |
okini3939 | 0:c4ca662ef73e | 72 | #define DISABLE_ACK_OPTION 1 |
okini3939 | 0:c4ca662ef73e | 73 | #define BROADCAST_OPTION 4 |
okini3939 | 0:c4ca662ef73e | 74 | |
okini3939 | 0:c4ca662ef73e | 75 | // RX options |
okini3939 | 0:c4ca662ef73e | 76 | #define ZB_PACKET_ACKNOWLEDGED 0x01 |
okini3939 | 0:c4ca662ef73e | 77 | #define ZB_BROADCAST_PACKET 0x02 |
okini3939 | 0:c4ca662ef73e | 78 | |
okini3939 | 0:c4ca662ef73e | 79 | // not everything is implemented! |
okini3939 | 0:c4ca662ef73e | 80 | /** |
okini3939 | 0:c4ca662ef73e | 81 | * Api Id constants |
okini3939 | 0:c4ca662ef73e | 82 | */ |
okini3939 | 0:c4ca662ef73e | 83 | #define TX_64_REQUEST 0x0 |
okini3939 | 0:c4ca662ef73e | 84 | #define TX_16_REQUEST 0x1 |
okini3939 | 0:c4ca662ef73e | 85 | #define AT_COMMAND_REQUEST 0x08 |
okini3939 | 0:c4ca662ef73e | 86 | #define AT_COMMAND_QUEUE_REQUEST 0x09 |
okini3939 | 0:c4ca662ef73e | 87 | #define REMOTE_AT_REQUEST 0x17 |
okini3939 | 0:c4ca662ef73e | 88 | #define ZB_TX_REQUEST 0x10 |
okini3939 | 0:c4ca662ef73e | 89 | #define ZB_EXPLICIT_TX_REQUEST 0x11 |
okini3939 | 0:c4ca662ef73e | 90 | #define RX_64_RESPONSE 0x80 |
okini3939 | 0:c4ca662ef73e | 91 | #define RX_16_RESPONSE 0x81 |
okini3939 | 0:c4ca662ef73e | 92 | #define RX_64_IO_RESPONSE 0x82 |
okini3939 | 0:c4ca662ef73e | 93 | #define RX_16_IO_RESPONSE 0x83 |
okini3939 | 0:c4ca662ef73e | 94 | #define AT_RESPONSE 0x88 |
okini3939 | 0:c4ca662ef73e | 95 | #define TX_STATUS_RESPONSE 0x89 |
okini3939 | 0:c4ca662ef73e | 96 | #define MODEM_STATUS_RESPONSE 0x8a |
okini3939 | 0:c4ca662ef73e | 97 | #define ZB_RX_RESPONSE 0x90 |
okini3939 | 0:c4ca662ef73e | 98 | #define ZB_EXPLICIT_RX_RESPONSE 0x91 |
okini3939 | 0:c4ca662ef73e | 99 | #define ZB_TX_STATUS_RESPONSE 0x8b |
okini3939 | 0:c4ca662ef73e | 100 | #define ZB_IO_SAMPLE_RESPONSE 0x92 |
okini3939 | 0:c4ca662ef73e | 101 | #define ZB_IO_NODE_IDENTIFIER_RESPONSE 0x95 |
okini3939 | 0:c4ca662ef73e | 102 | #define AT_COMMAND_RESPONSE 0x88 |
okini3939 | 0:c4ca662ef73e | 103 | #define REMOTE_AT_COMMAND_RESPONSE 0x97 |
okini3939 | 0:c4ca662ef73e | 104 | |
okini3939 | 0:c4ca662ef73e | 105 | |
okini3939 | 0:c4ca662ef73e | 106 | /** |
okini3939 | 0:c4ca662ef73e | 107 | * TX STATUS constants |
okini3939 | 0:c4ca662ef73e | 108 | */ |
okini3939 | 0:c4ca662ef73e | 109 | #define SUCCESS 0x0 |
okini3939 | 0:c4ca662ef73e | 110 | #define CCA_FAILURE 0x2 |
okini3939 | 0:c4ca662ef73e | 111 | #define INVALID_DESTINATION_ENDPOINT_SUCCESS 0x15 |
okini3939 | 0:c4ca662ef73e | 112 | #define NETWORK_ACK_FAILURE 0x21 |
okini3939 | 0:c4ca662ef73e | 113 | #define NOT_JOINED_TO_NETWORK 0x22 |
okini3939 | 0:c4ca662ef73e | 114 | #define SELF_ADDRESSED 0x23 |
okini3939 | 0:c4ca662ef73e | 115 | #define ADDRESS_NOT_FOUND 0x24 |
okini3939 | 0:c4ca662ef73e | 116 | #define ROUTE_NOT_FOUND 0x25 |
okini3939 | 0:c4ca662ef73e | 117 | #define PAYLOAD_TOO_LARGE 0x74 |
okini3939 | 0:c4ca662ef73e | 118 | |
okini3939 | 0:c4ca662ef73e | 119 | // modem status |
okini3939 | 0:c4ca662ef73e | 120 | #define HARDWARE_RESET 0 |
okini3939 | 0:c4ca662ef73e | 121 | #define WATCHDOG_TIMER_RESET 1 |
okini3939 | 0:c4ca662ef73e | 122 | #define ASSOCIATED 2 |
okini3939 | 0:c4ca662ef73e | 123 | #define DISASSOCIATED 3 |
okini3939 | 0:c4ca662ef73e | 124 | #define SYNCHRONIZATION_LOST 4 |
okini3939 | 0:c4ca662ef73e | 125 | #define COORDINATOR_REALIGNMENT 5 |
okini3939 | 0:c4ca662ef73e | 126 | #define COORDINATOR_STARTED 6 |
okini3939 | 0:c4ca662ef73e | 127 | |
okini3939 | 0:c4ca662ef73e | 128 | #define ZB_BROADCAST_RADIUS_MAX_HOPS 0 |
okini3939 | 0:c4ca662ef73e | 129 | |
okini3939 | 0:c4ca662ef73e | 130 | #define ZB_TX_UNICAST 0 |
okini3939 | 0:c4ca662ef73e | 131 | #define ZB_TX_BROADCAST 8 |
okini3939 | 0:c4ca662ef73e | 132 | |
okini3939 | 0:c4ca662ef73e | 133 | #define AT_OK 0 |
okini3939 | 0:c4ca662ef73e | 134 | #define AT_ERROR 1 |
okini3939 | 0:c4ca662ef73e | 135 | #define AT_INVALID_COMMAND 2 |
okini3939 | 0:c4ca662ef73e | 136 | #define AT_INVALID_PARAMETER 3 |
okini3939 | 0:c4ca662ef73e | 137 | #define AT_NO_RESPONSE 4 |
okini3939 | 0:c4ca662ef73e | 138 | |
okini3939 | 0:c4ca662ef73e | 139 | #define NO_ERROR 0 |
okini3939 | 0:c4ca662ef73e | 140 | #define CHECKSUM_FAILURE 1 |
okini3939 | 0:c4ca662ef73e | 141 | #define PACKET_EXCEEDS_BYTE_ARRAY_LENGTH 2 |
okini3939 | 0:c4ca662ef73e | 142 | #define UNEXPECTED_START_BYTE 3 |
okini3939 | 0:c4ca662ef73e | 143 | |
okini3939 | 0:c4ca662ef73e | 144 | /** |
okini3939 | 0:c4ca662ef73e | 145 | * The super class of all XBee responses (RX packets) |
okini3939 | 0:c4ca662ef73e | 146 | * Users should never attempt to create an instance of this class; instead |
okini3939 | 0:c4ca662ef73e | 147 | * create an instance of a subclass |
okini3939 | 0:c4ca662ef73e | 148 | * It is recommend to reuse subclasses to conserve memory |
okini3939 | 0:c4ca662ef73e | 149 | */ |
okini3939 | 0:c4ca662ef73e | 150 | class XBeeResponse { |
okini3939 | 0:c4ca662ef73e | 151 | public: |
okini3939 | 0:c4ca662ef73e | 152 | //static const int MODEM_STATUS = 0x8a; |
okini3939 | 0:c4ca662ef73e | 153 | /** |
okini3939 | 0:c4ca662ef73e | 154 | * Default constructor |
okini3939 | 0:c4ca662ef73e | 155 | */ |
okini3939 | 0:c4ca662ef73e | 156 | XBeeResponse(); |
okini3939 | 0:c4ca662ef73e | 157 | /** |
okini3939 | 0:c4ca662ef73e | 158 | * Returns Api Id of the response |
okini3939 | 0:c4ca662ef73e | 159 | */ |
okini3939 | 0:c4ca662ef73e | 160 | uint8_t getApiId(); |
okini3939 | 0:c4ca662ef73e | 161 | void setApiId(uint8_t apiId); |
okini3939 | 0:c4ca662ef73e | 162 | /** |
okini3939 | 0:c4ca662ef73e | 163 | * Returns the MSB length of the packet |
okini3939 | 0:c4ca662ef73e | 164 | */ |
okini3939 | 0:c4ca662ef73e | 165 | uint8_t getMsbLength(); |
okini3939 | 0:c4ca662ef73e | 166 | void setMsbLength(uint8_t msbLength); |
okini3939 | 0:c4ca662ef73e | 167 | /** |
okini3939 | 0:c4ca662ef73e | 168 | * Returns the LSB length of the packet |
okini3939 | 0:c4ca662ef73e | 169 | */ |
okini3939 | 0:c4ca662ef73e | 170 | uint8_t getLsbLength(); |
okini3939 | 0:c4ca662ef73e | 171 | void setLsbLength(uint8_t lsbLength); |
okini3939 | 0:c4ca662ef73e | 172 | /** |
okini3939 | 0:c4ca662ef73e | 173 | * Returns the packet checksum |
okini3939 | 0:c4ca662ef73e | 174 | */ |
okini3939 | 0:c4ca662ef73e | 175 | uint8_t getChecksum(); |
okini3939 | 0:c4ca662ef73e | 176 | void setChecksum(uint8_t checksum); |
okini3939 | 0:c4ca662ef73e | 177 | /** |
okini3939 | 0:c4ca662ef73e | 178 | * Returns the length of the frame data: all bytes after the api id, and prior to the checksum |
okini3939 | 0:c4ca662ef73e | 179 | * Note up to release 0.1.2, this was incorrectly including the checksum in the length. |
okini3939 | 0:c4ca662ef73e | 180 | */ |
okini3939 | 0:c4ca662ef73e | 181 | uint8_t getFrameDataLength(); |
okini3939 | 0:c4ca662ef73e | 182 | void setFrameData(uint8_t* frameDataPtr); |
okini3939 | 0:c4ca662ef73e | 183 | /** |
okini3939 | 0:c4ca662ef73e | 184 | * Returns the buffer that contains the response. |
okini3939 | 0:c4ca662ef73e | 185 | * Starts with byte that follows API ID and includes all bytes prior to the checksum |
okini3939 | 0:c4ca662ef73e | 186 | * Length is specified by getFrameDataLength() |
okini3939 | 0:c4ca662ef73e | 187 | * Note: Unlike Digi's definition of the frame data, this does not start with the API ID.. |
okini3939 | 0:c4ca662ef73e | 188 | * The reason for this is all responses include an API ID, whereas my frame data |
okini3939 | 0:c4ca662ef73e | 189 | * includes only the API specific data. |
okini3939 | 0:c4ca662ef73e | 190 | */ |
okini3939 | 0:c4ca662ef73e | 191 | uint8_t* getFrameData(); |
okini3939 | 0:c4ca662ef73e | 192 | |
okini3939 | 0:c4ca662ef73e | 193 | void setFrameLength(uint8_t frameLength); |
okini3939 | 0:c4ca662ef73e | 194 | // to support future 65535 byte packets I guess |
okini3939 | 0:c4ca662ef73e | 195 | /** |
okini3939 | 0:c4ca662ef73e | 196 | * Returns the length of the packet |
okini3939 | 0:c4ca662ef73e | 197 | */ |
okini3939 | 0:c4ca662ef73e | 198 | uint16_t getPacketLength(); |
okini3939 | 0:c4ca662ef73e | 199 | /** |
okini3939 | 0:c4ca662ef73e | 200 | * Resets the response to default values |
okini3939 | 0:c4ca662ef73e | 201 | */ |
okini3939 | 0:c4ca662ef73e | 202 | void reset(); |
okini3939 | 0:c4ca662ef73e | 203 | /** |
okini3939 | 0:c4ca662ef73e | 204 | * Initializes the response |
okini3939 | 0:c4ca662ef73e | 205 | */ |
okini3939 | 0:c4ca662ef73e | 206 | void init(); |
okini3939 | 0:c4ca662ef73e | 207 | #ifdef SERIES_2 |
okini3939 | 0:c4ca662ef73e | 208 | /** |
okini3939 | 0:c4ca662ef73e | 209 | * Call with instance of ZBTxStatusResponse class only if getApiId() == ZB_TX_STATUS_RESPONSE |
okini3939 | 0:c4ca662ef73e | 210 | * to populate response |
okini3939 | 0:c4ca662ef73e | 211 | */ |
okini3939 | 0:c4ca662ef73e | 212 | void getZBTxStatusResponse(XBeeResponse &response); |
okini3939 | 0:c4ca662ef73e | 213 | /** |
okini3939 | 0:c4ca662ef73e | 214 | * Call with instance of ZBRxResponse class only if getApiId() == ZB_RX_RESPONSE |
okini3939 | 0:c4ca662ef73e | 215 | * to populate response |
okini3939 | 0:c4ca662ef73e | 216 | */ |
okini3939 | 0:c4ca662ef73e | 217 | void getZBRxResponse(XBeeResponse &response); |
okini3939 | 0:c4ca662ef73e | 218 | /** |
okini3939 | 0:c4ca662ef73e | 219 | * Call with instance of ZBRxIoSampleResponse class only if getApiId() == ZB_IO_SAMPLE_RESPONSE |
okini3939 | 0:c4ca662ef73e | 220 | * to populate response |
okini3939 | 0:c4ca662ef73e | 221 | */ |
okini3939 | 0:c4ca662ef73e | 222 | void getZBRxIoSampleResponse(XBeeResponse &response); |
okini3939 | 0:c4ca662ef73e | 223 | #endif |
okini3939 | 0:c4ca662ef73e | 224 | #ifdef SERIES_1 |
okini3939 | 0:c4ca662ef73e | 225 | /** |
okini3939 | 0:c4ca662ef73e | 226 | * Call with instance of TxStatusResponse only if getApiId() == TX_STATUS_RESPONSE |
okini3939 | 0:c4ca662ef73e | 227 | */ |
okini3939 | 0:c4ca662ef73e | 228 | void getTxStatusResponse(XBeeResponse &response); |
okini3939 | 0:c4ca662ef73e | 229 | /** |
okini3939 | 0:c4ca662ef73e | 230 | * Call with instance of Rx16Response only if getApiId() == RX_16_RESPONSE |
okini3939 | 0:c4ca662ef73e | 231 | */ |
okini3939 | 0:c4ca662ef73e | 232 | void getRx16Response(XBeeResponse &response); |
okini3939 | 0:c4ca662ef73e | 233 | /** |
okini3939 | 0:c4ca662ef73e | 234 | * Call with instance of Rx64Response only if getApiId() == RX_64_RESPONSE |
okini3939 | 0:c4ca662ef73e | 235 | */ |
okini3939 | 0:c4ca662ef73e | 236 | void getRx64Response(XBeeResponse &response); |
okini3939 | 0:c4ca662ef73e | 237 | /** |
okini3939 | 0:c4ca662ef73e | 238 | * Call with instance of Rx16IoSampleResponse only if getApiId() == RX_16_IO_RESPONSE |
okini3939 | 0:c4ca662ef73e | 239 | */ |
okini3939 | 0:c4ca662ef73e | 240 | void getRx16IoSampleResponse(XBeeResponse &response); |
okini3939 | 0:c4ca662ef73e | 241 | /** |
okini3939 | 0:c4ca662ef73e | 242 | * Call with instance of Rx64IoSampleResponse only if getApiId() == RX_64_IO_RESPONSE |
okini3939 | 0:c4ca662ef73e | 243 | */ |
okini3939 | 0:c4ca662ef73e | 244 | void getRx64IoSampleResponse(XBeeResponse &response); |
okini3939 | 0:c4ca662ef73e | 245 | #endif |
okini3939 | 0:c4ca662ef73e | 246 | /** |
okini3939 | 0:c4ca662ef73e | 247 | * Call with instance of AtCommandResponse only if getApiId() == AT_COMMAND_RESPONSE |
okini3939 | 0:c4ca662ef73e | 248 | */ |
okini3939 | 0:c4ca662ef73e | 249 | void getAtCommandResponse(XBeeResponse &responses); |
okini3939 | 0:c4ca662ef73e | 250 | /** |
okini3939 | 0:c4ca662ef73e | 251 | * Call with instance of RemoteAtCommandResponse only if getApiId() == REMOTE_AT_COMMAND_RESPONSE |
okini3939 | 0:c4ca662ef73e | 252 | */ |
okini3939 | 0:c4ca662ef73e | 253 | void getRemoteAtCommandResponse(XBeeResponse &response); |
okini3939 | 0:c4ca662ef73e | 254 | /** |
okini3939 | 0:c4ca662ef73e | 255 | * Call with instance of ModemStatusResponse only if getApiId() == MODEM_STATUS_RESPONSE |
okini3939 | 0:c4ca662ef73e | 256 | */ |
okini3939 | 0:c4ca662ef73e | 257 | void getModemStatusResponse(XBeeResponse &response); |
okini3939 | 0:c4ca662ef73e | 258 | /** |
okini3939 | 0:c4ca662ef73e | 259 | * Returns true if the response has been successfully parsed and is complete and ready for use |
okini3939 | 0:c4ca662ef73e | 260 | */ |
okini3939 | 0:c4ca662ef73e | 261 | bool isAvailable(); |
okini3939 | 0:c4ca662ef73e | 262 | void setAvailable(bool complete); |
okini3939 | 0:c4ca662ef73e | 263 | /** |
okini3939 | 0:c4ca662ef73e | 264 | * Returns true if the response contains errors |
okini3939 | 0:c4ca662ef73e | 265 | */ |
okini3939 | 0:c4ca662ef73e | 266 | bool isError(); |
okini3939 | 0:c4ca662ef73e | 267 | /** |
okini3939 | 0:c4ca662ef73e | 268 | * Returns an error code, or zero, if successful. |
okini3939 | 0:c4ca662ef73e | 269 | * Error codes include: CHECKSUM_FAILURE, PACKET_EXCEEDS_BYTE_ARRAY_LENGTH, UNEXPECTED_START_BYTE |
okini3939 | 0:c4ca662ef73e | 270 | */ |
okini3939 | 0:c4ca662ef73e | 271 | uint8_t getErrorCode(); |
okini3939 | 0:c4ca662ef73e | 272 | void setErrorCode(uint8_t errorCode); |
okini3939 | 0:c4ca662ef73e | 273 | protected: |
okini3939 | 0:c4ca662ef73e | 274 | // pointer to frameData |
okini3939 | 0:c4ca662ef73e | 275 | uint8_t* _frameDataPtr; |
okini3939 | 0:c4ca662ef73e | 276 | private: |
okini3939 | 0:c4ca662ef73e | 277 | void setCommon(XBeeResponse &target); |
okini3939 | 0:c4ca662ef73e | 278 | uint8_t _apiId; |
okini3939 | 0:c4ca662ef73e | 279 | uint8_t _msbLength; |
okini3939 | 0:c4ca662ef73e | 280 | uint8_t _lsbLength; |
okini3939 | 0:c4ca662ef73e | 281 | uint8_t _checksum; |
okini3939 | 0:c4ca662ef73e | 282 | uint8_t _frameLength; |
okini3939 | 0:c4ca662ef73e | 283 | bool _complete; |
okini3939 | 0:c4ca662ef73e | 284 | uint8_t _errorCode; |
okini3939 | 0:c4ca662ef73e | 285 | }; |
okini3939 | 0:c4ca662ef73e | 286 | |
okini3939 | 0:c4ca662ef73e | 287 | class XBeeAddress { |
okini3939 | 0:c4ca662ef73e | 288 | public: |
okini3939 | 0:c4ca662ef73e | 289 | XBeeAddress(); |
okini3939 | 0:c4ca662ef73e | 290 | }; |
okini3939 | 0:c4ca662ef73e | 291 | |
okini3939 | 0:c4ca662ef73e | 292 | /** |
okini3939 | 0:c4ca662ef73e | 293 | * Represents a 64-bit XBee Address |
okini3939 | 0:c4ca662ef73e | 294 | */ |
okini3939 | 0:c4ca662ef73e | 295 | class XBeeAddress64 : public XBeeAddress { |
okini3939 | 0:c4ca662ef73e | 296 | public: |
okini3939 | 0:c4ca662ef73e | 297 | XBeeAddress64(uint32_t msb, uint32_t lsb); |
okini3939 | 0:c4ca662ef73e | 298 | XBeeAddress64(); |
okini3939 | 0:c4ca662ef73e | 299 | uint32_t getMsb(); |
okini3939 | 0:c4ca662ef73e | 300 | uint32_t getLsb(); |
okini3939 | 0:c4ca662ef73e | 301 | void setMsb(uint32_t msb); |
okini3939 | 0:c4ca662ef73e | 302 | void setLsb(uint32_t lsb); |
okini3939 | 0:c4ca662ef73e | 303 | private: |
okini3939 | 0:c4ca662ef73e | 304 | uint32_t _msb; |
okini3939 | 0:c4ca662ef73e | 305 | uint32_t _lsb; |
okini3939 | 0:c4ca662ef73e | 306 | }; |
okini3939 | 0:c4ca662ef73e | 307 | |
okini3939 | 0:c4ca662ef73e | 308 | //class XBeeAddress16 : public XBeeAddress { |
okini3939 | 0:c4ca662ef73e | 309 | //public: |
okini3939 | 0:c4ca662ef73e | 310 | // XBeeAddress16(uint16_t addr); |
okini3939 | 0:c4ca662ef73e | 311 | // XBeeAddress16(); |
okini3939 | 0:c4ca662ef73e | 312 | // uint16_t getAddress(); |
okini3939 | 0:c4ca662ef73e | 313 | // void setAddress(uint16_t addr); |
okini3939 | 0:c4ca662ef73e | 314 | //private: |
okini3939 | 0:c4ca662ef73e | 315 | // uint16_t _addr; |
okini3939 | 0:c4ca662ef73e | 316 | //}; |
okini3939 | 0:c4ca662ef73e | 317 | |
okini3939 | 0:c4ca662ef73e | 318 | /** |
okini3939 | 0:c4ca662ef73e | 319 | * This class is extended by all Responses that include a frame id |
okini3939 | 0:c4ca662ef73e | 320 | */ |
okini3939 | 0:c4ca662ef73e | 321 | class FrameIdResponse : public XBeeResponse { |
okini3939 | 0:c4ca662ef73e | 322 | public: |
okini3939 | 0:c4ca662ef73e | 323 | FrameIdResponse(); |
okini3939 | 0:c4ca662ef73e | 324 | uint8_t getFrameId(); |
okini3939 | 0:c4ca662ef73e | 325 | private: |
okini3939 | 0:c4ca662ef73e | 326 | uint8_t _frameId; |
okini3939 | 0:c4ca662ef73e | 327 | }; |
okini3939 | 0:c4ca662ef73e | 328 | |
okini3939 | 0:c4ca662ef73e | 329 | /** |
okini3939 | 0:c4ca662ef73e | 330 | * Common functionality for both Series 1 and 2 data RX data packets |
okini3939 | 0:c4ca662ef73e | 331 | */ |
okini3939 | 0:c4ca662ef73e | 332 | class RxDataResponse : public XBeeResponse { |
okini3939 | 0:c4ca662ef73e | 333 | public: |
okini3939 | 0:c4ca662ef73e | 334 | RxDataResponse(); |
okini3939 | 0:c4ca662ef73e | 335 | /** |
okini3939 | 0:c4ca662ef73e | 336 | * Returns the specified index of the payload. The index may be 0 to getDataLength() - 1 |
okini3939 | 0:c4ca662ef73e | 337 | * This method is deprecated; use uint8_t* getData() |
okini3939 | 0:c4ca662ef73e | 338 | */ |
okini3939 | 0:c4ca662ef73e | 339 | uint8_t getData(int index); |
okini3939 | 0:c4ca662ef73e | 340 | /** |
okini3939 | 0:c4ca662ef73e | 341 | * Returns the payload array. This may be accessed from index 0 to getDataLength() - 1 |
okini3939 | 0:c4ca662ef73e | 342 | */ |
okini3939 | 0:c4ca662ef73e | 343 | uint8_t* getData(); |
okini3939 | 0:c4ca662ef73e | 344 | /** |
okini3939 | 0:c4ca662ef73e | 345 | * Returns the length of the payload |
okini3939 | 0:c4ca662ef73e | 346 | */ |
okini3939 | 0:c4ca662ef73e | 347 | virtual uint8_t getDataLength() = 0; |
okini3939 | 0:c4ca662ef73e | 348 | /** |
okini3939 | 0:c4ca662ef73e | 349 | * Returns the position in the frame data where the data begins |
okini3939 | 0:c4ca662ef73e | 350 | */ |
okini3939 | 0:c4ca662ef73e | 351 | virtual uint8_t getDataOffset() = 0; |
okini3939 | 0:c4ca662ef73e | 352 | }; |
okini3939 | 0:c4ca662ef73e | 353 | |
okini3939 | 0:c4ca662ef73e | 354 | // getResponse to return the proper subclass: |
okini3939 | 0:c4ca662ef73e | 355 | // we maintain a pointer to each type of response, when a response is parsed, it is allocated only if NULL |
okini3939 | 0:c4ca662ef73e | 356 | // can we allocate an object in a function? |
okini3939 | 0:c4ca662ef73e | 357 | |
okini3939 | 0:c4ca662ef73e | 358 | #ifdef SERIES_2 |
okini3939 | 0:c4ca662ef73e | 359 | /** |
okini3939 | 0:c4ca662ef73e | 360 | * Represents a Series 2 TX status packet |
okini3939 | 0:c4ca662ef73e | 361 | */ |
okini3939 | 0:c4ca662ef73e | 362 | class ZBTxStatusResponse : public FrameIdResponse { |
okini3939 | 0:c4ca662ef73e | 363 | public: |
okini3939 | 0:c4ca662ef73e | 364 | ZBTxStatusResponse(); |
okini3939 | 0:c4ca662ef73e | 365 | uint16_t getRemoteAddress(); |
okini3939 | 0:c4ca662ef73e | 366 | uint8_t getTxRetryCount(); |
okini3939 | 0:c4ca662ef73e | 367 | uint8_t getDeliveryStatus(); |
okini3939 | 0:c4ca662ef73e | 368 | uint8_t getDiscoveryStatus(); |
okini3939 | 0:c4ca662ef73e | 369 | bool isSuccess(); |
okini3939 | 0:c4ca662ef73e | 370 | }; |
okini3939 | 0:c4ca662ef73e | 371 | |
okini3939 | 0:c4ca662ef73e | 372 | /** |
okini3939 | 0:c4ca662ef73e | 373 | * Represents a Series 2 RX packet |
okini3939 | 0:c4ca662ef73e | 374 | */ |
okini3939 | 0:c4ca662ef73e | 375 | class ZBRxResponse : public RxDataResponse { |
okini3939 | 0:c4ca662ef73e | 376 | public: |
okini3939 | 0:c4ca662ef73e | 377 | ZBRxResponse(); |
okini3939 | 0:c4ca662ef73e | 378 | XBeeAddress64& getRemoteAddress64(); |
okini3939 | 0:c4ca662ef73e | 379 | uint16_t getRemoteAddress16(); |
okini3939 | 0:c4ca662ef73e | 380 | uint8_t getOption(); |
okini3939 | 0:c4ca662ef73e | 381 | virtual uint8_t getDataLength(); |
okini3939 | 0:c4ca662ef73e | 382 | // frame position where data starts |
okini3939 | 0:c4ca662ef73e | 383 | virtual uint8_t getDataOffset(); |
okini3939 | 0:c4ca662ef73e | 384 | private: |
okini3939 | 0:c4ca662ef73e | 385 | XBeeAddress64 _remoteAddress64; |
okini3939 | 0:c4ca662ef73e | 386 | }; |
okini3939 | 0:c4ca662ef73e | 387 | |
okini3939 | 0:c4ca662ef73e | 388 | /** |
okini3939 | 0:c4ca662ef73e | 389 | * Represents a Series 2 RX I/O Sample packet |
okini3939 | 0:c4ca662ef73e | 390 | */ |
okini3939 | 0:c4ca662ef73e | 391 | class ZBRxIoSampleResponse : public ZBRxResponse { |
okini3939 | 0:c4ca662ef73e | 392 | public: |
okini3939 | 0:c4ca662ef73e | 393 | ZBRxIoSampleResponse(); |
okini3939 | 0:c4ca662ef73e | 394 | bool containsAnalog(); |
okini3939 | 0:c4ca662ef73e | 395 | bool containsDigital(); |
okini3939 | 0:c4ca662ef73e | 396 | /** |
okini3939 | 0:c4ca662ef73e | 397 | * Returns true if the pin is enabled |
okini3939 | 0:c4ca662ef73e | 398 | */ |
okini3939 | 0:c4ca662ef73e | 399 | bool isAnalogEnabled(uint8_t pin); |
okini3939 | 0:c4ca662ef73e | 400 | /** |
okini3939 | 0:c4ca662ef73e | 401 | * Returns true if the pin is enabled |
okini3939 | 0:c4ca662ef73e | 402 | */ |
okini3939 | 0:c4ca662ef73e | 403 | bool isDigitalEnabled(uint8_t pin); |
okini3939 | 0:c4ca662ef73e | 404 | /** |
okini3939 | 0:c4ca662ef73e | 405 | * Returns the 10-bit analog reading of the specified pin. |
okini3939 | 0:c4ca662ef73e | 406 | * Valid pins include ADC:xxx. |
okini3939 | 0:c4ca662ef73e | 407 | */ |
okini3939 | 0:c4ca662ef73e | 408 | uint16_t getAnalog(uint8_t pin); |
okini3939 | 0:c4ca662ef73e | 409 | /** |
okini3939 | 0:c4ca662ef73e | 410 | * Returns true if the specified pin is high/on. |
okini3939 | 0:c4ca662ef73e | 411 | * Valid pins include DIO:xxx. |
okini3939 | 0:c4ca662ef73e | 412 | */ |
okini3939 | 0:c4ca662ef73e | 413 | bool isDigitalOn(uint8_t pin); |
okini3939 | 0:c4ca662ef73e | 414 | uint8_t getDigitalMaskMsb(); |
okini3939 | 0:c4ca662ef73e | 415 | uint8_t getDigitalMaskLsb(); |
okini3939 | 0:c4ca662ef73e | 416 | uint8_t getAnalogMask(); |
okini3939 | 0:c4ca662ef73e | 417 | }; |
okini3939 | 0:c4ca662ef73e | 418 | |
okini3939 | 0:c4ca662ef73e | 419 | #endif |
okini3939 | 0:c4ca662ef73e | 420 | |
okini3939 | 0:c4ca662ef73e | 421 | #ifdef SERIES_1 |
okini3939 | 0:c4ca662ef73e | 422 | /** |
okini3939 | 0:c4ca662ef73e | 423 | * Represents a Series 1 TX Status packet |
okini3939 | 0:c4ca662ef73e | 424 | */ |
okini3939 | 0:c4ca662ef73e | 425 | class TxStatusResponse : public FrameIdResponse { |
okini3939 | 0:c4ca662ef73e | 426 | public: |
okini3939 | 0:c4ca662ef73e | 427 | TxStatusResponse(); |
okini3939 | 0:c4ca662ef73e | 428 | uint8_t getStatus(); |
okini3939 | 0:c4ca662ef73e | 429 | bool isSuccess(); |
okini3939 | 0:c4ca662ef73e | 430 | }; |
okini3939 | 0:c4ca662ef73e | 431 | |
okini3939 | 0:c4ca662ef73e | 432 | /** |
okini3939 | 0:c4ca662ef73e | 433 | * Represents a Series 1 RX packet |
okini3939 | 0:c4ca662ef73e | 434 | */ |
okini3939 | 0:c4ca662ef73e | 435 | class RxResponse : public RxDataResponse { |
okini3939 | 0:c4ca662ef73e | 436 | public: |
okini3939 | 0:c4ca662ef73e | 437 | RxResponse(); |
okini3939 | 0:c4ca662ef73e | 438 | // remember rssi is negative but this is unsigned byte so it's up to you to convert |
okini3939 | 0:c4ca662ef73e | 439 | uint8_t getRssi(); |
okini3939 | 0:c4ca662ef73e | 440 | uint8_t getOption(); |
okini3939 | 0:c4ca662ef73e | 441 | bool isAddressBroadcast(); |
okini3939 | 0:c4ca662ef73e | 442 | bool isPanBroadcast(); |
okini3939 | 0:c4ca662ef73e | 443 | virtual uint8_t getDataLength(); |
okini3939 | 0:c4ca662ef73e | 444 | virtual uint8_t getDataOffset(); |
okini3939 | 0:c4ca662ef73e | 445 | virtual uint8_t getRssiOffset() = 0; |
okini3939 | 0:c4ca662ef73e | 446 | }; |
okini3939 | 0:c4ca662ef73e | 447 | |
okini3939 | 0:c4ca662ef73e | 448 | /** |
okini3939 | 0:c4ca662ef73e | 449 | * Represents a Series 1 16-bit address RX packet |
okini3939 | 0:c4ca662ef73e | 450 | */ |
okini3939 | 0:c4ca662ef73e | 451 | class Rx16Response : public RxResponse { |
okini3939 | 0:c4ca662ef73e | 452 | public: |
okini3939 | 0:c4ca662ef73e | 453 | Rx16Response(); |
okini3939 | 0:c4ca662ef73e | 454 | virtual uint8_t getRssiOffset(); |
okini3939 | 0:c4ca662ef73e | 455 | uint16_t getRemoteAddress16(); |
okini3939 | 0:c4ca662ef73e | 456 | protected: |
okini3939 | 0:c4ca662ef73e | 457 | uint16_t _remoteAddress; |
okini3939 | 0:c4ca662ef73e | 458 | }; |
okini3939 | 0:c4ca662ef73e | 459 | |
okini3939 | 0:c4ca662ef73e | 460 | /** |
okini3939 | 0:c4ca662ef73e | 461 | * Represents a Series 1 64-bit address RX packet |
okini3939 | 0:c4ca662ef73e | 462 | */ |
okini3939 | 0:c4ca662ef73e | 463 | class Rx64Response : public RxResponse { |
okini3939 | 0:c4ca662ef73e | 464 | public: |
okini3939 | 0:c4ca662ef73e | 465 | Rx64Response(); |
okini3939 | 0:c4ca662ef73e | 466 | virtual uint8_t getRssiOffset(); |
okini3939 | 0:c4ca662ef73e | 467 | XBeeAddress64& getRemoteAddress64(); |
okini3939 | 0:c4ca662ef73e | 468 | private: |
okini3939 | 0:c4ca662ef73e | 469 | XBeeAddress64 _remoteAddress; |
okini3939 | 0:c4ca662ef73e | 470 | }; |
okini3939 | 0:c4ca662ef73e | 471 | |
okini3939 | 0:c4ca662ef73e | 472 | /** |
okini3939 | 0:c4ca662ef73e | 473 | * Represents a Series 1 RX I/O Sample packet |
okini3939 | 0:c4ca662ef73e | 474 | */ |
okini3939 | 0:c4ca662ef73e | 475 | class RxIoSampleBaseResponse : public RxResponse { |
okini3939 | 0:c4ca662ef73e | 476 | public: |
okini3939 | 0:c4ca662ef73e | 477 | RxIoSampleBaseResponse(); |
okini3939 | 0:c4ca662ef73e | 478 | /** |
okini3939 | 0:c4ca662ef73e | 479 | * Returns the number of samples in this packet |
okini3939 | 0:c4ca662ef73e | 480 | */ |
okini3939 | 0:c4ca662ef73e | 481 | uint8_t getSampleSize(); |
okini3939 | 0:c4ca662ef73e | 482 | bool containsAnalog(); |
okini3939 | 0:c4ca662ef73e | 483 | bool containsDigital(); |
okini3939 | 0:c4ca662ef73e | 484 | /** |
okini3939 | 0:c4ca662ef73e | 485 | * Returns true if the specified analog pin is enabled |
okini3939 | 0:c4ca662ef73e | 486 | */ |
okini3939 | 0:c4ca662ef73e | 487 | bool isAnalogEnabled(uint8_t pin); |
okini3939 | 0:c4ca662ef73e | 488 | /** |
okini3939 | 0:c4ca662ef73e | 489 | * Returns true if the specified digital pin is enabled |
okini3939 | 0:c4ca662ef73e | 490 | */ |
okini3939 | 0:c4ca662ef73e | 491 | bool isDigitalEnabled(uint8_t pin); |
okini3939 | 0:c4ca662ef73e | 492 | /** |
okini3939 | 0:c4ca662ef73e | 493 | * Returns the 10-bit analog reading of the specified pin. |
okini3939 | 0:c4ca662ef73e | 494 | * Valid pins include ADC:0-5. Sample index starts at 0 |
okini3939 | 0:c4ca662ef73e | 495 | */ |
okini3939 | 0:c4ca662ef73e | 496 | uint16_t getAnalog(uint8_t pin, uint8_t sample); |
okini3939 | 0:c4ca662ef73e | 497 | /** |
okini3939 | 0:c4ca662ef73e | 498 | * Returns true if the specified pin is high/on. |
okini3939 | 0:c4ca662ef73e | 499 | * Valid pins include DIO:0-8. Sample index starts at 0 |
okini3939 | 0:c4ca662ef73e | 500 | */ |
okini3939 | 0:c4ca662ef73e | 501 | bool isDigitalOn(uint8_t pin, uint8_t sample); |
okini3939 | 0:c4ca662ef73e | 502 | uint8_t getSampleOffset(); |
okini3939 | 0:c4ca662ef73e | 503 | private: |
okini3939 | 0:c4ca662ef73e | 504 | }; |
okini3939 | 0:c4ca662ef73e | 505 | |
okini3939 | 0:c4ca662ef73e | 506 | class Rx16IoSampleResponse : public RxIoSampleBaseResponse { |
okini3939 | 0:c4ca662ef73e | 507 | public: |
okini3939 | 0:c4ca662ef73e | 508 | Rx16IoSampleResponse(); |
okini3939 | 0:c4ca662ef73e | 509 | uint16_t getRemoteAddress16(); |
okini3939 | 0:c4ca662ef73e | 510 | virtual uint8_t getRssiOffset(); |
okini3939 | 0:c4ca662ef73e | 511 | |
okini3939 | 0:c4ca662ef73e | 512 | }; |
okini3939 | 0:c4ca662ef73e | 513 | |
okini3939 | 0:c4ca662ef73e | 514 | class Rx64IoSampleResponse : public RxIoSampleBaseResponse { |
okini3939 | 0:c4ca662ef73e | 515 | public: |
okini3939 | 0:c4ca662ef73e | 516 | Rx64IoSampleResponse(); |
okini3939 | 0:c4ca662ef73e | 517 | XBeeAddress64& getRemoteAddress64(); |
okini3939 | 0:c4ca662ef73e | 518 | virtual uint8_t getRssiOffset(); |
okini3939 | 0:c4ca662ef73e | 519 | private: |
okini3939 | 0:c4ca662ef73e | 520 | XBeeAddress64 _remoteAddress; |
okini3939 | 0:c4ca662ef73e | 521 | }; |
okini3939 | 0:c4ca662ef73e | 522 | |
okini3939 | 0:c4ca662ef73e | 523 | #endif |
okini3939 | 0:c4ca662ef73e | 524 | |
okini3939 | 0:c4ca662ef73e | 525 | /** |
okini3939 | 0:c4ca662ef73e | 526 | * Represents a Modem Status RX packet |
okini3939 | 0:c4ca662ef73e | 527 | */ |
okini3939 | 0:c4ca662ef73e | 528 | class ModemStatusResponse : public XBeeResponse { |
okini3939 | 0:c4ca662ef73e | 529 | public: |
okini3939 | 0:c4ca662ef73e | 530 | ModemStatusResponse(); |
okini3939 | 0:c4ca662ef73e | 531 | uint8_t getStatus(); |
okini3939 | 0:c4ca662ef73e | 532 | }; |
okini3939 | 0:c4ca662ef73e | 533 | |
okini3939 | 0:c4ca662ef73e | 534 | /** |
okini3939 | 0:c4ca662ef73e | 535 | * Represents an AT Command RX packet |
okini3939 | 0:c4ca662ef73e | 536 | */ |
okini3939 | 0:c4ca662ef73e | 537 | class AtCommandResponse : public FrameIdResponse { |
okini3939 | 0:c4ca662ef73e | 538 | public: |
okini3939 | 0:c4ca662ef73e | 539 | AtCommandResponse(); |
okini3939 | 0:c4ca662ef73e | 540 | /** |
okini3939 | 0:c4ca662ef73e | 541 | * Returns an array containing the two character command |
okini3939 | 0:c4ca662ef73e | 542 | */ |
okini3939 | 0:c4ca662ef73e | 543 | uint8_t* getCommand(); |
okini3939 | 0:c4ca662ef73e | 544 | /** |
okini3939 | 0:c4ca662ef73e | 545 | * Returns the command status code. |
okini3939 | 0:c4ca662ef73e | 546 | * Zero represents a successful command |
okini3939 | 0:c4ca662ef73e | 547 | */ |
okini3939 | 0:c4ca662ef73e | 548 | uint8_t getStatus(); |
okini3939 | 0:c4ca662ef73e | 549 | /** |
okini3939 | 0:c4ca662ef73e | 550 | * Returns an array containing the command value. |
okini3939 | 0:c4ca662ef73e | 551 | * This is only applicable to query commands. |
okini3939 | 0:c4ca662ef73e | 552 | */ |
okini3939 | 0:c4ca662ef73e | 553 | uint8_t* getValue(); |
okini3939 | 0:c4ca662ef73e | 554 | /** |
okini3939 | 0:c4ca662ef73e | 555 | * Returns the length of the command value array. |
okini3939 | 0:c4ca662ef73e | 556 | */ |
okini3939 | 0:c4ca662ef73e | 557 | uint8_t getValueLength(); |
okini3939 | 0:c4ca662ef73e | 558 | /** |
okini3939 | 0:c4ca662ef73e | 559 | * Returns true if status equals AT_OK |
okini3939 | 0:c4ca662ef73e | 560 | */ |
okini3939 | 0:c4ca662ef73e | 561 | bool isOk(); |
okini3939 | 0:c4ca662ef73e | 562 | }; |
okini3939 | 0:c4ca662ef73e | 563 | |
okini3939 | 0:c4ca662ef73e | 564 | /** |
okini3939 | 0:c4ca662ef73e | 565 | * Represents a Remote AT Command RX packet |
okini3939 | 0:c4ca662ef73e | 566 | */ |
okini3939 | 0:c4ca662ef73e | 567 | class RemoteAtCommandResponse : public AtCommandResponse { |
okini3939 | 0:c4ca662ef73e | 568 | public: |
okini3939 | 0:c4ca662ef73e | 569 | RemoteAtCommandResponse(); |
okini3939 | 0:c4ca662ef73e | 570 | /** |
okini3939 | 0:c4ca662ef73e | 571 | * Returns an array containing the two character command |
okini3939 | 0:c4ca662ef73e | 572 | */ |
okini3939 | 0:c4ca662ef73e | 573 | uint8_t* getCommand(); |
okini3939 | 0:c4ca662ef73e | 574 | /** |
okini3939 | 0:c4ca662ef73e | 575 | * Returns the command status code. |
okini3939 | 0:c4ca662ef73e | 576 | * Zero represents a successful command |
okini3939 | 0:c4ca662ef73e | 577 | */ |
okini3939 | 0:c4ca662ef73e | 578 | uint8_t getStatus(); |
okini3939 | 0:c4ca662ef73e | 579 | /** |
okini3939 | 0:c4ca662ef73e | 580 | * Returns an array containing the command value. |
okini3939 | 0:c4ca662ef73e | 581 | * This is only applicable to query commands. |
okini3939 | 0:c4ca662ef73e | 582 | */ |
okini3939 | 0:c4ca662ef73e | 583 | uint8_t* getValue(); |
okini3939 | 0:c4ca662ef73e | 584 | /** |
okini3939 | 0:c4ca662ef73e | 585 | * Returns the length of the command value array. |
okini3939 | 0:c4ca662ef73e | 586 | */ |
okini3939 | 0:c4ca662ef73e | 587 | uint8_t getValueLength(); |
okini3939 | 0:c4ca662ef73e | 588 | /** |
okini3939 | 0:c4ca662ef73e | 589 | * Returns the 16-bit address of the remote radio |
okini3939 | 0:c4ca662ef73e | 590 | */ |
okini3939 | 0:c4ca662ef73e | 591 | uint16_t getRemoteAddress16(); |
okini3939 | 0:c4ca662ef73e | 592 | /** |
okini3939 | 0:c4ca662ef73e | 593 | * Returns the 64-bit address of the remote radio |
okini3939 | 0:c4ca662ef73e | 594 | */ |
okini3939 | 0:c4ca662ef73e | 595 | XBeeAddress64& getRemoteAddress64(); |
okini3939 | 0:c4ca662ef73e | 596 | /** |
okini3939 | 0:c4ca662ef73e | 597 | * Returns true if command was successful |
okini3939 | 0:c4ca662ef73e | 598 | */ |
okini3939 | 0:c4ca662ef73e | 599 | bool isOk(); |
okini3939 | 0:c4ca662ef73e | 600 | private: |
okini3939 | 0:c4ca662ef73e | 601 | XBeeAddress64 _remoteAddress64; |
okini3939 | 0:c4ca662ef73e | 602 | }; |
okini3939 | 0:c4ca662ef73e | 603 | |
okini3939 | 0:c4ca662ef73e | 604 | |
okini3939 | 0:c4ca662ef73e | 605 | /** |
okini3939 | 0:c4ca662ef73e | 606 | * Super class of all XBee requests (TX packets) |
okini3939 | 0:c4ca662ef73e | 607 | * Users should never create an instance of this class; instead use an subclass of this class |
okini3939 | 0:c4ca662ef73e | 608 | * It is recommended to reuse Subclasses of the class to conserve memory |
okini3939 | 0:c4ca662ef73e | 609 | * <p/> |
okini3939 | 0:c4ca662ef73e | 610 | * This class allocates a buffer to |
okini3939 | 0:c4ca662ef73e | 611 | */ |
okini3939 | 0:c4ca662ef73e | 612 | class XBeeRequest { |
okini3939 | 0:c4ca662ef73e | 613 | public: |
okini3939 | 0:c4ca662ef73e | 614 | /** |
okini3939 | 0:c4ca662ef73e | 615 | * Constructor |
okini3939 | 0:c4ca662ef73e | 616 | * TODO make protected |
okini3939 | 0:c4ca662ef73e | 617 | */ |
okini3939 | 0:c4ca662ef73e | 618 | XBeeRequest(uint8_t apiId, uint8_t frameId); |
okini3939 | 0:c4ca662ef73e | 619 | /** |
okini3939 | 0:c4ca662ef73e | 620 | * Sets the frame id. Must be between 1 and 255 inclusive to get a TX status response. |
okini3939 | 0:c4ca662ef73e | 621 | */ |
okini3939 | 0:c4ca662ef73e | 622 | void setFrameId(uint8_t frameId); |
okini3939 | 0:c4ca662ef73e | 623 | /** |
okini3939 | 0:c4ca662ef73e | 624 | * Returns the frame id |
okini3939 | 0:c4ca662ef73e | 625 | */ |
okini3939 | 0:c4ca662ef73e | 626 | uint8_t getFrameId(); |
okini3939 | 0:c4ca662ef73e | 627 | /** |
okini3939 | 0:c4ca662ef73e | 628 | * Returns the API id |
okini3939 | 0:c4ca662ef73e | 629 | */ |
okini3939 | 0:c4ca662ef73e | 630 | uint8_t getApiId(); |
okini3939 | 0:c4ca662ef73e | 631 | // setting = 0 makes this a pure virtual function, meaning the subclass must implement, like abstract in java |
okini3939 | 0:c4ca662ef73e | 632 | /** |
okini3939 | 0:c4ca662ef73e | 633 | * Starting after the frame id (pos = 0) and up to but not including the checksum |
okini3939 | 0:c4ca662ef73e | 634 | * Note: Unlike Digi's definition of the frame data, this does not start with the API ID. |
okini3939 | 0:c4ca662ef73e | 635 | * The reason for this is the API ID and Frame ID are common to all requests, whereas my definition of |
okini3939 | 0:c4ca662ef73e | 636 | * frame data is only the API specific data. |
okini3939 | 0:c4ca662ef73e | 637 | */ |
okini3939 | 0:c4ca662ef73e | 638 | virtual uint8_t getFrameData(uint8_t pos) = 0; |
okini3939 | 0:c4ca662ef73e | 639 | /** |
okini3939 | 0:c4ca662ef73e | 640 | * Returns the size of the api frame (not including frame id or api id or checksum). |
okini3939 | 0:c4ca662ef73e | 641 | */ |
okini3939 | 0:c4ca662ef73e | 642 | virtual uint8_t getFrameDataLength() = 0; |
okini3939 | 0:c4ca662ef73e | 643 | //void reset(); |
okini3939 | 0:c4ca662ef73e | 644 | protected: |
okini3939 | 0:c4ca662ef73e | 645 | void setApiId(uint8_t apiId); |
okini3939 | 0:c4ca662ef73e | 646 | private: |
okini3939 | 0:c4ca662ef73e | 647 | uint8_t _apiId; |
okini3939 | 0:c4ca662ef73e | 648 | uint8_t _frameId; |
okini3939 | 0:c4ca662ef73e | 649 | }; |
okini3939 | 0:c4ca662ef73e | 650 | |
okini3939 | 0:c4ca662ef73e | 651 | // TODO add reset/clear method since responses are often reused |
okini3939 | 0:c4ca662ef73e | 652 | /** |
okini3939 | 0:c4ca662ef73e | 653 | * Primary interface for communicating with an XBee Radio. |
okini3939 | 0:c4ca662ef73e | 654 | * This class provides methods for sending and receiving packets with an XBee radio via the serial port. |
okini3939 | 0:c4ca662ef73e | 655 | * The XBee radio must be configured in API (packet) mode (AP=2) |
okini3939 | 0:c4ca662ef73e | 656 | * in order to use this software. |
okini3939 | 0:c4ca662ef73e | 657 | * <p/> |
okini3939 | 0:c4ca662ef73e | 658 | * Since this code is designed to run on a microcontroller, with only one thread, you are responsible for reading the |
okini3939 | 0:c4ca662ef73e | 659 | * data off the serial buffer in a timely manner. This involves a call to a variant of readPacket(...). |
okini3939 | 0:c4ca662ef73e | 660 | * If your serial port is receiving data faster than you are reading, you can expect to lose packets. |
okini3939 | 0:c4ca662ef73e | 661 | * Arduino only has a 128 byte serial buffer so it can easily overflow if two or more packets arrive |
okini3939 | 0:c4ca662ef73e | 662 | * without a call to readPacket(...) |
okini3939 | 0:c4ca662ef73e | 663 | * <p/> |
okini3939 | 0:c4ca662ef73e | 664 | * In order to conserve resources, this class only supports storing one response packet in memory at a time. |
okini3939 | 0:c4ca662ef73e | 665 | * This means that you must fully consume the packet prior to calling readPacket(...), because calling |
okini3939 | 0:c4ca662ef73e | 666 | * readPacket(...) overwrites the previous response. |
okini3939 | 0:c4ca662ef73e | 667 | * <p/> |
okini3939 | 0:c4ca662ef73e | 668 | * This class creates an array of size MAX_FRAME_DATA_SIZE for storing the response packet. You may want |
okini3939 | 0:c4ca662ef73e | 669 | * to adjust this value to conserve memory. |
okini3939 | 0:c4ca662ef73e | 670 | * |
okini3939 | 0:c4ca662ef73e | 671 | * \author Andrew Rapp |
okini3939 | 0:c4ca662ef73e | 672 | */ |
okini3939 | 0:c4ca662ef73e | 673 | class XBee : public Base { |
okini3939 | 0:c4ca662ef73e | 674 | public: |
okini3939 | 0:c4ca662ef73e | 675 | XBee(PinName p_tx, PinName p_rx); |
okini3939 | 0:c4ca662ef73e | 676 | // for eclipse dev only |
okini3939 | 0:c4ca662ef73e | 677 | // void setSerial(HardwareSerial serial); |
okini3939 | 0:c4ca662ef73e | 678 | /** |
okini3939 | 0:c4ca662ef73e | 679 | * Reads all available serial bytes until a packet is parsed, an error occurs, or the buffer is empty. |
okini3939 | 0:c4ca662ef73e | 680 | * You may call <i>xbee</i>.getResponse().isAvailable() after calling this method to determine if |
okini3939 | 0:c4ca662ef73e | 681 | * a packet is ready, or <i>xbee</i>.getResponse().isError() to determine if |
okini3939 | 0:c4ca662ef73e | 682 | * a error occurred. |
okini3939 | 0:c4ca662ef73e | 683 | * <p/> |
okini3939 | 0:c4ca662ef73e | 684 | * This method should always return quickly since it does not wait for serial data to arrive. |
okini3939 | 0:c4ca662ef73e | 685 | * You will want to use this method if you are doing other timely stuff in your loop, where |
okini3939 | 0:c4ca662ef73e | 686 | * a delay would cause problems. |
okini3939 | 0:c4ca662ef73e | 687 | * NOTE: calling this method resets the current response, so make sure you first consume the |
okini3939 | 0:c4ca662ef73e | 688 | * current response |
okini3939 | 0:c4ca662ef73e | 689 | */ |
okini3939 | 0:c4ca662ef73e | 690 | void readPacket(); |
okini3939 | 0:c4ca662ef73e | 691 | /** |
okini3939 | 0:c4ca662ef73e | 692 | * Waits a maximum of <i>timeout</i> milliseconds for a response packet before timing out; returns true if packet is read. |
okini3939 | 0:c4ca662ef73e | 693 | * Returns false if timeout or error occurs. |
okini3939 | 0:c4ca662ef73e | 694 | */ |
okini3939 | 0:c4ca662ef73e | 695 | bool readPacket(int timeout); |
okini3939 | 0:c4ca662ef73e | 696 | /** |
okini3939 | 0:c4ca662ef73e | 697 | * Reads until a packet is received or an error occurs. |
okini3939 | 0:c4ca662ef73e | 698 | * Caution: use this carefully since if you don't get a response, your Arduino code will hang on this |
okini3939 | 0:c4ca662ef73e | 699 | * call forever!! often it's better to use a timeout: readPacket(int) |
okini3939 | 0:c4ca662ef73e | 700 | */ |
okini3939 | 0:c4ca662ef73e | 701 | void readPacketUntilAvailable(); |
okini3939 | 0:c4ca662ef73e | 702 | /** |
okini3939 | 0:c4ca662ef73e | 703 | * Starts the serial connection at the supplied baud rate |
okini3939 | 0:c4ca662ef73e | 704 | */ |
okini3939 | 0:c4ca662ef73e | 705 | void begin(long baud); |
okini3939 | 0:c4ca662ef73e | 706 | void getResponse(XBeeResponse &response); |
okini3939 | 0:c4ca662ef73e | 707 | /** |
okini3939 | 0:c4ca662ef73e | 708 | * Returns a reference to the current response |
okini3939 | 0:c4ca662ef73e | 709 | * Note: once readPacket is called again this response will be overwritten! |
okini3939 | 0:c4ca662ef73e | 710 | */ |
okini3939 | 0:c4ca662ef73e | 711 | XBeeResponse& getResponse(); |
okini3939 | 0:c4ca662ef73e | 712 | /** |
okini3939 | 0:c4ca662ef73e | 713 | * Sends a XBeeRequest (TX packet) out the serial port |
okini3939 | 0:c4ca662ef73e | 714 | */ |
okini3939 | 0:c4ca662ef73e | 715 | void send(XBeeRequest &request); |
okini3939 | 0:c4ca662ef73e | 716 | //uint8_t sendAndWaitForResponse(XBeeRequest &request, int timeout); |
okini3939 | 0:c4ca662ef73e | 717 | /** |
okini3939 | 0:c4ca662ef73e | 718 | * Returns a sequential frame id between 1 and 255 |
okini3939 | 0:c4ca662ef73e | 719 | */ |
okini3939 | 0:c4ca662ef73e | 720 | uint8_t getNextFrameId(); |
okini3939 | 0:c4ca662ef73e | 721 | private: |
okini3939 | 0:c4ca662ef73e | 722 | Serial _xbee; |
okini3939 | 0:c4ca662ef73e | 723 | void sendByte(uint8_t b, bool escape); |
okini3939 | 0:c4ca662ef73e | 724 | void resetResponse(); |
okini3939 | 0:c4ca662ef73e | 725 | XBeeResponse _response; |
okini3939 | 0:c4ca662ef73e | 726 | bool _escape; |
okini3939 | 0:c4ca662ef73e | 727 | // current packet position for response. just a state variable for packet parsing and has no relevance for the response otherwise |
okini3939 | 0:c4ca662ef73e | 728 | uint8_t _pos; |
okini3939 | 0:c4ca662ef73e | 729 | // last byte read |
okini3939 | 0:c4ca662ef73e | 730 | uint8_t b; |
okini3939 | 0:c4ca662ef73e | 731 | uint8_t _checksumTotal; |
okini3939 | 0:c4ca662ef73e | 732 | uint8_t _nextFrameId; |
okini3939 | 0:c4ca662ef73e | 733 | // buffer for incoming RX packets. holds only the api specific frame data, starting after the api id byte and prior to checksum |
okini3939 | 0:c4ca662ef73e | 734 | uint8_t _responseFrameData[MAX_FRAME_DATA_SIZE]; |
okini3939 | 0:c4ca662ef73e | 735 | }; |
okini3939 | 0:c4ca662ef73e | 736 | |
okini3939 | 0:c4ca662ef73e | 737 | /** |
okini3939 | 0:c4ca662ef73e | 738 | * All TX packets that support payloads extend this class |
okini3939 | 0:c4ca662ef73e | 739 | */ |
okini3939 | 0:c4ca662ef73e | 740 | class PayloadRequest : public XBeeRequest { |
okini3939 | 0:c4ca662ef73e | 741 | public: |
okini3939 | 0:c4ca662ef73e | 742 | PayloadRequest(uint8_t apiId, uint8_t frameId, uint8_t *payload, uint8_t payloadLength); |
okini3939 | 0:c4ca662ef73e | 743 | /** |
okini3939 | 0:c4ca662ef73e | 744 | * Returns the payload of the packet, if not null |
okini3939 | 0:c4ca662ef73e | 745 | */ |
okini3939 | 0:c4ca662ef73e | 746 | uint8_t* getPayload(); |
okini3939 | 0:c4ca662ef73e | 747 | /** |
okini3939 | 0:c4ca662ef73e | 748 | * Sets the payload array |
okini3939 | 0:c4ca662ef73e | 749 | */ |
okini3939 | 0:c4ca662ef73e | 750 | void setPayload(uint8_t* payloadPtr); |
okini3939 | 0:c4ca662ef73e | 751 | /** |
okini3939 | 0:c4ca662ef73e | 752 | * Returns the length of the payload array, as specified by the user. |
okini3939 | 0:c4ca662ef73e | 753 | */ |
okini3939 | 0:c4ca662ef73e | 754 | uint8_t getPayloadLength(); |
okini3939 | 0:c4ca662ef73e | 755 | /** |
okini3939 | 0:c4ca662ef73e | 756 | * Sets the length of the payload to include in the request. For example if the payload array |
okini3939 | 0:c4ca662ef73e | 757 | * is 50 bytes and you only want the first 10 to be included in the packet, set the length to 10. |
okini3939 | 0:c4ca662ef73e | 758 | * Length must be <= to the array length. |
okini3939 | 0:c4ca662ef73e | 759 | */ |
okini3939 | 0:c4ca662ef73e | 760 | void setPayloadLength(uint8_t payloadLength); |
okini3939 | 0:c4ca662ef73e | 761 | private: |
okini3939 | 0:c4ca662ef73e | 762 | uint8_t* _payloadPtr; |
okini3939 | 0:c4ca662ef73e | 763 | uint8_t _payloadLength; |
okini3939 | 0:c4ca662ef73e | 764 | }; |
okini3939 | 0:c4ca662ef73e | 765 | |
okini3939 | 0:c4ca662ef73e | 766 | #ifdef SERIES_1 |
okini3939 | 0:c4ca662ef73e | 767 | |
okini3939 | 0:c4ca662ef73e | 768 | /** |
okini3939 | 0:c4ca662ef73e | 769 | * Represents a Series 1 TX packet that corresponds to Api Id: TX_16_REQUEST |
okini3939 | 0:c4ca662ef73e | 770 | * <p/> |
okini3939 | 0:c4ca662ef73e | 771 | * Be careful not to send a data array larger than the max packet size of your radio. |
okini3939 | 0:c4ca662ef73e | 772 | * This class does not perform any validation of packet size and there will be no indication |
okini3939 | 0:c4ca662ef73e | 773 | * if the packet is too large, other than you will not get a TX Status response. |
okini3939 | 0:c4ca662ef73e | 774 | * The datasheet says 100 bytes is the maximum, although that could change in future firmware. |
okini3939 | 0:c4ca662ef73e | 775 | */ |
okini3939 | 0:c4ca662ef73e | 776 | class Tx16Request : public PayloadRequest { |
okini3939 | 0:c4ca662ef73e | 777 | public: |
okini3939 | 0:c4ca662ef73e | 778 | Tx16Request(uint16_t addr16, uint8_t option, uint8_t *payload, uint8_t payloadLength, uint8_t frameId); |
okini3939 | 0:c4ca662ef73e | 779 | /** |
okini3939 | 0:c4ca662ef73e | 780 | * Creates a Unicast Tx16Request with the ACK option and DEFAULT_FRAME_ID |
okini3939 | 0:c4ca662ef73e | 781 | */ |
okini3939 | 0:c4ca662ef73e | 782 | Tx16Request(uint16_t addr16, uint8_t *payload, uint8_t payloadLength); |
okini3939 | 0:c4ca662ef73e | 783 | /** |
okini3939 | 0:c4ca662ef73e | 784 | * Creates a default instance of this class. At a minimum you must specify |
okini3939 | 0:c4ca662ef73e | 785 | * a payload, payload length and a destination address before sending this request. |
okini3939 | 0:c4ca662ef73e | 786 | */ |
okini3939 | 0:c4ca662ef73e | 787 | Tx16Request(); |
okini3939 | 0:c4ca662ef73e | 788 | uint16_t getAddress16(); |
okini3939 | 0:c4ca662ef73e | 789 | void setAddress16(uint16_t addr16); |
okini3939 | 0:c4ca662ef73e | 790 | uint8_t getOption(); |
okini3939 | 0:c4ca662ef73e | 791 | void setOption(uint8_t option); |
okini3939 | 0:c4ca662ef73e | 792 | virtual uint8_t getFrameData(uint8_t pos); |
okini3939 | 0:c4ca662ef73e | 793 | virtual uint8_t getFrameDataLength(); |
okini3939 | 0:c4ca662ef73e | 794 | protected: |
okini3939 | 0:c4ca662ef73e | 795 | private: |
okini3939 | 0:c4ca662ef73e | 796 | uint16_t _addr16; |
okini3939 | 0:c4ca662ef73e | 797 | uint8_t _option; |
okini3939 | 0:c4ca662ef73e | 798 | }; |
okini3939 | 0:c4ca662ef73e | 799 | |
okini3939 | 0:c4ca662ef73e | 800 | /** |
okini3939 | 0:c4ca662ef73e | 801 | * Represents a Series 1 TX packet that corresponds to Api Id: TX_64_REQUEST |
okini3939 | 0:c4ca662ef73e | 802 | * |
okini3939 | 0:c4ca662ef73e | 803 | * Be careful not to send a data array larger than the max packet size of your radio. |
okini3939 | 0:c4ca662ef73e | 804 | * This class does not perform any validation of packet size and there will be no indication |
okini3939 | 0:c4ca662ef73e | 805 | * if the packet is too large, other than you will not get a TX Status response. |
okini3939 | 0:c4ca662ef73e | 806 | * The datasheet says 100 bytes is the maximum, although that could change in future firmware. |
okini3939 | 0:c4ca662ef73e | 807 | */ |
okini3939 | 0:c4ca662ef73e | 808 | class Tx64Request : public PayloadRequest { |
okini3939 | 0:c4ca662ef73e | 809 | public: |
okini3939 | 0:c4ca662ef73e | 810 | Tx64Request(XBeeAddress64 &addr64, uint8_t option, uint8_t *payload, uint8_t payloadLength, uint8_t frameId); |
okini3939 | 0:c4ca662ef73e | 811 | /** |
okini3939 | 0:c4ca662ef73e | 812 | * Creates a unicast Tx64Request with the ACK option and DEFAULT_FRAME_ID |
okini3939 | 0:c4ca662ef73e | 813 | */ |
okini3939 | 0:c4ca662ef73e | 814 | Tx64Request(XBeeAddress64 &addr64, uint8_t *payload, uint8_t payloadLength); |
okini3939 | 0:c4ca662ef73e | 815 | /** |
okini3939 | 0:c4ca662ef73e | 816 | * Creates a default instance of this class. At a minimum you must specify |
okini3939 | 0:c4ca662ef73e | 817 | * a payload, payload length and a destination address before sending this request. |
okini3939 | 0:c4ca662ef73e | 818 | */ |
okini3939 | 0:c4ca662ef73e | 819 | Tx64Request(); |
okini3939 | 0:c4ca662ef73e | 820 | XBeeAddress64& getAddress64(); |
okini3939 | 0:c4ca662ef73e | 821 | void setAddress64(XBeeAddress64& addr64); |
okini3939 | 0:c4ca662ef73e | 822 | // TODO move option to superclass |
okini3939 | 0:c4ca662ef73e | 823 | uint8_t getOption(); |
okini3939 | 0:c4ca662ef73e | 824 | void setOption(uint8_t option); |
okini3939 | 0:c4ca662ef73e | 825 | virtual uint8_t getFrameData(uint8_t pos); |
okini3939 | 0:c4ca662ef73e | 826 | virtual uint8_t getFrameDataLength(); |
okini3939 | 0:c4ca662ef73e | 827 | private: |
okini3939 | 0:c4ca662ef73e | 828 | XBeeAddress64 _addr64; |
okini3939 | 0:c4ca662ef73e | 829 | uint8_t _option; |
okini3939 | 0:c4ca662ef73e | 830 | }; |
okini3939 | 0:c4ca662ef73e | 831 | |
okini3939 | 0:c4ca662ef73e | 832 | #endif |
okini3939 | 0:c4ca662ef73e | 833 | |
okini3939 | 0:c4ca662ef73e | 834 | |
okini3939 | 0:c4ca662ef73e | 835 | #ifdef SERIES_2 |
okini3939 | 0:c4ca662ef73e | 836 | |
okini3939 | 0:c4ca662ef73e | 837 | /** |
okini3939 | 0:c4ca662ef73e | 838 | * Represents a Series 2 TX packet that corresponds to Api Id: ZB_TX_REQUEST |
okini3939 | 0:c4ca662ef73e | 839 | * |
okini3939 | 0:c4ca662ef73e | 840 | * Be careful not to send a data array larger than the max packet size of your radio. |
okini3939 | 0:c4ca662ef73e | 841 | * This class does not perform any validation of packet size and there will be no indication |
okini3939 | 0:c4ca662ef73e | 842 | * if the packet is too large, other than you will not get a TX Status response. |
okini3939 | 0:c4ca662ef73e | 843 | * The datasheet says 72 bytes is the maximum for ZNet firmware and ZB Pro firmware provides |
okini3939 | 0:c4ca662ef73e | 844 | * the ATNP command to get the max supported payload size. This command is useful since the |
okini3939 | 0:c4ca662ef73e | 845 | * maximum payload size varies according to certain settings, such as encryption. |
okini3939 | 0:c4ca662ef73e | 846 | * ZB Pro firmware provides a PAYLOAD_TOO_LARGE that is returned if payload size |
okini3939 | 0:c4ca662ef73e | 847 | * exceeds the maximum. |
okini3939 | 0:c4ca662ef73e | 848 | */ |
okini3939 | 0:c4ca662ef73e | 849 | class ZBTxRequest : public PayloadRequest { |
okini3939 | 0:c4ca662ef73e | 850 | public: |
okini3939 | 0:c4ca662ef73e | 851 | /** |
okini3939 | 0:c4ca662ef73e | 852 | * Creates a unicast ZBTxRequest with the ACK option and DEFAULT_FRAME_ID |
okini3939 | 0:c4ca662ef73e | 853 | */ |
okini3939 | 0:c4ca662ef73e | 854 | ZBTxRequest(XBeeAddress64 &addr64, uint8_t *payload, uint8_t payloadLength); |
okini3939 | 0:c4ca662ef73e | 855 | ZBTxRequest(XBeeAddress64 &addr64, uint16_t addr16, uint8_t broadcastRadius, uint8_t option, uint8_t *payload, uint8_t payloadLength, uint8_t frameId); |
okini3939 | 0:c4ca662ef73e | 856 | /** |
okini3939 | 0:c4ca662ef73e | 857 | * Creates a default instance of this class. At a minimum you must specify |
okini3939 | 0:c4ca662ef73e | 858 | * a payload, payload length and a destination address before sending this request. |
okini3939 | 0:c4ca662ef73e | 859 | */ |
okini3939 | 0:c4ca662ef73e | 860 | ZBTxRequest(); |
okini3939 | 0:c4ca662ef73e | 861 | XBeeAddress64& getAddress64(); |
okini3939 | 0:c4ca662ef73e | 862 | uint16_t getAddress16(); |
okini3939 | 0:c4ca662ef73e | 863 | uint8_t getBroadcastRadius(); |
okini3939 | 0:c4ca662ef73e | 864 | uint8_t getOption(); |
okini3939 | 0:c4ca662ef73e | 865 | void setAddress64(XBeeAddress64& addr64); |
okini3939 | 0:c4ca662ef73e | 866 | void setAddress16(uint16_t addr16); |
okini3939 | 0:c4ca662ef73e | 867 | void setBroadcastRadius(uint8_t broadcastRadius); |
okini3939 | 0:c4ca662ef73e | 868 | void setOption(uint8_t option); |
okini3939 | 0:c4ca662ef73e | 869 | protected: |
okini3939 | 0:c4ca662ef73e | 870 | // declare virtual functions |
okini3939 | 0:c4ca662ef73e | 871 | virtual uint8_t getFrameData(uint8_t pos); |
okini3939 | 0:c4ca662ef73e | 872 | virtual uint8_t getFrameDataLength(); |
okini3939 | 0:c4ca662ef73e | 873 | private: |
okini3939 | 0:c4ca662ef73e | 874 | XBeeAddress64 _addr64; |
okini3939 | 0:c4ca662ef73e | 875 | uint16_t _addr16; |
okini3939 | 0:c4ca662ef73e | 876 | uint8_t _broadcastRadius; |
okini3939 | 0:c4ca662ef73e | 877 | uint8_t _option; |
okini3939 | 0:c4ca662ef73e | 878 | }; |
okini3939 | 0:c4ca662ef73e | 879 | |
okini3939 | 0:c4ca662ef73e | 880 | #endif |
okini3939 | 0:c4ca662ef73e | 881 | |
okini3939 | 0:c4ca662ef73e | 882 | /** |
okini3939 | 0:c4ca662ef73e | 883 | * Represents an AT Command TX packet |
okini3939 | 0:c4ca662ef73e | 884 | * The command is used to configure the serially connected XBee radio |
okini3939 | 0:c4ca662ef73e | 885 | */ |
okini3939 | 0:c4ca662ef73e | 886 | class AtCommandRequest : public XBeeRequest { |
okini3939 | 0:c4ca662ef73e | 887 | public: |
okini3939 | 0:c4ca662ef73e | 888 | AtCommandRequest(); |
okini3939 | 0:c4ca662ef73e | 889 | AtCommandRequest(uint8_t *command); |
okini3939 | 0:c4ca662ef73e | 890 | AtCommandRequest(uint8_t *command, uint8_t *commandValue, uint8_t commandValueLength); |
okini3939 | 0:c4ca662ef73e | 891 | virtual uint8_t getFrameData(uint8_t pos); |
okini3939 | 0:c4ca662ef73e | 892 | virtual uint8_t getFrameDataLength(); |
okini3939 | 0:c4ca662ef73e | 893 | uint8_t* getCommand(); |
okini3939 | 0:c4ca662ef73e | 894 | void setCommand(uint8_t* command); |
okini3939 | 0:c4ca662ef73e | 895 | uint8_t* getCommandValue(); |
okini3939 | 0:c4ca662ef73e | 896 | void setCommandValue(uint8_t* command); |
okini3939 | 0:c4ca662ef73e | 897 | uint8_t getCommandValueLength(); |
okini3939 | 0:c4ca662ef73e | 898 | void setCommandValueLength(uint8_t length); |
okini3939 | 0:c4ca662ef73e | 899 | /** |
okini3939 | 0:c4ca662ef73e | 900 | * Clears the optional commandValue and commandValueLength so that a query may be sent |
okini3939 | 0:c4ca662ef73e | 901 | */ |
okini3939 | 0:c4ca662ef73e | 902 | void clearCommandValue(); |
okini3939 | 0:c4ca662ef73e | 903 | //void reset(); |
okini3939 | 0:c4ca662ef73e | 904 | private: |
okini3939 | 0:c4ca662ef73e | 905 | uint8_t *_command; |
okini3939 | 0:c4ca662ef73e | 906 | uint8_t *_commandValue; |
okini3939 | 0:c4ca662ef73e | 907 | uint8_t _commandValueLength; |
okini3939 | 0:c4ca662ef73e | 908 | }; |
okini3939 | 0:c4ca662ef73e | 909 | |
okini3939 | 0:c4ca662ef73e | 910 | /** |
okini3939 | 0:c4ca662ef73e | 911 | * Represents an Remote AT Command TX packet |
okini3939 | 0:c4ca662ef73e | 912 | * The command is used to configure a remote XBee radio |
okini3939 | 0:c4ca662ef73e | 913 | */ |
okini3939 | 0:c4ca662ef73e | 914 | class RemoteAtCommandRequest : public AtCommandRequest { |
okini3939 | 0:c4ca662ef73e | 915 | public: |
okini3939 | 0:c4ca662ef73e | 916 | RemoteAtCommandRequest(); |
okini3939 | 0:c4ca662ef73e | 917 | /** |
okini3939 | 0:c4ca662ef73e | 918 | * Creates a RemoteAtCommandRequest with 16-bit address to set a command. |
okini3939 | 0:c4ca662ef73e | 919 | * 64-bit address defaults to broadcast and applyChanges is true. |
okini3939 | 0:c4ca662ef73e | 920 | */ |
okini3939 | 0:c4ca662ef73e | 921 | RemoteAtCommandRequest(uint16_t remoteAddress16, uint8_t *command, uint8_t *commandValue, uint8_t commandValueLength); |
okini3939 | 0:c4ca662ef73e | 922 | /** |
okini3939 | 0:c4ca662ef73e | 923 | * Creates a RemoteAtCommandRequest with 16-bit address to query a command. |
okini3939 | 0:c4ca662ef73e | 924 | * 64-bit address defaults to broadcast and applyChanges is true. |
okini3939 | 0:c4ca662ef73e | 925 | */ |
okini3939 | 0:c4ca662ef73e | 926 | RemoteAtCommandRequest(uint16_t remoteAddress16, uint8_t *command); |
okini3939 | 0:c4ca662ef73e | 927 | /** |
okini3939 | 0:c4ca662ef73e | 928 | * Creates a RemoteAtCommandRequest with 64-bit address to set a command. |
okini3939 | 0:c4ca662ef73e | 929 | * 16-bit address defaults to broadcast and applyChanges is true. |
okini3939 | 0:c4ca662ef73e | 930 | */ |
okini3939 | 0:c4ca662ef73e | 931 | RemoteAtCommandRequest(XBeeAddress64 &remoteAddress64, uint8_t *command, uint8_t *commandValue, uint8_t commandValueLength); |
okini3939 | 0:c4ca662ef73e | 932 | /** |
okini3939 | 0:c4ca662ef73e | 933 | * Creates a RemoteAtCommandRequest with 16-bit address to query a command. |
okini3939 | 0:c4ca662ef73e | 934 | * 16-bit address defaults to broadcast and applyChanges is true. |
okini3939 | 0:c4ca662ef73e | 935 | */ |
okini3939 | 0:c4ca662ef73e | 936 | RemoteAtCommandRequest(XBeeAddress64 &remoteAddress64, uint8_t *command); |
okini3939 | 0:c4ca662ef73e | 937 | uint16_t getRemoteAddress16(); |
okini3939 | 0:c4ca662ef73e | 938 | void setRemoteAddress16(uint16_t remoteAddress16); |
okini3939 | 0:c4ca662ef73e | 939 | XBeeAddress64& getRemoteAddress64(); |
okini3939 | 0:c4ca662ef73e | 940 | void setRemoteAddress64(XBeeAddress64 &remoteAddress64); |
okini3939 | 0:c4ca662ef73e | 941 | bool getApplyChanges(); |
okini3939 | 0:c4ca662ef73e | 942 | void setApplyChanges(bool applyChanges); |
okini3939 | 0:c4ca662ef73e | 943 | virtual uint8_t getFrameData(uint8_t pos); |
okini3939 | 0:c4ca662ef73e | 944 | virtual uint8_t getFrameDataLength(); |
okini3939 | 0:c4ca662ef73e | 945 | static XBeeAddress64 broadcastAddress64; |
okini3939 | 0:c4ca662ef73e | 946 | // static uint16_t broadcast16Address; |
okini3939 | 0:c4ca662ef73e | 947 | private: |
okini3939 | 0:c4ca662ef73e | 948 | XBeeAddress64 _remoteAddress64; |
okini3939 | 0:c4ca662ef73e | 949 | uint16_t _remoteAddress16; |
okini3939 | 0:c4ca662ef73e | 950 | bool _applyChanges; |
okini3939 | 0:c4ca662ef73e | 951 | }; |
okini3939 | 0:c4ca662ef73e | 952 | |
okini3939 | 0:c4ca662ef73e | 953 | |
okini3939 | 0:c4ca662ef73e | 954 | |
okini3939 | 0:c4ca662ef73e | 955 | #endif //XBee_h |