diff options
author | JF002 <JF002@users.noreply.github.com> | 2021-02-14 12:03:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-14 12:03:49 +0100 |
commit | 4c3803450e33e321dd2f90bdf62b9abe99f1e491 (patch) | |
tree | 1b69be394c55dce4cbe64750dae6603bfd33b09c /src/components | |
parent | 6420885abb96735e085f3c60b123b0c671a7afb8 (diff) | |
parent | d4c31bcbbe2f8b6d2e6c45203193745f9cb2a41b (diff) |
Merge pull request #161 from petterhs/calls
Call functionality with changed UUID for notification event characteristic
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/ble/AlertNotificationClient.h | 2 | ||||
-rw-r--r-- | src/components/ble/AlertNotificationService.cpp | 65 | ||||
-rw-r--r-- | src/components/ble/AlertNotificationService.h | 35 | ||||
-rw-r--r-- | src/components/ble/NimbleController.h | 1 |
4 files changed, 98 insertions, 5 deletions
diff --git a/src/components/ble/AlertNotificationClient.h b/src/components/ble/AlertNotificationClient.h index fa10456c..d49205e3 100644 --- a/src/components/ble/AlertNotificationClient.h +++ b/src/components/ble/AlertNotificationClient.h @@ -83,4 +83,4 @@ namespace Pinetime { bool isDescriptorFound = false; }; } -}
\ No newline at end of file +} diff --git a/src/components/ble/AlertNotificationService.cpp b/src/components/ble/AlertNotificationService.cpp index 3156470c..0639119c 100644 --- a/src/components/ble/AlertNotificationService.cpp +++ b/src/components/ble/AlertNotificationService.cpp @@ -9,6 +9,7 @@ using namespace Pinetime::Controllers; constexpr ble_uuid16_t AlertNotificationService::ansUuid; constexpr ble_uuid16_t AlertNotificationService::ansCharUuid; +constexpr ble_uuid128_t AlertNotificationService::notificationEventUuid; int AlertNotificationCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg) { @@ -34,6 +35,13 @@ AlertNotificationService::AlertNotificationService ( System::SystemTask& systemT .flags = BLE_GATT_CHR_F_WRITE }, { + .uuid = (ble_uuid_t *) ¬ificationEventUuid, + .access_cb = AlertNotificationCallback, + .arg = this, + .flags = BLE_GATT_CHR_F_NOTIFY, + .val_handle = &eventHandle + }, + { 0 } }, @@ -61,14 +69,65 @@ int AlertNotificationService::OnAlert(uint16_t conn_handle, uint16_t attr_handle const auto dbgPacketLen = OS_MBUF_PKTLEN(ctxt->om); size_t bufferSize = std::min(dbgPacketLen + stringTerminatorSize, maxBufferSize); auto messageSize = std::min(maxMessageSize, (bufferSize-headerSize)); + Categories category; NotificationManager::Notification notif; os_mbuf_copydata(ctxt->om, headerSize, messageSize-1, notif.message.data()); + os_mbuf_copydata(ctxt->om, 0, 1, &category); notif.message[messageSize-1] = '\0'; - notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert; - notificationManager.Push(std::move(notif)); - systemTask.PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification); + // TODO convert all ANS categories to NotificationController categories + switch(category) { + case Categories::Call: + notif.category = Pinetime::Controllers::NotificationManager::Categories::IncomingCall; + break; + default: + notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert; + break; + } + + auto event = Pinetime::System::SystemTask::Messages::OnNewNotification; + notificationManager.Push(std::move(notif)); + systemTask.PushMessage(event); } return 0; } + +void AlertNotificationService::AcceptIncomingCall() { + auto response = IncomingCallResponses::Answer; + auto *om = ble_hs_mbuf_from_flat(&response, 1); + + uint16_t connectionHandle = systemTask.nimble().connHandle(); + + if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) { + return; + } + + ble_gattc_notify_custom(connectionHandle, eventHandle, om); +} + +void AlertNotificationService::RejectIncomingCall() { + auto response = IncomingCallResponses::Reject; + auto *om = ble_hs_mbuf_from_flat(&response, 1); + + uint16_t connectionHandle = systemTask.nimble().connHandle(); + + if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) { + return; + } + + ble_gattc_notify_custom(connectionHandle, eventHandle, om); +} + +void AlertNotificationService::MuteIncomingCall() { + auto response = IncomingCallResponses::Mute; + auto *om = ble_hs_mbuf_from_flat(&response, 1); + + uint16_t connectionHandle = systemTask.nimble().connHandle(); + + if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) { + return; + } + + ble_gattc_notify_custom(connectionHandle, eventHandle, om); +}
\ No newline at end of file diff --git a/src/components/ble/AlertNotificationService.h b/src/components/ble/AlertNotificationService.h index 120312d2..caad7a2b 100644 --- a/src/components/ble/AlertNotificationService.h +++ b/src/components/ble/AlertNotificationService.h @@ -7,6 +7,9 @@ #undef max #undef min +//00020001-78fc-48fe-8e23-433b3a1942d0 +#define NOTIFICATION_EVENT_SERVICE_UUID_BASE {0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, 0x01, 0x00, 0x02, 0x00} + namespace Pinetime { namespace System { @@ -24,8 +27,31 @@ namespace Pinetime { int OnAlert(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt); + void AcceptIncomingCall(); + void RejectIncomingCall(); + void MuteIncomingCall(); + + enum class IncomingCallResponses : uint8_t { + Reject = 0x00, + Answer = 0x01, + Mute = 0x02 + }; private: + enum class Categories : uint8_t { + SimpleAlert = 0x00, + Email = 0x01, + News = 0x02, + Call = 0x03, + MissedCall = 0x04, + MmsSms = 0x05, + VoiceMail = 0x06, + Schedule = 0x07, + HighPrioritizedAlert = 0x08, + InstantMessage = 0x09, + All = 0xff + }; + static constexpr uint16_t ansId {0x1811}; static constexpr uint16_t ansCharId {0x2a46}; @@ -39,11 +65,18 @@ namespace Pinetime { .value = ansCharId }; - struct ble_gatt_chr_def characteristicDefinition[2]; + static constexpr ble_uuid128_t notificationEventUuid { + .u { .type = BLE_UUID_TYPE_128 }, + .value = NOTIFICATION_EVENT_SERVICE_UUID_BASE + }; + + struct ble_gatt_chr_def characteristicDefinition[3]; struct ble_gatt_svc_def serviceDefinition[2]; Pinetime::System::SystemTask &systemTask; NotificationManager ¬ificationManager; + + uint16_t eventHandle; }; } } diff --git a/src/components/ble/NimbleController.h b/src/components/ble/NimbleController.h index a109800c..7bb135da 100644 --- a/src/components/ble/NimbleController.h +++ b/src/components/ble/NimbleController.h @@ -58,6 +58,7 @@ namespace Pinetime { Pinetime::Controllers::MusicService& music() {return musicService;}; Pinetime::Controllers::NavigationService& navigation() {return navService;}; + Pinetime::Controllers::AlertNotificationService& alertService() {return anService;}; uint16_t connHandle(); |