+bool testModulation(uint8_t mode, uint8_t modread){\r
+ switch( mode ){\r
+ case DEMOD_FSK:\r
+ if (modread > 3 && modread < 8) return TRUE;\r
+ break;\r
+ case DEMOD_ASK:\r
+ if (modread == DEMOD_ASK) return TRUE;\r
+ break;\r
+ case DEMOD_PSK1:\r
+ if (modread == DEMOD_PSK1) return TRUE;\r
+ break;\r
+ case DEMOD_PSK2:\r
+ if (modread == DEMOD_PSK2) return TRUE;\r
+ break;\r
+ case DEMOD_PSK3:\r
+ if (modread == DEMOD_PSK3) return TRUE;\r
+ break;\r
+ case DEMOD_NRZ:\r
+ if (modread == DEMOD_NRZ) return TRUE;\r
+ break;\r
+ case DEMOD_BI:\r
+ if (modread == DEMOD_BI) return TRUE;\r
+ break;\r
+ case DEMOD_BIa:\r
+ if (modread == DEMOD_BIa) return TRUE;\r
+ break; \r
+ default:\r
+ return FALSE;\r
+ }\r
+ return FALSE;\r
+}\r
+\r
+bool testBitRate(uint8_t readRate, uint8_t mod){\r
+ uint8_t expected[8] = {8, 16, 32, 40, 50, 64, 100, 128};\r
+ uint8_t detRate = 0;\r
+ switch( mod ){\r
+ case DEMOD_FSK:\r
+ case DEMOD_FSK1:\r
+ case DEMOD_FSK1a:\r
+ case DEMOD_FSK2:\r
+ case DEMOD_FSK2a:\r
+ detRate = GetFskClock("",FALSE, FALSE); \r
+ if (expected[readRate] == detRate) \r
+ return TRUE;\r
+ break;\r
+ case DEMOD_ASK:\r
+ case DEMOD_BI:\r
+ case DEMOD_BIa:\r
+ detRate = GetAskClock("",FALSE, FALSE); \r
+ if (expected[readRate] == detRate) \r
+ return TRUE;\r
+ break;\r
+ case DEMOD_PSK1:\r
+ case DEMOD_PSK2:\r
+ case DEMOD_PSK3:\r
+ detRate = GetPskClock("",FALSE, FALSE); \r
+ if (expected[readRate] == detRate)\r
+ return TRUE;\r
+ break;\r
+ case DEMOD_NRZ:\r
+ detRate = GetNrzClock("",FALSE, FALSE); \r
+ if (expected[readRate] == detRate)\r
+ return TRUE;\r
+ break;\r
+ default:\r
+ return FALSE;\r
+ }\r
+ return FALSE;\r
+}\r
+\r
+bool test(uint8_t mode, uint8_t *offset, int *fndBitRate){\r
+\r
+ if ( DemodBufferLen < 64 ) return FALSE;\r
+ uint8_t si = 0;\r
+ for (uint8_t idx = 0; idx < 64; idx++){\r
+ si = idx;\r
+ if ( PackBits(si, 32, DemodBuffer) == 0x00 ) continue;\r
+\r
+ uint8_t safer = PackBits(si, 4, DemodBuffer); si += 4; //master key\r
+ uint8_t resv = PackBits(si, 4, DemodBuffer); si += 4; //was 7 & +=7+3 //should be only 4 bits if extended mode\r
+ // 2nibble must be zeroed.\r
+ // moved test to here, since this gets most faults first.\r
+ if ( resv > 0x00) continue;\r
+\r
+ uint8_t xtRate = PackBits(si, 3, DemodBuffer); si += 3; //extended mode part of rate\r
+ int bitRate = PackBits(si, 3, DemodBuffer); si += 3; //bit rate\r
+ if (bitRate > 7) continue;\r
+ uint8_t extend = PackBits(si, 1, DemodBuffer); si += 1; //bit 15 extended mode\r
+ uint8_t modread = PackBits(si, 5, DemodBuffer); si += 5+2+1; \r
+ //uint8_t pskcr = PackBits(si, 2, DemodBuffer); si += 2+1; //could check psk cr\r
+ uint8_t nml01 = PackBits(si, 1, DemodBuffer); si += 1+5; //bit 24, 30, 31 could be tested for 0 if not extended mode\r
+ uint8_t nml02 = PackBits(si, 2, DemodBuffer); si += 2;\r
+ \r
+ //if extended mode\r
+ bool extMode =( (safer == 0x6 || safer == 0x9) && extend) ? TRUE : FALSE;\r
+\r
+ if (!extMode){\r
+ if (nml01 || nml02 || xtRate) continue;\r
+ }\r
+ //test modulation\r
+ if (!testModulation(mode, modread)) continue;\r
+ if (!testBitRate(bitRate, mode)) continue;\r
+ *fndBitRate = bitRate;\r
+ *offset = idx;\r
+ return TRUE;\r
+ }\r
+ return FALSE;\r
+}\r
+\r
+void printT55xxBlock(const char *blockNum){\r