AP_Scripting: added warning on heap expansion

This commit is contained in:
Andrew Tridgell 2024-11-17 16:10:45 +11:00
parent bfeed7cc32
commit 1cd05618f0
1 changed files with 13 additions and 0 deletions

View File

@ -540,6 +540,8 @@ void lua_scripts::run(void) {
succeeded_initial_load = true; succeeded_initial_load = true;
#endif // __clang_analyzer__ #endif // __clang_analyzer__
uint32_t expansion_size = 0;
while (AP_Scripting::get_singleton()->should_run()) { while (AP_Scripting::get_singleton()->should_run()) {
#if defined(AP_SCRIPTING_CHECKS) && AP_SCRIPTING_CHECKS >= 1 #if defined(AP_SCRIPTING_CHECKS) && AP_SCRIPTING_CHECKS >= 1
if (lua_gettop(L) != 0) { if (lua_gettop(L) != 0) {
@ -607,6 +609,17 @@ void lua_scripts::run(void) {
hal.scheduler->delay(1000); hal.scheduler->delay(1000);
} }
/*
report a warning if SCR_HEAP_SIZE wasn't adequate and we
expanded at runtime, so the user can fix it for future
flights
*/
const uint32_t new_expansion_size = _heap.get_expansion_size();
if (new_expansion_size > expansion_size) {
expansion_size = new_expansion_size;
set_and_print_new_error_message(MAV_SEVERITY_WARNING, "Required SCR_HEAP_SIZE over %u", unsigned(expansion_size));
}
// re-print the latest error message every 10 seconds 10 times // re-print the latest error message every 10 seconds 10 times
const uint8_t error_prints = 10; const uint8_t error_prints = 10;
if ((print_error_count < error_prints) && (AP_HAL::millis() - last_print_ms > 10000)) { if ((print_error_count < error_prints) && (AP_HAL::millis() - last_print_ms > 10000)) {