mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
change command name from data to dump, add data command to fetch array, marker position
This commit is contained in:
parent
520ebef659
commit
0d6c718a47
33
ili9431.c
33
ili9431.c
|
|
@ -556,10 +556,10 @@ draw_on_strut(int v0, int d, int color)
|
|||
}
|
||||
|
||||
trace_t trace[TRACES_MAX] = {
|
||||
{ 1, TRC_LOGMAG, 0, RGB565(0,255,255), 0 },
|
||||
{ 1, TRC_LOGMAG, 1, RGB565(255,0,40), 0 },
|
||||
{ 1, TRC_SMITH, 0, RGB565(0,0,255), 1 },
|
||||
{ 1, TRC_PHASE, 1, RGB565(50,255,0), 1 }
|
||||
{ 1, TRC_LOGMAG, 0, 1.0, RGB565(0,255,255), 0 },
|
||||
{ 1, TRC_LOGMAG, 1, 1.0, RGB565(255,0,40), 0 },
|
||||
{ 1, TRC_SMITH, 0, 1.0, RGB565(0,0,255), 1 },
|
||||
{ 1, TRC_PHASE, 1, 1.0, RGB565(50,255,0), 1 }
|
||||
};
|
||||
|
||||
uint32_t trace_index[TRACES_MAX][101];
|
||||
|
|
@ -598,12 +598,11 @@ float swr(float *v)
|
|||
|
||||
#define RADIUS ((HEIGHT-1)/2)
|
||||
void
|
||||
cartesian_scale(float re, float im, int *xp, int *yp)
|
||||
cartesian_scale(float re, float im, int *xp, int *yp, float scale)
|
||||
{
|
||||
//float scale = 4e-3;
|
||||
float scale = RADIUS;
|
||||
int x = re * scale;
|
||||
int y = im * scale;
|
||||
int x = re * RADIUS * scale;
|
||||
int y = im * RADIUS * scale;
|
||||
if (x < -RADIUS) x = -RADIUS;
|
||||
if (y < -RADIUS) y = -RADIUS;
|
||||
if (x > RADIUS) x = RADIUS;
|
||||
|
|
@ -733,7 +732,7 @@ trace_into_index(int x, int t, int i, float coeff[2])
|
|||
case TRC_SMITH:
|
||||
case TRC_ADMIT:
|
||||
case TRC_POLAR:
|
||||
cartesian_scale(coeff[0], coeff[1], &x1, &y1);
|
||||
cartesian_scale(coeff[0], coeff[1], &x1, &y1, trace[t].scale);
|
||||
idx = INDEX(x1, y1, i);
|
||||
break;
|
||||
}
|
||||
|
|
@ -748,7 +747,7 @@ void plot_into_index(float measured[2][101][2])
|
|||
for (t = 0; t < TRACES_MAX; t++) {
|
||||
if (!trace[t].enabled)
|
||||
continue;
|
||||
int n = trace[t].source;
|
||||
int n = trace[t].channel;
|
||||
trace_index[t][i] = trace_into_index(x, t, i, measured[n][i]);
|
||||
}
|
||||
}
|
||||
|
|
@ -1025,11 +1024,25 @@ draw_cell(int m, int n)
|
|||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
if (m == 0 && n == 0) {
|
||||
draw_marker(w, h, 8, 12, trace[0].color, '1');
|
||||
draw_marker(w, h, 18, 20, trace[1].color, '2');
|
||||
draw_marker(w, h, 4, 30, trace[2].color, '3');
|
||||
}
|
||||
#endif
|
||||
|
||||
i = 30;
|
||||
for (t = 0; t < TRACES_MAX; t++) {
|
||||
if (!trace[t].enabled)
|
||||
continue;
|
||||
uint32_t index = trace_index[t][i];
|
||||
int x = CELL_X(index) - x0;
|
||||
int y = CELL_Y(index) - y0;
|
||||
if (x > -12 && x < w+12 && y >= 0 && y < h+12)
|
||||
draw_marker(w, h, x, y, trace[t].color, '1');
|
||||
}
|
||||
|
||||
ili9341_bulk(OFFSETX + x0, OFFSETY + y0, w, h);
|
||||
}
|
||||
|
|
|
|||
100
main.c
100
main.c
|
|
@ -266,6 +266,29 @@ static const I2SConfig i2sconfig = {
|
|||
};
|
||||
|
||||
static void cmd_data(BaseSequentialStream *chp, int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
int len;
|
||||
int sel = 0;
|
||||
|
||||
if (argc == 1)
|
||||
sel = atoi(argv[0]);
|
||||
if (sel == 0 || sel == 1) {
|
||||
pause_sweep();
|
||||
for (i = 0; i < 101; i++) {
|
||||
chprintf(chp, "%f %f\r\n", measured[sel][i][0], measured[sel][i][1]);
|
||||
}
|
||||
} else if (sel >= 2 && sel < 7) {
|
||||
pause_sweep();
|
||||
for (i = 0; i < 101; i++) {
|
||||
chprintf(chp, "%f %f\r\n", cal_data[sel-2][i][0], cal_data[sel-2][i][1]);
|
||||
}
|
||||
} else {
|
||||
chprintf(chp, "usage: data [array]\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void cmd_dump(BaseSequentialStream *chp, int argc, char *argv[])
|
||||
{
|
||||
int i, j;
|
||||
int len;
|
||||
|
|
@ -371,7 +394,7 @@ void scan_lcd(void)
|
|||
delay = set_frequency(frequencies[0]);
|
||||
delay += 2;
|
||||
for (i = 0; i < sweep_points; i++) {
|
||||
wait_count = delay + 1;
|
||||
wait_count = delay + 2;
|
||||
tlv320aic3204_select_in3();
|
||||
while (wait_count)
|
||||
;
|
||||
|
|
@ -381,7 +404,7 @@ void scan_lcd(void)
|
|||
__enable_irq();
|
||||
|
||||
tlv320aic3204_select_in1();
|
||||
wait_count = 2 + 1;
|
||||
wait_count = 2 + 2;
|
||||
while (wait_count)
|
||||
;
|
||||
__disable_irq();
|
||||
|
|
@ -485,6 +508,32 @@ eterm_copy(int dst, int src)
|
|||
memcpy(cal_data[dst], cal_data[src], sizeof cal_data[dst]);
|
||||
}
|
||||
|
||||
|
||||
struct open_model {
|
||||
float c0;
|
||||
float c1;
|
||||
float c2;
|
||||
float c3;
|
||||
} open_model = { 50, 0, -300, 27 };
|
||||
|
||||
#if 1
|
||||
static void
|
||||
adjust_ed(void)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 101; i++) {
|
||||
// z=1/(jwc*z0) = 1/(2*pi*f*c*z0) Note: normalized with Z0
|
||||
// s11ao = (z-1)/(z+1) = (1-1/z)/(1+1/z) = (1-jwcz0)/(1+jwcz0)
|
||||
// prepare 1/s11ao for effeiciency
|
||||
float c = 1000e-15;
|
||||
float z0 = 50;
|
||||
//float z = 6.2832 * frequencies[i] * c * z0;
|
||||
float z = 0.02;
|
||||
cal_data[ETERM_ED][i][0] += z;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
eterm_calc_es(void)
|
||||
{
|
||||
|
|
@ -493,7 +542,8 @@ eterm_calc_es(void)
|
|||
// z=1/(jwc*z0) = 1/(2*pi*f*c*z0) Note: normalized with Z0
|
||||
// s11ao = (z-1)/(z+1) = (1-1/z)/(1+1/z) = (1-jwcz0)/(1+jwcz0)
|
||||
// prepare 1/s11ao for effeiciency
|
||||
float c = 150e-15;
|
||||
float c = 50e-15;
|
||||
//float c = 1.707e-12;
|
||||
float z0 = 50;
|
||||
float z = 6.2832 * frequencies[i] * c * z0;
|
||||
float sq = 1 + z*z;
|
||||
|
|
@ -524,9 +574,9 @@ eterm_calc_er(int sign)
|
|||
{
|
||||
int i;
|
||||
for (i = 0; i < 101; i++) {
|
||||
// Er = sign*(1-sign*Es)S11mo'
|
||||
float s11or = cal_data[CAL_SHORT][i][0] - cal_data[ETERM_ED][i][0];
|
||||
float s11oi = cal_data[CAL_SHORT][i][1] - cal_data[ETERM_ED][i][1];
|
||||
// Er = sign*(1-sign*Es)S11ms'
|
||||
float s11sr = cal_data[CAL_SHORT][i][0] - cal_data[ETERM_ED][i][0];
|
||||
float s11si = cal_data[CAL_SHORT][i][1] - cal_data[ETERM_ED][i][1];
|
||||
float esr = cal_data[ETERM_ES][i][0];
|
||||
float esi = cal_data[ETERM_ES][i][1];
|
||||
if (sign > 0) {
|
||||
|
|
@ -534,14 +584,15 @@ eterm_calc_er(int sign)
|
|||
esi = -esi;
|
||||
}
|
||||
esr = 1 + esr;
|
||||
float err = esr * s11or - esi * s11oi;
|
||||
float eri = esr * s11oi + esi * s11or;
|
||||
float err = esr * s11sr - esi * s11si;
|
||||
float eri = esr * s11si + esi * s11sr;
|
||||
if (sign < 0) {
|
||||
err = -err;
|
||||
eri = -eri;
|
||||
}
|
||||
cal_data[ETERM_ER][i][0] = err;
|
||||
cal_data[ETERM_ER][i][1] = eri;
|
||||
cal_data[ETERM_ES][i][1] = 0;
|
||||
}
|
||||
cal_status &= ~CALSTAT_SHORT;
|
||||
cal_status |= CALSTAT_ER;
|
||||
|
|
@ -619,22 +670,35 @@ static void cmd_cal(BaseSequentialStream *chp, int argc, char *argv[])
|
|||
char *cmd = argv[0];
|
||||
if (strcmp(cmd, "load") == 0) {
|
||||
cal_status |= CALSTAT_LOAD;
|
||||
chMtxLock(&mutex);
|
||||
memcpy(cal_data[CAL_LOAD], measured[0], sizeof measured[0]);
|
||||
chMtxUnlock(&mutex);
|
||||
} else if (strcmp(cmd, "open") == 0) {
|
||||
cal_status |= CALSTAT_OPEN;
|
||||
cal_status &= ~(CALSTAT_ES|CALSTAT_APPLY);
|
||||
chMtxLock(&mutex);
|
||||
memcpy(cal_data[CAL_OPEN], measured[0], sizeof measured[0]);
|
||||
chMtxUnlock(&mutex);
|
||||
} else if (strcmp(cmd, "short") == 0) {
|
||||
cal_status |= CALSTAT_SHORT;
|
||||
cal_status &= ~(CALSTAT_ER|CALSTAT_APPLY);
|
||||
chMtxLock(&mutex);
|
||||
memcpy(cal_data[CAL_SHORT], measured[0], sizeof measured[0]);
|
||||
chMtxUnlock(&mutex);
|
||||
} else if (strcmp(cmd, "thru") == 0) {
|
||||
cal_status |= CALSTAT_THRU;
|
||||
chMtxLock(&mutex);
|
||||
memcpy(cal_data[CAL_THRU], measured[1], sizeof measured[0]);
|
||||
chMtxUnlock(&mutex);
|
||||
} else if (strcmp(cmd, "isoln") == 0) {
|
||||
cal_status |= CALSTAT_ISOLN;
|
||||
chMtxLock(&mutex);
|
||||
memcpy(cal_data[CAL_ISOLN], measured[1], sizeof measured[0]);
|
||||
chMtxUnlock(&mutex);
|
||||
} else if (strcmp(cmd, "done") == 0) {
|
||||
if (!(cal_status & CALSTAT_LOAD))
|
||||
eterm_set(ETERM_ED, 0.0, 0.0);
|
||||
//adjust_ed();
|
||||
if ((cal_status & CALSTAT_SHORT) && (cal_status & CALSTAT_OPEN)) {
|
||||
eterm_calc_es();
|
||||
eterm_calc_er(-1);
|
||||
|
|
@ -703,7 +767,7 @@ static void cmd_recall(BaseSequentialStream *chp, int argc, char *argv[])
|
|||
const char *trc_type_name[] = {
|
||||
"LogMAG", "Phase", "Smith", "Admit", "Polar", "Linear", "SWR"
|
||||
};
|
||||
const char *trc_source_name[] = {
|
||||
const char *trc_channel_name[] = {
|
||||
"S11", "S21"
|
||||
};
|
||||
|
||||
|
|
@ -715,8 +779,8 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
|
|||
for (t = 0; t < 4; t++) {
|
||||
if (trace[t].enabled) {
|
||||
const char *type = trc_type_name[trace[t].type];
|
||||
const char *source = trc_source_name[trace[t].source];
|
||||
chprintf(chp, "%d %s %s\r\n", t, type, source);
|
||||
const char *channel = trc_channel_name[trace[t].channel];
|
||||
chprintf(chp, "%d %s %s\r\n", t, type, channel);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
|
@ -726,8 +790,8 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
|
|||
goto usage;
|
||||
if (argc == 1) {
|
||||
const char *type = trc_type_name[trace[t].type];
|
||||
const char *source = trc_source_name[trace[t].source];
|
||||
chprintf(chp, "%d %s %s\r\n", t, type, source);
|
||||
const char *channel = trc_channel_name[trace[t].channel];
|
||||
chprintf(chp, "%d %s %s\r\n", t, type, channel);
|
||||
return;
|
||||
}
|
||||
if (argc > 1) {
|
||||
|
|
@ -761,15 +825,18 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
|
|||
trace[t].enabled = TRUE;
|
||||
} else if (strcmp(argv[1], "off") == 0) {
|
||||
trace[t].enabled = FALSE;
|
||||
} else if (strcmp(argv[1], "scale") == 0 && argc >= 3) {
|
||||
trace[t].scale = atoi(argv[2]);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
if (argc > 2) {
|
||||
int src = atoi(argv[2]);
|
||||
if (src != 0 && src != 1)
|
||||
goto usage;
|
||||
trace[t].source = src;
|
||||
trace[t].channel = src;
|
||||
}
|
||||
|
||||
exit:
|
||||
return;
|
||||
usage:
|
||||
chprintf(chp, "trace [n] [logmag|phase|smith|swr] [src]\r\n");
|
||||
|
|
@ -877,7 +944,7 @@ static void cmd_stat(BaseSequentialStream *chp, int argc, char *argv[])
|
|||
|
||||
|
||||
|
||||
#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(460)
|
||||
#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(454)
|
||||
|
||||
static const ShellCommand commands[] =
|
||||
{
|
||||
|
|
@ -887,6 +954,7 @@ static const ShellCommand commands[] =
|
|||
{ "time", cmd_time },
|
||||
{ "dac", cmd_dac },
|
||||
{ "data", cmd_data },
|
||||
{ "dump", cmd_dump },
|
||||
{ "port", cmd_port },
|
||||
{ "stat", cmd_stat },
|
||||
{ "gain", cmd_gain },
|
||||
|
|
|
|||
Loading…
Reference in a new issue