ref: 45e65b66b11b6b8533b225067ce4c2a4b5eac653
src/components/ble/CurrentTimeClient.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
#pragma once #include <cstdint> #include <array> #include "components/datetime/DateTimeController.h" #include <host/ble_gap.h> namespace Pinetime { namespace Controllers { class CurrentTimeClient { public: explicit CurrentTimeClient(DateTime& dateTimeController); void Init(); bool OnDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error *error, const ble_gatt_svc *service); int OnCharacteristicDiscoveryEvent(uint16_t conn_handle, const ble_gatt_error *error, const ble_gatt_chr *characteristic); int OnCurrentTimeReadResult(uint16_t conn_handle, const ble_gatt_error *error, const ble_gatt_attr *attribute); bool IsDiscovered() const; uint16_t StartHandle() const; uint16_t EndHandle() const; uint16_t CurrentTimeHandle() const; static constexpr const ble_uuid16_t* Uuid() { return &CurrentTimeClient::ctsServiceUuid; } static constexpr const ble_uuid16_t* CurrentTimeCharacteristicUuid() { return &CurrentTimeClient::currentTimeCharacteristicUuid; } private: typedef struct __attribute__((packed)) { uint16_t year; uint8_t month; uint8_t dayofmonth; uint8_t hour; uint8_t minute; uint8_t second; uint8_t millis; uint8_t reason; } CtsData; static constexpr uint16_t ctsServiceId {0x1805}; static constexpr uint16_t currentTimeCharacteristicId {0x2a2b}; static constexpr ble_uuid16_t ctsServiceUuid { .u { .type = BLE_UUID_TYPE_16 }, .value = ctsServiceId }; static constexpr ble_uuid16_t currentTimeCharacteristicUuid { .u { .type = BLE_UUID_TYPE_16 }, .value = currentTimeCharacteristicId }; uint16_t currentTimeHandle; DateTime& dateTimeController; bool isDiscovered = false; uint16_t ctsStartHandle; uint16_t ctsEndHandle; }; } } |