Senet Packet API

Committer:
shaunkrnelson
Date:
Mon Mar 07 12:08:34 2016 -0500
Revision:
1:c4435fed9eb9
Parent:
0:08689149c8e3
Add buffer parameter to packet constructor
General cleanup

Who changed what in which revision?

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