Compare commits

...

4 commits

Author SHA1 Message Date
FintasticMan ba07ebd798
Merge d7ca78b24e into 8598142c27 2024-10-19 20:29:10 +02:00
NeroBurner 8598142c27
Remove unused submodule QCBOR (#2138)
Some checks failed
CI / build-firmware (push) Successful in 5m57s
CI / build-simulator (push) Failing after 3s
CI / get-base-ref-size (push) Has been skipped
CI / Compare build size (push) Has been skipped
The submodule isn't used anymore. Remove the submodule reference
completely.
2024-10-09 20:26:08 +02:00
Finlay Davidson d7ca78b24e alertnotificationservice: Make use of extra char in message array for \0
Also move category reading down for clarity
2023-03-17 14:18:29 +01:00
Finlay Davidson d1b16a7dcb alertnotificationclient: Make use of extra char in message array for \0 2023-03-17 14:12:20 +01:00
4 changed files with 18 additions and 28 deletions

3
.gitmodules vendored
View file

@ -4,9 +4,6 @@
[submodule "src/libs/littlefs"]
path = src/libs/littlefs
url = https://github.com/littlefs-project/littlefs.git
[submodule "src/libs/QCBOR"]
path = src/libs/QCBOR
url = https://github.com/laurencelundblade/QCBOR.git
[submodule "src/libs/arduinoFFT"]
path = src/libs/arduinoFFT
url = https://github.com/kosme/arduinoFFT.git

View file

@ -143,24 +143,22 @@ int AlertNotificationClient::OnDescriptorDiscoveryEventCallback(uint16_t connect
void AlertNotificationClient::OnNotification(ble_gap_event* event) {
if (event->notify_rx.attr_handle == newAlertHandle) {
constexpr size_t stringTerminatorSize = 1; // end of string '\0'
constexpr size_t headerSize = 3;
const auto maxMessageSize {NotificationManager::MaximumMessageSize()};
const auto maxBufferSize {maxMessageSize + headerSize};
constexpr uint32_t headerSize = 3;
constexpr uint32_t maxMessageSize = NotificationManager::MaximumMessageSize();
// Ignore notifications with empty message
const auto packetLen = OS_MBUF_PKTLEN(event->notify_rx.om);
if (packetLen <= headerSize)
const uint32_t 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));
const uint32_t messageSize = std::min(maxMessageSize, packetLen - headerSize);
NotificationManager::Notification notif;
os_mbuf_copydata(event->notify_rx.om, headerSize, messageSize - 1, notif.message.data());
notif.message[messageSize - 1] = '\0';
os_mbuf_copydata(event->notify_rx.om, headerSize, messageSize, notif.message.data());
notif.message[messageSize] = '\0';
notif.size = messageSize;
notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
notif.category = NotificationManager::Categories::SimpleAlert;
notificationManager.Push(std::move(notif));
systemTask.PushMessage(Pinetime::System::Messages::OnNewNotification);

View file

@ -46,27 +46,24 @@ AlertNotificationService::AlertNotificationService(System::SystemTask& systemTas
int AlertNotificationService::OnAlert(struct ble_gatt_access_ctxt* ctxt) {
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
constexpr size_t stringTerminatorSize = 1; // end of string '\0'
constexpr size_t headerSize = 3;
const auto maxMessageSize {NotificationManager::MaximumMessageSize()};
const auto maxBufferSize {maxMessageSize + headerSize};
constexpr uint32_t headerSize = 3;
constexpr uint32_t maxMessageSize = NotificationManager::MaximumMessageSize();
// Ignore notifications with empty message
const auto packetLen = OS_MBUF_PKTLEN(ctxt->om);
const uint32_t 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;
const uint32_t messageSize = std::min(maxMessageSize, packetLen - headerSize);
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';
os_mbuf_copydata(ctxt->om, headerSize, messageSize, notif.message.data());
notif.message[messageSize] = '\0';
notif.size = messageSize;
Categories category;
os_mbuf_copydata(ctxt->om, 0, 1, &category);
// TODO convert all ANS categories to NotificationController categories
switch (category) {
case Categories::Call:
@ -77,9 +74,8 @@ int AlertNotificationService::OnAlert(struct ble_gatt_access_ctxt* ctxt) {
break;
}
auto event = Pinetime::System::Messages::OnNewNotification;
notificationManager.Push(std::move(notif));
systemTask.PushMessage(event);
systemTask.PushMessage(Pinetime::System::Messages::OnNewNotification);
}
return 0;
}

@ -1 +0,0 @@
Subproject commit 56b17bf9f74096774944bcac0829adcd887d391e