Merge pull request #164 from marshmellow42/master

fix issue #163, prevent two calls to getFromGraphBuf - fix char array pointer...
This commit is contained in:
Martin Holst Swende 2016-02-16 15:39:52 +01:00
commit b12f076b0d

View file

@ -919,19 +919,21 @@ int CmdDetectClockRate(const char *Cmd)
char *GetFSKType(uint8_t fchigh, uint8_t fclow, uint8_t invert)
{
char *fskType;
static char fType[8];
memset(fType, 0x00, 8);
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;
}
@ -959,17 +961,18 @@ int FSKrawDemod(const char *Cmd, bool verbose)
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) {
@ -982,11 +985,10 @@ int FSKrawDemod(const char *Cmd, bool verbose)
// 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");