Bluetooth Low Energy for Smart Plug

Dependencies:   BLE_API mbed nRF51822

Revision:
1:e036e77762fa
Parent:
0:25ad6eba7916
Child:
2:6db5c9a2894c
--- a/Services/SmartPlugService.h	Tue Jul 07 04:02:14 2015 +0000
+++ b/Services/SmartPlugService.h	Tue Jul 07 04:58:28 2015 +0000
@@ -43,25 +43,62 @@
     void onDataWritten(const GattWriteCallbackParams *params);
     void update(void* data);    
     void updateData(SmartPlug* data);
+    void updateRelay(Relay* relay);
     void setupService(void);
 private:
+    class RelayValueBytes
+    {
+        public:
+            static const uint8_t MAX_SIZE_BYTES = 3;
+            static const uint8_t STATE_INDEX = 0;
+            static const uint8_t HOUR_TIMER_INDEX = 1;
+            static const uint8_t MINUTE_TIMER_INDEX = 2;
+            
+            RelayValueBytes()
+            {
+                
+            }
+            
+            void updateData(Relay* relay)
+            {
+                data[STATE_INDEX] = relay->getState();
+                data[HOUR_TIMER_INDEX] = relay->getHrCounter();
+                data[MINUTE_TIMER_INDEX] = relay->getMinCounter();
+            }
+            
+            uint8_t* getDataPointer()
+            {
+                return data;
+            }
+            
+            uint8_t getLenBytes()
+            {
+                if(data[HOUR_TIMER_INDEX] == 0 && data[MINUTE_TIMER_INDEX] == 0)
+                    return 1;
+                else
+                    return MAX_SIZE_BYTES;
+            }
+        private:
+            uint8_t data[MAX_SIZE_BYTES];
+    };
+
     BLE ble;
     
-    uint8_t voltage[4];
-    uint8_t current[4];
-    uint8_t power[4];
-    uint8_t powerFactor[4];
-    uint8_t energy[4];
-    uint8_t relayValue[3];
+    unsigned long voltage;
+    unsigned long current;
+    unsigned long power;
+    unsigned long powerFactor;
+    unsigned long energy;
+    RelayValueBytes relayValue;
     //uint8_t updateValue;
     SmartPlugBLE& system;
     
-    ReadOnlyGattCharacteristic<uint8_t> voltageChar;
-    ReadOnlyGattCharacteristic<uint8_t> currentChar;
-    ReadOnlyGattCharacteristic<uint8_t> powerChar;
-    ReadOnlyGattCharacteristic<uint8_t> powerFactorChar;
-    ReadOnlyGattCharacteristic<uint8_t> energyChar;
-    ReadWriteGattCharacteristic<uint8_t> relayChar;
+    ReadOnlyGattCharacteristic<unsigned long> voltageChar;
+    ReadOnlyGattCharacteristic<unsigned long> currentChar;
+    ReadOnlyGattCharacteristic<unsigned long> powerChar;
+    ReadOnlyGattCharacteristic<unsigned long> powerFactorChar;
+    ReadOnlyGattCharacteristic<unsigned long> energyChar;
+    GattCharacteristic relayChar;
     WriteOnlyGattCharacteristic<uint8_t> updateChar;
 };