+// 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 = DEMOD_FSK;\r
+ tests[hits].inversed = FALSE;\r
+ ++hits;\r
+ }\r
+ if ( FSKrawDemod("0 1", FALSE) && test()) {\r
+ tests[hits].modulation = DEMOD_FSK;\r
+ tests[hits].inversed = TRUE;\r
+ ++hits;\r
+ }\r
+ } else {\r
+ if ( ASKmanDemod("0 0 1", FALSE, FALSE) && test()) {\r
+ tests[hits].modulation = DEMOD_ASK;\r
+ tests[hits].inversed = FALSE;\r
+ ++hits;\r
+ }\r
+\r
+ if ( ASKmanDemod("0 1 1", FALSE, FALSE) && test()) {\r
+ tests[hits].modulation = DEMOD_ASK;\r
+ tests[hits].inversed = TRUE;\r
+ ++hits;\r
+ }\r
+ \r
+ if ( NRZrawDemod("0 0 1", FALSE) && test()) {\r
+ tests[hits].modulation = DEMOD_NZR;\r
+ tests[hits].inversed = FALSE;\r
+ ++hits;\r
+ }\r
+\r
+ if ( NRZrawDemod("0 1 1", FALSE) && test()) {\r
+ tests[hits].modulation = DEMOD_NZR;\r
+ tests[hits].inversed = TRUE;\r
+ ++hits;\r
+ }\r
+ \r
+ if ( PSKDemod("0 0 1", FALSE) >= 0 && test()) {\r
+ tests[hits].modulation = DEMOD_PSK;\r
+ tests[hits].inversed = FALSE;\r
+ ++hits;\r
+ }\r
+ \r
+ if ( PSKDemod("0 1 1", FALSE) >= 0 && test()) {\r
+ tests[hits].modulation = DEMOD_PSK;\r
+ tests[hits].inversed = TRUE;\r
+ ++hits;\r
+ }\r
+ //PSK2?\r
+ // if (!BiphaseRawDecode("0",FALSE) && test()) {\r
+ // tests[++hits].modulation = DEMOD_BI;\r
+ // tests[hits].inversed = FALSE;\r
+ //}\r
+ // if (!BiphaseRawDecode("1",FALSE) && test()) {\r
+ // tests[++hits].modulation = DEMOD_BI;\r
+ // tests[hits].inversed = TRUE;\r
+ // }\r
+ } \r
+ if ( hits == 1) {\r
+ config.modulation = tests[0].modulation;\r
+ config.inversed = tests[0].inversed;\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
+ }\r
+ return FALSE;\r
+}\r
+\r
+bool test(){\r
+\r
+ if ( !DemodBufferLen) \r
+ return false;\r
+ \r
+ uint8_t si = 1;\r
+ uint8_t safer = PackBits(si, 4, DemodBuffer); si += 4; \r
+ uint8_t resv = PackBits(si, 7, DemodBuffer); si += 7+3;\r
+ uint8_t extend = PackBits(si, 1, DemodBuffer); si += 1;\r
+\r
+ //PrintAndLog("test: %X %X %X ", safer, resv, extend);\r
+ \r
+ // 2nibble must be zeroed.\r
+ if ( resv > 0x00) return FALSE;\r
+\r
+ if ( safer == 0x6 || safer == 0x9){\r
+ if ( extend == 0x00)\r
+ return TRUE;\r
+ }\r
+ if ( resv== 0x00) return TRUE;\r
+ return FALSE;\r
+}\r
+\r
+void printT55xxBlock(const char *demodStr){\r
+ \r
+ uint32_t blockData = 0;\r
+ uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0x00};\r
+ \r
+ if ( !DemodBufferLen) \r
+ return;\r
+ \r
+ int i =0;\r
+ for (;i<DemodBufferLen;++i)\r
+ bits[i]=DemodBuffer[i];\r
+ \r
+ blockData = PackBits(1, 32, bits);\r
+ PrintAndLog("0x%08X %s [%s]", blockData, sprint_bin(bits+1,32), demodStr);\r
+}\r
+\r
+void printConfiguration( t55xx_conf_block_t b){\r
+ PrintAndLog("Modulation : %s", GetSelectedModulationStr(b.modulation) );\r
+ PrintAndLog("Inverted : %s", (b.inversed) ? "Yes" : "No" );\r
+ PrintAndLog("Block0 : %08X", b.block0);\r
+ PrintAndLog("");\r
+}\r
+\r
+int CmdT55xxWriteBlock(const char *Cmd)\r