1
0
Fork 0

Ignore notification with empty message.

This commit is contained in:
Jean-François Milants 2021-04-04 15:19:37 +02:00
parent 1b71a10beb
commit 3934e9bef2
2 changed files with 10 additions and 4 deletions

View file

@ -158,8 +158,11 @@ void AlertNotificationClient::OnNotification(ble_gap_event *event) {
const auto maxMessageSize{NotificationManager::MaximumMessageSize()}; const auto maxMessageSize{NotificationManager::MaximumMessageSize()};
const auto maxBufferSize{maxMessageSize + headerSize}; const auto maxBufferSize{maxMessageSize + headerSize};
const auto dbgPacketLen = OS_MBUF_PKTLEN(event->notify_rx.om); // Ignore notifications with empty message
size_t bufferSize = std::min(dbgPacketLen + stringTerminatorSize, maxBufferSize); 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)); auto messageSize = std::min(maxMessageSize, (bufferSize - headerSize));
NotificationManager::Notification notif; NotificationManager::Notification notif;

View file

@ -66,8 +66,11 @@ int AlertNotificationService::OnAlert(uint16_t conn_handle, uint16_t attr_handle
const auto maxMessageSize {NotificationManager::MaximumMessageSize()}; const auto maxMessageSize {NotificationManager::MaximumMessageSize()};
const auto maxBufferSize{maxMessageSize + headerSize}; const auto maxBufferSize{maxMessageSize + headerSize};
const auto dbgPacketLen = OS_MBUF_PKTLEN(ctxt->om); // Ignore notifications with empty message
size_t bufferSize = std::min(dbgPacketLen + stringTerminatorSize, maxBufferSize); 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)); auto messageSize = std::min(maxMessageSize, (bufferSize-headerSize));
Categories category; Categories category;