From f7594a78c3d7d239c9e01d653d311dfb907a3d09 Mon Sep 17 00:00:00 2001 From: Ruffalo Lavoisier Date: Tue, 8 Oct 2024 00:07:19 +0900 Subject: [PATCH 1/7] BLE: add step count service --- include/services/OswServiceTaskBLEServer.h | 78 +++++++++++++ src/services/OswServiceTaskBLEServer.cpp | 129 +++++++++++++++++++-- 2 files changed, 196 insertions(+), 11 deletions(-) diff --git a/include/services/OswServiceTaskBLEServer.h b/include/services/OswServiceTaskBLEServer.h index 2e3afe03d..265342a1c 100644 --- a/include/services/OswServiceTaskBLEServer.h +++ b/include/services/OswServiceTaskBLEServer.h @@ -67,6 +67,75 @@ class OswServiceTaskBLEServer : public OswServiceTask { OswServiceTaskBLEServer* task; }; + class StepsTodayCharacteristicCallbacks: public NimBLECharacteristicCallbacks { + void onRead(NimBLECharacteristic* pCharacteristic); + /* + uint32_t value; + this->bytes[0] = (uint8_t) value; + this->bytes[1] = (uint8_t) (value >> 8); + this->bytes[2] = (uint8_t) (value >> 16); + this->bytes[3] = (uint8_t) (value >> 24); + */ + uint8_t bytes[4]; + }; + class StepsTotalWeekCharacteristicCallbacks: public NimBLECharacteristicCallbacks { + void onRead(NimBLECharacteristic* pCharacteristic); + /* + uint32_t value; + this->bytes[0] = (uint8_t) value; + this->bytes[1] = (uint8_t) (value >> 8); + this->bytes[2] = (uint8_t) (value >> 16); + this->bytes[3] = (uint8_t) (value >> 24); + */ + uint8_t bytes[4]; + }; + class StepsTotalCharacteristicCallbacks: public NimBLECharacteristicCallbacks { + void onRead(NimBLECharacteristic* pCharacteristic); + /* + uint32_t value; + this->bytes[0] = (uint8_t) value; + this->bytes[1] = (uint8_t) (value >> 8); + this->bytes[2] = (uint8_t) (value >> 16); + this->bytes[3] = (uint8_t) (value >> 24); + */ + uint8_t bytes[4]; + }; + class StepsAverageCharacteristicCallbacks: public NimBLECharacteristicCallbacks { + void onRead(NimBLECharacteristic* pCharacteristic); + /* + uint32_t value; + this->bytes[0] = (uint8_t) value; + this->bytes[1] = (uint8_t) (value >> 8); + this->bytes[2] = (uint8_t) (value >> 16); + this->bytes[3] = (uint8_t) (value >> 24); + */ + uint8_t bytes[4]; + }; + class StepsDayHistoryCharacteristicCallbacks: public NimBLECharacteristicCallbacks { + void onRead(NimBLECharacteristic* pCharacteristic); + /* + uint32_t value[7]; + this->bytes[0] = (uint8_t) value[0]; + this->bytes[1] = (uint8_t) (value[0] >> 8); + this->bytes[2] = (uint8_t) (value[0] >> 16); + this->bytes[3] = (uint8_t) (value[0] >> 24); + + this->bytes[4] = (uint8_t) value[1]; + this->bytes[5] = (uint8_t) (value[1] >> 8); + this->bytes[6] = (uint8_t) (value[1] >> 16); + this->bytes[7] = (uint8_t) (value[1] >> 24); + + this->bytes[8] = (uint8_t) value[2]; + this->bytes[9] = (uint8_t) (value[2] >> 8); + this->bytes[10] = (uint8_t) (value[2] >> 16); + this->bytes[11] = (uint8_t) (value[2] >> 24); + + ... + + */ + uint8_t bytes[4 * 7]; + }; + /// apply the desired BLE state void updateBLEConfig(); @@ -84,6 +153,15 @@ class OswServiceTaskBLEServer : public OswServiceTask { NimBLECharacteristic* characteristicSoftRev = nullptr; NimBLEService* serviceOsw = nullptr; NimBLECharacteristic* characteristicToast = nullptr; +#if OSW_PLATFORM_ENVIRONMENT_ACCELEROMETER == 1 + NimBLECharacteristic* characteristicStepCountTotal = nullptr; + NimBLECharacteristic* characteristicStepCountTotalWeek = nullptr; + NimBLECharacteristic* characteristicStepCountToday = nullptr; +#ifdef OSW_FEATURE_STATS_STEPS + NimBLECharacteristic* characteristicStepCountAverage = nullptr; + NimBLECharacteristic* characteristicStepCountHistory = nullptr; +#endif +#endif // ↓ our own stuff NotifierClient notify = NotifierClient("osw.ble.server"); diff --git a/src/services/OswServiceTaskBLEServer.cpp b/src/services/OswServiceTaskBLEServer.cpp index a0721e18c..cdaac1a7a 100644 --- a/src/services/OswServiceTaskBLEServer.cpp +++ b/src/services/OswServiceTaskBLEServer.cpp @@ -2,17 +2,23 @@ #include "./services/OswServiceTaskBLEServer.h" #include "osw_hal.h" -#define BATTERY_SERVICE_UUID "0000180F-0000-1000-8000-00805f9b34fb" -#define BATTERY_LEVEL_CHARACTERISTIC_UUID "00002A19-0000-1000-8000-00805f9b34fb" -#define BATTERY_LEVEL_STATUS_CHARACTERISTIC_UUID "00002bed-0000-1000-8000-00805f9b34fb" -#define TIME_SERVICE_UUID "00001805-0000-1000-8000-00805f9b34fb" -#define CURRENT_TIME_CHARACTERISTIC_UUID "00002a0c-0000-1000-8000-00805f9b34fb" -#define DEVICE_INFORMATION_SERVICE_UUID "0000180a-0000-1000-8000-00805f9b34fb" -#define FIRMWARE_REVISION_CHARACTERISTIC_UUID "00002a26-0000-1000-8000-00805f9b34fb" -#define HARDWARE_REVISION_CHARACTERISTIC_UUID "00002a27-0000-1000-8000-00805f9b34fb" -#define SOFTWARE_REVISION_CHARACTERISTIC_UUID "00002a28-0000-1000-8000-00805f9b34fb" -#define OSW_SERVICE_UUID "6ab9b834-3e0b-4770-a938-ebaa58d6b852" -#define TOAST_CHARACTERISTIC_UUID "9cadf570-4ec8-40b0-a8d3-cfdb4a90940b" +#define BATTERY_SERVICE_UUID "0000180F-0000-1000-8000-00805f9b34fb" +#define BATTERY_LEVEL_CHARACTERISTIC_UUID "00002A19-0000-1000-8000-00805f9b34fb" +#define BATTERY_LEVEL_STATUS_CHARACTERISTIC_UUID "00002bed-0000-1000-8000-00805f9b34fb" +#define TIME_SERVICE_UUID "00001805-0000-1000-8000-00805f9b34fb" +#define CURRENT_TIME_CHARACTERISTIC_UUID "00002a0c-0000-1000-8000-00805f9b34fb" +#define DEVICE_INFORMATION_SERVICE_UUID "0000180a-0000-1000-8000-00805f9b34fb" +#define FIRMWARE_REVISION_CHARACTERISTIC_UUID "00002a26-0000-1000-8000-00805f9b34fb" +#define HARDWARE_REVISION_CHARACTERISTIC_UUID "00002a27-0000-1000-8000-00805f9b34fb" +#define SOFTWARE_REVISION_CHARACTERISTIC_UUID "00002a28-0000-1000-8000-00805f9b34fb" + +#define OSW_SERVICE_UUID "6ab9b834-3e0b-4770-a938-ebaa58d6b852" +#define TOAST_CHARACTERISTIC_UUID "9cadf570-4ec8-40b0-a8d3-cfdb4a90940b" +#define STEP_COUNT_AVERAGE_CHARACTERISTIC_UUID "3d27dd91-b714-4fe4-8067-620ff7cf13c0" +#define STEP_COUNT_TOTAL_CHARACTERISTIC_UUID "6567e61b-41df-4416-96fc-4e068628bd37" +#define STEP_COUNT_TOTAL_WEEK_CHARACTERISTIC_UUID "0b97315f-883b-4e1e-a745-bc2dd14aedb4" +#define STEP_COUNT_TODAY_CHARACTERISTIC_UUID "143a6279-67ce-43c2-8db2-082a9fbca140" +#define STEP_COUNT_DAY_HISTORY_CHARACTERISTIC_UUID "6b078d24-79ae-4fff-bf3a-2b71dce2b2bb" void OswServiceTaskBLEServer::setup() { OswServiceTask::setup(); @@ -143,6 +149,38 @@ void OswServiceTaskBLEServer::updateBLEConfig() { ); this->characteristicToast->setCallbacks(new ToastCharacteristicCallbacks(this)); +#if OSW_PLATFORM_ENVIRONMENT_ACCELEROMETER == 1 + this->characteristicStepCountToday = this->serviceOsw->createCharacteristic( + STEP_COUNT_TODAY_CHARACTERISTIC_UUID, + NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::READ_ENC | NIMBLE_PROPERTY::READ_AUTHEN + ); + this->characteristicStepCountToday->setCallbacks(new StepsTodayCharacteristicCallbacks()); + + this->characteristicStepCountTotal = this->serviceOsw->createCharacteristic( + STEP_COUNT_TOTAL_CHARACTERISTIC_UUID, + NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::READ_ENC | NIMBLE_PROPERTY::READ_AUTHEN + ); + this->characteristicStepCountTotal->setCallbacks(new StepsTotalCharacteristicCallbacks()); + + this->characteristicStepCountTotalWeek = this->serviceOsw->createCharacteristic( + STEP_COUNT_TOTAL_WEEK_CHARACTERISTIC_UUID, + NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::READ_ENC | NIMBLE_PROPERTY::READ_AUTHEN + ); + this->characteristicStepCountTotalWeek->setCallbacks(new StepsTotalWeekCharacteristicCallbacks()); +#ifdef OSW_FEATURE_STATS_STEPS + this->characteristicStepCountAverage = this->serviceOsw->createCharacteristic( + STEP_COUNT_AVERAGE_CHARACTERISTIC_UUID, + NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::READ_ENC | NIMBLE_PROPERTY::READ_AUTHEN + ); + this->characteristicStepCountAverage->setCallbacks(new StepsAverageCharacteristicCallbacks()); + + this->characteristicStepCountHistory = this->serviceOsw->createCharacteristic( + STEP_COUNT_DAY_HISTORY_CHARACTERISTIC_UUID, + NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::READ_ENC | NIMBLE_PROPERTY::READ_AUTHEN + ); + this->characteristicStepCountHistory->setCallbacks(new StepsDayHistoryCharacteristicCallbacks()); // Create a BLE Characteristic: "Hardware Revision String" +#endif +#endif // Start the service this->serviceOsw->start(); } @@ -172,6 +210,15 @@ void OswServiceTaskBLEServer::updateBLEConfig() { this->serviceDevice->removeCharacteristic(this->characteristicSoftRev, true); this->server->removeService(this->serviceDevice, true); this->serviceOsw->removeCharacteristic(this->characteristicToast, true); +#if OSW_PLATFORM_ENVIRONMENT_ACCELEROMETER == 1 + this->serviceOsw->removeCharacteristic(this->characteristicStepCountToday, true); + this->serviceOsw->removeCharacteristic(this->characteristicStepCountTotal, true); + this->serviceOsw->removeCharacteristic(this->characteristicStepCountTotalWeek, true); +#ifdef OSW_FEATURE_STATS_STEPS + this->serviceOsw->removeCharacteristic(this->characteristicStepCountAverage, true); + this->serviceOsw->removeCharacteristic(this->characteristicStepCountHistory, true); +#endif +#endif this->server->removeService(this->serviceOsw, true); this->server = nullptr; NimBLEDevice::deinit(true); @@ -286,7 +333,67 @@ void OswServiceTaskBLEServer::HardwareRevisionCharacteristicCallbacks::onRead(Ni this->value = String(PIO_ENV_NAME); pCharacteristic->setValue((uint8_t*) this->value.c_str(), this->value.length()); } +#if OSW_PLATFORM_ENVIRONMENT_ACCELEROMETER == 1 +void OswServiceTaskBLEServer::StepsTodayCharacteristicCallbacks::onRead(NimBLECharacteristic* pCharacteristic) { + uint32_t stepsToday = OswHal::getInstance()->environment()->getStepsToday(); + + this->bytes[0] = (uint8_t) stepsToday; + this->bytes[1] = (uint8_t) (stepsToday >> 8); + this->bytes[2] = (uint8_t) (stepsToday >> 16); + this->bytes[3] = (uint8_t) (stepsToday >> 24); + + pCharacteristic->setValue(this->bytes, sizeof(this->bytes)); +} +void OswServiceTaskBLEServer::StepsTotalCharacteristicCallbacks::onRead(NimBLECharacteristic* pCharacteristic) { + uint32_t stepsTotal = OswHal::getInstance()->environment()->getStepsTotal(); + + this->bytes[0] = (uint8_t) stepsTotal; + this->bytes[1] = (uint8_t) (stepsTotal >> 8); + this->bytes[2] = (uint8_t) (stepsTotal >> 16); + this->bytes[3] = (uint8_t) (stepsTotal >> 24); + + pCharacteristic->setValue(this->bytes, sizeof(this->bytes)); +} + +void OswServiceTaskBLEServer::StepsTotalWeekCharacteristicCallbacks::onRead(NimBLECharacteristic* pCharacteristic) { + uint32_t stepsTotalWeek = OswHal::getInstance()->environment()->getStepsTotalWeek(); + + this->bytes[0] = (uint8_t) stepsTotalWeek; + this->bytes[1] = (uint8_t) (stepsTotalWeek >> 8); + this->bytes[2] = (uint8_t) (stepsTotalWeek >> 16); + this->bytes[3] = (uint8_t) (stepsTotalWeek >> 24); + + pCharacteristic->setValue(this->bytes, sizeof(this->bytes)); +} +#ifdef OSW_FEATURE_STATS_STEPS +void OswServiceTaskBLEServer::StepsAverageCharacteristicCallbacks::onRead(NimBLECharacteristic* pCharacteristic) { + uint32_t stepsAverage = OswHal::getInstance()->environment()->getStepsAverage(); + + this->bytes[0] = (uint8_t) stepsAverage; + this->bytes[1] = (uint8_t) (stepsAverage >> 8); + this->bytes[2] = (uint8_t) (stepsAverage >> 16); + this->bytes[3] = (uint8_t) (stepsAverage >> 24); + + pCharacteristic->setValue(this->bytes, sizeof(this->bytes)); +} + +void OswServiceTaskBLEServer::StepsDayHistoryCharacteristicCallbacks::onRead(NimBLECharacteristic* pCharacteristic) { + + for (uint8_t indexOfWeek = 0; indexOfWeek < 7; indexOfWeek++) + { + uint32_t value = OswHal::getInstance()->environment()->getStepsOnDay(indexOfWeek, true); + this->bytes[0 + indexOfWeek * 4] = (uint8_t) value; + this->bytes[1 + indexOfWeek * 4] = (uint8_t) (value >> 8); + this->bytes[2 + indexOfWeek * 4] = (uint8_t) (value >> 16); + this->bytes[3 + indexOfWeek * 4] = (uint8_t) (value >> 24); + /* code */ + } + + pCharacteristic->setValue(this->bytes, sizeof(this->bytes)); +} +#endif +#endif void OswServiceTaskBLEServer::SoftwareRevisionCharacteristicCallbacks::onRead(NimBLECharacteristic* pCharacteristic) { this->value = String(GIT_COMMIT_HASH) + " (" + String(GIT_BRANCH_NAME) + ")"; pCharacteristic->setValue((uint8_t*) this->value.c_str(), this->value.length()); From 73c42d4e630cb4a2a833115108dd6b291e8e3713 Mon Sep 17 00:00:00 2001 From: Ruffalo Lavoisier Date: Thu, 24 Oct 2024 00:52:29 +0900 Subject: [PATCH 2/7] get step history array --- src/services/OswServiceTaskBLEServer.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/services/OswServiceTaskBLEServer.cpp b/src/services/OswServiceTaskBLEServer.cpp index cdaac1a7a..af4737453 100644 --- a/src/services/OswServiceTaskBLEServer.cpp +++ b/src/services/OswServiceTaskBLEServer.cpp @@ -382,12 +382,11 @@ void OswServiceTaskBLEServer::StepsDayHistoryCharacteristicCallbacks::onRead(Nim for (uint8_t indexOfWeek = 0; indexOfWeek < 7; indexOfWeek++) { - uint32_t value = OswHal::getInstance()->environment()->getStepsOnDay(indexOfWeek, true); + uint32_t value = OswHal::getInstance()->environment()->getStepsOnDay(indexOfWeek, false); this->bytes[0 + indexOfWeek * 4] = (uint8_t) value; this->bytes[1 + indexOfWeek * 4] = (uint8_t) (value >> 8); this->bytes[2 + indexOfWeek * 4] = (uint8_t) (value >> 16); this->bytes[3 + indexOfWeek * 4] = (uint8_t) (value >> 24); - /* code */ } pCharacteristic->setValue(this->bytes, sizeof(this->bytes)); From 1c48790abff72cc2132556d588d1dd6ae2c66595 Mon Sep 17 00:00:00 2001 From: Ruffalo Lavoisier Date: Wed, 13 Nov 2024 14:25:33 +0900 Subject: [PATCH 3/7] Rename bytes value to feature part --- include/services/OswServiceTaskBLEServer.h | 10 +-- src/services/OswServiceTaskBLEServer.cpp | 72 +++++++++++----------- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/include/services/OswServiceTaskBLEServer.h b/include/services/OswServiceTaskBLEServer.h index 265342a1c..330ebff35 100644 --- a/include/services/OswServiceTaskBLEServer.h +++ b/include/services/OswServiceTaskBLEServer.h @@ -76,7 +76,7 @@ class OswServiceTaskBLEServer : public OswServiceTask { this->bytes[2] = (uint8_t) (value >> 16); this->bytes[3] = (uint8_t) (value >> 24); */ - uint8_t bytes[4]; + uint8_t bytesStepsToday[4]; }; class StepsTotalWeekCharacteristicCallbacks: public NimBLECharacteristicCallbacks { void onRead(NimBLECharacteristic* pCharacteristic); @@ -87,7 +87,7 @@ class OswServiceTaskBLEServer : public OswServiceTask { this->bytes[2] = (uint8_t) (value >> 16); this->bytes[3] = (uint8_t) (value >> 24); */ - uint8_t bytes[4]; + uint8_t bytesStepsTotalWeek[4]; }; class StepsTotalCharacteristicCallbacks: public NimBLECharacteristicCallbacks { void onRead(NimBLECharacteristic* pCharacteristic); @@ -98,7 +98,7 @@ class OswServiceTaskBLEServer : public OswServiceTask { this->bytes[2] = (uint8_t) (value >> 16); this->bytes[3] = (uint8_t) (value >> 24); */ - uint8_t bytes[4]; + uint8_t bytesStepsTotal[4]; }; class StepsAverageCharacteristicCallbacks: public NimBLECharacteristicCallbacks { void onRead(NimBLECharacteristic* pCharacteristic); @@ -109,7 +109,7 @@ class OswServiceTaskBLEServer : public OswServiceTask { this->bytes[2] = (uint8_t) (value >> 16); this->bytes[3] = (uint8_t) (value >> 24); */ - uint8_t bytes[4]; + uint8_t bytesStepsAverage[4]; }; class StepsDayHistoryCharacteristicCallbacks: public NimBLECharacteristicCallbacks { void onRead(NimBLECharacteristic* pCharacteristic); @@ -133,7 +133,7 @@ class OswServiceTaskBLEServer : public OswServiceTask { ... */ - uint8_t bytes[4 * 7]; + uint8_t bytesStepsDayHistory[4 * 7]; }; diff --git a/src/services/OswServiceTaskBLEServer.cpp b/src/services/OswServiceTaskBLEServer.cpp index af4737453..55373bd2f 100644 --- a/src/services/OswServiceTaskBLEServer.cpp +++ b/src/services/OswServiceTaskBLEServer.cpp @@ -312,17 +312,17 @@ void OswServiceTaskBLEServer::CurrentTimeCharacteristicCallbacks::onRead(NimBLEC uint32_t dow; OswHal::getInstance()->getDate(offset, &day, &dow); - this->bytes[0] = (uint8_t) year; // Exact Time 256 -> Day Date Time -> Date Time -> Year #1 - this->bytes[1] = (uint8_t) (year >> 8); // Exact Time 256 -> Day Date Time -> Date Time -> Year #2 - this->bytes[2] = (uint8_t) month; // Exact Time 256 -> Day Date Time -> Date Time -> Month - this->bytes[3] = (uint8_t) day; // Exact Time 256 -> Day Date Time -> Date Time -> Day - this->bytes[4] = (uint8_t) hour; // Exact Time 256 -> Day Date Time -> Date Time -> Hours - this->bytes[5] = (uint8_t) minute; // Exact Time 256 -> Day Date Time -> Date Time -> Minutes - this->bytes[6] = (uint8_t) second; // Exact Time 256 -> Day Date Time -> Date Time -> Seconds - this->bytes[7] = (uint8_t) (dow == 0 ? 7 : dow); // Exact Time 256 -> Day Date Time -> Day of Week - this->bytes[8] = 0b00000000; // Exact Time 256 -> Fractions256 - this->bytes[9] = 0b00000001; // Adjust Reason: External Reference Time Update - pCharacteristic->setValue(this->bytes, sizeof(this->bytes)); + this->bytesCurrentTime[0] = (uint8_t) year; // Exact Time 256 -> Day Date Time -> Date Time -> Year #1 + this->bytesCurrentTime[1] = (uint8_t) (year >> 8); // Exact Time 256 -> Day Date Time -> Date Time -> Year #2 + this->bytesCurrentTime[2] = (uint8_t) month; // Exact Time 256 -> Day Date Time -> Date Time -> Month + this->bytesCurrentTime[3] = (uint8_t) day; // Exact Time 256 -> Day Date Time -> Date Time -> Day + this->bytesCurrentTime[4] = (uint8_t) hour; // Exact Time 256 -> Day Date Time -> Date Time -> Hours + this->bytesCurrentTime[5] = (uint8_t) minute; // Exact Time 256 -> Day Date Time -> Date Time -> Minutes + this->bytesCurrentTime[6] = (uint8_t) second; // Exact Time 256 -> Day Date Time -> Date Time -> Seconds + this->bytesCurrentTime[7] = (uint8_t) (dow == 0 ? 7 : dow); // Exact Time 256 -> Day Date Time -> Day of Week + this->bytesCurrentTime[8] = 0b00000000; // Exact Time 256 -> Fractions256 + this->bytesCurrentTime[9] = 0b00000001; // Adjust Reason: External Reference Time Update + pCharacteristic->setValue(this->bytesCurrentTime, sizeof(this->bytesCurrentTime)); } void OswServiceTaskBLEServer::FirmwareRevisionCharacteristicCallbacks::onRead(NimBLECharacteristic* pCharacteristic) { @@ -337,45 +337,45 @@ void OswServiceTaskBLEServer::HardwareRevisionCharacteristicCallbacks::onRead(Ni void OswServiceTaskBLEServer::StepsTodayCharacteristicCallbacks::onRead(NimBLECharacteristic* pCharacteristic) { uint32_t stepsToday = OswHal::getInstance()->environment()->getStepsToday(); - this->bytes[0] = (uint8_t) stepsToday; - this->bytes[1] = (uint8_t) (stepsToday >> 8); - this->bytes[2] = (uint8_t) (stepsToday >> 16); - this->bytes[3] = (uint8_t) (stepsToday >> 24); + this->bytesStepsToday[0] = (uint8_t) stepsToday; + this->bytesStepsToday[1] = (uint8_t) (stepsToday >> 8); + this->bytesStepsToday[2] = (uint8_t) (stepsToday >> 16); + this->bytesStepsToday[3] = (uint8_t) (stepsToday >> 24); - pCharacteristic->setValue(this->bytes, sizeof(this->bytes)); + pCharacteristic->setValue(this->bytesStepsToday, sizeof(this->bytesStepsToday)); } void OswServiceTaskBLEServer::StepsTotalCharacteristicCallbacks::onRead(NimBLECharacteristic* pCharacteristic) { uint32_t stepsTotal = OswHal::getInstance()->environment()->getStepsTotal(); - this->bytes[0] = (uint8_t) stepsTotal; - this->bytes[1] = (uint8_t) (stepsTotal >> 8); - this->bytes[2] = (uint8_t) (stepsTotal >> 16); - this->bytes[3] = (uint8_t) (stepsTotal >> 24); + this->bytesStepsTotal[0] = (uint8_t) stepsTotal; + this->bytesStepsTotal[1] = (uint8_t) (stepsTotal >> 8); + this->bytesStepsTotal[2] = (uint8_t) (stepsTotal >> 16); + this->bytesStepsTotal[3] = (uint8_t) (stepsTotal >> 24); - pCharacteristic->setValue(this->bytes, sizeof(this->bytes)); + pCharacteristic->setValue(this->bytesStepsTotal, sizeof(this->bytesStepsTotal)); } void OswServiceTaskBLEServer::StepsTotalWeekCharacteristicCallbacks::onRead(NimBLECharacteristic* pCharacteristic) { uint32_t stepsTotalWeek = OswHal::getInstance()->environment()->getStepsTotalWeek(); - this->bytes[0] = (uint8_t) stepsTotalWeek; - this->bytes[1] = (uint8_t) (stepsTotalWeek >> 8); - this->bytes[2] = (uint8_t) (stepsTotalWeek >> 16); - this->bytes[3] = (uint8_t) (stepsTotalWeek >> 24); + this->bytesStepsTotalWeek[0] = (uint8_t) stepsTotalWeek; + this->bytesStepsTotalWeek[1] = (uint8_t) (stepsTotalWeek >> 8); + this->bytesStepsTotalWeek[2] = (uint8_t) (stepsTotalWeek >> 16); + this->bytesStepsTotalWeek[3] = (uint8_t) (stepsTotalWeek >> 24); - pCharacteristic->setValue(this->bytes, sizeof(this->bytes)); + pCharacteristic->setValue(this->bytesStepsTotalWeek, sizeof(this->bytesStepsTotalWeek)); } #ifdef OSW_FEATURE_STATS_STEPS void OswServiceTaskBLEServer::StepsAverageCharacteristicCallbacks::onRead(NimBLECharacteristic* pCharacteristic) { uint32_t stepsAverage = OswHal::getInstance()->environment()->getStepsAverage(); - this->bytes[0] = (uint8_t) stepsAverage; - this->bytes[1] = (uint8_t) (stepsAverage >> 8); - this->bytes[2] = (uint8_t) (stepsAverage >> 16); - this->bytes[3] = (uint8_t) (stepsAverage >> 24); + this->bytesStepsAverage[0] = (uint8_t) stepsAverage; + this->bytesStepsAverage[1] = (uint8_t) (stepsAverage >> 8); + this->bytesStepsAverage[2] = (uint8_t) (stepsAverage >> 16); + this->bytesStepsAverage[3] = (uint8_t) (stepsAverage >> 24); - pCharacteristic->setValue(this->bytes, sizeof(this->bytes)); + pCharacteristic->setValue(this->bytesStepsAverage, sizeof(this->bytesStepsAverage)); } void OswServiceTaskBLEServer::StepsDayHistoryCharacteristicCallbacks::onRead(NimBLECharacteristic* pCharacteristic) { @@ -383,13 +383,13 @@ void OswServiceTaskBLEServer::StepsDayHistoryCharacteristicCallbacks::onRead(Nim for (uint8_t indexOfWeek = 0; indexOfWeek < 7; indexOfWeek++) { uint32_t value = OswHal::getInstance()->environment()->getStepsOnDay(indexOfWeek, false); - this->bytes[0 + indexOfWeek * 4] = (uint8_t) value; - this->bytes[1 + indexOfWeek * 4] = (uint8_t) (value >> 8); - this->bytes[2 + indexOfWeek * 4] = (uint8_t) (value >> 16); - this->bytes[3 + indexOfWeek * 4] = (uint8_t) (value >> 24); + this->bytesStepsDayHistory[0 + indexOfWeek * 4] = (uint8_t) value; + this->bytesStepsDayHistory[1 + indexOfWeek * 4] = (uint8_t) (value >> 8); + this->bytesStepsDayHistory[2 + indexOfWeek * 4] = (uint8_t) (value >> 16); + this->bytesStepsDayHistory[3 + indexOfWeek * 4] = (uint8_t) (value >> 24); } - pCharacteristic->setValue(this->bytes, sizeof(this->bytes)); + pCharacteristic->setValue(this->bytesStepsDayHistory, sizeof(this->bytesStepsDayHistory)); } #endif #endif From 5b7f6805ae5254352550f748044c096616cce134 Mon Sep 17 00:00:00 2001 From: Ruffalo Lavoisier Date: Wed, 13 Nov 2024 14:30:01 +0900 Subject: [PATCH 4/7] Also rename bytes value to feature part --- include/services/OswServiceTaskBLEServer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/services/OswServiceTaskBLEServer.h b/include/services/OswServiceTaskBLEServer.h index 330ebff35..cd1b607fd 100644 --- a/include/services/OswServiceTaskBLEServer.h +++ b/include/services/OswServiceTaskBLEServer.h @@ -44,7 +44,7 @@ class OswServiceTaskBLEServer : public OswServiceTask { }; class CurrentTimeCharacteristicCallbacks: public NimBLECharacteristicCallbacks { void onRead(NimBLECharacteristic* pCharacteristic); - uint8_t bytes[9+1]; // will be read from (9 exact-time-256, 1 reason) + uint8_t bytesCurrentTime[9+1]; // will be read from (9 exact-time-256, 1 reason) }; class FirmwareRevisionCharacteristicCallbacks: public NimBLECharacteristicCallbacks { void onRead(NimBLECharacteristic* pCharacteristic); From 420a22bbde8335ede2c12aef564e7d470bb02533 Mon Sep 17 00:00:00 2001 From: Ruffalo Lavoisier Date: Sun, 12 Jan 2025 03:31:48 +0900 Subject: [PATCH 5/7] OswServiceTaskBLEServer: fix typo lower case on random uuid --- src/services/OswServiceTaskBLEServer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/OswServiceTaskBLEServer.cpp b/src/services/OswServiceTaskBLEServer.cpp index 55373bd2f..0ba9c99d8 100644 --- a/src/services/OswServiceTaskBLEServer.cpp +++ b/src/services/OswServiceTaskBLEServer.cpp @@ -2,7 +2,7 @@ #include "./services/OswServiceTaskBLEServer.h" #include "osw_hal.h" -#define BATTERY_SERVICE_UUID "0000180F-0000-1000-8000-00805f9b34fb" +#define BATTERY_SERVICE_UUID "0000180f-0000-1000-8000-00805f9b34fb" #define BATTERY_LEVEL_CHARACTERISTIC_UUID "00002A19-0000-1000-8000-00805f9b34fb" #define BATTERY_LEVEL_STATUS_CHARACTERISTIC_UUID "00002bed-0000-1000-8000-00805f9b34fb" #define TIME_SERVICE_UUID "00001805-0000-1000-8000-00805f9b34fb" From f4949ba9379ac82bef0fa60d1e057c17f02770b6 Mon Sep 17 00:00:00 2001 From: Ruffalo Lavoisier Date: Sun, 12 Jan 2025 03:40:17 +0900 Subject: [PATCH 6/7] OswServiceTaskBLEServer: fix data type comments --- include/services/OswServiceTaskBLEServer.h | 58 ++-------------------- 1 file changed, 5 insertions(+), 53 deletions(-) diff --git a/include/services/OswServiceTaskBLEServer.h b/include/services/OswServiceTaskBLEServer.h index cd1b607fd..df6e506bb 100644 --- a/include/services/OswServiceTaskBLEServer.h +++ b/include/services/OswServiceTaskBLEServer.h @@ -69,71 +69,23 @@ class OswServiceTaskBLEServer : public OswServiceTask { }; class StepsTodayCharacteristicCallbacks: public NimBLECharacteristicCallbacks { void onRead(NimBLECharacteristic* pCharacteristic); - /* - uint32_t value; - this->bytes[0] = (uint8_t) value; - this->bytes[1] = (uint8_t) (value >> 8); - this->bytes[2] = (uint8_t) (value >> 16); - this->bytes[3] = (uint8_t) (value >> 24); - */ - uint8_t bytesStepsToday[4]; + uint8_t bytesStepsToday[4]; // this is a 4-byte array of a uint_32_t number }; class StepsTotalWeekCharacteristicCallbacks: public NimBLECharacteristicCallbacks { void onRead(NimBLECharacteristic* pCharacteristic); - /* - uint32_t value; - this->bytes[0] = (uint8_t) value; - this->bytes[1] = (uint8_t) (value >> 8); - this->bytes[2] = (uint8_t) (value >> 16); - this->bytes[3] = (uint8_t) (value >> 24); - */ - uint8_t bytesStepsTotalWeek[4]; + uint8_t bytesStepsTotalWeek[4]; // this is a 4-byte array of a uint_32_t number }; class StepsTotalCharacteristicCallbacks: public NimBLECharacteristicCallbacks { void onRead(NimBLECharacteristic* pCharacteristic); - /* - uint32_t value; - this->bytes[0] = (uint8_t) value; - this->bytes[1] = (uint8_t) (value >> 8); - this->bytes[2] = (uint8_t) (value >> 16); - this->bytes[3] = (uint8_t) (value >> 24); - */ - uint8_t bytesStepsTotal[4]; + uint8_t bytesStepsTotal[4]; // this is a 4-byte array of a uint_32_t number }; class StepsAverageCharacteristicCallbacks: public NimBLECharacteristicCallbacks { void onRead(NimBLECharacteristic* pCharacteristic); - /* - uint32_t value; - this->bytes[0] = (uint8_t) value; - this->bytes[1] = (uint8_t) (value >> 8); - this->bytes[2] = (uint8_t) (value >> 16); - this->bytes[3] = (uint8_t) (value >> 24); - */ - uint8_t bytesStepsAverage[4]; + uint8_t bytesStepsAverage[4]; // this is a 4-byte array of a uint_32_t number }; class StepsDayHistoryCharacteristicCallbacks: public NimBLECharacteristicCallbacks { void onRead(NimBLECharacteristic* pCharacteristic); - /* - uint32_t value[7]; - this->bytes[0] = (uint8_t) value[0]; - this->bytes[1] = (uint8_t) (value[0] >> 8); - this->bytes[2] = (uint8_t) (value[0] >> 16); - this->bytes[3] = (uint8_t) (value[0] >> 24); - - this->bytes[4] = (uint8_t) value[1]; - this->bytes[5] = (uint8_t) (value[1] >> 8); - this->bytes[6] = (uint8_t) (value[1] >> 16); - this->bytes[7] = (uint8_t) (value[1] >> 24); - - this->bytes[8] = (uint8_t) value[2]; - this->bytes[9] = (uint8_t) (value[2] >> 8); - this->bytes[10] = (uint8_t) (value[2] >> 16); - this->bytes[11] = (uint8_t) (value[2] >> 24); - - ... - - */ - uint8_t bytesStepsDayHistory[4 * 7]; + uint8_t bytesStepsDayHistory[4 * 7]; // this is a 28-byte array of a seven uint_32_t number }; From 1dc25c3c697593da125213ef47e62b6d5b2098c5 Mon Sep 17 00:00:00 2001 From: Ruffalo Lavoisier Date: Sun, 12 Jan 2025 03:41:26 +0900 Subject: [PATCH 7/7] OswServiceTaskBLEServer: remove comment - just copy comment --- src/services/OswServiceTaskBLEServer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/OswServiceTaskBLEServer.cpp b/src/services/OswServiceTaskBLEServer.cpp index 0ba9c99d8..bfa26722c 100644 --- a/src/services/OswServiceTaskBLEServer.cpp +++ b/src/services/OswServiceTaskBLEServer.cpp @@ -178,7 +178,7 @@ void OswServiceTaskBLEServer::updateBLEConfig() { STEP_COUNT_DAY_HISTORY_CHARACTERISTIC_UUID, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::READ_ENC | NIMBLE_PROPERTY::READ_AUTHEN ); - this->characteristicStepCountHistory->setCallbacks(new StepsDayHistoryCharacteristicCallbacks()); // Create a BLE Characteristic: "Hardware Revision String" + this->characteristicStepCountHistory->setCallbacks(new StepsDayHistoryCharacteristicCallbacks()); #endif #endif // Start the service