From 105801c5b02c2004cf125660d9f75e27c83c9f98 Mon Sep 17 00:00:00 2001 From: Iampete1 Date: Wed, 4 Oct 2023 18:01:20 +0100 Subject: [PATCH] AP_Scripting: add support for dependencty on manual methods, remove handling of mission commands without AP_Mission --- libraries/AP_Scripting/AP_Scripting.cpp | 2 ++ libraries/AP_Scripting/AP_Scripting.h | 2 ++ .../generator/description/bindings.desc | 2 +- libraries/AP_Scripting/generator/src/main.c | 17 +++++++++++++++++ libraries/AP_Scripting/lua_bindings.cpp | 2 ++ 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/libraries/AP_Scripting/AP_Scripting.cpp b/libraries/AP_Scripting/AP_Scripting.cpp index 1e1bfc96f9f1b..a31ba85f86450 100644 --- a/libraries/AP_Scripting/AP_Scripting.cpp +++ b/libraries/AP_Scripting/AP_Scripting.cpp @@ -304,6 +304,7 @@ void AP_Scripting::thread(void) { void AP_Scripting::handle_mission_command(const AP_Mission::Mission_Command& cmd_in) { +#if AP_MISSION_ENABLED if (!_enable) { return; } @@ -328,6 +329,7 @@ void AP_Scripting::handle_mission_command(const AP_Mission::Mission_Command& cmd AP_HAL::millis()}; mission_data->push(cmd); +#endif } bool AP_Scripting::arming_checks(size_t buflen, char *buffer) const diff --git a/libraries/AP_Scripting/AP_Scripting.h b/libraries/AP_Scripting/AP_Scripting.h index 8142ce356c189..bc057eb7335a7 100644 --- a/libraries/AP_Scripting/AP_Scripting.h +++ b/libraries/AP_Scripting/AP_Scripting.h @@ -90,6 +90,7 @@ class AP_Scripting ScriptingCANSensor *_CAN_dev2; #endif +#if AP_MISSION_ENABLED // mission item buffer static const int mission_cmd_queue_size = 5; struct scripting_mission_cmd { @@ -100,6 +101,7 @@ class AP_Scripting uint32_t time_ms; }; ObjectBuffer * mission_data; +#endif // PWMSource storage uint8_t num_pwm_source; diff --git a/libraries/AP_Scripting/generator/description/bindings.desc b/libraries/AP_Scripting/generator/description/bindings.desc index a492819b13e58..54285356bd807 100644 --- a/libraries/AP_Scripting/generator/description/bindings.desc +++ b/libraries/AP_Scripting/generator/description/bindings.desc @@ -760,7 +760,7 @@ singleton i2c manual get_device lua_get_i2c_device 4 global manual millis lua_millis 0 global manual micros lua_micros 0 -global manual mission_receive lua_mission_receive 0 +global manual mission_receive lua_mission_receive 0 depends AP_MISSION_ENABLED userdata uint32_t creation lua_new_uint32_t 1 userdata uint32_t manual_operator __add uint32_t___add diff --git a/libraries/AP_Scripting/generator/src/main.c b/libraries/AP_Scripting/generator/src/main.c index 57e90b36e22a5..b414f45546c10 100644 --- a/libraries/AP_Scripting/generator/src/main.c +++ b/libraries/AP_Scripting/generator/src/main.c @@ -368,6 +368,7 @@ struct method_alias { int line; int num_args; enum alias_type type; + char *dependency; }; struct userdata_field { @@ -887,6 +888,20 @@ void handle_manual(struct userdata *node, enum alias_type type) { } alias->num_args = atoi(num_args); } + + char *depends_keyword = next_token(); + if (depends_keyword != NULL) { + if (strcmp(depends_keyword, keyword_depends) != 0) { + error(ERROR_SINGLETON, "Expected depends keyword for manual method %s %s, got: %s", node->name, name, depends_keyword); + } else { + char *dependency = strtok(NULL, ""); + if (dependency == NULL) { + error(ERROR_USERDATA, "Expected dependency string for global %s on line", name, state.line_num); + } + string_copy(&(alias->dependency), dependency); + } + } + alias->next = node->method_aliases; node->method_aliases = alias; } @@ -2414,7 +2429,9 @@ void emit_sandbox(void) { if (manual_aliases->type != ALIAS_TYPE_MANUAL) { error(ERROR_GLOBALS, "Globals only support manual methods"); } + start_dependency(source, manual_aliases->dependency); fprintf(source, " {\"%s\", %s},\n", manual_aliases->alias, manual_aliases->name); + end_dependency(source, manual_aliases->dependency); manual_aliases = manual_aliases->next; } } diff --git a/libraries/AP_Scripting/lua_bindings.cpp b/libraries/AP_Scripting/lua_bindings.cpp index 02e3c414bef19..1ff491ed74078 100644 --- a/libraries/AP_Scripting/lua_bindings.cpp +++ b/libraries/AP_Scripting/lua_bindings.cpp @@ -215,6 +215,7 @@ int lua_mavlink_block_command(lua_State *L) { } #endif // HAL_GCS_ENABLED +#if AP_MISSION_ENABLED int lua_mission_receive(lua_State *L) { binding_argcheck(L, 0); @@ -242,6 +243,7 @@ int lua_mission_receive(lua_State *L) { return 5; } +#endif // AP_MISSION_ENABLED #if HAL_LOGGING_ENABLED int AP_Logger_Write(lua_State *L) {