From 1b7d416e6376af1ff893a176961399c1a3d11f2b Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Mon, 25 May 2020 12:32:04 +0200 Subject: [PATCH] Enable execution of single selftest --- nanovna.h | 1 + sa_cmd.c | 8 ++++++-- sa_core.c | 17 ++++++++++++----- ui_sa.c | 1 + 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/nanovna.h b/nanovna.h index f52dd95..422637e 100644 --- a/nanovna.h +++ b/nanovna.h @@ -567,6 +567,7 @@ typedef struct setting float trigger_level; int trigger; int linearity_step; + int test_argument; uint32_t checksum; }setting_t; diff --git a/sa_cmd.c b/sa_cmd.c index 22b6400..87bb891 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -146,11 +146,15 @@ VNA_SHELL_FUNCTION(cmd_y) VNA_SHELL_FUNCTION(cmd_selftest) { - if (argc != 1) { - shell_printf("usage: selftest (1-3)\r\n"); + if (argc < 1 || argc > 2) { + shell_printf("usage: selftest (1-3) [arg]\r\n"); return; } setting.test = my_atoi(argv[0]); + if (argc == 1) + setting.test_argument = 0; + else + setting.test_argument = my_atoi(argv[1]); sweep_mode = SWEEP_SELFTEST; } diff --git a/sa_core.c b/sa_core.c index db0a184..56b2a20 100644 --- a/sa_core.c +++ b/sa_core.c @@ -1850,14 +1850,19 @@ int validate_peak_below(int i, float margin) { int validate_below(int tc, int from, int to) { int status = TS_PASS; + float sum = 0; + int sum_count = 0; for (int j = from; j < to; j++) { - if (actual_t[j] > stored_t[j] - 5) - status = TS_CRITICAL; - else if (actual_t[j] > stored_t[j]) { + sum += actual_t[j]; + sum_count++; + if (actual_t[j] > stored_t[j]) { status = TS_FAIL; break; } } + sum = sum / sum_count; + if (sum > stored_t[from] - 5) + status = TS_CRITICAL; if (status != TS_PASS) test_fail_cause[tc] = "Above "; return(status); @@ -2142,7 +2147,9 @@ void self_test(int test) } show_test_info = TRUE; int i=0; - while (test_case[i].kind != TC_END) { + if (setting.test_argument > 0) + i=setting.test_argument-1; + do { setting.frequency_IF = old_IF; test_prepare(i); test_acquire(i); // Acquire test @@ -2151,7 +2158,7 @@ void self_test(int test) wait_user(); } i++; - } + } while (test_case[i].kind != TC_END && setting.test_argument == 0 ); ili9341_set_foreground(BRIGHT_COLOR_GREEN); ili9341_drawstring_7x13("Self test complete", 50, 200); ili9341_drawstring_7x13("Touch screen to continue", 50, 215); diff --git a/ui_sa.c b/ui_sa.c index bfcbff7..f59e99f 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -543,6 +543,7 @@ static void menu_config_cb(int item, uint8_t data) menu_move_back(); ui_mode_normal(); setting.test = 0; + setting.test_argument = 0; sweep_mode = SWEEP_SELFTEST; break; case 4: