mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
refactor: introduce trace_info
This commit is contained in:
parent
f2ab569e5a
commit
3e841920fb
57
main.c
57
main.c
|
|
@ -493,10 +493,10 @@ properties_t current_props = {
|
||||||
/* electrical_delay */ 0,
|
/* electrical_delay */ 0,
|
||||||
/* trace[4] */
|
/* trace[4] */
|
||||||
{/*enable, type, channel, polar, scale, refpos*/
|
{/*enable, type, channel, polar, scale, refpos*/
|
||||||
{ 1, TRC_LOGMAG, 0, 0, 10, 7.0 },
|
{ 1, TRC_LOGMAG, 0, 0, 1.0, 7.0 },
|
||||||
{ 1, TRC_LOGMAG, 1, 0, 10, 7.0 },
|
{ 1, TRC_LOGMAG, 1, 0, 1.0, 7.0 },
|
||||||
{ 1, TRC_SMITH, 0, 1, 1.0, 0.0 },
|
{ 1, TRC_SMITH, 0, 1, 1.0, 0.0 },
|
||||||
{ 1, TRC_PHASE, 1, 0, 90, 4.0 }
|
{ 1, TRC_PHASE, 1, 0, 1.0, 4.0 }
|
||||||
},
|
},
|
||||||
/* markers[4] */ {
|
/* markers[4] */ {
|
||||||
{ 1, 30, 0 }, { 0, 40, 0 }, { 0, 60, 0 }, { 0, 80, 0 }
|
{ 1, 30, 0 }, { 0, 40, 0 }, { 0, 60, 0 }, { 0, 80, 0 }
|
||||||
|
|
@ -1271,27 +1271,34 @@ static void cmd_recall(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
chprintf(chp, "recall {id}\r\n");
|
chprintf(chp, "recall {id}\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const struct {
|
||||||
const char *trc_type_name[] = {
|
const char *name;
|
||||||
"LOGMAG", "PHASE", "DELAY",
|
uint16_t refpos;
|
||||||
"SMITH", "POLAR", "LINEAR", "SWR",
|
float scale_unit;
|
||||||
"REAL", "IMAG", "R", "X"
|
} trace_info[] = {
|
||||||
};
|
{ "LOGMAG", 7, 10 },
|
||||||
const uint8_t default_refpos[] = {
|
{ "PHASE", 4, 90 },
|
||||||
7, 4, 4,
|
{ "DELAY", 4, 1 },
|
||||||
0, 0, 0, 0,
|
{ "SMITH", 0, 1 },
|
||||||
4, 4, 0, 4
|
{ "POLAR", 0, 1 },
|
||||||
};
|
{ "LINEAR", 0, 0.125 },
|
||||||
const float default_scale[] = {
|
{ "SWR", 0, 1 },
|
||||||
10, 90, 1,
|
{ "REAL", 4, 0.25 },
|
||||||
0, 0, 0.125, 1,
|
{ "IMAG", 4, 0.25 },
|
||||||
0.25, 0.25, 100, 100
|
{ "R", 0, 100 },
|
||||||
|
{ "X", 4, 100 }
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *trc_channel_name[] = {
|
const char *trc_channel_name[] = {
|
||||||
"CH0", "CH1"
|
"CH0", "CH1"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const char *
|
||||||
|
get_trace_typename(int t)
|
||||||
|
{
|
||||||
|
return trace_info[trace[t].type].name;
|
||||||
|
}
|
||||||
|
|
||||||
void set_trace_type(int t, int type)
|
void set_trace_type(int t, int type)
|
||||||
{
|
{
|
||||||
int polar = type == TRC_SMITH || type == TRC_POLAR;
|
int polar = type == TRC_SMITH || type == TRC_POLAR;
|
||||||
|
|
@ -1308,8 +1315,7 @@ void set_trace_type(int t, int type)
|
||||||
}
|
}
|
||||||
if (trace[t].type != type) {
|
if (trace[t].type != type) {
|
||||||
trace[t].type = type;
|
trace[t].type = type;
|
||||||
trace[t].refpos = default_refpos[type];
|
trace[t].refpos = trace_info[type].refpos;
|
||||||
trace[t].scale = default_scale[type];
|
|
||||||
if (polar)
|
if (polar)
|
||||||
force = TRUE;
|
force = TRUE;
|
||||||
}
|
}
|
||||||
|
|
@ -1329,6 +1335,7 @@ void set_trace_channel(int t, int channel)
|
||||||
|
|
||||||
void set_trace_scale(int t, float scale)
|
void set_trace_scale(int t, float scale)
|
||||||
{
|
{
|
||||||
|
scale /= trace_info[trace[t].type].scale_unit;
|
||||||
if (trace[t].scale != scale) {
|
if (trace[t].scale != scale) {
|
||||||
trace[t].scale = scale;
|
trace[t].scale = scale;
|
||||||
force_set_markmap();
|
force_set_markmap();
|
||||||
|
|
@ -1337,7 +1344,7 @@ void set_trace_scale(int t, float scale)
|
||||||
|
|
||||||
float get_trace_scale(int t)
|
float get_trace_scale(int t)
|
||||||
{
|
{
|
||||||
return trace[t].scale;
|
return trace[t].scale * trace_info[trace[t].type].scale_unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_trace_refpos(int t, float refpos)
|
void set_trace_refpos(int t, float refpos)
|
||||||
|
|
@ -1396,10 +1403,10 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
for (t = 0; t < 4; t++) {
|
for (t = 0; t < 4; t++) {
|
||||||
if (trace[t].enabled) {
|
if (trace[t].enabled) {
|
||||||
const char *type = trc_type_name[trace[t].type];
|
const char *type = trace_info[trace[t].type].name;
|
||||||
const char *channel = trc_channel_name[trace[t].channel];
|
const char *channel = trc_channel_name[trace[t].channel];
|
||||||
float scale = trace[t].scale;
|
float scale = get_trace_scale(t);
|
||||||
float refpos = trace[t].refpos;
|
float refpos = get_trace_refpos(t);
|
||||||
chprintf(chp, "%d %s %s %f %f\r\n", t, type, channel, scale, refpos);
|
chprintf(chp, "%d %s %s %f %f\r\n", t, type, channel, scale, refpos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1419,7 +1426,7 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
if (t < 0 || t >= 4)
|
if (t < 0 || t >= 4)
|
||||||
goto usage;
|
goto usage;
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
const char *type = trc_type_name[trace[t].type];
|
const char *type = get_trace_typename(t);
|
||||||
const char *channel = trc_channel_name[trace[t].channel];
|
const char *channel = trc_channel_name[trace[t].channel];
|
||||||
chprintf(chp, "%d %s %s\r\n", t, type, channel);
|
chprintf(chp, "%d %s %s\r\n", t, type, channel);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -152,8 +152,6 @@ enum {
|
||||||
TRC_LOGMAG, TRC_PHASE, TRC_DELAY, TRC_SMITH, TRC_POLAR, TRC_LINEAR, TRC_SWR, TRC_REAL, TRC_IMAG, TRC_R, TRC_X, TRC_OFF
|
TRC_LOGMAG, TRC_PHASE, TRC_DELAY, TRC_SMITH, TRC_POLAR, TRC_LINEAR, TRC_SWR, TRC_REAL, TRC_IMAG, TRC_R, TRC_X, TRC_OFF
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const char *trc_type_name[];
|
|
||||||
|
|
||||||
// LOGMAG: SCALE, REFPOS, REFVAL
|
// LOGMAG: SCALE, REFPOS, REFVAL
|
||||||
// PHASE: SCALE, REFPOS, REFVAL
|
// PHASE: SCALE, REFPOS, REFVAL
|
||||||
// DELAY: SCALE, REFPOS, REFVAL
|
// DELAY: SCALE, REFPOS, REFVAL
|
||||||
|
|
@ -195,6 +193,7 @@ void set_trace_scale(int t, float scale);
|
||||||
void set_trace_refpos(int t, float refpos);
|
void set_trace_refpos(int t, float refpos);
|
||||||
float get_trace_scale(int t);
|
float get_trace_scale(int t);
|
||||||
float get_trace_refpos(int t);
|
float get_trace_refpos(int t);
|
||||||
|
const char *get_trace_typename(int t);
|
||||||
|
|
||||||
void set_electrical_delay(float picoseconds);
|
void set_electrical_delay(float picoseconds);
|
||||||
float get_electrical_delay(void);
|
float get_electrical_delay(void);
|
||||||
|
|
|
||||||
20
plot.c
20
plot.c
|
|
@ -494,8 +494,8 @@ trace_into_index(int x, int t, int i, float coeff[2])
|
||||||
{
|
{
|
||||||
int y = 0;
|
int y = 0;
|
||||||
float v = 0;
|
float v = 0;
|
||||||
float refpos = 8 - trace[t].refpos;
|
float refpos = 8 - get_trace_refpos(t);
|
||||||
float scale = 1 / trace[t].scale;
|
float scale = 1 / get_trace_scale(t);
|
||||||
switch (trace[t].type) {
|
switch (trace[t].type) {
|
||||||
case TRC_LOGMAG:
|
case TRC_LOGMAG:
|
||||||
v = refpos - logmag(coeff) * scale;
|
v = refpos - logmag(coeff) * scale;
|
||||||
|
|
@ -510,10 +510,10 @@ trace_into_index(int x, int t, int i, float coeff[2])
|
||||||
v = refpos+ (1 - swr(coeff)) * scale;
|
v = refpos+ (1 - swr(coeff)) * scale;
|
||||||
break;
|
break;
|
||||||
case TRC_REAL:
|
case TRC_REAL:
|
||||||
v = refpos - coeff[0] * 8 * scale;
|
v = refpos - coeff[0] * scale;
|
||||||
break;
|
break;
|
||||||
case TRC_IMAG:
|
case TRC_IMAG:
|
||||||
v = refpos - coeff[1] * 8 * scale;
|
v = refpos - coeff[1] * scale;
|
||||||
break;
|
break;
|
||||||
case TRC_R:
|
case TRC_R:
|
||||||
v = refpos - resitance(coeff) * scale;
|
v = refpos - resitance(coeff) * scale;
|
||||||
|
|
@ -680,21 +680,21 @@ trace_get_value_string(int t, char *buf, int len, float coeff[2], uint32_t frequ
|
||||||
void
|
void
|
||||||
trace_get_info(int t, char *buf, int len)
|
trace_get_info(int t, char *buf, int len)
|
||||||
{
|
{
|
||||||
const char *type = trc_type_name[trace[t].type];
|
const char *type = get_trace_typename(t);
|
||||||
switch (trace[t].type) {
|
switch (trace[t].type) {
|
||||||
case TRC_LOGMAG:
|
case TRC_LOGMAG:
|
||||||
chsnprintf(buf, len, "%s %ddB/", type, (int)(trace[t].scale));
|
chsnprintf(buf, len, "%s %ddB/", type, (int)get_trace_scale(t));
|
||||||
break;
|
break;
|
||||||
case TRC_PHASE:
|
case TRC_PHASE:
|
||||||
chsnprintf(buf, len, "%s %d" S_DEGREE "/", type, (int)(trace[t].scale));
|
chsnprintf(buf, len, "%s %d" S_DEGREE "/", type, (int)get_trace_scale(t));
|
||||||
break;
|
break;
|
||||||
case TRC_SMITH:
|
case TRC_SMITH:
|
||||||
//case TRC_ADMIT:
|
//case TRC_ADMIT:
|
||||||
case TRC_POLAR:
|
case TRC_POLAR:
|
||||||
chsnprintf(buf, len, "%s %.1fFS", type, trace[t].scale);
|
chsnprintf(buf, len, "%s %.1fFS", type, get_trace_scale(t));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
chsnprintf(buf, len, "%s %.1f/", type, trace[t].scale);
|
chsnprintf(buf, len, "%s %.1f/", type, get_trace_scale(t));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -962,7 +962,7 @@ cell_draw_refpos(int m, int n, int w, int h)
|
||||||
if (trace[t].type == TRC_SMITH || trace[t].type == TRC_POLAR)
|
if (trace[t].type == TRC_SMITH || trace[t].type == TRC_POLAR)
|
||||||
continue;
|
continue;
|
||||||
int x = 0 - x0 +CELLOFFSETX;
|
int x = 0 - x0 +CELLOFFSETX;
|
||||||
int y = 8*GRIDY - (int)(trace[t].refpos * GRIDY) - y0;
|
int y = 8*GRIDY - (int)(get_trace_refpos(t) * GRIDY) - y0;
|
||||||
if (x > -5 && x < w && y >= -3 && y < h+3)
|
if (x > -5 && x < w && y >= -3 && y < h+3)
|
||||||
draw_refpos(w, h, x, y, config.trace_color[t]);
|
draw_refpos(w, h, x, y, config.trace_color[t]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue