Senet Packet API

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

Files at this revision

API Documentation at this revision

Comitter:
dkjendal
Date:
Tue Aug 23 16:01:03 2016 +0000
Parent:
4:7d43feca0e3d
Commit message:
Add SensorPacket deserialization routines

Changed in this revision

senet_packet.cpp Show annotated file Show diff for this revision Revisions of this file
senet_packet.h Show annotated file Show diff for this revision Revisions of this file
--- a/senet_packet.cpp	Thu Aug 11 12:48:46 2016 +0000
+++ b/senet_packet.cpp	Tue Aug 23 16:01:03 2016 +0000
@@ -156,7 +156,21 @@
     }
     return bytes; 
 }
-
+int32_t SensorPacket::deserializePayload(uint8_t *frame, int32_t len) 
+{
+    int32_t num_sensors = 0;
+    for(int i = 0;i < MAX_SENSOR_VALUES;i++)
+    {
+        if(len < 3)
+            break;
+        sensorValue[i].type = frame[i*3+0];
+        sensorValue[i].value= (frame[i*3+1]<<8)|frame[i*3+2];
+        sensorValue[i].isSet= true;
+        len-=3;
+        num_sensors++;
+    }
+    return(num_sensors);
+}
 bool SelfIdPacket::setDeviceType(uint32_t model, uint8_t revision)
 {
     if((model & 0x00FFFFFF) != model)
--- a/senet_packet.h	Thu Aug 11 12:48:46 2016 +0000
+++ b/senet_packet.h	Tue Aug 23 16:01:03 2016 +0000
@@ -343,15 +343,16 @@
  */
 struct SensorPacket : public SenetPacket
 {
-    bool setPrimarySensor(uint16_t value) { return addSensorValue(0,1, value);};
+    bool setPrimarySensor(uint16_t value) { return addSensorValue(0,1, value);}
     bool setTemperature  (uint16_t value) { return addSensorValue(1,2, value);}
+    bool setPressure     (uint16_t value) { return addSensorValue(2,3, value);}
     void reset();
 
     SensorPacket(uint8_t *_buffer=NULL, uint8_t _buflen=0) :
         SenetPacket(SENSOR_PACKET, _buffer, _buflen) {}
 
-    protected:
-    static const uint8_t MAX_SENSOR_VALUES = 2;
+    public:
+    static const uint8_t MAX_SENSOR_VALUES = 3;
 
     struct SensorValue
     {
@@ -373,16 +374,10 @@
         }
     } sensorValue[MAX_SENSOR_VALUES];
 
-            bool    addSensorValue(uint8_t position, uint8_t type, uint16_t value);
+    bool    addSensorValue(uint8_t position, uint8_t type, uint16_t value);
 
-    /*
-     *--------------------------------------------------------------------------------------
-     *       Class:  SelfIdPacket 
-     *      Method:  serializePayload
-     * Description:  Serialize the data 
-     *--------------------------------------------------------------------------------------
-     */
     virtual int32_t serializePayload(uint8_t *frame, int32_t len);
+    virtual int32_t deserializePayload(uint8_t *frame, int32_t len);
 
 };