From a106b0dcdf1e92cb8bde8cabd8008a1a99b2d291 Mon Sep 17 00:00:00 2001 From: bugobliterator Date: Thu, 14 Sep 2023 17:18:49 +1000 Subject: [PATCH] AP_OpenDroneID: ensure Persistent memory is not read continuously --- libraries/AP_OpenDroneID/AP_OpenDroneID.cpp | 6 ++++-- libraries/AP_OpenDroneID/AP_OpenDroneID.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libraries/AP_OpenDroneID/AP_OpenDroneID.cpp b/libraries/AP_OpenDroneID/AP_OpenDroneID.cpp index f0bf5da4daeaa2..cec2a300c3844b 100644 --- a/libraries/AP_OpenDroneID/AP_OpenDroneID.cpp +++ b/libraries/AP_OpenDroneID/AP_OpenDroneID.cpp @@ -131,7 +131,7 @@ void AP_OpenDroneID::set_basic_id() { if (pkt_basic_id.id_type != MAV_ODID_ID_TYPE_NONE) { return; } - if (id_len == 0) { + if ((id_len == 0) && (_options & LockUASIDOnFirstBasicIDRx)) { load_UAS_ID_from_persistent_memory(); } if (id_len > 0) { @@ -208,10 +208,12 @@ void AP_OpenDroneID::update() if ((pkt_basic_id.id_type == MAV_ODID_ID_TYPE_SERIAL_NUMBER) && (_options & LockUASIDOnFirstBasicIDRx) - && id_len == 0) { + && id_len == 0 + && !bootloader_flashed) { hal.util->flash_bootloader(); // reset the basic id on next set_basic_id call pkt_basic_id.id_type = MAV_ODID_ID_TYPE_NONE; + bootloader_flashed = true; } set_basic_id(); diff --git a/libraries/AP_OpenDroneID/AP_OpenDroneID.h b/libraries/AP_OpenDroneID/AP_OpenDroneID.h index 5ebb6cd65f3fef..fd266568de38a4 100644 --- a/libraries/AP_OpenDroneID/AP_OpenDroneID.h +++ b/libraries/AP_OpenDroneID/AP_OpenDroneID.h @@ -117,7 +117,7 @@ class AP_OpenDroneID char id_type[3]; size_t id_len; char id_str[21]; - + bool bootloader_flashed; enum Options : int16_t { EnforceArming = (1U << 0U), AllowNonGPSPosition = (1U << 1U),