diff --git a/client/src/cmddata.c b/client/src/cmddata.c index a5e6c7784..bdeca3043 100644 --- a/client/src/cmddata.c +++ b/client/src/cmddata.c @@ -3788,60 +3788,59 @@ static int CmdXor(const char *Cmd) { } static command_t CommandTable[] = { - {"-----------", CmdHelp, AlwaysAvailable, "------------------------- " _CYAN_("General") "-------------------------"}, - {"help", CmdHelp, AlwaysAvailable, "This help"}, - {"-----------", CmdHelp, AlwaysAvailable, "------------------------- " _CYAN_("Modulation") "-------------------------"}, - {"biphaserawdecode", CmdBiphaseDecodeRaw, AlwaysAvailable, "Biphase decode bin stream in DemodBuffer"}, - {"detectclock", CmdDetectClockRate, AlwaysAvailable, "Detect ASK, FSK, NRZ, PSK clock rate of wave in GraphBuffer"}, - {"fsktonrz", CmdFSKToNRZ, AlwaysAvailable, "Convert fsk2 to nrz wave for alternate fsk demodulating (for weak fsk)"}, - {"manrawdecode", Cmdmandecoderaw, AlwaysAvailable, "Manchester decode binary stream in DemodBuffer"}, - {"modulation", CmdDataModulationSearch, AlwaysAvailable, "Identify LF signal for clock and modulation"}, - {"rawdemod", CmdRawDemod, AlwaysAvailable, "Demodulate the data in the GraphBuffer and output binary"}, + {"-----------", CmdHelp, AlwaysAvailable, "------------------------- " _CYAN_("General") "-------------------------"}, + {"help", CmdHelp, AlwaysAvailable, "This help"}, + {"clear", CmdBuffClear, AlwaysAvailable, "Clears various buffers used by the graph window"}, + {"hide", CmdHide, AlwaysAvailable, "Hide the graph window"}, + {"plot", CmdPlot, AlwaysAvailable, "Show the graph window"}, + {"load", CmdLoad, AlwaysAvailable, "Load contents of file into graph window"}, + {"save", CmdSave, AlwaysAvailable, "Save signal trace data"}, - {"-----------", CmdHelp, AlwaysAvailable, "------------------------- " _CYAN_("Graph") "-------------------------"}, - {"askedgedetect", CmdAskEdgeDetect, AlwaysAvailable, "Adjust Graph for manual ASK demod"}, - {"autocorr", CmdAutoCorr, AlwaysAvailable, "Autocorrelation over window"}, - {"dirthreshold", CmdDirectionalThreshold, AlwaysAvailable, "Max rising higher up-thres/ Min falling lower down-thres"}, - {"decimate", CmdDecimate, AlwaysAvailable, "Decimate samples"}, - {"envelope", CmdEnvelope, AlwaysAvailable, "Generate square envelope of samples"}, - {"undecimate", CmdUndecimate, AlwaysAvailable, "Un-decimate samples"}, - {"hide", CmdHide, AlwaysAvailable, "Hide graph window"}, - {"hpf", CmdHpf, AlwaysAvailable, "Remove DC offset from trace"}, - {"iir", CmdDataIIR, AlwaysAvailable, "Apply IIR buttersworth filter on plot data"}, - {"grid", CmdGrid, AlwaysAvailable, "overlay grid on graph window"}, - {"ltrim", CmdLtrim, AlwaysAvailable, "Trim samples from left of trace"}, - {"mtrim", CmdMtrim, AlwaysAvailable, "Trim out samples from the specified start to the specified stop"}, - {"norm", CmdNorm, AlwaysAvailable, "Normalize max/min to +/-128"}, - {"plot", CmdPlot, AlwaysAvailable, "Show graph window"}, + {"-----------", CmdHelp, AlwaysAvailable, "------------------------- " _CYAN_("Modulation") "-------------------------"}, + {"detectclock", CmdDetectClockRate, AlwaysAvailable, "Detect ASK, FSK, NRZ, PSK clock rate of wave in GraphBuffer"}, + {"biphaserawdecode", CmdBiphaseDecodeRaw, AlwaysAvailable, "Biphase decode bin stream in DemodBuffer"}, + {"fsktonrz", CmdFSKToNRZ, AlwaysAvailable, "Convert fsk2 to nrz wave for alternate fsk demodulating (for weak fsk)"}, + {"manrawdecode", Cmdmandecoderaw, AlwaysAvailable, "Manchester decode binary stream in DemodBuffer"}, + {"modulation", CmdDataModulationSearch, AlwaysAvailable, "Identify LF signal for clock and modulation"}, + {"rawdemod", CmdRawDemod, AlwaysAvailable, "Demodulate the data in the GraphBuffer and output binary"}, - {"cthreshold", CmdCenterThreshold, AlwaysAvailable, "Average out all values between"}, + {"-----------", CmdHelp, AlwaysAvailable, "------------------------- " _CYAN_("Graph") "-------------------------"}, + {"askedgedetect", CmdAskEdgeDetect, AlwaysAvailable, "Adjust Graph for manual ASK demod"}, + {"autocorr", CmdAutoCorr, AlwaysAvailable, "Autocorrelation over window"}, + {"cthreshold", CmdCenterThreshold, AlwaysAvailable, "Average out all values between"}, + {"dirthreshold", CmdDirectionalThreshold, AlwaysAvailable, "Max rising higher up-thres/ Min falling lower down-thres"}, + {"decimate", CmdDecimate, AlwaysAvailable, "Decimate samples"}, + {"undecimate", CmdUndecimate, AlwaysAvailable, "Un-decimate samples"}, + {"envelope", CmdEnvelope, AlwaysAvailable, "Generate square envelope of samples"}, + {"grid", CmdGrid, AlwaysAvailable, "overlay grid on graph window"}, + {"hpf", CmdHpf, AlwaysAvailable, "Remove DC offset from trace"}, + {"iir", CmdDataIIR, AlwaysAvailable, "Apply IIR buttersworth filter on plot data"}, + {"ltrim", CmdLtrim, AlwaysAvailable, "Trim samples from left of trace"}, + {"mtrim", CmdMtrim, AlwaysAvailable, "Trim out samples from the specified start to the specified stop"}, + {"rtrim", CmdRtrim, AlwaysAvailable, "Trim samples from right of trace"}, + {"norm", CmdNorm, AlwaysAvailable, "Normalize max/min to +/-128"}, + {"setgraphmarkers", CmdSetGraphMarkers, AlwaysAvailable, "Set blue and orange marker in graph window"}, + {"shiftgraphzero", CmdGraphShiftZero, AlwaysAvailable, "Shift 0 for Graphed wave + or - shift value"}, + {"timescale", CmdTimeScale, AlwaysAvailable, "Set cursor display timescale"}, + {"convertbitstream", CmdConvertBitStream, AlwaysAvailable, "Convert GraphBuffer's 0/1 values to 127 / -127"}, + {"getbitstream", CmdGetBitStream, AlwaysAvailable, "Convert GraphBuffer's >=1 values to 1 and <1 to 0"}, + {"zerocrossings", CmdZerocrossings, AlwaysAvailable, "Count time between zero-crossings"}, - {"rtrim", CmdRtrim, AlwaysAvailable, "Trim samples from right of trace"}, - {"setgraphmarkers", CmdSetGraphMarkers, AlwaysAvailable, "Set blue and orange marker in graph window"}, - {"shiftgraphzero", CmdGraphShiftZero, AlwaysAvailable, "Shift 0 for Graphed wave + or - shift value"}, - {"timescale", CmdTimeScale, AlwaysAvailable, "Set cursor display timescale"}, - {"zerocrossings", CmdZerocrossings, AlwaysAvailable, "Count time between zero-crossings"}, - {"convertbitstream", CmdConvertBitStream, AlwaysAvailable, "Convert GraphBuffer's 0/1 values to 127 / -127"}, - {"getbitstream", CmdGetBitStream, AlwaysAvailable, "Convert GraphBuffer's >=1 values to 1 and <1 to 0"}, - - {"-----------", CmdHelp, AlwaysAvailable, "------------------------- " _CYAN_("Operations") "-------------------------"}, - {"asn1", CmdAsn1Decoder, AlwaysAvailable, "ASN1 decoder"}, - {"atr", CmdAtrLookup, AlwaysAvailable, "ATR lookup"}, - {"bin2hex", Cmdbin2hex, AlwaysAvailable, "Converts binary to hexadecimal"}, - {"bitsamples", CmdBitsamples, IfPm3Present, "Get raw samples as bitstring"}, - {"bmap", CmdBinaryMap, AlwaysAvailable, "Convert hex value according a binary template"}, - {"clear", CmdBuffClear, AlwaysAvailable, "Clears bigbuf on deviceside and graph window"}, - {"crypto", CmdCryptography, AlwaysAvailable, "Encrypt and decrypt data"}, - {"diff", CmdDiff, AlwaysAvailable, "Diff of input files"}, - {"hexsamples", CmdHexsamples, IfPm3Present, "Dump big buffer as hex bytes"}, - {"hex2bin", Cmdhex2bin, AlwaysAvailable, "Converts hexadecimal to binary"}, - {"load", CmdLoad, AlwaysAvailable, "Load contents of file into graph window"}, - {"num", CmdNumCon, AlwaysAvailable, "Converts dec/hex/bin"}, - {"print", CmdPrintDemodBuff, AlwaysAvailable, "Print the data in the DemodBuffer"}, - {"samples", CmdSamples, IfPm3Present, "Get raw samples for graph window ( GraphBuffer )"}, - {"save", CmdSave, AlwaysAvailable, "Save signal trace data ( GraphBuffer )"}, - {"setdebugmode", CmdSetDebugMode, AlwaysAvailable, "Set Debugging Level on client side"}, - {"xor", CmdXor, AlwaysAvailable, "Xor a input string"}, + {"-----------", CmdHelp, AlwaysAvailable, "------------------------- " _CYAN_("Operations") "-------------------------"}, + {"asn1", CmdAsn1Decoder, AlwaysAvailable, "ASN1 decoder"}, + {"atr", CmdAtrLookup, AlwaysAvailable, "ATR lookup"}, + {"bin2hex", Cmdbin2hex, AlwaysAvailable, "Converts binary to hexadecimal"}, + {"bitsamples", CmdBitsamples, IfPm3Present, "Get raw samples as bitstring"}, + {"bmap", CmdBinaryMap, AlwaysAvailable, "Convert hex value according a binary template"}, + {"crypto", CmdCryptography, AlwaysAvailable, "Encrypt and decrypt data"}, + {"diff", CmdDiff, AlwaysAvailable, "Diff of input files"}, + {"hexsamples", CmdHexsamples, IfPm3Present, "Dump big buffer as hex bytes"}, + {"hex2bin", Cmdhex2bin, AlwaysAvailable, "Converts hexadecimal to binary"}, + {"num", CmdNumCon, AlwaysAvailable, "Converts dec/hex/bin"}, + {"print", CmdPrintDemodBuff, AlwaysAvailable, "Print the data in the DemodBuffer"}, + {"samples", CmdSamples, IfPm3Present, "Get raw samples for graph window ( GraphBuffer )"}, + {"setdebugmode", CmdSetDebugMode, AlwaysAvailable, "Set Debugging Level on client side"}, + {"xor", CmdXor, AlwaysAvailable, "Xor a input string"}, {NULL, NULL, NULL, NULL} }; diff --git a/client/src/graph.c b/client/src/graph.c index 8b97dcfad..7d77aabf2 100644 --- a/client/src/graph.c +++ b/client/src/graph.c @@ -26,6 +26,7 @@ int g_GraphBuffer[MAX_GRAPH_TRACE_LEN]; +int g_OperationBuffer[MAX_GRAPH_TRACE_LEN]; size_t g_GraphTraceLen; /* write a manchester bit to the graph @@ -68,6 +69,7 @@ void AppendGraph(bool redraw, uint16_t clock, int bit) { size_t ClearGraph(bool redraw) { size_t gtl = g_GraphTraceLen; memset(g_GraphBuffer, 0x00, g_GraphTraceLen); + memset(g_OperationBuffer, 0x00, g_GraphTraceLen); g_GraphTraceLen = 0; g_GraphStart = 0; g_GraphStop = 0; @@ -78,6 +80,7 @@ size_t ClearGraph(bool redraw) { return gtl; } + // option '1' to save g_GraphBuffer any other to restore void save_restoreGB(uint8_t saveOpt) { static int SavedGB[MAX_GRAPH_TRACE_LEN]; @@ -92,6 +95,7 @@ void save_restoreGB(uint8_t saveOpt) { Savedg_GridOffsetAdj = g_GridOffset; } else if (GB_Saved) { //restore memcpy(g_GraphBuffer, SavedGB, sizeof(g_GraphBuffer)); + memcpy(g_OperationBuffer, SavedGB, sizeof(g_OperationBuffer)); g_GraphTraceLen = SavedGBlen; g_GridOffset = Savedg_GridOffsetAdj; RepaintGraphWindow(); @@ -103,11 +107,14 @@ void setGraphBuf(const uint8_t *src, size_t size) { ClearGraph(false); - if (size > MAX_GRAPH_TRACE_LEN) + if (size > MAX_GRAPH_TRACE_LEN) { size = MAX_GRAPH_TRACE_LEN; + } - for (size_t i = 0; i < size; ++i) + for (size_t i = 0; i < size; ++i) { g_GraphBuffer[i] = src[i] - 128; + g_OperationBuffer[i] = src[i] - 128; + } g_GraphTraceLen = size; RepaintGraphWindow(); diff --git a/client/src/graph.h b/client/src/graph.h index 3a05dd8eb..b5cbf99e0 100644 --- a/client/src/graph.h +++ b/client/src/graph.h @@ -48,6 +48,7 @@ bool fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, int *firstClockEdge); #define GRAPH_RESTORE 0 extern int g_GraphBuffer[MAX_GRAPH_TRACE_LEN]; +extern int g_OperationBuffer[MAX_GRAPH_TRACE_LEN]; extern size_t g_GraphTraceLen; #ifdef __cplusplus diff --git a/client/src/proxguiqt.cpp b/client/src/proxguiqt.cpp index 3bfdca727..fa141bbe1 100644 --- a/client/src/proxguiqt.cpp +++ b/client/src/proxguiqt.cpp @@ -45,7 +45,7 @@ extern "C" int preferences_save(void); -static int s_Buff[MAX_GRAPH_TRACE_LEN]; +static int s_OverlayBuff[MAX_GRAPH_TRACE_LEN]; static bool gs_useOverlays = false; static int gs_absVMax = 0; static uint32_t startMax; // Maximum offset in the graph (right side of graph) @@ -340,7 +340,7 @@ void SliderWidget::moveEvent(QMoveEvent *event) { void ProxWidget::applyOperation() { //printf("ApplyOperation()"); save_restoreGB(GRAPH_SAVE); - memcpy(g_GraphBuffer, s_Buff, sizeof(int) * g_GraphTraceLen); + memcpy(g_GraphBuffer, s_OverlayBuff, sizeof(int) * g_GraphTraceLen); RepaintGraphWindow(); } void ProxWidget::stickOperation() { @@ -348,21 +348,21 @@ void ProxWidget::stickOperation() { //printf("stickOperation()"); } void ProxWidget::vchange_autocorr(int v) { - int ans = AutoCorrelate(g_GraphBuffer, s_Buff, g_GraphTraceLen, v, true, false); + int ans = AutoCorrelate(g_GraphBuffer, s_OverlayBuff, g_GraphTraceLen, v, true, false); if (g_debugMode) printf("vchange_autocorr(w:%d): %d\n", v, ans); gs_useOverlays = true; RepaintGraphWindow(); } void ProxWidget::vchange_askedge(int v) { //extern int AskEdgeDetect(const int *in, int *out, int len, int threshold); - int ans = AskEdgeDetect(g_GraphBuffer, s_Buff, g_GraphTraceLen, v); + int ans = AskEdgeDetect(g_GraphBuffer, s_OverlayBuff, g_GraphTraceLen, v); if (g_debugMode) printf("vchange_askedge(w:%d)%d\n", v, ans); gs_useOverlays = true; RepaintGraphWindow(); } void ProxWidget::vchange_dthr_up(int v) { int down = opsController->horizontalSlider_dirthr_down->value(); - directionalThreshold(g_GraphBuffer, s_Buff, g_GraphTraceLen, v, down); + directionalThreshold(g_GraphBuffer, s_OverlayBuff, g_GraphTraceLen, v, down); //printf("vchange_dthr_up(%d)", v); gs_useOverlays = true; RepaintGraphWindow(); @@ -370,7 +370,7 @@ void ProxWidget::vchange_dthr_up(int v) { void ProxWidget::vchange_dthr_down(int v) { //printf("vchange_dthr_down(%d)", v); int up = opsController->horizontalSlider_dirthr_up->value(); - directionalThreshold(g_GraphBuffer, s_Buff, g_GraphTraceLen, v, up); + directionalThreshold(g_GraphBuffer, s_OverlayBuff, g_GraphTraceLen, v, up); gs_useOverlays = true; RepaintGraphWindow(); } @@ -538,6 +538,7 @@ static const QColor GREEN = QColor(100, 255, 100); static const QColor RED = QColor(255, 100, 100); static const QColor BLUE = QColor(100, 100, 255); static const QColor YELLOW = QColor(255, 255, 0); +static const QColor CITRON = QColor(215, 197, 46); static const QColor PINK = QColor(255, 0, 255); static const QColor ORANGE = QColor(255, 153, 0); static const QColor LIGHTBLUE = QColor(100, 209, 246); @@ -566,7 +567,7 @@ void Plot::setMaxAndStart(int *buffer, size_t len, QRect plotRect) { uint32_t t = (plotRect.right() - plotRect.left() - 40) / g_GraphPixelsPerPoint; if (len >= t) { startMax = len - t; - } + } } if (g_GraphStart > startMax) { @@ -778,6 +779,41 @@ void Plot::plotGridLines(QPainter *painter, QRect r) { } } +void Plot::plotOperations(int *buffer, size_t len, QPainter *painter, QRect plotRect) { + if(len == 0) { + return; + } + + QPainterPath penPath; + int32_t x = xCoordOf(g_GraphStart, plotRect), prevX = 0; + int32_t y = yCoordOf(buffer[g_GraphStart], plotRect, gs_absVMax), prevY = 0; + int32_t current = 0; + + for (uint32_t pos = g_GraphStart; pos < len && xCoordOf(pos, plotRect) < plotRect.right(); pos++) { + //Store the previous x and y values to move the pen to if we need to draw a line + prevX = x; + prevY = y; + + x = xCoordOf(pos, plotRect); + current = buffer[pos]; + y = yCoordOf(current, plotRect, gs_absVMax); + + //We only want to graph changes between the Graph Buffer and the Operation Buffer + if(current == g_GraphBuffer[pos]) continue; + + penPath.moveTo(prevX, prevY); //Move the pen + penPath.lineTo(x, y); //Draw the line from the previous coords to the new ones + + if (g_GraphPixelsPerPoint > 10) { + QRect point(QPoint(x - 3, y - 3), QPoint(x + 3, y + 3)); + painter->fillRect(point, WHITE); + } + } + + painter->setPen(CITRON); + painter->drawPath(penPath); +} + #define HEIGHT_INFO 60 #define WIDTH_AXES 80 @@ -824,10 +860,16 @@ void Plot::paintEvent(QPaintEvent *event) { if (g_DemodBufferLen > 8) { PlotDemod(g_DemodBuffer, g_DemodBufferLen, plotRect, infoRect, &painter, 2, g_DemodStartIdx); } + + //Plot the Operation Overlay + //setMaxAndStart(g_OperationBuffer, g_GraphTraceLen, plotRect); + plotOperations(g_OperationBuffer, g_GraphTraceLen, &painter, plotRect); + + //Plot the Overlay if (gs_useOverlays) { //init graph variables - setMaxAndStart(s_Buff, g_GraphTraceLen, plotRect); - PlotGraph(s_Buff, g_GraphTraceLen, plotRect, infoRect, &painter, 1); + setMaxAndStart(s_OverlayBuff, g_GraphTraceLen, plotRect); + PlotGraph(s_OverlayBuff, g_GraphTraceLen, plotRect, infoRect, &painter, 1); } // End graph drawing @@ -1260,33 +1302,55 @@ void Plot::keyPressEvent(QKeyEvent *event) { RepaintGraphWindow(); break; - case Qt::Key_BracketLeft: + case Qt::Key_BracketLeft: { if(event->modifiers() & Qt::ControlModifier) { CursorAPos -= 5; } else { CursorAPos -= 1; } + if((CursorAPos >= g_GraphStop) || (CursorAPos <= g_GraphStart)) { + uint32_t halfway = PageWidth / 2; + + if((CursorAPos - halfway) > g_GraphTraceLen) { + g_GraphStart = 0; + } else { + g_GraphStart = CursorAPos - halfway; + } + } + if(CursorAPos < g_GraphStart) { CursorAPos = g_GraphStart; } RepaintGraphWindow(); break; + } - case Qt::Key_BracketRight: + case Qt::Key_BracketRight: { if(event->modifiers() & Qt::ControlModifier) { CursorAPos += 5; } else { CursorAPos += 1; } + if((CursorAPos >= g_GraphStop) || (CursorAPos <= g_GraphStart)) { + uint32_t halfway = PageWidth / 2; + + if((CursorAPos + halfway) >= g_GraphTraceLen) { + g_GraphStart = g_GraphTraceLen - halfway; + } else { + g_GraphStart = CursorAPos - halfway; + } + } + if(CursorAPos >= g_GraphTraceLen) { CursorAPos = g_GraphTraceLen; } RepaintGraphWindow(); break; + } case Qt::Key_BraceLeft: if(event->modifiers() & Qt::ControlModifier) { diff --git a/client/src/proxguiqt.h b/client/src/proxguiqt.h index 244d083e3..5fd739073 100644 --- a/client/src/proxguiqt.h +++ b/client/src/proxguiqt.h @@ -48,6 +48,7 @@ class Plot: public QWidget { void PlotGraph(int *buffer, size_t len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum); void PlotDemod(uint8_t *buffer, size_t len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum, uint32_t plotOffset); void plotGridLines(QPainter *painter, QRect r); + void plotOperations(int *buffer, size_t len, QPainter *painter, QRect rect); int xCoordOf(int i, QRect r); int yCoordOf(int v, QRect r, int maxVal); int valueOf_yCoord(int y, QRect r, int maxVal);