From 0827aaa16d6ba8a8c003e50d494c8114ae780906 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sun, 3 May 2020 13:00:37 +0200 Subject: [PATCH] PC control working --- main.c | 3 ++ nanovna.h | 7 ++-- sa_cmd.c | 100 +++++++++++++++++++++++++++++++++++++----------------- sa_core.c | 1 + ui_sa.c | 2 +- 5 files changed, 77 insertions(+), 36 deletions(-) diff --git a/main.c b/main.c index 1b867f1..4109559 100644 --- a/main.c +++ b/main.c @@ -138,6 +138,8 @@ static THD_FUNCTION(Thread1, arg) // call from lowest level to save stack space self_test(setting.test); sweep_mode = SWEEP_ENABLE; + } else if (sweep_mode & SWEEP_REMOTE) { + sweep_remote(); } else if (sweep_mode & SWEEP_CALIBRATE) { // call from lowest level to save stack space calibrate(); @@ -2261,6 +2263,7 @@ static const VNAShellCommand commands[] = { "attenuate", cmd_attenuate, 0 }, { "rbw", cmd_rbw, 0 }, { "mode", cmd_mode, 0 }, + { "spur", cmd_spur, 0 }, { "selftest", cmd_selftest, 0 }, { "x", cmd_x, 0 }, { "i", cmd_i, 0 }, diff --git a/nanovna.h b/nanovna.h index da0c0e7..57ec27f 100644 --- a/nanovna.h +++ b/nanovna.h @@ -150,10 +150,11 @@ enum { #define MODE_LOW(x) ((x) == M_LOW || (x) == M_GENLOW ) #define MODE_SELECT(x) (MODE_HIGH(x) ? 1 : 0) -#define SWEEP_ENABLE 0x01 -#define SWEEP_ONCE 0x02 +#define SWEEP_ENABLE 0x01 +#define SWEEP_ONCE 0x02 #define SWEEP_CALIBRATE 0x04 #define SWEEP_SELFTEST 0x08 +#define SWEEP_REMOTE 0x10 extern int8_t sweep_mode; extern const char *info_about[]; @@ -214,7 +215,7 @@ void set_modulation(int); void set_measurement(int); // extern int settingSpeed; //extern int setting.step_delay; - +void sweep_remote(void); #ifdef __VNA__ /* * dsp.c diff --git a/sa_cmd.c b/sa_cmd.c index 3156a02..f599708 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -31,6 +31,21 @@ VNA_SHELL_FUNCTION(cmd_mode) goto usage; } +VNA_SHELL_FUNCTION(cmd_spur) +{ + if (argc != 1) { + usage: + shell_printf("usage: spur on|off\r\n"); + return; + } + if (strcmp(argv[0],"on") == 0) { + setting.spur = 1; + } else if (strcmp(argv[0],"off") == 0) { + setting.spur = 0; + } else + goto usage; +} + VNA_SHELL_FUNCTION(cmd_attenuate) { if (argc != 1) { @@ -183,31 +198,39 @@ return; // Don't use!!!! VNA_SHELL_FUNCTION(cmd_o) { (void) argc; - return; uint32_t value = my_atoi(argv[0]); -// if (VFO == 0) -// setting.frequency_IF = value; - set_freq(VFO, value); + if (VFO == 0) + setting.frequency_IF = value; +// set_freq(VFO, value); } VNA_SHELL_FUNCTION(cmd_d) { (void) argc; int32_t a = my_atoi(argv[0]); - setting.drive = a; +// setting.drive = a; } VNA_SHELL_FUNCTION(cmd_a) { (void)argc; + if (argc != 1) { + shell_printf("a=%d\r\n", frequencyStart); + return; + } int32_t value = my_atoi(argv[0]); frequencyStart = value; } + VNA_SHELL_FUNCTION(cmd_b) { (void)argc; + if (argc != 1) { + shell_printf("b=%d\r\n", frequencyStop); + return; + } int32_t value = my_atoi(argv[0]); frequencyStop = value; } @@ -221,6 +244,10 @@ VNA_SHELL_FUNCTION(cmd_t) VNA_SHELL_FUNCTION(cmd_e) { (void)argc; + if (argc != 1) { + shell_printf("e=%d\r\n", setting.tracking); + return; + } setting.tracking = my_atoi(argv[0]); if (setting.tracking == -1) setting.tracking = false; @@ -234,45 +261,54 @@ VNA_SHELL_FUNCTION(cmd_e) VNA_SHELL_FUNCTION(cmd_s) { (void)argc; + if (argc != 1) { + shell_printf("s=%d\r\n", points); + return; + } points = my_atoi(argv[0]); } -VNA_SHELL_FUNCTION(cmd_m) +void sweep_remote(void) { - (void)argc; - (void)argv; - - set_mode(0); - setting.tracking = false; //Default test setup - setting.step_atten = false; - set_attenuation(0); - set_reflevel(-10); - set_sweep_frequency(ST_START,frequencyStart - setting.frequency_IF ); - set_sweep_frequency(ST_STOP, frequencyStop - setting.frequency_IF); - draw_cal_status(); - - pause_sweep(); - int32_t f_step = (frequencyStop-frequencyStart)/ points; - palClearPad(GPIOB, GPIOB_LED); // disable led and wait for voltage stabilization int old_step = setting.frequency_step; + uint32_t f_step = (frequencyStop-frequencyStart)/ points; setting.frequency_step = f_step; - update_rbw(); - chThdSleepMilliseconds(10); streamPut(shell_stream, '{'); dirty = true; for (int i = 0; i>8) & 0xFF)); - // enable led + if (operation_requested) + break; + float val = perform(false, i, frequencyStart - setting.frequency_IF + f_step * i, false); + streamPut(shell_stream, 'x'); + int v = val*2 + 256; + streamPut(shell_stream, (uint8_t)(v & 0xFF)); + streamPut(shell_stream, (uint8_t)((v>>8) & 0xFF)); + // enable led } streamPut(shell_stream, '}'); setting.frequency_step = old_step; - update_rbw(); - resume_sweep(); - palSetPad(GPIOB, GPIOB_LED); + sweep_mode = 0; +} + +VNA_SHELL_FUNCTION(cmd_m) +{ + (void)argc; + (void)argv; + +// set_mode(0); +// setting.tracking = false; //Default test setup +// setting.step_atten = false; +// set_attenuation(0); +// set_reflevel(-10); +// set_sweep_frequency(ST_START,frequencyStart - setting.frequency_IF ); +// set_sweep_frequency(ST_STOP, frequencyStop - setting.frequency_IF); +// draw_cal_status(); + + pause_sweep(); +// update_rbw(); + chThdSleepMilliseconds(10); + sweep_mode = SWEEP_REMOTE; +// update_rbw(); } VNA_SHELL_FUNCTION(cmd_p) diff --git a/sa_core.c b/sa_core.c index c729f78..48ce3b0 100644 --- a/sa_core.c +++ b/sa_core.c @@ -768,6 +768,7 @@ static const int spur_table[] = 22960000, 28960000, 29800000, + 38105000, 49500000, #ifdef IF_AT_4339 780000, // 433.9MHz table diff --git a/ui_sa.c b/ui_sa.c index bc964ae..db4a1f6 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1501,7 +1501,7 @@ static void menu_item_modify_attribute( mark = true; } } else if (menu == menu_stimulus) { - if (item == 5 /* PAUSE */ && !(sweep_mode&SWEEP_ENABLE)) { + if (item == 6 && setting.spur) { mark = true; } } else if (menu == menu_average) {