]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
new grid X offset calcs to fix some issues graphwork2
authormarshmellow42 <marshmellowrf@gmail.com>
Mon, 17 Apr 2017 22:37:23 +0000 (18:37 -0400)
committermarshmellow42 <marshmellowrf@gmail.com>
Mon, 17 Apr 2017 22:37:23 +0000 (18:37 -0400)
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.

client/cmddata.c
client/cmdlf.c
client/cmdlfem4x.c
client/cmdlft55xx.c
client/graph.c
client/graph.h
client/proxgui.h
client/proxguiqt.cpp

index 87c542312009f2cdefcf5a5b7fbff1feae4b7615..c12c2ce6d58cd9341740a215f81a67b468c73744 100644 (file)
@@ -71,7 +71,7 @@ void save_restoreDB(uint8_t saveOpt)
        static int savedDemodStartIdx = 0;
        static int savedDemodClock = 0;
 
        static int savedDemodStartIdx = 0;
        static int savedDemodClock = 0;
 
-       if (saveOpt==1) { //save
+       if (saveOpt == GRAPH_SAVE) { //save
 
                memcpy(SavedDB, DemodBuffer, sizeof(DemodBuffer));
                SavedDBlen = DemodBufferLen;
 
                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);
 
        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;
        if (offset < 0) offset += clk;
 
        if (offset > GraphTraceLen || offset < 0) return;
index b18cf21583a72abfef9d62f70824808731e9226a..49c9ea39ef23a15f1b13a1518ec781e3aeef0f90 100644 (file)
@@ -879,25 +879,25 @@ int CheckChipType(char cmdp) {
 
        if (offline || cmdp == '1') return 0;
 
 
        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");
        //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");
                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;               
        }
                return 1;               
        }
-       save_restoreGB(0);
-       save_restoreDB(0);
+       save_restoreGB(GRAPH_RESTORE);
+       save_restoreDB(GRAPH_RESTORE);
        return 0;
 }
 
        return 0;
 }
 
@@ -1057,7 +1057,7 @@ int CmdLFfind(const char *Cmd)
 
        PrintAndLog("\nNo Known Tags Found!\n");
        if (testRaw=='u' || testRaw=='U') {
 
        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);
                //test unknown tag formats (raw mode)0
                PrintAndLog("\nChecking for Unknown tags:\n");
                ans=AutoCorrelate(GraphBuffer, GraphBuffer, GraphTraceLen, 4000, false, false);
index 4e0ada5720b212509a8b9c686053a6d6e1f3f8e7..e84cccf97f226e41ae825d0a1d217ac367606126 100644 (file)
@@ -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       
        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);
        // 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) {
                        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
                        return 0;
                }
                //set DemodBufferLen to just one block
@@ -638,7 +638,7 @@ int EM4x50Read(const char *Cmd, bool verbose)
        }
 
        //restore GraphBuffer
        }
 
        //restore GraphBuffer
-       save_restoreGB(0);
+       save_restoreGB(GRAPH_RESTORE);
        return (int)AllPTest;
 }
 
        return (int)AllPTest;
 }
 
index ed8e3152c54c09ea9d8767ada680a9576848279d..252aaaa2a9440cca6812b488b5fd6c8d1ae608de 100644 (file)
@@ -419,23 +419,23 @@ bool DecodeT55xxBlock(){
                        break;\r
                case DEMOD_PSK1:\r
                        // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
                        break;\r
                case DEMOD_PSK1:\r
                        // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
-                       save_restoreGB(1);\r
+                       save_restoreGB(GRAPH_SAVE);\r
                        CmdLtrim("160");\r
                        snprintf(cmdStr, sizeof(buf),"%d %d 6", bitRate[config.bitrate], config.inverted );\r
                        ans = PSKDemod(cmdStr, false);\r
                        //undo trim samples\r
                        CmdLtrim("160");\r
                        snprintf(cmdStr, sizeof(buf),"%d %d 6", bitRate[config.bitrate], config.inverted );\r
                        ans = PSKDemod(cmdStr, false);\r
                        //undo trim samples\r
-                       save_restoreGB(0);\r
+                       save_restoreGB(GRAPH_RESTORE);\r
                        break;\r
                case DEMOD_PSK2: //inverted won't affect this\r
                case DEMOD_PSK3: //not fully implemented\r
                        // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
                        break;\r
                case DEMOD_PSK2: //inverted won't affect this\r
                case DEMOD_PSK3: //not fully implemented\r
                        // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
-                       save_restoreGB(1);\r
+                       save_restoreGB(GRAPH_SAVE);\r
                        CmdLtrim("160");\r
                        snprintf(cmdStr, sizeof(buf),"%d 0 6", bitRate[config.bitrate] );\r
                        ans = PSKDemod(cmdStr, false);\r
                        psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
                        //undo trim samples\r
                        CmdLtrim("160");\r
                        snprintf(cmdStr, sizeof(buf),"%d 0 6", bitRate[config.bitrate] );\r
                        ans = PSKDemod(cmdStr, false);\r
                        psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
                        //undo trim samples\r
-                       save_restoreGB(0);\r
+                       save_restoreGB(GRAPH_RESTORE);\r
                        break;\r
                case DEMOD_NRZ:\r
                        snprintf(cmdStr, sizeof(buf),"%d %d 1", bitRate[config.bitrate], config.inverted );\r
                        break;\r
                case DEMOD_NRZ:\r
                        snprintf(cmdStr, sizeof(buf),"%d %d 1", bitRate[config.bitrate], config.inverted );\r
@@ -594,7 +594,7 @@ bool tryDetectModulation(){
                clk = GetPskClock("", false, false);\r
                if (clk>0) {\r
                        // allow undo\r
                clk = GetPskClock("", false, false);\r
                if (clk>0) {\r
                        // allow undo\r
-                       save_restoreGB(1);\r
+                       save_restoreGB(GRAPH_SAVE);\r
                        // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
                        CmdLtrim("160");\r
                        if ( PSKDemod("0 0 6", false) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
                        // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
                        CmdLtrim("160");\r
                        if ( PSKDemod("0 0 6", false) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
@@ -638,7 +638,7 @@ bool tryDetectModulation(){
                                }\r
                        } // inverse waves does not affect this demod\r
                        //undo trim samples\r
                                }\r
                        } // inverse waves does not affect this demod\r
                        //undo trim samples\r
-                       save_restoreGB(0);\r
+                       save_restoreGB(GRAPH_RESTORE);\r
                }\r
        }       \r
        if ( hits == 1) {\r
                }\r
        }       \r
        if ( hits == 1) {\r
index cc0ec6fb20a95dc9c3d7d8693ec2651bc071d77b..3ea47d2d4267ca30b7cdb5a7645ee350a994808c 100644 (file)
@@ -53,16 +53,19 @@ int ClearGraph(int redraw)
 void save_restoreGB(uint8_t saveOpt)
 {
        static int SavedGB[MAX_GRAPH_TRACE_LEN];
 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 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;
                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;
                memcpy(GraphBuffer, SavedGB, sizeof(GraphBuffer));
                GraphTraceLen = SavedGBlen;
+               GridOffset = SavedGridOffsetAdj;
                RepaintGraphWindow();
        }
        return;
                RepaintGraphWindow();
        }
        return;
index d77db301c8f5dbf88b091a4619ba03d2a8d09213..b20ae4e84552546a73f464a4fa2a0e9da6b0fa56 100644 (file)
@@ -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 )
 
 // 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;
 
 extern int GraphBuffer[MAX_GRAPH_TRACE_LEN];
 extern int GraphTraceLen;
index 846ac45d2add13e69cdb43a0a71e5de088c260f9..74c5063c7fe76a87358c989aeb81d496644b32c0 100644 (file)
@@ -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);
 
 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;
 #define MAX_DEMOD_BUF_LEN (1024*128)
 extern uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN];
 extern size_t DemodBufferLen;
index 6171c429ddb3b22a1239073d5e5bd3cdceb9b4e0..3805411d226e388493e3418fcba8d41a03c71b60 100644 (file)
@@ -32,7 +32,7 @@ bool g_useOverlays = false;
 int g_absVMax = 0;
 int startMax;
 int PageWidth;
 int g_absVMax = 0;
 int startMax;
 int PageWidth;
-
+int unlockStart = 0;
 
 void ProxGuiQT::ShowGraphWindow(void)
 {
 
 void ProxGuiQT::ShowGraphWindow(void)
 {
@@ -119,13 +119,13 @@ ProxGuiQT::~ProxGuiQT(void)
 void ProxWidget::applyOperation()
 {
        //printf("ApplyOperation()");
 void ProxWidget::applyOperation()
 {
        //printf("ApplyOperation()");
-       save_restoreGB(1);
+       save_restoreGB(GRAPH_SAVE);
        memcpy(GraphBuffer, s_Buff, sizeof(int) * GraphTraceLen);
        RepaintGraphWindow();
 }
 void ProxWidget::stickOperation()
 {
        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)
        //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)
 {
 
 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)) {
        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());
                } 
        }
                        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;
 void Plot::keyPressEvent(QKeyEvent *event)
 {
        int     offset;
-       int     gridchanged;
-
-       gridchanged= 0;
 
        if(event->modifiers() & Qt::ShiftModifier) {
                if (PlotGridX)
 
        if(event->modifiers() & Qt::ShiftModifier) {
                if (PlotGridX)
@@ -611,53 +619,18 @@ void Plot::keyPressEvent(QKeyEvent *event)
 
                case Qt::Key_Right:
                        if(GraphPixelsPerPoint < 20) {
 
                case Qt::Key_Right:
                        if(GraphPixelsPerPoint < 20) {
-                               if (PlotGridX && GridLocked && GraphStart < startMax){
-                                       GridOffset -= offset;
-                                       GridOffset %= PlotGridX;
-                                       gridchanged= 1;
-                               }
                                GraphStart += offset;
                        } else {
                                GraphStart += offset;
                        } else {
-                               if (PlotGridX && GridLocked && GraphStart < startMax){
-                                       GridOffset--;
-                                       GridOffset %= PlotGridX;
-                                       gridchanged= 1;
-                               }
                                GraphStart++;
                        }
                                GraphStart++;
                        }
-                       if(GridOffset < 0) {
-                               GridOffset += PlotGridX;
-                       }
-                       if (gridchanged)
-                               if (GraphStart > startMax) {
-                                       GridOffset += (GraphStart - startMax);
-                                       GridOffset %= PlotGridX;
-                               }
                        break;
 
                case Qt::Key_Left:
                        if(GraphPixelsPerPoint < 20) {
                        break;
 
                case Qt::Key_Left:
                        if(GraphPixelsPerPoint < 20) {
-                               if (PlotGridX && GridLocked && GraphStart > 0){
-                                       GridOffset += offset;
-                                       GridOffset %= PlotGridX;
-                                       gridchanged= 1;
-                               }
                                GraphStart -= offset;
                        } else {
                                GraphStart -= offset;
                        } else {
-                               if (PlotGridX && GridLocked && GraphStart > 0){
-                                       GridOffset++;
-                                       GridOffset %= PlotGridX;
-                                       gridchanged= 1;
-                               }
                                GraphStart--;
                        }
                                GraphStart--;
                        }
-                       if (gridchanged){
-                               if (GraphStart < 0)
-                                       GridOffset += GraphStart;
-                               if(GridOffset < 0)
-                                       GridOffset += PlotGridX;
-                       GridOffset %= PlotGridX;
-                       }
                        break;
 
                case Qt::Key_G:
                        break;
 
                case Qt::Key_G:
@@ -667,7 +640,7 @@ void Plot::keyPressEvent(QKeyEvent *event)
                        } else {
                                PlotGridX= PlotGridXdefault;
                                PlotGridY= PlotGridYdefault;
                        } else {
                                PlotGridX= PlotGridXdefault;
                                PlotGridY= PlotGridYdefault;
-                               }
+                       }
                        break;
 
                case Qt::Key_H:
                        break;
 
                case Qt::Key_H:
@@ -692,7 +665,11 @@ void Plot::keyPressEvent(QKeyEvent *event)
                        break;
 
                case Qt::Key_L:
                        break;
 
                case Qt::Key_L:
-                       GridLocked= !GridLocked;
+                       GridLocked = !GridLocked;
+                       if (GridLocked)
+                               GridOffset += (GraphStart - unlockStart);
+                       else
+                               unlockStart = GraphStart;
                        break;
 
                case Qt::Key_Q:
                        break;
 
                case Qt::Key_Q:
Impressum, Datenschutz