Skip to content

Commit

Permalink
AP_Scripting: add support for dependencty on manual methods, remove h…
Browse files Browse the repository at this point in the history
…andling of mission commands without AP_Mission
  • Loading branch information
IamPete1 authored and tridge committed Oct 16, 2023
1 parent 77e2d07 commit 105801c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions libraries/AP_Scripting/AP_Scripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions libraries/AP_Scripting/AP_Scripting.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -100,6 +101,7 @@ class AP_Scripting
uint32_t time_ms;
};
ObjectBuffer<struct scripting_mission_cmd> * mission_data;
#endif

// PWMSource storage
uint8_t num_pwm_source;
Expand Down
2 changes: 1 addition & 1 deletion libraries/AP_Scripting/generator/description/bindings.desc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions libraries/AP_Scripting/generator/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ struct method_alias {
int line;
int num_args;
enum alias_type type;
char *dependency;
};

struct userdata_field {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
2 changes: 2 additions & 0 deletions libraries/AP_Scripting/lua_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 105801c

Please sign in to comment.