AP_Scripting: convert DEBUG_LVL to DEBUG_OPTS bitmask
This commit is contained in:
parent
9210488550
commit
817864ce74
@ -75,11 +75,12 @@ const AP_Param::GroupInfo AP_Scripting::var_info[] = {
|
||||
// @RebootRequired: True
|
||||
AP_GROUPINFO("HEAP_SIZE", 3, AP_Scripting, _script_heap_size, SCRIPTING_HEAP_SIZE),
|
||||
|
||||
// @Param: DEBUG_LVL
|
||||
// @Param: DEBUG_OPTS
|
||||
// @DisplayName: Scripting Debug Level
|
||||
// @Description: The higher the number the more verbose builtin scripting debug will be.
|
||||
// @Description: Debugging options
|
||||
// @Bitmask: 0:No Scripts to run message if all scripts have stopped, 1:Runtime messages for memory usage and execution time
|
||||
// @User: Advanced
|
||||
AP_GROUPINFO("DEBUG_LVL", 4, AP_Scripting, _debug_level, 0),
|
||||
AP_GROUPINFO("DEBUG_OPTS", 4, AP_Scripting, _debug_options, 0),
|
||||
|
||||
// @Param: USER1
|
||||
// @DisplayName: Scripting User Parameter1
|
||||
@ -210,7 +211,7 @@ void AP_Scripting::thread(void) {
|
||||
_stop = false;
|
||||
_restart = false;
|
||||
|
||||
lua_scripts *lua = new lua_scripts(_script_vm_exec_count, _script_heap_size, _debug_level, terminal);
|
||||
lua_scripts *lua = new lua_scripts(_script_vm_exec_count, _script_heap_size, _debug_options, terminal);
|
||||
if (lua == nullptr || !lua->heap_allocated()) {
|
||||
gcs().send_text(MAV_SEVERITY_CRITICAL, "Unable to allocate scripting memory");
|
||||
_init_failed = true;
|
||||
@ -237,7 +238,7 @@ void AP_Scripting::thread(void) {
|
||||
gcs().send_text(MAV_SEVERITY_CRITICAL, "Scripting restated");
|
||||
break;
|
||||
}
|
||||
if (_debug_level > 0) {
|
||||
if ((_debug_options.get() & uint8_t(lua_scripts::DebugLevel::NO_SCRIPTS_TO_RUN)) != 0) {
|
||||
gcs().send_text(MAV_SEVERITY_DEBUG, "Lua: scripting stopped");
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ private:
|
||||
AP_Int8 _enable;
|
||||
AP_Int32 _script_vm_exec_count;
|
||||
AP_Int32 _script_heap_size;
|
||||
AP_Int8 _debug_level;
|
||||
AP_Int8 _debug_options;
|
||||
AP_Int16 _dir_disable;
|
||||
|
||||
bool _init_failed; // true if memory allocation failed
|
||||
|
@ -27,9 +27,9 @@ char *lua_scripts::error_msg_buf;
|
||||
uint8_t lua_scripts::print_error_count;
|
||||
uint32_t lua_scripts::last_print_ms;
|
||||
|
||||
lua_scripts::lua_scripts(const AP_Int32 &vm_steps, const AP_Int32 &heap_size, const AP_Int8 &debug_level, struct AP_Scripting::terminal_s &_terminal)
|
||||
lua_scripts::lua_scripts(const AP_Int32 &vm_steps, const AP_Int32 &heap_size, const AP_Int8 &debug_options, struct AP_Scripting::terminal_s &_terminal)
|
||||
: _vm_steps(vm_steps),
|
||||
_debug_level(debug_level),
|
||||
_debug_options(debug_options),
|
||||
terminal(_terminal) {
|
||||
_heap = hal.util->allocate_heap_memory(heap_size);
|
||||
}
|
||||
@ -460,7 +460,7 @@ void lua_scripts::run(void) {
|
||||
hal.scheduler->delay(scripts->next_run_ms - now_ms);
|
||||
}
|
||||
|
||||
if (_debug_level > 1) {
|
||||
if ((_debug_options.get() & uint8_t(DebugLevel::RUNTIME_MSG)) != 0) {
|
||||
gcs().send_text(MAV_SEVERITY_DEBUG, "Lua: Running %s", scripts->name);
|
||||
}
|
||||
|
||||
@ -471,7 +471,7 @@ void lua_scripts::run(void) {
|
||||
|
||||
const uint32_t runEnd = AP_HAL::micros();
|
||||
const int endMem = lua_gc(L, LUA_GCCOUNT, 0) * 1024 + lua_gc(L, LUA_GCCOUNTB, 0);
|
||||
if (_debug_level > 1) {
|
||||
if ((_debug_options.get() & uint8_t(DebugLevel::RUNTIME_MSG)) != 0) {
|
||||
gcs().send_text(MAV_SEVERITY_DEBUG, "Lua: Time: %u Mem: %d + %d",
|
||||
(unsigned int)(runEnd - loadEnd),
|
||||
(int)endMem,
|
||||
@ -482,7 +482,7 @@ void lua_scripts::run(void) {
|
||||
lua_gc(L, LUA_GCCOLLECT, 0);
|
||||
|
||||
} else {
|
||||
if (_debug_level > 0) {
|
||||
if ((_debug_options.get() & uint8_t(DebugLevel::NO_SCRIPTS_TO_RUN)) != 0) {
|
||||
gcs().send_text(MAV_SEVERITY_DEBUG, "Lua: No scripts to run");
|
||||
}
|
||||
hal.scheduler->delay(1000);
|
||||
|
@ -50,7 +50,7 @@
|
||||
class lua_scripts
|
||||
{
|
||||
public:
|
||||
lua_scripts(const AP_Int32 &vm_steps, const AP_Int32 &heap_size, const AP_Int8 &debug_level, struct AP_Scripting::terminal_s &_terminal);
|
||||
lua_scripts(const AP_Int32 &vm_steps, const AP_Int32 &heap_size, const AP_Int8 &debug_options, struct AP_Scripting::terminal_s &_terminal);
|
||||
|
||||
/* Do not allow copies */
|
||||
lua_scripts(const lua_scripts &other) = delete;
|
||||
@ -63,6 +63,12 @@ public:
|
||||
void run(void);
|
||||
|
||||
static bool overtime; // script exceeded it's execution slot, and we are bailing out
|
||||
|
||||
enum class DebugLevel {
|
||||
NO_SCRIPTS_TO_RUN = 1U << 0,
|
||||
RUNTIME_MSG = 1U << 1,
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
void create_sandbox(lua_State *L);
|
||||
@ -116,7 +122,7 @@ private:
|
||||
lua_State *lua_state;
|
||||
|
||||
const AP_Int32 & _vm_steps;
|
||||
const AP_Int8 & _debug_level;
|
||||
const AP_Int8 & _debug_options;
|
||||
|
||||
static void *alloc(void *ud, void *ptr, size_t osize, size_t nsize);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user