summaryrefslogtreecommitdiff
path: root/src/Components/Ble/CurrentTimeClient.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Components/Ble/CurrentTimeClient.cpp')
-rw-r--r--src/Components/Ble/CurrentTimeClient.cpp51
1 files changed, 24 insertions, 27 deletions
diff --git a/src/Components/Ble/CurrentTimeClient.cpp b/src/Components/Ble/CurrentTimeClient.cpp
index 44065bce..fdebc084 100644
--- a/src/Components/Ble/CurrentTimeClient.cpp
+++ b/src/Components/Ble/CurrentTimeClient.cpp
@@ -6,25 +6,6 @@ using namespace Pinetime::Controllers;
constexpr ble_uuid16_t CurrentTimeClient::ctsServiceUuid;
constexpr ble_uuid16_t CurrentTimeClient::currentTimeCharacteristicUuid;
-int Pinetime::Controllers::CurrentTimeDiscoveryEventCallback(uint16_t conn_handle, const struct ble_gatt_error *error,
- const struct ble_gatt_svc *service, void *arg) {
- auto client = static_cast<CurrentTimeClient*>(arg);
- return client->OnDiscoveryEvent(conn_handle, error, service);
-}
-
-int Pinetime::Controllers::CurrentTimeCharacteristicDiscoveredCallback(uint16_t conn_handle, const struct ble_gatt_error *error,
- const struct ble_gatt_chr *chr, void *arg) {
- auto client = static_cast<CurrentTimeClient*>(arg);
- return client->OnCharacteristicDiscoveryEvent(conn_handle, error, chr);
-}
-
-int Pinetime::Controllers::CurrentTimeReadCallback(uint16_t conn_handle, const struct ble_gatt_error *error,
- struct ble_gatt_attr *attr, void *arg) {
- auto client = static_cast<CurrentTimeClient*>(arg);
- return client->OnCurrentTimeReadResult(conn_handle, error, attr);
-}
-
-
CurrentTimeClient::CurrentTimeClient(DateTime& dateTimeController) : dateTimeController{dateTimeController} {
}
@@ -33,10 +14,6 @@ void CurrentTimeClient::Init() {
}
-void CurrentTimeClient::StartDiscovery(uint16_t connectionHandle) {
- ble_gattc_disc_svc_by_uuid(connectionHandle, ((ble_uuid_t*)&ctsServiceUuid), CurrentTimeDiscoveryEventCallback, this);
-}
-
bool CurrentTimeClient::OnDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error *error, const ble_gatt_svc *service) {
if(service == nullptr && error->status == BLE_HS_EDONE) {
NRF_LOG_INFO("CTS Discovery complete");
@@ -45,20 +22,24 @@ bool CurrentTimeClient::OnDiscoveryEvent(uint16_t connectionHandle, const ble_ga
if(service != nullptr && ble_uuid_cmp(((ble_uuid_t*)&ctsServiceUuid), &service->uuid.u) == 0) {
NRF_LOG_INFO("CTS discovered : 0x%x", service->start_handle);
- ble_gattc_disc_chrs_by_uuid(connectionHandle, service->start_handle, service->end_handle, ((ble_uuid_t*)&currentTimeCharacteristicUuid), CurrentTimeCharacteristicDiscoveredCallback, this);
+ isDiscovered = true;
+ ctsStartHandle = service->start_handle;
+ ctsEndHandle = service->end_handle;
+ return false;
}
return false;
}
int CurrentTimeClient::OnCharacteristicDiscoveryEvent(uint16_t conn_handle, const ble_gatt_error *error,
const ble_gatt_chr *characteristic) {
- if(characteristic == nullptr && error->status == BLE_HS_EDONE)
+ if(characteristic == nullptr && error->status == BLE_HS_EDONE) {
NRF_LOG_INFO("CTS Characteristic discovery complete");
+ return 0;
+ }
if(characteristic != nullptr && ble_uuid_cmp(((ble_uuid_t*)&currentTimeCharacteristicUuid), &characteristic->uuid.u) == 0) {
NRF_LOG_INFO("CTS Characteristic discovered : 0x%x", characteristic->val_handle);
-
- ble_gattc_read(conn_handle, characteristic->val_handle, CurrentTimeReadCallback, this);
+ currentTimeHandle = characteristic->val_handle;
}
return 0;
}
@@ -78,3 +59,19 @@ int CurrentTimeClient::OnCurrentTimeReadResult(uint16_t conn_handle, const ble_g
}
return 0;
}
+
+bool CurrentTimeClient::IsDiscovered() const {
+ return isDiscovered;
+}
+
+uint16_t CurrentTimeClient::StartHandle() const {
+ return ctsStartHandle;
+}
+
+uint16_t CurrentTimeClient::EndHandle() const {
+ return ctsEndHandle;
+}
+
+uint16_t CurrentTimeClient::CurrentTimeHandle() const {
+ return currentTimeHandle;
+}