- \r
- bitlen = getFromGraphBuf(bits);\r
-\r
- int ans = 0;\r
- ans = CmdFSKrawdemod("");\r
- ans = CmdFSKrawdemod("1"); //invert?\r
- ans = Cmdaskmandemod("");\r
- ans = Cmdaskrawdemod("");\r
- ans = CmdNRZrawDemod("");\r
- ans = CmdPSK1rawDemod("");\r
- ans = CmdPSK2rawDemod("");\r
- \r
- // if ( !tryDemod(bits, bitlen) )\r
- // return 3;\r
- \r
- // //move bits back to DemodBuffer\r
- // setDemodBuf(bits, bitlen, 0);\r
- // printBitStream(bits, bitlen);\r
+ \r
+ if ( !tryDetectModulation() ){\r
+ PrintAndLog("Could not detect modulation automatically. Try setting it manually with \'lf t55xx config\'");\r
+ }\r
+ return 0;\r
+}\r
+\r
+// detect configuration?\r
+bool tryDetectModulation(){\r
+ \r
+ uint8_t hits = 0;\r
+ t55xx_conf_block_t tests[10];\r
+ \r
+ if (GetFskClock("", FALSE, FALSE)){ \r
+ if ( FSKrawDemod("0 0", FALSE) && test()){\r
+ tests[hits].modulation = 1;\r
+ tests[hits].inversed = 0;\r
+ ++hits;\r
+ }\r
+ if ( FSKrawDemod("0 1", FALSE) && test()) {\r
+ tests[hits].modulation = 1;\r
+ tests[hits].inversed = 1;\r
+ ++hits;\r
+ }\r
+ } else {\r
+ if ( ASKmanDemod("0 0 1", FALSE, FALSE) && test()) {\r
+ tests[hits].modulation = 2;\r
+ tests[hits].inversed = 0;\r
+ ++hits;\r
+ }\r
+\r
+ if ( ASKmanDemod("0 1 1", FALSE, FALSE) && test()) {\r
+ tests[hits].modulation = 2;\r
+ tests[hits].inversed = 1;\r
+ ++hits;\r
+ }\r
+ \r
+ if ( NRZrawDemod("0 0 1", FALSE) && test()) {\r
+ tests[hits].modulation = 3;\r
+ tests[hits].inversed = 0;\r
+ ++hits;\r
+ }\r
+\r
+ if ( NRZrawDemod("0 1 1", FALSE) && test()) {\r
+ tests[hits].modulation = 3;\r
+ tests[hits].inversed = 1;\r
+ ++hits;\r
+ }\r
+ \r
+ if ( PSKDemod("0 0 1", FALSE) && test()) {\r
+ tests[hits].modulation = 4;\r
+ tests[hits].inversed = 0;\r
+ ++hits;\r
+ }\r
+ \r
+ if ( PSKDemod("0 1 1", FALSE) && test()) {\r
+ tests[++hits].modulation = 4;\r
+ tests[hits].inversed = 1;\r
+ ++hits;\r
+ }\r
+ //PSK2?\r
+ // if (!BiphaseRawDecode("0",FALSE) && test()) {\r
+ // tests[++hits].modulation = 5;\r
+ // tests[hits].inversed = 0;\r
+ //}\r
+ // if (!BiphaseRawDecode("1",FALSE) && test()) {\r
+ // tests[++hits].modulation = 5;\r
+ // tests[hits].inversed = 1;\r
+ // }\r
+ } \r
+ if ( hits == 1) {\r
+ PrintAndLog("Modulation: %d Inverse: %d", tests[0].modulation, tests[0].inversed);\r
+ config.modulation = tests[0].modulation;\r
+ config.inversed = tests[0].inversed;\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("Modulation: %d Inverse: %d", tests[i].modulation, tests[i].inversed);\r
+ }\r
+ }\r
+ return FALSE;\r
+}\r
+\r
+bool test(){\r
+\r