From a0cc89b47902cf6f61e08fceda9ac78df85b012e Mon Sep 17 00:00:00 2001 From: marshmellow42 Date: Mon, 15 Feb 2016 21:39:34 -0500 Subject: [PATCH 1/4] use different fsk field clock detection routine ... ... to prevent double call to getFromGraphBuf()... also adjust %hu to u and as there is a possible problem with %hu in printf. --- client/cmddata.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/client/cmddata.c b/client/cmddata.c index 6dd96ab0..55e2daca 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -951,42 +951,42 @@ int FSKrawDemod(const char *Cmd, bool verbose) fchigh = param_get8(Cmd, 2); fclow = param_get8(Cmd, 3); if (strlen(Cmd)>0 && strlen(Cmd)<=2) { - if (rfLen==1){ + if (rfLen==1) { invert = 1; //if invert option only is used rfLen = 0; - } + } } uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0}; size_t BitLen = getFromGraphBuf(BitStream); if (BitLen==0) return 0; + if (g_debugMode==2) PrintAndLog("DEBUG: Got samples"); //get field clock lengths - uint8_t fc1=0, fc2=0, rf1=0; + uint16_t fcs=0; if (!fchigh || !fclow) { - uint8_t ans = fskClocks(&fc1, &fc2, &rf1, false); - if (ans == 0) { - if (g_debugMode) PrintAndLog("\nError: cannot detect valid fsk field clocks"); - return 0; // can't detect field clock + fcs = countFC(BitStream, BitLen, 1); + if (!fcs) { + fchigh = 10; + fclow = 8; + } else { + fchigh = (fcs >> 8) & 0x00FF; + fclow = fcs & 0x00FF; } - fchigh = fc1; - fclow = fc2; - if (rfLen == 0) rfLen = rf1; } //get bit clock length - if (!rfLen){ + if (!rfLen) { rfLen = detectFSKClk(BitStream, BitLen, fchigh, fclow); if (!rfLen) rfLen = 50; } int size = fskdemod(BitStream, BitLen, rfLen, invert, fchigh, fclow); - if (size > 0){ + if (size > 0) { setDemodBuf(BitStream,size,0); // Now output the bitstream to the scrollback by line of 16 bits if (verbose || g_debugMode) { - PrintAndLog("\nUsing Clock:%hu, invert:%hu, fchigh:%hu, fclow:%hu", rfLen, invert, fchigh, fclow); + 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)); printDemodBuff(); } - return 1; } else { if (g_debugMode) PrintAndLog("no FSK data found"); From 0c50084a2b7f5172796582441c3ce9204a752fc8 Mon Sep 17 00:00:00 2001 From: marshmellow42 Date: Mon, 15 Feb 2016 22:31:21 -0500 Subject: [PATCH 2/4] fix char* pointer not assigned fix --- client/cmddata.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/cmddata.c b/client/cmddata.c index 55e2daca..f4e16175 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -919,7 +919,8 @@ int CmdDetectClockRate(const char *Cmd) char *GetFSKType(uint8_t fchigh, uint8_t fclow, uint8_t invert) { - char *fskType; + static char fType[8]; + char *fskType = fType; if (fchigh==10 && fclow==8){ if (invert) //fsk2a fskType = "FSK2a"; From 9e4cee22b79ac2da6f54b7949fab59206d1d7e6b Mon Sep 17 00:00:00 2001 From: marshmellow42 Date: Mon, 15 Feb 2016 22:36:51 -0500 Subject: [PATCH 3/4] clear char array with each call --- client/cmddata.c | 1 + 1 file changed, 1 insertion(+) diff --git a/client/cmddata.c b/client/cmddata.c index f4e16175..c43dfaf1 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -920,6 +920,7 @@ int CmdDetectClockRate(const char *Cmd) char *GetFSKType(uint8_t fchigh, uint8_t fclow, uint8_t invert) { static char fType[8]; + memset(fType, 0x00, 8); char *fskType = fType; if (fchigh==10 && fclow==8){ if (invert) //fsk2a From 38b3509542c4a5451a5701be0b073acbd7f79465 Mon Sep 17 00:00:00 2001 From: marshmellow42 Date: Tue, 16 Feb 2016 09:38:37 -0500 Subject: [PATCH 4/4] use memcpy instead of re-assign pointer --- client/cmddata.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/client/cmddata.c b/client/cmddata.c index c43dfaf1..900cfc83 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -924,16 +924,16 @@ char *GetFSKType(uint8_t fchigh, uint8_t fclow, uint8_t invert) char *fskType = fType; if (fchigh==10 && fclow==8){ if (invert) //fsk2a - fskType = "FSK2a"; + memcpy(fskType, "FSK2a", 5); else //fsk2 - fskType = "FSK2"; + memcpy(fskType, "FSK2", 4); } else if (fchigh == 8 && fclow == 5) { if (invert) - fskType = "FSK1"; + memcpy(fskType, "FSK1", 4); else - fskType = "FSK1a"; + memcpy(fskType, "FSK1a", 5); } else { - fskType = "FSK??"; + memcpy(fskType, "FSK??", 5); } return fskType; }