- uint8_t preamble[6] = {0,0,1,0,1,0};
-
- // test for FSK wave (easiest to 99% ID)
- if (GetFskClock("", FALSE, FALSE)) {
- //valid fsk clocks found
- ans = FSKrawDemod("0 0", false);
- if (!ans) {
- if (g_debugMode) PrintAndLog("DEBUG: Error - EM4305: FSK Demod failed");
- //return -1;
- } else {
- // set size to 10 to only test first 4 positions for the preamble
- size_t size = (10 > DemodBufferLen) ? DemodBufferLen : 10;
- size_t startIdx = 0;
-
- if (g_debugMode) PrintAndLog("ANS: %d | %u | %u", ans, startIdx, size);
-
- uint8_t errChk = !EMpreambleSearch(DemodBuffer, preamble, sizeof(preamble), size, &startIdx);
- if ( errChk == 0) {
- if (g_debugMode) PrintAndLog("DEBUG: Error - EM4305 preamble not found :: %d", startIdx);
- //return -1;
- } else {
- //can't test size because the preamble doesn't repeat :(
- //meaning chances of false positives are high.
- demodFound = true;
- }
+ uint8_t preamble[EM_PREAMBLE_LEN] = {0,0,1,0,1,0};
+
+ // set size to 10 to only test first 4 positions for the preamble
+ size_t size = (10 > DemodBufferLen) ? DemodBufferLen : 10;
+ *startIdx = 0;
+ uint8_t found = 0;
+
+ // em only sends preamble once, so look for it once in the first x bits
+ for (int idx = 0; idx < size - EM_PREAMBLE_LEN; idx++){
+ if (memcmp(DemodBuffer+idx, preamble, EM_PREAMBLE_LEN) == 0){
+ //first index found
+ *startIdx = idx;
+ found = 1;
+ break;