Fork of my original MQTTGateway

Dependencies:   mbed-http

Committer:
vpcola
Date:
Sat Apr 08 14:43:14 2017 +0000
Revision:
0:a1734fe1ec4b
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew 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(__API_FRAME_H_)
vpcola 0:a1734fe1ec4b 14 #define __API_FRAME_H_
vpcola 0:a1734fe1ec4b 15
vpcola 0:a1734fe1ec4b 16 #include "XBee/Addresses.h"
vpcola 0:a1734fe1ec4b 17
vpcola 0:a1734fe1ec4b 18 /** Class for XBee API frames */
vpcola 0:a1734fe1ec4b 19 class ApiFrame
vpcola 0:a1734fe1ec4b 20 {
vpcola 0:a1734fe1ec4b 21 /** Static variable that contains the last frame ID value assigned */
vpcola 0:a1734fe1ec4b 22 static uint8_t last_frame_id;
vpcola 0:a1734fe1ec4b 23
vpcola 0:a1734fe1ec4b 24 public:
vpcola 0:a1734fe1ec4b 25 /** List of API frames. Note that not all frames are supported by all radios */
vpcola 0:a1734fe1ec4b 26 enum ApiFrameType {
vpcola 0:a1734fe1ec4b 27
vpcola 0:a1734fe1ec4b 28 TxReq64Bit = 0x00, /**< TxReq64Bit: Only for 802.15.4 modules */
vpcola 0:a1734fe1ec4b 29 TxReq16Bit = 0x01, /**< TxReq16Bit: Only for 802.15.4 modules */
vpcola 0:a1734fe1ec4b 30 AtCmd = 0x08, /**< AtCmd */
vpcola 0:a1734fe1ec4b 31 AtCmdQueuePV = 0x09, /**< AtCmdQueuePV */
vpcola 0:a1734fe1ec4b 32 TxReqZBDM = 0x10, /**< TxReqZBDM: Only for ZigBee and DigiMesh modules */
vpcola 0:a1734fe1ec4b 33 ExpAddrCmd = 0x11, /**< ExpAddrCmd: Only for ZigBee modules and DigiMesh */
vpcola 0:a1734fe1ec4b 34 RemoteCmdReq = 0x17, /**< RemoteCmdReq */
vpcola 0:a1734fe1ec4b 35 CreateSrcRoute = 0x21, /**< CreateSrcRoute */
vpcola 0:a1734fe1ec4b 36 RxPacket64Bit = 0x80, /**< RxPacket64Bit: Only for 802.15.4 modules */
vpcola 0:a1734fe1ec4b 37 RxPacket16Bit = 0x81, /**< RxPacket16Bit: Only for 802.15.4 modules */
vpcola 0:a1734fe1ec4b 38 Io64Bit = 0x82, /**< Io64Bit: Only for 802.15.4 modules */
vpcola 0:a1734fe1ec4b 39 Io16Bit = 0x83, /**< Io16Bit */
vpcola 0:a1734fe1ec4b 40 AtCmdResp = 0x88, /**< AtCmdResp */
vpcola 0:a1734fe1ec4b 41 TxStatus = 0x89, /**< TxStatus */
vpcola 0:a1734fe1ec4b 42 AtModemStatus = 0x8A, /**< AtModemStatus */
vpcola 0:a1734fe1ec4b 43 TxStatusZBDM = 0x8B, /**< TxStatusZBDM: Only for ZigBee and DigiMesh modules */
vpcola 0:a1734fe1ec4b 44 RouteInfo = 0x8D, /**< RouteInfo: Only for DigiMesh modules */
vpcola 0:a1734fe1ec4b 45 AggregateAddr = 0x8E, /**< AggregateAddr: Only for DigiMesh modules */
vpcola 0:a1734fe1ec4b 46 RxPacketAO0 = 0x90, /**< RxPacketAO0: Only for ZigBee and DigiMesh modules */
vpcola 0:a1734fe1ec4b 47 RxPacketAO1 = 0x91, /**< RxPacketAO1: Only for ZigBee and DigiMesh modules */
vpcola 0:a1734fe1ec4b 48 IoSampleRxZBDM = 0x92, /**< IoSampleRxZBDM: Only for ZigBee and DigiMesh modules */
vpcola 0:a1734fe1ec4b 49 SensorRxIndAO0 = 0x94, /**< SensorRxIndAO0: Only for ZigBee modules */
vpcola 0:a1734fe1ec4b 50 NodeIdentIndAO0 = 0x95, /**< NodeIdentIndAO0: Only for ZigBee and DigiMesh modules */
vpcola 0:a1734fe1ec4b 51 RemoteCmdResp = 0x97, /**< RemoteCmdResp */
vpcola 0:a1734fe1ec4b 52 OtaFwUpStatus = 0xA0, /**< OtaFwUpStatus */
vpcola 0:a1734fe1ec4b 53 RouteRecInd = 0xA1, /**< RouteRecInd */
vpcola 0:a1734fe1ec4b 54 Many2OneRRInd = 0xA3, /**< Many2OneRRInd */
vpcola 0:a1734fe1ec4b 55 Invalid = ~0, /**< Invalid */
vpcola 0:a1734fe1ec4b 56 };
vpcola 0:a1734fe1ec4b 57
vpcola 0:a1734fe1ec4b 58 /** Default constructor */
vpcola 0:a1734fe1ec4b 59 ApiFrame();
vpcola 0:a1734fe1ec4b 60
vpcola 0:a1734fe1ec4b 61 /** Constructor
vpcola 0:a1734fe1ec4b 62 *
vpcola 0:a1734fe1ec4b 63 * @param len length of the API frame (will allocate len bytes).
vpcola 0:a1734fe1ec4b 64 */
vpcola 0:a1734fe1ec4b 65 ApiFrame(uint16_t len);
vpcola 0:a1734fe1ec4b 66
vpcola 0:a1734fe1ec4b 67 /** Constructor
vpcola 0:a1734fe1ec4b 68 *
vpcola 0:a1734fe1ec4b 69 * @param type frame type of this api frame.
vpcola 0:a1734fe1ec4b 70 * @param data pointer to frame data payload.
vpcola 0:a1734fe1ec4b 71 * @param len length of the payload.
vpcola 0:a1734fe1ec4b 72 */
vpcola 0:a1734fe1ec4b 73 ApiFrame(ApiFrameType type, const uint8_t *data, uint16_t len);
vpcola 0:a1734fe1ec4b 74
vpcola 0:a1734fe1ec4b 75 /** Destructor */
vpcola 0:a1734fe1ec4b 76 ~ApiFrame();
vpcola 0:a1734fe1ec4b 77
vpcola 0:a1734fe1ec4b 78 ApiFrame(const ApiFrame& other); /* Intentionally not implemented */
vpcola 0:a1734fe1ec4b 79
vpcola 0:a1734fe1ec4b 80 /** get_frame_type gets the type of the frame
vpcola 0:a1734fe1ec4b 81 *
vpcola 0:a1734fe1ec4b 82 * @returns the type of this frame.
vpcola 0:a1734fe1ec4b 83 */
vpcola 0:a1734fe1ec4b 84 ApiFrameType get_frame_type() const;
vpcola 0:a1734fe1ec4b 85
vpcola 0:a1734fe1ec4b 86 /** dump dumps the information of this frame */
vpcola 0:a1734fe1ec4b 87 void dump() const;
vpcola 0:a1734fe1ec4b 88
vpcola 0:a1734fe1ec4b 89 /** dump_if dumps the information of the frame if the frame type matches
vpcola 0:a1734fe1ec4b 90 * with the parameter.
vpcola 0:a1734fe1ec4b 91 *
vpcola 0:a1734fe1ec4b 92 * @param type dump the frame info/data if the frame type matches with type.
vpcola 0:a1734fe1ec4b 93 */
vpcola 0:a1734fe1ec4b 94 void dump_if(ApiFrameType type);
vpcola 0:a1734fe1ec4b 95
vpcola 0:a1734fe1ec4b 96
vpcola 0:a1734fe1ec4b 97 /** set_frame_type sets the type of the frame to type.
vpcola 0:a1734fe1ec4b 98 *
vpcola 0:a1734fe1ec4b 99 * @param type the type we want to set on the frame.
vpcola 0:a1734fe1ec4b 100 */
vpcola 0:a1734fe1ec4b 101 void set_frame_type(ApiFrameType type);
vpcola 0:a1734fe1ec4b 102
vpcola 0:a1734fe1ec4b 103 /** get_data_len gets the length of the frame data payload.
vpcola 0:a1734fe1ec4b 104 *
vpcola 0:a1734fe1ec4b 105 * @returns the length of the data payload.
vpcola 0:a1734fe1ec4b 106 */
vpcola 0:a1734fe1ec4b 107 uint16_t get_data_len() const;
vpcola 0:a1734fe1ec4b 108
vpcola 0:a1734fe1ec4b 109 /** set_data_len sets the length of the frame data payload.
vpcola 0:a1734fe1ec4b 110 *
vpcola 0:a1734fe1ec4b 111 * @param len the length of the data payload will be set on this frame.
vpcola 0:a1734fe1ec4b 112 */
vpcola 0:a1734fe1ec4b 113 void set_data_len(uint16_t len);
vpcola 0:a1734fe1ec4b 114
vpcola 0:a1734fe1ec4b 115 /** get_data returns a pointer to the frame data payload.
vpcola 0:a1734fe1ec4b 116 *
vpcola 0:a1734fe1ec4b 117 * @returns a pointer to the frame data payload.
vpcola 0:a1734fe1ec4b 118 */
vpcola 0:a1734fe1ec4b 119 const uint8_t *get_data() const;
vpcola 0:a1734fe1ec4b 120
vpcola 0:a1734fe1ec4b 121 /** get_data_at returns the byte at index offset.
vpcola 0:a1734fe1ec4b 122 *
vpcola 0:a1734fe1ec4b 123 * @param index offset of the byte we want to get.
vpcola 0:a1734fe1ec4b 124 * @returns the byte at index offset.
vpcola 0:a1734fe1ec4b 125 */
vpcola 0:a1734fe1ec4b 126 uint8_t get_data_at(uint16_t index) const;
vpcola 0:a1734fe1ec4b 127
vpcola 0:a1734fe1ec4b 128 /** set_data sets data byte at the specified index or offset.
vpcola 0:a1734fe1ec4b 129 *
vpcola 0:a1734fe1ec4b 130 * @param data byte that will be set at index position.
vpcola 0:a1734fe1ec4b 131 * @param index offset of the byte we want to set.
vpcola 0:a1734fe1ec4b 132 */
vpcola 0:a1734fe1ec4b 133 void set_data(uint8_t data, uint16_t index);
vpcola 0:a1734fe1ec4b 134
vpcola 0:a1734fe1ec4b 135 /** get_frame_id returns the frame id of this frame.
vpcola 0:a1734fe1ec4b 136 *
vpcola 0:a1734fe1ec4b 137 * @returns the frame id of this frame.
vpcola 0:a1734fe1ec4b 138 */
vpcola 0:a1734fe1ec4b 139 uint8_t get_frame_id() const;
vpcola 0:a1734fe1ec4b 140
vpcola 0:a1734fe1ec4b 141 static uint8_t get_current_frame_id()
vpcola 0:a1734fe1ec4b 142 {
vpcola 0:a1734fe1ec4b 143 return last_frame_id;
vpcola 0:a1734fe1ec4b 144 }
vpcola 0:a1734fe1ec4b 145
vpcola 0:a1734fe1ec4b 146 protected:
vpcola 0:a1734fe1ec4b 147 /** Type of this frame */
vpcola 0:a1734fe1ec4b 148 ApiFrameType _type;
vpcola 0:a1734fe1ec4b 149
vpcola 0:a1734fe1ec4b 150 /** length of the payload, excluding the frame type */
vpcola 0:a1734fe1ec4b 151 uint16_t _data_frame_len;
vpcola 0:a1734fe1ec4b 152
vpcola 0:a1734fe1ec4b 153 /** pointer to the frame data */
vpcola 0:a1734fe1ec4b 154 uint8_t *_data;
vpcola 0:a1734fe1ec4b 155
vpcola 0:a1734fe1ec4b 156 /** True if the constructor allocates the data. Needed to delete it on the destructor */
vpcola 0:a1734fe1ec4b 157 bool _alloc_data;
vpcola 0:a1734fe1ec4b 158
vpcola 0:a1734fe1ec4b 159 /** Frame ID of this frame */
vpcola 0:a1734fe1ec4b 160 uint8_t _frame_id;
vpcola 0:a1734fe1ec4b 161
vpcola 0:a1734fe1ec4b 162 /** get_next_frame_id - returns the next frame ID secuentially, skipping the value 0
vpcola 0:a1734fe1ec4b 163 *
vpcola 0:a1734fe1ec4b 164 * @returns the next frame ID that should be assigned to a frame
vpcola 0:a1734fe1ec4b 165 */
vpcola 0:a1734fe1ec4b 166 uint8_t get_next_frame_id();
vpcola 0:a1734fe1ec4b 167
vpcola 0:a1734fe1ec4b 168 /** set_api_frame sets several members
vpcola 0:a1734fe1ec4b 169 *
vpcola 0:a1734fe1ec4b 170 * @param type frame type of this api frame.
vpcola 0:a1734fe1ec4b 171 * @param data pointer to frame data payload.
vpcola 0:a1734fe1ec4b 172 * @param len length of the payload.
vpcola 0:a1734fe1ec4b 173 */
vpcola 0:a1734fe1ec4b 174 void set_api_frame(ApiFrameType type, const uint8_t *data, uint16_t len);
vpcola 0:a1734fe1ec4b 175 };
vpcola 0:a1734fe1ec4b 176
vpcola 0:a1734fe1ec4b 177 #endif /* __API_FRAME_H_ */