Ignore seen phoneapi packets (#4888)

* Ignore PhoneAPI packet if it's been seen

* ignoramus

* Also keep track of the last 20 packet IDs

* Fill

* Make this match the nimble one

* Add the log too

* Ignore zero ID packets

* Remove message entirely

* TRunkt
This commit is contained in:
Ben Meadors
2024-09-27 20:09:53 -05:00
committed by GitHub
parent 0e0811eccd
commit 8efc15f4d9
6 changed files with 52 additions and 6 deletions

View File

@@ -44,6 +44,9 @@ static BluetoothPhoneAPI *bluetoothPhoneAPI;
* Subclasses can use this as a hook to provide custom notifications for their transport (i.e. bluetooth notifies)
*/
// Last ToRadio value received from the phone
static uint8_t lastToRadio[MAX_TO_FROM_RADIO_SIZE];
class NimbleBluetoothToRadioCallback : public NimBLECharacteristicCallbacks
{
virtual void onWrite(NimBLECharacteristic *pCharacteristic)
@@ -51,7 +54,13 @@ class NimbleBluetoothToRadioCallback : public NimBLECharacteristicCallbacks
LOG_INFO("To Radio onwrite\n");
auto val = pCharacteristic->getValue();
bluetoothPhoneAPI->handleToRadio(val.data(), val.length());
if (memcmp(lastToRadio, val.data(), val.length()) != 0) {
LOG_DEBUG("New ToRadio packet\n");
memcpy(lastToRadio, val.data(), val.length());
bluetoothPhoneAPI->handleToRadio(val.data(), val.length());
} else {
LOG_DEBUG("Dropping duplicate ToRadio packet we just saw\n");
}
}
};