simpler debug printing

This commit is contained in:
iceman1001 2018-02-21 16:36:40 +01:00
commit 555b261eab
4 changed files with 72 additions and 75 deletions

View file

@ -250,7 +250,7 @@ int CmdAWIDDemod(const char *Cmd) {
int waveIdx = 0;
int idx = detectAWID(bits, &size, &waveIdx);
if (idx <= 0){
if (g_debugMode){
if (idx == -1)
PrintAndLogEx(DEBUG, "DEBUG: Error - AWID not enough samples");
else if (idx == -2)
@ -263,7 +263,7 @@ int CmdAWIDDemod(const char *Cmd) {
PrintAndLogEx(DEBUG, "DEBUG: Error - AWID size not correct, size %d", size);
else
PrintAndLogEx(DEBUG, "DEBUG: Error - AWID error demoding fsk %d",idx);
}
return 0;
}

View file

@ -363,7 +363,7 @@ int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo ) {
int ans = Em410xDecode(bits, &size, &idx, hi, lo);
if ( ans < 0){
if (g_debugMode){
if (ans == -1)
PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x not only 0|1 in decoded bitstream");
else if (ans == -2)
@ -374,7 +374,7 @@ int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo ) {
PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x Size not correct: %d", size);
else if (ans == -6)
PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x parity failed");
}
return 0;
}
if (!lo && !hi) {
@ -385,10 +385,10 @@ int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo ) {
//set GraphBuffer for clone or sim command
setDemodBuf(DemodBuffer, (size==40) ? 64 : 128, idx+1);
setClockGrid(g_DemodClock, g_DemodStartIdx + ((idx+1)*g_DemodClock));
if (g_debugMode){
PrintAndLogEx(DEBUG, "DEBUG: Em410x idx: %d, Len: %d, Printing Demod Buffer:", idx, size);
if (g_debugMode)
printDemodBuff();
}
if (verbose)
printEM410x(*hi, *lo);
@ -1009,7 +1009,7 @@ bool doPreambleSearch(size_t *startIdx){
// sanity check
if ( DemodBufferLen < EM_PREAMBLE_LEN) {
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - EM4305 demodbuffer too small");
PrintAndLogEx(DEBUG, "DEBUG: Error - EM4305 demodbuffer too small");
return false;
}
@ -1020,7 +1020,7 @@ bool doPreambleSearch(size_t *startIdx){
uint8_t preamble[EM_PREAMBLE_LEN] = {0,0,1,0,1,0};
if ( !preambleSearchEx(DemodBuffer, preamble, EM_PREAMBLE_LEN, &size, startIdx, true)) {
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - EM4305 preamble not found :: %d", *startIdx);
PrintAndLogEx(DEBUG, "DEBUG: Error - EM4305 preamble not found :: %d", *startIdx);
return false;
}
return true;
@ -1029,13 +1029,13 @@ bool doPreambleSearch(size_t *startIdx){
bool detectFSK(){
// detect fsk clock
if (!GetFskClock("", false)) {
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - EM: FSK clock failed");
PrintAndLogEx(DEBUG, "DEBUG: Error - EM: FSK clock failed");
return false;
}
// demod
int ans = FSKrawDemod("0 0", false);
if (!ans) {
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - EM: FSK Demod failed");
PrintAndLogEx(DEBUG, "DEBUG: Error - EM: FSK Demod failed");
return false;
}
return true;
@ -1044,19 +1044,19 @@ bool detectFSK(){
bool detectPSK(){
int ans = GetPskClock("", false);
if (ans <= 0) {
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - EM: PSK clock failed");
PrintAndLogEx(DEBUG, "DEBUG: Error - EM: PSK clock failed");
return false;
}
//demod
//try psk1 -- 0 0 6 (six errors?!?)
ans = PSKDemod("0 0 6", false);
if (!ans) {
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - EM: PSK1 Demod failed");
PrintAndLogEx(DEBUG, "DEBUG: Error - EM: PSK1 Demod failed");
//try psk1 inverted
ans = PSKDemod("0 1 6", false);
if (!ans) {
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - EM: PSK1 inverted Demod failed");
PrintAndLogEx(DEBUG, "DEBUG: Error - EM: PSK1 inverted Demod failed");
return false;
}
}
@ -1068,7 +1068,7 @@ bool detectPSK(){
bool detectASK_MAN(){
bool stcheck = false;
if ( !ASKDemod_ext("0 0 0", false, false, 1, &stcheck) ) {
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - EM: ASK/Manchester Demod failed");
PrintAndLogEx(DEBUG, "DEBUG: Error - EM: ASK/Manchester Demod failed");
return false;
}
return true;
@ -1094,13 +1094,13 @@ bool setDemodBufferEM(uint32_t *word, size_t idx){
uint8_t parity[45] = {0};
memcpy( parity, DemodBuffer, 45);
if (!EMwordparitytest(parity) ){
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - EM Parity tests failed");
PrintAndLogEx(DEBUG, "DEBUG: Error - EM Parity tests failed");
return false;
}
// test for even parity bits and remove them. (leave out the end row of parities so 36 bits)
if (!removeParity(DemodBuffer, idx + EM_PREAMBLE_LEN, 9, 0, 36)) {
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - EM, failed removing parity");
PrintAndLogEx(DEBUG, "DEBUG: Error - EM, failed removing parity");
return false;
}
setDemodBuf(DemodBuffer, 32, 0);

View file

@ -168,23 +168,23 @@ int CmdFDXBdemodBI(const char *Cmd){
errCnt = askdemod(BitStream, &size, &clk, &invert, maxErr, 0, 0);
if ( errCnt < 0 || errCnt > maxErr ) {
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - FDXB no data or error found %d, clock: %d", errCnt, clk);
PrintAndLogEx(DEBUG, "DEBUG: Error - FDXB no data or error found %d, clock: %d", errCnt, clk);
return 0;
}
errCnt = BiphaseRawDecode(BitStream, &size, &offset, 1);
if (errCnt < 0 || errCnt > maxErr ) {
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - FDXB BiphaseRawDecode: %d", errCnt);
PrintAndLogEx(DEBUG, "DEBUG: Error - FDXB BiphaseRawDecode: %d", errCnt);
return 0;
}
int preambleIndex = detectFDXB(BitStream, &size);
if (preambleIndex < 0){
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - FDXB preamble not found :: %d",preambleIndex);
PrintAndLogEx(DEBUG, "DEBUG: Error - FDXB preamble not found :: %d",preambleIndex);
return 0;
}
if (size != 128) {
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - FDXB incorrect data length found");
PrintAndLogEx(DEBUG, "DEBUG: Error - FDXB incorrect data length found");
return 0;
}
@ -193,7 +193,7 @@ int CmdFDXBdemodBI(const char *Cmd){
// remove marker bits (1's every 9th digit after preamble) (pType = 2)
size = removeParity(BitStream, preambleIndex + 11, 9, 2, 117);
if ( size != 104 ) {
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - FDXB error removeParity:: %d", size);
PrintAndLogEx(DEBUG, "DEBUG: Error - FDXB error removeParity:: %d", size);
return 0;
}
PrintAndLogEx(NORMAL, "\nFDX-B / ISO 11784/5 Animal Tag ID Found:");
@ -211,7 +211,7 @@ int CmdFDXBdemodBI(const char *Cmd){
uint8_t raw[8];
num_to_bytes(rawid, 8, raw);
if (g_debugMode) PrintAndLogEx(NORMAL, "Raw ID Hex: %s", sprint_hex(raw,8));
PrintAndLogEx(NORMAL, "Raw ID Hex: %s", sprint_hex(raw,8));
uint16_t calcCrc = crc16_kermit(raw, 8);
PrintAndLogEx(NORMAL, "Animal ID: %04u-%012" PRIu64, countryCode, NationalCode);
@ -224,7 +224,7 @@ int CmdFDXBdemodBI(const char *Cmd){
PrintAndLogEx(NORMAL, "CRC: 0x%04X - [%04X] - %s", crc16, calcCrc, (calcCrc == crc16) ? "Passed" : "Failed");
if (g_debugMode) {
PrintAndLogEx(NORMAL, "Start marker %d; Size %d", preambleIndex, size);
PrintAndLogEx(DEBUG, "Start marker %d; Size %d", preambleIndex, size);
char *bin = sprint_bin_break(BitStream,size,16);
PrintAndLogEx(DEBUG, "DEBUG BinStream:\n%s",bin);
}
@ -239,13 +239,13 @@ int CmdFdxDemod(const char *Cmd) {
//Differential Biphase / di-phase (inverted biphase)
//get binary from ask wave
if (!ASKbiphaseDemod("0 32 1 0", false)) {
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B ASKbiphaseDemod failed");
PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B ASKbiphaseDemod failed");
return 0;
}
size_t size = DemodBufferLen;
int preambleIndex = detectFDXB(DemodBuffer, &size);
if (preambleIndex < 0){
if (g_debugMode){
if (preambleIndex == -1)
PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B too few bits found");
else if (preambleIndex == -2)
@ -254,7 +254,6 @@ int CmdFdxDemod(const char *Cmd) {
PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B Size not correct: %d", size);
else
PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B ans: %d", preambleIndex);
}
return 0;
}
@ -264,7 +263,7 @@ int CmdFdxDemod(const char *Cmd) {
// remove marker bits (1's every 9th digit after preamble) (pType = 2)
size = removeParity(DemodBuffer, 11, 9, 2, 117);
if ( size != 104 ) {
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B error removeParity: %d", size);
PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B error removeParity: %d", size);
return 0;
}
@ -293,7 +292,7 @@ int CmdFdxDemod(const char *Cmd) {
PrintAndLogEx(NORMAL, "CRC-16 0x%04X - 0x%04X [%s]", crc16, calcCrc, (calcCrc == crc16) ? "Ok" : "Failed");
if (g_debugMode) {
PrintAndLogEx(NORMAL, "Start marker %d; Size %d", preambleIndex, size);
PrintAndLogEx(DEBUG, "Start marker %d; Size %d", preambleIndex, size);
char *bin = sprint_bin_break(DemodBuffer, size, 16);
PrintAndLogEx(DEBUG, "DEBUG bin stream:\n%s", bin);
}

View file

@ -177,7 +177,7 @@ int CmdGuardDemod(const char *Cmd) {
//Differential Biphase
//get binary from ask wave
if (!ASKbiphaseDemod("0 64 0 0", false)) {
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII ASKbiphaseDemod failed");
PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII ASKbiphaseDemod failed");
return 0;
}
@ -185,7 +185,7 @@ int CmdGuardDemod(const char *Cmd) {
int preambleIndex = detectGProxII(DemodBuffer, &size);
if (preambleIndex < 0){
if (g_debugMode){
if (preambleIndex == -1)
PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII too few bits found");
else if (preambleIndex == -2)
@ -196,7 +196,6 @@ int CmdGuardDemod(const char *Cmd) {
PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII wrong spacerbits");
else
PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII ans: %d", preambleIndex);
}
return 0;
}
@ -211,7 +210,6 @@ int CmdGuardDemod(const char *Cmd) {
// remove the 18 (90/5=18) parity bits (down to 72 bits (96-6-18=72))
size_t len = removeParity(bits_no_spacer, 0, 5, 3, 90); //source, startloc, paritylen, ptype, length_to_run
if (len != 72) {
if (g_debugMode)
PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII spacer removal did not produce 72 bits: %u, start: %u", len, startIdx);
return 0;
}
@ -219,7 +217,7 @@ int CmdGuardDemod(const char *Cmd) {
xorKey = (uint8_t)bytebits_to_byteLSBF(bits_no_spacer, 8);
for (size_t idx = 0; idx < 8; idx++) {
ByteStream[idx] = ((uint8_t)bytebits_to_byteLSBF(bits_no_spacer+8 + (idx*8),8)) ^ xorKey;
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: gProxII byte %u after xor: %02x", (unsigned int)idx, ByteStream[idx]);
PrintAndLogEx(DEBUG, "DEBUG: gProxII byte %u after xor: %02x", (unsigned int)idx, ByteStream[idx]);
}
setDemodBuf(DemodBuffer, 96, preambleIndex);