From 0f321d631adb37c7cc6c6567f66eef8e2a795760 Mon Sep 17 00:00:00 2001 From: marshmellow42 Date: Tue, 11 Apr 2017 10:34:43 -0400 Subject: [PATCH 01/17] align clock grid with demods on graph --- CHANGELOG.md | 1 + client/cmddata.c | 44 ++++++++++++++++++++++++++++++++++++-------- client/cmddata.h | 4 +--- client/cmdlf.c | 4 ++-- client/cmdlft55xx.c | 8 ++++---- client/graph.c | 19 +++++++++++++------ client/graph.h | 3 ++- client/proxgui.h | 3 ++- client/proxguiqt.cpp | 2 -- client/ui.c | 4 ++++ client/ui.h | 5 ++++- common/lfdemod.c | 19 ++----------------- common/lfdemod.h | 6 ++---- 13 files changed, 73 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1552e171..37470077 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac - Added option c to 'hf list' (mark CRC bytes) (piwi) ### Changed +- Adjusted the lf demods to auto align and set the grid for the graph plot. - `lf snoop` now automatically gets samples from the device - `lf read` now accepts [#samples] as arg. && now automatically gets samples from the device - adjusted lf t5 chip timings to use WaitUS. and adjusted the readblock timings diff --git a/client/cmddata.c b/client/cmddata.c index 823da9ce..664ef850 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -28,8 +28,6 @@ uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN]; uint8_t g_debugMode=0; size_t DemodBufferLen=0; -//size_t g_demodStartIdx=0; -//uint8_t g_demodClock=0; static int CmdHelp(const char *Cmd); @@ -223,7 +221,7 @@ int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType, } bool st = false; size_t ststart = 0, stend = 0; - if (*stCheck) st = DetectST_ext(BitStream, &BitLen, &foundclk, &ststart, &stend); + if (*stCheck) st = DetectST(BitStream, &BitLen, &foundclk, &ststart, &stend); *stCheck = st; if (st) { clk = (clk == 0) ? foundclk : clk; @@ -236,7 +234,8 @@ int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType, //} //RepaintGraphWindow(); } - int errCnt = askdemod(BitStream, &BitLen, &clk, &invert, maxErr, askamp, askType); + int startIdx = 0; + int errCnt = askdemod_ext(BitStream, &BitLen, &clk, &invert, maxErr, askamp, askType, &startIdx); if (errCnt<0 || BitLen<16){ //if fatal error (or -1) if (g_debugMode) PrintAndLog("DEBUG: no data found %d, errors:%d, bitlen:%d, clock:%d",errCnt,invert,BitLen,clk); return 0; @@ -249,6 +248,8 @@ int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType, //output setDemodBuf(BitStream,BitLen,0); + setClockGrid(clk, startIdx); + if (verbose || g_debugMode){ if (errCnt>0) PrintAndLog("# Errors during Demoding (shown as 7 in bit stream): %d",errCnt); if (askType) PrintAndLog("ASK/Manchester - Clock: %d - Decoded bitstream:",clk); @@ -787,12 +788,15 @@ int FSKrawDemod(const char *Cmd, bool verbose) } //get bit clock length if (!rfLen) { - rfLen = detectFSKClk(BitStream, BitLen, fchigh, fclow); + int firstClockEdge = 0; //todo - align grid on graph with this... + rfLen = detectFSKClk(BitStream, BitLen, fchigh, fclow, &firstClockEdge); if (!rfLen) rfLen = 50; } - int size = fskdemod(BitStream, BitLen, rfLen, invert, fchigh, fclow); + int startIdx = 0; + int size = fskdemod_ext(BitStream, BitLen, rfLen, invert, fchigh, fclow, &startIdx); if (size > 0) { setDemodBuf(BitStream,size,0); + setClockGrid(rfLen, startIdx); // Now output the bitstream to the scrollback by line of 16 bits if (verbose || g_debugMode) { @@ -854,7 +858,8 @@ int PSKDemod(const char *Cmd, bool verbose) size_t BitLen = getFromGraphBuf(BitStream); if (BitLen==0) return 0; int errCnt=0; - errCnt = pskRawDemod(BitStream, &BitLen, &clk, &invert); + int startIdx = 0; + errCnt = pskRawDemod_ext(BitStream, &BitLen, &clk, &invert, &startIdx); if (errCnt > maxErr){ if (g_debugMode || verbose) PrintAndLog("Too many errors found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt); return 0; @@ -871,6 +876,8 @@ int PSKDemod(const char *Cmd, bool verbose) } //prime demod buffer for output setDemodBuf(BitStream,BitLen,0); + setClockGrid(clk, startIdx); + return 1; } @@ -909,6 +916,8 @@ int NRZrawDemod(const char *Cmd, bool verbose) if (verbose || g_debugMode) PrintAndLog("Tried NRZ Demod using Clock: %d - invert: %d - Bits Found: %d",clk,invert,BitLen); //prime demod buffer for output setDemodBuf(BitStream,BitLen,0); + setClockGrid(clk, clkStartIdx); + if (errCnt>0 && (verbose || g_debugMode)) PrintAndLog("# Errors during Demoding (shown as 7 in bit stream): %d",errCnt); if (verbose || g_debugMode) { @@ -1047,6 +1056,26 @@ int CmdRawDemod(const char *Cmd) return ans; } +void setClockGrid(int clk, int offset) { + if (offset > clk) offset %= clk; + if (offset < 0) offset += clk; + + if (offset > GraphTraceLen || offset < 0) return; + if (clk < 8 || clk > GraphTraceLen) { + GridLocked = false; + GridOffset = 0; + PlotGridX = 0; + PlotGridXdefault = 0; + RepaintGraphWindow(); + } else { + GridLocked = true; + GridOffset = offset; + PlotGridX = clk; + PlotGridXdefault = clk; + RepaintGraphWindow(); + } +} + int CmdGrid(const char *Cmd) { sscanf(Cmd, "%i %i", &PlotGridX, &PlotGridY); @@ -1561,7 +1590,6 @@ static command_t CommandTable[] = {"buffclear", CmdBuffClear, 1, "Clear sample buffer and graph window"}, {"dec", CmdDec, 1, "Decimate samples"}, {"detectclock", CmdDetectClockRate, 1, "[modulation] Detect clock rate of wave in GraphBuffer (options: 'a','f','n','p' for ask, fsk, nrz, psk respectively)"}, - //{"fskfcdetect", CmdFSKfcDetect, 1, "Try to detect the Field Clock of an FSK wave"}, {"getbitstream", CmdGetBitStream, 1, "Convert GraphBuffer's >=1 values to 1 and <1 to 0"}, {"grid", CmdGrid, 1, " -- overlay grid on graph window, use zero value to turn off either"}, {"hexsamples", CmdHexsamples, 0, " [] -- Dump big buffer as hex bytes"}, diff --git a/client/cmddata.h b/client/cmddata.h index f9c45ae2..09467bd8 100644 --- a/client/cmddata.h +++ b/client/cmddata.h @@ -64,14 +64,12 @@ int FSKrawDemod(const char *Cmd, bool verbose); int PSKDemod(const char *Cmd, bool verbose); int NRZrawDemod(const char *Cmd, bool verbose); int getSamples(int n, bool silent); - +void setClockGrid(int clk, int offset); #define MAX_DEMOD_BUF_LEN (1024*128) extern uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN]; extern size_t DemodBufferLen; extern uint8_t g_debugMode; -//extern size_t g_demodStartIdx; -//extern uint8_t g_demodClock; #define BIGBUF_SIZE 40000 #endif diff --git a/client/cmdlf.c b/client/cmdlf.c index 7670136f..5825b339 100644 --- a/client/cmdlf.c +++ b/client/cmdlf.c @@ -548,10 +548,10 @@ int CmdLFfskSim(const char *Cmd) { return usage_lf_simfsk(); } - + int firstClockEdge = 0; if (dataLen == 0){ //using DemodBuffer if (clk==0 || fcHigh==0 || fcLow==0){ //manual settings must set them all - uint8_t ans = fskClocks(&fcHigh, &fcLow, &clk, 0); + uint8_t ans = fskClocks(&fcHigh, &fcLow, &clk, 0, &firstClockEdge); if (ans==0){ if (!fcHigh) fcHigh=10; if (!fcLow) fcLow=8; diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index 8ab1892d..ed8e3152 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -507,8 +507,8 @@ bool tryDetectModulation(){ t55xx_conf_block_t tests[15]; int bitRate=0; uint8_t fc1 = 0, fc2 = 0, ans = 0; - int clk=0; - ans = fskClocks(&fc1, &fc2, (uint8_t *)&clk, false); + int clk = 0, firstClockEdge = 0; + ans = fskClocks(&fc1, &fc2, (uint8_t *)&clk, false, &firstClockEdge); if (ans && ((fc1==10 && fc2==8) || (fc1==8 && fc2==5))) { if ( FSKrawDemod("0 0", false) && test(DEMOD_FSK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) { tests[hits].modulation = DEMOD_FSK; @@ -1555,7 +1555,7 @@ bool tryDetectP1(bool getData) { uint8_t preamble[] = {1,1,1,0,0,0,0,0,0,0,0,1,0,1,0,1}; size_t startIdx = 0; uint8_t fc1 = 0, fc2 = 0, ans = 0; - int clk = 0; + int clk = 0, firstClockEdge = 0; bool st = true; if ( getData ) { @@ -1564,7 +1564,7 @@ bool tryDetectP1(bool getData) { } // try fsk clock detect. if successful it cannot be any other type of modulation... (in theory...) - ans = fskClocks(&fc1, &fc2, (uint8_t *)&clk, false); + ans = fskClocks(&fc1, &fc2, (uint8_t *)&clk, false, &firstClockEdge); if (ans && ((fc1==10 && fc2==8) || (fc1==8 && fc2==5))) { if ( FSKrawDemod("0 0", false) && preambleSearchEx(DemodBuffer,preamble,sizeof(preamble),&DemodBufferLen,&startIdx,false) && diff --git a/client/graph.c b/client/graph.c index 12f5ff71..a96425b9 100644 --- a/client/graph.c +++ b/client/graph.c @@ -144,11 +144,14 @@ int GetAskClock(const char str[], bool printAns, bool verbose) PrintAndLog("Failed to copy from graphbuffer"); return -1; } - bool st = DetectST(grph, &size, &clock); - int start = 0; + //, size_t *ststart, size_t *stend + size_t ststart = 0, stend = 0; + bool st = DetectST(grph, &size, &clock, &ststart, &stend); + int start = stend; if (st == false) { start = DetectASKClock(grph, size, &clock, 20); } + setClockGrid(clock, start); // Only print this message if we're not looping something if (printAns || g_debugMode) { PrintAndLog("Auto-detected clock rate: %d, Best Starting Position: %d", clock, start); @@ -197,6 +200,7 @@ int GetPskClock(const char str[], bool printAns, bool verbose) size_t firstPhaseShiftLoc = 0; uint8_t curPhase = 0, fc = 0; clock = DetectPSKClock(grph, size, 0, &firstPhaseShiftLoc, &curPhase, &fc); + setClockGrid(clock, firstPhaseShiftLoc); // Only print this message if we're not looping something if (printAns){ PrintAndLog("Auto-detected clock rate: %d", clock); @@ -223,6 +227,7 @@ uint8_t GetNrzClock(const char str[], bool printAns, bool verbose) } size_t clkStartIdx = 0; clock = DetectNRZClock(grph, size, 0, &clkStartIdx); + setClockGrid(clock, clkStartIdx); // Only print this message if we're not looping something if (printAns){ PrintAndLog("Auto-detected clock rate: %d", clock); @@ -241,10 +246,12 @@ uint8_t GetFskClock(const char str[], bool printAns, bool verbose) uint8_t fc1=0, fc2=0, rf1=0; - uint8_t ans = fskClocks(&fc1, &fc2, &rf1, verbose); + int firstClockEdge = 0; + uint8_t ans = fskClocks(&fc1, &fc2, &rf1, verbose, &firstClockEdge); if (ans == 0) return 0; if ((fc1==10 && fc2==8) || (fc1==8 && fc2==5)){ if (printAns) PrintAndLog("Detected Field Clocks: FC/%d, FC/%d - Bit Clock: RF/%d", fc1, fc2, rf1); + setClockGrid(rf1, firstClockEdge); return rf1; } if (verbose){ @@ -253,7 +260,7 @@ uint8_t GetFskClock(const char str[], bool printAns, bool verbose) } return 0; } -uint8_t fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, bool verbose) +uint8_t fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, bool verbose, int *firstClockEdge) { uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0}; size_t size = getFromGraphBuf(BitStream); @@ -265,8 +272,8 @@ uint8_t fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, bool verbose) } *fc1 = (ans >> 8) & 0xFF; *fc2 = ans & 0xFF; - - *rf1 = detectFSKClk(BitStream, size, *fc1, *fc2); + //int firstClockEdge = 0; + *rf1 = detectFSKClk(BitStream, size, *fc1, *fc2, firstClockEdge); if (*rf1==0) { if (verbose || g_debugMode) PrintAndLog("DEBUG: Clock detect error"); return 0; diff --git a/client/graph.h b/client/graph.h index 6f3f600d..8747bf28 100644 --- a/client/graph.h +++ b/client/graph.h @@ -21,7 +21,8 @@ int GetPskClock(const char str[], bool printAns, bool verbose); uint8_t GetPskCarrier(const char str[], bool printAns, bool verbose); uint8_t GetNrzClock(const char str[], bool printAns, bool verbose); uint8_t GetFskClock(const char str[], bool printAns, bool verbose); -uint8_t fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, bool verbose); +uint8_t fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, bool verbose, int *firstClockEdge); +//uint8_t fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, bool verbose); bool graphJustNoise(int *BitStream, int size); void setGraphBuf(uint8_t *buff, size_t size); void save_restoreGB(uint8_t saveOpt); diff --git a/client/proxgui.h b/client/proxgui.h index ef9ac36a..ee0aa565 100644 --- a/client/proxgui.h +++ b/client/proxgui.h @@ -23,9 +23,10 @@ void ExitGraphics(void); extern int GraphBuffer[MAX_GRAPH_TRACE_LEN]; extern int GraphTraceLen; extern double CursorScaleFactor; -extern int PlotGridX, PlotGridY, PlotGridXdefault, PlotGridYdefault, CursorCPos, CursorDPos; +extern int PlotGridX, PlotGridY, PlotGridXdefault, PlotGridYdefault, CursorCPos, CursorDPos, GridOffset; extern int CommandFinished; extern int offline; +extern bool GridLocked; #ifdef __cplusplus } diff --git a/client/proxguiqt.cpp b/client/proxguiqt.cpp index cd8297ef..82f0e60f 100644 --- a/client/proxguiqt.cpp +++ b/client/proxguiqt.cpp @@ -22,8 +22,6 @@ #include "proxguiqt.h" #include "proxgui.h" -int GridOffset= 0; -bool GridLocked= 0; int startMax; int PageWidth; diff --git a/client/ui.c b/client/ui.c index 5902cb89..b438521e 100644 --- a/client/ui.c +++ b/client/ui.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -21,6 +22,9 @@ double CursorScaleFactor; int PlotGridX, PlotGridY, PlotGridXdefault= 64, PlotGridYdefault= 64, CursorCPos= 0, CursorDPos= 0; int offline; int flushAfterWrite = 0; //buzzy +int GridOffset = 0; +bool GridLocked = 0; + extern pthread_mutex_t print_lock; static char *logfilename = "proxmark3.log"; diff --git a/client/ui.h b/client/ui.h index 4e03bfab..929d3921 100644 --- a/client/ui.h +++ b/client/ui.h @@ -11,6 +11,8 @@ #ifndef UI_H__ #define UI_H__ +#include + void ShowGui(void); void HideGraphWindow(void); void ShowGraphWindow(void); @@ -19,8 +21,9 @@ void PrintAndLog(char *fmt, ...); void SetLogFilename(char *fn); extern double CursorScaleFactor; -extern int PlotGridX, PlotGridY, PlotGridXdefault, PlotGridYdefault, CursorCPos, CursorDPos; +extern int PlotGridX, PlotGridY, PlotGridXdefault, PlotGridYdefault, CursorCPos, CursorDPos, GridOffset; extern int offline; extern int flushAfterWrite; //buzzy +extern bool GridLocked; #endif diff --git a/common/lfdemod.c b/common/lfdemod.c index f81ac236..d6ef88a4 100644 --- a/common/lfdemod.c +++ b/common/lfdemod.c @@ -833,15 +833,9 @@ int DetectPSKClock(uint8_t dest[], size_t size, int clock, size_t *firstPhaseShi return clk[best]; } -//int DetectPSKClock(uint8_t dest[], size_t size, int clock) { -// size_t firstPhaseShift = 0; -// uint8_t curPhase = 0; -// return DetectPSKClock_ext(dest, size, clock, &firstPhaseShift, &curPhase); -//} - //by marshmellow //detects the bit clock for FSK given the high and low Field Clocks -uint8_t detectFSKClk_ext(uint8_t *BitStream, size_t size, uint8_t fcHigh, uint8_t fcLow, int *firstClockEdge) { +uint8_t detectFSKClk(uint8_t *BitStream, size_t size, uint8_t fcHigh, uint8_t fcLow, int *firstClockEdge) { uint8_t clk[] = {8,16,32,40,50,64,100,128,0}; uint16_t rfLens[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; uint8_t rfCnts[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; @@ -947,11 +941,6 @@ uint8_t detectFSKClk_ext(uint8_t *BitStream, size_t size, uint8_t fcHigh, uint8_ return clk[ii]; } -uint8_t detectFSKClk(uint8_t *BitStream, size_t size, uint8_t fcHigh, uint8_t fcLow) { - int firstClockEdge = 0; - return detectFSKClk_ext(BitStream, size, fcHigh, fcLow, &firstClockEdge); -} - //********************************************************************************************** //--------------------Modulation Demods &/or Decoding Section----------------------------------- //********************************************************************************************** @@ -977,7 +966,7 @@ bool findST(int *stStopLoc, int *stStartIdx, int lowToLowWaveLen[], int highToLo } //by marshmellow //attempt to identify a Sequence Terminator in ASK modulated raw wave -bool DetectST_ext(uint8_t buffer[], size_t *size, int *foundclock, size_t *ststart, size_t *stend) { +bool DetectST(uint8_t buffer[], size_t *size, int *foundclock, size_t *ststart, size_t *stend) { size_t bufsize = *size; //need to loop through all samples and identify our clock, look for the ST pattern int clk = 0; @@ -1098,10 +1087,6 @@ bool DetectST_ext(uint8_t buffer[], size_t *size, int *foundclock, size_t *ststa *size = newloc; return true; } -bool DetectST(uint8_t buffer[], size_t *size, int *foundclock) { - size_t ststart = 0, stend = 0; - return DetectST_ext(buffer, size, foundclock, &ststart, &stend); -} //by marshmellow //take 11 10 01 11 00 and make 01100 ... miller decoding diff --git a/common/lfdemod.h b/common/lfdemod.h index 697b78cb..9f37a969 100644 --- a/common/lfdemod.h +++ b/common/lfdemod.h @@ -27,13 +27,11 @@ extern uint32_t bytebits_to_byteLSBF(uint8_t* src, size_t numbits); extern uint16_t countFC(uint8_t *BitStream, size_t size, uint8_t fskAdj); extern int DetectASKClock(uint8_t dest[], size_t size, int *clock, int maxErr); extern uint8_t DetectCleanAskWave(uint8_t dest[], size_t size, uint8_t high, uint8_t low); -extern uint8_t detectFSKClk(uint8_t *BitStream, size_t size, uint8_t fcHigh, uint8_t fcLow); -extern uint8_t detectFSKClk_ext(uint8_t *BitStream, size_t size, uint8_t fcHigh, uint8_t fcLow, int *firstClockEdge); +extern uint8_t detectFSKClk(uint8_t *BitStream, size_t size, uint8_t fcHigh, uint8_t fcLow, int *firstClockEdge); extern int DetectNRZClock(uint8_t dest[], size_t size, int clock, size_t *clockStartIdx); extern int DetectPSKClock(uint8_t dest[], size_t size, int clock, size_t *firstPhaseShift, uint8_t *curPhase, uint8_t *fc); extern int DetectStrongAskClock(uint8_t dest[], size_t size, int high, int low, int *clock); -extern bool DetectST(uint8_t buffer[], size_t *size, int *foundclock); -extern bool DetectST_ext(uint8_t buffer[], size_t *size, int *foundclock, size_t *ststart, size_t *stend); +extern bool DetectST(uint8_t buffer[], size_t *size, int *foundclock, size_t *ststart, size_t *stend); extern int fskdemod(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow); extern int fskdemod_ext(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *startIdx); extern int getHiLo(uint8_t *BitStream, size_t size, int *high, int *low, uint8_t fuzzHi, uint8_t fuzzLo); From 3fe7103959574d63f9310c46548786b219a32771 Mon Sep 17 00:00:00 2001 From: marshmellow42 Date: Tue, 11 Apr 2017 21:51:31 -0400 Subject: [PATCH 02/17] proper initialized values --- client/ui.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/ui.c b/client/ui.c index b438521e..219ada63 100644 --- a/client/ui.c +++ b/client/ui.c @@ -18,12 +18,12 @@ #include "ui.h" -double CursorScaleFactor; +double CursorScaleFactor = 1; int PlotGridX, PlotGridY, PlotGridXdefault= 64, PlotGridYdefault= 64, CursorCPos= 0, CursorDPos= 0; int offline; int flushAfterWrite = 0; //buzzy int GridOffset = 0; -bool GridLocked = 0; +bool GridLocked = false; extern pthread_mutex_t print_lock; From b8fdac9e6fedfda5e291e437766ed46e3caf7c32 Mon Sep 17 00:00:00 2001 From: marshmellow42 Date: Wed, 12 Apr 2017 14:35:07 -0400 Subject: [PATCH 03/17] apply @holiman s graph changes + add demod data to graph. some bugs are known: if you close the graph window data plot will not bring it back. exiting the application without closing the widget form results in error. autocorrect graph y labels are ugly form has old askdemod tab. sticky button purpose not defined/labeled well. doesn't clear s_Buff when new graph loaded or sampled. probably more... --- client/cmddata.c | 16 +- client/cmddata.h | 2 + client/cmdlfem4x.c | 3 +- client/graph.c | 57 +++++ client/graph.h | 5 + client/proxgui.h | 16 ++ client/proxguiqt.cpp | 517 +++++++++++++++++++++++++++------------- client/proxguiqt.h | 64 ++++- client/ui.c | 3 +- client/ui.h | 1 + client/ui/overlays.ui | 272 +++++++++++++++++++++ client/ui/ui_overlays.h | 224 +++++++++++++++++ 12 files changed, 995 insertions(+), 185 deletions(-) create mode 100644 client/ui/overlays.ui create mode 100644 client/ui/ui_overlays.h diff --git a/client/cmddata.c b/client/cmddata.c index 664ef850..7a411324 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -28,6 +28,8 @@ uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN]; uint8_t g_debugMode=0; size_t DemodBufferLen=0; +int g_DemodStartIdx=0; +int g_DemodClock=0; static int CmdHelp(const char *Cmd); @@ -245,7 +247,6 @@ int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType, return 0; } if (verbose || g_debugMode) PrintAndLog("\nUsing Clock:%d, Invert:%d, Bits Found:%d",clk,invert,BitLen); - //output setDemodBuf(BitStream,BitLen,0); setClockGrid(clk, startIdx); @@ -295,11 +296,11 @@ int Cmdaskmandemod(const char *Cmd) } bool st = true; if (Cmd[0]=='s') - return ASKDemod_ext(Cmd++, true, true, 1, &st); + return ASKDemod_ext(Cmd++, true, false, 1, &st); else if (Cmd[1] == 's') - return ASKDemod_ext(Cmd+=2, true, true, 1, &st); + return ASKDemod_ext(Cmd+=2, true, false, 1, &st); else - return ASKDemod(Cmd, true, true, 1); + return ASKDemod(Cmd, true, false, 1); } //by marshmellow @@ -797,7 +798,7 @@ int FSKrawDemod(const char *Cmd, bool verbose) if (size > 0) { setDemodBuf(BitStream,size,0); setClockGrid(rfLen, startIdx); - + // Now output the bitstream to the scrollback by line of 16 bits if (verbose || g_debugMode) { PrintAndLog("\nUsing Clock:%u, invert:%u, fchigh:%u, fclow:%u", (unsigned int)rfLen, (unsigned int)invert, (unsigned int)fchigh, (unsigned int)fclow); @@ -1057,6 +1058,9 @@ int CmdRawDemod(const char *Cmd) } void setClockGrid(int clk, int offset) { + g_DemodStartIdx = offset; + g_DemodClock = clk; + PrintAndLog("demodoffset %d, clk %d",offset,clk); if (offset > clk) offset %= clk; if (offset < 0) offset += clk; @@ -1213,6 +1217,7 @@ int getSamples(int n, bool silent) GraphTraceLen = n; } + setClockGrid(0,0); RepaintGraphWindow(); return 0; } @@ -1316,6 +1321,7 @@ int CmdLoad(const char *Cmd) } fclose(f); PrintAndLog("loaded %d samples", GraphTraceLen); + setClockGrid(0,0); RepaintGraphWindow(); return 0; } diff --git a/client/cmddata.h b/client/cmddata.h index 09467bd8..4a3287a7 100644 --- a/client/cmddata.h +++ b/client/cmddata.h @@ -69,6 +69,8 @@ void setClockGrid(int clk, int offset); #define MAX_DEMOD_BUF_LEN (1024*128) extern uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN]; extern size_t DemodBufferLen; +extern int g_DemodStartIdx; +extern int g_DemodClock; extern uint8_t g_debugMode; #define BIGBUF_SIZE 40000 diff --git a/client/cmdlfem4x.c b/client/cmdlfem4x.c index 6b1fa883..83a7da4e 100644 --- a/client/cmdlfem4x.c +++ b/client/cmdlfem4x.c @@ -152,7 +152,8 @@ int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo ) if (Em410xDecode(BitStream, &BitLen, &idx, hi, lo)) { //set GraphBuffer for clone or sim command - setDemodBuf(BitStream, BitLen, idx); + setDemodBuf(DemodBuffer, (BitLen==40) ? 64 : 128, idx+1); + g_DemodStartIdx += (idx+1)*g_DemodClock; if (g_debugMode) { PrintAndLog("DEBUG: idx: %d, Len: %d, Printing Demod Buffer:", idx, BitLen); printDemodBuff(); diff --git a/client/graph.c b/client/graph.c index a96425b9..547e9b30 100644 --- a/client/graph.c +++ b/client/graph.c @@ -18,6 +18,9 @@ int GraphBuffer[MAX_GRAPH_TRACE_LEN]; int GraphTraceLen; + +int s_Buff[MAX_GRAPH_TRACE_LEN]; + /* write a manchester bit to the graph */ void AppendGraph(int redraw, int clock, int bit) { @@ -290,3 +293,57 @@ bool graphJustNoise(int *BitStream, int size) } return justNoise1; } +int autoCorr(const int* in, int *out, size_t len, int window) +{ + static int CorrelBuffer[MAX_GRAPH_TRACE_LEN]; + + if (window == 0) { + PrintAndLog("needs a window"); + return 0; + } + if (window >= len) { + PrintAndLog("window must be smaller than trace (%d samples)", + len); + return 0; + } + + PrintAndLog("performing %d correlations", len - window); + + for (int i = 0; i < len - window; ++i) { + int sum = 0; + for (int j = 0; j < window; ++j) { + sum += (in[j]*in[i + j]) / 256; + } + CorrelBuffer[i] = sum; + } + //GraphTraceLen = GraphTraceLen - window; + memcpy(out, CorrelBuffer, len * sizeof (int)); + return 0; +} +int directionalThreshold(const int* in, int *out, size_t len, int8_t up, int8_t down) +{ + int lastValue = in[0]; + out[0] = 0; // Will be changed at the end, but init 0 as we adjust to last samples value if no threshold kicks in. + + for (int i = 1; i < len; ++i) { + // Apply first threshold to samples heading up + if (in[i] >= up && in[i] > lastValue) + { + lastValue = out[i]; // Buffer last value as we overwrite it. + out[i] = 1; + } + // Apply second threshold to samples heading down + else if (in[i] <= down && in[i] < lastValue) + { + lastValue = out[i]; // Buffer last value as we overwrite it. + out[i] = -1; + } + else + { + lastValue = out[i]; // Buffer last value as we overwrite it. + out[i] = out[i-1]; + } + } + out[0] = out[1]; // Align with first edited sample. + return 0; +} diff --git a/client/graph.h b/client/graph.h index 8747bf28..e70efe46 100644 --- a/client/graph.h +++ b/client/graph.h @@ -35,4 +35,9 @@ void DetectHighLowInGraph(int *high, int *low, bool addFuzz); extern int GraphBuffer[MAX_GRAPH_TRACE_LEN]; extern int GraphTraceLen; +extern int s_Buff[MAX_GRAPH_TRACE_LEN]; + +int autoCorr(const int* in, int *out, size_t len, int window); +int directionalThreshold(const int* in, int *out, size_t len, int8_t up, int8_t down); + #endif diff --git a/client/proxgui.h b/client/proxgui.h index ee0aa565..a6d8f24a 100644 --- a/client/proxgui.h +++ b/client/proxgui.h @@ -12,6 +12,9 @@ extern "C" { #endif +#include +#include + void ShowGraphWindow(void); void HideGraphWindow(void); void RepaintGraphWindow(void); @@ -22,12 +25,25 @@ void ExitGraphics(void); #define MAX_GRAPH_TRACE_LEN (40000*8) extern int GraphBuffer[MAX_GRAPH_TRACE_LEN]; extern int GraphTraceLen; +extern int s_Buff[MAX_GRAPH_TRACE_LEN]; + extern double CursorScaleFactor; extern int PlotGridX, PlotGridY, PlotGridXdefault, PlotGridYdefault, CursorCPos, CursorDPos, GridOffset; extern int CommandFinished; extern int offline; extern bool GridLocked; +//Operations defined in data_operations +extern int autoCorr(const int* in, int *out, size_t len, int window); +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 MAX_DEMOD_BUF_LEN (1024*128) +extern uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN]; +extern size_t DemodBufferLen; +extern size_t g_DemodStartIdx; +extern bool showDemod; + #ifdef __cplusplus } #endif diff --git a/client/proxguiqt.cpp b/client/proxguiqt.cpp index 82f0e60f..c0aff8b6 100644 --- a/client/proxguiqt.cpp +++ b/client/proxguiqt.cpp @@ -19,8 +19,13 @@ #include #include #include +#include +#include #include "proxguiqt.h" #include "proxgui.h" +#include +//#include + int startMax; int PageWidth; @@ -86,6 +91,7 @@ ProxGuiQT::ProxGuiQT(int argc, char **argv) : plotapp(NULL), plotwidget(NULL), ProxGuiQT::~ProxGuiQT(void) { if (plotwidget) { + //plotwidget->close(); delete plotwidget; plotwidget = NULL; } @@ -97,15 +103,304 @@ ProxGuiQT::~ProxGuiQT(void) } } -void ProxWidget::paintEvent(QPaintEvent *event) +//-------------------- +void ProxWidget::applyOperation() +{ + printf("ApplyOperation()"); + save_restoreGB(1); + memcpy(GraphBuffer,s_Buff, sizeof(int) * GraphTraceLen); + RepaintGraphWindow(); + +} +void ProxWidget::stickOperation() +{ + save_restoreGB(0); + printf("stickOperation()"); +} +void ProxWidget::vchange_autocorr(int v) +{ + autoCorr(GraphBuffer,s_Buff, GraphTraceLen, v); + printf("vchange_autocorr(%d)\n", v); + RepaintGraphWindow(); +} +void ProxWidget::vchange_dthr_up(int v) +{ + int down = opsController->horizontalSlider_dirthr_down->value(); + directionalThreshold(GraphBuffer,s_Buff, GraphTraceLen, v, down); + printf("vchange_dthr_up(%d)", v); + RepaintGraphWindow(); + +} +void ProxWidget::vchange_dthr_down(int v) +{ + printf("vchange_dthr_down(%d)", v); + int up = opsController->horizontalSlider_dirthr_up->value(); + directionalThreshold(GraphBuffer,s_Buff, GraphTraceLen, v, up); + RepaintGraphWindow(); + +} +ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) +{ + this->master = master; + resize(800,500); + + /** Setup the controller widget **/ + + QWidget* controlWidget = new QWidget(); + opsController = new Ui::Form(); + opsController->setupUi(controlWidget); + //Due to quirks in QT Designer, we need to fiddle a bit + opsController->horizontalSlider_dirthr_down->setMinimum(-128); + opsController->horizontalSlider_dirthr_down->setMaximum(0); + opsController->horizontalSlider_dirthr_down->setValue(-20); + + + QObject::connect(opsController->pushButton_apply, SIGNAL(clicked()), this, SLOT(applyOperation())); + QObject::connect(opsController->pushButton_sticky, SIGNAL(clicked()), this, SLOT(stickOperation())); + QObject::connect(opsController->horizontalSlider_window, SIGNAL(valueChanged(int)), this, SLOT(vchange_autocorr(int))); + QObject::connect(opsController->horizontalSlider_dirthr_up, SIGNAL(valueChanged(int)), this, SLOT(vchange_dthr_up(int))); + QObject::connect(opsController->horizontalSlider_dirthr_down, SIGNAL(valueChanged(int)), this, SLOT(vchange_dthr_down(int))); + + controlWidget->show(); + + // Set up the plot widget, which does the actual plotting + + plot = new Plot(this); + /* + QSlider* slider = new QSlider(Qt::Horizontal); + slider->setFocusPolicy(Qt::StrongFocus); + slider->setTickPosition(QSlider::TicksBothSides); + slider->setTickInterval(10); + slider->setSingleStep(1); + */ + QVBoxLayout *layout = new QVBoxLayout; + //layout->addWidget(slider); + layout->addWidget(plot); + setLayout(layout); + //printf("Proxwidget Constructor just set layout\r\n"); +} + + +//----------- Plotting + +int Plot::xCoordOf(int i, QRect r ) +{ + return r.left() + (int)((i - GraphStart)*GraphPixelsPerPoint); +} + +int Plot::yCoordOf(int v, QRect r, int maxVal) +{ + int z = (r.bottom() - r.top())/2; + return -(z * v) / maxVal + z; +} + +int Plot::valueOf_yCoord(int y, QRect r, int maxVal) +{ + int z = (r.bottom() - r.top())/2; + return (y-z) * maxVal / z; +} +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 GRAY = QColor(240,240,240); + +QColor Plot::getColor(int graphNum) +{ + switch (graphNum) { + case 0: return GREEN; //Green + case 1: return RED; //Red + case 2: return BLUE; //Blue + default: return GRAY; //Gray + } +} + +void Plot::PlotDemod(uint8_t *buffer, size_t len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum, int plotOffset) +{ + if (len == 0 || PlotGridX <= 0) return; + //clock_t begin = clock(); + QPainterPath penPath; + + int grid_delta_x = PlotGridX; + int first_delta_x = grid_delta_x; //(plotOffset > 0) ? PlotGridX : (PlotGridX +); + if (GraphStart > plotOffset) first_delta_x -= (GraphStart-plotOffset); + int DemodStart = GraphStart; + if (plotOffset > GraphStart) DemodStart = plotOffset; + + int BitStart = 0; + // round down + if (DemodStart-plotOffset > 0) BitStart = (int)(((DemodStart-plotOffset)+(PlotGridX-1))/PlotGridX)-1; + first_delta_x += BitStart * PlotGridX; + if (BitStart > len) return; + int delta_x = 0; + int v = 0; + //printf("first_delta_x %i, grid_delta_x %i, DemodStart %i, BitStart %i\n",first_delta_x,grid_delta_x,DemodStart, BitStart); + + painter->setPen(getColor(graphNum)); + char str[5]; + int absVMax = (int)(100*1.05+1); + int x = xCoordOf(DemodStart, plotRect); + int y = yCoordOf((buffer[BitStart]*200-100)*-1,plotRect,absVMax); + penPath.moveTo(x, y); + delta_x = 0; + int clk = first_delta_x; + for(int i = BitStart; i < len && xCoordOf(delta_x+DemodStart, plotRect) < plotRect.right(); i++) { + for (int ii = 0; ii < (clk) && i < len && xCoordOf(DemodStart+delta_x+ii, plotRect) < plotRect.right() ; ii++ ) { + x = xCoordOf(DemodStart+delta_x+ii, plotRect); + v = buffer[i]*200-100; + + y = yCoordOf( v, plotRect, absVMax); + + penPath.lineTo(x, y); + + if(GraphPixelsPerPoint > 10) { + QRect f(QPoint(x - 3, y - 3),QPoint(x + 3, y + 3)); + painter->fillRect(f, QColor(100, 255, 100)); + } + if (ii == (int)clk/2) { + //print label + sprintf(str, "%u",buffer[i]); + painter->drawText(x-8, y + ((buffer[i] > 0) ? 18 : -6), str); + } + } + delta_x += clk; + clk = grid_delta_x; + } + + //Graph annotations + painter->drawPath(penPath); +} + +void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum) +{ + if (len == 0) return; + //clock_t begin = clock(); + QPainterPath penPath; + + startMax = (len - (int)((plotRect.right() - plotRect.left() - 40) / GraphPixelsPerPoint)); + if(startMax < 0) { + startMax = 0; + } + if(GraphStart > startMax) { + GraphStart = startMax; + } + if (GraphStart > len) return; + int vMin = INT_MAX, vMax = INT_MIN, vMean = 0, v = 0, absVMax = 0; + int sample_index = GraphStart ; + for( ; sample_index < len && xCoordOf(sample_index,plotRect) < plotRect.right() ; sample_index++) { + + v = buffer[sample_index]; + if(v < vMin) vMin = v; + if(v > vMax) vMax = v; + vMean += v; + } + + vMean /= (sample_index - GraphStart); + + if(fabs( (double) vMin) > absVMax) absVMax = (int)fabs( (double) vMin); + if(fabs( (double) vMax) > absVMax) absVMax = (int)fabs( (double) vMax); + absVMax = (int)(absVMax*1.25 + 1); + // number of points that will be plotted + int span = (int)((plotRect.right() - plotRect.left()) / GraphPixelsPerPoint); + // one label every 100 pixels, let us say + int labels = (plotRect.right() - plotRect.left() - 40) / 100; + if(labels <= 0) labels = 1; + int pointsPerLabel = span / labels; + if(pointsPerLabel <= 0) pointsPerLabel = 1; + + int x = xCoordOf(GraphStart, plotRect); + int y = yCoordOf(buffer[GraphStart],plotRect,absVMax); + penPath.moveTo(x, y); + for(int i = GraphStart; i < len && xCoordOf(i, plotRect) < plotRect.right(); i++) { + + x = xCoordOf(i, plotRect); + v = buffer[i]; + + y = yCoordOf( v, plotRect, absVMax);//(y * (r.top() - r.bottom()) / (2*absYMax)) + zeroHeight; + + penPath.lineTo(x, y); + + if(GraphPixelsPerPoint > 10) { + QRect f(QPoint(x - 3, y - 3),QPoint(x + 3, y + 3)); + painter->fillRect(f, QColor(100, 255, 100)); + } + } + + painter->setPen(getColor(graphNum)); + + //Draw y-axis + int xo = 5+(graphNum*40); + painter->drawLine(xo, plotRect.top(),xo, plotRect.bottom()); + + int vMarkers = (absVMax - (absVMax % 10)) / 5; + int minYDist = 40; //Minimum pixel-distance between markers + + char yLbl[20]; + + int n = 0; + int lasty0 = 65535; + + for(int v = vMarkers; yCoordOf(v,plotRect,absVMax) > plotRect.top() && n < 20; v+= vMarkers ,n++) + { + int y0 = yCoordOf(v,plotRect,absVMax); + int y1 = yCoordOf(-v,plotRect,absVMax); + + if(lasty0 - y0 < minYDist) continue; + + painter->drawLine(xo-5,y0, xo+5, y0); + + sprintf(yLbl, "%d", v); + painter->drawText(xo+8,y0+7,yLbl); + + painter->drawLine(xo-5, y1, xo+5, y1); + sprintf(yLbl, "%d",-v); + painter->drawText(xo+8, y1+5 , yLbl); + lasty0 = y0; + } + + //Graph annotations + painter->drawPath(penPath); + char str[200]; + sprintf(str, "max=%d min=%d mean=%d n=%d/%d CursorAVal=[%d] CursorBVal=[%d]", + vMax, vMin, vMean, sample_index, 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); +} + +void Plot::plotGridLines(QPainter* painter,QRect r) +{ + int zeroHeight = r.top() + (r.bottom() - r.top()) / 2; + + int i; + int grid_delta_x = (int) (PlotGridX * GraphPixelsPerPoint); + int grid_delta_y = (int) (PlotGridY * GraphPixelsPerPoint); + if ((PlotGridX > 0) && ((PlotGridX * GraphPixelsPerPoint) > 1)) { + for(i = (GridOffset * GraphPixelsPerPoint); i < r.right(); i += grid_delta_x) { + painter->drawLine(r.left()+i, r.top(), r.left()+i, r.bottom()); + } + } + if ((PlotGridY > 0) && ((PlotGridY * GraphPixelsPerPoint) > 1)){ + for(i = 0; i < ((r.top() + r.bottom())>>1); i += grid_delta_y) { + painter->drawLine(r.left(),zeroHeight + i,r.right(),zeroHeight + i); + painter->drawLine(r.left(),zeroHeight - i,r.right(),zeroHeight - i); + } + } +} + +#define HEIGHT_INFO 60 +#define WIDTH_AXES 80 + +void Plot::paintEvent(QPaintEvent *event) { QPainter painter(this); - QPainterPath penPath, whitePath, greyPath, lightgreyPath, cursorAPath, cursorBPath, cursorCPath, cursorDPath; - QRect r; + //QPainterPath penPath, whitePath, greyPath, lightgreyPath, cursorAPath, cursorBPath, cursorCPath, cursorDPath; + //QRect r; QBrush brush(QColor(100, 255, 100)); QPen pen(QColor(100, 255, 100)); - painter.setFont(QFont("Arial", 10)); + painter.setFont(QFont("Courier New", 10)); if(GraphStart < 0) { GraphStart = 0; @@ -120,176 +415,64 @@ void ProxWidget::paintEvent(QPaintEvent *event) if(CursorDPos > GraphTraceLen) CursorDPos= 0; - r = rect(); + QRect plotRect(WIDTH_AXES, 0, width()-WIDTH_AXES, height()-HEIGHT_INFO); + QRect infoRect(0, height()-HEIGHT_INFO, width(), HEIGHT_INFO); - painter.fillRect(r, QColor(0, 0, 0)); + //Grey background + painter.fillRect(rect(), QColor(60, 60, 60)); + //Black foreground + painter.fillRect(plotRect, QColor(0, 0, 0)); - whitePath.moveTo(r.left() + 40, r.top()); - whitePath.lineTo(r.left() + 40, r.bottom()); - - int zeroHeight = r.top() + (r.bottom() - r.top()) / 2; - - greyPath.moveTo(r.left(), zeroHeight); - greyPath.lineTo(r.right(), zeroHeight); + // center line + int zeroHeight = plotRect.top() + (plotRect.bottom() - plotRect.top()) / 2; painter.setPen(QColor(100, 100, 100)); - painter.drawPath(greyPath); + painter.drawLine(plotRect.left(), zeroHeight, plotRect.right(), zeroHeight); + // plot X and Y grid lines + plotGridLines(&painter, plotRect); - PageWidth= (int)((r.right() - r.left() - 40) / GraphPixelsPerPoint); - - // plot X and Y grid lines - int i; - if ((PlotGridX > 0) && ((PlotGridX * GraphPixelsPerPoint) > 1)) { - for(i = 40 + (GridOffset * GraphPixelsPerPoint); i < r.right(); i += (int)(PlotGridX * GraphPixelsPerPoint)) { - //SelectObject(hdc, GreyPenLite); - //MoveToEx(hdc, r.left + i, r.top, NULL); - //LineTo(hdc, r.left + i, r.bottom); - lightgreyPath.moveTo(r.left()+i,r.top()); - lightgreyPath.lineTo(r.left()+i,r.bottom()); - painter.drawPath(lightgreyPath); - } - } - if ((PlotGridY > 0) && ((PlotGridY * GraphPixelsPerPoint) > 1)){ - for(i = 0; i < ((r.top() + r.bottom())>>1); i += (int)(PlotGridY * GraphPixelsPerPoint)) { - lightgreyPath.moveTo(r.left() + 40,zeroHeight + i); - lightgreyPath.lineTo(r.right(),zeroHeight + i); - painter.drawPath(lightgreyPath); - lightgreyPath.moveTo(r.left() + 40,zeroHeight - i); - lightgreyPath.lineTo(r.right(),zeroHeight - i); - painter.drawPath(lightgreyPath); - } - } - - startMax = (GraphTraceLen - (int)((r.right() - r.left() - 40) / GraphPixelsPerPoint)); - if(startMax < 0) { - startMax = 0; + //Start painting graph + PlotGraph(GraphBuffer, GraphTraceLen,plotRect,infoRect,&painter,0); + PlotGraph(s_Buff, GraphTraceLen,plotRect,infoRect,&painter,1); + if (showDemod && DemodBufferLen > 8) { + PlotDemod(DemodBuffer, DemodBufferLen,plotRect,infoRect,&painter,2,g_DemodStartIdx); } - if(GraphStart > startMax) { - GraphStart = startMax; + // End graph drawing + + //Draw the cursors + if(CursorAPos > GraphStart && xCoordOf(CursorAPos, plotRect) < plotRect.right()) + { + painter.setPen(QColor(255, 255, 0)); + painter.drawLine(xCoordOf(CursorAPos, plotRect),plotRect.top(),xCoordOf(CursorAPos, plotRect),plotRect.bottom()); + } + if(CursorBPos > GraphStart && xCoordOf(CursorBPos, plotRect) < plotRect.right()) + { + painter.setPen(QColor(255, 0, 255)); + painter.drawLine(xCoordOf(CursorBPos, plotRect),plotRect.top(),xCoordOf(CursorBPos, plotRect),plotRect.bottom()); + } + if(CursorCPos > GraphStart && xCoordOf(CursorCPos, plotRect) < plotRect.right()) + { + painter.setPen(QColor(255, 153, 0)); //orange + painter.drawLine(xCoordOf(CursorCPos, plotRect),plotRect.top(),xCoordOf(CursorCPos, plotRect),plotRect.bottom()); + } + if(CursorDPos > GraphStart && xCoordOf(CursorDPos, plotRect) < plotRect.right()) + { + painter.setPen(QColor(0, 0, 205)); //light blue + painter.drawLine(xCoordOf(CursorDPos, plotRect),plotRect.top(),xCoordOf(CursorDPos, plotRect),plotRect.bottom()); } - int absYMax = 1; - - for(i = GraphStart; ; i++) { - if(i >= GraphTraceLen) { - break; - } - if(fabs((double)GraphBuffer[i]) > absYMax) { - absYMax = (int)fabs((double)GraphBuffer[i]); - } - int x = 40 + (int)((i - GraphStart)*GraphPixelsPerPoint); - if(x > r.right()) { - break; - } - } - - absYMax = (int)(absYMax*1.2 + 1); - - // number of points that will be plotted - int span = (int)((r.right() - r.left()) / GraphPixelsPerPoint); - // one label every 100 pixels, let us say - int labels = (r.right() - r.left() - 40) / 100; - if(labels <= 0) labels = 1; - int pointsPerLabel = span / labels; - if(pointsPerLabel <= 0) pointsPerLabel = 1; - - int yMin = INT_MAX; - int yMax = INT_MIN; - int yMean = 0; - int n = 0; - - for(i = GraphStart; ; i++) { - if(i >= GraphTraceLen) { - break; - } - int x = 40 + (int)((i - GraphStart)*GraphPixelsPerPoint); - if(x > r.right() + GraphPixelsPerPoint) { - break; - } - - int y = GraphBuffer[i]; - if(y < yMin) { - yMin = y; - } - if(y > yMax) { - yMax = y; - } - yMean += y; - n++; - - y = (y * (r.top() - r.bottom()) / (2*absYMax)) + zeroHeight; - if(i == GraphStart) { - penPath.moveTo(x, y); - } else { - penPath.lineTo(x, y); - } - - if(GraphPixelsPerPoint > 10) { - QRect f(QPoint(x - 3, y - 3),QPoint(x + 3, y + 3)); - painter.fillRect(f, brush); - } - - if(((i - GraphStart) % pointsPerLabel == 0) && i != GraphStart) { - whitePath.moveTo(x, zeroHeight - 3); - whitePath.lineTo(x, zeroHeight + 3); - - char str[100]; - sprintf(str, "+%d", (i - GraphStart)); - - painter.setPen(QColor(255, 255, 255)); - QRect size; - QFontMetrics metrics(painter.font()); - size = metrics.boundingRect(str); - painter.drawText(x - (size.right() - size.left()), zeroHeight + 9, str); - - penPath.moveTo(x,y); - } - - if(i == CursorAPos || i == CursorBPos || i == CursorCPos || i == CursorDPos) { - QPainterPath *cursorPath; - - if(i == CursorAPos) { - cursorPath = &cursorAPath; - } else if (i == CursorBPos) { - cursorPath = &cursorBPath; - } else if (i == CursorCPos) { - cursorPath = &cursorCPath; - } else { - cursorPath = &cursorDPath; - } - cursorPath->moveTo(x, r.top()); - cursorPath->lineTo(x, r.bottom()); - penPath.moveTo(x, y); - } - } - - if(n != 0) { - yMean /= n; - } - - painter.setPen(QColor(255, 255, 255)); - painter.drawPath(whitePath); - painter.setPen(pen); - painter.drawPath(penPath); - painter.setPen(QColor(255, 255, 0)); - painter.drawPath(cursorAPath); - painter.setPen(QColor(255, 0, 255)); - painter.drawPath(cursorBPath); - painter.setPen(QColor(255, 153, 0)); //orange - painter.drawPath(cursorCPath); - painter.setPen(QColor(0, 0, 205)); //light blue - painter.drawPath(cursorDPath); - + //Draw annotations char str[200]; - sprintf(str, "@%d max=%d min=%d mean=%d n=%d/%d dt=%d [%.3f] zoom=%.3f CursorA=%d [%d] CursorB=%d [%d] GridX=%d GridY=%d (%s)", - GraphStart, yMax, yMin, yMean, n, GraphTraceLen, - CursorBPos - CursorAPos, (CursorBPos - CursorAPos)/CursorScaleFactor,GraphPixelsPerPoint,CursorAPos,GraphBuffer[CursorAPos],CursorBPos,GraphBuffer[CursorBPos],PlotGridXdefault,PlotGridYdefault,GridLocked?"Locked":"Unlocked"); - + sprintf(str, "@%d dt=%d [%2.2f] zoom=%2.2f CursorAPos=%d CursorBPos=%d GridX=%d GridY=%d (%s) GridXoffset=%d", + GraphStart, CursorBPos - CursorAPos, (CursorBPos - CursorAPos)/CursorScaleFactor, + GraphPixelsPerPoint,CursorAPos,CursorBPos,PlotGridXdefault,PlotGridYdefault,GridLocked?"Locked":"Unlocked",GridOffset); painter.setPen(QColor(255, 255, 255)); - painter.drawText(50, r.bottom() - 20, str); + painter.drawText(20, infoRect.bottom() - 3, str); + } -ProxWidget::ProxWidget(QWidget *parent) : QWidget(parent), GraphStart(0), GraphPixelsPerPoint(1) +Plot::Plot(QWidget *parent) : QWidget(parent), GraphStart(0), GraphPixelsPerPoint(1) { + setFocusPolicy( Qt::StrongFocus); resize(600, 300); QPalette palette(QColor(0,0,0,0)); @@ -300,18 +483,20 @@ ProxWidget::ProxWidget(QWidget *parent) : QWidget(parent), GraphStart(0), GraphP setAutoFillBackground(true); CursorAPos = 0; CursorBPos = 0; + + setWindowTitle(tr("Sliders")); } -void ProxWidget::closeEvent(QCloseEvent *event) +void Plot::closeEvent(QCloseEvent *event) { event->ignore(); this->hide(); } -void ProxWidget::mouseMoveEvent(QMouseEvent *event) +void Plot::mouseMoveEvent(QMouseEvent *event) { int x = event->x(); - x -= 40; + x -= WIDTH_AXES; x = (int)(x / GraphPixelsPerPoint); x += GraphStart; if((event->buttons() & Qt::LeftButton)) { @@ -324,7 +509,7 @@ void ProxWidget::mouseMoveEvent(QMouseEvent *event) this->update(); } -void ProxWidget::keyPressEvent(QKeyEvent *event) +void Plot::keyPressEvent(QKeyEvent *event) { int offset; int gridchanged; diff --git a/client/proxguiqt.h b/client/proxguiqt.h index 303a37d0..794db2d7 100644 --- a/client/proxguiqt.h +++ b/client/proxguiqt.h @@ -13,26 +13,66 @@ #include #include #include +#include +#include "ui/ui_overlays.h" +/** + * @brief The actual plot, black area were we paint the graph + */ +class Plot: public QWidget +{ +private: + int GraphStart; + double GraphPixelsPerPoint; + int CursorAPos; + int CursorBPos; + void PlotGraph(int *buffer, int len, QRect r,QRect r2, QPainter* painter, int graphNum); + void PlotDemod(uint8_t *buffer, size_t len, QRect r,QRect r2, QPainter* painter, int graphNum, int plotOffset); + void plotGridLines(QPainter* painter,QRect r); + int xCoordOf(int i, QRect r ); + int yCoordOf(int v, QRect r, int maxVal); + int valueOf_yCoord(int y, QRect r, int maxVal); + QColor getColor(int graphNum); +public: + Plot(QWidget *parent = 0); + +protected: + void paintEvent(QPaintEvent *event); + void closeEvent(QCloseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void mousePressEvent(QMouseEvent *event) { mouseMoveEvent(event); } + void keyPressEvent(QKeyEvent *event); + +}; +class ProxGuiQT; + +/** + * The window with plot and controls + */ class ProxWidget : public QWidget { Q_OBJECT; private: - int GraphStart; - double GraphPixelsPerPoint; - int CursorAPos; - int CursorBPos; - + Plot *plot; + Ui::Form *opsController; + ProxGuiQT *master; + public: - ProxWidget(QWidget *parent = 0); + ProxWidget(QWidget *parent = 0, ProxGuiQT *master = NULL); - protected: - void paintEvent(QPaintEvent *event); - void closeEvent(QCloseEvent *event); - void mouseMoveEvent(QMouseEvent *event); - void mousePressEvent(QMouseEvent *event) { mouseMoveEvent(event); } - void keyPressEvent(QKeyEvent *event); + //protected: + // void paintEvent(QPaintEvent *event); + // void closeEvent(QCloseEvent *event); + // void mouseMoveEvent(QMouseEvent *event); + // void mousePressEvent(QMouseEvent *event) { mouseMoveEvent(event); } + // void keyPressEvent(QKeyEvent *event); + public slots: + void applyOperation(); + void stickOperation(); + void vchange_autocorr(int v); + void vchange_dthr_up(int v); + void vchange_dthr_down(int v); }; class ProxGuiQT : public QObject diff --git a/client/ui.c b/client/ui.c index 219ada63..05e29dc7 100644 --- a/client/ui.c +++ b/client/ui.c @@ -19,11 +19,12 @@ #include "ui.h" double CursorScaleFactor = 1; -int PlotGridX, PlotGridY, PlotGridXdefault= 64, PlotGridYdefault= 64, CursorCPos= 0, CursorDPos= 0; +int PlotGridX=0, PlotGridY=0, PlotGridXdefault= 64, PlotGridYdefault= 64, CursorCPos= 0, CursorDPos= 0; int offline; int flushAfterWrite = 0; //buzzy int GridOffset = 0; bool GridLocked = false; +bool showDemod = true; extern pthread_mutex_t print_lock; diff --git a/client/ui.h b/client/ui.h index 929d3921..5aaac17e 100644 --- a/client/ui.h +++ b/client/ui.h @@ -25,5 +25,6 @@ extern int PlotGridX, PlotGridY, PlotGridXdefault, PlotGridYdefault, CursorCPos, extern int offline; extern int flushAfterWrite; //buzzy extern bool GridLocked; +extern bool showDemod; #endif diff --git a/client/ui/overlays.ui b/client/ui/overlays.ui new file mode 100644 index 00000000..8b7f85e5 --- /dev/null +++ b/client/ui/overlays.ui @@ -0,0 +1,272 @@ + + + Form + + + + 0 + 0 + 614 + 286 + + + + Overlays + + + + + + 0 + + + + Qt::StrongFocus + + + Autocorrelate + + + + + + + + Window size + + + + + + + + + + + + + + + + 10 + + + 10000 + + + 2000 + + + Qt::Horizontal + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Askdemod + + + + + Dirthreshold + + + + + + + + Up + + + + + + + + + + + + + + + + 128 + + + 20 + + + Qt::Horizontal + + + + + + + + + Down + + + + + + + + + + + + + + + + 127 + + + Qt::Horizontal + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + Apply + + + + + + + Sticky + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + TextLabel + + + + + + + + + + + horizontalSlider_window + valueChanged(int) + label_4 + setNum(int) + + + 29 + 90 + + + 597 + 257 + + + + + horizontalSlider_window + valueChanged(int) + label_5 + setNum(int) + + + 153 + 84 + + + 161 + 69 + + + + + horizontalSlider_dirthr_up + valueChanged(int) + label_6 + setNum(int) + + + 53 + 92 + + + 68 + 67 + + + + + horizontalSlider_dirthr_down + valueChanged(int) + label_7 + setNum(int) + + + 184 + 161 + + + 149 + 135 + + + + + diff --git a/client/ui/ui_overlays.h b/client/ui/ui_overlays.h new file mode 100644 index 00000000..83aa3e6c --- /dev/null +++ b/client/ui/ui_overlays.h @@ -0,0 +1,224 @@ +/******************************************************************************** +** Form generated from reading UI file 'overlaystQ7020.ui' +** +** Created by: Qt User Interface Compiler version 4.8.6 +** +** WARNING! All changes made in this file will be lost when recompiling UI file! +********************************************************************************/ + +#ifndef OVERLAYSTQ7020_H +#define OVERLAYSTQ7020_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class Ui_Form +{ +public: + QVBoxLayout *verticalLayout_3; + QTabWidget *tabWidget_overlays; + QWidget *tab; + QVBoxLayout *verticalLayout_2; + QFormLayout *formLayout; + QLabel *label; + QLabel *label_5; + QSlider *horizontalSlider_window; + QSpacerItem *verticalSpacer; + QWidget *tab_3; + QWidget *tab_2; + QVBoxLayout *verticalLayout; + QFormLayout *formLayout_2; + QLabel *label_2; + QLabel *label_6; + QSlider *horizontalSlider_dirthr_up; + QFormLayout *formLayout_3; + QLabel *label_3; + QLabel *label_7; + QSlider *horizontalSlider_dirthr_down; + QSpacerItem *verticalSpacer_2; + QHBoxLayout *horizontalLayout; + QPushButton *pushButton_apply; + QPushButton *pushButton_sticky; + QSpacerItem *horizontalSpacer; + QLabel *label_4; + + void setupUi(QWidget *Form) + { + if (Form->objectName().isEmpty()) + Form->setObjectName(QString::fromUtf8("Form")); + Form->resize(614, 286); + verticalLayout_3 = new QVBoxLayout(Form); + verticalLayout_3->setObjectName(QString::fromUtf8("verticalLayout_3")); + tabWidget_overlays = new QTabWidget(Form); + tabWidget_overlays->setObjectName(QString::fromUtf8("tabWidget_overlays")); + tab = new QWidget(); + tab->setObjectName(QString::fromUtf8("tab")); + tab->setFocusPolicy(Qt::StrongFocus); + verticalLayout_2 = new QVBoxLayout(tab); + verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2")); + formLayout = new QFormLayout(); + formLayout->setObjectName(QString::fromUtf8("formLayout")); + label = new QLabel(tab); + label->setObjectName(QString::fromUtf8("label")); + + formLayout->setWidget(0, QFormLayout::LabelRole, label); + + label_5 = new QLabel(tab); + label_5->setObjectName(QString::fromUtf8("label_5")); + + formLayout->setWidget(0, QFormLayout::FieldRole, label_5); + + + verticalLayout_2->addLayout(formLayout); + + horizontalSlider_window = new QSlider(tab); + horizontalSlider_window->setObjectName(QString::fromUtf8("horizontalSlider_window")); + horizontalSlider_window->setMinimum(10); + horizontalSlider_window->setMaximum(10000); + horizontalSlider_window->setValue(2000); + horizontalSlider_window->setOrientation(Qt::Horizontal); + + verticalLayout_2->addWidget(horizontalSlider_window); + + verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); + + verticalLayout_2->addItem(verticalSpacer); + + tabWidget_overlays->addTab(tab, QString()); + tab_3 = new QWidget(); + tab_3->setObjectName(QString::fromUtf8("tab_3")); + tabWidget_overlays->addTab(tab_3, QString()); + tab_2 = new QWidget(); + tab_2->setObjectName(QString::fromUtf8("tab_2")); + verticalLayout = new QVBoxLayout(tab_2); + verticalLayout->setObjectName(QString::fromUtf8("verticalLayout")); + formLayout_2 = new QFormLayout(); + formLayout_2->setObjectName(QString::fromUtf8("formLayout_2")); + label_2 = new QLabel(tab_2); + label_2->setObjectName(QString::fromUtf8("label_2")); + + formLayout_2->setWidget(0, QFormLayout::LabelRole, label_2); + + label_6 = new QLabel(tab_2); + label_6->setObjectName(QString::fromUtf8("label_6")); + + formLayout_2->setWidget(0, QFormLayout::FieldRole, label_6); + + + verticalLayout->addLayout(formLayout_2); + + horizontalSlider_dirthr_up = new QSlider(tab_2); + horizontalSlider_dirthr_up->setObjectName(QString::fromUtf8("horizontalSlider_dirthr_up")); + horizontalSlider_dirthr_up->setMaximum(128); + horizontalSlider_dirthr_up->setValue(20); + horizontalSlider_dirthr_up->setOrientation(Qt::Horizontal); + + verticalLayout->addWidget(horizontalSlider_dirthr_up); + + formLayout_3 = new QFormLayout(); + formLayout_3->setObjectName(QString::fromUtf8("formLayout_3")); + label_3 = new QLabel(tab_2); + label_3->setObjectName(QString::fromUtf8("label_3")); + + formLayout_3->setWidget(0, QFormLayout::LabelRole, label_3); + + label_7 = new QLabel(tab_2); + label_7->setObjectName(QString::fromUtf8("label_7")); + + formLayout_3->setWidget(0, QFormLayout::FieldRole, label_7); + + + verticalLayout->addLayout(formLayout_3); + + horizontalSlider_dirthr_down = new QSlider(tab_2); + horizontalSlider_dirthr_down->setObjectName(QString::fromUtf8("horizontalSlider_dirthr_down")); + horizontalSlider_dirthr_down->setMaximum(127); + horizontalSlider_dirthr_down->setOrientation(Qt::Horizontal); + + verticalLayout->addWidget(horizontalSlider_dirthr_down); + + verticalSpacer_2 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); + + verticalLayout->addItem(verticalSpacer_2); + + tabWidget_overlays->addTab(tab_2, QString()); + + verticalLayout_3->addWidget(tabWidget_overlays); + + horizontalLayout = new QHBoxLayout(); + horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); + pushButton_apply = new QPushButton(Form); + pushButton_apply->setObjectName(QString::fromUtf8("pushButton_apply")); + + horizontalLayout->addWidget(pushButton_apply); + + pushButton_sticky = new QPushButton(Form); + pushButton_sticky->setObjectName(QString::fromUtf8("pushButton_sticky")); + + horizontalLayout->addWidget(pushButton_sticky); + + horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); + + horizontalLayout->addItem(horizontalSpacer); + + label_4 = new QLabel(Form); + label_4->setObjectName(QString::fromUtf8("label_4")); + + horizontalLayout->addWidget(label_4); + + + verticalLayout_3->addLayout(horizontalLayout); + + + retranslateUi(Form); + QObject::connect(horizontalSlider_window, SIGNAL(valueChanged(int)), label_4, SLOT(setNum(int))); + QObject::connect(horizontalSlider_window, SIGNAL(valueChanged(int)), label_5, SLOT(setNum(int))); + QObject::connect(horizontalSlider_dirthr_up, SIGNAL(valueChanged(int)), label_6, SLOT(setNum(int))); + QObject::connect(horizontalSlider_dirthr_down, SIGNAL(valueChanged(int)), label_7, SLOT(setNum(int))); + + tabWidget_overlays->setCurrentIndex(0); + + + QMetaObject::connectSlotsByName(Form); + } // setupUi + + void retranslateUi(QWidget *Form) + { + Form->setWindowTitle(QApplication::translate("Form", "Overlays", 0)); + label->setText(QApplication::translate("Form", "Window size", 0)); + label_5->setText(QString()); + tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab), QApplication::translate("Form", "Autocorrelate", 0)); + tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab_3), QApplication::translate("Form", "Askdemod", 0)); + label_2->setText(QApplication::translate("Form", "Up", 0)); + label_6->setText(QString()); + label_3->setText(QApplication::translate("Form", "Down", 0)); + label_7->setText(QString()); + tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab_2), QApplication::translate("Form", "Dirthreshold", 0)); + pushButton_apply->setText(QApplication::translate("Form", "Apply", 0)); + pushButton_sticky->setText(QApplication::translate("Form", "Sticky", 0)); + label_4->setText(QApplication::translate("Form", "TextLabel", 0)); + } // retranslateUi + +}; + +namespace Ui { + class Form: public Ui_Form {}; +} // namespace Ui + +QT_END_NAMESPACE + +#endif // OVERLAYSTQ7020_H From 9fe4507c03c26715b532b4ceb1f46e8198ecd4c9 Mon Sep 17 00:00:00 2001 From: marshmellow42 Date: Wed, 12 Apr 2017 17:55:31 -0400 Subject: [PATCH 04/17] update more demods for graphing still todo fsk based tag demods (like HID, AWID, IO, Pyramid...) --- client/cmddata.c | 16 ++++++++++------ client/cmdlfawid.c | 1 + client/cmdlfem4x.c | 5 ++++- client/cmdlffdx.c | 2 ++ client/cmdlfgproxii.c | 4 +++- client/cmdlfhid.c | 1 + client/cmdlfindala.c | 1 + client/cmdlfio.c | 2 ++ client/cmdlfjablotron.c | 4 ++-- client/cmdlfnexwatch.c | 3 ++- client/cmdlfnoralsy.c | 1 + client/cmdlfparadox.c | 1 + client/cmdlfpresco.c | 5 +++-- client/cmdlfpyramid.c | 1 + client/cmdlfsecurakey.c | 2 +- client/cmdlfviking.c | 3 ++- client/cmdlfvisa2000.c | 2 +- client/proxguiqt.cpp | 6 ++++-- common/lfdemod.c | 19 +++++-------------- common/lfdemod.h | 2 +- 20 files changed, 48 insertions(+), 33 deletions(-) diff --git a/client/cmddata.c b/client/cmddata.c index 7a411324..a59236e6 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -394,7 +394,7 @@ int CmdBiphaseDecodeRaw(const char *Cmd) uint8_t BitStream[MAX_DEMOD_BUF_LEN]={0}; size = sizeof(BitStream); if ( !getDemodBuf(BitStream, &size) ) return 0; - errCnt=BiphaseRawDecode(BitStream, &size, offset, invert); + errCnt=BiphaseRawDecode(BitStream, &size, &offset, invert); if (errCnt<0){ PrintAndLog("Error during decode:%d", errCnt); return 0; @@ -407,10 +407,12 @@ int CmdBiphaseDecodeRaw(const char *Cmd) if (errCnt>0){ PrintAndLog("# Errors found during Demod (shown as 7 in bit stream): %d",errCnt); } + PrintAndLog("Biphase Decoded using offset: %d - # invert:%d - data:",offset,invert); PrintAndLog("%s", sprint_bin_break(BitStream, size, 16)); if (offset) setDemodBuf(DemodBuffer,DemodBufferLen-offset, offset); //remove first bit from raw demod + setClockGrid(g_DemodClock, g_DemodStartIdx + g_DemodClock*offset/2); return 1; } @@ -423,26 +425,28 @@ int ASKbiphaseDemod(const char *Cmd, bool verbose) sscanf(Cmd, "%i %i %i %i", &offset, &clk, &invert, &maxErr); uint8_t BitStream[MAX_GRAPH_TRACE_LEN]; - size_t size = getFromGraphBuf(BitStream); + size_t size = getFromGraphBuf(BitStream); + int startIdx = 0; //invert here inverts the ask raw demoded bits which has no effect on the demod, but we need the pointer - int errCnt = askdemod(BitStream, &size, &clk, &invert, maxErr, 0, 0); + int errCnt = askdemod_ext(BitStream, &size, &clk, &invert, maxErr, 0, 0, &startIdx); if ( errCnt < 0 || errCnt > maxErr ) { if (g_debugMode) PrintAndLog("DEBUG: no data or error found %d, clock: %d", errCnt, clk); return 0; - } + } //attempt to Biphase decode BitStream - errCnt = BiphaseRawDecode(BitStream, &size, offset, invert); + errCnt = BiphaseRawDecode(BitStream, &size, &offset, invert); if (errCnt < 0){ if (g_debugMode || verbose) PrintAndLog("Error BiphaseRawDecode: %d", errCnt); return 0; - } + } if (errCnt > maxErr) { if (g_debugMode || verbose) PrintAndLog("Error BiphaseRawDecode too many errors: %d", errCnt); return 0; } //success set DemodBuffer and return setDemodBuf(BitStream, size, 0); + setClockGrid(clk, startIdx + clk*offset/2); if (g_debugMode || verbose){ PrintAndLog("Biphase Decoded using offset: %d - clock: %d - # errors:%d - data:",offset,clk,errCnt); printDemodBuff(); diff --git a/client/cmdlfawid.c b/client/cmdlfawid.c index 225816df..7f0b9910 100644 --- a/client/cmdlfawid.c +++ b/client/cmdlfawid.c @@ -126,6 +126,7 @@ int CmdFSKdemodAWID(const char *Cmd) uint32_t rawHi = bytebits_to_byte(BitStream+idx+32,32); uint32_t rawHi2 = bytebits_to_byte(BitStream+idx,32); setDemodBuf(BitStream,96,idx); + setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock)); size = removeParity(BitStream, idx+8, 4, 1, 88); if (size != 66){ diff --git a/client/cmdlfem4x.c b/client/cmdlfem4x.c index 83a7da4e..6587afe8 100644 --- a/client/cmdlfem4x.c +++ b/client/cmdlfem4x.c @@ -153,7 +153,8 @@ int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo ) if (Em410xDecode(BitStream, &BitLen, &idx, hi, lo)) { //set GraphBuffer for clone or sim command setDemodBuf(DemodBuffer, (BitLen==40) ? 64 : 128, idx+1); - g_DemodStartIdx += (idx+1)*g_DemodClock; + setClockGrid(g_DemodClock, g_DemodStartIdx + ((idx+1)*g_DemodClock)); + if (g_debugMode) { PrintAndLog("DEBUG: idx: %d, Len: %d, Printing Demod Buffer:", idx, BitLen); printDemodBuff(); @@ -704,6 +705,8 @@ bool EM4x05testDemodReadData(uint32_t *word, bool readCmd) { } setDemodBuf(DemodBuffer, 32, 0); + setClockGrid(0,0); + *word = bytebits_to_byteLSBF(DemodBuffer, 32); } return true; diff --git a/client/cmdlffdx.c b/client/cmdlffdx.c index e90d024e..234db59f 100644 --- a/client/cmdlffdx.c +++ b/client/cmdlffdx.c @@ -159,6 +159,8 @@ int CmdFdxDemod(const char *Cmd){ // set and leave DemodBuffer intact setDemodBuf(DemodBuffer, 128, preambleIndex); + setClockGrid(g_DemodClock, g_DemodStartIdx + (preambleIndex*g_DemodClock)); + uint8_t bits_no_spacer[117]; memcpy(bits_no_spacer, DemodBuffer + 11, 117); diff --git a/client/cmdlfgproxii.c b/client/cmdlfgproxii.c index 1657f761..71c5f391 100644 --- a/client/cmdlfgproxii.c +++ b/client/cmdlfgproxii.c @@ -83,7 +83,9 @@ int CmdG_Prox_II_Demod(const char *Cmd) PrintAndLog("Decoded Raw: %s", sprint_hex(ByteStream, 8)); } PrintAndLog("Raw: %08x%08x%08x", raw1,raw2,raw3); - setDemodBuf(DemodBuffer+ans, 96, 0); + setDemodBuf(DemodBuffer, 96, ans); + setClockGrid(g_DemodClock, g_DemodStartIdx + (ans*g_DemodClock)); + return 1; } //by marshmellow diff --git a/client/cmdlfhid.c b/client/cmdlfhid.c index e580a10d..a9693fb2 100644 --- a/client/cmdlfhid.c +++ b/client/cmdlfhid.c @@ -99,6 +99,7 @@ int CmdFSKdemodHID(const char *Cmd) (unsigned int) fmtLen, (unsigned int) fc, (unsigned int) cardnum); } setDemodBuf(BitStream,BitLen,idx); + setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock)); if (g_debugMode){ PrintAndLog("DEBUG: idx: %d, Len: %d, Printing Demod Buffer:", idx, BitLen); printDemodBuff(); diff --git a/client/cmdlfindala.c b/client/cmdlfindala.c index fc396ac6..de1757e9 100644 --- a/client/cmdlfindala.c +++ b/client/cmdlfindala.c @@ -46,6 +46,7 @@ int CmdIndalaDecode(const char *Cmd) { return -1; } setDemodBuf(DemodBuffer, size, (size_t)startIdx); + setClockGrid(g_DemodClock, g_DemodStartIdx + (startIdx*g_DemodClock)); if (invert) if (g_debugMode) PrintAndLog("Had to invert bits"); diff --git a/client/cmdlfio.c b/client/cmdlfio.c index cfcc7d62..be8cf25e 100644 --- a/client/cmdlfio.c +++ b/client/cmdlfio.c @@ -119,6 +119,8 @@ int CmdFSKdemodIO(const char *Cmd) PrintAndLog("IO Prox XSF(%02d)%02x:%05d (%08x%08x) [%02x %s]",version,facilitycode,number,code,code2, crc, crcStr); setDemodBuf(BitStream,64,idx); + setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock)); + if (g_debugMode){ PrintAndLog("DEBUG: idx: %d, Len: %d, Printing demod buffer:",idx,64); printDemodBuff(); diff --git a/client/cmdlfjablotron.c b/client/cmdlfjablotron.c index a2984ac8..9c69099e 100644 --- a/client/cmdlfjablotron.c +++ b/client/cmdlfjablotron.c @@ -117,8 +117,8 @@ int CmdJablotronDemod(const char *Cmd) { return 0; } - setDemodBuf(DemodBuffer+ans, 64, 0); - //setGrid_Clock(64); + setDemodBuf(DemodBuffer, 64, ans); + setClockGrid(g_DemodClock, g_DemodStartIdx + (ans*g_DemodClock)); //got a good demod uint32_t raw1 = bytebits_to_byte(DemodBuffer, 32); diff --git a/client/cmdlfnexwatch.c b/client/cmdlfnexwatch.c index 64ea54e5..caabe835 100644 --- a/client/cmdlfnexwatch.c +++ b/client/cmdlfnexwatch.c @@ -38,7 +38,8 @@ int CmdPSKNexWatch(const char *Cmd) } if (size != 128) return 0; setDemodBuf(DemodBuffer, size, startIdx+4); - startIdx = 8+32; //4 = extra i added, 8 = preamble, 32 = reserved bits (always 0) + setClockGrid(g_DemodClock, g_DemodStartIdx + ((startIdx+4)*g_DemodClock)); + startIdx = 8+32; // 8 = preamble, 32 = reserved bits (always 0) //get ID uint32_t ID = 0; for (uint8_t wordIdx=0; wordIdx<4; wordIdx++){ diff --git a/client/cmdlfnoralsy.c b/client/cmdlfnoralsy.c index 282a79ae..2c90fa14 100644 --- a/client/cmdlfnoralsy.c +++ b/client/cmdlfnoralsy.c @@ -135,6 +135,7 @@ int CmdNoralsyDemod(const char *Cmd) { return 0; } setDemodBuf(DemodBuffer, 96, ans); + setClockGrid(g_DemodClock, g_DemodStartIdx + (ans*g_DemodClock)); //setGrid_Clock(32); //got a good demod diff --git a/client/cmdlfparadox.c b/client/cmdlfparadox.c index 87e49b3a..6582eb35 100644 --- a/client/cmdlfparadox.c +++ b/client/cmdlfparadox.c @@ -63,6 +63,7 @@ int CmdFSKdemodParadox(const char *Cmd) PrintAndLog("Paradox TAG ID: %x%08x - FC: %d - Card: %d - Checksum: %02x - RAW: %08x%08x%08x", hi>>10, (hi & 0x3)<<26 | (lo>>10), fc, cardnum, (lo>>2) & 0xFF, rawHi2, rawHi, rawLo); setDemodBuf(BitStream,BitLen,idx); + setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock)); if (g_debugMode){ PrintAndLog("DEBUG: idx: %d, len: %d, Printing Demod Buffer:", idx, BitLen); printDemodBuff(); diff --git a/client/cmdlfpresco.c b/client/cmdlfpresco.c index f18c3ec6..8ac3a71e 100644 --- a/client/cmdlfpresco.c +++ b/client/cmdlfpresco.c @@ -144,8 +144,9 @@ int CmdPrescoDemod(const char *Cmd) { uint32_t cardid = raw4; PrintAndLog("Presco Tag Found: Card ID %08X", cardid); PrintAndLog("Raw: %08X%08X%08X%08X", raw1,raw2,raw3,raw4); - setDemodBuf(DemodBuffer+ans, 128, 0); - + setDemodBuf(DemodBuffer, 128, ans); + setClockGrid(g_DemodClock, g_DemodStartIdx + (ans*g_DemodClock)); + uint32_t sitecode = 0, usercode = 0, fullcode = 0; bool Q5=false; char cmd[12] = {0}; diff --git a/client/cmdlfpyramid.c b/client/cmdlfpyramid.c index 9cd4b207..c7a6cb93 100644 --- a/client/cmdlfpyramid.c +++ b/client/cmdlfpyramid.c @@ -152,6 +152,7 @@ int CmdFSKdemodPyramid(const char *Cmd) uint32_t rawHi2 = bytebits_to_byte(BitStream+idx+32,32); uint32_t rawHi3 = bytebits_to_byte(BitStream+idx,32); setDemodBuf(BitStream,128,idx); + setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock)); size = removeParity(BitStream, idx+8, 8, 1, 120); if (size != 105){ diff --git a/client/cmdlfsecurakey.c b/client/cmdlfsecurakey.c index 87ebb25e..8085eedc 100644 --- a/client/cmdlfsecurakey.c +++ b/client/cmdlfsecurakey.c @@ -64,7 +64,7 @@ int CmdSecurakeyDemod(const char *Cmd) { return 0; } setDemodBuf(DemodBuffer, 96, ans); - //setGrid_Clock(40); + setClockGrid(g_DemodClock, g_DemodStartIdx + (ans*g_DemodClock)); //got a good demod uint32_t raw1 = bytebits_to_byte(DemodBuffer , 32); diff --git a/client/cmdlfviking.c b/client/cmdlfviking.c index 3d525c1c..779156c8 100644 --- a/client/cmdlfviking.c +++ b/client/cmdlfviking.c @@ -73,7 +73,8 @@ int CmdVikingDemod(const char *Cmd) { uint8_t checksum = bytebits_to_byte(DemodBuffer+ans+32+24, 8); PrintAndLog("Viking Tag Found: Card ID %08X, Checksum: %02X", cardid, (unsigned int) checksum); PrintAndLog("Raw: %08X%08X", raw1,raw2); - setDemodBuf(DemodBuffer+ans, 64, 0); + setDemodBuf(DemodBuffer, 64, ans); + setClockGrid(g_DemodClock, g_DemodStartIdx + (ans*g_DemodClock)); return 1; } diff --git a/client/cmdlfvisa2000.c b/client/cmdlfvisa2000.c index b461d94d..562b9bcd 100644 --- a/client/cmdlfvisa2000.c +++ b/client/cmdlfvisa2000.c @@ -119,7 +119,7 @@ int CmdVisa2kDemod(const char *Cmd) { return 0; } setDemodBuf(DemodBuffer, 96, ans); - //setGrid_Clock(64); + setClockGrid(g_DemodClock, g_DemodStartIdx + (ans*g_DemodClock)); //got a good demod uint32_t raw1 = bytebits_to_byte(DemodBuffer, 32); diff --git a/client/proxguiqt.cpp b/client/proxguiqt.cpp index c0aff8b6..05a048d8 100644 --- a/client/proxguiqt.cpp +++ b/client/proxguiqt.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include "proxguiqt.h" @@ -431,11 +432,11 @@ void Plot::paintEvent(QPaintEvent *event) plotGridLines(&painter, plotRect); //Start painting graph - PlotGraph(GraphBuffer, GraphTraceLen,plotRect,infoRect,&painter,0); - PlotGraph(s_Buff, GraphTraceLen,plotRect,infoRect,&painter,1); if (showDemod && DemodBufferLen > 8) { PlotDemod(DemodBuffer, DemodBufferLen,plotRect,infoRect,&painter,2,g_DemodStartIdx); } + PlotGraph(s_Buff, GraphTraceLen,plotRect,infoRect,&painter,1); + PlotGraph(GraphBuffer, GraphTraceLen,plotRect,infoRect,&painter,0); // End graph drawing //Draw the cursors @@ -472,6 +473,7 @@ void Plot::paintEvent(QPaintEvent *event) Plot::Plot(QWidget *parent) : QWidget(parent), GraphStart(0), GraphPixelsPerPoint(1) { + //Need to set this, otherwise we don't receive keypress events setFocusPolicy( Qt::StrongFocus); resize(600, 300); diff --git a/common/lfdemod.c b/common/lfdemod.c index d6ef88a4..072bd120 100644 --- a/common/lfdemod.c +++ b/common/lfdemod.c @@ -1130,10 +1130,10 @@ int millerRawDecode(uint8_t *BitStream, size_t *size, int invert) { //take 01 or 10 = 1 and 11 or 00 = 0 //check for phase errors - should never have 111 or 000 should be 01001011 or 10110100 for 1010 //decodes biphase or if inverted it is AKA conditional dephase encoding AKA differential manchester encoding -int BiphaseRawDecode(uint8_t *BitStream, size_t *size, int offset, int invert) { +int BiphaseRawDecode(uint8_t *BitStream, size_t *size, int *offset, int invert) { uint16_t bitnum = 0; uint16_t errCnt = 0; - size_t i = offset; + size_t i = *offset; uint16_t MaxBits=512; //if not enough samples - error if (*size < 51) return -1; @@ -1143,8 +1143,8 @@ int BiphaseRawDecode(uint8_t *BitStream, size_t *size, int offset, int invert) { if (BitStream[i+1]==BitStream[i+2]) offsetA=0; if (BitStream[i+2]==BitStream[i+3]) offsetB=0; } - if (!offsetA && offsetB) offset++; - for (i=offset; i<*size-3; i+=2){ + if (!offsetA && offsetB) *offset+=1; + for (i=*offset; i<*size-3; i+=2){ //check for phase error if (BitStream[i+1]==BitStream[i+2]) { BitStream[bitnum++]=7; @@ -1490,6 +1490,7 @@ size_t aggregate_bits(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, //by marshmellow (from holiman's base) // full fsk demod from GraphBuffer wave to decoded 1s and 0s (no mandemod) int fskdemod_ext(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *startIdx) { + if (justNoise(dest, *size)) return 0; // FSK demodulator size = fsk_wave_demod(dest, size, fchigh, fclow, startIdx); size = aggregate_bits(dest, size, rfLen, invert, fchigh, fclow, startIdx); @@ -1631,8 +1632,6 @@ int AWIDdemodFSK(uint8_t *dest, size_t *size) { //make sure buffer has enough data if (*size < 96*50) return -1; - if (justNoise(dest, *size)) return -2; - // FSK demodulator *size = fskdemod(dest, *size, 50, 1, 10, 8); // fsk2a RF/50 if (*size < 96) return -3; //did we get a good demod? @@ -1717,8 +1716,6 @@ int gProxII_Demod(uint8_t BitStream[], size_t *size) { // loop to get raw HID waveform then FSK demodulate the TAG ID from it int HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo) { - if (justNoise(dest, *size)) return -1; - size_t numStart=0, size2=*size, startIdx=0; // FSK demodulator *size = fskdemod(dest, size2,50,1,10,8); //fsk2a @@ -1747,7 +1744,6 @@ int HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32 } int IOdemodFSK(uint8_t *dest, size_t size) { - if (justNoise(dest, size)) return -1; //make sure buffer has data if (size < 66*64) return -2; // FSK demodulator @@ -1797,8 +1793,6 @@ int indala26decode(uint8_t *bitStream, size_t *size, uint8_t *invert) { // loop to get raw paradox waveform then FSK demodulate the TAG ID from it int ParadoxdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo) { - if (justNoise(dest, *size)) return -1; - size_t numStart=0, size2=*size, startIdx=0; // FSK demodulator *size = fskdemod(dest, size2,50,1,10,8); //fsk2a @@ -1845,9 +1839,6 @@ int PyramiddemodFSK(uint8_t *dest, size_t *size) { //make sure buffer has data if (*size < 128*50) return -5; - //test samples are not just noise - if (justNoise(dest, *size)) return -1; - // FSK demodulator *size = fskdemod(dest, *size, 50, 1, 10, 8); // fsk2a RF/50 if (*size < 128) return -2; //did we get a good demod? diff --git a/common/lfdemod.h b/common/lfdemod.h index 9f37a969..56e07e56 100644 --- a/common/lfdemod.h +++ b/common/lfdemod.h @@ -21,7 +21,7 @@ extern size_t addParity(uint8_t *BitSource, uint8_t *dest, uint8_t sourceLen, extern int askdemod(uint8_t *BinStream, size_t *size, int *clk, int *invert, int maxErr, uint8_t amp, uint8_t askType); extern int askdemod_ext(uint8_t *BinStream, size_t *size, int *clk, int *invert, int maxErr, uint8_t amp, uint8_t askType, int *startIdx); extern void askAmp(uint8_t *BitStream, size_t size); -extern int BiphaseRawDecode(uint8_t * BitStream, size_t *size, int offset, int invert); +extern int BiphaseRawDecode(uint8_t * BitStream, size_t *size, int *offset, int invert); extern uint32_t bytebits_to_byte(uint8_t* src, size_t numbits); extern uint32_t bytebits_to_byteLSBF(uint8_t* src, size_t numbits); extern uint16_t countFC(uint8_t *BitStream, size_t size, uint8_t fskAdj); From c4f51073fc1a2cb74363bb9b0d9f616c7dd742bb Mon Sep 17 00:00:00 2001 From: marshmellow42 Date: Thu, 13 Apr 2017 10:33:18 -0400 Subject: [PATCH 05/17] combine autocorr, dirth functions fix lfdemod bug add askedge to overlays (remove askdemod) --- client/cmddata.c | 102 ++++++++++++++++++---------------- client/cmddata.h | 5 +- client/cmdlf.c | 2 +- client/graph.c | 54 ------------------ client/graph.h | 3 - client/proxgui.h | 4 +- client/proxguiqt.cpp | 20 +++++-- client/proxguiqt.h | 1 + client/ui/overlays.ui | 106 +++++++++++++++++++++++++++++------- client/ui/ui_overlays.h | 118 +++++++++++++++++++++++++++------------- common/lfdemod.c | 2 +- 11 files changed, 247 insertions(+), 170 deletions(-) diff --git a/client/cmddata.c b/client/cmddata.c index a59236e6..5dcd87b6 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -507,45 +507,44 @@ int Cmdaskrawdemod(const char *Cmd) return ASKDemod(Cmd, true, false, 0); } -int AutoCorrelate(int window, bool SaveGrph, bool verbose) +int AutoCorrelate(const int *in, int *out, size_t len, int window, bool SaveGrph, bool verbose) { static int CorrelBuffer[MAX_GRAPH_TRACE_LEN]; size_t Correlation = 0; int maxSum = 0; int lastMax = 0; if (verbose) PrintAndLog("performing %d correlations", GraphTraceLen - window); - for (int i = 0; i < GraphTraceLen - window; ++i) { + for (int i = 0; i < len - window; ++i) { int sum = 0; for (int j = 0; j < window; ++j) { - sum += (GraphBuffer[j]*GraphBuffer[i + j]) / 256; + sum += (in[j]*in[i + j]) / 256; } CorrelBuffer[i] = sum; - if (sum >= maxSum-100 && sum <= maxSum+100){ + if (sum >= maxSum-100 && sum <= maxSum+100) { //another max Correlation = i-lastMax; lastMax = i; if (sum > maxSum) maxSum = sum; - } else if (sum > maxSum){ + } else if (sum > maxSum) { maxSum=sum; lastMax = i; } } - if (Correlation==0){ + if (Correlation==0) { //try again with wider margin - for (int i = 0; i < GraphTraceLen - window; i++){ - if (CorrelBuffer[i] >= maxSum-(maxSum*0.05) && CorrelBuffer[i] <= maxSum+(maxSum*0.05)){ + for (int i = 0; i < len - window; i++) { + if (CorrelBuffer[i] >= maxSum-(maxSum*0.05) && CorrelBuffer[i] <= maxSum+(maxSum*0.05)) { //another max Correlation = i-lastMax; lastMax = i; - //if (CorrelBuffer[i] > maxSum) maxSum = sum; } } } if (verbose && Correlation > 0) PrintAndLog("Possible Correlation: %d samples",Correlation); - if (SaveGrph){ - GraphTraceLen = GraphTraceLen - window; - memcpy(GraphBuffer, CorrelBuffer, GraphTraceLen * sizeof (int)); + if (SaveGrph) { + //GraphTraceLen = GraphTraceLen - window; + memcpy(out, CorrelBuffer, len * sizeof(int)); RepaintGraphWindow(); } return Correlation; @@ -578,7 +577,7 @@ int CmdAutoCorr(const char *Cmd) return 0; } if (grph == 'g') updateGrph=true; - return AutoCorrelate(window, updateGrph, true); + return AutoCorrelate(GraphBuffer, GraphBuffer, GraphTraceLen, window, updateGrph, true); } int CmdBitsamples(const char *Cmd) @@ -681,6 +680,18 @@ int CmdGraphShiftZero(const char *Cmd) return 0; } +int AskEdgeDetect(const int *in, int *out, int len, int threshold) { + int Last = 0; + for(int i = 1; i= threshold) //large jump up + Last = 127; + else if(in[i]-in[i-1] <= -1 * threshold) //large jump down + Last = -127; + out[i-1] = Last; + } + return 0; +} + //by marshmellow //use large jumps in read samples to identify edges of waves and then amplify that wave to max //similar to dirtheshold, threshold commands @@ -688,18 +699,12 @@ int CmdGraphShiftZero(const char *Cmd) int CmdAskEdgeDetect(const char *Cmd) { int thresLen = 25; - int Last = 0; + int ans = 0; sscanf(Cmd, "%i", &thresLen); - for(int i = 1; i=thresLen) //large jump up - Last = 127; - else if(GraphBuffer[i]-GraphBuffer[i-1]<=-1*thresLen) //large jump down - Last = -127; - GraphBuffer[i-1] = Last; - } + ans = AskEdgeDetect(GraphBuffer, GraphBuffer, GraphTraceLen, thresLen); RepaintGraphWindow(); - return 0; + return ans; } /* Print our clock rate */ @@ -1433,6 +1438,34 @@ int CmdScale(const char *Cmd) return 0; } +int directionalThreshold(const int* in, int *out, size_t len, int8_t up, int8_t down) +{ + int lastValue = in[0]; + out[0] = 0; // Will be changed at the end, but init 0 as we adjust to last samples value if no threshold kicks in. + + for (int i = 1; i < len; ++i) { + // Apply first threshold to samples heading up + if (in[i] >= up && in[i] > lastValue) + { + lastValue = out[i]; // Buffer last value as we overwrite it. + out[i] = 1; + } + // Apply second threshold to samples heading down + else if (in[i] <= down && in[i] < lastValue) + { + lastValue = out[i]; // Buffer last value as we overwrite it. + out[i] = -1; + } + else + { + lastValue = out[i]; // Buffer last value as we overwrite it. + out[i] = out[i-1]; + } + } + out[0] = out[1]; // Align with first edited sample. + return 0; +} + int CmdDirectionalThreshold(const char *Cmd) { int8_t upThres = param_get8(Cmd, 0); @@ -1440,30 +1473,7 @@ int CmdDirectionalThreshold(const char *Cmd) printf("Applying Up Threshold: %d, Down Threshold: %d\n", upThres, downThres); - int lastValue = GraphBuffer[0]; - GraphBuffer[0] = 0; // Will be changed at the end, but init 0 as we adjust to last samples value if no threshold kicks in. - - for (int i = 1; i < GraphTraceLen; ++i) { - // Apply first threshold to samples heading up - if (GraphBuffer[i] >= upThres && GraphBuffer[i] > lastValue) - { - lastValue = GraphBuffer[i]; // Buffer last value as we overwrite it. - GraphBuffer[i] = 127; - } - // Apply second threshold to samples heading down - else if (GraphBuffer[i] <= downThres && GraphBuffer[i] < lastValue) - { - lastValue = GraphBuffer[i]; // Buffer last value as we overwrite it. - GraphBuffer[i] = -127; - } - else - { - lastValue = GraphBuffer[i]; // Buffer last value as we overwrite it. - GraphBuffer[i] = GraphBuffer[i-1]; - - } - } - GraphBuffer[0] = GraphBuffer[1]; // Aline with first edited sample. + directionalThreshold(GraphBuffer, GraphBuffer,GraphTraceLen, upThres, downThres); RepaintGraphWindow(); return 0; } diff --git a/client/cmddata.h b/client/cmddata.h index 4a3287a7..0484acdb 100644 --- a/client/cmddata.h +++ b/client/cmddata.h @@ -27,7 +27,7 @@ void save_restoreDB(uint8_t saveOpt);// option '1' to save DemodBuffer any other int CmdPrintDemodBuff(const char *Cmd); int Cmdaskrawdemod(const char *Cmd); int Cmdaskmandemod(const char *Cmd); -int AutoCorrelate(int window, bool SaveGrph, bool verbose); +int AutoCorrelate(const int *in, int *out, size_t len, int window, bool SaveGrph, bool verbose); int CmdAutoCorr(const char *Cmd); int CmdBiphaseDecodeRaw(const char *Cmd); int CmdBitsamples(const char *Cmd); @@ -65,6 +65,9 @@ int PSKDemod(const char *Cmd, bool verbose); int NRZrawDemod(const char *Cmd, bool verbose); int getSamples(int n, bool silent); void setClockGrid(int clk, int offset); +int directionalThreshold(const int* in, int *out, size_t len, int8_t up, int8_t down); +extern int AskEdgeDetect(const int *in, int *out, int len, int threshold); +//int autoCorr(const int* in, int *out, size_t len, int window); #define MAX_DEMOD_BUF_LEN (1024*128) extern uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN]; diff --git a/client/cmdlf.c b/client/cmdlf.c index 5825b339..3c4319c7 100644 --- a/client/cmdlf.c +++ b/client/cmdlf.c @@ -1059,7 +1059,7 @@ int CmdLFfind(const char *Cmd) ans=CheckChipType(cmdp); //test unknown tag formats (raw mode)0 PrintAndLog("\nChecking for Unknown tags:\n"); - ans=AutoCorrelate(4000, false, false); + ans=AutoCorrelate(GraphBuffer, GraphBuffer, GraphTraceLen, 4000, false, false); if (ans > 0) PrintAndLog("Possible Auto Correlation of %d repeating samples",ans); ans=GetFskClock("",false,false); if (ans != 0) { //fsk diff --git a/client/graph.c b/client/graph.c index 547e9b30..cc0ec6fb 100644 --- a/client/graph.c +++ b/client/graph.c @@ -293,57 +293,3 @@ bool graphJustNoise(int *BitStream, int size) } return justNoise1; } -int autoCorr(const int* in, int *out, size_t len, int window) -{ - static int CorrelBuffer[MAX_GRAPH_TRACE_LEN]; - - if (window == 0) { - PrintAndLog("needs a window"); - return 0; - } - if (window >= len) { - PrintAndLog("window must be smaller than trace (%d samples)", - len); - return 0; - } - - PrintAndLog("performing %d correlations", len - window); - - for (int i = 0; i < len - window; ++i) { - int sum = 0; - for (int j = 0; j < window; ++j) { - sum += (in[j]*in[i + j]) / 256; - } - CorrelBuffer[i] = sum; - } - //GraphTraceLen = GraphTraceLen - window; - memcpy(out, CorrelBuffer, len * sizeof (int)); - return 0; -} -int directionalThreshold(const int* in, int *out, size_t len, int8_t up, int8_t down) -{ - int lastValue = in[0]; - out[0] = 0; // Will be changed at the end, but init 0 as we adjust to last samples value if no threshold kicks in. - - for (int i = 1; i < len; ++i) { - // Apply first threshold to samples heading up - if (in[i] >= up && in[i] > lastValue) - { - lastValue = out[i]; // Buffer last value as we overwrite it. - out[i] = 1; - } - // Apply second threshold to samples heading down - else if (in[i] <= down && in[i] < lastValue) - { - lastValue = out[i]; // Buffer last value as we overwrite it. - out[i] = -1; - } - else - { - lastValue = out[i]; // Buffer last value as we overwrite it. - out[i] = out[i-1]; - } - } - out[0] = out[1]; // Align with first edited sample. - return 0; -} diff --git a/client/graph.h b/client/graph.h index e70efe46..d77db301 100644 --- a/client/graph.h +++ b/client/graph.h @@ -37,7 +37,4 @@ extern int GraphBuffer[MAX_GRAPH_TRACE_LEN]; extern int GraphTraceLen; extern int s_Buff[MAX_GRAPH_TRACE_LEN]; -int autoCorr(const int* in, int *out, size_t len, int window); -int directionalThreshold(const int* in, int *out, size_t len, int8_t up, int8_t down); - #endif diff --git a/client/proxgui.h b/client/proxgui.h index a6d8f24a..de6dd6c2 100644 --- a/client/proxgui.h +++ b/client/proxgui.h @@ -34,7 +34,9 @@ extern int offline; extern bool GridLocked; //Operations defined in data_operations -extern int autoCorr(const int* in, int *out, size_t len, int window); +//extern int autoCorr(const int* in, int *out, size_t len, int window); +extern int AskEdgeDetect(const int *in, int *out, int len, int threshold); +extern int AutoCorrelate(const int *in, int *out, size_t len, int window, bool SaveGrph, bool verbose); extern int directionalThreshold(const int* in, int *out, size_t len, int8_t up, int8_t down); extern void save_restoreGB(uint8_t saveOpt); diff --git a/client/proxguiqt.cpp b/client/proxguiqt.cpp index 05a048d8..c1fc7e12 100644 --- a/client/proxguiqt.cpp +++ b/client/proxguiqt.cpp @@ -109,7 +109,7 @@ void ProxWidget::applyOperation() { printf("ApplyOperation()"); save_restoreGB(1); - memcpy(GraphBuffer,s_Buff, sizeof(int) * GraphTraceLen); + memcpy(GraphBuffer, s_Buff, sizeof(int) * GraphTraceLen); RepaintGraphWindow(); } @@ -120,14 +120,23 @@ void ProxWidget::stickOperation() } void ProxWidget::vchange_autocorr(int v) { - autoCorr(GraphBuffer,s_Buff, GraphTraceLen, v); - printf("vchange_autocorr(%d)\n", v); + int ans; + ans = AutoCorrelate(GraphBuffer, s_Buff, GraphTraceLen, v, true, false); + printf("vchange_autocorr(w:%d): %d\n", v, ans); + RepaintGraphWindow(); +} +void ProxWidget::vchange_askedge(int v) +{ + int ans; + //extern int AskEdgeDetect(const int *in, int *out, int len, int threshold); + ans = AskEdgeDetect(GraphBuffer, s_Buff, GraphTraceLen, v); + printf("vchange_askedge(w:%d)\n", v); RepaintGraphWindow(); } void ProxWidget::vchange_dthr_up(int v) { int down = opsController->horizontalSlider_dirthr_down->value(); - directionalThreshold(GraphBuffer,s_Buff, GraphTraceLen, v, down); + directionalThreshold(GraphBuffer, s_Buff, GraphTraceLen, v, down); printf("vchange_dthr_up(%d)", v); RepaintGraphWindow(); @@ -161,6 +170,7 @@ ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) QObject::connect(opsController->horizontalSlider_window, SIGNAL(valueChanged(int)), this, SLOT(vchange_autocorr(int))); QObject::connect(opsController->horizontalSlider_dirthr_up, SIGNAL(valueChanged(int)), this, SLOT(vchange_dthr_up(int))); QObject::connect(opsController->horizontalSlider_dirthr_down, SIGNAL(valueChanged(int)), this, SLOT(vchange_dthr_down(int))); + QObject::connect(opsController->horizontalSlider_askedge, SIGNAL(valueChanged(int)), this, SLOT(vchange_askedge(int))); controlWidget->show(); @@ -178,7 +188,7 @@ ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) //layout->addWidget(slider); layout->addWidget(plot); setLayout(layout); - //printf("Proxwidget Constructor just set layout\r\n"); + printf("Proxwidget Constructor just set layout\r\n"); } diff --git a/client/proxguiqt.h b/client/proxguiqt.h index 794db2d7..fa1ba018 100644 --- a/client/proxguiqt.h +++ b/client/proxguiqt.h @@ -71,6 +71,7 @@ class ProxWidget : public QWidget void applyOperation(); void stickOperation(); void vchange_autocorr(int v); + void vchange_askedge(int v); void vchange_dthr_up(int v); void vchange_dthr_down(int v); }; diff --git a/client/ui/overlays.ui b/client/ui/overlays.ui index 8b7f85e5..7cc9043e 100644 --- a/client/ui/overlays.ui +++ b/client/ui/overlays.ui @@ -17,7 +17,7 @@ - 0 + 1 @@ -29,13 +29,6 @@ - - - - Window size - - - @@ -43,6 +36,13 @@ + + + + Window size + + + @@ -78,8 +78,60 @@ - Askdemod + AskEdge + + + + + 0 + + + + + Edge Jump Threshold + + + + + + + + + + + + + + + + 5 + + + 80 + + + 20 + + + Qt::Horizontal + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + @@ -174,7 +226,7 @@ - Sticky + Restore @@ -194,7 +246,7 @@ - TextLabel + @@ -211,8 +263,8 @@ setNum(int) - 29 - 90 + 46 + 118 597 @@ -227,8 +279,8 @@ setNum(int) - 153 - 84 + 170 + 118 161 @@ -243,8 +295,8 @@ setNum(int) - 53 - 92 + 70 + 118 68 @@ -259,8 +311,8 @@ setNum(int) - 184 - 161 + 201 + 185 149 @@ -268,5 +320,21 @@ + + horizontalSlider_askedge + valueChanged(int) + label_9 + setNum(int) + + + 149 + 102 + + + 250 + 70 + + + diff --git a/client/ui/ui_overlays.h b/client/ui/ui_overlays.h index 83aa3e6c..daa6192b 100644 --- a/client/ui/ui_overlays.h +++ b/client/ui/ui_overlays.h @@ -1,13 +1,13 @@ /******************************************************************************** -** Form generated from reading UI file 'overlaystQ7020.ui' +** Form generated from reading UI file 'overlays.ui' ** -** Created by: Qt User Interface Compiler version 4.8.6 +** Created by: Qt User Interface Compiler version 5.6.1 ** ** WARNING! All changes made in this file will be lost when recompiling UI file! ********************************************************************************/ -#ifndef OVERLAYSTQ7020_H -#define OVERLAYSTQ7020_H +#ifndef UI_OVERLAYS_H +#define UI_OVERLAYS_H #include #include @@ -34,11 +34,17 @@ public: QWidget *tab; QVBoxLayout *verticalLayout_2; QFormLayout *formLayout; - QLabel *label; QLabel *label_5; + QLabel *label; QSlider *horizontalSlider_window; QSpacerItem *verticalSpacer; QWidget *tab_3; + QVBoxLayout *verticalLayout_4; + QFormLayout *formLayout_4; + QLabel *label_8; + QLabel *label_9; + QSlider *horizontalSlider_askedge; + QSpacerItem *verticalSpacer_3; QWidget *tab_2; QVBoxLayout *verticalLayout; QFormLayout *formLayout_2; @@ -59,34 +65,34 @@ public: void setupUi(QWidget *Form) { if (Form->objectName().isEmpty()) - Form->setObjectName(QString::fromUtf8("Form")); + Form->setObjectName(QStringLiteral("Form")); Form->resize(614, 286); verticalLayout_3 = new QVBoxLayout(Form); - verticalLayout_3->setObjectName(QString::fromUtf8("verticalLayout_3")); + verticalLayout_3->setObjectName(QStringLiteral("verticalLayout_3")); tabWidget_overlays = new QTabWidget(Form); - tabWidget_overlays->setObjectName(QString::fromUtf8("tabWidget_overlays")); + tabWidget_overlays->setObjectName(QStringLiteral("tabWidget_overlays")); tab = new QWidget(); - tab->setObjectName(QString::fromUtf8("tab")); + tab->setObjectName(QStringLiteral("tab")); tab->setFocusPolicy(Qt::StrongFocus); verticalLayout_2 = new QVBoxLayout(tab); - verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2")); + verticalLayout_2->setObjectName(QStringLiteral("verticalLayout_2")); formLayout = new QFormLayout(); - formLayout->setObjectName(QString::fromUtf8("formLayout")); - label = new QLabel(tab); - label->setObjectName(QString::fromUtf8("label")); - - formLayout->setWidget(0, QFormLayout::LabelRole, label); - + formLayout->setObjectName(QStringLiteral("formLayout")); label_5 = new QLabel(tab); - label_5->setObjectName(QString::fromUtf8("label_5")); + label_5->setObjectName(QStringLiteral("label_5")); formLayout->setWidget(0, QFormLayout::FieldRole, label_5); + label = new QLabel(tab); + label->setObjectName(QStringLiteral("label")); + + formLayout->setWidget(0, QFormLayout::LabelRole, label); + verticalLayout_2->addLayout(formLayout); horizontalSlider_window = new QSlider(tab); - horizontalSlider_window->setObjectName(QString::fromUtf8("horizontalSlider_window")); + horizontalSlider_window->setObjectName(QStringLiteral("horizontalSlider_window")); horizontalSlider_window->setMinimum(10); horizontalSlider_window->setMaximum(10000); horizontalSlider_window->setValue(2000); @@ -100,21 +106,52 @@ public: tabWidget_overlays->addTab(tab, QString()); tab_3 = new QWidget(); - tab_3->setObjectName(QString::fromUtf8("tab_3")); + tab_3->setObjectName(QStringLiteral("tab_3")); + verticalLayout_4 = new QVBoxLayout(tab_3); + verticalLayout_4->setObjectName(QStringLiteral("verticalLayout_4")); + formLayout_4 = new QFormLayout(); + formLayout_4->setObjectName(QStringLiteral("formLayout_4")); + formLayout_4->setContentsMargins(-1, -1, -1, 0); + label_8 = new QLabel(tab_3); + label_8->setObjectName(QStringLiteral("label_8")); + + formLayout_4->setWidget(0, QFormLayout::LabelRole, label_8); + + label_9 = new QLabel(tab_3); + label_9->setObjectName(QStringLiteral("label_9")); + + formLayout_4->setWidget(0, QFormLayout::FieldRole, label_9); + + + verticalLayout_4->addLayout(formLayout_4); + + horizontalSlider_askedge = new QSlider(tab_3); + horizontalSlider_askedge->setObjectName(QStringLiteral("horizontalSlider_askedge")); + horizontalSlider_askedge->setMinimum(5); + horizontalSlider_askedge->setMaximum(80); + horizontalSlider_askedge->setValue(20); + horizontalSlider_askedge->setOrientation(Qt::Horizontal); + + verticalLayout_4->addWidget(horizontalSlider_askedge); + + verticalSpacer_3 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); + + verticalLayout_4->addItem(verticalSpacer_3); + tabWidget_overlays->addTab(tab_3, QString()); tab_2 = new QWidget(); - tab_2->setObjectName(QString::fromUtf8("tab_2")); + tab_2->setObjectName(QStringLiteral("tab_2")); verticalLayout = new QVBoxLayout(tab_2); - verticalLayout->setObjectName(QString::fromUtf8("verticalLayout")); + verticalLayout->setObjectName(QStringLiteral("verticalLayout")); formLayout_2 = new QFormLayout(); - formLayout_2->setObjectName(QString::fromUtf8("formLayout_2")); + formLayout_2->setObjectName(QStringLiteral("formLayout_2")); label_2 = new QLabel(tab_2); - label_2->setObjectName(QString::fromUtf8("label_2")); + label_2->setObjectName(QStringLiteral("label_2")); formLayout_2->setWidget(0, QFormLayout::LabelRole, label_2); label_6 = new QLabel(tab_2); - label_6->setObjectName(QString::fromUtf8("label_6")); + label_6->setObjectName(QStringLiteral("label_6")); formLayout_2->setWidget(0, QFormLayout::FieldRole, label_6); @@ -122,7 +159,7 @@ public: verticalLayout->addLayout(formLayout_2); horizontalSlider_dirthr_up = new QSlider(tab_2); - horizontalSlider_dirthr_up->setObjectName(QString::fromUtf8("horizontalSlider_dirthr_up")); + horizontalSlider_dirthr_up->setObjectName(QStringLiteral("horizontalSlider_dirthr_up")); horizontalSlider_dirthr_up->setMaximum(128); horizontalSlider_dirthr_up->setValue(20); horizontalSlider_dirthr_up->setOrientation(Qt::Horizontal); @@ -130,14 +167,14 @@ public: verticalLayout->addWidget(horizontalSlider_dirthr_up); formLayout_3 = new QFormLayout(); - formLayout_3->setObjectName(QString::fromUtf8("formLayout_3")); + formLayout_3->setObjectName(QStringLiteral("formLayout_3")); label_3 = new QLabel(tab_2); - label_3->setObjectName(QString::fromUtf8("label_3")); + label_3->setObjectName(QStringLiteral("label_3")); formLayout_3->setWidget(0, QFormLayout::LabelRole, label_3); label_7 = new QLabel(tab_2); - label_7->setObjectName(QString::fromUtf8("label_7")); + label_7->setObjectName(QStringLiteral("label_7")); formLayout_3->setWidget(0, QFormLayout::FieldRole, label_7); @@ -145,7 +182,7 @@ public: verticalLayout->addLayout(formLayout_3); horizontalSlider_dirthr_down = new QSlider(tab_2); - horizontalSlider_dirthr_down->setObjectName(QString::fromUtf8("horizontalSlider_dirthr_down")); + horizontalSlider_dirthr_down->setObjectName(QStringLiteral("horizontalSlider_dirthr_down")); horizontalSlider_dirthr_down->setMaximum(127); horizontalSlider_dirthr_down->setOrientation(Qt::Horizontal); @@ -160,14 +197,14 @@ public: verticalLayout_3->addWidget(tabWidget_overlays); horizontalLayout = new QHBoxLayout(); - horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); + horizontalLayout->setObjectName(QStringLiteral("horizontalLayout")); pushButton_apply = new QPushButton(Form); - pushButton_apply->setObjectName(QString::fromUtf8("pushButton_apply")); + pushButton_apply->setObjectName(QStringLiteral("pushButton_apply")); horizontalLayout->addWidget(pushButton_apply); pushButton_sticky = new QPushButton(Form); - pushButton_sticky->setObjectName(QString::fromUtf8("pushButton_sticky")); + pushButton_sticky->setObjectName(QStringLiteral("pushButton_sticky")); horizontalLayout->addWidget(pushButton_sticky); @@ -176,7 +213,7 @@ public: horizontalLayout->addItem(horizontalSpacer); label_4 = new QLabel(Form); - label_4->setObjectName(QString::fromUtf8("label_4")); + label_4->setObjectName(QStringLiteral("label_4")); horizontalLayout->addWidget(label_4); @@ -189,8 +226,9 @@ public: QObject::connect(horizontalSlider_window, SIGNAL(valueChanged(int)), label_5, SLOT(setNum(int))); QObject::connect(horizontalSlider_dirthr_up, SIGNAL(valueChanged(int)), label_6, SLOT(setNum(int))); QObject::connect(horizontalSlider_dirthr_down, SIGNAL(valueChanged(int)), label_7, SLOT(setNum(int))); + QObject::connect(horizontalSlider_askedge, SIGNAL(valueChanged(int)), label_9, SLOT(setNum(int))); - tabWidget_overlays->setCurrentIndex(0); + tabWidget_overlays->setCurrentIndex(1); QMetaObject::connectSlotsByName(Form); @@ -199,18 +237,20 @@ public: void retranslateUi(QWidget *Form) { Form->setWindowTitle(QApplication::translate("Form", "Overlays", 0)); - label->setText(QApplication::translate("Form", "Window size", 0)); label_5->setText(QString()); + label->setText(QApplication::translate("Form", "Window size", 0)); tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab), QApplication::translate("Form", "Autocorrelate", 0)); - tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab_3), QApplication::translate("Form", "Askdemod", 0)); + label_8->setText(QApplication::translate("Form", "Edge Jump Threshold", 0)); + label_9->setText(QString()); + tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab_3), QApplication::translate("Form", "AskEdge", 0)); label_2->setText(QApplication::translate("Form", "Up", 0)); label_6->setText(QString()); label_3->setText(QApplication::translate("Form", "Down", 0)); label_7->setText(QString()); tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab_2), QApplication::translate("Form", "Dirthreshold", 0)); pushButton_apply->setText(QApplication::translate("Form", "Apply", 0)); - pushButton_sticky->setText(QApplication::translate("Form", "Sticky", 0)); - label_4->setText(QApplication::translate("Form", "TextLabel", 0)); + pushButton_sticky->setText(QApplication::translate("Form", "Restore", 0)); + label_4->setText(QString()); } // retranslateUi }; @@ -221,4 +261,4 @@ namespace Ui { QT_END_NAMESPACE -#endif // OVERLAYSTQ7020_H +#endif // UI_OVERLAYS_H diff --git a/common/lfdemod.c b/common/lfdemod.c index 072bd120..be9d3613 100644 --- a/common/lfdemod.c +++ b/common/lfdemod.c @@ -1490,7 +1490,7 @@ size_t aggregate_bits(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, //by marshmellow (from holiman's base) // full fsk demod from GraphBuffer wave to decoded 1s and 0s (no mandemod) int fskdemod_ext(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *startIdx) { - if (justNoise(dest, *size)) return 0; + if (justNoise(dest, size)) return 0; // FSK demodulator size = fsk_wave_demod(dest, size, fchigh, fclow, startIdx); size = aggregate_bits(dest, size, rfLen, invert, fchigh, fclow, startIdx); From f516ff0895ca25cf29a8a3770c543efbf0345be3 Mon Sep 17 00:00:00 2001 From: marshmellow42 Date: Thu, 13 Apr 2017 17:16:34 -0400 Subject: [PATCH 06/17] a few notation fixes --- client/cmddata.c | 2 +- client/cmdlf.c | 6 +++--- client/cmdlfem4x.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client/cmddata.c b/client/cmddata.c index 5dcd87b6..8c2049ad 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -1069,7 +1069,7 @@ int CmdRawDemod(const char *Cmd) void setClockGrid(int clk, int offset) { g_DemodStartIdx = offset; g_DemodClock = clk; - PrintAndLog("demodoffset %d, clk %d",offset,clk); + if (g_debugMode) PrintAndLog("demodoffset %d, clk %d",offset,clk); if (offset > clk) offset %= clk; if (offset < 0) offset += clk; diff --git a/client/cmdlf.c b/client/cmdlf.c index 3c4319c7..5c479ae0 100644 --- a/client/cmdlf.c +++ b/client/cmdlf.c @@ -1066,7 +1066,7 @@ int CmdLFfind(const char *Cmd) ans=FSKrawDemod("",true); if (ans>0) { PrintAndLog("\nUnknown FSK Modulated Tag Found!"); - return CheckChipType(cmdp);; + return CheckChipType(cmdp); } } bool st = true; @@ -1074,14 +1074,14 @@ int CmdLFfind(const char *Cmd) if (ans>0) { PrintAndLog("\nUnknown ASK Modulated and Manchester encoded Tag Found!"); PrintAndLog("\nif it does not look right it could instead be ASK/Biphase - try 'data rawdemod ab'"); - return CheckChipType(cmdp);; + return CheckChipType(cmdp); } ans=CmdPSK1rawDemod(""); if (ans>0) { PrintAndLog("Possible unknown PSK1 Modulated Tag Found above!\n\nCould also be PSK2 - try 'data rawdemod p2'"); PrintAndLog("\nCould also be PSK3 - [currently not supported]"); PrintAndLog("\nCould also be NRZ - try 'data nrzrawdemod'"); - return CheckChipType(cmdp);; + return CheckChipType(cmdp); } ans = CheckChipType(cmdp); PrintAndLog("\nNo Data Found!\n"); diff --git a/client/cmdlfem4x.c b/client/cmdlfem4x.c index 6587afe8..66c4221a 100644 --- a/client/cmdlfem4x.c +++ b/client/cmdlfem4x.c @@ -705,7 +705,7 @@ bool EM4x05testDemodReadData(uint32_t *word, bool readCmd) { } setDemodBuf(DemodBuffer, 32, 0); - setClockGrid(0,0); + //setClockGrid(0,0); *word = bytebits_to_byteLSBF(DemodBuffer, 32); } From 1a3c006469f38deb037cd8f0d79555f2f564d784 Mon Sep 17 00:00:00 2001 From: marshmellow42 Date: Fri, 14 Apr 2017 09:53:36 -0400 Subject: [PATCH 07/17] maybe fixed loading/unloading bug. --- client/proxgui.cpp | 3 +- client/proxgui.h | 1 + client/proxguiqt.cpp | 80 ++++++++++++++++++++++++++++++++------------ client/proxguiqt.h | 24 +++++++++---- client/proxmark3.c | 19 ++++++----- client/ui.h | 1 + 6 files changed, 91 insertions(+), 37 deletions(-) diff --git a/client/proxgui.cpp b/client/proxgui.cpp index 12faab79..7dcb0da0 100644 --- a/client/proxgui.cpp +++ b/client/proxgui.cpp @@ -63,6 +63,7 @@ extern "C" void ExitGraphics(void) if (!gui) return; - delete gui; + gui->Exit(); + //delete gui; gui = NULL; } diff --git a/client/proxgui.h b/client/proxgui.h index de6dd6c2..846ac45d 100644 --- a/client/proxgui.h +++ b/client/proxgui.h @@ -45,6 +45,7 @@ extern uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN]; extern size_t DemodBufferLen; extern size_t g_DemodStartIdx; extern bool showDemod; +extern uint8_t g_debugMode; #ifdef __cplusplus } diff --git a/client/proxguiqt.cpp b/client/proxguiqt.cpp index c1541999..d81c8108 100644 --- a/client/proxguiqt.cpp +++ b/client/proxguiqt.cpp @@ -23,7 +23,6 @@ #include #include #include -#include "proxguiqt.h" #include "proxgui.h" #include //#include @@ -47,6 +46,11 @@ void ProxGuiQT::HideGraphWindow(void) emit HideGraphWindowSignal(); } +void ProxGuiQT::Exit(void) +{ + emit ExitSignal(); +} + void ProxGuiQT::_ShowGraphWindow(void) { if(!plotapp) @@ -74,6 +78,9 @@ void ProxGuiQT::_HideGraphWindow(void) plotwidget->hide(); } +void ProxGuiQT::_Exit(void) { + delete this; +} void ProxGuiQT::MainLoop() { plotapp = new QApplication(argc, argv); @@ -81,6 +88,7 @@ void ProxGuiQT::MainLoop() connect(this, SIGNAL(ShowGraphWindowSignal()), this, SLOT(_ShowGraphWindow())); connect(this, SIGNAL(RepaintGraphWindowSignal()), this, SLOT(_RepaintGraphWindow())); connect(this, SIGNAL(HideGraphWindowSignal()), this, SLOT(_HideGraphWindow())); + connect(this, SIGNAL(ExitSignal()), this, SLOT(_Exit())); plotapp->exec(); } @@ -92,12 +100,11 @@ ProxGuiQT::ProxGuiQT(int argc, char **argv) : plotapp(NULL), plotwidget(NULL), ProxGuiQT::~ProxGuiQT(void) { - if (plotwidget) { - //plotwidget->close(); - delete plotwidget; - plotwidget = NULL; - } - + //if (plotwidget) { + //plotwidget->destroy(true,true); + // delete plotwidget; + // plotwidget = NULL; + //} if (plotapp) { plotapp->quit(); delete plotapp; @@ -108,22 +115,21 @@ ProxGuiQT::~ProxGuiQT(void) //-------------------- void ProxWidget::applyOperation() { - printf("ApplyOperation()"); + //printf("ApplyOperation()"); save_restoreGB(1); memcpy(GraphBuffer, s_Buff, sizeof(int) * GraphTraceLen); RepaintGraphWindow(); - } void ProxWidget::stickOperation() { save_restoreGB(0); - printf("stickOperation()"); + //printf("stickOperation()"); } void ProxWidget::vchange_autocorr(int v) { int ans; ans = AutoCorrelate(GraphBuffer, s_Buff, GraphTraceLen, v, true, false); - printf("vchange_autocorr(w:%d): %d\n", v, ans); + if (g_debugMode) printf("vchange_autocorr(w:%d): %d\n", v, ans); RepaintGraphWindow(); } void ProxWidget::vchange_askedge(int v) @@ -131,20 +137,20 @@ void ProxWidget::vchange_askedge(int v) int ans; //extern int AskEdgeDetect(const int *in, int *out, int len, int threshold); ans = AskEdgeDetect(GraphBuffer, s_Buff, GraphTraceLen, v); - printf("vchange_askedge(w:%d)\n", v); + if (g_debugMode) printf("vchange_askedge(w:%d)%d\n", v, ans); RepaintGraphWindow(); } void ProxWidget::vchange_dthr_up(int v) { int down = opsController->horizontalSlider_dirthr_down->value(); directionalThreshold(GraphBuffer, s_Buff, GraphTraceLen, v, down); - printf("vchange_dthr_up(%d)", v); + //printf("vchange_dthr_up(%d)", v); RepaintGraphWindow(); } void ProxWidget::vchange_dthr_down(int v) { - printf("vchange_dthr_down(%d)", v); + //printf("vchange_dthr_down(%d)", v); int up = opsController->horizontalSlider_dirthr_up->value(); directionalThreshold(GraphBuffer,s_Buff, GraphTraceLen, v, up); RepaintGraphWindow(); @@ -157,7 +163,7 @@ ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) /** Setup the controller widget **/ - QWidget* controlWidget = new QWidget(); + controlWidget = new QWidget(); opsController = new Ui::Form(); opsController->setupUi(controlWidget); //Due to quirks in QT Designer, we need to fiddle a bit @@ -189,9 +195,43 @@ ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) //layout->addWidget(slider); layout->addWidget(plot); setLayout(layout); - printf("Proxwidget Constructor just set layout\r\n"); + //printf("Proxwidget Constructor just set layout\r\n"); } +// not 100% sure what i need in this block +// feel free to fix - marshmellow... +ProxWidget::~ProxWidget(void) +{ + if (controlWidget) { + controlWidget->close(); + delete controlWidget; + controlWidget = NULL; + } + + if (opsController) { + delete opsController; + opsController = NULL; + } + + if (plot) { + plot->close(); + delete plot; + plot = NULL; + } +} +void ProxWidget::closeEvent(QCloseEvent *event) +{ + event->ignore(); + this->hide(); +} +void ProxWidget::hideEvent(QHideEvent *event) { + controlWidget->hide(); + plot->hide(); +} +void ProxWidget::showEvent(QShowEvent *event) { + controlWidget->show(); + plot->show(); +} //----------- Plotting @@ -242,7 +282,7 @@ void Plot::PlotDemod(uint8_t *buffer, size_t len, QRect plotRect, QRect annotati // round down if (DemodStart-plotOffset > 0) BitStart = (int)(((DemodStart-plotOffset)+(PlotGridX-1))/PlotGridX)-1; first_delta_x += BitStart * PlotGridX; - if (BitStart > len) return; + if (BitStart > (int)len) return; int delta_x = 0; int v = 0; //printf("first_delta_x %i, grid_delta_x %i, DemodStart %i, BitStart %i\n",first_delta_x,grid_delta_x,DemodStart, BitStart); @@ -255,8 +295,8 @@ void Plot::PlotDemod(uint8_t *buffer, size_t len, QRect plotRect, QRect annotati penPath.moveTo(x, y); delta_x = 0; int clk = first_delta_x; - for(int i = BitStart; i < len && xCoordOf(delta_x+DemodStart, plotRect) < plotRect.right(); i++) { - for (int ii = 0; ii < (clk) && i < len && xCoordOf(DemodStart+delta_x+ii, plotRect) < plotRect.right() ; ii++ ) { + for(int i = BitStart; i < (int)len && xCoordOf(delta_x+DemodStart, plotRect) < plotRect.right(); i++) { + for (int ii = 0; ii < (clk) && i < (int)len && xCoordOf(DemodStart+delta_x+ii, plotRect) < plotRect.right() ; ii++ ) { x = xCoordOf(DemodStart+delta_x+ii, plotRect); v = buffer[i]*200-100; @@ -407,8 +447,6 @@ void Plot::plotGridLines(QPainter* painter,QRect r) void Plot::paintEvent(QPaintEvent *event) { QPainter painter(this); - //QPainterPath penPath, whitePath, greyPath, lightgreyPath, cursorAPath, cursorBPath, cursorCPath, cursorDPath; - //QRect r; QBrush brush(QColor(100, 255, 100)); QPen pen(QColor(100, 255, 100)); diff --git a/client/proxguiqt.h b/client/proxguiqt.h index fa1ba018..aa3b5b35 100644 --- a/client/proxguiqt.h +++ b/client/proxguiqt.h @@ -8,6 +8,9 @@ // GUI (QT) //----------------------------------------------------------------------------- +#ifndef PROXGUI_QT +#define PROXGUI_QT + #include #include #include @@ -51,19 +54,24 @@ class ProxGuiQT; */ class ProxWidget : public QWidget { - Q_OBJECT; + Q_OBJECT; //needed for slot/signal classes private: + ProxGuiQT *master; Plot *plot; Ui::Form *opsController; - ProxGuiQT *master; - + QWidget* controlWidget; + public: ProxWidget(QWidget *parent = 0, ProxGuiQT *master = NULL); + ~ProxWidget(void); + //OpsShow(void); - //protected: + protected: // void paintEvent(QPaintEvent *event); - // void closeEvent(QCloseEvent *event); + void closeEvent(QCloseEvent *event); + void showEvent(QShowEvent *event); + void hideEvent(QHideEvent *event); // void mouseMoveEvent(QMouseEvent *event); // void mousePressEvent(QMouseEvent *event) { mouseMoveEvent(event); } // void keyPressEvent(QKeyEvent *event); @@ -94,14 +102,16 @@ class ProxGuiQT : public QObject void RepaintGraphWindow(void); void HideGraphWindow(void); void MainLoop(void); - + void Exit(void); private slots: void _ShowGraphWindow(void); void _RepaintGraphWindow(void); void _HideGraphWindow(void); - + void _Exit(void); signals: void ShowGraphWindowSignal(void); void RepaintGraphWindowSignal(void); void HideGraphWindowSignal(void); + void ExitSignal(void); }; +#endif // PROXGUI_QT diff --git a/client/proxmark3.c b/client/proxmark3.c index 98f7880e..d00af5cc 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -102,7 +102,7 @@ static void *main_loop(void *targ) { struct receiver_arg rarg; char *cmd = NULL; pthread_t reader_thread; - + if (arg->usb_present == 1) { rarg.run = 1; pthread_create(&reader_thread, NULL, &uart_receiver, &rarg); @@ -175,13 +175,13 @@ static void *main_loop(void *targ) { rarg.run = 0; pthread_join(reader_thread, NULL); } - + + ExitGraphics(); + if (script_file) { fclose(script_file); script_file = NULL; } - - ExitGraphics(); pthread_exit(NULL); return NULL; } @@ -254,7 +254,7 @@ int main(int argc, char* argv[]) { .usb_present = 0, .script_cmds_file = NULL }; - pthread_t main_loop_threat; + pthread_t main_loop_thread; sp = uart_open(argv[1]); @@ -288,13 +288,16 @@ int main(int argc, char* argv[]) { // create a mutex to avoid interlacing print commands from our different threads pthread_mutex_init(&print_lock, NULL); + pthread_create(&main_loop_thread, NULL, &main_loop, &marg); - pthread_create(&main_loop_threat, NULL, &main_loop, &marg); + // build ui/graph forms on separate thread (killed on main_loop_thread); InitGraphics(argc, argv); - MainGraphics(); + //this won't return until ExitGraphics() is called - pthread_join(main_loop_threat, NULL); + //wait for thread to finish + pthread_join(main_loop_thread, NULL); + // Clean up the port if (offline == 0) { diff --git a/client/ui.h b/client/ui.h index 5aaac17e..4049033d 100644 --- a/client/ui.h +++ b/client/ui.h @@ -12,6 +12,7 @@ #define UI_H__ #include +#include void ShowGui(void); void HideGraphWindow(void); From 27882d378be348c9bf68b741f993de0ea2001ab8 Mon Sep 17 00:00:00 2001 From: marshmellow42 Date: Fri, 14 Apr 2017 10:31:00 -0400 Subject: [PATCH 08/17] add uic make ui_overlays.h to makefile --- client/Makefile | 8 +++++++- client/ui/ui_overlays.h | 32 ++++++++++++++++---------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/client/Makefile b/client/Makefile index cea981f9..2f853093 100644 --- a/client/Makefile +++ b/client/Makefile @@ -40,11 +40,13 @@ endif QTINCLUDES = $(shell pkg-config --cflags Qt5Core Qt5Widgets 2>/dev/null) QTLDLIBS = $(shell pkg-config --libs Qt5Core Qt5Widgets 2>/dev/null) MOC = $(shell pkg-config --variable=host_bins Qt5Core)/moc +UIC = $(shell pkg-config --variable=host_bins Qt5Core)/uic ifeq ($(QTINCLUDES), ) # if Qt5 not found Check for correctly configured Qt4 QTINCLUDES = $(shell pkg-config --cflags QtCore QtGui 2>/dev/null) QTLDLIBS = $(shell pkg-config --libs QtCore QtGui 2>/dev/null) MOC = $(shell pkg-config --variable=moc_location QtCore) + UIC = $(shell pkg-config --variable=uic_location QtCore) endif ifeq ($(QTINCLUDES), ) # if both pkg-config commands failed, search in common places @@ -56,6 +58,7 @@ ifeq ($(QTINCLUDES), ) QTLDLIBS = -L$(QTDIR)/lib -lQt5Widgets -lQt5Gui -lQt5Core endif MOC = $(QTDIR)/bin/moc + UIC = $(QTDIR)/bin/uic endif endif @@ -159,7 +162,7 @@ ZLIBOBJS = $(ZLIBSRCS:%.c=$(OBJDIR)/%.o) BINS = proxmark3 flasher fpga_compress WINBINS = $(patsubst %, %.exe, $(BINS)) -CLEAN = $(BINS) $(WINBINS) $(COREOBJS) $(CMDOBJS) $(ZLIBOBJS) $(QTGUIOBJS) $(OBJDIR)/*.o *.moc.cpp +CLEAN = $(BINS) $(WINBINS) $(COREOBJS) $(CMDOBJS) $(ZLIBOBJS) $(QTGUIOBJS) $(OBJDIR)/*.o *.moc.cpp ./ui/ui_overlays.h all: lua_build $(BINS) @@ -179,6 +182,9 @@ fpga_compress: $(OBJDIR)/fpga_compress.o $(ZLIBOBJS) proxguiqt.moc.cpp: proxguiqt.h $(MOC) -o$@ $^ +ui/ui_overlays.h: ./ui/overlays.ui + $(UIC) $^ > $@ + lualibs/usb_cmd.lua: ../include/usb_cmd.h awk -f usb_cmd_h2lua.awk $^ > $@ diff --git a/client/ui/ui_overlays.h b/client/ui/ui_overlays.h index daa6192b..76003fc1 100644 --- a/client/ui/ui_overlays.h +++ b/client/ui/ui_overlays.h @@ -6,23 +6,23 @@ ** WARNING! All changes made in this file will be lost when recompiling UI file! ********************************************************************************/ -#ifndef UI_OVERLAYS_H -#define UI_OVERLAYS_H +#ifndef OVERLAYS_H +#define OVERLAYS_H #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include QT_BEGIN_NAMESPACE @@ -261,4 +261,4 @@ namespace Ui { QT_END_NAMESPACE -#endif // UI_OVERLAYS_H +#endif // OVERLAYS_H From 2c441f573c32b11e5764b3bfb70b64e289314267 Mon Sep 17 00:00:00 2001 From: marshmellow42 Date: Sat, 15 Apr 2017 13:12:56 -0400 Subject: [PATCH 09/17] attempt ui_overlays.h qt4 version --- client/ui/ui_overlays.h | 106 ++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/client/ui/ui_overlays.h b/client/ui/ui_overlays.h index 76003fc1..a0dc3223 100644 --- a/client/ui/ui_overlays.h +++ b/client/ui/ui_overlays.h @@ -1,7 +1,7 @@ /******************************************************************************** ** Form generated from reading UI file 'overlays.ui' ** -** Created by: Qt User Interface Compiler version 5.6.1 +** Created by: Qt User Interface Compiler version 4.8.6 ** ** WARNING! All changes made in this file will be lost when recompiling UI file! ********************************************************************************/ @@ -10,19 +10,19 @@ #define OVERLAYS_H #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include QT_BEGIN_NAMESPACE @@ -65,26 +65,26 @@ public: void setupUi(QWidget *Form) { if (Form->objectName().isEmpty()) - Form->setObjectName(QStringLiteral("Form")); + Form->setObjectName(QString::fromUtf8("Form")); Form->resize(614, 286); verticalLayout_3 = new QVBoxLayout(Form); - verticalLayout_3->setObjectName(QStringLiteral("verticalLayout_3")); + verticalLayout_3->setObjectName(QString::fromUtf8("verticalLayout_3")); tabWidget_overlays = new QTabWidget(Form); - tabWidget_overlays->setObjectName(QStringLiteral("tabWidget_overlays")); + tabWidget_overlays->setObjectName(QString::fromUtf8("tabWidget_overlays")); tab = new QWidget(); - tab->setObjectName(QStringLiteral("tab")); + tab->setObjectName(QString::fromUtf8("tab")); tab->setFocusPolicy(Qt::StrongFocus); verticalLayout_2 = new QVBoxLayout(tab); - verticalLayout_2->setObjectName(QStringLiteral("verticalLayout_2")); + verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2")); formLayout = new QFormLayout(); - formLayout->setObjectName(QStringLiteral("formLayout")); + formLayout->setObjectName(QString::fromUtf8("formLayout")); label_5 = new QLabel(tab); - label_5->setObjectName(QStringLiteral("label_5")); + label_5->setObjectName(QString::fromUtf8("label_5")); formLayout->setWidget(0, QFormLayout::FieldRole, label_5); label = new QLabel(tab); - label->setObjectName(QStringLiteral("label")); + label->setObjectName(QString::fromUtf8("label")); formLayout->setWidget(0, QFormLayout::LabelRole, label); @@ -92,7 +92,7 @@ public: verticalLayout_2->addLayout(formLayout); horizontalSlider_window = new QSlider(tab); - horizontalSlider_window->setObjectName(QStringLiteral("horizontalSlider_window")); + horizontalSlider_window->setObjectName(QString::fromUtf8("horizontalSlider_window")); horizontalSlider_window->setMinimum(10); horizontalSlider_window->setMaximum(10000); horizontalSlider_window->setValue(2000); @@ -106,19 +106,19 @@ public: tabWidget_overlays->addTab(tab, QString()); tab_3 = new QWidget(); - tab_3->setObjectName(QStringLiteral("tab_3")); + tab_3->setObjectName(QString::fromUtf8("tab_3")); verticalLayout_4 = new QVBoxLayout(tab_3); - verticalLayout_4->setObjectName(QStringLiteral("verticalLayout_4")); + verticalLayout_4->setObjectName(QString::fromUtf8("verticalLayout_4")); formLayout_4 = new QFormLayout(); - formLayout_4->setObjectName(QStringLiteral("formLayout_4")); + formLayout_4->setObjectName(QString::fromUtf8("formLayout_4")); formLayout_4->setContentsMargins(-1, -1, -1, 0); label_8 = new QLabel(tab_3); - label_8->setObjectName(QStringLiteral("label_8")); + label_8->setObjectName(QString::fromUtf8("label_8")); formLayout_4->setWidget(0, QFormLayout::LabelRole, label_8); label_9 = new QLabel(tab_3); - label_9->setObjectName(QStringLiteral("label_9")); + label_9->setObjectName(QString::fromUtf8("label_9")); formLayout_4->setWidget(0, QFormLayout::FieldRole, label_9); @@ -126,7 +126,7 @@ public: verticalLayout_4->addLayout(formLayout_4); horizontalSlider_askedge = new QSlider(tab_3); - horizontalSlider_askedge->setObjectName(QStringLiteral("horizontalSlider_askedge")); + horizontalSlider_askedge->setObjectName(QString::fromUtf8("horizontalSlider_askedge")); horizontalSlider_askedge->setMinimum(5); horizontalSlider_askedge->setMaximum(80); horizontalSlider_askedge->setValue(20); @@ -140,18 +140,18 @@ public: tabWidget_overlays->addTab(tab_3, QString()); tab_2 = new QWidget(); - tab_2->setObjectName(QStringLiteral("tab_2")); + tab_2->setObjectName(QString::fromUtf8("tab_2")); verticalLayout = new QVBoxLayout(tab_2); - verticalLayout->setObjectName(QStringLiteral("verticalLayout")); + verticalLayout->setObjectName(QString::fromUtf8("verticalLayout")); formLayout_2 = new QFormLayout(); - formLayout_2->setObjectName(QStringLiteral("formLayout_2")); + formLayout_2->setObjectName(QString::fromUtf8("formLayout_2")); label_2 = new QLabel(tab_2); - label_2->setObjectName(QStringLiteral("label_2")); + label_2->setObjectName(QString::fromUtf8("label_2")); formLayout_2->setWidget(0, QFormLayout::LabelRole, label_2); label_6 = new QLabel(tab_2); - label_6->setObjectName(QStringLiteral("label_6")); + label_6->setObjectName(QString::fromUtf8("label_6")); formLayout_2->setWidget(0, QFormLayout::FieldRole, label_6); @@ -159,7 +159,7 @@ public: verticalLayout->addLayout(formLayout_2); horizontalSlider_dirthr_up = new QSlider(tab_2); - horizontalSlider_dirthr_up->setObjectName(QStringLiteral("horizontalSlider_dirthr_up")); + horizontalSlider_dirthr_up->setObjectName(QString::fromUtf8("horizontalSlider_dirthr_up")); horizontalSlider_dirthr_up->setMaximum(128); horizontalSlider_dirthr_up->setValue(20); horizontalSlider_dirthr_up->setOrientation(Qt::Horizontal); @@ -167,14 +167,14 @@ public: verticalLayout->addWidget(horizontalSlider_dirthr_up); formLayout_3 = new QFormLayout(); - formLayout_3->setObjectName(QStringLiteral("formLayout_3")); + formLayout_3->setObjectName(QString::fromUtf8("formLayout_3")); label_3 = new QLabel(tab_2); - label_3->setObjectName(QStringLiteral("label_3")); + label_3->setObjectName(QString::fromUtf8("label_3")); formLayout_3->setWidget(0, QFormLayout::LabelRole, label_3); label_7 = new QLabel(tab_2); - label_7->setObjectName(QStringLiteral("label_7")); + label_7->setObjectName(QString::fromUtf8("label_7")); formLayout_3->setWidget(0, QFormLayout::FieldRole, label_7); @@ -182,7 +182,7 @@ public: verticalLayout->addLayout(formLayout_3); horizontalSlider_dirthr_down = new QSlider(tab_2); - horizontalSlider_dirthr_down->setObjectName(QStringLiteral("horizontalSlider_dirthr_down")); + horizontalSlider_dirthr_down->setObjectName(QString::fromUtf8("horizontalSlider_dirthr_down")); horizontalSlider_dirthr_down->setMaximum(127); horizontalSlider_dirthr_down->setOrientation(Qt::Horizontal); @@ -197,14 +197,14 @@ public: verticalLayout_3->addWidget(tabWidget_overlays); horizontalLayout = new QHBoxLayout(); - horizontalLayout->setObjectName(QStringLiteral("horizontalLayout")); + horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); pushButton_apply = new QPushButton(Form); - pushButton_apply->setObjectName(QStringLiteral("pushButton_apply")); + pushButton_apply->setObjectName(QString::fromUtf8("pushButton_apply")); horizontalLayout->addWidget(pushButton_apply); pushButton_sticky = new QPushButton(Form); - pushButton_sticky->setObjectName(QStringLiteral("pushButton_sticky")); + pushButton_sticky->setObjectName(QString::fromUtf8("pushButton_sticky")); horizontalLayout->addWidget(pushButton_sticky); @@ -213,7 +213,7 @@ public: horizontalLayout->addItem(horizontalSpacer); label_4 = new QLabel(Form); - label_4->setObjectName(QStringLiteral("label_4")); + label_4->setObjectName(QString::fromUtf8("label_4")); horizontalLayout->addWidget(label_4); @@ -236,20 +236,20 @@ public: void retranslateUi(QWidget *Form) { - Form->setWindowTitle(QApplication::translate("Form", "Overlays", 0)); + Form->setWindowTitle(QApplication::translate("Form", "Overlays", 0, QApplication::UnicodeUTF8)); label_5->setText(QString()); - label->setText(QApplication::translate("Form", "Window size", 0)); - tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab), QApplication::translate("Form", "Autocorrelate", 0)); - label_8->setText(QApplication::translate("Form", "Edge Jump Threshold", 0)); + label->setText(QApplication::translate("Form", "Window size", 0, QApplication::UnicodeUTF8)); + tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab), QApplication::translate("Form", "Autocorrelate", 0, QApplication::UnicodeUTF8)); + label_8->setText(QApplication::translate("Form", "Edge Jump Threshold", 0, QApplication::UnicodeUTF8)); label_9->setText(QString()); - tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab_3), QApplication::translate("Form", "AskEdge", 0)); - label_2->setText(QApplication::translate("Form", "Up", 0)); + tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab_3), QApplication::translate("Form", "AskEdge", 0, QApplication::UnicodeUTF8)); + label_2->setText(QApplication::translate("Form", "Up", 0, QApplication::UnicodeUTF8)); label_6->setText(QString()); - label_3->setText(QApplication::translate("Form", "Down", 0)); + label_3->setText(QApplication::translate("Form", "Down", 0, QApplication::UnicodeUTF8)); label_7->setText(QString()); - tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab_2), QApplication::translate("Form", "Dirthreshold", 0)); - pushButton_apply->setText(QApplication::translate("Form", "Apply", 0)); - pushButton_sticky->setText(QApplication::translate("Form", "Restore", 0)); + tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab_2), QApplication::translate("Form", "Dirthreshold", 0, QApplication::UnicodeUTF8)); + pushButton_apply->setText(QApplication::translate("Form", "Apply", 0, QApplication::UnicodeUTF8)); + pushButton_sticky->setText(QApplication::translate("Form", "Restore", 0, QApplication::UnicodeUTF8)); label_4->setText(QString()); } // retranslateUi From b760f0ffd8358bbea7e0a5c24a576ca8efdeda44 Mon Sep 17 00:00:00 2001 From: marshmellow42 Date: Sat, 15 Apr 2017 13:40:49 -0400 Subject: [PATCH 10/17] cannot seem to get uic to work for ... ... different qt versions in the make file correctly... so, make the ui_overlays.h file version generic. maybe... --- client/Makefile | 8 ++++--- client/ui/ui_overlays.h | 46 ++++++++++++++++++++--------------------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/client/Makefile b/client/Makefile index 2f853093..82697612 100644 --- a/client/Makefile +++ b/client/Makefile @@ -162,7 +162,8 @@ ZLIBOBJS = $(ZLIBSRCS:%.c=$(OBJDIR)/%.o) BINS = proxmark3 flasher fpga_compress WINBINS = $(patsubst %, %.exe, $(BINS)) -CLEAN = $(BINS) $(WINBINS) $(COREOBJS) $(CMDOBJS) $(ZLIBOBJS) $(QTGUIOBJS) $(OBJDIR)/*.o *.moc.cpp ./ui/ui_overlays.h +CLEAN = $(BINS) $(WINBINS) $(COREOBJS) $(CMDOBJS) $(ZLIBOBJS) $(QTGUIOBJS) $(OBJDIR)/*.o *.moc.cpp +#./ui/ui_overlays.h all: lua_build $(BINS) @@ -182,8 +183,9 @@ fpga_compress: $(OBJDIR)/fpga_compress.o $(ZLIBOBJS) proxguiqt.moc.cpp: proxguiqt.h $(MOC) -o$@ $^ -ui/ui_overlays.h: ./ui/overlays.ui - $(UIC) $^ > $@ +#cannot seem to get this to work accross qt versions... +#ui/ui_overlays.h: ./ui/overlays.ui +# $(UIC) $^ > $@ lualibs/usb_cmd.lua: ../include/usb_cmd.h awk -f usb_cmd_h2lua.awk $^ > $@ diff --git a/client/ui/ui_overlays.h b/client/ui/ui_overlays.h index a0dc3223..ff0665e5 100644 --- a/client/ui/ui_overlays.h +++ b/client/ui/ui_overlays.h @@ -10,19 +10,19 @@ #define OVERLAYS_H #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include QT_BEGIN_NAMESPACE @@ -236,20 +236,20 @@ public: void retranslateUi(QWidget *Form) { - Form->setWindowTitle(QApplication::translate("Form", "Overlays", 0, QApplication::UnicodeUTF8)); + Form->setWindowTitle(QApplication::translate("Form", "Overlays", 0)); label_5->setText(QString()); - label->setText(QApplication::translate("Form", "Window size", 0, QApplication::UnicodeUTF8)); - tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab), QApplication::translate("Form", "Autocorrelate", 0, QApplication::UnicodeUTF8)); - label_8->setText(QApplication::translate("Form", "Edge Jump Threshold", 0, QApplication::UnicodeUTF8)); + label->setText(QApplication::translate("Form", "Window size", 0)); + tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab), QApplication::translate("Form", "Autocorrelate", 0)); + label_8->setText(QApplication::translate("Form", "Edge Jump Threshold", 0)); label_9->setText(QString()); - tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab_3), QApplication::translate("Form", "AskEdge", 0, QApplication::UnicodeUTF8)); - label_2->setText(QApplication::translate("Form", "Up", 0, QApplication::UnicodeUTF8)); + tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab_3), QApplication::translate("Form", "AskEdge", 0)); + label_2->setText(QApplication::translate("Form", "Up", 0)); label_6->setText(QString()); - label_3->setText(QApplication::translate("Form", "Down", 0, QApplication::UnicodeUTF8)); + label_3->setText(QApplication::translate("Form", "Down", 0)); label_7->setText(QString()); - tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab_2), QApplication::translate("Form", "Dirthreshold", 0, QApplication::UnicodeUTF8)); - pushButton_apply->setText(QApplication::translate("Form", "Apply", 0, QApplication::UnicodeUTF8)); - pushButton_sticky->setText(QApplication::translate("Form", "Restore", 0, QApplication::UnicodeUTF8)); + tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab_2), QApplication::translate("Form", "Dirthreshold", 0)); + pushButton_apply->setText(QApplication::translate("Form", "Apply", 0)); + pushButton_sticky->setText(QApplication::translate("Form", "Restore", 0)); label_4->setText(QString()); } // retranslateUi From 1c70664ae75332e17466e8d7bcba718e406da36c Mon Sep 17 00:00:00 2001 From: marshmellow42 Date: Sat, 15 Apr 2017 16:18:54 -0400 Subject: [PATCH 11/17] finish FSK graph index changes --- armsrc/lfops.c | 10 ++++++---- client/cmddata.c | 8 +++++++- client/cmdlfawid.c | 5 +++-- client/cmdlfhid.c | 5 +++-- client/cmdlfio.c | 5 +++-- client/cmdlfparadox.c | 5 +++-- client/cmdlfpyramid.c | 5 +++-- common/lfdemod.c | 31 +++++++++++++------------------ common/lfdemod.h | 13 ++++++------- 9 files changed, 47 insertions(+), 40 deletions(-) diff --git a/armsrc/lfops.c b/armsrc/lfops.c index a3f7a02f..566ba1d4 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -769,6 +769,7 @@ void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol) size_t size; uint32_t hi2=0, hi=0, lo=0; int idx=0; + int dummyIdx = 0; // Configure to go in 125Khz listen mode LFSetupFPGAForADC(95, true); @@ -784,7 +785,7 @@ void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol) // FSK demodulator //size = sizeOfBigBuff; //variable size will change after demod so re initialize it before use size = 50*128*2; //big enough to catch 2 sequences of largest format - idx = HIDdemodFSK(dest, &size, &hi2, &hi, &lo); + idx = HIDdemodFSK(dest, &size, &hi2, &hi, &lo, &dummyIdx); if (idx>0 && lo>0 && (size==96 || size==192)){ // go over previously decoded manchester data and decode into usable tag ID @@ -861,7 +862,7 @@ void CmdAWIDdemodFSK(int findone, int *high, int *low, int ledcontrol) { uint8_t *dest = BigBuf_get_addr(); size_t size; - int idx=0; + int idx=0, dummyIdx=0; //clear read buffer BigBuf_Clear_keep_EM(); // Configure to go in 125Khz listen mode @@ -875,7 +876,7 @@ void CmdAWIDdemodFSK(int findone, int *high, int *low, int ledcontrol) DoAcquisition_default(-1,true); // FSK demodulator size = 50*128*2; //big enough to catch 2 sequences of largest format - idx = AWIDdemodFSK(dest, &size); + idx = AWIDdemodFSK(dest, &size, &dummyIdx); if (idx<=0 || size!=96) continue; // Index map @@ -1017,6 +1018,7 @@ void CmdIOdemodFSK(int findone, int *high, int *low, int ledcontrol) uint8_t version=0; uint8_t facilitycode=0; uint16_t number=0; + int dummyIdx=0; //clear read buffer BigBuf_Clear_keep_EM(); // Configure to go in 125Khz listen mode @@ -1028,7 +1030,7 @@ void CmdIOdemodFSK(int findone, int *high, int *low, int ledcontrol) DoAcquisition_default(-1,true); //fskdemod and get start index WDT_HIT(); - idx = IOdemodFSK(dest, BigBuf_max_traceLen()); + idx = IOdemodFSK(dest, BigBuf_max_traceLen(), &dummyIdx); if (idx<0) continue; //valid tag found diff --git a/client/cmddata.c b/client/cmddata.c index e291c924..87c54231 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -68,15 +68,21 @@ void save_restoreDB(uint8_t saveOpt) static uint8_t SavedDB[MAX_DEMOD_BUF_LEN]; static size_t SavedDBlen; static bool DB_Saved = false; + static int savedDemodStartIdx = 0; + static int savedDemodClock = 0; if (saveOpt==1) { //save memcpy(SavedDB, DemodBuffer, sizeof(DemodBuffer)); SavedDBlen = DemodBufferLen; DB_Saved=true; + savedDemodStartIdx = g_DemodStartIdx; + savedDemodClock = g_DemodClock; } else if (DB_Saved) { //restore memcpy(DemodBuffer, SavedDB, sizeof(DemodBuffer)); DemodBufferLen = SavedDBlen; + g_DemodClock = savedDemodClock; + g_DemodStartIdx = savedDemodStartIdx; } return; } @@ -803,7 +809,7 @@ int FSKrawDemod(const char *Cmd, bool verbose) if (!rfLen) rfLen = 50; } int startIdx = 0; - int size = fskdemod_ext(BitStream, BitLen, rfLen, invert, fchigh, fclow, &startIdx); + int size = fskdemod(BitStream, BitLen, rfLen, invert, fchigh, fclow, &startIdx); if (size > 0) { setDemodBuf(BitStream,size,0); setClockGrid(rfLen, startIdx); diff --git a/client/cmdlfawid.c b/client/cmdlfawid.c index 7f0b9910..141ba172 100644 --- a/client/cmdlfawid.c +++ b/client/cmdlfawid.c @@ -88,8 +88,9 @@ int CmdFSKdemodAWID(const char *Cmd) size_t size = getFromGraphBuf(BitStream); if (size==0) return 0; + int waveIdx = 0; //get binary from fsk wave - int idx = AWIDdemodFSK(BitStream, &size); + int idx = AWIDdemodFSK(BitStream, &size, &waveIdx); if (idx<=0){ if (g_debugMode){ if (idx == -1) @@ -126,7 +127,7 @@ int CmdFSKdemodAWID(const char *Cmd) uint32_t rawHi = bytebits_to_byte(BitStream+idx+32,32); uint32_t rawHi2 = bytebits_to_byte(BitStream+idx,32); setDemodBuf(BitStream,96,idx); - setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock)); + setClockGrid(50, waveIdx + (idx*50)); size = removeParity(BitStream, idx+8, 4, 1, 88); if (size != 66){ diff --git a/client/cmdlfhid.c b/client/cmdlfhid.c index a9693fb2..fd8e2148 100644 --- a/client/cmdlfhid.c +++ b/client/cmdlfhid.c @@ -32,7 +32,8 @@ int CmdFSKdemodHID(const char *Cmd) size_t BitLen = getFromGraphBuf(BitStream); if (BitLen==0) return 0; //get binary from fsk wave - int idx = HIDdemodFSK(BitStream,&BitLen,&hi2,&hi,&lo); + int waveIdx = 0; + int idx = HIDdemodFSK(BitStream,&BitLen,&hi2,&hi,&lo, &waveIdx); if (idx<0){ if (g_debugMode){ if (idx==-1){ @@ -99,7 +100,7 @@ int CmdFSKdemodHID(const char *Cmd) (unsigned int) fmtLen, (unsigned int) fc, (unsigned int) cardnum); } setDemodBuf(BitStream,BitLen,idx); - setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock)); + setClockGrid(50, waveIdx + (idx*50)); if (g_debugMode){ PrintAndLog("DEBUG: idx: %d, Len: %d, Printing Demod Buffer:", idx, BitLen); printDemodBuff(); diff --git a/client/cmdlfio.c b/client/cmdlfio.c index be8cf25e..c71928ec 100644 --- a/client/cmdlfio.c +++ b/client/cmdlfio.c @@ -53,8 +53,9 @@ int CmdFSKdemodIO(const char *Cmd) size_t BitLen = getFromGraphBuf(BitStream); if (BitLen==0) return 0; + int waveIdx = 0; //get binary from fsk wave - idx = IOdemodFSK(BitStream,BitLen); + idx = IOdemodFSK(BitStream,BitLen, &waveIdx); if (idx<0){ if (g_debugMode){ if (idx==-1){ @@ -119,7 +120,7 @@ int CmdFSKdemodIO(const char *Cmd) PrintAndLog("IO Prox XSF(%02d)%02x:%05d (%08x%08x) [%02x %s]",version,facilitycode,number,code,code2, crc, crcStr); setDemodBuf(BitStream,64,idx); - setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock)); + setClockGrid(64, waveIdx + (idx*64)); if (g_debugMode){ PrintAndLog("DEBUG: idx: %d, Len: %d, Printing demod buffer:",idx,64); diff --git a/client/cmdlfparadox.c b/client/cmdlfparadox.c index 6582eb35..e918c7fe 100644 --- a/client/cmdlfparadox.c +++ b/client/cmdlfparadox.c @@ -32,8 +32,9 @@ int CmdFSKdemodParadox(const char *Cmd) uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0}; size_t BitLen = getFromGraphBuf(BitStream); if (BitLen==0) return 0; + int waveIdx=0; //get binary from fsk wave - int idx = ParadoxdemodFSK(BitStream,&BitLen,&hi2,&hi,&lo); + int idx = ParadoxdemodFSK(BitStream,&BitLen,&hi2,&hi,&lo,&waveIdx); if (idx<0){ if (g_debugMode){ if (idx==-1){ @@ -63,7 +64,7 @@ int CmdFSKdemodParadox(const char *Cmd) PrintAndLog("Paradox TAG ID: %x%08x - FC: %d - Card: %d - Checksum: %02x - RAW: %08x%08x%08x", hi>>10, (hi & 0x3)<<26 | (lo>>10), fc, cardnum, (lo>>2) & 0xFF, rawHi2, rawHi, rawLo); setDemodBuf(BitStream,BitLen,idx); - setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock)); + setClockGrid(50, waveIdx + (idx*50)); if (g_debugMode){ PrintAndLog("DEBUG: idx: %d, len: %d, Printing Demod Buffer:", idx, BitLen); printDemodBuff(); diff --git a/client/cmdlfpyramid.c b/client/cmdlfpyramid.c index c7a6cb93..366889f3 100644 --- a/client/cmdlfpyramid.c +++ b/client/cmdlfpyramid.c @@ -96,8 +96,9 @@ int CmdFSKdemodPyramid(const char *Cmd) size_t size = getFromGraphBuf(BitStream); if (size==0) return 0; + int waveIdx=0; //get binary from fsk wave - int idx = PyramiddemodFSK(BitStream, &size); + int idx = PyramiddemodFSK(BitStream, &size, &waveIdx); if (idx < 0){ if (g_debugMode){ if (idx == -5) @@ -152,7 +153,7 @@ int CmdFSKdemodPyramid(const char *Cmd) uint32_t rawHi2 = bytebits_to_byte(BitStream+idx+32,32); uint32_t rawHi3 = bytebits_to_byte(BitStream+idx,32); setDemodBuf(BitStream,128,idx); - setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock)); + setClockGrid(50, waveIdx + (idx*50)); size = removeParity(BitStream, idx+8, 8, 1, 120); if (size != 105){ diff --git a/common/lfdemod.c b/common/lfdemod.c index be9d3613..d2e0fca4 100644 --- a/common/lfdemod.c +++ b/common/lfdemod.c @@ -1489,7 +1489,7 @@ size_t aggregate_bits(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, //by marshmellow (from holiman's base) // full fsk demod from GraphBuffer wave to decoded 1s and 0s (no mandemod) -int fskdemod_ext(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *startIdx) { +int fskdemod(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *startIdx) { if (justNoise(dest, size)) return 0; // FSK demodulator size = fsk_wave_demod(dest, size, fchigh, fclow, startIdx); @@ -1497,11 +1497,6 @@ int fskdemod_ext(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint return size; } -int fskdemod(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow) { - int startIdx=0; - return fskdemod_ext(dest, size, rfLen, invert, fchigh, fclow, &startIdx); -} - // by marshmellow // convert psk1 demod to psk2 demod // only transition waves are 1s @@ -1628,12 +1623,12 @@ int pskRawDemod(uint8_t dest[], size_t *size, int *clock, int *invert) { // by marshmellow // FSK Demod then try to locate an AWID ID -int AWIDdemodFSK(uint8_t *dest, size_t *size) { +int AWIDdemodFSK(uint8_t *dest, size_t *size, int *waveStartIdx) { //make sure buffer has enough data if (*size < 96*50) return -1; // FSK demodulator - *size = fskdemod(dest, *size, 50, 1, 10, 8); // fsk2a RF/50 + *size = fskdemod(dest, *size, 50, 1, 10, 8, waveStartIdx); // fsk2a RF/50 if (*size < 96) return -3; //did we get a good demod? uint8_t preamble[] = {0,0,0,0,0,0,0,1}; @@ -1715,10 +1710,10 @@ int gProxII_Demod(uint8_t BitStream[], size_t *size) { } // loop to get raw HID waveform then FSK demodulate the TAG ID from it -int HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo) { +int HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx) { size_t numStart=0, size2=*size, startIdx=0; - // FSK demodulator - *size = fskdemod(dest, size2,50,1,10,8); //fsk2a + // FSK demodulator fsk2a so invert and fc/10/8 + *size = fskdemod(dest, size2, 50, 1, 10, 8, waveStartIdx); if (*size < 96*2) return -2; // 00011101 bit pattern represent start of frame, 01 pattern represents a 0 and 10 represents a 1 uint8_t preamble[] = {0,0,0,1,1,1,0,1}; @@ -1743,11 +1738,11 @@ int HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32 return (int)startIdx; } -int IOdemodFSK(uint8_t *dest, size_t size) { +int IOdemodFSK(uint8_t *dest, size_t size, int *waveStartIdx) { //make sure buffer has data if (size < 66*64) return -2; - // FSK demodulator - size = fskdemod(dest, size, 64, 1, 10, 8); // FSK2a RF/64 + // FSK demodulator RF/64, fsk2a so invert, and fc/10/8 + size = fskdemod(dest, size, 64, 1, 10, 8, waveStartIdx); if (size < 65) return -3; //did we get a good demod? //Index map //0 10 20 30 40 50 60 @@ -1792,10 +1787,10 @@ int indala26decode(uint8_t *bitStream, size_t *size, uint8_t *invert) { } // loop to get raw paradox waveform then FSK demodulate the TAG ID from it -int ParadoxdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo) { +int ParadoxdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx) { size_t numStart=0, size2=*size, startIdx=0; // FSK demodulator - *size = fskdemod(dest, size2,50,1,10,8); //fsk2a + *size = fskdemod(dest, size2,50,1,10,8,waveStartIdx); //fsk2a if (*size < 96) return -2; // 00001111 bit pattern represent start of frame, 01 pattern represents a 0 and 10 represents a 1 @@ -1835,12 +1830,12 @@ int PrescoDemod(uint8_t *dest, size_t *size) { // by marshmellow // FSK Demod then try to locate a Farpointe Data (pyramid) ID -int PyramiddemodFSK(uint8_t *dest, size_t *size) { +int PyramiddemodFSK(uint8_t *dest, size_t *size, int *waveStartIdx) { //make sure buffer has data if (*size < 128*50) return -5; // FSK demodulator - *size = fskdemod(dest, *size, 50, 1, 10, 8); // fsk2a RF/50 + *size = fskdemod(dest, *size, 50, 1, 10, 8, waveStartIdx); // fsk2a RF/50 if (*size < 128) return -2; //did we get a good demod? uint8_t preamble[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}; diff --git a/common/lfdemod.h b/common/lfdemod.h index 56e07e56..c926a8a4 100644 --- a/common/lfdemod.h +++ b/common/lfdemod.h @@ -32,8 +32,7 @@ extern int DetectNRZClock(uint8_t dest[], size_t size, int clock, size_t *c extern int DetectPSKClock(uint8_t dest[], size_t size, int clock, size_t *firstPhaseShift, uint8_t *curPhase, uint8_t *fc); extern int DetectStrongAskClock(uint8_t dest[], size_t size, int high, int low, int *clock); extern bool DetectST(uint8_t buffer[], size_t *size, int *foundclock, size_t *ststart, size_t *stend); -extern int fskdemod(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow); -extern int fskdemod_ext(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *startIdx); +extern int fskdemod(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *startIdx); extern int getHiLo(uint8_t *BitStream, size_t size, int *high, int *low, uint8_t fuzzHi, uint8_t fuzzLo); extern uint32_t manchesterEncode2Bytes(uint16_t datain); extern int ManchesterEncode(uint8_t *BitStream, size_t size); @@ -49,16 +48,16 @@ extern void psk1TOpsk2(uint8_t *BitStream, size_t size); extern size_t removeParity(uint8_t *BitStream, size_t startIdx, uint8_t pLen, uint8_t pType, size_t bLen); //tag specific -extern int AWIDdemodFSK(uint8_t *dest, size_t *size); +extern int AWIDdemodFSK(uint8_t *dest, size_t *size, int *waveStartIdx); extern uint8_t Em410xDecode(uint8_t *BitStream, size_t *size, size_t *startIdx, uint32_t *hi, uint64_t *lo); extern int FDXBdemodBI(uint8_t *dest, size_t *size); extern int gProxII_Demod(uint8_t BitStream[], size_t *size); -extern int HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo); -extern int IOdemodFSK(uint8_t *dest, size_t size); +extern int HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx); +extern int IOdemodFSK(uint8_t *dest, size_t size, int *waveStartIdx); extern int indala26decode(uint8_t *bitStream, size_t *size, uint8_t *invert); -extern int ParadoxdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo); +extern int ParadoxdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx); extern int PrescoDemod(uint8_t *dest, size_t *size); -extern int PyramiddemodFSK(uint8_t *dest, size_t *size); +extern int PyramiddemodFSK(uint8_t *dest, size_t *size, int *waveStartIdx); extern int VikingDemod_AM(uint8_t *dest, size_t *size); extern int Visa2kDemod_AM(uint8_t *dest, size_t *size); From 537f80f2c8a84c8d48e66af78ed28d96306b8d9f Mon Sep 17 00:00:00 2001 From: marshmellow42 Date: Sat, 15 Apr 2017 21:40:05 -0400 Subject: [PATCH 12/17] adjust lf search to not use save/restore if... offline or '1' entered this allows the graph restore button to continue functioning after a `lf search 1` --- client/cmdlf.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/client/cmdlf.c b/client/cmdlf.c index 5c479ae0..b18cf215 100644 --- a/client/cmdlf.c +++ b/client/cmdlf.c @@ -877,19 +877,20 @@ int CmdVchDemod(const char *Cmd) int CheckChipType(char cmdp) { uint32_t wordData = 0; - //check for em4x05/em4x69 chips first + if (offline || cmdp == '1') return 0; + save_restoreGB(1); save_restoreDB(1); - if ((!offline && (cmdp != '1')) && EM4x05Block0Test(&wordData)) { + //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); return 1; } - //TODO check for t55xx chip... - - if ((!offline && (cmdp != '1')) && tryDetectP1(true)) { + //check for t55xx chip... + if (tryDetectP1(true)) { PrintAndLog("\nValid T55xx Chip Found\nTry lf t55xx ... commands\n"); save_restoreGB(0); save_restoreDB(0); From 999d57c20113c76bab27fc190c5fa394f9274629 Mon Sep 17 00:00:00 2001 From: marshmellow42 Date: Sun, 16 Apr 2017 00:26:26 -0400 Subject: [PATCH 13/17] fix y grid + and move em4x50 saveGB to allow graph restore after lf search clean up plotgraph unused code. should be done for a bit... --- client/cmdlfem4x.c | 5 +- client/proxguiqt.cpp | 124 +++++++++++++++++++++++++------------------ client/proxguiqt.h | 1 + 3 files changed, 74 insertions(+), 56 deletions(-) diff --git a/client/cmdlfem4x.c b/client/cmdlfem4x.c index 66c4221a..4e0ada57 100644 --- a/client/cmdlfem4x.c +++ b/client/cmdlfem4x.c @@ -474,9 +474,6 @@ int EM4x50Read(const char *Cmd, bool verbose) // get user entry if any sscanf(Cmd, "%i %i", &clk, &invert); - // save GraphBuffer - to restore it later - save_restoreGB(1); - // first get high and low values for (i = 0; i < GraphTraceLen; i++) { if (GraphBuffer[i] > high) @@ -573,6 +570,8 @@ int EM4x50Read(const char *Cmd, bool verbose) } else if (start < 0) return 0; start = skip; snprintf(tmp2, sizeof(tmp2),"%d %d 1000 %d", clk, invert, clk*47); + // save GraphBuffer - to restore it later + save_restoreGB(1); // get rid of leading crap snprintf(tmp, sizeof(tmp), "%i", skip); CmdLtrim(tmp); diff --git a/client/proxguiqt.cpp b/client/proxguiqt.cpp index d81c8108..6171c429 100644 --- a/client/proxguiqt.cpp +++ b/client/proxguiqt.cpp @@ -9,6 +9,7 @@ //----------------------------------------------------------------------------- #include "proxguiqt.h" +#include #include #include #include @@ -27,10 +28,12 @@ #include //#include - +bool g_useOverlays = false; +int g_absVMax = 0; int startMax; int PageWidth; + void ProxGuiQT::ShowGraphWindow(void) { emit ShowGraphWindowSignal(); @@ -130,6 +133,7 @@ void ProxWidget::vchange_autocorr(int v) int ans; ans = AutoCorrelate(GraphBuffer, s_Buff, GraphTraceLen, v, true, false); if (g_debugMode) printf("vchange_autocorr(w:%d): %d\n", v, ans); + g_useOverlays = true; RepaintGraphWindow(); } void ProxWidget::vchange_askedge(int v) @@ -138,6 +142,7 @@ void ProxWidget::vchange_askedge(int v) //extern int AskEdgeDetect(const int *in, int *out, int len, int threshold); ans = AskEdgeDetect(GraphBuffer, s_Buff, GraphTraceLen, v); if (g_debugMode) printf("vchange_askedge(w:%d)%d\n", v, ans); + g_useOverlays = true; RepaintGraphWindow(); } void ProxWidget::vchange_dthr_up(int v) @@ -145,16 +150,16 @@ void ProxWidget::vchange_dthr_up(int v) int down = opsController->horizontalSlider_dirthr_down->value(); directionalThreshold(GraphBuffer, s_Buff, GraphTraceLen, v, down); //printf("vchange_dthr_up(%d)", v); + g_useOverlays = true; RepaintGraphWindow(); - } void ProxWidget::vchange_dthr_down(int v) { //printf("vchange_dthr_down(%d)", v); int up = opsController->horizontalSlider_dirthr_up->value(); directionalThreshold(GraphBuffer,s_Buff, GraphTraceLen, v, up); + g_useOverlays = true; RepaintGraphWindow(); - } ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) { @@ -170,6 +175,11 @@ ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) opsController->horizontalSlider_dirthr_down->setMinimum(-128); opsController->horizontalSlider_dirthr_down->setMaximum(0); opsController->horizontalSlider_dirthr_down->setValue(-20); + opsController->horizontalSlider_dirthr_up->setMinimum(-40); + opsController->horizontalSlider_dirthr_up->setMaximum(128); + opsController->horizontalSlider_dirthr_up->setValue(20); + opsController->horizontalSlider_askedge->setValue(25); + opsController->horizontalSlider_window->setValue(4000); QObject::connect(opsController->pushButton_apply, SIGNAL(clicked()), this, SLOT(applyOperation())); @@ -223,6 +233,7 @@ void ProxWidget::closeEvent(QCloseEvent *event) { event->ignore(); this->hide(); + g_useOverlays = false; } void ProxWidget::hideEvent(QHideEvent *event) { controlWidget->hide(); @@ -266,6 +277,32 @@ QColor Plot::getColor(int graphNum) } } +void Plot::setMaxAndStart(int *buffer, int len, QRect plotRect) +{ + if (len == 0) return; + startMax = (len - (int)((plotRect.right() - plotRect.left() - 40) / GraphPixelsPerPoint)); + if(startMax < 0) { + startMax = 0; + } + if(GraphStart > startMax) { + GraphStart = startMax; + } + if (GraphStart > len) return; + int vMin = INT_MAX, vMax = INT_MIN, v = 0; + int sample_index = GraphStart ; + for( ; sample_index < len && xCoordOf(sample_index,plotRect) < plotRect.right() ; sample_index++) { + + v = buffer[sample_index]; + if(v < vMin) vMin = v; + if(v > vMax) vMax = v; + } + + g_absVMax = 0; + if(fabs( (double) vMin) > g_absVMax) g_absVMax = (int)fabs( (double) vMin); + if(fabs( (double) vMax) > g_absVMax) g_absVMax = (int)fabs( (double) vMax); + g_absVMax = (int)(g_absVMax*1.25 + 1); +} + void Plot::PlotDemod(uint8_t *buffer, size_t len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum, int plotOffset) { if (len == 0 || PlotGridX <= 0) return; @@ -327,47 +364,16 @@ void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect, if (len == 0) return; //clock_t begin = clock(); QPainterPath penPath; - - startMax = (len - (int)((plotRect.right() - plotRect.left() - 40) / GraphPixelsPerPoint)); - if(startMax < 0) { - startMax = 0; - } - if(GraphStart > startMax) { - GraphStart = startMax; - } - if (GraphStart > len) return; - int vMin = INT_MAX, vMax = INT_MIN, vMean = 0, v = 0, absVMax = 0; - int sample_index = GraphStart ; - for( ; sample_index < len && xCoordOf(sample_index,plotRect) < plotRect.right() ; sample_index++) { - - v = buffer[sample_index]; - if(v < vMin) vMin = v; - if(v > vMax) vMax = v; - vMean += v; - } - - vMean /= (sample_index - GraphStart); - - if(fabs( (double) vMin) > absVMax) absVMax = (int)fabs( (double) vMin); - if(fabs( (double) vMax) > absVMax) absVMax = (int)fabs( (double) vMax); - absVMax = (int)(absVMax*1.25 + 1); - // number of points that will be plotted - int span = (int)((plotRect.right() - plotRect.left()) / GraphPixelsPerPoint); - // one label every 100 pixels, let us say - int labels = (plotRect.right() - plotRect.left() - 40) / 100; - if(labels <= 0) labels = 1; - int pointsPerLabel = span / labels; - if(pointsPerLabel <= 0) pointsPerLabel = 1; - + int vMin = INT_MAX, vMax = INT_MIN, vMean = 0, v = 0, i = 0; int x = xCoordOf(GraphStart, plotRect); - int y = yCoordOf(buffer[GraphStart],plotRect,absVMax); + int y = yCoordOf(buffer[GraphStart],plotRect,g_absVMax); penPath.moveTo(x, y); - for(int i = GraphStart; i < len && xCoordOf(i, plotRect) < plotRect.right(); i++) { + for(i = GraphStart; i < len && xCoordOf(i, plotRect) < plotRect.right(); i++) { x = xCoordOf(i, plotRect); v = buffer[i]; - y = yCoordOf( v, plotRect, absVMax);//(y * (r.top() - r.bottom()) / (2*absYMax)) + zeroHeight; + y = yCoordOf( v, plotRect, g_absVMax); penPath.lineTo(x, y); @@ -375,7 +381,12 @@ void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect, QRect f(QPoint(x - 3, y - 3),QPoint(x + 3, y + 3)); painter->fillRect(f, QColor(100, 255, 100)); } + //catch stats + if(v < vMin) vMin = v; + if(v > vMax) vMax = v; + vMean += v; } + vMean /= (i - GraphStart); painter->setPen(getColor(graphNum)); @@ -383,7 +394,7 @@ void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect, int xo = 5+(graphNum*40); painter->drawLine(xo, plotRect.top(),xo, plotRect.bottom()); - int vMarkers = (absVMax - (absVMax % 10)) / 5; + int vMarkers = (g_absVMax - (g_absVMax % 10)) / 5; int minYDist = 40; //Minimum pixel-distance between markers char yLbl[20]; @@ -391,10 +402,10 @@ void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect, int n = 0; int lasty0 = 65535; - for(int v = vMarkers; yCoordOf(v,plotRect,absVMax) > plotRect.top() && n < 20; v+= vMarkers ,n++) + for(v = vMarkers; yCoordOf(v,plotRect,g_absVMax) > plotRect.top() && n < 20; v+= vMarkers ,n++) { - int y0 = yCoordOf(v,plotRect,absVMax); - int y1 = yCoordOf(-v,plotRect,absVMax); + int y0 = yCoordOf(v,plotRect,g_absVMax); + int y1 = yCoordOf(-v,plotRect,g_absVMax); if(lasty0 - y0 < minYDist) continue; @@ -413,7 +424,7 @@ void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect, painter->drawPath(penPath); char str[200]; sprintf(str, "max=%d min=%d mean=%d n=%d/%d CursorAVal=[%d] CursorBVal=[%d]", - vMax, vMin, vMean, sample_index, len, buffer[CursorAPos], buffer[CursorBPos]); + vMax, vMin, vMean, i, len, buffer[CursorAPos], buffer[CursorBPos]); painter->drawText(20, annotationRect.bottom() - 23 - 20 * graphNum, str); //clock_t end = clock(); @@ -423,20 +434,18 @@ void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect, void Plot::plotGridLines(QPainter* painter,QRect r) { - int zeroHeight = r.top() + (r.bottom() - r.top()) / 2; - int i; int grid_delta_x = (int) (PlotGridX * GraphPixelsPerPoint); - int grid_delta_y = (int) (PlotGridY * GraphPixelsPerPoint); + int grid_delta_y = PlotGridY; if ((PlotGridX > 0) && ((PlotGridX * GraphPixelsPerPoint) > 1)) { for(i = (GridOffset * GraphPixelsPerPoint); i < r.right(); i += grid_delta_x) { painter->drawLine(r.left()+i, r.top(), r.left()+i, r.bottom()); } - } - if ((PlotGridY > 0) && ((PlotGridY * GraphPixelsPerPoint) > 1)){ - for(i = 0; i < ((r.top() + r.bottom())>>1); i += grid_delta_y) { - painter->drawLine(r.left(),zeroHeight + i,r.right(),zeroHeight + i); - painter->drawLine(r.left(),zeroHeight - i,r.right(),zeroHeight - i); + } + if (PlotGridY > 0) { + for(i = 0; yCoordOf(i,r,g_absVMax) > r.top(); i += grid_delta_y) { + painter->drawLine( r.left(), yCoordOf(i,r,g_absVMax), r.right(), yCoordOf(i,r,g_absVMax) ); + painter->drawLine( r.left(), yCoordOf(i*-1,r,g_absVMax), r.right(), yCoordOf(i*-1,r,g_absVMax) ); } } } @@ -446,6 +455,7 @@ void Plot::plotGridLines(QPainter* painter,QRect r) void Plot::paintEvent(QPaintEvent *event) { + QPainter painter(this); QBrush brush(QColor(100, 255, 100)); QPen pen(QColor(100, 255, 100)); @@ -473,6 +483,9 @@ void Plot::paintEvent(QPaintEvent *event) //Black foreground painter.fillRect(plotRect, QColor(0, 0, 0)); + //init graph variables + setMaxAndStart(GraphBuffer,GraphTraceLen,plotRect); + // center line int zeroHeight = plotRect.top() + (plotRect.bottom() - plotRect.top()) / 2; painter.setPen(QColor(100, 100, 100)); @@ -481,11 +494,15 @@ void Plot::paintEvent(QPaintEvent *event) plotGridLines(&painter, plotRect); //Start painting graph + PlotGraph(GraphBuffer, GraphTraceLen,plotRect,infoRect,&painter,0); if (showDemod && DemodBufferLen > 8) { PlotDemod(DemodBuffer, DemodBufferLen,plotRect,infoRect,&painter,2,g_DemodStartIdx); } - PlotGraph(s_Buff, GraphTraceLen,plotRect,infoRect,&painter,1); - PlotGraph(GraphBuffer, GraphTraceLen,plotRect,infoRect,&painter,0); + if (g_useOverlays) { + //init graph variables + setMaxAndStart(s_Buff,GraphTraceLen,plotRect); + PlotGraph(s_Buff, GraphTraceLen,plotRect,infoRect,&painter,1); + } // End graph drawing //Draw the cursors @@ -542,6 +559,7 @@ void Plot::closeEvent(QCloseEvent *event) { event->ignore(); this->hide(); + g_useOverlays = false; } void Plot::mouseMoveEvent(QMouseEvent *event) diff --git a/client/proxguiqt.h b/client/proxguiqt.h index aa3b5b35..8ea4d312 100644 --- a/client/proxguiqt.h +++ b/client/proxguiqt.h @@ -35,6 +35,7 @@ private: int xCoordOf(int i, QRect r ); int yCoordOf(int v, QRect r, int maxVal); int valueOf_yCoord(int y, QRect r, int maxVal); + void setMaxAndStart(int *buffer, int len, QRect plotRect); QColor getColor(int graphNum); public: Plot(QWidget *parent = 0); From 3fd7fce4accbe4c5b59987fa4979ec46adcb459c Mon Sep 17 00:00:00 2001 From: marshmellow42 Date: Mon, 17 Apr 2017 18:37:23 -0400 Subject: [PATCH 14/17] 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. --- client/cmddata.c | 4 +-- client/cmdlf.c | 18 ++++++------ client/cmdlfem4x.c | 6 ++-- client/cmdlft55xx.c | 12 ++++---- client/graph.c | 9 ++++-- client/graph.h | 2 ++ client/proxgui.h | 2 ++ client/proxguiqt.cpp | 65 ++++++++++++++------------------------------ 8 files changed, 51 insertions(+), 67 deletions(-) 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: From 3fc4596f2c56dbec9448685fa691333aa1ea5fb2 Mon Sep 17 00:00:00 2001 From: marshmellow42 Date: Tue, 18 Apr 2017 23:41:38 -0400 Subject: [PATCH 15/17] fix makefile to allow make of overlays.ui to ui_overlays.h add ui_overlays.h to .gitignore should now compile to whatever qt version you have. (as long as it is compatible with the overlays.ui file...) --- .gitignore | 1 + client/Makefile | 11 +++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index d08c67b8..d41f7c1d 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ *.moc.cpp *.z version.c +ui_overlays.h *.exe proxmark3 diff --git a/client/Makefile b/client/Makefile index 82697612..ee2a25c0 100644 --- a/client/Makefile +++ b/client/Makefile @@ -162,10 +162,10 @@ ZLIBOBJS = $(ZLIBSRCS:%.c=$(OBJDIR)/%.o) BINS = proxmark3 flasher fpga_compress WINBINS = $(patsubst %, %.exe, $(BINS)) -CLEAN = $(BINS) $(WINBINS) $(COREOBJS) $(CMDOBJS) $(ZLIBOBJS) $(QTGUIOBJS) $(OBJDIR)/*.o *.moc.cpp -#./ui/ui_overlays.h +CLEAN = $(BINS) $(WINBINS) $(COREOBJS) $(CMDOBJS) $(ZLIBOBJS) $(QTGUIOBJS) $(OBJDIR)/*.o *.moc.cpp ui/ui_overlays.h -all: lua_build $(BINS) +# need to assign dependancies to build these first... +all: ui/ui_overlays.h lua_build $(BINS) all-static: LDLIBS:=-static $(LDLIBS) all-static: proxmark3 flasher fpga_compress @@ -183,9 +183,8 @@ fpga_compress: $(OBJDIR)/fpga_compress.o $(ZLIBOBJS) proxguiqt.moc.cpp: proxguiqt.h $(MOC) -o$@ $^ -#cannot seem to get this to work accross qt versions... -#ui/ui_overlays.h: ./ui/overlays.ui -# $(UIC) $^ > $@ +ui/ui_overlays.h: ui/overlays.ui + $(UIC) $^ > $@ lualibs/usb_cmd.lua: ../include/usb_cmd.h awk -f usb_cmd_h2lua.awk $^ > $@ From 9c44a9b6caf8a3f4462b77ed30453c5b71c3e7cd Mon Sep 17 00:00:00 2001 From: marshmellow42 Date: Tue, 18 Apr 2017 23:43:42 -0400 Subject: [PATCH 16/17] fix .gitignore changes --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d41f7c1d..422d53e5 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,7 @@ *.moc.cpp *.z version.c -ui_overlays.h +client/ui/ui_overlays.h *.exe proxmark3 From 3759e8a02d40ddfe20c451f92707dd188dcc9a94 Mon Sep 17 00:00:00 2001 From: marshmellow42 Date: Tue, 18 Apr 2017 23:59:40 -0400 Subject: [PATCH 17/17] Remove built file --- client/ui/ui_overlays.h | 264 ---------------------------------------- 1 file changed, 264 deletions(-) delete mode 100644 client/ui/ui_overlays.h diff --git a/client/ui/ui_overlays.h b/client/ui/ui_overlays.h deleted file mode 100644 index ff0665e5..00000000 --- a/client/ui/ui_overlays.h +++ /dev/null @@ -1,264 +0,0 @@ -/******************************************************************************** -** Form generated from reading UI file 'overlays.ui' -** -** Created by: Qt User Interface Compiler version 4.8.6 -** -** WARNING! All changes made in this file will be lost when recompiling UI file! -********************************************************************************/ - -#ifndef OVERLAYS_H -#define OVERLAYS_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class Ui_Form -{ -public: - QVBoxLayout *verticalLayout_3; - QTabWidget *tabWidget_overlays; - QWidget *tab; - QVBoxLayout *verticalLayout_2; - QFormLayout *formLayout; - QLabel *label_5; - QLabel *label; - QSlider *horizontalSlider_window; - QSpacerItem *verticalSpacer; - QWidget *tab_3; - QVBoxLayout *verticalLayout_4; - QFormLayout *formLayout_4; - QLabel *label_8; - QLabel *label_9; - QSlider *horizontalSlider_askedge; - QSpacerItem *verticalSpacer_3; - QWidget *tab_2; - QVBoxLayout *verticalLayout; - QFormLayout *formLayout_2; - QLabel *label_2; - QLabel *label_6; - QSlider *horizontalSlider_dirthr_up; - QFormLayout *formLayout_3; - QLabel *label_3; - QLabel *label_7; - QSlider *horizontalSlider_dirthr_down; - QSpacerItem *verticalSpacer_2; - QHBoxLayout *horizontalLayout; - QPushButton *pushButton_apply; - QPushButton *pushButton_sticky; - QSpacerItem *horizontalSpacer; - QLabel *label_4; - - void setupUi(QWidget *Form) - { - if (Form->objectName().isEmpty()) - Form->setObjectName(QString::fromUtf8("Form")); - Form->resize(614, 286); - verticalLayout_3 = new QVBoxLayout(Form); - verticalLayout_3->setObjectName(QString::fromUtf8("verticalLayout_3")); - tabWidget_overlays = new QTabWidget(Form); - tabWidget_overlays->setObjectName(QString::fromUtf8("tabWidget_overlays")); - tab = new QWidget(); - tab->setObjectName(QString::fromUtf8("tab")); - tab->setFocusPolicy(Qt::StrongFocus); - verticalLayout_2 = new QVBoxLayout(tab); - verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2")); - formLayout = new QFormLayout(); - formLayout->setObjectName(QString::fromUtf8("formLayout")); - label_5 = new QLabel(tab); - label_5->setObjectName(QString::fromUtf8("label_5")); - - formLayout->setWidget(0, QFormLayout::FieldRole, label_5); - - label = new QLabel(tab); - label->setObjectName(QString::fromUtf8("label")); - - formLayout->setWidget(0, QFormLayout::LabelRole, label); - - - verticalLayout_2->addLayout(formLayout); - - horizontalSlider_window = new QSlider(tab); - horizontalSlider_window->setObjectName(QString::fromUtf8("horizontalSlider_window")); - horizontalSlider_window->setMinimum(10); - horizontalSlider_window->setMaximum(10000); - horizontalSlider_window->setValue(2000); - horizontalSlider_window->setOrientation(Qt::Horizontal); - - verticalLayout_2->addWidget(horizontalSlider_window); - - verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); - - verticalLayout_2->addItem(verticalSpacer); - - tabWidget_overlays->addTab(tab, QString()); - tab_3 = new QWidget(); - tab_3->setObjectName(QString::fromUtf8("tab_3")); - verticalLayout_4 = new QVBoxLayout(tab_3); - verticalLayout_4->setObjectName(QString::fromUtf8("verticalLayout_4")); - formLayout_4 = new QFormLayout(); - formLayout_4->setObjectName(QString::fromUtf8("formLayout_4")); - formLayout_4->setContentsMargins(-1, -1, -1, 0); - label_8 = new QLabel(tab_3); - label_8->setObjectName(QString::fromUtf8("label_8")); - - formLayout_4->setWidget(0, QFormLayout::LabelRole, label_8); - - label_9 = new QLabel(tab_3); - label_9->setObjectName(QString::fromUtf8("label_9")); - - formLayout_4->setWidget(0, QFormLayout::FieldRole, label_9); - - - verticalLayout_4->addLayout(formLayout_4); - - horizontalSlider_askedge = new QSlider(tab_3); - horizontalSlider_askedge->setObjectName(QString::fromUtf8("horizontalSlider_askedge")); - horizontalSlider_askedge->setMinimum(5); - horizontalSlider_askedge->setMaximum(80); - horizontalSlider_askedge->setValue(20); - horizontalSlider_askedge->setOrientation(Qt::Horizontal); - - verticalLayout_4->addWidget(horizontalSlider_askedge); - - verticalSpacer_3 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); - - verticalLayout_4->addItem(verticalSpacer_3); - - tabWidget_overlays->addTab(tab_3, QString()); - tab_2 = new QWidget(); - tab_2->setObjectName(QString::fromUtf8("tab_2")); - verticalLayout = new QVBoxLayout(tab_2); - verticalLayout->setObjectName(QString::fromUtf8("verticalLayout")); - formLayout_2 = new QFormLayout(); - formLayout_2->setObjectName(QString::fromUtf8("formLayout_2")); - label_2 = new QLabel(tab_2); - label_2->setObjectName(QString::fromUtf8("label_2")); - - formLayout_2->setWidget(0, QFormLayout::LabelRole, label_2); - - label_6 = new QLabel(tab_2); - label_6->setObjectName(QString::fromUtf8("label_6")); - - formLayout_2->setWidget(0, QFormLayout::FieldRole, label_6); - - - verticalLayout->addLayout(formLayout_2); - - horizontalSlider_dirthr_up = new QSlider(tab_2); - horizontalSlider_dirthr_up->setObjectName(QString::fromUtf8("horizontalSlider_dirthr_up")); - horizontalSlider_dirthr_up->setMaximum(128); - horizontalSlider_dirthr_up->setValue(20); - horizontalSlider_dirthr_up->setOrientation(Qt::Horizontal); - - verticalLayout->addWidget(horizontalSlider_dirthr_up); - - formLayout_3 = new QFormLayout(); - formLayout_3->setObjectName(QString::fromUtf8("formLayout_3")); - label_3 = new QLabel(tab_2); - label_3->setObjectName(QString::fromUtf8("label_3")); - - formLayout_3->setWidget(0, QFormLayout::LabelRole, label_3); - - label_7 = new QLabel(tab_2); - label_7->setObjectName(QString::fromUtf8("label_7")); - - formLayout_3->setWidget(0, QFormLayout::FieldRole, label_7); - - - verticalLayout->addLayout(formLayout_3); - - horizontalSlider_dirthr_down = new QSlider(tab_2); - horizontalSlider_dirthr_down->setObjectName(QString::fromUtf8("horizontalSlider_dirthr_down")); - horizontalSlider_dirthr_down->setMaximum(127); - horizontalSlider_dirthr_down->setOrientation(Qt::Horizontal); - - verticalLayout->addWidget(horizontalSlider_dirthr_down); - - verticalSpacer_2 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); - - verticalLayout->addItem(verticalSpacer_2); - - tabWidget_overlays->addTab(tab_2, QString()); - - verticalLayout_3->addWidget(tabWidget_overlays); - - horizontalLayout = new QHBoxLayout(); - horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); - pushButton_apply = new QPushButton(Form); - pushButton_apply->setObjectName(QString::fromUtf8("pushButton_apply")); - - horizontalLayout->addWidget(pushButton_apply); - - pushButton_sticky = new QPushButton(Form); - pushButton_sticky->setObjectName(QString::fromUtf8("pushButton_sticky")); - - horizontalLayout->addWidget(pushButton_sticky); - - horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); - - horizontalLayout->addItem(horizontalSpacer); - - label_4 = new QLabel(Form); - label_4->setObjectName(QString::fromUtf8("label_4")); - - horizontalLayout->addWidget(label_4); - - - verticalLayout_3->addLayout(horizontalLayout); - - - retranslateUi(Form); - QObject::connect(horizontalSlider_window, SIGNAL(valueChanged(int)), label_4, SLOT(setNum(int))); - QObject::connect(horizontalSlider_window, SIGNAL(valueChanged(int)), label_5, SLOT(setNum(int))); - QObject::connect(horizontalSlider_dirthr_up, SIGNAL(valueChanged(int)), label_6, SLOT(setNum(int))); - QObject::connect(horizontalSlider_dirthr_down, SIGNAL(valueChanged(int)), label_7, SLOT(setNum(int))); - QObject::connect(horizontalSlider_askedge, SIGNAL(valueChanged(int)), label_9, SLOT(setNum(int))); - - tabWidget_overlays->setCurrentIndex(1); - - - QMetaObject::connectSlotsByName(Form); - } // setupUi - - void retranslateUi(QWidget *Form) - { - Form->setWindowTitle(QApplication::translate("Form", "Overlays", 0)); - label_5->setText(QString()); - label->setText(QApplication::translate("Form", "Window size", 0)); - tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab), QApplication::translate("Form", "Autocorrelate", 0)); - label_8->setText(QApplication::translate("Form", "Edge Jump Threshold", 0)); - label_9->setText(QString()); - tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab_3), QApplication::translate("Form", "AskEdge", 0)); - label_2->setText(QApplication::translate("Form", "Up", 0)); - label_6->setText(QString()); - label_3->setText(QApplication::translate("Form", "Down", 0)); - label_7->setText(QString()); - tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab_2), QApplication::translate("Form", "Dirthreshold", 0)); - pushButton_apply->setText(QApplication::translate("Form", "Apply", 0)); - pushButton_sticky->setText(QApplication::translate("Form", "Restore", 0)); - label_4->setText(QString()); - } // retranslateUi - -}; - -namespace Ui { - class Form: public Ui_Form {}; -} // namespace Ui - -QT_END_NAMESPACE - -#endif // OVERLAYS_H