Skip to content

Commit

Permalink
AP_Scripting: remove support for REPL
Browse files Browse the repository at this point in the history
  • Loading branch information
IamPete1 committed May 23, 2024
1 parent 91423d4 commit a910337
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 368 deletions.
42 changes: 3 additions & 39 deletions libraries/AP_Scripting/AP_Scripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,9 @@ void AP_Scripting::init(void) {
MAV_RESULT AP_Scripting::handle_command_int_packet(const mavlink_command_int_t &packet) {
switch ((SCRIPTING_CMD)packet.param1) {
case SCRIPTING_CMD_REPL_START:
return repl_start() ? MAV_RESULT_ACCEPTED : MAV_RESULT_FAILED;
case SCRIPTING_CMD_REPL_STOP:
repl_stop();
return MAV_RESULT_ACCEPTED;
return MAV_RESULT_DENIED;

case SCRIPTING_CMD_STOP:
_restart = false;
_stop = true;
Expand All @@ -244,41 +243,6 @@ MAV_RESULT AP_Scripting::handle_command_int_packet(const mavlink_command_int_t &
}
#endif

bool AP_Scripting::repl_start(void) {
if (terminal.session) { // it's already running, this is fine
return true;
}

// nuke the old folder and all contents
struct stat st;
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));
}

// create a new folder
AP::FS().mkdir(REPL_DIRECTORY);
// delete old files in case we couldn't
AP::FS().unlink(REPL_DIRECTORY "/in");
AP::FS().unlink(REPL_DIRECTORY "/out");

// 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");
return false;
}

terminal.session = true;
return true;
}

void AP_Scripting::repl_stop(void) {
terminal.session = false;
// can't do any more cleanup here, closing the open FD's is the REPL's responsibility
}

/*
avoid optimisation of the thread function. This avoids nasty traps
where setjmp/longjmp does not properly handle save/restore of
Expand All @@ -295,7 +259,7 @@ void AP_Scripting::thread(void) {
_restart = false;
_init_failed = false;

lua_scripts *lua = new lua_scripts(_script_vm_exec_count, _script_heap_size, _debug_options, terminal);
lua_scripts *lua = new lua_scripts(_script_vm_exec_count, _script_heap_size, _debug_options);
if (lua == nullptr || !lua->heap_allocated()) {
GCS_SEND_TEXT(MAV_SEVERITY_CRITICAL, "Scripting: %s", "Unable to allocate memory");
_init_failed = true;
Expand Down
9 changes: 0 additions & 9 deletions libraries/AP_Scripting/AP_Scripting.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,6 @@ class AP_Scripting
// User parameters for inputs into scripts
AP_Float _user[6];

struct terminal_s {
int output_fd;
off_t input_offset;
bool session;
} terminal;

enum class SCR_DIR {
ROMFS = 1 << 0,
SCRIPTS = 1 << 1,
Expand Down Expand Up @@ -146,9 +140,6 @@ class AP_Scripting

private:

bool repl_start(void);
void repl_stop(void);

void thread(void); // main script execution thread

// Check if DEBUG_OPTS bit has been set to save current checksum values to params
Expand Down
16 changes: 0 additions & 16 deletions libraries/AP_Scripting/lua_common_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@

#include <AP_HAL/AP_HAL_Boards.h>

#ifndef REPL_DIRECTORY
#if HAL_OS_FATFS_IO
#define REPL_DIRECTORY "/APM/repl"
#else
#define REPL_DIRECTORY "./repl"
#endif //HAL_OS_FATFS_IO
#endif // REPL_DIRECTORY

#ifndef SCRIPTING_DIRECTORY
#if HAL_OS_FATFS_IO
#define SCRIPTING_DIRECTORY "/APM/scripts"
Expand All @@ -18,14 +10,6 @@
#endif //HAL_OS_FATFS_IO
#endif // SCRIPTING_DIRECTORY

#ifndef REPL_IN
#define REPL_IN REPL_DIRECTORY "/in"
#endif // REPL_IN

#ifndef REPL_OUT
#define REPL_OUT REPL_DIRECTORY "/out"
#endif // REPL_OUT

int lua_get_current_ref();
const char* lua_get_modules_path();
void lua_abort(void) __attribute__((noreturn));
Expand Down
264 changes: 0 additions & 264 deletions libraries/AP_Scripting/lua_repl.cpp

This file was deleted.

Loading

0 comments on commit a910337

Please sign in to comment.