Skip to content

Commit

Permalink
Implemented resetting of knownBLEAddresses to defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-bs committed Apr 24, 2024
1 parent 17c9b01 commit 76b6513
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions src/AppLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
// 20240419 Modified downlink decoding
// 20240424 Fixes in decodeDownlink()
// Fixed getBleAddr()
// Implemented resetting of knownBLEAddresses to defaults
//
//
// ToDo:
Expand Down Expand Up @@ -139,7 +140,10 @@ AppLayer::decodeDownlink(uint8_t port, uint8_t *payload, size_t size)
payload[i + 4],
payload[i + 5]);
}

// Note: New addresses will be applied only after restart.
setBleAddr(payload, size);

return 0;
}
#endif
Expand Down Expand Up @@ -609,13 +613,6 @@ void AppLayer::setBleAddr(uint8_t *bytes, uint8_t size)
appPrefs.begin("BWS-LW-APP", false);
appPrefs.putBytes("ble", bytes, size);
appPrefs.end();

std::vector<std::string> bleAddr;
for (size_t i = 0; i < size; i += 6)
{
bleAddr.push_back(BLEAddress(&bytes[i]).toString());
}
bleSensors.setAddresses(bleAddr);
}

uint8_t AppLayer::getBleAddr(uint8_t *payload)
Expand All @@ -634,17 +631,34 @@ std::vector<std::string> AppLayer::getBleAddr(void)

appPrefs.begin("BWS-LW-APP", false);
uint8_t size = appPrefs.getBytesLength("ble");
char addrBytes[48];
uint8_t addrBytes[48];
appPrefs.getBytes("ble", addrBytes, size);
appPrefs.end();

if (size < 6)
{
// return empty list
return bleAddr;
}

uint8_t check = 0;
for (size_t i = 0; i < 6; i++)
{
check |= addrBytes[i];
}
if (check == 0)
{
// First address is 00:00:00:00:00:00, return empty list
return bleAddr;
}

for (size_t i = 0; i < size; i += 6)
{
char addr[18];
snprintf(addr, 18, "%02X:%02X:%02X:%02X:%02X:%02X",
addrBytes[i], addrBytes[i+1], addrBytes[i+2], addrBytes[i+3],addrBytes[i+4],addrBytes[i+5]
);
snprintf(addr, 18, "%02X:%02X:%02X:%02X:%02X:%02X",
addrBytes[i], addrBytes[i + 1], addrBytes[i + 2], addrBytes[i + 3], addrBytes[i + 4], addrBytes[i + 5]);
bleAddr.push_back(addr);
}
appPrefs.end();

return bleAddr;
}
Expand Down

0 comments on commit 76b6513

Please sign in to comment.