plot: fix mean, rework annotations

This commit is contained in:
Philippe Teuwen 2020-10-04 20:01:08 +02:00
commit e179fdb3b0
5 changed files with 25 additions and 15 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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,

View file

@ -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;

View file

@ -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)