Senet Packet API

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

Revision:
1:3e0cc8ad24f1
Parent:
0:cc9f4010bba6
Child:
3:b6823438e893
--- a/senet_packet.cpp	Tue Mar 08 09:08:44 2016 -0500
+++ b/senet_packet.cpp	Fri Mar 11 12:19:51 2016 -0500
@@ -23,26 +23,32 @@
 int32_t SenetPacket::
 PacketHeader::serialize(uint8_t *frame, int32_t len)
 {
-    int32_t serializedLen = 0;
+    int32_t serializedLen = -1;
 
     if(len >= PacketHeader::HEADER_SIZE)
     {
-        frame[0] = version;
-        frame[1] = type;
-        serializedLen = PacketHeader::HEADER_SIZE;
+        serializedLen = 0;
+        frame[serializedLen++] = version;
+        frame[serializedLen++] = type;
+
+        ASSERT(serializedLen == PacketHeader::HEADER_SIZE);
     }
 
     return serializedLen;
 }
 
-bool SenetPacket::
+int32_t SenetPacket::
 PacketHeader::deserialize(uint8_t *frame, int32_t len)
 {
     if((frame != NULL) && (len >= PacketHeader::HEADER_SIZE))
     {
-        version = frame[0];
-        type    = frame[1];
-        return true;
+        int32_t offset = 0;
+        version = frame[offset++];
+        type    = frame[offset++];
+
+        ASSERT(offset == PacketHeader::HEADER_SIZE);
+
+        return  PacketHeader::HEADER_SIZE;
     }
     return false;
 }
@@ -103,6 +109,23 @@
     return -1;
 }
 
+int32_t SenetPacket::deserialize(uint8_t *frame, int32_t len)
+{
+    int32_t bytes = 0;
+
+    bytes = header.deserialize(frame, len);
+    if(bytes > 0)
+    {
+        int32_t payloadLen = deserializePayload(frame, len - bytes);
+        if(payloadLen > 0)
+            bytes += payloadLen; 
+        else
+            bytes = payloadLen; 
+
+    }
+    return bytes;
+}
+
 
 bool SensorPacket::addSensorValue(uint8_t position, uint8_t type, uint16_t value)
 {
@@ -247,6 +270,30 @@
 
 }
 
+int32_t ConfigWordPacket::deserializePayload(uint8_t *frame, int32_t len) 
+{
+    if(CONTROL_PAYLOAD_LENGTH <= len)
+    {
+        int32_t offset = 0;
+
+        config  = frame[offset++]<<24; 
+        config |= frame[offset++]<<16; 
+        config |= frame[offset++]<<8; 
+        config |= frame[offset++]; 
+
+        mask  = frame[offset++]<<24; 
+        mask |= frame[offset++]<<16; 
+        mask |= frame[offset++]<<8; 
+        mask |= frame[offset++]; 
+
+        authKey = frame[offset++];
+
+        return offset;
+    }
+    return -1;
+}
+
+
 int32_t BootInfoPacket::serializePayload(uint8_t *frame, int32_t len) 
 {
     int32_t out = -1;
@@ -269,12 +316,8 @@
     return out;
 }
 
-bool GpsPacket::setCoordinates(uint32_t _latitude, uint32_t _longitude, uint16_t _elevation)
+bool GpsPacket::setCoordinates(int32_t _latitude, int32_t _longitude, uint16_t _elevation)
 {
-
-    if(((_latitude & 0x00ffffff) != _latitude) || ((_longitude & 0x00ffffff) != _longitude))
-        return false;
-
     latitude  = _latitude; 
     longitude = _longitude; 
     elevation = _elevation;