BLE FORK
Fork of BLE_API by
Revision 1131:4d921282c434, committed 2016-10-26
- Comitter:
- paulocroman
- Date:
- Wed Oct 26 00:18:34 2016 +0000
- Parent:
- 985:3cb4b0e44d8f
- Commit message:
- PPG BLE
Changed in this revision
ble/services/HeartRateService.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 3cb4b0e44d8f -r 4d921282c434 ble/services/HeartRateService.h --- a/ble/services/HeartRateService.h Thu Nov 26 12:52:37 2015 +0000 +++ b/ble/services/HeartRateService.h Wed Oct 26 00:18:34 2016 +0000 @@ -74,9 +74,9 @@ * @param[in] location * Sensor's location. */ - HeartRateService(BLE &_ble, uint16_t hrmCounter, uint8_t location) : + HeartRateService(BLE &_ble, uint16_t v1, uint16_t v2, uint8_t location) : ble(_ble), - valueBytes(hrmCounter), + valueBytes(v1,v2), hrmRate(GattCharacteristic::UUID_HEART_RATE_MEASUREMENT_CHAR, valueBytes.getPointer(), valueBytes.getNumValueBytes(), HeartRateValueBytes::MAX_VALUE_BYTES, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), @@ -106,6 +106,16 @@ valueBytes.updateHeartRate(hrmCounter); ble.gattServer().write(hrmRate.getValueHandle(), valueBytes.getPointer(), valueBytes.getNumValueBytes()); } + + void updateHeartRate(uint16_t v1, uint16_t v2) { + valueBytes.updateHeartRate(v1,v2); + ble.gattServer().write(hrmRate.getValueHandle(), valueBytes.getPointer(), valueBytes.getNumValueBytes()); + } + + void updateHeartRate(int32_t v1, int32_t v2) { + valueBytes.updateHeartRate(v1,v2); + ble.gattServer().write(hrmRate.getValueHandle(), valueBytes.getPointer(), valueBytes.getNumValueBytes()); + } /** * This callback allows the HeartRateService to receive updates to the @@ -137,7 +147,7 @@ protected: /* Private internal representation for the bytes used to work with the vaulue of the heart-rate characteristic. */ struct HeartRateValueBytes { - static const unsigned MAX_VALUE_BYTES = 3; /* FLAGS + up to two bytes for heart-rate */ + static const unsigned MAX_VALUE_BYTES = 10; /* FLAGS + up to two bytes for heart-rate */ static const unsigned FLAGS_BYTE_INDEX = 0; static const unsigned VALUE_FORMAT_BITNUM = 0; @@ -151,6 +161,10 @@ updateHeartRate(hrmCounter); } + HeartRateValueBytes(uint16_t v1, uint16_t v2) : valueBytes() { + updateHeartRate(v1,v2); + } + void updateHeartRate(uint8_t hrmCounter) { valueBytes[FLAGS_BYTE_INDEX] &= ~VALUE_FORMAT_FLAG; valueBytes[FLAGS_BYTE_INDEX + 1] = hrmCounter; @@ -161,6 +175,33 @@ valueBytes[FLAGS_BYTE_INDEX + 1] = (uint8_t)(hrmCounter & 0xFF); valueBytes[FLAGS_BYTE_INDEX + 2] = (uint8_t)(hrmCounter >> 8); } + + void updateHeartRate(uint16_t v1, uint16_t v2) + { + valueBytes[FLAGS_BYTE_INDEX] |= VALUE_FORMAT_FLAG; + valueBytes[FLAGS_BYTE_INDEX + 1] = (uint8_t)(v1 & 0xFF); + valueBytes[FLAGS_BYTE_INDEX + 2] = (uint8_t)(v1 >> 8); + valueBytes[FLAGS_BYTE_INDEX + 3] = (uint8_t)(v2 & 0xFF); + valueBytes[FLAGS_BYTE_INDEX + 4] = (uint8_t)(v2 >> 8); + } + + void updateHeartRate(int32_t v1, int32_t v2) + { + unsigned char *u1; + u1 = ((unsigned char*)&v1); + valueBytes[FLAGS_BYTE_INDEX] |= VALUE_FORMAT_FLAG; + valueBytes[FLAGS_BYTE_INDEX + 1] = (uint8_t)(u1[0]&0xFF); + valueBytes[FLAGS_BYTE_INDEX + 2] = (uint8_t)(u1[1]&0xFF); + valueBytes[FLAGS_BYTE_INDEX + 3] = (uint8_t)(u1[2]&0xFF); + valueBytes[FLAGS_BYTE_INDEX + 4] = (uint8_t)(u1[3]&0xFF); + + u1 = ((unsigned char*)&v2); + valueBytes[FLAGS_BYTE_INDEX + 5] = (uint8_t)(u1[0]&0xFF); + valueBytes[FLAGS_BYTE_INDEX + 6] = (uint8_t)(u1[1]&0xFF); + valueBytes[FLAGS_BYTE_INDEX + 7] = (uint8_t)(u1[2]&0xFF); + valueBytes[FLAGS_BYTE_INDEX + 8] = (uint8_t)(u1[3]&0xFF); + } + uint8_t *getPointer(void) { return valueBytes; @@ -171,7 +212,8 @@ } unsigned getNumValueBytes(void) const { - return 1 + ((valueBytes[FLAGS_BYTE_INDEX] & VALUE_FORMAT_FLAG) ? sizeof(uint16_t) : sizeof(uint8_t)); + //return 1 + ((valueBytes[FLAGS_BYTE_INDEX] & VALUE_FORMAT_FLAG) ? sizeof(uint16_t) : sizeof(uint8_t)); + return 1 + sizeof(uint32_t)*2; } private: