AP_Scripting: add support for dependencty on manual methods, remove handling of mission commands without AP_Mission

This commit is contained in:
Iampete1 2023-10-04 18:01:20 +01:00 committed by Andrew Tridgell
parent 77e2d07979
commit 105801c5b0
5 changed files with 24 additions and 1 deletions

View File

@ -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

View File

@ -90,6 +90,7 @@ public:
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 @@ public:
uint32_t time_ms;
};
ObjectBuffer<struct scripting_mission_cmd> * mission_data;
#endif
// PWMSource storage
uint8_t num_pwm_source;

View File

@ -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

View File

@ -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;
}
}

View File

@ -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) {