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
UberVestService.h
00001 class UberVestService { 00002 public: 00003 const static uint16_t UBER_VEST_SERVICE_UUID = 0xB000; 00004 const static uint16_t ECG_CHARACTERISTIC_UUID = 0xB002; 00005 const static uint16_t TEMP_CHARACTERISTIC_UUID = 0xB003; 00006 00007 UberVestService(BLE &_ble, int8_t ecgInitial, uint8_t tempInitial) : 00008 ble(_ble), 00009 ecgState(ECG_CHARACTERISTIC_UUID, &ecgInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), 00010 tempState(TEMP_CHARACTERISTIC_UUID, &tempInitial, 5, 5, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) 00011 { 00012 GattCharacteristic *charTable[] = {&ecgState, &tempState}; 00013 GattService uberVestService(UberVestService::UBER_VEST_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); 00014 00015 ble.gattServer().addService(uberVestService); 00016 } 00017 00018 void updateEcg(int8_t value) { 00019 ble.gattServer().write(ecgState.getValueHandle(), (uint8_t *)&value, sizeof(int8_t)); 00020 } 00021 00022 // The following adapted from https://developer.mbed.org/users/donalm/code/BLE_Health_Thermometer_Blog/file/f11df1469db2/main.cpp: 00023 void updateTemp(float value) { 00024 uint8_t thermTempPayload[5] = { 0, 0, 0, 0, 0 }; 00025 uint32_t temp_ieee11073 = quick_ieee11073_from_float(value); 00026 00027 memcpy(thermTempPayload + 1, &temp_ieee11073, 4); 00028 00029 ble.gattServer().write(tempState.getValueHandle(), thermTempPayload, sizeof(thermTempPayload)); 00030 } 00031 00032 /** 00033 * @brief A very quick conversion between a float temperature and 11073-20601 FLOAT-Type. 00034 * @param temperature The temperature as a float. 00035 * @return The temperature in 11073-20601 FLOAT-Type format. 00036 */ 00037 uint32_t quick_ieee11073_from_float(float temperature) 00038 { 00039 uint8_t exponent = 0xFF; //exponent is -1 00040 uint32_t mantissa = (uint32_t)(temperature*10); 00041 00042 return ( ((uint32_t)exponent) << 24) | mantissa; 00043 } 00044 00045 private: 00046 BLE &ble; 00047 ReadOnlyGattCharacteristic<int8_t> ecgState; 00048 GattCharacteristic tempState; 00049 };
Generated on Thu Jul 21 2022 03:22:43 by
1.7.2