mbed code for UberVest health monitoring

Dependencies:   BLE_API mbed nRF51822

Committer:
haydenball
Date:
Wed Jan 13 21:36:17 2016 +0000
Revision:
7:7e1a474ca416
Parent:
6:808cfc0b9480
Final Changes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
haydenball 0:b6fae6eb2bfe 1 class UberVestService {
haydenball 0:b6fae6eb2bfe 2 public:
haydenball 6:808cfc0b9480 3 const static uint16_t UBER_VEST_SERVICE_UUID = 0xB000;
haydenball 6:808cfc0b9480 4 const static uint16_t ECG_CHARACTERISTIC_UUID = 0xB002;
haydenball 6:808cfc0b9480 5 const static uint16_t TEMP_CHARACTERISTIC_UUID = 0xB003;
haydenball 0:b6fae6eb2bfe 6
haydenball 6:808cfc0b9480 7 UberVestService(BLE &_ble, int8_t ecgInitial, uint8_t tempInitial) :
haydenball 1:7d2c09f56b33 8 ble(_ble),
haydenball 6:808cfc0b9480 9 ecgState(ECG_CHARACTERISTIC_UUID, &ecgInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
haydenball 6:808cfc0b9480 10 tempState(TEMP_CHARACTERISTIC_UUID, &tempInitial, 5, 5, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
haydenball 0:b6fae6eb2bfe 11 {
haydenball 6:808cfc0b9480 12 GattCharacteristic *charTable[] = {&ecgState, &tempState};
haydenball 0:b6fae6eb2bfe 13 GattService uberVestService(UberVestService::UBER_VEST_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
haydenball 0:b6fae6eb2bfe 14
haydenball 0:b6fae6eb2bfe 15 ble.gattServer().addService(uberVestService);
haydenball 0:b6fae6eb2bfe 16 }
haydenball 0:b6fae6eb2bfe 17
haydenball 0:b6fae6eb2bfe 18 void updateEcg(int8_t value) {
haydenball 0:b6fae6eb2bfe 19 ble.gattServer().write(ecgState.getValueHandle(), (uint8_t *)&value, sizeof(int8_t));
haydenball 0:b6fae6eb2bfe 20 }
haydenball 6:808cfc0b9480 21
haydenball 6:808cfc0b9480 22 // The following adapted from https://developer.mbed.org/users/donalm/code/BLE_Health_Thermometer_Blog/file/f11df1469db2/main.cpp:
haydenball 6:808cfc0b9480 23 void updateTemp(float value) {
haydenball 6:808cfc0b9480 24 uint8_t thermTempPayload[5] = { 0, 0, 0, 0, 0 };
haydenball 6:808cfc0b9480 25 uint32_t temp_ieee11073 = quick_ieee11073_from_float(value);
haydenball 6:808cfc0b9480 26
haydenball 6:808cfc0b9480 27 memcpy(thermTempPayload + 1, &temp_ieee11073, 4);
haydenball 6:808cfc0b9480 28
haydenball 6:808cfc0b9480 29 ble.gattServer().write(tempState.getValueHandle(), thermTempPayload, sizeof(thermTempPayload));
haydenball 6:808cfc0b9480 30 }
haydenball 6:808cfc0b9480 31
haydenball 6:808cfc0b9480 32 /**
haydenball 6:808cfc0b9480 33 * @brief A very quick conversion between a float temperature and 11073-20601 FLOAT-Type.
haydenball 6:808cfc0b9480 34 * @param temperature The temperature as a float.
haydenball 6:808cfc0b9480 35 * @return The temperature in 11073-20601 FLOAT-Type format.
haydenball 6:808cfc0b9480 36 */
haydenball 6:808cfc0b9480 37 uint32_t quick_ieee11073_from_float(float temperature)
haydenball 6:808cfc0b9480 38 {
haydenball 6:808cfc0b9480 39 uint8_t exponent = 0xFF; //exponent is -1
haydenball 6:808cfc0b9480 40 uint32_t mantissa = (uint32_t)(temperature*10);
haydenball 6:808cfc0b9480 41
haydenball 6:808cfc0b9480 42 return ( ((uint32_t)exponent) << 24) | mantissa;
haydenball 6:808cfc0b9480 43 }
haydenball 0:b6fae6eb2bfe 44
haydenball 0:b6fae6eb2bfe 45 private:
haydenball 6:808cfc0b9480 46 BLE &ble;
haydenball 0:b6fae6eb2bfe 47 ReadOnlyGattCharacteristic<int8_t> ecgState;
haydenball 6:808cfc0b9480 48 GattCharacteristic tempState;
haydenball 0:b6fae6eb2bfe 49 };