diff options
author | Jean-François Milants <jf@codingfield.com> | 2021-04-09 21:16:21 +0200 |
---|---|---|
committer | Jean-François Milants <jf@codingfield.com> | 2021-04-09 21:16:21 +0200 |
commit | 15b3b8e282dd5b2132b0095716cd9d88740d4579 (patch) | |
tree | c26870103f8baaa933399cfb86cca25aa7e60d8b /src/components/ble | |
parent | 9ac4be8b759bb2cedeb999ce5e87d983261beded (diff) | |
parent | 57b4c3f0edc6acfa31bd2160abdcd6091920ba63 (diff) |
Merge branch 'develop' into motion-sensor
# Conflicts:
# src/CMakeLists.txt
# src/displayapp/Apps.h
# src/displayapp/DisplayApp.cpp
# src/displayapp/DisplayApp.h
# src/displayapp/lv_pinetime_theme.c
# src/displayapp/screens/ApplicationList.cpp
# src/drivers/TwiMaster.cpp
# src/systemtask/SystemTask.h
Diffstat (limited to 'src/components/ble')
-rw-r--r-- | src/components/ble/AlertNotificationClient.cpp | 8 | ||||
-rw-r--r-- | src/components/ble/AlertNotificationService.cpp | 8 | ||||
-rw-r--r-- | src/components/ble/MusicService.cpp | 3 | ||||
-rw-r--r-- | src/components/ble/NavigationService.cpp | 1 | ||||
-rw-r--r-- | src/components/ble/NotificationManager.cpp | 16 | ||||
-rw-r--r-- | src/components/ble/NotificationManager.h | 4 |
6 files changed, 33 insertions, 7 deletions
diff --git a/src/components/ble/AlertNotificationClient.cpp b/src/components/ble/AlertNotificationClient.cpp index e7a18626..9efede39 100644 --- a/src/components/ble/AlertNotificationClient.cpp +++ b/src/components/ble/AlertNotificationClient.cpp @@ -158,13 +158,17 @@ void AlertNotificationClient::OnNotification(ble_gap_event *event) { const auto maxMessageSize{NotificationManager::MaximumMessageSize()}; const auto maxBufferSize{maxMessageSize + headerSize}; - const auto dbgPacketLen = OS_MBUF_PKTLEN(event->notify_rx.om); - size_t bufferSize = std::min(dbgPacketLen + stringTerminatorSize, maxBufferSize); + // Ignore notifications with empty message + const auto packetLen = OS_MBUF_PKTLEN(event->notify_rx.om); + if(packetLen <= headerSize) return; + + size_t bufferSize = std::min(packetLen + stringTerminatorSize, maxBufferSize); auto messageSize = std::min(maxMessageSize, (bufferSize - headerSize)); NotificationManager::Notification notif; os_mbuf_copydata(event->notify_rx.om, headerSize, messageSize - 1, notif.message.data()); notif.message[messageSize - 1] = '\0'; + notif.size = messageSize; notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert; notificationManager.Push(std::move(notif)); diff --git a/src/components/ble/AlertNotificationService.cpp b/src/components/ble/AlertNotificationService.cpp index 0639119c..d91e2090 100644 --- a/src/components/ble/AlertNotificationService.cpp +++ b/src/components/ble/AlertNotificationService.cpp @@ -66,8 +66,11 @@ int AlertNotificationService::OnAlert(uint16_t conn_handle, uint16_t attr_handle const auto maxMessageSize {NotificationManager::MaximumMessageSize()}; const auto maxBufferSize{maxMessageSize + headerSize}; - const auto dbgPacketLen = OS_MBUF_PKTLEN(ctxt->om); - size_t bufferSize = std::min(dbgPacketLen + stringTerminatorSize, maxBufferSize); + // Ignore notifications with empty message + const auto packetLen = OS_MBUF_PKTLEN(ctxt->om); + if(packetLen <= headerSize) return 0; + + size_t bufferSize = std::min(packetLen + stringTerminatorSize, maxBufferSize); auto messageSize = std::min(maxMessageSize, (bufferSize-headerSize)); Categories category; @@ -75,6 +78,7 @@ int AlertNotificationService::OnAlert(uint16_t conn_handle, uint16_t attr_handle 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.size = messageSize; // TODO convert all ANS categories to NotificationController categories switch(category) { diff --git a/src/components/ble/MusicService.cpp b/src/components/ble/MusicService.cpp index bd6e27fb..1230ad57 100644 --- a/src/components/ble/MusicService.cpp +++ b/src/components/ble/MusicService.cpp @@ -164,7 +164,7 @@ Pinetime::Controllers::MusicService::MusicService(Pinetime::System::SystemTask & artistName = "Waiting for"; albumName = ""; - trackName = "track information..."; + trackName = "track information.."; playing = false; repeat = false; shuffle = false; @@ -191,7 +191,6 @@ int Pinetime::Controllers::MusicService::OnCommand(uint16_t conn_handle, uint16_ data[notifSize] = '\0'; os_mbuf_copydata(ctxt->om, 0, notifSize, data); char *s = (char *) &data[0]; - NRF_LOG_INFO("DATA : %s", s); if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t *) &msArtistCharUuid) == 0) { artistName = s; } else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t *) &msTrackCharUuid) == 0) { diff --git a/src/components/ble/NavigationService.cpp b/src/components/ble/NavigationService.cpp index 3c1fd162..545c44da 100644 --- a/src/components/ble/NavigationService.cpp +++ b/src/components/ble/NavigationService.cpp @@ -101,7 +101,6 @@ int Pinetime::Controllers::NavigationService::OnCommand(uint16_t conn_handle, ui data[notifSize] = '\0'; os_mbuf_copydata(ctxt->om, 0, notifSize, data); char *s = (char *) &data[0]; - NRF_LOG_INFO("DATA : %s", s); if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t *) &navFlagCharUuid) == 0) { m_flag = s; } else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t *) &navNarrativeCharUuid) == 0) { diff --git a/src/components/ble/NotificationManager.cpp b/src/components/ble/NotificationManager.cpp index 36abf026..88e83b92 100644 --- a/src/components/ble/NotificationManager.cpp +++ b/src/components/ble/NotificationManager.cpp @@ -87,3 +87,19 @@ size_t NotificationManager::NbNotifications() const { return std::count_if(notifications.begin(), notifications.end(), [](const Notification& n){ return n.valid;}); } +const char* NotificationManager::Notification::Message() const { + const char* itField = std::find(message.begin(), message.begin()+size-1, '\0'); + if(itField != message.begin()+size-1) { + const char* ptr = (itField)+1; + return ptr; + } + return const_cast<char*>(message.data()); +} + +const char* NotificationManager::Notification::Title() const { + const char * itField = std::find(message.begin(), message.begin()+size-1, '\0'); + if(itField != message.begin()+size-1) { + return message.data(); + } + return {}; +} diff --git a/src/components/ble/NotificationManager.h b/src/components/ble/NotificationManager.h index 075a9a45..486bba15 100644 --- a/src/components/ble/NotificationManager.h +++ b/src/components/ble/NotificationManager.h @@ -17,8 +17,12 @@ namespace Pinetime { Id id; bool valid = false; uint8_t index; + uint8_t size; std::array<char, MessageSize+1> message; Categories category = Categories::Unknown; + + const char* Message() const; + const char* Title() const; }; Notification::Id nextId {0}; |