Senet Packet API
Dependents: MTDOT-UDKDemo_Senet Senet NAMote mDot-IKS01A1 unh-hackathon-example ... more
senet_packet.h@3:b6823438e893, 2016-05-23 (annotated)
- Committer:
- shaunkrnelson
- Date:
- Mon May 23 14:15:27 2016 -0400
- Revision:
- 3:b6823438e893
- Parent:
- 2:9c971be7692b
- Parent:
- 1:3e0cc8ad24f1
- Child:
- 5:1a67bed5b486
- Child:
- 6:17e4e5f99d0c
Merging latest changes from Senet repo to mbed
Who changed what in which revision?
User | Revision | Line number | New 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 |
1:3e0cc8ad24f1 | 59 | /* |
shaunkrnelson |
1:3e0cc8ad24f1 | 60 | *-------------------------------------------------------------------------------------- |
shaunkrnelson |
1:3e0cc8ad24f1 | 61 | * Class: SenetPacket |
shaunkrnelson |
1:3e0cc8ad24f1 | 62 | * Method: deserialize |
shaunkrnelson |
1:3e0cc8ad24f1 | 63 | * Description: Packet deserializer |
shaunkrnelson |
1:3e0cc8ad24f1 | 64 | *-------------------------------------------------------------------------------------- |
shaunkrnelson |
1:3e0cc8ad24f1 | 65 | */ |
shaunkrnelson |
1:3e0cc8ad24f1 | 66 | int32_t deserialize(uint8_t *frame, int32_t len); |
shaunkrnelson |
1:3e0cc8ad24f1 | 67 | |
shaunkrnelson |
0:cc9f4010bba6 | 68 | inline const uint8_t* payload() { return buffer;} |
shaunkrnelson |
0:cc9f4010bba6 | 69 | uint8_t length () { return pktLen; } |
shaunkrnelson |
0:cc9f4010bba6 | 70 | |
shaunkrnelson |
0:cc9f4010bba6 | 71 | protected: |
shaunkrnelson |
0:cc9f4010bba6 | 72 | // Common packet header |
shaunkrnelson |
0:cc9f4010bba6 | 73 | struct PacketHeader |
shaunkrnelson |
0:cc9f4010bba6 | 74 | { |
shaunkrnelson |
0:cc9f4010bba6 | 75 | static const uint8_t HEADER_SIZE = 2; |
shaunkrnelson |
0:cc9f4010bba6 | 76 | |
shaunkrnelson |
0:cc9f4010bba6 | 77 | uint8_t version; // packet format versioni |
shaunkrnelson |
0:cc9f4010bba6 | 78 | uint8_t type; // Senet packet type |
shaunkrnelson |
0:cc9f4010bba6 | 79 | |
shaunkrnelson |
0:cc9f4010bba6 | 80 | PacketHeader(uint8_t _type=0) |
shaunkrnelson |
0:cc9f4010bba6 | 81 | { |
shaunkrnelson |
0:cc9f4010bba6 | 82 | version = VERSION; |
shaunkrnelson |
0:cc9f4010bba6 | 83 | type = _type; |
shaunkrnelson |
0:cc9f4010bba6 | 84 | } |
shaunkrnelson |
0:cc9f4010bba6 | 85 | |
shaunkrnelson |
0:cc9f4010bba6 | 86 | int32_t serialize (uint8_t *frame, int32_t len); |
shaunkrnelson |
1:3e0cc8ad24f1 | 87 | int32_t deserialize(uint8_t *frame, int32_t len); |
shaunkrnelson |
0:cc9f4010bba6 | 88 | } header; |
shaunkrnelson |
0:cc9f4010bba6 | 89 | |
shaunkrnelson |
0:cc9f4010bba6 | 90 | uint8_t pktLen; |
shaunkrnelson |
0:cc9f4010bba6 | 91 | uint8_t *buffer; |
shaunkrnelson |
0:cc9f4010bba6 | 92 | uint8_t bufferLen; |
shaunkrnelson |
0:cc9f4010bba6 | 93 | bool ownBuffer; |
shaunkrnelson |
0:cc9f4010bba6 | 94 | |
shaunkrnelson |
0:cc9f4010bba6 | 95 | SenetPacket(uint8_t senetPktType, uint8_t *_buffer=NULL, uint8_t _buflen=0); |
shaunkrnelson |
0:cc9f4010bba6 | 96 | ~SenetPacket(); |
shaunkrnelson |
0:cc9f4010bba6 | 97 | |
shaunkrnelson |
0:cc9f4010bba6 | 98 | /* |
shaunkrnelson |
0:cc9f4010bba6 | 99 | *-------------------------------------------------------------------------------------- |
shaunkrnelson |
0:cc9f4010bba6 | 100 | * Class: SenetPacket |
shaunkrnelson |
0:cc9f4010bba6 | 101 | * Method: serializePayload |
shaunkrnelson |
0:cc9f4010bba6 | 102 | * Description: Each unique packet type implements this to serialize its payload |
shaunkrnelson |
0:cc9f4010bba6 | 103 | *-------------------------------------------------------------------------------------- |
shaunkrnelson |
0:cc9f4010bba6 | 104 | */ |
shaunkrnelson |
0:cc9f4010bba6 | 105 | virtual int32_t serializePayload(uint8_t *frame, int32_t len) = 0; |
shaunkrnelson |
0:cc9f4010bba6 | 106 | |
shaunkrnelson |
1:3e0cc8ad24f1 | 107 | /* |
shaunkrnelson |
1:3e0cc8ad24f1 | 108 | *-------------------------------------------------------------------------------------- |
shaunkrnelson |
1:3e0cc8ad24f1 | 109 | * Class: SenetPacket |
shaunkrnelson |
1:3e0cc8ad24f1 | 110 | * Method: deserializePayload |
shaunkrnelson |
1:3e0cc8ad24f1 | 111 | * Description: Derived packet types can implement this to deserialize |
shaunkrnelson |
1:3e0cc8ad24f1 | 112 | *-------------------------------------------------------------------------------------- |
shaunkrnelson |
1:3e0cc8ad24f1 | 113 | */ |
shaunkrnelson |
1:3e0cc8ad24f1 | 114 | virtual int32_t deserializePayload(uint8_t *frame, int32_t len) {return 0;} |
shaunkrnelson |
1:3e0cc8ad24f1 | 115 | |
shaunkrnelson |
0:cc9f4010bba6 | 116 | }; |
shaunkrnelson |
0:cc9f4010bba6 | 117 | |
shaunkrnelson |
0:cc9f4010bba6 | 118 | |
shaunkrnelson |
0:cc9f4010bba6 | 119 | /* |
shaunkrnelson |
0:cc9f4010bba6 | 120 | * ===================================================================================== |
shaunkrnelson |
0:cc9f4010bba6 | 121 | * Class: BootInfoPacket |
shaunkrnelson |
0:cc9f4010bba6 | 122 | * Description: Device Boot information packet |
shaunkrnelson |
0:cc9f4010bba6 | 123 | * ===================================================================================== |
shaunkrnelson |
0:cc9f4010bba6 | 124 | */ |
shaunkrnelson |
0:cc9f4010bba6 | 125 | struct BootInfoPacket : public SenetPacket |
shaunkrnelson |
0:cc9f4010bba6 | 126 | { |
shaunkrnelson |
2:9c971be7692b | 127 | static const uint8_t BOOT_PAYLOAD_LENGTH = 9; |
shaunkrnelson |
0:cc9f4010bba6 | 128 | |
shaunkrnelson |
0:cc9f4010bba6 | 129 | uint16_t bootCount; // number of device boots |
shaunkrnelson |
0:cc9f4010bba6 | 130 | uint16_t resetCount; // number of device resets |
shaunkrnelson |
0:cc9f4010bba6 | 131 | uint32_t lastBootReason; // last boot reason |
shaunkrnelson |
2:9c971be7692b | 132 | uint8_t authKey; |
shaunkrnelson |
0:cc9f4010bba6 | 133 | |
shaunkrnelson |
0:cc9f4010bba6 | 134 | BootInfoPacket(uint8_t *_buffer=NULL, uint8_t _buflen=0) : |
shaunkrnelson |
0:cc9f4010bba6 | 135 | SenetPacket(BOOT_INFO_PACKET, _buffer, _buflen) |
shaunkrnelson |
0:cc9f4010bba6 | 136 | { |
shaunkrnelson |
0:cc9f4010bba6 | 137 | bootCount = 0; |
shaunkrnelson |
0:cc9f4010bba6 | 138 | resetCount = 0; |
shaunkrnelson |
0:cc9f4010bba6 | 139 | lastBootReason = 0; |
shaunkrnelson |
2:9c971be7692b | 140 | authKey = 0; |
shaunkrnelson |
0:cc9f4010bba6 | 141 | } |
shaunkrnelson |
0:cc9f4010bba6 | 142 | |
shaunkrnelson |
0:cc9f4010bba6 | 143 | protected: |
shaunkrnelson |
0:cc9f4010bba6 | 144 | /* |
shaunkrnelson |
0:cc9f4010bba6 | 145 | *-------------------------------------------------------------------------------------- |
shaunkrnelson |
0:cc9f4010bba6 | 146 | * Class: BootInfoPacket |
shaunkrnelson |
0:cc9f4010bba6 | 147 | * Method: serializePayload |
shaunkrnelson |
0:cc9f4010bba6 | 148 | * Description: Serialize packet data |
shaunkrnelson |
0:cc9f4010bba6 | 149 | *-------------------------------------------------------------------------------------- |
shaunkrnelson |
0:cc9f4010bba6 | 150 | */ |
shaunkrnelson |
0:cc9f4010bba6 | 151 | virtual int32_t serializePayload(uint8_t *frame, int32_t len); |
shaunkrnelson |
2:9c971be7692b | 152 | |
shaunkrnelson |
2:9c971be7692b | 153 | /* |
shaunkrnelson |
2:9c971be7692b | 154 | *-------------------------------------------------------------------------------------- |
shaunkrnelson |
2:9c971be7692b | 155 | * Class: BootInfoPacket |
shaunkrnelson |
2:9c971be7692b | 156 | * Method: deserializePayload |
shaunkrnelson |
2:9c971be7692b | 157 | * Description: Deserialize packet data |
shaunkrnelson |
2:9c971be7692b | 158 | *-------------------------------------------------------------------------------------- |
shaunkrnelson |
2:9c971be7692b | 159 | */ |
shaunkrnelson |
2:9c971be7692b | 160 | virtual int32_t deserializePayload(uint8_t *frame, int32_t len); |
shaunkrnelson |
0:cc9f4010bba6 | 161 | }; |
shaunkrnelson |
0:cc9f4010bba6 | 162 | |
shaunkrnelson |
0:cc9f4010bba6 | 163 | |
shaunkrnelson |
0:cc9f4010bba6 | 164 | /* |
shaunkrnelson |
0:cc9f4010bba6 | 165 | * ===================================================================================== |
shaunkrnelson |
2:9c971be7692b | 166 | * Class: ConfigWordPacket |
shaunkrnelson |
0:cc9f4010bba6 | 167 | * Description: Packet to configure device |
shaunkrnelson |
0:cc9f4010bba6 | 168 | * ===================================================================================== |
shaunkrnelson |
0:cc9f4010bba6 | 169 | */ |
shaunkrnelson |
0:cc9f4010bba6 | 170 | struct ConfigWordPacket : public SenetPacket |
shaunkrnelson |
0:cc9f4010bba6 | 171 | { |
shaunkrnelson |
0:cc9f4010bba6 | 172 | static const uint8_t CONTROL_PAYLOAD_LENGTH = 9; |
shaunkrnelson |
0:cc9f4010bba6 | 173 | |
shaunkrnelson |
0:cc9f4010bba6 | 174 | ConfigWordPacket(uint8_t *_buffer=NULL, uint8_t _buflen=0) : |
shaunkrnelson |
0:cc9f4010bba6 | 175 | SenetPacket(CONTROL_PACKET, _buffer, _buflen) { config = 0; mask = 0; authKey = 0; } |
shaunkrnelson |
0:cc9f4010bba6 | 176 | |
shaunkrnelson |
0:cc9f4010bba6 | 177 | uint32_t config; // configuration word |
shaunkrnelson |
0:cc9f4010bba6 | 178 | uint32_t mask; // valid bit mask applied to configuration word |
shaunkrnelson |
0:cc9f4010bba6 | 179 | uint8_t authKey; // Downlink authentication key |
shaunkrnelson |
0:cc9f4010bba6 | 180 | |
shaunkrnelson |
0:cc9f4010bba6 | 181 | /* |
shaunkrnelson |
0:cc9f4010bba6 | 182 | *-------------------------------------------------------------------------------------- |
shaunkrnelson |
0:cc9f4010bba6 | 183 | * Class: ConfigWordPacket |
shaunkrnelson |
0:cc9f4010bba6 | 184 | * Method: serializePayload |
shaunkrnelson |
0:cc9f4010bba6 | 185 | * Description: Serialize packet data |
shaunkrnelson |
0:cc9f4010bba6 | 186 | *-------------------------------------------------------------------------------------- |
shaunkrnelson |
0:cc9f4010bba6 | 187 | */ |
shaunkrnelson |
0:cc9f4010bba6 | 188 | virtual int32_t serializePayload(uint8_t *frame, int32_t len); |
shaunkrnelson |
1:3e0cc8ad24f1 | 189 | |
shaunkrnelson |
1:3e0cc8ad24f1 | 190 | /* |
shaunkrnelson |
1:3e0cc8ad24f1 | 191 | *-------------------------------------------------------------------------------------- |
shaunkrnelson |
1:3e0cc8ad24f1 | 192 | * Class: ConfigWordPacket |
shaunkrnelson |
1:3e0cc8ad24f1 | 193 | * Method: deserializePayload |
shaunkrnelson |
1:3e0cc8ad24f1 | 194 | * Description: Deserialize packet data |
shaunkrnelson |
1:3e0cc8ad24f1 | 195 | *-------------------------------------------------------------------------------------- |
shaunkrnelson |
1:3e0cc8ad24f1 | 196 | */ |
shaunkrnelson |
1:3e0cc8ad24f1 | 197 | virtual int32_t deserializePayload(uint8_t *frame, int32_t len); |
shaunkrnelson |
0:cc9f4010bba6 | 198 | }; |
shaunkrnelson |
0:cc9f4010bba6 | 199 | |
shaunkrnelson |
0:cc9f4010bba6 | 200 | |
shaunkrnelson |
0:cc9f4010bba6 | 201 | /* |
shaunkrnelson |
0:cc9f4010bba6 | 202 | * ===================================================================================== |
shaunkrnelson |
0:cc9f4010bba6 | 203 | * Class: GpsPacket |
shaunkrnelson |
0:cc9f4010bba6 | 204 | * Description: Transmit device location in Decimal degress (http://www.en.wikipedia.org/wiki/Decimal_degrees) |
shaunkrnelson |
0:cc9f4010bba6 | 205 | * ===================================================================================== |
shaunkrnelson |
0:cc9f4010bba6 | 206 | */ |
shaunkrnelson |
0:cc9f4010bba6 | 207 | struct GpsPacket : public SenetPacket |
shaunkrnelson |
0:cc9f4010bba6 | 208 | { |
shaunkrnelson |
0:cc9f4010bba6 | 209 | static const uint8_t GPS_PAYLOAD_LENGTH = 9; |
shaunkrnelson |
0:cc9f4010bba6 | 210 | |
shaunkrnelson |
1:3e0cc8ad24f1 | 211 | bool setCoordinates(int32_t latitude, int32_t longitude, uint16_t elevation); |
shaunkrnelson |
0:cc9f4010bba6 | 212 | inline void setTxPower(uint8_t dBm) { txPower = dBm; } |
shaunkrnelson |
0:cc9f4010bba6 | 213 | |
shaunkrnelson |
0:cc9f4010bba6 | 214 | |
shaunkrnelson |
0:cc9f4010bba6 | 215 | GpsPacket(uint8_t* _buffer=NULL, uint8_t _buflen=0): |
shaunkrnelson |
0:cc9f4010bba6 | 216 | SenetPacket(GPS_PACKET, _buffer, _buflen) |
shaunkrnelson |
0:cc9f4010bba6 | 217 | { |
shaunkrnelson |
0:cc9f4010bba6 | 218 | latitude = 0; |
shaunkrnelson |
0:cc9f4010bba6 | 219 | longitude = 0; |
shaunkrnelson |
0:cc9f4010bba6 | 220 | elevation = 0; |
shaunkrnelson |
0:cc9f4010bba6 | 221 | txPower = 0; |
shaunkrnelson |
0:cc9f4010bba6 | 222 | } |
shaunkrnelson |
0:cc9f4010bba6 | 223 | |
shaunkrnelson |
0:cc9f4010bba6 | 224 | protected: |
shaunkrnelson |
0:cc9f4010bba6 | 225 | uint32_t latitude; |
shaunkrnelson |
0:cc9f4010bba6 | 226 | uint32_t longitude; |
shaunkrnelson |
0:cc9f4010bba6 | 227 | uint16_t elevation; |
shaunkrnelson |
0:cc9f4010bba6 | 228 | uint8_t txPower; |
shaunkrnelson |
0:cc9f4010bba6 | 229 | |
shaunkrnelson |
0:cc9f4010bba6 | 230 | /* |
shaunkrnelson |
0:cc9f4010bba6 | 231 | *-------------------------------------------------------------------------------------- |
shaunkrnelson |
0:cc9f4010bba6 | 232 | * Class: GpsPacket |
shaunkrnelson |
0:cc9f4010bba6 | 233 | * Method: serializePayload |
shaunkrnelson |
0:cc9f4010bba6 | 234 | * Description: Serialize the data |
shaunkrnelson |
0:cc9f4010bba6 | 235 | *-------------------------------------------------------------------------------------- |
shaunkrnelson |
0:cc9f4010bba6 | 236 | */ |
shaunkrnelson |
0:cc9f4010bba6 | 237 | virtual int32_t serializePayload(uint8_t *frame, int32_t len); |
shaunkrnelson |
0:cc9f4010bba6 | 238 | }; |
shaunkrnelson |
0:cc9f4010bba6 | 239 | |
shaunkrnelson |
0:cc9f4010bba6 | 240 | |
shaunkrnelson |
0:cc9f4010bba6 | 241 | /* |
shaunkrnelson |
0:cc9f4010bba6 | 242 | * ===================================================================================== |
shaunkrnelson |
0:cc9f4010bba6 | 243 | * Class: OctetStringPacket |
shaunkrnelson |
0:cc9f4010bba6 | 244 | * Description: Variable length Octet String packet |
shaunkrnelson |
0:cc9f4010bba6 | 245 | * ===================================================================================== |
shaunkrnelson |
0:cc9f4010bba6 | 246 | */ |
shaunkrnelson |
0:cc9f4010bba6 | 247 | struct OctetStringPacket : public SenetPacket |
shaunkrnelson |
0:cc9f4010bba6 | 248 | { |
shaunkrnelson |
0:cc9f4010bba6 | 249 | bool setOctetString(uint8_t *os, uint8_t len); |
shaunkrnelson |
0:cc9f4010bba6 | 250 | |
shaunkrnelson |
0:cc9f4010bba6 | 251 | OctetStringPacket(uint8_t size); |
shaunkrnelson |
0:cc9f4010bba6 | 252 | |
shaunkrnelson |
0:cc9f4010bba6 | 253 | protected: |
shaunkrnelson |
0:cc9f4010bba6 | 254 | uint8_t oslen; |
shaunkrnelson |
0:cc9f4010bba6 | 255 | uint8_t max; |
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 | * Class: RFDataPacket |
shaunkrnelson |
0:cc9f4010bba6 | 263 | * Description: Radio Data packet |
shaunkrnelson |
0:cc9f4010bba6 | 264 | * ===================================================================================== |
shaunkrnelson |
0:cc9f4010bba6 | 265 | */ |
shaunkrnelson |
0:cc9f4010bba6 | 266 | struct RFDataPacket : public SenetPacket |
shaunkrnelson |
0:cc9f4010bba6 | 267 | { |
shaunkrnelson |
2:9c971be7692b | 268 | static const uint8_t RFDATA_PAYLOAD_LEN = 9; |
shaunkrnelson |
0:cc9f4010bba6 | 269 | |
shaunkrnelson |
0:cc9f4010bba6 | 270 | uint8_t channel; // The channel the device sent on |
shaunkrnelson |
0:cc9f4010bba6 | 271 | uint8_t txpower; // The transmit power in dBm used by the device |
shaunkrnelson |
0:cc9f4010bba6 | 272 | uint8_t datarate; // The datarate used by the device |
shaunkrnelson |
0:cc9f4010bba6 | 273 | uint8_t snr; // Signal to Noise ratio of the last frame received |
shaunkrnelson |
0:cc9f4010bba6 | 274 | uint8_t rssi; // RSSI of the last frame received |
shaunkrnelson |
0:cc9f4010bba6 | 275 | uint32_t timestamp; // The device's current timestamp |
shaunkrnelson |
0:cc9f4010bba6 | 276 | |
shaunkrnelson |
0:cc9f4010bba6 | 277 | RFDataPacket(uint8_t *_buffer=NULL, uint8_t _buflen=0): |
shaunkrnelson |
0:cc9f4010bba6 | 278 | SenetPacket(RF_PACKET, _buffer, _buflen) |
shaunkrnelson |
0:cc9f4010bba6 | 279 | { |
shaunkrnelson |
0:cc9f4010bba6 | 280 | channel = 0; |
shaunkrnelson |
0:cc9f4010bba6 | 281 | txpower = 0; |
shaunkrnelson |
0:cc9f4010bba6 | 282 | datarate = 0; |
shaunkrnelson |
0:cc9f4010bba6 | 283 | snr = 0; |
shaunkrnelson |
0:cc9f4010bba6 | 284 | rssi = 0; |
shaunkrnelson |
0:cc9f4010bba6 | 285 | timestamp = 0; |
shaunkrnelson |
0:cc9f4010bba6 | 286 | } |
shaunkrnelson |
0:cc9f4010bba6 | 287 | |
shaunkrnelson |
0:cc9f4010bba6 | 288 | /* |
shaunkrnelson |
0:cc9f4010bba6 | 289 | *-------------------------------------------------------------------------------------- |
shaunkrnelson |
0:cc9f4010bba6 | 290 | * Class: RFDataPacket |
shaunkrnelson |
0:cc9f4010bba6 | 291 | * Method: serializePayload |
shaunkrnelson |
0:cc9f4010bba6 | 292 | * Description: Serialize the data |
shaunkrnelson |
0:cc9f4010bba6 | 293 | *-------------------------------------------------------------------------------------- |
shaunkrnelson |
0:cc9f4010bba6 | 294 | */ |
shaunkrnelson |
0:cc9f4010bba6 | 295 | virtual int32_t serializePayload(uint8_t *frame, int32_t len); |
shaunkrnelson |
0:cc9f4010bba6 | 296 | }; |
shaunkrnelson |
0:cc9f4010bba6 | 297 | |
shaunkrnelson |
0:cc9f4010bba6 | 298 | |
shaunkrnelson |
0:cc9f4010bba6 | 299 | /* |
shaunkrnelson |
0:cc9f4010bba6 | 300 | * ===================================================================================== |
shaunkrnelson |
0:cc9f4010bba6 | 301 | * Class: SelfIdPacket |
shaunkrnelson |
0:cc9f4010bba6 | 302 | * Description: |
shaunkrnelson |
0:cc9f4010bba6 | 303 | * ===================================================================================== |
shaunkrnelson |
0:cc9f4010bba6 | 304 | */ |
shaunkrnelson |
0:cc9f4010bba6 | 305 | struct SelfIdPacket : public SenetPacket |
shaunkrnelson |
0:cc9f4010bba6 | 306 | { |
shaunkrnelson |
0:cc9f4010bba6 | 307 | const static uint8_t EXT_POWER_SUPPLY_ID_MAX = 2; |
shaunkrnelson |
0:cc9f4010bba6 | 308 | const static uint8_t EXT_POWER_SUPPLY_1 = 1; |
shaunkrnelson |
0:cc9f4010bba6 | 309 | const static uint8_t EXT_POWER_SUPPLY_2 = 2; |
shaunkrnelson |
0:cc9f4010bba6 | 310 | const static uint8_t BATTERY_LEVEL_MAX = 7; |
shaunkrnelson |
2:9c971be7692b | 311 | const static uint8_t SELFID_PAYLOAD_LEN = 9; |
shaunkrnelson |
0:cc9f4010bba6 | 312 | |
shaunkrnelson |
0:cc9f4010bba6 | 313 | bool setDeviceType (uint32_t model, uint8_t revision); |
shaunkrnelson |
0:cc9f4010bba6 | 314 | bool setSwVersion (uint8_t major, uint8_t minor, uint8_t point, uint16_t build, uint8_t developer); |
shaunkrnelson |
0:cc9f4010bba6 | 315 | void setBatteryFailState (bool failed); |
shaunkrnelson |
0:cc9f4010bba6 | 316 | bool setBatteryLevel (uint8_t level); |
shaunkrnelson |
0:cc9f4010bba6 | 317 | bool setExtPowerSupplyState (uint8_t id, bool isPresent); |
shaunkrnelson |
0:cc9f4010bba6 | 318 | |
shaunkrnelson |
0:cc9f4010bba6 | 319 | SelfIdPacket(uint8_t *_buffer=NULL, uint8_t _buflen=0) : |
shaunkrnelson |
0:cc9f4010bba6 | 320 | SenetPacket(SELF_ID_PACKET, _buffer, _buflen) { deviceType = 0; swVersion = 0; powerMask = 0; } |
shaunkrnelson |
0:cc9f4010bba6 | 321 | |
shaunkrnelson |
0:cc9f4010bba6 | 322 | protected: |
shaunkrnelson |
0:cc9f4010bba6 | 323 | uint32_t deviceType; |
shaunkrnelson |
0:cc9f4010bba6 | 324 | uint32_t swVersion; |
shaunkrnelson |
0:cc9f4010bba6 | 325 | uint8_t powerMask; |
shaunkrnelson |
0:cc9f4010bba6 | 326 | |
shaunkrnelson |
0:cc9f4010bba6 | 327 | /* |
shaunkrnelson |
0:cc9f4010bba6 | 328 | *-------------------------------------------------------------------------------------- |
shaunkrnelson |
0:cc9f4010bba6 | 329 | * Class: SelfIdPacket |
shaunkrnelson |
0:cc9f4010bba6 | 330 | * Method: serializePayload |
shaunkrnelson |
0:cc9f4010bba6 | 331 | * Description: Serialize the data |
shaunkrnelson |
0:cc9f4010bba6 | 332 | *-------------------------------------------------------------------------------------- |
shaunkrnelson |
0:cc9f4010bba6 | 333 | */ |
shaunkrnelson |
0:cc9f4010bba6 | 334 | virtual int32_t serializePayload(uint8_t *frame, int32_t len); |
shaunkrnelson |
0:cc9f4010bba6 | 335 | }; |
shaunkrnelson |
0:cc9f4010bba6 | 336 | |
shaunkrnelson |
0:cc9f4010bba6 | 337 | |
shaunkrnelson |
0:cc9f4010bba6 | 338 | /* |
shaunkrnelson |
0:cc9f4010bba6 | 339 | * ===================================================================================== |
shaunkrnelson |
0:cc9f4010bba6 | 340 | * Class: SensorPacket |
shaunkrnelson |
0:cc9f4010bba6 | 341 | * Description: |
shaunkrnelson |
0:cc9f4010bba6 | 342 | * ===================================================================================== |
shaunkrnelson |
0:cc9f4010bba6 | 343 | */ |
shaunkrnelson |
0:cc9f4010bba6 | 344 | struct SensorPacket : public SenetPacket |
shaunkrnelson |
0:cc9f4010bba6 | 345 | { |
shaunkrnelson |
0:cc9f4010bba6 | 346 | bool setPrimarySensor(uint16_t value) { return addSensorValue(0,1, value);}; |
shaunkrnelson |
0:cc9f4010bba6 | 347 | bool setTemperature (uint16_t value) { return addSensorValue(1,2, value);} |
shaunkrnelson |
0:cc9f4010bba6 | 348 | void reset(); |
shaunkrnelson |
0:cc9f4010bba6 | 349 | |
shaunkrnelson |
0:cc9f4010bba6 | 350 | SensorPacket(uint8_t *_buffer=NULL, uint8_t _buflen=0) : |
shaunkrnelson |
0:cc9f4010bba6 | 351 | SenetPacket(SENSOR_PACKET, _buffer, _buflen) {} |
shaunkrnelson |
0:cc9f4010bba6 | 352 | |
shaunkrnelson |
0:cc9f4010bba6 | 353 | protected: |
shaunkrnelson |
0:cc9f4010bba6 | 354 | static const uint8_t MAX_SENSOR_VALUES = 2; |
shaunkrnelson |
0:cc9f4010bba6 | 355 | |
shaunkrnelson |
0:cc9f4010bba6 | 356 | struct SensorValue |
shaunkrnelson |
0:cc9f4010bba6 | 357 | { |
shaunkrnelson |
0:cc9f4010bba6 | 358 | uint8_t type; |
shaunkrnelson |
0:cc9f4010bba6 | 359 | uint16_t value; |
shaunkrnelson |
0:cc9f4010bba6 | 360 | bool isSet; |
shaunkrnelson |
0:cc9f4010bba6 | 361 | |
shaunkrnelson |
0:cc9f4010bba6 | 362 | SensorValue() { type = 0; value = 0; isSet = false;} |
shaunkrnelson |
0:cc9f4010bba6 | 363 | |
shaunkrnelson |
0:cc9f4010bba6 | 364 | int32_t serialize(uint8_t *frame, int32_t len) |
shaunkrnelson |
0:cc9f4010bba6 | 365 | { |
shaunkrnelson |
0:cc9f4010bba6 | 366 | if(len < 3) |
shaunkrnelson |
0:cc9f4010bba6 | 367 | return -1; |
shaunkrnelson |
0:cc9f4010bba6 | 368 | |
shaunkrnelson |
0:cc9f4010bba6 | 369 | frame[0] = type; |
shaunkrnelson |
0:cc9f4010bba6 | 370 | frame[1] = (value >> 8) & 0xff; |
shaunkrnelson |
0:cc9f4010bba6 | 371 | frame[2] = value & 0xff; |
shaunkrnelson |
0:cc9f4010bba6 | 372 | return 3; |
shaunkrnelson |
0:cc9f4010bba6 | 373 | } |
shaunkrnelson |
0:cc9f4010bba6 | 374 | } sensorValue[MAX_SENSOR_VALUES]; |
shaunkrnelson |
0:cc9f4010bba6 | 375 | |
shaunkrnelson |
0:cc9f4010bba6 | 376 | bool addSensorValue(uint8_t position, uint8_t type, uint16_t value); |
shaunkrnelson |
0:cc9f4010bba6 | 377 | |
shaunkrnelson |
0:cc9f4010bba6 | 378 | /* |
shaunkrnelson |
0:cc9f4010bba6 | 379 | *-------------------------------------------------------------------------------------- |
shaunkrnelson |
0:cc9f4010bba6 | 380 | * Class: SelfIdPacket |
shaunkrnelson |
0:cc9f4010bba6 | 381 | * Method: serializePayload |
shaunkrnelson |
0:cc9f4010bba6 | 382 | * Description: Serialize the data |
shaunkrnelson |
0:cc9f4010bba6 | 383 | *-------------------------------------------------------------------------------------- |
shaunkrnelson |
0:cc9f4010bba6 | 384 | */ |
shaunkrnelson |
0:cc9f4010bba6 | 385 | virtual int32_t serializePayload(uint8_t *frame, int32_t len); |
shaunkrnelson |
0:cc9f4010bba6 | 386 | |
shaunkrnelson |
0:cc9f4010bba6 | 387 | }; |
shaunkrnelson |
0:cc9f4010bba6 | 388 | |
shaunkrnelson |
0:cc9f4010bba6 | 389 | #endif // __SENET_PACKET__ |
shaunkrnelson |
0:cc9f4010bba6 | 390 |