static int savedDemodStartIdx = 0;
static int savedDemodClock = 0;
- if (saveOpt==1) { //save
+ if (saveOpt == GRAPH_SAVE) { //save
memcpy(SavedDB, DemodBuffer, sizeof(DemodBuffer));
SavedDBlen = DemodBufferLen;
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 (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;
}
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);
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);
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
}
//restore GraphBuffer
- save_restoreGB(0);
+ save_restoreGB(GRAPH_RESTORE);
return (int)AllPTest;
}
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
- 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
- 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
- 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
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
}\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
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;
// 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 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;
int g_absVMax = 0;
int startMax;
int PageWidth;
-
+int unlockStart = 0;
void ProxGuiQT::ShowGraphWindow(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)
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());
}
}
void Plot::keyPressEvent(QKeyEvent *event)
{
int offset;
- int gridchanged;
-
- gridchanged= 0;
if(event->modifiers() & Qt::ShiftModifier) {
if (PlotGridX)
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:
} else {
PlotGridX= PlotGridXdefault;
PlotGridY= PlotGridYdefault;
- }
+ }
break;
case Qt::Key_H:
break;
case Qt::Key_L:
- GridLocked= !GridLocked;
+ GridLocked = !GridLocked;
+ if (GridLocked)
+ GridOffset += (GraphStart - unlockStart);
+ else
+ unlockStart = GraphStart;
break;
case Qt::Key_Q: