*.moc.cpp
*.z
version.c
+client/ui/ui_overlays.h
*.exe
proxmark3
- 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
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);
// 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
{
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
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
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
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
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
QTLDLIBS = -L$(QTDIR)/lib -lQt5Widgets -lQt5Gui -lQt5Core
endif
MOC = $(QTDIR)/bin/moc
+ UIC = $(QTDIR)/bin/uic
endif
endif
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)
+# 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
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 $^ > $@
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;
+int g_DemodStartIdx=0;
+int g_DemodClock=0;
static int CmdHelp(const char *Cmd);
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
+ if (saveOpt == GRAPH_SAVE) { //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;
}
}
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;
//}
//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;
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);
+
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);
}
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
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;
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;
}
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();
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;
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)
return 0;
}
+int AskEdgeDetect(const int *in, int *out, int len, int threshold) {
+ int Last = 0;
+ for(int i = 1; i<len; i++) {
+ if (in[i]-in[i-1] >= 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
int CmdAskEdgeDetect(const char *Cmd)
{
int thresLen = 25;
- int Last = 0;
+ int ans = 0;
sscanf(Cmd, "%i", &thresLen);
- for(int i = 1; i<GraphTraceLen; i++){
- if (GraphBuffer[i]-GraphBuffer[i-1]>=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 */
}
//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(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
+ // 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);
PrintAndLog("%s decoded bitstream:",GetFSKType(fchigh,fclow,invert));
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;
}
//prime demod buffer for output
setDemodBuf(BitStream,BitLen,0);
+ setClockGrid(clk, startIdx);
+
return 1;
}
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) {
return ans;
}
+void setClockGrid(int clk, int offset) {
+ g_DemodStartIdx = offset;
+ g_DemodClock = clk;
+ if (g_debugMode) PrintAndLog("demodoffset %d, clk %d",offset,clk);
+
+ 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);
GraphTraceLen = n;
}
+ setClockGrid(0,0);
RepaintGraphWindow();
return 0;
}
}
fclose(f);
PrintAndLog("loaded %d samples", GraphTraceLen);
+ setClockGrid(0,0);
RepaintGraphWindow();
return 0;
}
return 0;
}
-int CmdDirectionalThreshold(const char *Cmd)
+int directionalThreshold(const int* in, int *out, size_t len, int8_t up, int8_t down)
{
- int8_t upThres = param_get8(Cmd, 0);
- int8_t downThres = param_get8(Cmd, 1);
-
- printf("Applying Up Threshold: %d, Down Threshold: %d\n", upThres, downThres);
+ 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.
- 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) {
+ for (int i = 1; i < len; ++i) {
// Apply first threshold to samples heading up
- if (GraphBuffer[i] >= upThres && GraphBuffer[i] > lastValue)
+ if (in[i] >= up && in[i] > lastValue)
{
- lastValue = GraphBuffer[i]; // Buffer last value as we overwrite it.
- GraphBuffer[i] = 127;
+ lastValue = out[i]; // Buffer last value as we overwrite it.
+ out[i] = 1;
}
// Apply second threshold to samples heading down
- else if (GraphBuffer[i] <= downThres && GraphBuffer[i] < lastValue)
+ else if (in[i] <= down && in[i] < lastValue)
{
- lastValue = GraphBuffer[i]; // Buffer last value as we overwrite it.
- GraphBuffer[i] = -127;
+ lastValue = out[i]; // Buffer last value as we overwrite it.
+ out[i] = -1;
}
else
{
- lastValue = GraphBuffer[i]; // Buffer last value as we overwrite it.
- GraphBuffer[i] = GraphBuffer[i-1];
-
+ lastValue = out[i]; // Buffer last value as we overwrite it.
+ out[i] = out[i-1];
}
}
- GraphBuffer[0] = GraphBuffer[1]; // Aline with first edited sample.
+ out[0] = out[1]; // Align with first edited sample.
+ return 0;
+}
+
+int CmdDirectionalThreshold(const char *Cmd)
+{
+ int8_t upThres = param_get8(Cmd, 0);
+ int8_t downThres = param_get8(Cmd, 1);
+
+ printf("Applying Up Threshold: %d, Down Threshold: %d\n", upThres, downThres);
+
+ directionalThreshold(GraphBuffer, GraphBuffer,GraphTraceLen, upThres, downThres);
RepaintGraphWindow();
return 0;
}
{"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, "<x> <y> -- overlay grid on graph window, use zero value to turn off either"},
{"hexsamples", CmdHexsamples, 0, "<bytes> [<offset>] -- Dump big buffer as hex bytes"},
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);
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];
extern size_t DemodBufferLen;
+extern int g_DemodStartIdx;
+extern int g_DemodClock;
extern uint8_t g_debugMode;
-//extern size_t g_demodStartIdx;
-//extern uint8_t g_demodClock;
#define BIGBUF_SIZE 40000
#endif
{
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;
int CheckChipType(char cmdp) {
uint32_t wordData = 0;
+ if (offline || cmdp == '1') return 0;
+
+ save_restoreGB(GRAPH_SAVE);
+ save_restoreDB(GRAPH_SAVE);
//check for em4x05/em4x69 chips first
- save_restoreGB(1);
- save_restoreDB(1);
- if ((!offline && (cmdp != '1')) && EM4x05Block0Test(&wordData)) {
+ 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;
}
- //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);
+ save_restoreGB(GRAPH_RESTORE);
+ save_restoreDB(GRAPH_RESTORE);
return 1;
}
- save_restoreGB(0);
- save_restoreDB(0);
+ save_restoreGB(GRAPH_RESTORE);
+ save_restoreDB(GRAPH_RESTORE);
return 0;
}
PrintAndLog("\nNo Known Tags Found!\n");
if (testRaw=='u' || testRaw=='U') {
- ans=CheckChipType(cmdp);
+ //ans=CheckChipType(cmdp);
//test unknown tag formats (raw mode)0
PrintAndLog("\nChecking for Unknown tags:\n");
- ans=AutoCorrelate(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
ans=FSKrawDemod("",true);
if (ans>0) {
PrintAndLog("\nUnknown FSK Modulated Tag Found!");
- return CheckChipType(cmdp);;
+ return CheckChipType(cmdp);
}
}
bool st = true;
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");
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)
uint32_t rawHi = bytebits_to_byte(BitStream+idx+32,32);
uint32_t rawHi2 = bytebits_to_byte(BitStream+idx,32);
setDemodBuf(BitStream,96,idx);
+ setClockGrid(50, waveIdx + (idx*50));
size = removeParity(BitStream, idx+8, 4, 1, 88);
if (size != 66){
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);
+ setClockGrid(g_DemodClock, g_DemodStartIdx + ((idx+1)*g_DemodClock));
+
if (g_debugMode) {
PrintAndLog("DEBUG: idx: %d, Len: %d, Printing Demod Buffer:", idx, BitLen);
printDemodBuff();
// 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)
} 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(GRAPH_SAVE);
// get rid of leading crap
snprintf(tmp, sizeof(tmp), "%i", skip);
CmdLtrim(tmp);
phaseoff = 0;
i += 2;
if (ASKDemod(tmp2, false, false, 1) < 1) {
- save_restoreGB(0);
+ save_restoreGB(GRAPH_RESTORE);
return 0;
}
//set DemodBufferLen to just one block
}
//restore GraphBuffer
- save_restoreGB(0);
+ save_restoreGB(GRAPH_RESTORE);
return (int)AllPTest;
}
}
setDemodBuf(DemodBuffer, 32, 0);
+ //setClockGrid(0,0);
+
*word = bytebits_to_byteLSBF(DemodBuffer, 32);
}
return true;
// 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);
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
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){
(unsigned int) fmtLen, (unsigned int) fc, (unsigned int) cardnum);
}
setDemodBuf(BitStream,BitLen,idx);
+ setClockGrid(50, waveIdx + (idx*50));
if (g_debugMode){
PrintAndLog("DEBUG: idx: %d, Len: %d, Printing Demod Buffer:", idx, BitLen);
printDemodBuff();
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");
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){
PrintAndLog("IO Prox XSF(%02d)%02x:%05d (%08x%08x) [%02x %s]",version,facilitycode,number,code,code2, crc, crcStr);
setDemodBuf(BitStream,64,idx);
+ setClockGrid(64, waveIdx + (idx*64));
+
if (g_debugMode){
PrintAndLog("DEBUG: idx: %d, Len: %d, Printing demod buffer:",idx,64);
printDemodBuff();
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);
}
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++){
return 0;
}
setDemodBuf(DemodBuffer, 96, ans);
+ setClockGrid(g_DemodClock, g_DemodStartIdx + (ans*g_DemodClock));
//setGrid_Clock(32);
//got a good demod
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){
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(50, waveIdx + (idx*50));
if (g_debugMode){
PrintAndLog("DEBUG: idx: %d, len: %d, Printing Demod Buffer:", idx, BitLen);
printDemodBuff();
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};
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)
uint32_t rawHi2 = bytebits_to_byte(BitStream+idx+32,32);
uint32_t rawHi3 = bytebits_to_byte(BitStream+idx,32);
setDemodBuf(BitStream,128,idx);
+ setClockGrid(50, waveIdx + (idx*50));
size = removeParity(BitStream, idx+8, 8, 1, 120);
if (size != 105){
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);
break;\r
case DEMOD_PSK1:\r
// skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
- save_restoreGB(1);\r
+ save_restoreGB(GRAPH_SAVE);\r
CmdLtrim("160");\r
snprintf(cmdStr, sizeof(buf),"%d %d 6", bitRate[config.bitrate], config.inverted );\r
ans = PSKDemod(cmdStr, false);\r
//undo trim samples\r
- save_restoreGB(0);\r
+ save_restoreGB(GRAPH_RESTORE);\r
break;\r
case DEMOD_PSK2: //inverted won't affect this\r
case DEMOD_PSK3: //not fully implemented\r
// skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
- save_restoreGB(1);\r
+ save_restoreGB(GRAPH_SAVE);\r
CmdLtrim("160");\r
snprintf(cmdStr, sizeof(buf),"%d 0 6", bitRate[config.bitrate] );\r
ans = PSKDemod(cmdStr, false);\r
psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
//undo trim samples\r
- save_restoreGB(0);\r
+ save_restoreGB(GRAPH_RESTORE);\r
break;\r
case DEMOD_NRZ:\r
snprintf(cmdStr, sizeof(buf),"%d %d 1", bitRate[config.bitrate], config.inverted );\r
t55xx_conf_block_t tests[15];\r
int bitRate=0;\r
uint8_t fc1 = 0, fc2 = 0, ans = 0;\r
- int clk=0;\r
- ans = fskClocks(&fc1, &fc2, (uint8_t *)&clk, false);\r
+ int clk = 0, firstClockEdge = 0;\r
+ ans = fskClocks(&fc1, &fc2, (uint8_t *)&clk, false, &firstClockEdge);\r
if (ans && ((fc1==10 && fc2==8) || (fc1==8 && fc2==5))) {\r
if ( FSKrawDemod("0 0", false) && test(DEMOD_FSK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
tests[hits].modulation = DEMOD_FSK;\r
clk = GetPskClock("", false, false);\r
if (clk>0) {\r
// allow undo\r
- save_restoreGB(1);\r
+ save_restoreGB(GRAPH_SAVE);\r
// skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
CmdLtrim("160");\r
if ( PSKDemod("0 0 6", false) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
}\r
} // inverse waves does not affect this demod\r
//undo trim samples\r
- save_restoreGB(0);\r
+ save_restoreGB(GRAPH_RESTORE);\r
}\r
} \r
if ( hits == 1) {\r
uint8_t preamble[] = {1,1,1,0,0,0,0,0,0,0,0,1,0,1,0,1};\r
size_t startIdx = 0;\r
uint8_t fc1 = 0, fc2 = 0, ans = 0;\r
- int clk = 0;\r
+ int clk = 0, firstClockEdge = 0;\r
bool st = true;\r
\r
if ( getData ) {\r
}\r
\r
// try fsk clock detect. if successful it cannot be any other type of modulation... (in theory...)\r
- ans = fskClocks(&fc1, &fc2, (uint8_t *)&clk, false);\r
+ ans = fskClocks(&fc1, &fc2, (uint8_t *)&clk, false, &firstClockEdge);\r
if (ans && ((fc1==10 && fc2==8) || (fc1==8 && fc2==5))) {\r
if ( FSKrawDemod("0 0", false) && \r
preambleSearchEx(DemodBuffer,preamble,sizeof(preamble),&DemodBufferLen,&startIdx,false) && \r
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;
}
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);
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)
{
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;
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);
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);
}
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);
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){
}
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);
}
*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;
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);
// Max graph trace len: 40000 (bigbuf) * 8 (at 1 bit per sample)
#define MAX_GRAPH_TRACE_LEN (40000 * 8 )
+#define GRAPH_SAVE 1
+#define GRAPH_RESTORE 0
extern int GraphBuffer[MAX_GRAPH_TRACE_LEN];
extern int GraphTraceLen;
+extern int s_Buff[MAX_GRAPH_TRACE_LEN];
+
#endif
if (!gui)
return;
- delete gui;
+ gui->Exit();
+ //delete gui;
gui = NULL;
}
extern "C" {
#endif
+#include <stdint.h>
+#include <string.h>
+
void ShowGraphWindow(void);
void HideGraphWindow(void);
void RepaintGraphWindow(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;
+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 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);
+
+#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;
+extern size_t g_DemodStartIdx;
+extern bool showDemod;
+extern uint8_t g_debugMode;
#ifdef __cplusplus
}
//-----------------------------------------------------------------------------
#include "proxguiqt.h"
+#include <stdbool.h>
#include <iostream>
#include <QPainterPath>
#include <QBrush>
#include <math.h>
#include <limits.h>
#include <stdio.h>
+#include <QSlider>
+#include <QHBoxLayout>
+#include <string.h>
#include "proxgui.h"
+#include <QtGui>
+//#include <ctime>
-int GridOffset= 0;
-bool GridLocked= 0;
+bool g_useOverlays = false;
+int g_absVMax = 0;
int startMax;
int PageWidth;
+int unlockStart = 0;
void ProxGuiQT::ShowGraphWindow(void)
{
emit HideGraphWindowSignal();
}
+void ProxGuiQT::Exit(void)
+{
+ emit ExitSignal();
+}
+
void ProxGuiQT::_ShowGraphWindow(void)
{
if(!plotapp)
plotwidget->hide();
}
+void ProxGuiQT::_Exit(void) {
+ delete this;
+}
void ProxGuiQT::MainLoop()
{
plotapp = new QApplication(argc, argv);
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();
}
ProxGuiQT::~ProxGuiQT(void)
{
- if (plotwidget) {
- delete plotwidget;
- plotwidget = NULL;
- }
-
+ //if (plotwidget) {
+ //plotwidget->destroy(true,true);
+ // delete plotwidget;
+ // plotwidget = NULL;
+ //}
if (plotapp) {
plotapp->quit();
delete plotapp;
}
}
-void ProxWidget::paintEvent(QPaintEvent *event)
+//--------------------
+void ProxWidget::applyOperation()
{
- 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));
+ //printf("ApplyOperation()");
+ save_restoreGB(GRAPH_SAVE);
+ memcpy(GraphBuffer, s_Buff, sizeof(int) * GraphTraceLen);
+ RepaintGraphWindow();
+}
+void ProxWidget::stickOperation()
+{
+ save_restoreGB(GRAPH_RESTORE);
+ //printf("stickOperation()");
+}
+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)
+{
+ int ans;
+ //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)
+{
+ 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)
+{
+ this->master = master;
+ resize(800,500);
+
+ /** Setup the controller widget **/
+
+ 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);
+ 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()));
+ 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)));
+ QObject::connect(opsController->horizontalSlider_askedge, SIGNAL(valueChanged(int)), this, SLOT(vchange_askedge(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");
+}
- painter.setFont(QFont("Arial", 10));
+// 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(GraphStart < 0) {
- GraphStart = 0;
+ if (opsController) {
+ delete opsController;
+ opsController = NULL;
}
- if (CursorAPos > GraphTraceLen)
- CursorAPos= 0;
- if(CursorBPos > GraphTraceLen)
- CursorBPos= 0;
- if(CursorCPos > GraphTraceLen)
- CursorCPos= 0;
- if(CursorDPos > GraphTraceLen)
- CursorDPos= 0;
+ if (plot) {
+ plot->close();
+ delete plot;
+ plot = NULL;
+ }
+}
+void ProxWidget::closeEvent(QCloseEvent *event)
+{
+ event->ignore();
+ this->hide();
+ g_useOverlays = false;
+}
+void ProxWidget::hideEvent(QHideEvent *event) {
+ controlWidget->hide();
+ plot->hide();
+}
+void ProxWidget::showEvent(QShowEvent *event) {
+ controlWidget->show();
+ plot->show();
+}
- r = rect();
+//----------- Plotting
- painter.fillRect(r, QColor(0, 0, 0));
+int Plot::xCoordOf(int i, QRect r )
+{
+ return r.left() + (int)((i - GraphStart)*GraphPixelsPerPoint);
+}
- whitePath.moveTo(r.left() + 40, r.top());
- whitePath.lineTo(r.left() + 40, r.bottom());
+int Plot::yCoordOf(int v, QRect r, int maxVal)
+{
+ int z = (r.bottom() - r.top())/2;
+ return -(z * v) / maxVal + z;
+}
- int zeroHeight = r.top() + (r.bottom() - r.top()) / 2;
+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);
- greyPath.moveTo(r.left(), zeroHeight);
- greyPath.lineTo(r.right(), zeroHeight);
- painter.setPen(QColor(100, 100, 100));
- painter.drawPath(greyPath);
-
- 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));
+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::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;
+ }
- int absYMax = 1;
+ 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);
+}
- 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;
+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 > (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);
+
+ 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 < (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;
+
+ 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;
}
- 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;
+ //Graph annotations
+ painter->drawPath(penPath);
+}
- for(i = GraphStart; ; i++) {
- if(i >= GraphTraceLen) {
- break;
- }
- int x = 40 + (int)((i - GraphStart)*GraphPixelsPerPoint);
- if(x > r.right() + GraphPixelsPerPoint) {
- break;
- }
+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;
+ int vMin = INT_MAX, vMax = INT_MIN, vMean = 0, v = 0, i = 0;
+ int x = xCoordOf(GraphStart, plotRect);
+ int y = yCoordOf(buffer[GraphStart],plotRect,g_absVMax);
+ penPath.moveTo(x, y);
+ for(i = GraphStart; i < len && xCoordOf(i, plotRect) < plotRect.right(); i++) {
- int y = GraphBuffer[i];
- if(y < yMin) {
- yMin = y;
- }
- if(y > yMax) {
- yMax = y;
- }
- yMean += y;
- n++;
+ x = xCoordOf(i, plotRect);
+ v = buffer[i];
- y = (y * (r.top() - r.bottom()) / (2*absYMax)) + zeroHeight;
- if(i == GraphStart) {
- penPath.moveTo(x, y);
- } else {
- penPath.lineTo(x, y);
- }
+ y = yCoordOf( v, plotRect, g_absVMax);
+
+ penPath.lineTo(x, y);
if(GraphPixelsPerPoint > 10) {
QRect f(QPoint(x - 3, y - 3),QPoint(x + 3, y + 3));
- painter.fillRect(f, brush);
+ painter->fillRect(f, QColor(100, 255, 100));
}
+ //catch stats
+ if(v < vMin) vMin = v;
+ if(v > vMax) vMax = v;
+ vMean += v;
+ }
+ vMean /= (i - GraphStart);
- if(((i - GraphStart) % pointsPerLabel == 0) && i != GraphStart) {
- whitePath.moveTo(x, zeroHeight - 3);
- whitePath.lineTo(x, zeroHeight + 3);
+ painter->setPen(getColor(graphNum));
- char str[100];
- sprintf(str, "+%d", (i - GraphStart));
+ //Draw y-axis
+ int xo = 5+(graphNum*40);
+ painter->drawLine(xo, plotRect.top(),xo, plotRect.bottom());
- 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);
+ int vMarkers = (g_absVMax - (g_absVMax % 10)) / 5;
+ int minYDist = 40; //Minimum pixel-distance between markers
- penPath.moveTo(x,y);
- }
+ char yLbl[20];
+
+ int n = 0;
+ int lasty0 = 65535;
- if(i == CursorAPos || i == CursorBPos || i == CursorCPos || i == CursorDPos) {
- QPainterPath *cursorPath;
+ for(v = vMarkers; yCoordOf(v,plotRect,g_absVMax) > plotRect.top() && n < 20; v+= vMarkers ,n++)
+ {
+ int y0 = yCoordOf(v,plotRect,g_absVMax);
+ int y1 = yCoordOf(-v,plotRect,g_absVMax);
- 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(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, i, 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)
+{
+ // 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 = (offset * GraphPixelsPerPoint); i < r.right(); i += grid_delta_x) {
+ painter->drawLine(r.left()+i, r.top(), r.left()+i, r.bottom());
+ }
+ }
+ 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) );
}
}
+}
+
+#define HEIGHT_INFO 60
+#define WIDTH_AXES 80
+
+void Plot::paintEvent(QPaintEvent *event)
+{
+
+ QPainter painter(this);
+ QBrush brush(QColor(100, 255, 100));
+ QPen pen(QColor(100, 255, 100));
+
+ painter.setFont(QFont("Courier New", 10));
+
+ if(GraphStart < 0) {
+ GraphStart = 0;
+ }
+
+ if (CursorAPos > GraphTraceLen)
+ CursorAPos= 0;
+ if(CursorBPos > GraphTraceLen)
+ CursorBPos= 0;
+ if(CursorCPos > GraphTraceLen)
+ CursorCPos= 0;
+ if(CursorDPos > GraphTraceLen)
+ CursorDPos= 0;
+
+ QRect plotRect(WIDTH_AXES, 0, width()-WIDTH_AXES, height()-HEIGHT_INFO);
+ QRect infoRect(0, height()-HEIGHT_INFO, width(), HEIGHT_INFO);
- if(n != 0) {
- yMean /= n;
+ //Grey background
+ painter.fillRect(rect(), QColor(60, 60, 60));
+ //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));
+ painter.drawLine(plotRect.left(), zeroHeight, plotRect.right(), zeroHeight);
+ // plot X and Y grid lines
+ 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);
}
+ if (g_useOverlays) {
+ //init graph variables
+ setMaxAndStart(s_Buff,GraphTraceLen,plotRect);
+ PlotGraph(s_Buff, GraphTraceLen,plotRect,infoRect,&painter,1);
+ }
+ // End graph drawing
- 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 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());
+ }
+ //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)
{
+ //Need to set this, otherwise we don't receive keypress events
+ setFocusPolicy( Qt::StrongFocus);
resize(600, 300);
QPalette palette(QColor(0,0,0,0));
setAutoFillBackground(true);
CursorAPos = 0;
CursorBPos = 0;
+
+ setWindowTitle(tr("Sliders"));
}
-void ProxWidget::closeEvent(QCloseEvent *event)
+void Plot::closeEvent(QCloseEvent *event)
{
event->ignore();
this->hide();
+ g_useOverlays = false;
}
-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)) {
this->update();
}
-void ProxWidget::keyPressEvent(QKeyEvent *event)
+void Plot::keyPressEvent(QKeyEvent *event)
{
int offset;
- int gridchanged;
-
- gridchanged= 0;
if(event->modifiers() & Qt::ShiftModifier) {
if (PlotGridX)
case Qt::Key_Right:
if(GraphPixelsPerPoint < 20) {
- if (PlotGridX && GridLocked && GraphStart < startMax){
- GridOffset -= offset;
- GridOffset %= PlotGridX;
- gridchanged= 1;
- }
GraphStart += offset;
} else {
- if (PlotGridX && GridLocked && GraphStart < startMax){
- GridOffset--;
- GridOffset %= PlotGridX;
- gridchanged= 1;
- }
GraphStart++;
}
- if(GridOffset < 0) {
- GridOffset += PlotGridX;
- }
- if (gridchanged)
- if (GraphStart > startMax) {
- GridOffset += (GraphStart - startMax);
- GridOffset %= PlotGridX;
- }
break;
case Qt::Key_Left:
if(GraphPixelsPerPoint < 20) {
- if (PlotGridX && GridLocked && GraphStart > 0){
- GridOffset += offset;
- GridOffset %= PlotGridX;
- gridchanged= 1;
- }
GraphStart -= offset;
} else {
- if (PlotGridX && GridLocked && GraphStart > 0){
- GridOffset++;
- GridOffset %= PlotGridX;
- gridchanged= 1;
- }
GraphStart--;
}
- if (gridchanged){
- if (GraphStart < 0)
- GridOffset += GraphStart;
- if(GridOffset < 0)
- GridOffset += PlotGridX;
- GridOffset %= PlotGridX;
- }
break;
case Qt::Key_G:
} else {
PlotGridX= PlotGridXdefault;
PlotGridY= PlotGridYdefault;
- }
+ }
break;
case Qt::Key_H:
break;
case Qt::Key_L:
- GridLocked= !GridLocked;
+ GridLocked = !GridLocked;
+ if (GridLocked)
+ GridOffset += (GraphStart - unlockStart);
+ else
+ unlockStart = GraphStart;
break;
case Qt::Key_Q:
// GUI (QT)
//-----------------------------------------------------------------------------
+#ifndef PROXGUI_QT
+#define PROXGUI_QT
+
#include <QApplication>
#include <QPushButton>
#include <QObject>
#include <QWidget>
#include <QPainter>
+#include <QtGui>
+
+#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);
+ void setMaxAndStart(int *buffer, int len, QRect plotRect);
+ 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;
+ Q_OBJECT; //needed for slot/signal classes
private:
- int GraphStart;
- double GraphPixelsPerPoint;
- int CursorAPos;
- int CursorBPos;
+ ProxGuiQT *master;
+ Plot *plot;
+ Ui::Form *opsController;
+ QWidget* controlWidget;
public:
- ProxWidget(QWidget *parent = 0);
+ ProxWidget(QWidget *parent = 0, ProxGuiQT *master = NULL);
+ ~ProxWidget(void);
+ //OpsShow(void);
protected:
- void paintEvent(QPaintEvent *event);
+ // void paintEvent(QPaintEvent *event);
void closeEvent(QCloseEvent *event);
- void mouseMoveEvent(QMouseEvent *event);
- void mousePressEvent(QMouseEvent *event) { mouseMoveEvent(event); }
- void keyPressEvent(QKeyEvent *event);
+ void showEvent(QShowEvent *event);
+ void hideEvent(QHideEvent *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_askedge(int v);
+ void vchange_dthr_up(int v);
+ void vchange_dthr_down(int v);
};
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
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);
rarg.run = 0;
pthread_join(reader_thread, NULL);
}
-
+
+ ExitGraphics();
+
if (script_file) {
fclose(script_file);
script_file = NULL;
}
-
- ExitGraphics();
pthread_exit(NULL);
return NULL;
}
.usb_present = 0,
.script_cmds_file = NULL
};
- pthread_t main_loop_threat;
+ pthread_t main_loop_thread;
sp = uart_open(argv[1]);
// 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) {
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
+#include <stdbool.h>
#include <readline/readline.h>
#include <pthread.h>
#include "ui.h"
-double CursorScaleFactor;
-int PlotGridX, PlotGridY, PlotGridXdefault= 64, PlotGridYdefault= 64, CursorCPos= 0, CursorDPos= 0;
+double CursorScaleFactor = 1;
+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;
static char *logfilename = "proxmark3.log";
#ifndef UI_H__
#define UI_H__
+#include <stdbool.h>
+#include <stdint.h>
+
void ShowGui(void);
void HideGraphWindow(void);
void ShowGraphWindow(void);
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;
+extern bool showDemod;
#endif
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Form</class>
+ <widget class="QWidget" name="Form">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>614</width>
+ <height>286</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Overlays</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <item>
+ <widget class="QTabWidget" name="tabWidget_overlays">
+ <property name="currentIndex">
+ <number>1</number>
+ </property>
+ <widget class="QWidget" name="tab">
+ <property name="focusPolicy">
+ <enum>Qt::StrongFocus</enum>
+ </property>
+ <attribute name="title">
+ <string>Autocorrelate</string>
+ </attribute>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <layout class="QFormLayout" name="formLayout">
+ <item row="0" column="1">
+ <widget class="QLabel" name="label_5">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Window size</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QSlider" name="horizontalSlider_window">
+ <property name="minimum">
+ <number>10</number>
+ </property>
+ <property name="maximum">
+ <number>10000</number>
+ </property>
+ <property name="value">
+ <number>2000</number>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="tab_3">
+ <attribute name="title">
+ <string>AskEdge</string>
+ </attribute>
+ <layout class="QVBoxLayout" name="verticalLayout_4">
+ <item>
+ <layout class="QFormLayout" name="formLayout_4">
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_8">
+ <property name="text">
+ <string>Edge Jump Threshold</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLabel" name="label_9">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QSlider" name="horizontalSlider_askedge">
+ <property name="minimum">
+ <number>5</number>
+ </property>
+ <property name="maximum">
+ <number>80</number>
+ </property>
+ <property name="value">
+ <number>20</number>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer_3">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="tab_2">
+ <attribute name="title">
+ <string>Dirthreshold</string>
+ </attribute>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QFormLayout" name="formLayout_2">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Up</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLabel" name="label_6">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QSlider" name="horizontalSlider_dirthr_up">
+ <property name="maximum">
+ <number>128</number>
+ </property>
+ <property name="value">
+ <number>20</number>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QFormLayout" name="formLayout_3">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Down</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLabel" name="label_7">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QSlider" name="horizontalSlider_dirthr_down">
+ <property name="maximum">
+ <number>127</number>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QPushButton" name="pushButton_apply">
+ <property name="text">
+ <string>Apply</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButton_sticky">
+ <property name="text">
+ <string>Restore</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_4">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>horizontalSlider_window</sender>
+ <signal>valueChanged(int)</signal>
+ <receiver>label_4</receiver>
+ <slot>setNum(int)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>46</x>
+ <y>118</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>597</x>
+ <y>257</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>horizontalSlider_window</sender>
+ <signal>valueChanged(int)</signal>
+ <receiver>label_5</receiver>
+ <slot>setNum(int)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>170</x>
+ <y>118</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>161</x>
+ <y>69</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>horizontalSlider_dirthr_up</sender>
+ <signal>valueChanged(int)</signal>
+ <receiver>label_6</receiver>
+ <slot>setNum(int)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>70</x>
+ <y>118</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>68</x>
+ <y>67</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>horizontalSlider_dirthr_down</sender>
+ <signal>valueChanged(int)</signal>
+ <receiver>label_7</receiver>
+ <slot>setNum(int)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>201</x>
+ <y>185</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>149</x>
+ <y>135</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>horizontalSlider_askedge</sender>
+ <signal>valueChanged(int)</signal>
+ <receiver>label_9</receiver>
+ <slot>setNum(int)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>149</x>
+ <y>102</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>250</x>
+ <y>70</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
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};
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-----------------------------------
//**********************************************************************************************
}
//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;
*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
//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;
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;
//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);
size = aggregate_bits(dest, size, rfLen, invert, fchigh, fclow, startIdx);
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
// 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;
- if (justNoise(dest, *size)) return -2;
-
// 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};
}
// 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;
-
+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};
return (int)startIdx;
}
-int IOdemodFSK(uint8_t *dest, size_t size) {
- if (justNoise(dest, size)) return -1;
+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
}
// 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;
-
+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
// 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;
- //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
+ *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};
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);
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 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 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, 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);
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);