diff options
| author | Adam Pigg <adam@piggz.co.uk> | 2020-07-11 21:41:20 +0100 |
|---|---|---|
| committer | Adam Pigg <adam@piggz.co.uk> | 2020-07-11 21:41:20 +0100 |
| commit | 789e06fdb77704fa5da12355ad5f1d8c9d4455e5 (patch) | |
| tree | 56972f902675749e0df58e91d8670dd5215d677e /src/Components/Ble/AlertNotificationClient.cpp | |
| parent | 7a1e6e6e5bf187846bd533f04ee58e04798f0035 (diff) | |
| parent | 6309719a62436fd746a7a8b228205e93b419ca26 (diff) | |
Merge branch 'develop' of https://github.com/JF002/Pinetime into music
Diffstat (limited to 'src/Components/Ble/AlertNotificationClient.cpp')
| -rw-r--r-- | src/Components/Ble/AlertNotificationClient.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/Components/Ble/AlertNotificationClient.cpp b/src/Components/Ble/AlertNotificationClient.cpp index bf4d851c..b65e019d 100644 --- a/src/Components/Ble/AlertNotificationClient.cpp +++ b/src/Components/Ble/AlertNotificationClient.cpp @@ -105,14 +105,25 @@ int AlertNotificationClient::OnDescriptorDiscoveryEventCallback(uint16_t connect void AlertNotificationClient::OnNotification(ble_gap_event *event) { if(event->notify_rx.attr_handle == newAlertHandle) { - size_t notifSize = OS_MBUF_PKTLEN(event->notify_rx.om); - uint8_t data[notifSize + 1]; - data[notifSize] = '\0'; - os_mbuf_copydata(event->notify_rx.om, 0, notifSize, data); - char *s = (char *) &data[2]; - NRF_LOG_INFO("DATA : %s", s); + // TODO implement this with more memory safety (and constexpr) + static const size_t maxBufferSize{21}; + static const size_t maxMessageSize{18}; + size_t bufferSize = min(OS_MBUF_PKTLEN(event->notify_rx.om), maxBufferSize); - notificationManager.Push(Pinetime::Controllers::NotificationManager::Categories::SimpleAlert, s, notifSize + 1); + uint8_t data[bufferSize]; + os_mbuf_copydata(event->notify_rx.om, 0, bufferSize, data); + + char *s = (char *) &data[3]; + auto messageSize = min(maxMessageSize, (bufferSize-3)); + + for (int i = 0; i < messageSize-1; i++) { + if (s[i] == 0x00) { + s[i] = 0x0A; + } + } + s[messageSize-1] = '\0'; + + notificationManager.Push(Pinetime::Controllers::NotificationManager::Categories::SimpleAlert, s, messageSize); systemTask.PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification); } } |
