From: marshmellow42 Date: Mon, 17 Apr 2017 22:37:23 +0000 (-0400) Subject: new grid X offset calcs to fix some issues X-Git-Tag: v3.0.0~12^2~3 X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/3fd7fce4accbe4c5b59987fa4979ec46adcb459c?hp=-c new grid X offset calcs to fix some issues also fixed a save_restore issue with grid alignments now save_restoreGB() saves/restores offset values added macro enumeration of SAVE vs RESTORE for save_restore commands. --- 3fd7fce4accbe4c5b59987fa4979ec46adcb459c diff --git a/client/cmddata.c b/client/cmddata.c index 87c54231..c12c2ce6 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -71,7 +71,7 @@ void save_restoreDB(uint8_t saveOpt) static int savedDemodStartIdx = 0; static int savedDemodClock = 0; - if (saveOpt==1) { //save + if (saveOpt == GRAPH_SAVE) { //save memcpy(SavedDB, DemodBuffer, sizeof(DemodBuffer)); SavedDBlen = DemodBufferLen; @@ -1077,7 +1077,7 @@ void setClockGrid(int clk, int offset) { g_DemodClock = clk; if (g_debugMode) PrintAndLog("demodoffset %d, clk %d",offset,clk); - if (offset > clk) offset %= clk; + if (offset > clk) offset %= clk; if (offset < 0) offset += clk; if (offset > GraphTraceLen || offset < 0) return; diff --git a/client/cmdlf.c b/client/cmdlf.c index b18cf215..49c9ea39 100644 --- a/client/cmdlf.c +++ b/client/cmdlf.c @@ -879,25 +879,25 @@ int CheckChipType(char cmdp) { if (offline || cmdp == '1') return 0; - save_restoreGB(1); - save_restoreDB(1); + save_restoreGB(GRAPH_SAVE); + save_restoreDB(GRAPH_SAVE); //check for em4x05/em4x69 chips first if (EM4x05Block0Test(&wordData)) { PrintAndLog("\nValid EM4x05/EM4x69 Chip Found\nTry lf em 4x05... commands\n"); - save_restoreGB(0); - save_restoreDB(0); + save_restoreGB(GRAPH_RESTORE); + save_restoreDB(GRAPH_RESTORE); return 1; } //check for t55xx chip... if (tryDetectP1(true)) { PrintAndLog("\nValid T55xx Chip Found\nTry lf t55xx ... commands\n"); - save_restoreGB(0); - save_restoreDB(0); + save_restoreGB(GRAPH_RESTORE); + save_restoreDB(GRAPH_RESTORE); return 1; } - save_restoreGB(0); - save_restoreDB(0); + save_restoreGB(GRAPH_RESTORE); + save_restoreDB(GRAPH_RESTORE); return 0; } @@ -1057,7 +1057,7 @@ int CmdLFfind(const char *Cmd) PrintAndLog("\nNo Known Tags Found!\n"); if (testRaw=='u' || testRaw=='U') { - ans=CheckChipType(cmdp); + //ans=CheckChipType(cmdp); //test unknown tag formats (raw mode)0 PrintAndLog("\nChecking for Unknown tags:\n"); ans=AutoCorrelate(GraphBuffer, GraphBuffer, GraphTraceLen, 4000, false, false); diff --git a/client/cmdlfem4x.c b/client/cmdlfem4x.c index 4e0ada57..e84cccf9 100644 --- a/client/cmdlfem4x.c +++ b/client/cmdlfem4x.c @@ -571,7 +571,7 @@ int EM4x50Read(const char *Cmd, bool verbose) start = skip; snprintf(tmp2, sizeof(tmp2),"%d %d 1000 %d", clk, invert, clk*47); // save GraphBuffer - to restore it later - save_restoreGB(1); + save_restoreGB(GRAPH_SAVE); // get rid of leading crap snprintf(tmp, sizeof(tmp), "%i", skip); CmdLtrim(tmp); @@ -599,7 +599,7 @@ int EM4x50Read(const char *Cmd, bool verbose) phaseoff = 0; i += 2; if (ASKDemod(tmp2, false, false, 1) < 1) { - save_restoreGB(0); + save_restoreGB(GRAPH_RESTORE); return 0; } //set DemodBufferLen to just one block @@ -638,7 +638,7 @@ int EM4x50Read(const char *Cmd, bool verbose) } //restore GraphBuffer - save_restoreGB(0); + save_restoreGB(GRAPH_RESTORE); return (int)AllPTest; } diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index ed8e3152..252aaaa2 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -419,23 +419,23 @@ bool DecodeT55xxBlock(){ break; case DEMOD_PSK1: // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise) - save_restoreGB(1); + save_restoreGB(GRAPH_SAVE); CmdLtrim("160"); snprintf(cmdStr, sizeof(buf),"%d %d 6", bitRate[config.bitrate], config.inverted ); ans = PSKDemod(cmdStr, false); //undo trim samples - save_restoreGB(0); + save_restoreGB(GRAPH_RESTORE); break; case DEMOD_PSK2: //inverted won't affect this case DEMOD_PSK3: //not fully implemented // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise) - save_restoreGB(1); + save_restoreGB(GRAPH_SAVE); CmdLtrim("160"); snprintf(cmdStr, sizeof(buf),"%d 0 6", bitRate[config.bitrate] ); ans = PSKDemod(cmdStr, false); psk1TOpsk2(DemodBuffer, DemodBufferLen); //undo trim samples - save_restoreGB(0); + save_restoreGB(GRAPH_RESTORE); break; case DEMOD_NRZ: snprintf(cmdStr, sizeof(buf),"%d %d 1", bitRate[config.bitrate], config.inverted ); @@ -594,7 +594,7 @@ bool tryDetectModulation(){ clk = GetPskClock("", false, false); if (clk>0) { // allow undo - save_restoreGB(1); + save_restoreGB(GRAPH_SAVE); // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise) CmdLtrim("160"); if ( PSKDemod("0 0 6", false) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) { @@ -638,7 +638,7 @@ bool tryDetectModulation(){ } } // inverse waves does not affect this demod //undo trim samples - save_restoreGB(0); + save_restoreGB(GRAPH_RESTORE); } } if ( hits == 1) { diff --git a/client/graph.c b/client/graph.c index cc0ec6fb..3ea47d2d 100644 --- a/client/graph.c +++ b/client/graph.c @@ -53,16 +53,19 @@ int ClearGraph(int redraw) void save_restoreGB(uint8_t saveOpt) { static int SavedGB[MAX_GRAPH_TRACE_LEN]; - static int SavedGBlen; + static int SavedGBlen=0; static bool GB_Saved = false; + static int SavedGridOffsetAdj=0; - if (saveOpt==1) { //save + if (saveOpt == GRAPH_SAVE) { //save memcpy(SavedGB, GraphBuffer, sizeof(GraphBuffer)); SavedGBlen = GraphTraceLen; GB_Saved=true; - } else if (GB_Saved){ //restore + SavedGridOffsetAdj = GridOffset; + } else if (GB_Saved) { //restore memcpy(GraphBuffer, SavedGB, sizeof(GraphBuffer)); GraphTraceLen = SavedGBlen; + GridOffset = SavedGridOffsetAdj; RepaintGraphWindow(); } return; diff --git a/client/graph.h b/client/graph.h index d77db301..b20ae4e8 100644 --- a/client/graph.h +++ b/client/graph.h @@ -32,6 +32,8 @@ void DetectHighLowInGraph(int *high, int *low, bool addFuzz); // Max graph trace len: 40000 (bigbuf) * 8 (at 1 bit per sample) #define MAX_GRAPH_TRACE_LEN (40000 * 8 ) +#define GRAPH_SAVE 1 +#define GRAPH_RESTORE 0 extern int GraphBuffer[MAX_GRAPH_TRACE_LEN]; extern int GraphTraceLen; diff --git a/client/proxgui.h b/client/proxgui.h index 846ac45d..74c5063c 100644 --- a/client/proxgui.h +++ b/client/proxgui.h @@ -40,6 +40,8 @@ extern int AutoCorrelate(const int *in, int *out, size_t len, int window, bool S extern int directionalThreshold(const int* in, int *out, size_t len, int8_t up, int8_t down); extern void save_restoreGB(uint8_t saveOpt); +#define GRAPH_SAVE 1 +#define GRAPH_RESTORE 0 #define MAX_DEMOD_BUF_LEN (1024*128) extern uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN]; extern size_t DemodBufferLen; diff --git a/client/proxguiqt.cpp b/client/proxguiqt.cpp index 6171c429..3805411d 100644 --- a/client/proxguiqt.cpp +++ b/client/proxguiqt.cpp @@ -32,7 +32,7 @@ bool g_useOverlays = false; int g_absVMax = 0; int startMax; int PageWidth; - +int unlockStart = 0; void ProxGuiQT::ShowGraphWindow(void) { @@ -119,13 +119,13 @@ ProxGuiQT::~ProxGuiQT(void) void ProxWidget::applyOperation() { //printf("ApplyOperation()"); - save_restoreGB(1); + save_restoreGB(GRAPH_SAVE); memcpy(GraphBuffer, s_Buff, sizeof(int) * GraphTraceLen); RepaintGraphWindow(); } void ProxWidget::stickOperation() { - save_restoreGB(0); + save_restoreGB(GRAPH_RESTORE); //printf("stickOperation()"); } void ProxWidget::vchange_autocorr(int v) @@ -434,11 +434,22 @@ void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect, void Plot::plotGridLines(QPainter* painter,QRect r) { + // set GridOffset + if (PlotGridX <= 0) return; + int offset = GridOffset; + if (GridLocked && PlotGridX) { + offset = GridOffset + PlotGridX - (GraphStart % PlotGridX); + } else if (!GridLocked && GraphStart > 0 && PlotGridX) { + offset = PlotGridX-((GraphStart - offset) % PlotGridX) + GraphStart - unlockStart; + } + offset %= PlotGridX; + if (offset < 0) offset += PlotGridX; + int i; int grid_delta_x = (int) (PlotGridX * GraphPixelsPerPoint); int grid_delta_y = PlotGridY; if ((PlotGridX > 0) && ((PlotGridX * GraphPixelsPerPoint) > 1)) { - for(i = (GridOffset * GraphPixelsPerPoint); i < r.right(); i += grid_delta_x) { + for(i = (offset * GraphPixelsPerPoint); i < r.right(); i += grid_delta_x) { painter->drawLine(r.left()+i, r.top(), r.left()+i, r.bottom()); } } @@ -581,9 +592,6 @@ void Plot::mouseMoveEvent(QMouseEvent *event) void Plot::keyPressEvent(QKeyEvent *event) { int offset; - int gridchanged; - - gridchanged= 0; if(event->modifiers() & Qt::ShiftModifier) { if (PlotGridX) @@ -611,53 +619,18 @@ void Plot::keyPressEvent(QKeyEvent *event) case Qt::Key_Right: if(GraphPixelsPerPoint < 20) { - if (PlotGridX && GridLocked && GraphStart < startMax){ - GridOffset -= offset; - GridOffset %= PlotGridX; - gridchanged= 1; - } GraphStart += offset; } else { - if (PlotGridX && GridLocked && GraphStart < startMax){ - GridOffset--; - GridOffset %= PlotGridX; - gridchanged= 1; - } GraphStart++; } - if(GridOffset < 0) { - GridOffset += PlotGridX; - } - if (gridchanged) - if (GraphStart > startMax) { - GridOffset += (GraphStart - startMax); - GridOffset %= PlotGridX; - } break; case Qt::Key_Left: if(GraphPixelsPerPoint < 20) { - if (PlotGridX && GridLocked && GraphStart > 0){ - GridOffset += offset; - GridOffset %= PlotGridX; - gridchanged= 1; - } GraphStart -= offset; } else { - if (PlotGridX && GridLocked && GraphStart > 0){ - GridOffset++; - GridOffset %= PlotGridX; - gridchanged= 1; - } GraphStart--; } - if (gridchanged){ - if (GraphStart < 0) - GridOffset += GraphStart; - if(GridOffset < 0) - GridOffset += PlotGridX; - GridOffset %= PlotGridX; - } break; case Qt::Key_G: @@ -667,7 +640,7 @@ void Plot::keyPressEvent(QKeyEvent *event) } else { PlotGridX= PlotGridXdefault; PlotGridY= PlotGridYdefault; - } + } break; case Qt::Key_H: @@ -692,7 +665,11 @@ void Plot::keyPressEvent(QKeyEvent *event) break; case Qt::Key_L: - GridLocked= !GridLocked; + GridLocked = !GridLocked; + if (GridLocked) + GridOffset += (GraphStart - unlockStart); + else + unlockStart = GraphStart; break; case Qt::Key_Q: