add offset option to data printdemodbuffer

easily see demod buffer's hex values at different bit offsets by using:
data printdemodbuffer x o <offset>
This commit is contained in:
marshmellow42 2015-05-28 13:23:31 -04:00
parent e35031d2b7
commit 979bba376d

View file

@ -55,6 +55,15 @@ int CmdSetDebugMode(const char *Cmd)
return 1; return 1;
} }
int usage_data_printdemodbuf(){
PrintAndLog("Usage: data printdemodbuffer x o <offset>");
PrintAndLog("Options: ");
PrintAndLog(" h This help");
PrintAndLog(" x output in hex (omit for binary output)");
PrintAndLog(" o <offset> enter offset in # of bits");
return 0;
}
//by marshmellow //by marshmellow
void printDemodBuff(void) void printDemodBuff(void)
{ {
@ -73,23 +82,50 @@ void printDemodBuff(void)
int CmdPrintDemodBuff(const char *Cmd) int CmdPrintDemodBuff(const char *Cmd)
{ {
char hex; char hex[512]={0x00};
char printBuff[512]={0x00}; bool hexMode = false;
uint8_t numBits = DemodBufferLen & 0xFFFC; bool errors = false;
sscanf(Cmd, "%c", &hex); uint8_t offset = 0;
if (hex == 'h'){ char cmdp = 0;
PrintAndLog("Usage: data printdemodbuffer [x]"); while(param_getchar(Cmd, cmdp) != 0x00)
PrintAndLog("Options: "); {
PrintAndLog(" h This help"); switch(param_getchar(Cmd, cmdp))
PrintAndLog(" x output in hex (omit for binary output)"); {
return 0; case 'h':
case 'H':
return usage_data_printdemodbuf();
case 'x':
case 'X':
hexMode = true;
cmdp++;
break;
case 'o':
case 'O':
offset = param_get8(Cmd, cmdp+1);
if (!offset) errors = true;
cmdp += 2;
break;
default:
PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
errors = true;
break;
} }
if (hex == 'x'){ if(errors) break;
numBits = binarraytohex(printBuff, (char *)DemodBuffer, numBits); }
//Validations
if(errors) return usage_data_printdemodbuf();
int numBits = (DemodBufferLen-offset) & 0x7FC; //make sure we don't exceed our string
if (hexMode){
char *buf = DemodBuffer + offset;
numBits = binarraytohex(hex, buf, numBits);
if (numBits==0) return 0; if (numBits==0) return 0;
PrintAndLog("DemodBuffer: %s",printBuff); PrintAndLog("DemodBuffer: %s",hex);
} else { } else {
printDemodBuff(); //setDemodBuf(DemodBuffer, DemodBufferLen-offset, offset);
char *bin = sprint_bin_break(DemodBuffer+offset,numBits,16);
PrintAndLog("DemodBuffer:\n%s",bin);
} }
return 1; return 1;
} }
@ -2182,7 +2218,7 @@ static command_t CommandTable[] =
{"manrawdecode", Cmdmandecoderaw, 1, "[invert] [maxErr] -- Manchester decode binary stream in DemodBuffer"}, {"manrawdecode", Cmdmandecoderaw, 1, "[invert] [maxErr] -- Manchester decode binary stream in DemodBuffer"},
{"norm", CmdNorm, 1, "Normalize max/min to +/-128"}, {"norm", CmdNorm, 1, "Normalize max/min to +/-128"},
{"plot", CmdPlot, 1, "Show graph window (hit 'h' in window for keystroke help)"}, {"plot", CmdPlot, 1, "Show graph window (hit 'h' in window for keystroke help)"},
{"printdemodbuffer",CmdPrintDemodBuff, 1, "[x] -- print the data in the DemodBuffer - 'x' for hex output"}, {"printdemodbuffer",CmdPrintDemodBuff, 1, "[x] [o] <offset> -- print the data in the DemodBuffer - 'x' for hex output"},
{"pskindalademod", CmdIndalaDecode, 1, "[clock] [invert<0|1>] -- Demodulate an indala tag (PSK1) from GraphBuffer (args optional)"}, {"pskindalademod", CmdIndalaDecode, 1, "[clock] [invert<0|1>] -- Demodulate an indala tag (PSK1) from GraphBuffer (args optional)"},
{"psknexwatchdemod",CmdPSKNexWatch, 1, "Demodulate a NexWatch tag (nexkey, quadrakey) (PSK1) from GraphBuffer"}, {"psknexwatchdemod",CmdPSKNexWatch, 1, "Demodulate a NexWatch tag (nexkey, quadrakey) (PSK1) from GraphBuffer"},
{"rawdemod", CmdRawDemod, 1, "[modulation] ... <options> -see help (h option) -- Demodulate the data in the GraphBuffer and output binary"}, {"rawdemod", CmdRawDemod, 1, "[modulation] ... <options> -see help (h option) -- Demodulate the data in the GraphBuffer and output binary"},