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