-/*\r
-FSK1 / FSK1a\r
-size = fskdemod(dest, size, 32, 0, 8, 10); // fsk1 RF/32 \r
-size = fskdemod(dest, size, 32, 1, 8, 10); // fsk1a RF/32 \r
-\r
-FSK2 / FSK2a\r
-size = fskdemod(dest, size, 32, 0, 10, 8); // fsk2 RF/32 \r
-size = fskdemod(dest, size, 32, 1, 10, 8); // fsk2a RF/32 \r
-size = fskdemod(dest, size, 50, 1, 10, 8); // fsk2a RF/50 \r
-size = fskdemod(dest, size, 64, 1, 10, 8); // FSK2a RF/64 \r
-\r
-PSK1\r
-errCnt = pskRawDemod(bits, &bitlen, 32, 0);\r
-*/\r
-bool tryDemod(uint8_t bits[], size_t bitlen) {\r
- \r
- int invert = 0;\r
- int clk = 0;\r
- int errCnt, size;\r
- int maxErr = 100;\r
- uint8_t rflen, fchigh, fclow, dummy = 0;\r
- uint16_t fcs=0;\r
-\r
- // ASK - manchester demod\r
- errCnt = askmandemod(bits, &bitlen, &clk, &invert, maxErr);\r
- if ( analyseDemod(errCnt, bitlen, clk, invert) ) \r
- return true;\r
-\r
- // FSK demod\r
- fcs = countFC(bits, bitlen, &dummy);\r
- if (fcs == 0){\r
- fchigh = 10;\r
- fclow = 8;\r
- }else{\r
- fchigh = (fcs >> 8) & 0xFF;\r
- fclow = fcs & 0xFF;\r
+ // PSK2 - needs a call to psk1TOpsk2.\r
+ if ( PSKDemod("0 0 1", FALSE)) {\r
+ psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
+ if (test(DEMOD_PSK2, &tests[hits].offset)){\r
+ tests[hits].modulation = DEMOD_PSK2;\r
+ tests[hits].inverted = FALSE;\r
+ tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer); \r
+ ++hits;\r
+ }\r
+ }\r
+ // PSK2 - needs a call to psk1TOpsk2.\r
+ if ( PSKDemod("0 1 1", FALSE)) {\r
+ psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
+ if (test(DEMOD_PSK2, &tests[hits].offset)){\r
+ tests[hits].modulation = DEMOD_PSK2;\r
+ tests[hits].inverted = TRUE;\r
+ tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer); \r
+ ++hits;\r
+ }\r
+ }\r
+\r
+ // PSK3 - needs a call to psk1TOpsk2.\r
+ if ( PSKDemod("0 0 1", FALSE)) {\r
+ psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
+ if (test(DEMOD_PSK3, &tests[hits].offset)){\r
+ tests[hits].modulation = DEMOD_PSK3;\r
+ tests[hits].inverted = FALSE;\r
+ tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer); \r
+ ++hits;\r
+ }\r
+ }\r
+ // PSK3 - needs a call to psk1TOpsk2.\r
+ if ( PSKDemod("0 1 1", FALSE)) {\r
+ psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
+ if (test(DEMOD_PSK3, &tests[hits].offset)){\r
+ tests[hits].modulation = DEMOD_PSK3;\r
+ tests[hits].inverted = TRUE;\r
+ tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
+ ++hits;\r
+ }\r
+ }\r
+ \r
+ if ( ASKbiphaseDemod("0 0 0 1", FALSE) && test(DEMOD_BI, &tests[hits].offset) ) {\r
+ tests[hits].modulation = DEMOD_BI;\r
+ tests[hits].inverted = FALSE;\r
+ tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
+ ++hits;\r
+ }\r
+ if ( ASKbiphaseDemod("0 0 1 1", FALSE) && test(DEMOD_BI, &tests[hits].offset) ) {\r
+ tests[hits].modulation = DEMOD_BI;\r
+ tests[hits].inverted = TRUE;\r
+ tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
+ ++hits;\r
+ }\r
+ } \r
+\r
+ if ( hits == 1) {\r
+ config.modulation = tests[0].modulation;\r
+ config.inverted = tests[0].inverted;\r
+ config.offset = tests[0].offset;\r
+ \r
+ DecodeT55xxBlock();\r
+ if (DemodBufferLen > config.offset + 32) \r
+ config.block0 = PackBits(config.offset, 32, DemodBuffer);\r
+ printConfiguration( config );\r
+ return TRUE;\r
+ }\r
+ \r
+ if ( hits > 1) {\r
+ PrintAndLog("Found [%d] possible matches for modulation.",hits);\r
+ for(int i=0; i<hits; ++i){\r
+ PrintAndLog("--[%d]---------------", i+1);\r
+ printConfiguration( tests[i] );\r
+ }\r