summaryrefslogtreecommitdiff
path: root/src/components/ble/AlertNotificationService.cpp
diff options
context:
space:
mode:
authorJF <jf@codingfield.com>2020-10-22 08:43:42 (GMT)
committerJF <jf@codingfield.com>2020-10-22 08:43:42 (GMT)
commit07b6812f61cf5b7726fbf6015c2c60caa12c7f20 (patch)
tree1dc7a0e6c2dbf9760437e61b38602f87a5537ec9 /src/components/ble/AlertNotificationService.cpp
parentcabf1168d429db84b0985e25881ead86d80dde3c (diff)
Notifications : Fix copy when the messages is spread across multiple os_mbuf.
Diffstat (limited to 'src/components/ble/AlertNotificationService.cpp')
-rw-r--r--src/components/ble/AlertNotificationService.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/components/ble/AlertNotificationService.cpp b/src/components/ble/AlertNotificationService.cpp
index 7e432b8..32711b9 100644
--- a/src/components/ble/AlertNotificationService.cpp
+++ b/src/components/ble/AlertNotificationService.cpp
@@ -54,18 +54,21 @@ AlertNotificationService::AlertNotificationService ( System::SystemTask& systemT
int AlertNotificationService::OnAlert(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt) {
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
- static constexpr size_t stringTerminatorSize{1}; // end of string '\0'
- static constexpr size_t headerSize{3};
+ constexpr size_t stringTerminatorSize = 1; // end of string '\0'
+ constexpr size_t headerSize = 3;
const auto maxMessageSize {NotificationManager::MaximumMessageSize()};
const auto maxBufferSize{maxMessageSize + headerSize};
- size_t bufferSize = min(OS_MBUF_PKTLEN(ctxt->om) + stringTerminatorSize, maxBufferSize);
- char *message = (char *)(&ctxt->om->om_data[headerSize]);
+ const auto dbgPacketLen = OS_MBUF_PKTLEN(ctxt->om);
+ size_t bufferSize = min(dbgPacketLen + stringTerminatorSize, maxBufferSize);
auto messageSize = min(maxMessageSize, (bufferSize-headerSize));
- message[messageSize-1] = '\0';
+ NotificationManager::Notification notif;
+ os_mbuf_copydata(ctxt->om, headerSize, messageSize-1, notif.message.data());
+ notif.message[messageSize-1] = '\0';
+ notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
+ notificationManager.Push(std::move(notif));
- notificationManager.Push(Pinetime::Controllers::NotificationManager::Categories::SimpleAlert, message, messageSize);
systemTask.PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification);
}
return 0;