From e179fdb3b071c75ae3a9bd40a822f4d6a92a5cd5 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 4 Oct 2020 20:01:08 +0200 Subject: [PATCH] plot: fix mean, rework annotations --- client/src/cmddata.c | 10 +++++----- client/src/proxgui.h | 2 +- client/src/proxguiqt.cpp | 25 +++++++++++++++++-------- client/src/proxguiqt.h | 1 + client/src/ui.c | 2 +- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/client/src/cmddata.c b/client/src/cmddata.c index e183af77c..cdbf1f04b 100644 --- a/client/src/cmddata.c +++ b/client/src/cmddata.c @@ -1905,9 +1905,9 @@ static int CmdScale(const char *Cmd) { "Set cursor display scale.\n" "Setting the scale makes the differential `dt` reading between the yellow and purple markers meaningful.\n" "once the scale is set, the differential reading between brackets can become a time duration.", - "data scale --sr 125 -u ms -> if sampled in 125 kHz, reading will be in milliseconds\n" - "data scale --sr 1.695 -u us -> if HF, sampling is 1.695 MHz. Reading will be in microseconds\n" - "data scale --sr 16 -u ETU -> if HF, 16 samples per ETU. Reading will be in ETUs" + "data scale --sr 125 -u ms -> for LF sampled at 125 kHz. Reading will be in milliseconds\n" + "data scale --sr 1.695 -u us -> for HF sampled at 1.695 MHz. Reading will be in microseconds\n" + "data scale --sr 16 -u ETU -> for HF with 16 samples per ETU. Reading will be in ETUs" ); void *argtable[] = { arg_param_begin, @@ -1922,8 +1922,8 @@ static int CmdScale(const char *Cmd) { CursorScaleFactor = 1; } int len = 0; - CursorScaleFactorUint[0] = '\x00'; - CLIParamStrToBuf(arg_get_str(ctx, 2), (uint8_t*)CursorScaleFactorUint, sizeof(CursorScaleFactorUint), &len); + CursorScaleFactorUnit[0] = '\x00'; + CLIParamStrToBuf(arg_get_str(ctx, 2), (uint8_t*)CursorScaleFactorUnit, sizeof(CursorScaleFactorUnit), &len); CLIParserFree(ctx); RepaintGraphWindow(); return PM3_SUCCESS; diff --git a/client/src/proxgui.h b/client/src/proxgui.h index 00c954123..921e4dcd5 100644 --- a/client/src/proxgui.h +++ b/client/src/proxgui.h @@ -27,7 +27,7 @@ void InitGraphics(int argc, char **argv, char *script_cmds_file, char *script_cm void ExitGraphics(void); extern double CursorScaleFactor; -extern char CursorScaleFactorUint[11]; +extern char CursorScaleFactorUnit[11]; extern int PlotGridX, PlotGridY, PlotGridXdefault, PlotGridYdefault, GridOffset; extern uint32_t CursorCPos, CursorDPos; extern int CommandFinished; diff --git a/client/src/proxguiqt.cpp b/client/src/proxguiqt.cpp index ed4e049dd..79fc403ff 100644 --- a/client/src/proxguiqt.cpp +++ b/client/src/proxguiqt.cpp @@ -424,7 +424,8 @@ void Plot::PlotGraph(int *buffer, size_t len, QRect plotRect, QRect annotationRe if (len == 0) return; // clock_t begin = clock(); QPainterPath penPath; - int vMin = INT_MAX, vMax = INT_MIN, vMean = 0, v = 0; + int vMin = INT_MAX, vMax = INT_MIN, v = 0; + int64_t vMean = 0; uint32_t i = 0; int x = xCoordOf(GraphStart, plotRect); int y = yCoordOf(buffer[GraphStart], plotRect, g_absVMax); @@ -447,7 +448,8 @@ void Plot::PlotGraph(int *buffer, size_t len, QRect plotRect, QRect annotationRe if (v > vMax) vMax = v; vMean += v; } - vMean /= (i - GraphStart); + GraphStop = i; + vMean /= (GraphStop - GraphStart); painter->setPen(getColor(graphNum)); @@ -483,10 +485,9 @@ void Plot::PlotGraph(int *buffer, size_t len, QRect plotRect, QRect annotationRe //Graph annotations painter->drawPath(penPath); char str[200]; - sprintf(str, "max=%d min=%d mean=%d n=%u/%zu CursorAVal=[%d] CursorBVal=[%d]", - vMax, vMin, vMean, i, len, buffer[CursorAPos], buffer[CursorBPos]); + sprintf(str, "max=%d min=%d mean=%" PRId64 " n=%u/%zu CursorAVal=[%d] CursorBVal=[%d]", + vMax, vMin, vMean, GraphStop - GraphStart, len, buffer[CursorAPos], buffer[CursorBPos]); painter->drawText(20, annotationRect.bottom() - 23 - 20 * graphNum, str); - //clock_t end = clock(); //double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC; //printf("Plot time %f\n", elapsed_secs); @@ -596,11 +597,19 @@ void Plot::paintEvent(QPaintEvent *event) { //Draw annotations char str[200]; - sprintf(str, "@%u dt=%i [%2.2f %s] zoom=%2.2f CursorAPos=%u CursorBPos=%u GridX=%d GridY=%d (%s) GridXoffset=%d", + char scalestr[30] = {0}; + if (CursorScaleFactor != 1) { + if (CursorScaleFactorUnit[0] == '\x00') { + sprintf(scalestr, "[%2.2f] ", ((int32_t)(CursorBPos - CursorAPos)) / CursorScaleFactor); + } else { + sprintf(scalestr, "[%2.2f %s] ", ((int32_t)(CursorBPos - CursorAPos)) / CursorScaleFactor, CursorScaleFactorUnit); + } + } + sprintf(str, "@%u..%u dt=%i %szoom=%2.2f CursorAPos=%u CursorBPos=%u GridX=%d GridY=%d (%s) GridXoffset=%d", GraphStart, + GraphStop, CursorBPos - CursorAPos, - ((int32_t)(CursorBPos - CursorAPos)) / CursorScaleFactor, - CursorScaleFactorUint, + scalestr, GraphPixelsPerPoint, CursorAPos, CursorBPos, diff --git a/client/src/proxguiqt.h b/client/src/proxguiqt.h index 3264a2919..ea9638832 100644 --- a/client/src/proxguiqt.h +++ b/client/src/proxguiqt.h @@ -32,6 +32,7 @@ class Plot: public QWidget { private: QWidget *master; uint32_t GraphStart; // Starting point/offset for the left side of the graph + uint32_t GraphStop; // Stop point/offset for the right side of the graph double GraphPixelsPerPoint; // How many visual pixels are between each sample point (x axis) uint32_t CursorAPos; uint32_t CursorBPos; diff --git a/client/src/ui.c b/client/src/ui.c index 579b21f42..ecc0cb94e 100644 --- a/client/src/ui.c +++ b/client/src/ui.c @@ -38,7 +38,7 @@ session_arg_t session; double CursorScaleFactor = 1; -char CursorScaleFactorUint[11] = {0}; +char CursorScaleFactorUnit[11] = {0}; int PlotGridX = 0, PlotGridY = 0, PlotGridXdefault = 64, PlotGridYdefault = 64; uint32_t CursorCPos = 0, CursorDPos = 0; double GraphPixelsPerPoint = 1.f; // How many visual pixels are between each sample point (x axis)