From 9935fb193c7f8c109d8fc4de6e030d4146f35f5f Mon Sep 17 00:00:00 2001 From: Adam Pigg Date: Mon, 4 May 2020 21:43:51 +0100 Subject: [PATCH] Move PinetimeService to CurrentTimeService witha view to implement CTS for time handling --- src/CMakeLists.txt | 2 +- ...timeService.cpp => CurrentTimeService.cpp} | 27 ++++++++++--------- ...PinetimeService.h => CurrentTimeService.h} | 18 ++++++------- src/Components/Ble/NimbleController.cpp | 4 +-- src/Components/Ble/NimbleController.h | 4 +-- 5 files changed, 27 insertions(+), 28 deletions(-) rename src/Components/Ble/{PinetimeService.cpp => CurrentTimeService.cpp} (59%) rename src/Components/Ble/{PinetimeService.h => CurrentTimeService.h} (68%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e2bf9620..11a345c1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -319,7 +319,7 @@ list(APPEND SOURCE_FILES Components/Ble/DeviceInformationService.cpp Components/Ble/CurrentTimeClient.cpp Components/Ble/AlertNotificationClient.cpp - Components/Ble/PinetimeService.cpp + Components/Ble/CurrentTimeService.cpp Components/Ble/AlertNotificationService.cpp drivers/Cst816s.cpp FreeRTOS/port.c diff --git a/src/Components/Ble/PinetimeService.cpp b/src/Components/Ble/CurrentTimeService.cpp similarity index 59% rename from src/Components/Ble/PinetimeService.cpp rename to src/Components/Ble/CurrentTimeService.cpp index e18d78aa..0af20dd3 100644 --- a/src/Components/Ble/PinetimeService.cpp +++ b/src/Components/Ble/CurrentTimeService.cpp @@ -1,24 +1,24 @@ -#include "PinetimeService.h" +#include "CurrentTimeService.h" #include using namespace Pinetime::Controllers; -constexpr ble_uuid16_t PinetimeService::pinetimeUuid; -constexpr ble_uuid16_t PinetimeService::timeUuid; +constexpr ble_uuid16_t CurrentTimeService::ctsUuid; +constexpr ble_uuid16_t CurrentTimeService::ctChrUuid; -int PinetimeTimeCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg) { - auto pinetimeService = static_cast(arg); - return pinetimeService->OnTimeAccessed(conn_handle, attr_handle, ctxt); +int CTSCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg) { + auto cts = static_cast(arg); + return cts->OnTimeAccessed(conn_handle, attr_handle, ctxt); } -void PinetimeService::Init() { +void CurrentTimeService::Init() { ble_gatts_count_cfg(serviceDefinition); ble_gatts_add_svcs(serviceDefinition); } -int PinetimeService::OnTimeAccessed(uint16_t conn_handle, uint16_t attr_handle, +int CurrentTimeService::OnTimeAccessed(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt) { NRF_LOG_INFO("Setting time..."); @@ -35,17 +35,18 @@ int PinetimeService::OnTimeAccessed(uint16_t conn_handle, uint16_t attr_handle, 0, result.hour, result.minute, result.second, nrf_rtc_counter_get(portNRF_RTC_REG)); } + //!TODO need to support reading the time. return 0; } -PinetimeService::PinetimeService(DateTime &dateTimeController) : m_dateTimeController{dateTimeController}, +CurrentTimeService::CurrentTimeService(DateTime &dateTimeController) : m_dateTimeController{dateTimeController}, characteristicDefinition{ { - .uuid = (ble_uuid_t *) &timeUuid, - .access_cb = PinetimeTimeCallback, + .uuid = (ble_uuid_t *) &ctChrUuid, + .access_cb = CTSCallback, .arg = this, - .flags = BLE_GATT_CHR_F_WRITE + .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ }, { 0 @@ -55,7 +56,7 @@ PinetimeService::PinetimeService(DateTime &dateTimeController) : m_dateTimeContr { /* Device Information Service */ .type = BLE_GATT_SVC_TYPE_PRIMARY, - .uuid = (ble_uuid_t *) &pinetimeUuid, + .uuid = (ble_uuid_t *) &ctsUuid, .characteristics = characteristicDefinition }, { diff --git a/src/Components/Ble/PinetimeService.h b/src/Components/Ble/CurrentTimeService.h similarity index 68% rename from src/Components/Ble/PinetimeService.h rename to src/Components/Ble/CurrentTimeService.h index 0cae8345..58bc5ba6 100644 --- a/src/Components/Ble/PinetimeService.h +++ b/src/Components/Ble/CurrentTimeService.h @@ -6,28 +6,26 @@ namespace Pinetime { namespace Controllers { - class PinetimeService { + class CurrentTimeService { public: - PinetimeService(DateTime &dateTimeController); + CurrentTimeService(DateTime &dateTimeController); void Init(); int OnTimeAccessed(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt); - void setDateTimeController(DateTime *dateTimeController); - private: - static constexpr uint16_t pinetimeId {0x6666}; - static constexpr uint16_t timeCharId {0x6667}; + static constexpr uint16_t ctsId {0x1805}; + static constexpr uint16_t ctsCharId {0x2a2b}; - static constexpr ble_uuid16_t pinetimeUuid { + static constexpr ble_uuid16_t ctsUuid { .u { .type = BLE_UUID_TYPE_16 }, - .value = pinetimeId + .value = ctsId }; - static constexpr ble_uuid16_t timeUuid { + static constexpr ble_uuid16_t ctChrUuid { .u { .type = BLE_UUID_TYPE_16 }, - .value = timeCharId + .value = ctsCharId }; struct ble_gatt_chr_def characteristicDefinition[2]; diff --git a/src/Components/Ble/NimbleController.cpp b/src/Components/Ble/NimbleController.cpp index 90f60c0d..3e549653 100644 --- a/src/Components/Ble/NimbleController.cpp +++ b/src/Components/Ble/NimbleController.cpp @@ -30,7 +30,7 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask, currentTimeClient{dateTimeController}, alertNotificationClient{systemTask, notificationManager}, anService{systemTask, notificationManager}, - pinetimeService{dateTimeController} { + currentTimeService{dateTimeController} { } @@ -74,7 +74,7 @@ void NimbleController::Init() { deviceInformationService.Init(); currentTimeClient.Init(); - pinetimeService.Init(); + currentTimeService.Init(); anService.Init(); diff --git a/src/Components/Ble/NimbleController.h b/src/Components/Ble/NimbleController.h index 13dfbdb0..7a08a73c 100644 --- a/src/Components/Ble/NimbleController.h +++ b/src/Components/Ble/NimbleController.h @@ -5,7 +5,7 @@ #include "AlertNotificationClient.h" #include "DeviceInformationService.h" #include "CurrentTimeClient.h" -#include "PinetimeService.h" +#include "CurrentTimeService.h" #include namespace Pinetime { @@ -37,7 +37,7 @@ namespace Pinetime { CurrentTimeClient currentTimeClient; AlertNotificationService anService; AlertNotificationClient alertNotificationClient; - PinetimeService pinetimeService; + CurrentTimeService currentTimeService; uint8_t addrType; uint16_t connectionHandle;