From 21b550831b49e5387cde45e5e6922eb037ea04da Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Tue, 14 May 2024 08:24:21 +0200 Subject: [PATCH] Abort command --- main.c | 21 ++++++++++++++------- nanovna.h | 2 ++ sa_cmd.c | 17 +++++++++++++++++ ui.c | 1 + 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/main.c b/main.c index 82f0403..9f8ed2d 100644 --- a/main.c +++ b/main.c @@ -244,8 +244,10 @@ static THD_FUNCTION(Thread1, arg) do { shell_function(shell_nargs - 1, &shell_args[1]); shell_function = 0; + if (operation_requested == OP_NONE) // Don't prompt if aborted + shell_printf(VNA_SHELL_PROMPT_STR); // Resume shell thread - osalThreadDequeueNextI(&shell_thread, MSG_OK); + if (!abort_enabled) osalThreadDequeueNextI(&shell_thread, MSG_OK); } while (shell_function); if (dirty) { if (MODE_OUTPUT(setting.mode)) @@ -1313,10 +1315,10 @@ VNA_SHELL_FUNCTION(cmd_scan) do_scan: pause_sweep(); setting.sweep = true; // prevent abort - sweep(false); + sweep(true); setting.sweep = false; // Output data after if set (faster data recive) - if (argc == 4) { + if (argc == 4 && !operation_requested) { uint16_t mask = my_atoui(argv[3]); if (mask) { for (i = 0; i < sweep_points; i++) { @@ -2320,6 +2322,7 @@ static const VNAShellCommand commands[] = {"hop" , cmd_hop , CMD_WAIT_MUTEX}, #endif {"scanraw" , cmd_scanraw , CMD_WAIT_MUTEX}, + {"abort" , cmd_abort , 0}, {"zero" , cmd_zero , CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD}, // Will set the scanraw measured value offset (128 or 174) {"sweep" , cmd_sweep , CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD}, {"test" , cmd_test , 0}, @@ -2698,12 +2701,15 @@ static void VNAShell_executeLine(char *line) shell_function = scp->sc_function; operation_requested|=OP_CONSOLE; // this will abort current sweep to give priority to the new request // Wait execute command in sweep thread - do { - osalThreadEnqueueTimeoutS(&shell_thread, TIME_INFINITE); - } while (shell_function); + if (!abort_enabled && shell_function != 0){ + do { + osalThreadEnqueueTimeoutS(&shell_thread, TIME_INFINITE); + } while (shell_function); + } } else { operation_requested = false; // otherwise commands will be aborted scp->sc_function(shell_nargs - 1, &shell_args[1]); + shell_printf(VNA_SHELL_PROMPT_STR); if (dirty) { operation_requested = true; // ensure output is updated if (MODE_OUTPUT(setting.mode)) @@ -2715,6 +2721,7 @@ static void VNAShell_executeLine(char *line) return; } shell_printf("%s?" VNA_SHELL_NEWLINE_STR, shell_args[0]); + shell_printf(VNA_SHELL_PROMPT_STR); } void shell_executeCMDLine(char *line) { @@ -3207,8 +3214,8 @@ int main(void) chThdWait(shelltp); #else shell_printf(VNA_SHELL_NEWLINE_STR"tinySA Shell"VNA_SHELL_NEWLINE_STR); + shell_printf(VNA_SHELL_PROMPT_STR); do { - shell_printf(VNA_SHELL_PROMPT_STR); if (VNAShell_readLine(shell_line, VNA_SHELL_MAX_LENGTH)) VNAShell_executeLine(shell_line); else diff --git a/nanovna.h b/nanovna.h index 8a28836..4b362b5 100644 --- a/nanovna.h +++ b/nanovna.h @@ -1596,6 +1596,8 @@ extern int si5351_available; //#define OP_FREQCHANGE 0x04 extern volatile uint8_t operation_requested; extern volatile uint8_t break_execute; +extern volatile uint8_t abort_enabled; + // lever_mode enum lever_mode { diff --git a/sa_cmd.c b/sa_cmd.c index 04d5987..2dfd857 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -1233,6 +1233,23 @@ VNA_SHELL_FUNCTION(cmd_correction) shell_printf("updated %d to %D %.1f\r\n", i, config.correction_frequency[m][i], config.correction_value[m][i]); } +VNA_SHELL_FUNCTION(cmd_abort) +{ + static const char cmd_on_off[] = "off|on"; + if (argc > 1) { + usage: + shell_printf("usage: abort [%s]\r\n", cmd_on_off); + return; + } + if (argc == 1) { + int i = get_str_index(argv[0], cmd_on_off); + if (i < 0) + goto usage; + abort_enabled = i; + } else + operation_requested = OP_CONSOLE; +} + VNA_SHELL_FUNCTION(cmd_scanraw) { freq_t start, stop; diff --git a/ui.c b/ui.c index 54b19a8..46ae56a 100644 --- a/ui.c +++ b/ui.c @@ -72,6 +72,7 @@ static uint16_t menu_button_height = MENU_BUTTON_HEIGHT_N(MENU_BUTTON_MIN); volatile uint8_t operation_requested = OP_NONE; volatile uint8_t break_execute = false; +volatile uint8_t abort_enabled = false; int8_t previous_marker = MARKER_INVALID;