Reading SenseAir LP8 CO2 sensor over bluetooth low energy

Dependencies:   BLE_API mbed nRF51822

Revision:
3:933dd59ad44d
Parent:
2:d02255d8c36f
diff -r d02255d8c36f -r 933dd59ad44d LP8_Service.h
--- a/LP8_Service.h	Mon Aug 14 20:52:48 2017 +0000
+++ b/LP8_Service.h	Fri Aug 18 18:20:41 2017 +0000
@@ -8,29 +8,36 @@
 public:
 
     //UUID descriptors
-    const static uint16_t LP8_SERVICE_UUID                      = 0xA000;           // 
+    const static uint16_t LP8_SERVICE_UUID                      = 0xA000;           // service identifier
     const static uint16_t LP8_STATE_CHARACTERISTIC_UUID         = 0xA001;           // CO2 concentration characteristic
     const static uint16_t LP8_READ_TEMP_UUID                    = 0x2A1F;           // temp (Celsius) characteristic
     const static uint16_t LP8_VCAP_UUID                         = 0xA010;           // Vcap characteristic (mV)
-    const static uint16_t LP8_ERROR_UUID                        = 0xA011;           // LP8 Error bits characteristic
-    
+    const static uint16_t LP8_ERROR_UUID                        = 0xA011;           // LP8 Error bits characteristic  
     const static uint16_t LP8_WRITE_UUID                        = 0xA002;           // Write calculation control from app to lp8
     const static uint16_t LP8_WRITTEN_UUID                      = 0xB001;           // display what was written into lp8 calculation control
     
+    const static uint16_t LP8_reWrite_uuid                      = 0xB111;
     
-    //constructor setup for Gatt Service
-    LP8_Service(BLE &_ble, int co2ValueInitial, double tempValueInitial, 
-                int initialVcap, uint32_t initialError, uint8_t initCC):  /* Pass variables to ble stack  */
+    
+//constructor setup for Gatt Service
+    LP8_Service(BLE         &_ble,                                                  /* Pass variables to characteristics and ble  */
+                int         co2ValueInitial, 
+                float       tempValueInitial, 
+                int         initialVcap, 
+                uint32_t    initialError, 
+                uint8_t     initCC, 
+                uint8_t     initSentCC):                                            
         ble(_ble), 
         lp8State(LP8_STATE_CHARACTERISTIC_UUID, &co2ValueInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
         lp8Temp(LP8_READ_TEMP_UUID, &tempValueInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
         lp8Vcap(LP8_VCAP_UUID, &initialVcap, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
         lp8Error(LP8_ERROR_UUID, &initialError, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
         lp8WriteCC(LP8_WRITE_UUID, &initCC),
-        lp8Written(LP8_WRITTEN_UUID, &initCC, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
+        lp8Written(LP8_WRITTEN_UUID, &initSentCC, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
+        lp8reWriteCC(LP8_reWrite_uuid, &initCC, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
         {
             //characterisitics 
-            GattCharacteristic *charTable[] = {&lp8State, &lp8Temp, &lp8Vcap, &lp8Error, &lp8WriteCC, &lp8Written };
+            GattCharacteristic *charTable[] = {&lp8State, &lp8Temp, &lp8Vcap, &lp8Error, &lp8WriteCC, &lp8Written, &lp8reWriteCC };
              
             //Service, Setup for LP8 GattService
             GattService        lp8Service(LP8_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));       
@@ -46,7 +53,7 @@
         ble.gattServer().write(lp8State.getValueAttribute().getHandle(),(uint8_t *) &co2Value, sizeof(co2Value));   
     };
 
-    void updateTempValue(double tempValue)
+    void updateTempValue(float tempValue)
     {
         ble.gattServer().write(lp8Temp.getValueAttribute().getHandle(),(uint8_t *) &tempValue, sizeof(tempValue));              
     };
@@ -61,11 +68,16 @@
         ble.gattServer().write(lp8Error.getValueAttribute().getHandle(),(uint8_t *) &lp8ErrorValue, sizeof(lp8ErrorValue));                        
     };
 
-//reWrite written data     
+//     
     void updateDataWritten(uint8_t lp8WrittenValue)
     {
         ble.gattServer().write(lp8Written.getValueAttribute().getHandle(),(uint8_t *) &lp8WrittenValue, sizeof(lp8WrittenValue));
     }
+    
+    void updateReWrite ( uint8_t lp8ReWrite )
+    {
+        ble.gattServer().write(lp8reWriteCC.getValueAttribute().getHandle(),(uint8_t *) &lp8ReWrite, sizeof(lp8ReWrite));    
+    }
 
 
 private:
@@ -73,14 +85,19 @@
     BLE                                     &ble;       //
     
     //Service Characteristics
-    //Read Values
+    
+    //Read sensor values
     ReadOnlyGattCharacteristic<int>         lp8State;   //
-    ReadOnlyGattCharacteristic<double>      lp8Temp;
+    ReadOnlyGattCharacteristic<float>       lp8Temp;
     ReadOnlyGattCharacteristic<int>         lp8Vcap;
     ReadOnlyGattCharacteristic<uint32_t>    lp8Error;
+    
+    //Write Value
+    WriteOnlyGattCharacteristic<uint8_t>    lp8WriteCC;
+    
+    //read back written and cc byte(flag)
     ReadOnlyGattCharacteristic<uint8_t>     lp8Written;
-    //Write Values
-    WriteOnlyGattCharacteristic<uint8_t>    lp8WriteCC;
+    ReadOnlyGattCharacteristic<uint8_t>     lp8reWriteCC;
     
 
 };