Senet Packet API

Dependents:   MTDOT-UDKDemo_Senet Senet NAMote mDot-IKS01A1 unh-hackathon-example ... more

Committer:
shaunkrnelson
Date:
Tue Mar 08 09:08:44 2016 -0500
Revision:
0:cc9f4010bba6
Child:
1:3e0cc8ad24f1
Child:
2:9c971be7692b
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shaunkrnelson 0:cc9f4010bba6 1 /*
shaunkrnelson 0:cc9f4010bba6 2 * =====================================================================================
shaunkrnelson 0:cc9f4010bba6 3 *
shaunkrnelson 0:cc9f4010bba6 4 * Filename: senet_packet.h
shaunkrnelson 0:cc9f4010bba6 5 *
shaunkrnelson 0:cc9f4010bba6 6 * Description: Senet Packet types
shaunkrnelson 0:cc9f4010bba6 7 *
shaunkrnelson 0:cc9f4010bba6 8 * Version: 1.0
shaunkrnelson 0:cc9f4010bba6 9 * Created: 03/05/2016 03:13:20 PM
shaunkrnelson 0:cc9f4010bba6 10 * Revision: 1
shaunkrnelson 0:cc9f4010bba6 11 *
shaunkrnelson 0:cc9f4010bba6 12 * Author: Shaun Nelson, coder extraodinaire
shaunkrnelson 0:cc9f4010bba6 13 * Company: Senet, Inc
shaunkrnelson 0:cc9f4010bba6 14 *
shaunkrnelson 0:cc9f4010bba6 15 * =====================================================================================
shaunkrnelson 0:cc9f4010bba6 16 */
shaunkrnelson 0:cc9f4010bba6 17
shaunkrnelson 0:cc9f4010bba6 18 #ifndef __SENET_PACKET__
shaunkrnelson 0:cc9f4010bba6 19 #define __SENET_PACKET__
shaunkrnelson 0:cc9f4010bba6 20
shaunkrnelson 0:cc9f4010bba6 21 #include <stdint.h>
shaunkrnelson 0:cc9f4010bba6 22 #include <string.h>
shaunkrnelson 0:cc9f4010bba6 23
shaunkrnelson 0:cc9f4010bba6 24
shaunkrnelson 0:cc9f4010bba6 25 // Senet packet types
shaunkrnelson 0:cc9f4010bba6 26 enum SenetPacketT
shaunkrnelson 0:cc9f4010bba6 27 {
shaunkrnelson 0:cc9f4010bba6 28 SELF_ID_PACKET = 0,
shaunkrnelson 0:cc9f4010bba6 29 RF_PACKET = 1,
shaunkrnelson 0:cc9f4010bba6 30 GPS_PACKET = 2,
shaunkrnelson 0:cc9f4010bba6 31 CONTROL_PACKET = 3,
shaunkrnelson 0:cc9f4010bba6 32 BOOT_INFO_PACKET = 4,
shaunkrnelson 0:cc9f4010bba6 33 SENSOR_PACKET = 8,
shaunkrnelson 0:cc9f4010bba6 34 OCTET_STRING_PACKET = 126,
shaunkrnelson 0:cc9f4010bba6 35 UTF_8_STRING = 127
shaunkrnelson 0:cc9f4010bba6 36 };
shaunkrnelson 0:cc9f4010bba6 37
shaunkrnelson 0:cc9f4010bba6 38
shaunkrnelson 0:cc9f4010bba6 39 /*
shaunkrnelson 0:cc9f4010bba6 40 * =====================================================================================
shaunkrnelson 0:cc9f4010bba6 41 * Class: SenetPacket
shaunkrnelson 0:cc9f4010bba6 42 * Description: Senet Packet Base class
shaunkrnelson 0:cc9f4010bba6 43 * =====================================================================================
shaunkrnelson 0:cc9f4010bba6 44 */
shaunkrnelson 0:cc9f4010bba6 45 struct SenetPacket
shaunkrnelson 0:cc9f4010bba6 46 {
shaunkrnelson 0:cc9f4010bba6 47 static const uint32_t MAX_FRAME_SIZE = 242;
shaunkrnelson 0:cc9f4010bba6 48 static const uint8_t VERSION = 1;
shaunkrnelson 0:cc9f4010bba6 49
shaunkrnelson 0:cc9f4010bba6 50 /*
shaunkrnelson 0:cc9f4010bba6 51 *--------------------------------------------------------------------------------------
shaunkrnelson 0:cc9f4010bba6 52 * Class: SenetPacket
shaunkrnelson 0:cc9f4010bba6 53 * Method: serialize
shaunkrnelson 0:cc9f4010bba6 54 * Description: Packet serializer
shaunkrnelson 0:cc9f4010bba6 55 *--------------------------------------------------------------------------------------
shaunkrnelson 0:cc9f4010bba6 56 */
shaunkrnelson 0:cc9f4010bba6 57 int32_t serialize();
shaunkrnelson 0:cc9f4010bba6 58
shaunkrnelson 0:cc9f4010bba6 59 inline const uint8_t* payload() { return buffer;}
shaunkrnelson 0:cc9f4010bba6 60 uint8_t length () { return pktLen; }
shaunkrnelson 0:cc9f4010bba6 61
shaunkrnelson 0:cc9f4010bba6 62 protected:
shaunkrnelson 0:cc9f4010bba6 63 // Common packet header
shaunkrnelson 0:cc9f4010bba6 64 struct PacketHeader
shaunkrnelson 0:cc9f4010bba6 65 {
shaunkrnelson 0:cc9f4010bba6 66 static const uint8_t HEADER_SIZE = 2;
shaunkrnelson 0:cc9f4010bba6 67
shaunkrnelson 0:cc9f4010bba6 68 uint8_t version; // packet format versioni
shaunkrnelson 0:cc9f4010bba6 69 uint8_t type; // Senet packet type
shaunkrnelson 0:cc9f4010bba6 70
shaunkrnelson 0:cc9f4010bba6 71 PacketHeader(uint8_t _type=0)
shaunkrnelson 0:cc9f4010bba6 72 {
shaunkrnelson 0:cc9f4010bba6 73 version = VERSION;
shaunkrnelson 0:cc9f4010bba6 74 type = _type;
shaunkrnelson 0:cc9f4010bba6 75 }
shaunkrnelson 0:cc9f4010bba6 76
shaunkrnelson 0:cc9f4010bba6 77 int32_t serialize (uint8_t *frame, int32_t len);
shaunkrnelson 0:cc9f4010bba6 78 bool deserialize(uint8_t *frame, int32_t len);
shaunkrnelson 0:cc9f4010bba6 79 } header;
shaunkrnelson 0:cc9f4010bba6 80
shaunkrnelson 0:cc9f4010bba6 81 uint8_t pktLen;
shaunkrnelson 0:cc9f4010bba6 82 uint8_t *buffer;
shaunkrnelson 0:cc9f4010bba6 83 uint8_t bufferLen;
shaunkrnelson 0:cc9f4010bba6 84 bool ownBuffer;
shaunkrnelson 0:cc9f4010bba6 85
shaunkrnelson 0:cc9f4010bba6 86 SenetPacket(uint8_t senetPktType, uint8_t *_buffer=NULL, uint8_t _buflen=0);
shaunkrnelson 0:cc9f4010bba6 87 ~SenetPacket();
shaunkrnelson 0:cc9f4010bba6 88
shaunkrnelson 0:cc9f4010bba6 89 /*
shaunkrnelson 0:cc9f4010bba6 90 *--------------------------------------------------------------------------------------
shaunkrnelson 0:cc9f4010bba6 91 * Class: SenetPacket
shaunkrnelson 0:cc9f4010bba6 92 * Method: serializePayload
shaunkrnelson 0:cc9f4010bba6 93 * Description: Each unique packet type implements this to serialize its payload
shaunkrnelson 0:cc9f4010bba6 94 *--------------------------------------------------------------------------------------
shaunkrnelson 0:cc9f4010bba6 95 */
shaunkrnelson 0:cc9f4010bba6 96 virtual int32_t serializePayload(uint8_t *frame, int32_t len) = 0;
shaunkrnelson 0:cc9f4010bba6 97
shaunkrnelson 0:cc9f4010bba6 98 };
shaunkrnelson 0:cc9f4010bba6 99
shaunkrnelson 0:cc9f4010bba6 100
shaunkrnelson 0:cc9f4010bba6 101 /*
shaunkrnelson 0:cc9f4010bba6 102 * =====================================================================================
shaunkrnelson 0:cc9f4010bba6 103 * Class: BootInfoPacket
shaunkrnelson 0:cc9f4010bba6 104 * Description: Device Boot information packet
shaunkrnelson 0:cc9f4010bba6 105 * =====================================================================================
shaunkrnelson 0:cc9f4010bba6 106 */
shaunkrnelson 0:cc9f4010bba6 107 struct BootInfoPacket : public SenetPacket
shaunkrnelson 0:cc9f4010bba6 108 {
shaunkrnelson 0:cc9f4010bba6 109 static const uint8_t BOOT_PAYLOAD_LENGTH = 8;
shaunkrnelson 0:cc9f4010bba6 110
shaunkrnelson 0:cc9f4010bba6 111 uint16_t bootCount; // number of device boots
shaunkrnelson 0:cc9f4010bba6 112 uint16_t resetCount; // number of device resets
shaunkrnelson 0:cc9f4010bba6 113 uint32_t lastBootReason; // last boot reason
shaunkrnelson 0:cc9f4010bba6 114
shaunkrnelson 0:cc9f4010bba6 115 BootInfoPacket(uint8_t *_buffer=NULL, uint8_t _buflen=0) :
shaunkrnelson 0:cc9f4010bba6 116 SenetPacket(BOOT_INFO_PACKET, _buffer, _buflen)
shaunkrnelson 0:cc9f4010bba6 117 {
shaunkrnelson 0:cc9f4010bba6 118 bootCount = 0;
shaunkrnelson 0:cc9f4010bba6 119 resetCount = 0;
shaunkrnelson 0:cc9f4010bba6 120 lastBootReason = 0;
shaunkrnelson 0:cc9f4010bba6 121 }
shaunkrnelson 0:cc9f4010bba6 122
shaunkrnelson 0:cc9f4010bba6 123 protected:
shaunkrnelson 0:cc9f4010bba6 124 /*
shaunkrnelson 0:cc9f4010bba6 125 *--------------------------------------------------------------------------------------
shaunkrnelson 0:cc9f4010bba6 126 * Class: BootInfoPacket
shaunkrnelson 0:cc9f4010bba6 127 * Method: serializePayload
shaunkrnelson 0:cc9f4010bba6 128 * Description: Serialize packet data
shaunkrnelson 0:cc9f4010bba6 129 *--------------------------------------------------------------------------------------
shaunkrnelson 0:cc9f4010bba6 130 */
shaunkrnelson 0:cc9f4010bba6 131 virtual int32_t serializePayload(uint8_t *frame, int32_t len);
shaunkrnelson 0:cc9f4010bba6 132 };
shaunkrnelson 0:cc9f4010bba6 133
shaunkrnelson 0:cc9f4010bba6 134
shaunkrnelson 0:cc9f4010bba6 135 /*
shaunkrnelson 0:cc9f4010bba6 136 * =====================================================================================
shaunkrnelson 0:cc9f4010bba6 137 * Class: ControlWordPacket
shaunkrnelson 0:cc9f4010bba6 138 * Description: Packet to configure device
shaunkrnelson 0:cc9f4010bba6 139 * =====================================================================================
shaunkrnelson 0:cc9f4010bba6 140 */
shaunkrnelson 0:cc9f4010bba6 141 struct ConfigWordPacket : public SenetPacket
shaunkrnelson 0:cc9f4010bba6 142 {
shaunkrnelson 0:cc9f4010bba6 143 static const uint8_t CONTROL_PAYLOAD_LENGTH = 9;
shaunkrnelson 0:cc9f4010bba6 144
shaunkrnelson 0:cc9f4010bba6 145 ConfigWordPacket(uint8_t *_buffer=NULL, uint8_t _buflen=0) :
shaunkrnelson 0:cc9f4010bba6 146 SenetPacket(CONTROL_PACKET, _buffer, _buflen) { config = 0; mask = 0; authKey = 0; }
shaunkrnelson 0:cc9f4010bba6 147
shaunkrnelson 0:cc9f4010bba6 148 uint32_t config; // configuration word
shaunkrnelson 0:cc9f4010bba6 149 uint32_t mask; // valid bit mask applied to configuration word
shaunkrnelson 0:cc9f4010bba6 150 uint8_t authKey; // Downlink authentication key
shaunkrnelson 0:cc9f4010bba6 151
shaunkrnelson 0:cc9f4010bba6 152 /*
shaunkrnelson 0:cc9f4010bba6 153 *--------------------------------------------------------------------------------------
shaunkrnelson 0:cc9f4010bba6 154 * Class: ConfigWordPacket
shaunkrnelson 0:cc9f4010bba6 155 * Method: serializePayload
shaunkrnelson 0:cc9f4010bba6 156 * Description: Serialize packet data
shaunkrnelson 0:cc9f4010bba6 157 *--------------------------------------------------------------------------------------
shaunkrnelson 0:cc9f4010bba6 158 */
shaunkrnelson 0:cc9f4010bba6 159 virtual int32_t serializePayload(uint8_t *frame, int32_t len);
shaunkrnelson 0:cc9f4010bba6 160 };
shaunkrnelson 0:cc9f4010bba6 161
shaunkrnelson 0:cc9f4010bba6 162
shaunkrnelson 0:cc9f4010bba6 163 /*
shaunkrnelson 0:cc9f4010bba6 164 * =====================================================================================
shaunkrnelson 0:cc9f4010bba6 165 * Class: GpsPacket
shaunkrnelson 0:cc9f4010bba6 166 * Description: Transmit device location in Decimal degress (http://www.en.wikipedia.org/wiki/Decimal_degrees)
shaunkrnelson 0:cc9f4010bba6 167 * =====================================================================================
shaunkrnelson 0:cc9f4010bba6 168 */
shaunkrnelson 0:cc9f4010bba6 169 struct GpsPacket : public SenetPacket
shaunkrnelson 0:cc9f4010bba6 170 {
shaunkrnelson 0:cc9f4010bba6 171 static const uint8_t GPS_PAYLOAD_LENGTH = 9;
shaunkrnelson 0:cc9f4010bba6 172
shaunkrnelson 0:cc9f4010bba6 173 bool setCoordinates(uint32_t latitude, uint32_t longitude, uint16_t elevation);
shaunkrnelson 0:cc9f4010bba6 174 inline void setTxPower(uint8_t dBm) { txPower = dBm; }
shaunkrnelson 0:cc9f4010bba6 175
shaunkrnelson 0:cc9f4010bba6 176
shaunkrnelson 0:cc9f4010bba6 177 GpsPacket(uint8_t* _buffer=NULL, uint8_t _buflen=0):
shaunkrnelson 0:cc9f4010bba6 178 SenetPacket(GPS_PACKET, _buffer, _buflen)
shaunkrnelson 0:cc9f4010bba6 179 {
shaunkrnelson 0:cc9f4010bba6 180 latitude = 0;
shaunkrnelson 0:cc9f4010bba6 181 longitude = 0;
shaunkrnelson 0:cc9f4010bba6 182 elevation = 0;
shaunkrnelson 0:cc9f4010bba6 183 txPower = 0;
shaunkrnelson 0:cc9f4010bba6 184 }
shaunkrnelson 0:cc9f4010bba6 185
shaunkrnelson 0:cc9f4010bba6 186 protected:
shaunkrnelson 0:cc9f4010bba6 187 uint32_t latitude;
shaunkrnelson 0:cc9f4010bba6 188 uint32_t longitude;
shaunkrnelson 0:cc9f4010bba6 189 uint16_t elevation;
shaunkrnelson 0:cc9f4010bba6 190 uint8_t txPower;
shaunkrnelson 0:cc9f4010bba6 191
shaunkrnelson 0:cc9f4010bba6 192 /*
shaunkrnelson 0:cc9f4010bba6 193 *--------------------------------------------------------------------------------------
shaunkrnelson 0:cc9f4010bba6 194 * Class: GpsPacket
shaunkrnelson 0:cc9f4010bba6 195 * Method: serializePayload
shaunkrnelson 0:cc9f4010bba6 196 * Description: Serialize the data
shaunkrnelson 0:cc9f4010bba6 197 *--------------------------------------------------------------------------------------
shaunkrnelson 0:cc9f4010bba6 198 */
shaunkrnelson 0:cc9f4010bba6 199 virtual int32_t serializePayload(uint8_t *frame, int32_t len);
shaunkrnelson 0:cc9f4010bba6 200 };
shaunkrnelson 0:cc9f4010bba6 201
shaunkrnelson 0:cc9f4010bba6 202
shaunkrnelson 0:cc9f4010bba6 203 /*
shaunkrnelson 0:cc9f4010bba6 204 * =====================================================================================
shaunkrnelson 0:cc9f4010bba6 205 * Class: OctetStringPacket
shaunkrnelson 0:cc9f4010bba6 206 * Description: Variable length Octet String packet
shaunkrnelson 0:cc9f4010bba6 207 * =====================================================================================
shaunkrnelson 0:cc9f4010bba6 208 */
shaunkrnelson 0:cc9f4010bba6 209 struct OctetStringPacket : public SenetPacket
shaunkrnelson 0:cc9f4010bba6 210 {
shaunkrnelson 0:cc9f4010bba6 211 bool setOctetString(uint8_t *os, uint8_t len);
shaunkrnelson 0:cc9f4010bba6 212
shaunkrnelson 0:cc9f4010bba6 213 OctetStringPacket(uint8_t size);
shaunkrnelson 0:cc9f4010bba6 214
shaunkrnelson 0:cc9f4010bba6 215 protected:
shaunkrnelson 0:cc9f4010bba6 216 uint8_t oslen;
shaunkrnelson 0:cc9f4010bba6 217 uint8_t max;
shaunkrnelson 0:cc9f4010bba6 218
shaunkrnelson 0:cc9f4010bba6 219 virtual int32_t serializePayload(uint8_t *frame, int32_t len);
shaunkrnelson 0:cc9f4010bba6 220 };
shaunkrnelson 0:cc9f4010bba6 221
shaunkrnelson 0:cc9f4010bba6 222 /*
shaunkrnelson 0:cc9f4010bba6 223 * =====================================================================================
shaunkrnelson 0:cc9f4010bba6 224 * Class: RFDataPacket
shaunkrnelson 0:cc9f4010bba6 225 * Description: Radio Data packet
shaunkrnelson 0:cc9f4010bba6 226 * =====================================================================================
shaunkrnelson 0:cc9f4010bba6 227 */
shaunkrnelson 0:cc9f4010bba6 228 struct RFDataPacket : public SenetPacket
shaunkrnelson 0:cc9f4010bba6 229 {
shaunkrnelson 0:cc9f4010bba6 230 static const uint8_t RFDATA_PAYLOAD_LEN = 8;
shaunkrnelson 0:cc9f4010bba6 231
shaunkrnelson 0:cc9f4010bba6 232 uint8_t channel; // The channel the device sent on
shaunkrnelson 0:cc9f4010bba6 233 uint8_t txpower; // The transmit power in dBm used by the device
shaunkrnelson 0:cc9f4010bba6 234 uint8_t datarate; // The datarate used by the device
shaunkrnelson 0:cc9f4010bba6 235 uint8_t snr; // Signal to Noise ratio of the last frame received
shaunkrnelson 0:cc9f4010bba6 236 uint8_t rssi; // RSSI of the last frame received
shaunkrnelson 0:cc9f4010bba6 237 uint32_t timestamp; // The device's current timestamp
shaunkrnelson 0:cc9f4010bba6 238
shaunkrnelson 0:cc9f4010bba6 239 RFDataPacket(uint8_t *_buffer=NULL, uint8_t _buflen=0):
shaunkrnelson 0:cc9f4010bba6 240 SenetPacket(RF_PACKET, _buffer, _buflen)
shaunkrnelson 0:cc9f4010bba6 241 {
shaunkrnelson 0:cc9f4010bba6 242 channel = 0;
shaunkrnelson 0:cc9f4010bba6 243 txpower = 0;
shaunkrnelson 0:cc9f4010bba6 244 datarate = 0;
shaunkrnelson 0:cc9f4010bba6 245 snr = 0;
shaunkrnelson 0:cc9f4010bba6 246 rssi = 0;
shaunkrnelson 0:cc9f4010bba6 247 timestamp = 0;
shaunkrnelson 0:cc9f4010bba6 248 }
shaunkrnelson 0:cc9f4010bba6 249
shaunkrnelson 0:cc9f4010bba6 250 /*
shaunkrnelson 0:cc9f4010bba6 251 *--------------------------------------------------------------------------------------
shaunkrnelson 0:cc9f4010bba6 252 * Class: RFDataPacket
shaunkrnelson 0:cc9f4010bba6 253 * Method: serializePayload
shaunkrnelson 0:cc9f4010bba6 254 * Description: Serialize the data
shaunkrnelson 0:cc9f4010bba6 255 *--------------------------------------------------------------------------------------
shaunkrnelson 0:cc9f4010bba6 256 */
shaunkrnelson 0:cc9f4010bba6 257 virtual int32_t serializePayload(uint8_t *frame, int32_t len);
shaunkrnelson 0:cc9f4010bba6 258 };
shaunkrnelson 0:cc9f4010bba6 259
shaunkrnelson 0:cc9f4010bba6 260
shaunkrnelson 0:cc9f4010bba6 261 /*
shaunkrnelson 0:cc9f4010bba6 262 * =====================================================================================
shaunkrnelson 0:cc9f4010bba6 263 * Class: SelfIdPacket
shaunkrnelson 0:cc9f4010bba6 264 * Description:
shaunkrnelson 0:cc9f4010bba6 265 * =====================================================================================
shaunkrnelson 0:cc9f4010bba6 266 */
shaunkrnelson 0:cc9f4010bba6 267 struct SelfIdPacket : public SenetPacket
shaunkrnelson 0:cc9f4010bba6 268 {
shaunkrnelson 0:cc9f4010bba6 269 const static uint8_t EXT_POWER_SUPPLY_ID_MAX = 2;
shaunkrnelson 0:cc9f4010bba6 270 const static uint8_t EXT_POWER_SUPPLY_1 = 1;
shaunkrnelson 0:cc9f4010bba6 271 const static uint8_t EXT_POWER_SUPPLY_2 = 2;
shaunkrnelson 0:cc9f4010bba6 272 const static uint8_t BATTERY_LEVEL_MAX = 7;
shaunkrnelson 0:cc9f4010bba6 273 const static uint8_t SELFID_PAYLOAD_LEN = 8;
shaunkrnelson 0:cc9f4010bba6 274
shaunkrnelson 0:cc9f4010bba6 275 bool setDeviceType (uint32_t model, uint8_t revision);
shaunkrnelson 0:cc9f4010bba6 276 bool setSwVersion (uint8_t major, uint8_t minor, uint8_t point, uint16_t build, uint8_t developer);
shaunkrnelson 0:cc9f4010bba6 277 void setBatteryFailState (bool failed);
shaunkrnelson 0:cc9f4010bba6 278 bool setBatteryLevel (uint8_t level);
shaunkrnelson 0:cc9f4010bba6 279 bool setExtPowerSupplyState (uint8_t id, bool isPresent);
shaunkrnelson 0:cc9f4010bba6 280
shaunkrnelson 0:cc9f4010bba6 281 SelfIdPacket(uint8_t *_buffer=NULL, uint8_t _buflen=0) :
shaunkrnelson 0:cc9f4010bba6 282 SenetPacket(SELF_ID_PACKET, _buffer, _buflen) { deviceType = 0; swVersion = 0; powerMask = 0; }
shaunkrnelson 0:cc9f4010bba6 283
shaunkrnelson 0:cc9f4010bba6 284 protected:
shaunkrnelson 0:cc9f4010bba6 285 uint32_t deviceType;
shaunkrnelson 0:cc9f4010bba6 286 uint32_t swVersion;
shaunkrnelson 0:cc9f4010bba6 287 uint8_t powerMask;
shaunkrnelson 0:cc9f4010bba6 288
shaunkrnelson 0:cc9f4010bba6 289 /*
shaunkrnelson 0:cc9f4010bba6 290 *--------------------------------------------------------------------------------------
shaunkrnelson 0:cc9f4010bba6 291 * Class: SelfIdPacket
shaunkrnelson 0:cc9f4010bba6 292 * Method: serializePayload
shaunkrnelson 0:cc9f4010bba6 293 * Description: Serialize the data
shaunkrnelson 0:cc9f4010bba6 294 *--------------------------------------------------------------------------------------
shaunkrnelson 0:cc9f4010bba6 295 */
shaunkrnelson 0:cc9f4010bba6 296 virtual int32_t serializePayload(uint8_t *frame, int32_t len);
shaunkrnelson 0:cc9f4010bba6 297 };
shaunkrnelson 0:cc9f4010bba6 298
shaunkrnelson 0:cc9f4010bba6 299
shaunkrnelson 0:cc9f4010bba6 300 /*
shaunkrnelson 0:cc9f4010bba6 301 * =====================================================================================
shaunkrnelson 0:cc9f4010bba6 302 * Class: SensorPacket
shaunkrnelson 0:cc9f4010bba6 303 * Description:
shaunkrnelson 0:cc9f4010bba6 304 * =====================================================================================
shaunkrnelson 0:cc9f4010bba6 305 */
shaunkrnelson 0:cc9f4010bba6 306 struct SensorPacket : public SenetPacket
shaunkrnelson 0:cc9f4010bba6 307 {
shaunkrnelson 0:cc9f4010bba6 308 bool setPrimarySensor(uint16_t value) { return addSensorValue(0,1, value);};
shaunkrnelson 0:cc9f4010bba6 309 bool setTemperature (uint16_t value) { return addSensorValue(1,2, value);}
shaunkrnelson 0:cc9f4010bba6 310 void reset();
shaunkrnelson 0:cc9f4010bba6 311
shaunkrnelson 0:cc9f4010bba6 312 SensorPacket(uint8_t *_buffer=NULL, uint8_t _buflen=0) :
shaunkrnelson 0:cc9f4010bba6 313 SenetPacket(SENSOR_PACKET, _buffer, _buflen) {}
shaunkrnelson 0:cc9f4010bba6 314
shaunkrnelson 0:cc9f4010bba6 315 protected:
shaunkrnelson 0:cc9f4010bba6 316 static const uint8_t MAX_SENSOR_VALUES = 2;
shaunkrnelson 0:cc9f4010bba6 317
shaunkrnelson 0:cc9f4010bba6 318 struct SensorValue
shaunkrnelson 0:cc9f4010bba6 319 {
shaunkrnelson 0:cc9f4010bba6 320 uint8_t type;
shaunkrnelson 0:cc9f4010bba6 321 uint16_t value;
shaunkrnelson 0:cc9f4010bba6 322 bool isSet;
shaunkrnelson 0:cc9f4010bba6 323
shaunkrnelson 0:cc9f4010bba6 324 SensorValue() { type = 0; value = 0; isSet = false;}
shaunkrnelson 0:cc9f4010bba6 325
shaunkrnelson 0:cc9f4010bba6 326 int32_t serialize(uint8_t *frame, int32_t len)
shaunkrnelson 0:cc9f4010bba6 327 {
shaunkrnelson 0:cc9f4010bba6 328 if(len < 3)
shaunkrnelson 0:cc9f4010bba6 329 return -1;
shaunkrnelson 0:cc9f4010bba6 330
shaunkrnelson 0:cc9f4010bba6 331 frame[0] = type;
shaunkrnelson 0:cc9f4010bba6 332 frame[1] = (value >> 8) & 0xff;
shaunkrnelson 0:cc9f4010bba6 333 frame[2] = value & 0xff;
shaunkrnelson 0:cc9f4010bba6 334 return 3;
shaunkrnelson 0:cc9f4010bba6 335 }
shaunkrnelson 0:cc9f4010bba6 336 } sensorValue[MAX_SENSOR_VALUES];
shaunkrnelson 0:cc9f4010bba6 337
shaunkrnelson 0:cc9f4010bba6 338 bool addSensorValue(uint8_t position, uint8_t type, uint16_t value);
shaunkrnelson 0:cc9f4010bba6 339
shaunkrnelson 0:cc9f4010bba6 340 /*
shaunkrnelson 0:cc9f4010bba6 341 *--------------------------------------------------------------------------------------
shaunkrnelson 0:cc9f4010bba6 342 * Class: SelfIdPacket
shaunkrnelson 0:cc9f4010bba6 343 * Method: serializePayload
shaunkrnelson 0:cc9f4010bba6 344 * Description: Serialize the data
shaunkrnelson 0:cc9f4010bba6 345 *--------------------------------------------------------------------------------------
shaunkrnelson 0:cc9f4010bba6 346 */
shaunkrnelson 0:cc9f4010bba6 347 virtual int32_t serializePayload(uint8_t *frame, int32_t len);
shaunkrnelson 0:cc9f4010bba6 348
shaunkrnelson 0:cc9f4010bba6 349 };
shaunkrnelson 0:cc9f4010bba6 350
shaunkrnelson 0:cc9f4010bba6 351 #endif // __SENET_PACKET__
shaunkrnelson 0:cc9f4010bba6 352