diff --git a/client/cmddata.c b/client/cmddata.c index 7d8cef081..f4bfb3ff4 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -456,8 +456,8 @@ int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType, int maxErr = 100; int maxLen = 0; uint8_t askamp = 0; - char amp = param_getchar(Cmd, 0); - uint8_t BitStream[MAX_GRAPH_TRACE_LEN] = {0}; + char amp = tolower(param_getchar(Cmd, 0)); + uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0}; sscanf(Cmd, "%i %i %i %i %c", &clk, &invert, &maxErr, &maxLen, &); @@ -473,7 +473,7 @@ int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType, clk = 0; } - size_t BitLen = getFromGraphBuf(BitStream); + size_t BitLen = getFromGraphBuf(bits); PrintAndLogEx(DEBUG, "DEBUG: (ASKDemod_ext) Bitlen from grphbuff: %d", BitLen); @@ -483,13 +483,13 @@ int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType, int foundclk = 0; //amp before ST check - if (amp == 'a' || amp == 'A') - askAmp(BitStream, BitLen); + if (amp == 'a') + askAmp(bits, BitLen); bool st = false; size_t ststart = 0, stend = 0; if (*stCheck) - st = DetectST(BitStream, &BitLen, &foundclk, &ststart, &stend); + st = DetectST(bits, &BitLen, &foundclk, &ststart, &stend); if (st) { *stCheck = st; @@ -501,10 +501,10 @@ int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType, } int startIdx = 0; - int errCnt = askdemod_ext(BitStream, &BitLen, &clk, &invert, maxErr, askamp, askType, &startIdx); + int errCnt = askdemod_ext(bits, &BitLen, &clk, &invert, maxErr, askamp, askType, &startIdx); if (errCnt < 0 || BitLen < 16){ //if fatal error (or -1) - PrintAndLogEx(DEBUG, "DEBUG: (ASKDemod_ext) No data found errors:%d, invert:%d, bitlen:%d, clock:%d", errCnt, invert, BitLen, clk); + PrintAndLogEx(DEBUG, "DEBUG: (ASKDemod_ext) No data found errors:%d, invert:%c, bitlen:%d, clock:%d", errCnt, (invert)?'Y':'N', BitLen, clk); return 0; } @@ -516,7 +516,7 @@ int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType, if (verbose || g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: (ASKDemod_ext) Using clock:%d, invert:%d, bits found:%d", clk, invert, BitLen); //output - setDemodBuf(BitStream,BitLen,0); + setDemodBuf(bits, BitLen, 0); setClockGrid(clk, startIdx); if (verbose || g_debugMode){ @@ -1429,6 +1429,7 @@ int getSamples(int n, bool silent) { GraphTraceLen = j; if (!silent) PrintAndLogEx(NORMAL, "Unpacked %d samples" , j ); + } else { for (int j = 0; j < n; j++) { GraphBuffer[j] = ((int)got[j]) - 128; @@ -1436,9 +1437,11 @@ int getSamples(int n, bool silent) { GraphTraceLen = n; } -//ICEMAN todo - // set signal properties low/high/mean/amplitude and is_noice detection - justNoise(GraphBuffer, GraphTraceLen); + //ICEMAN todo + uint8_t bits[GraphTraceLen]; + size_t size = getFromGraphBuf(bits); + // set signal properties low/high/mean/amplitude and is_noice detection + isNoise(bits, size); setClockGrid(0, 0); DemodBufferLen = 0; @@ -1569,9 +1572,9 @@ int CmdLoad(const char *Cmd) { DemodBufferLen = 0; RepaintGraphWindow(); -//ICEMAN todo + //ICEMAN todo // set signal properties low/high/mean/amplitude and isnoice detection - justNoise(GraphBuffer, GraphTraceLen); + isNoise_int(GraphBuffer, GraphTraceLen); return 0; } @@ -1637,9 +1640,9 @@ int CmdNorm(const char *Cmd) { } RepaintGraphWindow(); -//ICEMAN todo + //ICEMAN todo // set signal properties low/high/mean/amplitude and isnoice detection - justNoise(GraphBuffer, GraphTraceLen); + isNoise_int(GraphBuffer, GraphTraceLen); return 0; } @@ -1722,7 +1725,12 @@ int CmdDirectionalThreshold(const char *Cmd) { PrintAndLogEx(INFO, "Applying Up Threshold: %d, Down Threshold: %d\n", up, down); - directionalThreshold(GraphBuffer, GraphBuffer,GraphTraceLen, up, down); + directionalThreshold(GraphBuffer, GraphBuffer, GraphTraceLen, up, down); + + //ICEMAN todo + // set signal properties low/high/mean/amplitude and isnoice detection + isNoise_int(GraphBuffer, GraphTraceLen); + RepaintGraphWindow(); return 0; } @@ -1751,7 +1759,7 @@ int CmdZerocrossings(const char *Cmd) { //ICEMAN todo // set signal properties low/high/mean/amplitude and isnoice detection - justNoise(GraphBuffer, GraphTraceLen); + isNoise_int(GraphBuffer, GraphTraceLen); RepaintGraphWindow(); return 0; @@ -2004,6 +2012,10 @@ int CmdDataIIR(const char *Cmd){ uint8_t k = param_get8(Cmd, 0); //iceIIR_Butterworth(GraphBuffer, GraphTraceLen); iceSimple_Filter(GraphBuffer, GraphTraceLen, k); + //ICEMAN todo + // set signal properties low/high/mean/amplitude and isnoice detection + isNoise_int(GraphBuffer, GraphTraceLen); + RepaintGraphWindow(); return 0; } diff --git a/client/cmdlf.c b/client/cmdlf.c index ccb781014..50077add2 100644 --- a/client/cmdlf.c +++ b/client/cmdlf.c @@ -147,10 +147,9 @@ int CmdLFCommandRead(const char *Cmd) { bool errors = false; uint8_t cmdp = 0; - while(param_getchar(Cmd, cmdp) != 0x00 && !errors) { - switch(param_getchar(Cmd, cmdp)) { + while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { + switch (tolower(param_getchar(Cmd, cmdp))) { case 'h': - case 'H': return usage_lf_cmdread(); case 'c': param_getstr(Cmd, cmdp+1, (char *)&c.d.asBytes, sizeof(c.d.asBytes)); @@ -188,16 +187,20 @@ int CmdLFCommandRead(const char *Cmd) { int CmdFlexdemod(const char *Cmd) { #define LONG_WAIT 100 - int i, j, start, bit, sum; - int phase = 0; + int i, j, start, bit, sum, phase = 0; - for (i = 0; i < GraphTraceLen; ++i) - GraphBuffer[i] = (GraphBuffer[i] < 0) ? -1 : 1; + uint8_t data[MAX_GRAPH_TRACE_LEN] = {0}; + size_t size = getFromGraphBuf(data); + if (size == 0) + return 0; + + for (i = 0; i < size; ++i) + data[i] = (data[i] < 0) ? -1 : 1; - for (start = 0; start < GraphTraceLen - LONG_WAIT; start++) { - int first = GraphBuffer[start]; + for (start = 0; start < size - LONG_WAIT; start++) { + int first = data[start]; for (i = start; i < start + LONG_WAIT; i++) { - if (GraphBuffer[i] != first) { + if (data[i] != first) { break; } } @@ -205,20 +208,21 @@ int CmdFlexdemod(const char *Cmd) { break; } - if (start == GraphTraceLen - LONG_WAIT) { + if (start == size - LONG_WAIT) { PrintAndLogEx(NORMAL, "nothing to wait for"); return 0; } - GraphBuffer[start] = 2; - GraphBuffer[start+1] = -2; + data[start] = 4; + data[start+1] = 0; + uint8_t bits[64] = {0x00}; i = start; for (bit = 0; bit < 64; bit++) { sum = 0; for (int j = 0; j < 16; j++) { - sum += GraphBuffer[i++]; + sum += data[i++]; } bits[bit] = (sum > 0) ? 1 : 0; PrintAndLogEx(NORMAL, "bit %d sum %d", bit, sum); @@ -227,7 +231,7 @@ int CmdFlexdemod(const char *Cmd) { for (bit = 0; bit < 64; bit++) { sum = 0; for (j = 0; j < 16; j++) - sum += GraphBuffer[i++]; + sum += data[i++]; if (sum > 0 && bits[bit] != 1) PrintAndLogEx(NORMAL, "oops1 at %d", bit); @@ -235,8 +239,9 @@ int CmdFlexdemod(const char *Cmd) { } + // iceman, use demod buffer? blue line? // HACK writing back to graphbuffer. - GraphTraceLen = 32*64; + GraphTraceLen = 32 * 64; i = 0; for (bit = 0; bit < 64; bit++) { @@ -261,8 +266,8 @@ int CmdLFSetConfig(const char *Cmd) { uint8_t unsigned_trigg = 0; uint8_t cmdp = 0; - while(param_getchar(Cmd, cmdp) != 0x00 && !errors) { - switch(param_getchar(Cmd, cmdp)) { + while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { + switch (param_getchar(Cmd, cmdp)) { case 'h': return usage_lf_config(); case 'H': @@ -348,18 +353,15 @@ int CmdLFRead(const char *Cmd) { bool silent = false; uint32_t samples = 0; uint8_t cmdp = 0; - while(param_getchar(Cmd, cmdp) != 0x00 && !errors) { - switch(param_getchar(Cmd, cmdp)) { + while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { + switch (tolower(param_getchar(Cmd, cmdp))) { case 'h': - case 'H': return usage_lf_read(); case 's': - case 'S': silent = true; cmdp++; break; case 'd': - case 'D': samples = param_get32ex(Cmd, cmdp, 0, 10); cmdp +=2; break; @@ -377,8 +379,8 @@ int CmdLFRead(const char *Cmd) { } int CmdLFSnoop(const char *Cmd) { - uint8_t cmdp = param_getchar(Cmd, 0); - if(cmdp == 'h' || cmdp == 'H') return usage_lf_snoop(); + uint8_t cmdp = tolower(param_getchar(Cmd, 0)); + if (cmdp == 'h') return usage_lf_snoop(); UsbCommand c = {CMD_LF_SNOOP_RAW_ADC_SAMPLES,{0,0,0}}; clearCommandBuffer(); @@ -444,8 +446,8 @@ int CmdLFfskSim(const char *Cmd) { int dataLen = 0; uint8_t cmdp = 0; - while(param_getchar(Cmd, cmdp) != 0x00 && !errors) { - switch(param_getchar(Cmd, cmdp)){ + while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { + switch (param_getchar(Cmd, cmdp)){ case 'h': return usage_lf_simfsk(); case 'c': @@ -473,7 +475,7 @@ int CmdLFfskSim(const char *Cmd) { if (dataLen == 0) errors = true; if (errors) PrintAndLogEx(WARNING, "Error getting hex data"); - cmdp+=2; + cmdp += 2; break; default: PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); @@ -533,13 +535,12 @@ int CmdLFaskSim(const char *Cmd) { uint8_t encoding = 1, separator = 0, clk = 0, invert = 0; bool errors = false; char hexData[64] = {0x00}; - uint8_t data[255]= {0x00}; // store entered hex data + uint8_t data[255] = {0x00}; // store entered hex data int dataLen = 0; uint8_t cmdp = 0; while(param_getchar(Cmd, cmdp) != 0x00 && !errors) { - switch(param_getchar(Cmd, cmdp)) { - case 'H': + switch (tolower(param_getchar(Cmd, cmdp))) { case 'h': return usage_lf_simask(); case 'i': invert = 1; @@ -632,8 +633,8 @@ int CmdLFpskSim(const char *Cmd) { uint8_t cmdp = 0; uint8_t pskType = 1; - while(param_getchar(Cmd, cmdp) != 0x00 && !errors) { - switch(param_getchar(Cmd, cmdp)) { + while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { + switch (tolower(param_getchar(Cmd, cmdp))) { case 'h': return usage_lf_simpsk(); case 'i': @@ -735,6 +736,7 @@ int CmdLFSimBidir(const char *Cmd) { return 0; } +// ICEMAN, todo, swap from Graphbuffer. int CmdVchDemod(const char *Cmd) { // Is this the entire sync pattern, or does this also include some // data bits that happen to be the same everywhere? That would be diff --git a/client/cmdlfem4x.c b/client/cmdlfem4x.c index 806628fcb..1664a3c2b 100644 --- a/client/cmdlfem4x.c +++ b/client/cmdlfem4x.c @@ -411,7 +411,7 @@ int CmdEM410xRead(const char *Cmd) { // this read loops on device side. // uses the demod in lfops.c int CmdEM410xRead_device(const char *Cmd) { - char cmdp = param_getchar(Cmd, 0); + char cmdp = tolower(param_getchar(Cmd, 0)); uint8_t findone = (cmdp == '1') ? 1 : 0; UsbCommand c = {CMD_EM410X_DEMOD, {findone, 0, 0}}; SendCommand(&c); @@ -423,13 +423,13 @@ int CmdEM410xRead_device(const char *Cmd) { //attempts to demodulate ask while decoding manchester //prints binary found and saves in graphbuffer for further commands int CmdEM410xDemod(const char *Cmd) { - char cmdp = param_getchar(Cmd, 0); - if (strlen(Cmd) > 10 || cmdp == 'h' || cmdp == 'H') return usage_lf_em410x_demod(); + char cmdp = tolower(param_getchar(Cmd, 0)); + if (strlen(Cmd) > 10 || cmdp == 'h') return usage_lf_em410x_demod(); uint32_t hi = 0; uint64_t lo = 0; - if(AskEm410xDemod(Cmd, &hi, &lo, true) != 1) return 0; + if (AskEm410xDemod(Cmd, &hi, &lo, true) != 1) return 0; g_em410xid = lo; return 1; @@ -437,8 +437,8 @@ int CmdEM410xDemod(const char *Cmd) { // emulate an EM410X tag int CmdEM410xSim(const char *Cmd) { - char cmdp = param_getchar(Cmd, 0); - if (cmdp == 'h' || cmdp == 'H') return usage_lf_em410x_sim(); + char cmdp = tolower(param_getchar(Cmd, 0)); + if (cmdp == 'h') return usage_lf_em410x_sim(); uint8_t uid[5] = {0x00}; @@ -594,8 +594,8 @@ int CmdEM410xWatch(const char *Cmd) { //currently only supports manchester modulations int CmdEM410xWatchnSpoof(const char *Cmd) { - char cmdp = param_getchar(Cmd, 0); - if (cmdp == 'h' || cmdp == 'H') return usage_lf_em410x_ws(); + char cmdp = tolower(param_getchar(Cmd, 0)); + if (cmdp == 'h') return usage_lf_em410x_ws(); // loops if the captured ID was in XL-format. CmdEM410xWatch(Cmd); @@ -784,64 +784,59 @@ uint32_t OutputEM4x50_Block(uint8_t *BitStream, size_t size, bool verbose, bool //completed by Marshmellow int EM4x50Read(const char *Cmd, bool verbose) { uint8_t fndClk[] = {8,16,32,40,50,64,128}; - int clk = 0; - int invert = 0; - int tol = 0; - int i, j, startblock, skip, block, start, end, low, high, minClk; - bool complete = false; - int tmpbuff[MAX_GRAPH_TRACE_LEN / 64]; + int clk = 0, invert = 0, tol = 0, phaseoff; + int i = 0, j = 0, startblock, skip, block, start, end, low = 0, high = 0, minClk = 255; uint32_t Code[6]; char tmp[6]; char tmp2[20]; - int phaseoff; - high = low = 0; + bool complete = false; + + int tmpbuff[MAX_GRAPH_TRACE_LEN / 64]; memset(tmpbuff, 0, sizeof(tmpbuff) ); // get user entry if any sscanf(Cmd, "%i %i", &clk, &invert); - // first get high and low values - for (i = 0; i < GraphTraceLen; i++) { - if (GraphBuffer[i] > high) - high = GraphBuffer[i]; - else if (GraphBuffer[i] < low) - low = GraphBuffer[i]; - } + uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0}; + size_t size = getFromGraphBuf(bits); + + isNoise(bits, size); + + signal_t *sp = getSignalProperties(); + high = sp->high; + low = sp->low; - i = 0; - j = 0; - minClk = 255; // get to first full low to prime loop and skip incomplete first pulse - while ((GraphBuffer[i] < high) && (i < GraphTraceLen)) + while ((bits[i] < high) && (i < size)) ++i; - while ((GraphBuffer[i] > low) && (i < GraphTraceLen)) + while ((bits[i] > low) && (i < size)) ++i; skip = i; // populate tmpbuff buffer with pulse lengths - while (i < GraphTraceLen) { + while (i < size) { // measure from low to low - while ((GraphBuffer[i] > low) && (i < GraphTraceLen)) + while ((bits[i] > low) && (i < size)) ++i; start= i; - while ((GraphBuffer[i] < high) && (i < GraphTraceLen)) + while ((bits[i] < high) && (i < size)) ++i; - while ((GraphBuffer[i] > low) && (i < GraphTraceLen)) + while ((bits[i] > low) && (i < size)) ++i; - if (j>=(MAX_GRAPH_TRACE_LEN/64)) { + if (j >= (MAX_GRAPH_TRACE_LEN/64)) { break; } - tmpbuff[j++]= i - start; - if (i-start < minClk && i < GraphTraceLen) { + tmpbuff[j++] = i - start; + if (i-start < minClk && i < size) { minClk = i - start; } } // set clock if (!clk) { - for (uint8_t clkCnt = 0; clkCnt<7; clkCnt++) { - tol = fndClk[clkCnt]/8; - if (minClk >= fndClk[clkCnt]-tol && minClk <= fndClk[clkCnt]+1) { - clk=fndClk[clkCnt]; + for (uint8_t clkCnt = 0; clkCnt < 7; clkCnt++) { + tol = fndClk[clkCnt] / 8; + if (minClk >= fndClk[clkCnt] - tol && minClk <= fndClk[clkCnt] + 1) { + clk = fndClk[clkCnt]; break; } } @@ -849,15 +844,15 @@ int EM4x50Read(const char *Cmd, bool verbose) { if (verbose || g_debugMode) PrintAndLogEx(WARNING, "Error: EM4x50 - didn't find a clock"); return 0; } - } else tol = clk/8; + } else tol = clk / 8; // look for data start - should be 2 pairs of LW (pulses of clk*3,clk*2) start = -1; for (i= 0; i < j - 4 ; ++i) { skip += tmpbuff[i]; - if (tmpbuff[i] >= clk*3-tol && tmpbuff[i] <= clk*3+tol) //3 clocks - if (tmpbuff[i+1] >= clk*2-tol && tmpbuff[i+1] <= clk*2+tol) //2 clocks - if (tmpbuff[i+2] >= clk*3-tol && tmpbuff[i+2] <= clk*3+tol) //3 clocks + if (tmpbuff[i] >= clk * 3 - tol && tmpbuff[i] <= clk * 3 + tol) //3 clocks + if (tmpbuff[i+1] >= clk * 2 - tol && tmpbuff[i+1] <= clk * 2 + tol) //2 clocks + if (tmpbuff[i+2] >= clk * 3 - tol && tmpbuff[i+2] <= clk * 3 + tol) //3 clocks if (tmpbuff[i+3] >= clk-tol) //1.5 to 2 clocks - depends on bit following { start= i + 4; @@ -867,18 +862,20 @@ int EM4x50Read(const char *Cmd, bool verbose) { startblock = i + 4; // skip over the remainder of LW - skip += tmpbuff[i+1] + tmpbuff[i+2] + clk; - if (tmpbuff[i+3]>clk) - phaseoff = tmpbuff[i+3]-clk; + skip += (tmpbuff[i+1] + tmpbuff[i+2] + clk); + + if (tmpbuff[i+3] > clk) + phaseoff = tmpbuff[i+3] - clk; else phaseoff = 0; + // now do it again to find the end end = skip; for (i += 3; i < j - 4 ; ++i) { end += tmpbuff[i]; - if (tmpbuff[i] >= clk*3-tol && tmpbuff[i] <= clk*3+tol) //3 clocks - if (tmpbuff[i+1] >= clk*2-tol && tmpbuff[i+1] <= clk*2+tol) //2 clocks - if (tmpbuff[i+2] >= clk*3-tol && tmpbuff[i+2] <= clk*3+tol) //3 clocks + if (tmpbuff[i] >= clk * 3 - tol && tmpbuff[i] <= clk * 3 + tol) //3 clocks + if (tmpbuff[i+1] >= clk * 2 - tol && tmpbuff[i+1] <= clk * 2 + tol) //2 clocks + if (tmpbuff[i+2] >= clk * 3 - tol && tmpbuff[i+2] <= clk * 3 + tol) //3 clocks if (tmpbuff[i+3] >= clk-tol) //1.5 to 2 clocks - depends on bit following { complete= true; @@ -897,8 +894,9 @@ int EM4x50Read(const char *Cmd, bool verbose) { return 0; } } else if (start < 0) return 0; + start = skip; - snprintf(tmp2, sizeof(tmp2),"%d %d 1000 %d", clk, invert, clk*47); + 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 @@ -916,17 +914,19 @@ int EM4x50Read(const char *Cmd, bool verbose) { // look for LW before start of next block for ( ; i < j - 4 ; ++i) { skip += tmpbuff[i]; - if (tmpbuff[i] >= clk*3-tol && tmpbuff[i] <= clk*3+tol) + if (tmpbuff[i] >= clk * 3 - tol && tmpbuff[i] <= clk * 3 + tol) if (tmpbuff[i+1] >= clk-tol) break; } if (i >= j-4) break; //next LW not found skip += clk; - if (tmpbuff[i+1]>clk) - phaseoff = tmpbuff[i+1]-clk; + if (tmpbuff[i+1] > clk) + phaseoff = tmpbuff[i+1] - clk; else phaseoff = 0; + i += 2; + if (ASKDemod(tmp2, false, false, 1) < 1) { save_restoreGB(GRAPH_RESTORE); return 0; @@ -934,14 +934,14 @@ int EM4x50Read(const char *Cmd, bool verbose) { //set DemodBufferLen to just one block DemodBufferLen = skip/clk; //test parities - pTest = EM_ByteParityTest(DemodBuffer,DemodBufferLen,5,9,0); - pTest &= EM_EndParityTest(DemodBuffer,DemodBufferLen,5,9,0); + pTest = EM_ByteParityTest(DemodBuffer,DemodBufferLen, 5, 9, 0); + pTest &= EM_EndParityTest(DemodBuffer,DemodBufferLen, 5, 9, 0); AllPTest &= pTest; //get output - Code[block] = OutputEM4x50_Block(DemodBuffer,DemodBufferLen,verbose, pTest); + Code[block] = OutputEM4x50_Block(DemodBuffer, DemodBufferLen, verbose, pTest); PrintAndLogEx(DEBUG, "\nskipping %d samples, bits:%d", skip, skip/clk); //skip to start of next block - snprintf(tmp,sizeof(tmp),"%i",skip); + snprintf(tmp, sizeof(tmp), "%i", skip); CmdLtrim(tmp); block++; if (i >= end) break; //in case chip doesn't output 6 blocks @@ -956,7 +956,7 @@ int EM4x50Read(const char *Cmd, bool verbose) { PrintAndLogEx(NORMAL, "Found data at sample: %i - using clock: %i", start, clk); end = block; for (block=0; block < end; block++){ - PrintAndLogEx(NORMAL, "Block %d: %08x",block,Code[block]); + PrintAndLogEx(NORMAL, "Block %d: %08x", block, Code[block]); } if (AllPTest) { PrintAndLogEx(NORMAL, "Parities Passed"); @@ -972,19 +972,19 @@ int EM4x50Read(const char *Cmd, bool verbose) { } int CmdEM4x50Read(const char *Cmd) { - uint8_t ctmp = param_getchar(Cmd, 0); - if ( ctmp == 'H' || ctmp == 'h' ) return usage_lf_em4x50_read(); + uint8_t ctmp = tolower(param_getchar(Cmd, 0)); + if ( ctmp == 'h' ) return usage_lf_em4x50_read(); return EM4x50Read(Cmd, true); } int CmdEM4x50Write(const char *Cmd){ - uint8_t ctmp = param_getchar(Cmd, 0); - if ( ctmp == 'H' || ctmp == 'h' ) return usage_lf_em4x50_write(); + uint8_t ctmp = tolower(param_getchar(Cmd, 0)); + if ( ctmp == 'h' ) return usage_lf_em4x50_write(); PrintAndLogEx(NORMAL, "no implemented yet"); return 0; } int CmdEM4x50Dump(const char *Cmd){ - uint8_t ctmp = param_getchar(Cmd, 0); - if ( ctmp == 'H' || ctmp == 'h' ) return usage_lf_em4x50_dump(); + uint8_t ctmp = tolower(param_getchar(Cmd, 0)); + if ( ctmp == 'h' ) return usage_lf_em4x50_dump(); PrintAndLogEx(NORMAL, "no implemented yet"); return 0; } @@ -1000,6 +1000,11 @@ bool downloadSamplesEM(){ return false; } setGraphBuf(got, sizeof(got)); + + if (isNoise(got, sizeof(got))) { + PrintAndLogEx(DEBUG, "No tag found"); + return false; + } return true; } @@ -1146,12 +1151,7 @@ int EM4x05ReadWord_ext(uint8_t addr, uint32_t pwd, bool usePwd, uint32_t *word) if ( !downloadSamplesEM() ) { return -1; } - int testLen = (GraphTraceLen < 1000) ? GraphTraceLen : 1000; - if (justNoise(GraphBuffer, testLen)) { - PrintAndLogEx(DEBUG, "No tag found"); - return -1; - } return demodEM4x05resp(word); } diff --git a/client/cmdlfindala.c b/client/cmdlfindala.c index f4993fb5e..dd262e0dc 100644 --- a/client/cmdlfindala.c +++ b/client/cmdlfindala.c @@ -184,9 +184,11 @@ int CmdIndalaDemodAlt(const char *Cmd) { int count = 0; int i, j; - // worst case with GraphTraceLen=64000 is < 4096 + // worst case with GraphTraceLen=40000 is < 4096 // under normal conditions it's < 2048 - + uint8_t data[MAX_GRAPH_TRACE_LEN] = {0}; + size_t datasize = getFromGraphBuf(data); + uint8_t rawbits[4096]; int rawbit = 0; int worst = 0, worstPos = 0; @@ -197,9 +199,9 @@ int CmdIndalaDemodAlt(const char *Cmd) { // PrintAndLogEx(NORMAL, "Expecting a bit less than %d raw bits", GraphTraceLen / 32); // loop through raw signal - since we know it is psk1 rf/32 fc/2 skip every other value (+=2) - for (i = 0; i < GraphTraceLen-1; i += 2) { + for (i = 0; i < datasize-1; i += 2) { count += 1; - if ((GraphBuffer[i] > GraphBuffer[i + 1]) && (state != 1)) { + if ((data[i] > data[i + 1]) && (state != 1)) { // appears redundant - marshmellow if (state == 0) { for (j = 0; j < count - 8; j += 16) { @@ -212,7 +214,7 @@ int CmdIndalaDemodAlt(const char *Cmd) { } state = 1; count = 0; - } else if ((GraphBuffer[i] < GraphBuffer[i + 1]) && (state != 0)) { + } else if ((data[i] < data[i + 1]) && (state != 0)) { //appears redundant if (state == 1) { for (j = 0; j < count - 8; j += 16) { @@ -228,7 +230,7 @@ int CmdIndalaDemodAlt(const char *Cmd) { } } - if (rawbit>0){ + if (rawbit > 0){ PrintAndLogEx(NORMAL, "Recovered %d raw bits, expected: %d", rawbit, GraphTraceLen/32); PrintAndLogEx(NORMAL, "worst metric (0=best..7=worst): %d at pos %d", worst, worstPos); } else { @@ -301,14 +303,14 @@ int CmdIndalaDemodAlt(const char *Cmd) { int idx; uid1 = uid2 = 0; - if (uidlen==64){ - for( idx=0; idx<64; idx++) { + if (uidlen == 64){ + for( idx=0; idx < 64; idx++) { if (showbits[idx] == '0') { - uid1=(uid1<<1)|(uid2>>31); - uid2=(uid2<<1)|0; + uid1 = (uid1<<1) | (uid2>>31); + uid2 = (uid2<<1) | 0; } else { - uid1=(uid1<<1)|(uid2>>31); - uid2=(uid2<<1)|1; + uid1 = (uid1<<1) | (uid2>>31); + uid2 = (uid2<<1) | 1; } } PrintAndLogEx(NORMAL, "UID=%s (%x%08x)", showbits, uid1, uid2); @@ -317,12 +319,12 @@ int CmdIndalaDemodAlt(const char *Cmd) { uid3 = uid4 = uid5 = uid6 = uid7 = 0; for( idx=0; idx<224; idx++) { - uid1=(uid1<<1)|(uid2>>31); - uid2=(uid2<<1)|(uid3>>31); - uid3=(uid3<<1)|(uid4>>31); - uid4=(uid4<<1)|(uid5>>31); - uid5=(uid5<<1)|(uid6>>31); - uid6=(uid6<<1)|(uid7>>31); + uid1 = (uid1<<1) | (uid2>>31); + uid2 = (uid2<<1) | (uid3>>31); + uid3 = (uid3<<1) | (uid4>>31); + uid4 = (uid4<<1) | (uid5>>31); + uid5 = (uid5<<1) | (uid6>>31); + uid6 = (uid6<<1) | (uid7>>31); if (showbits[idx] == '0') uid7 = (uid7<<1) | 0; @@ -353,7 +355,7 @@ int CmdIndalaDemodAlt(const char *Cmd) { // Remodulating for tag cloning // HACK: 2015-01-04 this will have an impact on our new way of seening lf commands (demod) // since this changes graphbuffer data. - GraphTraceLen = 32*uidlen; + GraphTraceLen = 32 * uidlen; i = 0; int phase = 0; for (bit = 0; bit < uidlen; bit++) { diff --git a/client/cmdlfio.c b/client/cmdlfio.c index a2bc08217..d2cecec4b 100644 --- a/client/cmdlfio.c +++ b/client/cmdlfio.c @@ -83,10 +83,10 @@ int CmdIOProxRead_device(const char *Cmd) { int CmdIOProxDemod(const char *Cmd) { int retval = 0; int idx = 0; - uint8_t bits[MAX_GRAPH_TRACE_LEN]={0}; + uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0}; size_t size = getFromGraphBuf(bits); if (size < 65) { - if (g_debugMode)PrintAndLogEx(DEBUG, "DEBUG: Error - IO prox not enough samples in GraphBuffer"); + if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - IO prox not enough samples in GraphBuffer"); return 0; } //get binary from fsk wave diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index c4d1e3be6..7fbf143d3 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -504,12 +504,13 @@ int CmdT55xxDetect(const char *Cmd){ // detect configuration? bool tryDetectModulation(){ - uint8_t hits = 0; + t55xx_conf_block_t tests[15]; - int bitRate=0; - uint8_t fc1 = 0, fc2 = 0, ans = 0; - int clk = 0, firstClockEdge = 0; + int bitRate = 0, clk = 0, firstClockEdge = 0; + uint8_t hits = 0, fc1 = 0, fc2 = 0, ans = 0; + ans = fskClocks(&fc1, &fc2, (uint8_t *)&clk, &firstClockEdge); + if (ans && ((fc1==10 && fc2==8) || (fc1==8 && fc2==5))) { if ( FSKrawDemod("0 0", false) && test(DEMOD_FSK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)){ tests[hits].modulation = DEMOD_FSK; @@ -1305,15 +1306,13 @@ bool AquireData( uint8_t page, uint8_t block, bool pwdmode, uint32_t password ){ return false; } - //uint8_t got[12288]; - uint8_t got[7679]; - if ( !GetFromDevice(BIG_BUF, got, sizeof(got), 0, NULL, 6000, true)) { + uint8_t got[8000]; + if ( !GetFromDevice(BIG_BUF, got, sizeof(got), 0, NULL, 4000, true)) { PrintAndLogEx(WARNING, "command execution time out"); return false; } setGraphBuf(got, sizeof(got)); - - return !justNoise(GraphBuffer, sizeof(got)); + return !isNoise(got, sizeof(got)); } char * GetBitRateStr(uint32_t id, bool xmode) { diff --git a/common/lfdemod.c b/common/lfdemod.c index 9fbf933f4..0525f7ff9 100644 --- a/common/lfdemod.c +++ b/common/lfdemod.c @@ -105,7 +105,6 @@ int32_t compute_mean_int(int *in, size_t N) { return mean / (int)N; } - void zeromean(uint8_t* data, size_t size) { // zero mean data @@ -119,13 +118,13 @@ void zeromean(uint8_t* data, size_t size) { data[i] -= accum; } - //test samples are not just noise // By measuring mean and look at amplitude of signal from HIGH / LOW, we can detect noise bool isNoise_int(int *bits, uint32_t size) { resetSignal(); if ( bits == NULL || size < 100 ) return true; - + //zeromean(bits, size); + int32_t sum = 0; for ( size_t i = 0; i < size; i++) { if ( bits[i] < signalprop.low ) signalprop.low = bits[i]; @@ -138,7 +137,7 @@ bool isNoise_int(int *bits, uint32_t size) { signalprop.amplitude = ABS(signalprop.high - signalprop.mean); signalprop.isnoise = signalprop.amplitude < NOICE_AMPLITUDE_THRESHOLD; - if (g_debugMode == 1) + if (g_debugMode) printSignal(); return signalprop.isnoise; @@ -149,6 +148,7 @@ bool isNoise_int(int *bits, uint32_t size) { bool isNoise(uint8_t *bits, uint32_t size) { resetSignal(); if ( bits == NULL || size < 100 ) return true; + zeromean(bits, size); uint32_t sum = 0; for ( uint32_t i = 0; i < size; i++) { @@ -162,7 +162,7 @@ bool isNoise(uint8_t *bits, uint32_t size) { signalprop.amplitude = signalprop.high - signalprop.mean; signalprop.isnoise = signalprop.amplitude < NOICE_AMPLITUDE_THRESHOLD; - if (g_debugMode == 1) + if (g_debugMode) printSignal(); return signalprop.isnoise; @@ -170,22 +170,20 @@ bool isNoise(uint8_t *bits, uint32_t size) { //by marshmellow //get high and low values of a wave with passed in fuzz factor. also return noise test = 1 for passed or 0 for only noise -int getHiLo(uint8_t *bits, size_t size, int *high, int *low, uint8_t fuzzHi, uint8_t fuzzLo) { - - // just noise - no super good detection. good enough - if (signalprop.isnoise) return -1; - +//void getHiLo(uint8_t *bits, size_t size, int *high, int *low, uint8_t fuzzHi, uint8_t fuzzLo) { +void getHiLo(int *high, int *low, uint8_t fuzzHi, uint8_t fuzzLo) { // add fuzz. *high = (signalprop.high * fuzzHi) / 100; if ( signalprop.low < 0 ) { *low = (signalprop.low * fuzzLo) / 100; - } else { - *low = signalprop.low * (100 + (100 - fuzzLo))/100; + } else { + uint8_t range = signalprop.high - signalprop.low; + + *low = signalprop.low + ((range * (100-fuzzLo))/100); } - if (g_debugMode > 0) + if (g_debugMode) prnt("getHiLo fuzzed: High %d | Low %d", *high, *low); - return 1; } // by marshmellow @@ -361,13 +359,17 @@ void getNextHigh(uint8_t *samples, size_t size, int high, size_t *i) { // load wave counters bool loadWaveCounters(uint8_t *samples, size_t size, int lowToLowWaveLen[], int highToLowWaveLen[], int *waveCnt, int *skip, int *minClk, int *high, int *low) { - size_t i=0, firstLow, firstHigh; - size_t testsize = (size < 512) ? size : 512; - - if ( getHiLo(samples, testsize, high, low, 80, 80) == -1 ) { + size_t i = 0, firstLow, firstHigh; + //size_t testsize = (size < 512) ? size : 512; + + // just noise - no super good detection. good enough + if (signalprop.isnoise) { if (g_debugMode == 2) prnt("DEBUG STT: just noise detected - quitting"); - return false; //just noise + return false; } + + //getHiLo(samples, testsize, high, low, 80, 80); + getHiLo(high, low, 80, 80); // get to first full low to prime loop and skip incomplete first pulse getNextHigh(samples, size, *high, &i); @@ -469,7 +471,8 @@ int ManchesterEncode(uint8_t *bits, size_t size) { // by marshmellow // to detect a wave that has heavily clipped (clean) samples -uint8_t DetectCleanAskWave(uint8_t *dest, size_t size, uint8_t high, uint8_t low) { +// loop 512 samples, if 300 of them is deemed maxed out, we assume the wave is clipped. +bool DetectCleanAskWave(uint8_t *dest, size_t size, uint8_t high, uint8_t low) { bool allArePeaks = true; uint16_t cntPeaks = 0; size_t loopEnd = 512 + 160; @@ -484,8 +487,9 @@ uint8_t DetectCleanAskWave(uint8_t *dest, size_t size, uint8_t high, uint8_t low else cntPeaks++; } + if (!allArePeaks){ - if (cntPeaks > 300) return true; + if (cntPeaks > 250) return true; } return allArePeaks; } @@ -504,11 +508,13 @@ int DetectStrongAskClock(uint8_t *dest, size_t size, int high, int low, int *clo size_t i = 100; size_t minClk = 512; int shortestWaveIdx = 0; - + + if (g_debugMode == 1) prnt("DEBUG ASK: DetectStrongAskClock: hi %d | low %d ", high, low); + // get to first full low to prime loop and skip incomplete first pulse getNextHigh(dest, size, high, &i); getNextLow(dest, size, low, &i); - + // loop through all samples while (i < size) { // measure from low to low @@ -516,7 +522,7 @@ int DetectStrongAskClock(uint8_t *dest, size_t size, int high, int low, int *clo getNextHigh(dest, size, high, &i); getNextLow(dest, size, low, &i); - + //get minimum measured distance if (i-startwave < minClk && i < size) { minClk = i - startwave; @@ -546,18 +552,29 @@ int DetectASKClock(uint8_t *dest, size_t size, int *clock, int maxErr) { size -= 60; //sometimes there is a strange end wave - filter out this.... //if we already have a valid clock uint8_t clockFnd = 0; - for (; i < clkEnd; ++i) - if (clk[i] == *clock) clockFnd = i; - //clock found but continue to find best startpos + for (; i < clkEnd; ++i) { + if (clk[i] == *clock) { + //clock found but continue to find best startpos + clockFnd = i; + } + } + // just noise - no super good detection. good enough + if (signalprop.isnoise) { + if (g_debugMode == 2) prnt("DEBUG DetectASKClock: just noise detected - quitting"); + return -1; + } + //get high and low peak - int peak, low; - if (getHiLo(dest, loopCnt, &peak, &low, 75, 75) < 1) return -1; + int peak_hi, peak_low; + //getHiLo(dest, loopCnt, &peak_hi, &peak_low, 75, 75); + getHiLo(&peak_hi, &peak_low, 75, 75); //test for large clean peaks if (!clockFnd){ - if (DetectCleanAskWave(dest, size, peak, low)==1){ - int ans = DetectStrongAskClock(dest, size, peak, low, clock); + if (DetectCleanAskWave(dest, size, peak_hi, peak_low)){ + + int ans = DetectStrongAskClock(dest, size, peak_hi, peak_low, clock); if (g_debugMode == 2) prnt("DEBUG ASK: detectaskclk Clean Ask Wave Detected: clk %i, ShortestWave: %i", *clock ,ans); if (ans > 0){ return ans; //return shortest wave start position @@ -570,8 +587,8 @@ int DetectASKClock(uint8_t *dest, size_t size, int *clock, int maxErr) { uint16_t ii; uint8_t clkCnt, tol = 0; - uint16_t bestErr[]={1000,1000,1000,1000,1000,1000,1000,1000,1000}; - uint8_t bestStart[]={0,0,0,0,0,0,0,0,0}; + uint16_t bestErr[] = {1000,1000,1000,1000,1000,1000,1000,1000,1000}; + uint8_t bestStart[] = {0,0,0,0,0,0,0,0,0}; size_t errCnt = 0; size_t arrLoc, loopEnd; @@ -585,9 +602,9 @@ int DetectASKClock(uint8_t *dest, size_t size, int *clock, int maxErr) { //test each valid clock from smallest to greatest to see which lines up for (; clkCnt < clkEnd; clkCnt++) { if (clk[clkCnt] <= 32) { - tol=1; + tol = 1; } else { - tol=0; + tol = 0; } //if no errors allowed - keep start within the first clock if (!maxErr && size > clk[clkCnt]*2 + tol && clk[clkCnt] < 128) @@ -597,17 +614,17 @@ int DetectASKClock(uint8_t *dest, size_t size, int *clock, int maxErr) { //try lining up the peaks by moving starting point (try first few clocks) for (ii=0; ii < loopCnt; ii++){ - if (dest[ii] < peak && dest[ii] > low) continue; + if (dest[ii] < peak_hi && dest[ii] > peak_low) continue; errCnt = 0; // now that we have the first one lined up test rest of wave array loopEnd = ((size-ii-tol) / clk[clkCnt]) - 1; for (i=0; i < loopEnd; ++i){ arrLoc = ii + (i * clk[clkCnt]); - if (dest[arrLoc] >= peak || dest[arrLoc] <= low){ - }else if (dest[arrLoc-tol] >= peak || dest[arrLoc-tol] <= low){ - }else if (dest[arrLoc+tol] >= peak || dest[arrLoc+tol] <= low){ - }else{ //error no peak detected + if (dest[arrLoc] >= peak_hi || dest[arrLoc] <= peak_low){ + } else if (dest[arrLoc-tol] >= peak_hi || dest[arrLoc-tol] <= peak_low){ + } else if (dest[arrLoc+tol] >= peak_hi || dest[arrLoc+tol] <= peak_low){ + } else { //error no peak detected errCnt++; } } @@ -618,7 +635,7 @@ int DetectASKClock(uint8_t *dest, size_t size, int *clock, int maxErr) { if (!clockFnd) *clock = clk[clkCnt]; return ii; - } + } //if we found errors see if it is lowest so far and save it as best run if (errCnt < bestErr[clkCnt]) { bestErr[clkCnt] = errCnt; @@ -701,10 +718,18 @@ int DetectNRZClock(uint8_t *dest, size_t size, int clock, size_t *clockStartIdx) // size must be larger than 20 here if (size < loopCnt) loopCnt = size-20; + + // just noise - no super good detection. good enough + if (signalprop.isnoise) { + if (g_debugMode == 2) prnt("DEBUG DetectNZRClock: just noise detected - quitting"); + return 0; + } + //get high and low peak int peak, low; - if (getHiLo(dest, loopCnt, &peak, &low, 90, 90) < 1) return 0; - + //getHiLo(dest, loopCnt, &peak, &low, 90, 90); + getHiLo(&peak, &low, 90, 90); + bool strong = false; int lowestTransition = DetectStrongNRZClk(dest, size-20, peak, low, &strong); if (strong) return lowestTransition; @@ -1431,11 +1456,18 @@ int cleanAskRawDemod(uint8_t *bits, size_t *size, int clk, int invert, int high, //by marshmellow //attempts to demodulate ask modulations, askType == 0 for ask/raw, askType==1 for ask/manchester int askdemod_ext(uint8_t *bits, size_t *size, int *clk, int *invert, int maxErr, uint8_t amp, uint8_t askType, int *startIdx) { - if (*size==0) return -1; - int start = DetectASKClock(bits, *size, clk, maxErr); //clock default - if (*clk==0 || start < 0) return -3; + + if (*size == 0) return -1; + + int start = DetectASKClock(bits, *size, clk, maxErr); + if (*clk == 0 || start < 0) return -3; + if (*invert != 1) *invert = 0; - if (amp==1) askAmp(bits, *size); + + // amplify signal data. + // ICEMAN todo, + if (amp == 1) askAmp(bits, *size); + if (g_debugMode == 2) prnt("DEBUG ASK: clk %d, beststart %d, amp %d", *clk, start, amp); //start pos from detect ask clock is 1/2 clock offset @@ -1443,12 +1475,19 @@ int askdemod_ext(uint8_t *bits, size_t *size, int *clk, int *invert, int maxErr, *startIdx = start - (*clk/2); uint16_t initLoopMax = 1024; if (initLoopMax > *size) initLoopMax = *size; + + // just noise - no super good detection. good enough + if (signalprop.isnoise) { + if (g_debugMode == 2) prnt("DEBUG askdemod_ext: just noise detected - quitting"); + return -2; + } + // Detect high and lows //25% clip in case highs and lows aren't clipped [marshmellow] int high, low; - if (getHiLo(bits, initLoopMax, &high, &low, 75, 75) < 1) - return -2; //just noise - + //getHiLo(bits, initLoopMax, &high, &low, 75, 75); + getHiLo(&high, &low, 75, 75); + size_t errCnt = 0; // if clean clipped waves detected run alternate demod if (DetectCleanAskWave(bits, *size, high, low)) { @@ -1461,11 +1500,13 @@ int askdemod_ext(uint8_t *bits, size_t *size, int *clk, int *invert, int maxErr, uint8_t alignPos = 0; errCnt = manrawdecode(bits, size, 0, &alignPos); *startIdx += *clk/2 * alignPos; + if (g_debugMode) prnt("DEBUG: (askdemod_ext) CLEAN: startIdx %i, alignPos %u", *startIdx, alignPos); } return errCnt; } + if (g_debugMode) prnt("DEBUG: (askdemod_ext) Weak wave detected: startIdx %i", *startIdx); int lastBit; //set first clock check - can go negative @@ -1477,28 +1518,28 @@ int askdemod_ext(uint8_t *bits, size_t *size, int *clk, int *invert, int maxErr, lastBit = start - *clk; for (i = start; i < *size; ++i) { - if (i-lastBit >= *clk-tol){ + if (i - lastBit >= *clk - tol){ if (bits[i] >= high) { bits[bitnum++] = *invert; } else if (bits[i] <= low) { bits[bitnum++] = *invert ^ 1; - } else if (i-lastBit >= *clk+tol) { + } else if (i-lastBit >= *clk + tol) { if (bitnum > 0) { if (g_debugMode == 2) prnt("DEBUG: (askdemod_ext) Modulation Error at: %u", i); - bits[bitnum++]=7; - errCnt++; + bits[bitnum++] = 7; + errCnt++; } } else { //in tolerance - looking for peak continue; } midBit = 0; lastBit += *clk; - } else if (i-lastBit >= (*clk/2-tol) && !midBit && !askType){ + } else if (i-lastBit >= (*clk/2 - tol) && !midBit && !askType){ if (bits[i] >= high) { bits[bitnum++] = *invert; } else if (bits[i] <= low) { bits[bitnum++] = *invert ^ 1; - } else if (i-lastBit >= *clk/2+tol) { + } else if (i-lastBit >= *clk/2 + tol) { bits[bitnum] = bits[bitnum-1]; bitnum++; } else { //in tolerance - looking for peak @@ -1530,8 +1571,17 @@ int nrzRawDemod(uint8_t *dest, size_t *size, int *clk, int *invert, int *startId if (gLen > *size) gLen = *size-20; + + // just noise - no super good detection. good enough + if (signalprop.isnoise) { + if (g_debugMode == 2) prnt("DEBUG nrzRawDemod: just noise detected - quitting"); + return -3; + } + int high, low; - if (getHiLo(dest, gLen, &high, &low, 75, 75) < 1) return -3; //25% fuzz on high 25% fuzz on low + //getHiLo(dest, gLen, &high, &low, 75, 75); + getHiLo(&high, &low, 75, 75); + getHiLo(&high, &low, 75, 75); uint8_t bit=0; //convert wave samples to 1's and 0's diff --git a/common/lfdemod.h b/common/lfdemod.h index 3a7f873d7..48b4b9481 100644 --- a/common/lfdemod.h +++ b/common/lfdemod.h @@ -35,14 +35,7 @@ extern int32_t compute_mean_int(int *in, size_t N); bool isNoise_int(int *bits, uint32_t size); bool isNoise(uint8_t *bits, uint32_t size); extern void zeromean(uint8_t* data, size_t size); - -// buffer is unsigned on DEVIE -#ifdef ON_DEVICE - #define justNoise(a, b) isNoise((a), (b)) -#else - #define justNoise(a, b) isNoise_int((a), (b)) -#endif - + void getNextLow(uint8_t *samples, size_t size, int low, size_t *i); void getNextHigh(uint8_t *samples, size_t size, int high, size_t *i); bool loadWaveCounters(uint8_t *samples, size_t size, int lowToLowWaveLen[], int highToLowWaveLen[], int *waveCnt, int *skip, int *minClk, int *high, int *low); @@ -58,14 +51,15 @@ 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 *bits, 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 bool DetectCleanAskWave(uint8_t *dest, size_t size, uint8_t high, uint8_t low); extern uint8_t detectFSKClk(uint8_t *bits, 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, size_t *ststart, size_t *stend); extern size_t 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 *bits, size_t size, int *high, int *low, uint8_t fuzzHi, uint8_t fuzzLo); +//extern void getHiLo(uint8_t *bits, size_t size, int *high, int *low, uint8_t fuzzHi, uint8_t fuzzLo); +extern void getHiLo(int *high, int *low, uint8_t fuzzHi, uint8_t fuzzLo); extern uint32_t manchesterEncode2Bytes(uint16_t datain); extern int ManchesterEncode(uint8_t *bits, size_t size); extern int manrawdecode(uint8_t *bits, size_t *size, uint8_t invert, uint8_t *alignPos);