BTLE RX: fix for name disappearing (#1575)

* Fix for name disappearing

* cleanings

---------

Co-authored-by: GullCode <gullradriel@hotmail.com>
This commit is contained in:
gullradriel 2023-11-12 15:59:36 +01:00 committed by GitHub
parent 5953cb57b0
commit 351f7b13b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -545,32 +545,29 @@ void BLERxView::updateEntry(const BlePacketData* packet, BleRecentEntry& entry,
entry.packetData.data[i] = packet->data[i]; entry.packetData.data[i] = packet->data[i];
} }
entry.nameString = "";
entry.include_name = check_name.value(); entry.include_name = check_name.value();
// Only parse name for advertisment packets // Only parse name for advertisment packets and empty name entries
if (pdu_type == ADV_IND || pdu_type == ADV_NONCONN_IND || pdu_type == SCAN_RSP || pdu_type == ADV_SCAN_IND) { if ((pdu_type == ADV_IND || pdu_type == ADV_NONCONN_IND || pdu_type == SCAN_RSP || pdu_type == ADV_SCAN_IND) && entry.nameString.empty()) {
uint8_t currentByte = 0; uint8_t currentByte = 0;
uint8_t length = 0; uint8_t length = 0;
uint8_t type = 0; uint8_t type = 0;
bool stringFound = false; std::string decoded_data;
for (currentByte = 0; (currentByte < entry.packetData.dataLen);) { for (currentByte = 0; (currentByte < entry.packetData.dataLen);) {
length = entry.packetData.data[currentByte++]; length = entry.packetData.data[currentByte++];
type = entry.packetData.data[currentByte++]; type = entry.packetData.data[currentByte++];
// Subtract 1 because type is part of the length. // Subtract 1 because type is part of the length.
for (int i = 0; i < length - 1; i++) { for (int i = 0; i < length - 1; i++) {
if (((type == 0x08) || (type == 0x09)) && !stringFound) { if (type == 0x08 || type == 0x09) {
entry.nameString += (char)entry.packetData.data[currentByte]; decoded_data += (char)entry.packetData.data[currentByte];
} }
currentByte++; currentByte++;
} }
if (!decoded_data.empty()) {
if (!entry.nameString.empty()) { entry.nameString = std::move(decoded_data);
stringFound = true; break;
} }
} }
} }