Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed nRF51822
LP8_Service.h
00001 #ifndef LP8_SERVICE_H 00002 #define LP8_SERVICE_H 00003 00004 /* LP8 Gatt Service Class */ 00005 00006 class LP8_Service 00007 { 00008 public: 00009 00010 //UUID descriptors 00011 const static uint16_t LP8_SERVICE_UUID = 0xA000; // service identifier 00012 const static uint16_t LP8_STATE_CHARACTERISTIC_UUID = 0xA001; // CO2 concentration characteristic 00013 const static uint16_t LP8_READ_TEMP_UUID = 0x2A1F; // temp (Celsius) characteristic 00014 const static uint16_t LP8_VCAP_UUID = 0xA010; // Vcap characteristic (mV) 00015 const static uint16_t LP8_ERROR_UUID = 0xA011; // LP8 Error bits characteristic 00016 const static uint16_t LP8_WRITE_UUID = 0xA002; // Write calculation control from app to lp8 00017 const static uint16_t LP8_WRITTEN_UUID = 0xB001; // display what was written into lp8 calculation control 00018 00019 const static uint16_t LP8_reWrite_uuid = 0xB111; 00020 00021 00022 //constructor setup for Gatt Service 00023 LP8_Service(BLE &_ble, /* Pass variables to characteristics and ble */ 00024 int co2ValueInitial, 00025 float tempValueInitial, 00026 int initialVcap, 00027 uint32_t initialError, 00028 uint8_t initCC, 00029 uint8_t initSentCC): 00030 ble(_ble), 00031 lp8State(LP8_STATE_CHARACTERISTIC_UUID, &co2ValueInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), 00032 lp8Temp(LP8_READ_TEMP_UUID, &tempValueInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), 00033 lp8Vcap(LP8_VCAP_UUID, &initialVcap, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), 00034 lp8Error(LP8_ERROR_UUID, &initialError, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), 00035 lp8WriteCC(LP8_WRITE_UUID, &initCC), 00036 lp8Written(LP8_WRITTEN_UUID, &initSentCC, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), 00037 lp8reWriteCC(LP8_reWrite_uuid, &initCC, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) 00038 { 00039 //characterisitics 00040 GattCharacteristic *charTable[] = {&lp8State, &lp8Temp, &lp8Vcap, &lp8Error, &lp8WriteCC, &lp8Written, &lp8reWriteCC }; 00041 00042 //Service, Setup for LP8 GattService 00043 GattService lp8Service(LP8_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); 00044 00045 //add gatt service to ble stack 00046 ble.addService(lp8Service); 00047 }; 00048 00049 00050 //update Gattserver with new values to characteristics 00051 void updateCo2Value(int co2Value) 00052 { 00053 ble.gattServer().write(lp8State.getValueAttribute().getHandle(),(uint8_t *) &co2Value, sizeof(co2Value)); 00054 }; 00055 00056 void updateTempValue(float tempValue) 00057 { 00058 ble.gattServer().write(lp8Temp.getValueAttribute().getHandle(),(uint8_t *) &tempValue, sizeof(tempValue)); 00059 }; 00060 00061 void updateVcapValue(int Vcap) 00062 { 00063 ble.gattServer().write(lp8Vcap.getValueAttribute().getHandle(),(uint8_t *) &Vcap, sizeof(Vcap)); 00064 }; 00065 00066 void updateError(uint32_t lp8ErrorValue) 00067 { 00068 ble.gattServer().write(lp8Error.getValueAttribute().getHandle(),(uint8_t *) &lp8ErrorValue, sizeof(lp8ErrorValue)); 00069 }; 00070 00071 // 00072 void updateDataWritten(uint8_t lp8WrittenValue) 00073 { 00074 ble.gattServer().write(lp8Written.getValueAttribute().getHandle(),(uint8_t *) &lp8WrittenValue, sizeof(lp8WrittenValue)); 00075 } 00076 00077 void updateReWrite ( uint8_t lp8ReWrite ) 00078 { 00079 ble.gattServer().write(lp8reWriteCC.getValueAttribute().getHandle(),(uint8_t *) &lp8ReWrite, sizeof(lp8ReWrite)); 00080 } 00081 00082 00083 private: 00084 00085 BLE &ble; // 00086 00087 //Service Characteristics 00088 00089 //Read sensor values 00090 ReadOnlyGattCharacteristic<int> lp8State; // 00091 ReadOnlyGattCharacteristic<float> lp8Temp; 00092 ReadOnlyGattCharacteristic<int> lp8Vcap; 00093 ReadOnlyGattCharacteristic<uint32_t> lp8Error; 00094 00095 //Write Value 00096 WriteOnlyGattCharacteristic<uint8_t> lp8WriteCC; 00097 00098 //read back written and cc byte(flag) 00099 ReadOnlyGattCharacteristic<uint8_t> lp8Written; 00100 ReadOnlyGattCharacteristic<uint8_t> lp8reWriteCC; 00101 00102 00103 }; 00104 #endif
Generated on Thu Jul 21 2022 16:19:39 by
1.7.2