AP_Scripting: add some missing dependencies

This commit is contained in:
Iampete1
2023-09-26 11:29:42 +10:00
committed by Andrew Tridgell
parent 82628c2559
commit 7bbd4a7c7d
5 changed files with 37 additions and 17 deletions
+13 -9
View File
@@ -154,17 +154,18 @@ void AP_Scripting::init(void) {
const char *dir_name = SCRIPTING_DIRECTORY;
if (AP::FS().mkdir(dir_name)) {
if (errno != EEXIST) {
gcs().send_text(MAV_SEVERITY_INFO, "Scripting: failed to create (%s)", dir_name);
GCS_SEND_TEXT(MAV_SEVERITY_INFO, "Scripting: failed to create (%s)", dir_name);
}
}
if (!hal.scheduler->thread_create(FUNCTOR_BIND_MEMBER(&AP_Scripting::thread, void),
"Scripting", SCRIPTING_STACK_SIZE, AP_HAL::Scheduler::PRIORITY_SCRIPTING, 0)) {
gcs().send_text(MAV_SEVERITY_ERROR, "Scripting: %s", "failed to start");
GCS_SEND_TEXT(MAV_SEVERITY_ERROR, "Scripting: %s", "failed to start");
_thread_failed = true;
}
}
#if HAL_GCS_ENABLED
MAV_RESULT AP_Scripting::handle_command_int_packet(const mavlink_command_int_t &packet) {
switch ((SCRIPTING_CMD)packet.param1) {
case SCRIPTING_CMD_REPL_START:
@@ -186,6 +187,7 @@ MAV_RESULT AP_Scripting::handle_command_int_packet(const mavlink_command_int_t &
return MAV_RESULT_UNSUPPORTED;
}
#endif
bool AP_Scripting::repl_start(void) {
if (terminal.session) { // it's already running, this is fine
@@ -197,7 +199,7 @@ bool AP_Scripting::repl_start(void) {
if ((AP::FS().stat(REPL_DIRECTORY, &st) == -1) &&
(AP::FS().unlink(REPL_DIRECTORY) == -1) &&
(errno != EEXIST)) {
gcs().send_text(MAV_SEVERITY_INFO, "Scripting: Unable to delete old REPL %s", strerror(errno));
GCS_SEND_TEXT(MAV_SEVERITY_INFO, "Scripting: Unable to delete old REPL %s", strerror(errno));
}
// create a new folder
@@ -209,7 +211,7 @@ bool AP_Scripting::repl_start(void) {
// make the output pointer
terminal.output_fd = AP::FS().open(REPL_OUT, O_WRONLY|O_CREAT|O_TRUNC);
if (terminal.output_fd == -1) {
gcs().send_text(MAV_SEVERITY_INFO, "Scripting: %s", "Unable to make new REPL");
GCS_SEND_TEXT(MAV_SEVERITY_INFO, "Scripting: %s", "Unable to make new REPL");
return false;
}
@@ -240,14 +242,14 @@ void AP_Scripting::thread(void) {
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, "Scripting: %s", "Unable to allocate memory");
GCS_SEND_TEXT(MAV_SEVERITY_CRITICAL, "Scripting: %s", "Unable to allocate memory");
_init_failed = true;
} else {
// run won't return while scripting is still active
lua->run();
// only reachable if the lua backend has died for any reason
gcs().send_text(MAV_SEVERITY_CRITICAL, "Scripting: %s", "stopped");
GCS_SEND_TEXT(MAV_SEVERITY_CRITICAL, "Scripting: %s", "stopped");
}
delete lua;
lua = nullptr;
@@ -289,11 +291,11 @@ void AP_Scripting::thread(void) {
}
// must be enabled to get this far
if (cleared || _restart) {
gcs().send_text(MAV_SEVERITY_CRITICAL, "Scripting: %s", "restarted");
GCS_SEND_TEXT(MAV_SEVERITY_CRITICAL, "Scripting: %s", "restarted");
break;
}
if ((_debug_options.get() & uint8_t(lua_scripts::DebugLevel::NO_SCRIPTS_TO_RUN)) != 0) {
gcs().send_text(MAV_SEVERITY_DEBUG, "Scripting: %s", "stopped");
GCS_SEND_TEXT(MAV_SEVERITY_DEBUG, "Scripting: %s", "stopped");
}
}
}
@@ -314,7 +316,7 @@ void AP_Scripting::handle_mission_command(const AP_Mission::Mission_Command& cmd
mission_data = nullptr;
}
if (mission_data == nullptr) {
gcs().send_text(MAV_SEVERITY_INFO, "Scripting: %s", "unable to receive mission command");
GCS_SEND_TEXT(MAV_SEVERITY_INFO, "Scripting: %s", "unable to receive mission command");
return;
}
}
@@ -362,6 +364,7 @@ void AP_Scripting::restart_all()
_stop = true;
}
#if HAL_GCS_ENABLED
void AP_Scripting::handle_message(const mavlink_message_t &msg, const mavlink_channel_t chan) {
if (mavlink_data.rx_buffer == nullptr) {
return;
@@ -396,6 +399,7 @@ bool AP_Scripting::is_handling_command(uint16_t cmd_id)
return false;
}
#endif // HAL_GCS_ENABLED
AP_Scripting *AP_Scripting::_singleton = nullptr;