Implementation of Heart Rate Service on nRF52-DK with security (bonding/pairing procedure). Correct key for smartphone to enter is printed on serial. Baud rate 9600, 8 bits + 1 stop bit + no parity bit.
Fork of mbed-os-example-ble-HeartRate by
Revision 71:ef25b79853ee, committed 2018-10-10
- Comitter:
- marcusjzw
- Date:
- Wed Oct 10 01:15:42 2018 +0000
- Parent:
- 70:cae5b05ed2b9
- Commit message:
- working spoof, use cplusplus_arraygen.py alongside this
Changed in this revision
source/HeartRateService.h | Show annotated file Show diff for this revision Revisions of this file |
source/main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r cae5b05ed2b9 -r ef25b79853ee source/HeartRateService.h --- a/source/HeartRateService.h Tue Oct 09 23:06:03 2018 +0000 +++ b/source/HeartRateService.h Wed Oct 10 01:15:42 2018 +0000 @@ -140,7 +140,7 @@ static const unsigned MAX_VALUE_BYTES = 3; /* Flags, and up to two bytes for heart rate. */ static const unsigned FLAGS_BYTE_INDEX = 0; - static const unsigned VALUE_FORMAT_BITNUM = 0; + static const unsigned VALUE_FORMAT_BITNUM = 0; // for flag corresponding to 16 bit number static const uint8_t VALUE_FORMAT_FLAG = (1 << VALUE_FORMAT_BITNUM); HeartRateValueBytes(uint8_t hrmCounter) : valueBytes() { @@ -152,14 +152,23 @@ } void updateHeartRate(uint8_t hrmCounter) { - valueBytes[FLAGS_BYTE_INDEX] &= ~VALUE_FORMAT_FLAG; + // valueBytes[FLAGS_BYTE_INDEX] &= ~VALUE_FORMAT_FLAG; + valueBytes[FLAGS_BYTE_INDEX] = 0; // 0000 0000 = 8-bit valueBytes[FLAGS_BYTE_INDEX + 1] = hrmCounter; } void updateHeartRate(uint16_t hrmCounter) { - valueBytes[FLAGS_BYTE_INDEX] |= VALUE_FORMAT_FLAG; + if (hrmCounter <= 255) { + // valueBytes[FLAGS_BYTE_INDEX] &= ~VALUE_FORMAT_FLAG; + valueBytes[FLAGS_BYTE_INDEX] = 0; // 0000 0000 = 8-bit + valueBytes[FLAGS_BYTE_INDEX + 1] = hrmCounter; + } + else { + // valueBytes[FLAGS_BYTE_INDEX] |= VALUE_FORMAT_FLAG; + valueBytes[FLAGS_BYTE_INDEX] = 1; // 0000 0001 = 16-bit valueBytes[FLAGS_BYTE_INDEX + 1] = (uint8_t)(hrmCounter & 0xFF); valueBytes[FLAGS_BYTE_INDEX + 2] = (uint8_t)(hrmCounter >> 8); + } } uint8_t *getPointer(void) {
diff -r cae5b05ed2b9 -r ef25b79853ee source/main.cpp --- a/source/main.cpp Tue Oct 09 23:06:03 2018 +0000 +++ b/source/main.cpp Wed Oct 10 01:15:42 2018 +0000 @@ -26,7 +26,7 @@ static const uint16_t uuid16_list[] = {GattService::UUID_HEART_RATE_SERVICE}; static uint16_t rriValues[100] = {880,860,860,860,870,880,890,910,920,930,940,940,950,940,950,940,950,950,950,950,530,1350,950,930,910,920,940,940,950,940,950,940,930,940,950,950,950,960,960,960,950,960,950,960,950,960,960,950,960,960,950,950,940,950,950,940,930,930,920,920,910,920,910,900,670,1130,910,880,880,870,660,1100,890,880,880,880,660,1110,910,890,900,900,690,1110,910,900,910,900,900,910,930,920,940,940,940,950,960,950,950,960}; static uint16_t counter = 0; -static uint8_t hrmCounter = 800; // init +static uint16_t hrmCounter = 800; // init static HeartRateService *hrServicePtr; @@ -119,7 +119,7 @@ ble.gap().onConnection(connectionCallback); /* Setup primary service. */ - hrServicePtr = new HeartRateService(ble, hrmCounter, HeartRateService::LOCATION_FINGER); + hrServicePtr = new HeartRateService(ble, hrmCounter, HeartRateService::LOCATION_CHEST); /* Initialize BLE security */ bool enableBonding = true;