Fork of my MQTTGateway

Dependencies:   mbed-http

Committer:
vpcola
Date:
Sat Apr 08 14:45:51 2017 +0000
Revision:
0:f1d3878b8dd9
Initial commit

Who changed what in which revision?

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