Skip to content

Commit

Permalink
auto_analyse_raw_data Add kXxMsbFirst to easy change MSBFirst for the…
Browse files Browse the repository at this point in the history
… full protocol
  • Loading branch information
NiKiZe committed Sep 6, 2024
1 parent 5406737 commit a02bf4f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 34 deletions.
11 changes: 7 additions & 4 deletions tools/auto_analyse_raw_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def add_data_code(self, bin_str, name="", footer=True):
code.append(f" // Data Section #{self.section_count}")
code.append(f" // e.g. data = 0x{int(bin_str, 2):X}, nbits = {nbits}")
code.append(f" sendData(k{name}BitMark, k{name}OneSpace, k{name}BitMark,"
f" k{name}ZeroSpace, send_data, {nbits}, true);")
f" k{name}ZeroSpace, send_data, {nbits}, k{name}MsbFirst);")
code.append(f" send_data >>= {nbits};")
if footer:
code.append(" // Footer")
Expand All @@ -122,7 +122,8 @@ def add_data_decode_code(self, bin_str, name="", footer=True):
f" // e.g. data_result.data = 0x{int(bin_str, 2):X}, nbits = {nbits}",
f" data_result = matchData(&(results->rawbuf[offset]), {nbits},",
f" k{name}BitMark, k{name}OneSpace,",
f" k{name}BitMark, k{name}ZeroSpace);",
f" k{name}BitMark, k{name}ZeroSpace,",
f" kUseDefTol, kMarkExcess, k{name}MsbFirst);",
" offset += data_result.used;",
" if (data_result.success == false) return false; // Fail",
f" data <<= {nbits}; // Make room for the new bits of data.",
Expand Down Expand Up @@ -163,7 +164,8 @@ def add_data_byte_code(self, bin_str, name="", ambles=None):
f" k{name}BitMark, k{name}ZeroSpace,",
f" {lastmark}, {lastspace},",
f" data + pos, {int(nbytes)}, // Bytes",
f" k{name}Freq, true, kNoRepeat, kDutyDefault);",
f" k{name}Freq, k{name}MsbFirst, kNoRepeat,"
" kDutyDefault);",
f" pos += {int(nbytes)};"
f" // Adjust by how many bytes of data we sent"])
return code
Expand Down Expand Up @@ -198,7 +200,7 @@ def add_data_byte_decode_code(self, bin_str, name="", ambles=None):
f" {firstmark}, {firstspace},",
f" k{name}BitMark, k{name}OneSpace,",
f" k{name}BitMark, k{name}ZeroSpace,",
f" {lastmark}, {lastspace}, true);",
f" {lastmark}, {lastspace}, k{name}MsbFirst);",
" if (used == 0) return false; // We failed to find any data.",
" offset += used; // Adjust for how much of the message we read.",
f" pos += {int(nbytes)};"
Expand Down Expand Up @@ -351,6 +353,7 @@ def dump_constants(message, defines, name="", output=sys.stdout):
defines.append(f"const uint16_t k{name}SpaceGap{count} = {gap};")
defines.append(f"const uint16_t k{name}Freq = 38000; "
"// Hz. (Guessing the most common frequency.)")
defines.append(f"const bool k{name}MsbFirst = true; // default assumption")


def parse_and_report(rawdata_str, margin, gen_code=False, name="",
Expand Down
77 changes: 47 additions & 30 deletions tools/auto_analyse_raw_data_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def test_dump_constants_simple(self):
'const uint16_t kBAROneSpace = 1485;',
'const uint16_t kBARZeroSpace = 520;',
'const uint16_t kBARFreq = 38000; // Hz. (Guessing the most common '
'frequency.)'
'frequency.)',
'const bool kBARMsbFirst = true; // default assumption'
])
self.assertEqual(
output.getvalue(), 'Guessing key value:\n'
Expand Down Expand Up @@ -113,7 +114,8 @@ def test_dump_constants_aircon(self):
'const uint16_t kTESTZeroSpace = 554;',
'const uint16_t kTESTSpaceGap = 19990;',
'const uint16_t kTESTFreq = 38000; // Hz. (Guessing the most common '
'frequency.)'
'frequency.)',
'const bool kTESTMsbFirst = true; // default assumption'
])
self.assertEqual(
output.getvalue(), 'Guessing key value:\n'
Expand Down Expand Up @@ -302,6 +304,7 @@ def test_parse_and_report(self):
'const uint16_t kFOOZeroSpace = 520;\n'
'const uint16_t kFOOFreq = 38000; // Hz. (Guessing the most common'
' frequency.)\n'
'const bool kFOOMsbFirst = true; // default assumption\n'
'const uint16_t kFOOBits = 16; // Move to IRremoteESP8266.h\n'
'const uint16_t kFOOOverhead = 5;\n'
'\n'
Expand All @@ -323,15 +326,15 @@ def test_parse_and_report(self):
' // Data Section #1\n'
' // e.g. data = 0xEB, nbits = 8\n'
' sendData(kFOOBitMark, kFOOOneSpace, kFOOBitMark, kFOOZeroSpace,'
' send_data, 8, true);\n'
' send_data, 8, kFOOMsbFirst);\n'
' send_data >>= 8;\n'
' // Footer\n'
' mark(kFOOBitMark);\n'
' space(kFOOHdrSpace);\n'
' // Data Section #2\n'
' // e.g. data = 0x1, nbits = 8\n'
' sendData(kFOOBitMark, kFOOOneSpace, kFOOBitMark, kFOOZeroSpace,'
' send_data, 8, true);\n'
' send_data, 8, kFOOMsbFirst);\n'
' send_data >>= 8;\n'
' // Footer\n'
' mark(kFOOBitMark);\n'
Expand Down Expand Up @@ -374,7 +377,8 @@ def test_parse_and_report(self):
' // e.g. data_result.data = 0xEB, nbits = 8\n'
' data_result = matchData(&(results->rawbuf[offset]), 8,\n'
' kFOOBitMark, kFOOOneSpace,\n'
' kFOOBitMark, kFOOZeroSpace);\n'
' kFOOBitMark, kFOOZeroSpace,\n'
' kUseDefTol, kMarkExcess, kFOOMsbFirst);\n'
' offset += data_result.used;\n'
' if (data_result.success == false) return false; // Fail\n'
' data <<= 8; // Make room for the new bits of data.\n'
Expand All @@ -390,7 +394,8 @@ def test_parse_and_report(self):
' // e.g. data_result.data = 0x1, nbits = 8\n'
' data_result = matchData(&(results->rawbuf[offset]), 8,\n'
' kFOOBitMark, kFOOOneSpace,\n'
' kFOOBitMark, kFOOZeroSpace);\n'
' kFOOBitMark, kFOOZeroSpace,\n'
' kUseDefTol, kMarkExcess, kFOOMsbFirst);\n'
' offset += data_result.used;\n'
' if (data_result.success == false) return false; // Fail\n'
' data <<= 8; // Make room for the new bits of data.\n'
Expand Down Expand Up @@ -585,6 +590,7 @@ def test_leader_marks(self):
'const uint16_t kHitachiSpaceGap = 49290;\n'
'const uint16_t kHitachiFreq = 38000; // Hz. (Guessing the most'
' common frequency.)\n'
'const bool kHitachiMsbFirst = true; // default assumption\n'
'const uint16_t kHitachiBits = 424; // Move to IRremoteESP8266.h\n'
'const uint16_t kHitachiStateLength = 53; // Move to IRremoteESP8266.h'
'\n'
Expand Down Expand Up @@ -616,7 +622,7 @@ def test_leader_marks(self):
'FFCA358F7000FF00FF01FEC03F807F11EE00FF00FFFF00FF00FF00FF00,'
' nbits = 424\n'
' sendData(kHitachiBitMark, kHitachiOneSpace, kHitachiBitMark,'
' kHitachiZeroSpace, send_data, 424, true);\n'
' kHitachiZeroSpace, send_data, 424, kHitachiMsbFirst);\n'
' send_data >>= 424;\n'
' // Footer\n'
' mark(kHitachiBitMark);\n'
Expand Down Expand Up @@ -663,7 +669,8 @@ def test_leader_marks(self):
' kHitachiBitMark, kHitachiZeroSpace,\n'
' kHitachiBitMark, kHitachiSpaceGap,\n'
' data + pos, 53, // Bytes\n'
' kHitachiFreq, true, kNoRepeat, kDutyDefault);\n'
' kHitachiFreq, kHitachiMsbFirst, kNoRepeat,'
' kDutyDefault);\n'
' pos += 53; // Adjust by how many bytes of data we sent\n'
' }\n'
'}\n'
Expand Down Expand Up @@ -714,7 +721,9 @@ def test_leader_marks(self):
' nbits = 424\n'
' data_result = matchData(&(results->rawbuf[offset]), 424,\n'
' kHitachiBitMark, kHitachiOneSpace,\n'
' kHitachiBitMark, kHitachiZeroSpace);\n'
' kHitachiBitMark, kHitachiZeroSpace,\n'
' kUseDefTol, kMarkExcess,'
' kHitachiMsbFirst);\n'
' offset += data_result.used;\n'
' if (data_result.success == false) return false; // Fail\n'
' data <<= 424; // Make room for the new bits of data.\n'
Expand Down Expand Up @@ -772,7 +781,8 @@ def test_leader_marks(self):
' kHitachiHdrMark, kHitachiHdrSpace,\n'
' kHitachiBitMark, kHitachiOneSpace,\n'
' kHitachiBitMark, kHitachiZeroSpace,\n'
' kHitachiBitMark, kHitachiSpaceGap, true);\n'
' kHitachiBitMark, kHitachiSpaceGap,'
' kHitachiMsbFirst);\n'
' if (used == 0) return false; // We failed to find any data.\n'
' offset += used; // Adjust for how much of the message we read.\n'
' pos += 53; // Adjust by how many bytes of data we read\n'
Expand Down Expand Up @@ -898,6 +908,7 @@ def test_unusual_gaps(self):
'const uint16_t kFOOSpaceGap = 13996;\n'
'const uint16_t kFOOFreq = 38000; // Hz. (Guessing the most common'
' frequency.)\n'
'const bool kFOOMsbFirst = true; // default assumption\n'
'const uint16_t kFOOBits = 128; // Move to IRremoteESP8266.h\n'
'const uint16_t kFOOStateLength = 16; // Move to IRremoteESP8266.h\n'
'const uint16_t kFOOOverhead = 16;\n'
Expand All @@ -922,15 +933,15 @@ def test_unusual_gaps(self):
' // Data Section #1\n'
' // e.g. data = 0x5F5F4040, nbits = 32\n'
' sendData(kFOOBitMark, kFOOOneSpace, kFOOBitMark, kFOOZeroSpace,'
' send_data, 32, true);\n'
' send_data, 32, kFOOMsbFirst);\n'
' send_data >>= 32;\n'
' // Header\n'
' mark(kFOOHdrMark);\n'
' space(kFOOHdrSpace);\n'
' // Data Section #2\n'
' // e.g. data = 0x5F5F4040, nbits = 32\n'
' sendData(kFOOBitMark, kFOOOneSpace, kFOOBitMark, kFOOZeroSpace,'
' send_data, 32, true);\n'
' send_data, 32, kFOOMsbFirst);\n'
' send_data >>= 32;\n'
' // Header\n'
' mark(kFOOHdrMark);\n'
Expand All @@ -944,15 +955,15 @@ def test_unusual_gaps(self):
' // Data Section #3\n'
' // e.g. data = 0x2F2F6C6C, nbits = 32\n'
' sendData(kFOOBitMark, kFOOOneSpace, kFOOBitMark, kFOOZeroSpace,'
' send_data, 32, true);\n'
' send_data, 32, kFOOMsbFirst);\n'
' send_data >>= 32;\n'
' // Header\n'
' mark(kFOOHdrMark);\n'
' space(kFOOHdrSpace);\n'
' // Data Section #4\n'
' // e.g. data = 0x2F2F6C6C, nbits = 32\n'
' sendData(kFOOBitMark, kFOOOneSpace, kFOOBitMark, kFOOZeroSpace,'
' send_data, 32, true);\n'
' send_data, 32, kFOOMsbFirst);\n'
' send_data >>= 32;\n'
' // Header\n'
' mark(kFOOHdrMark);\n'
Expand Down Expand Up @@ -994,7 +1005,7 @@ def test_unusual_gaps(self):
' kFOOBitMark, kFOOZeroSpace,\n'
' kFOOHdrMark, kFOOHdrSpace,\n'
' data + pos, 4, // Bytes\n'
' kFOOFreq, true, kNoRepeat, kDutyDefault);\n'
' kFOOFreq, kFOOMsbFirst, kNoRepeat, kDutyDefault);\n'
' pos += 4; // Adjust by how many bytes of data we sent\n'
' // Data Section #2\n'
' // e.g.\n'
Expand All @@ -1005,7 +1016,7 @@ def test_unusual_gaps(self):
' kFOOBitMark, kFOOZeroSpace,\n'
' kFOOHdrMark, kFOOHdrSpace,\n'
' data + pos, 4, // Bytes\n'
' kFOOFreq, true, kNoRepeat, kDutyDefault);\n'
' kFOOFreq, kFOOMsbFirst, kNoRepeat, kDutyDefault);\n'
' pos += 4; // Adjust by how many bytes of data we sent\n'
' // Data Section #3\n'
' // e.g.\n'
Expand All @@ -1016,7 +1027,7 @@ def test_unusual_gaps(self):
' kFOOBitMark, kFOOZeroSpace,\n'
' kFOOHdrMark, kFOOHdrSpace,\n'
' data + pos, 4, // Bytes\n'
' kFOOFreq, true, kNoRepeat, kDutyDefault);\n'
' kFOOFreq, kFOOMsbFirst, kNoRepeat, kDutyDefault);\n'
' pos += 4; // Adjust by how many bytes of data we sent\n'
' // Data Section #4\n'
' // e.g.\n'
Expand All @@ -1027,7 +1038,7 @@ def test_unusual_gaps(self):
' kFOOBitMark, kFOOZeroSpace,\n'
' kFOOHdrMark, kFOOHdrSpace,\n'
' data + pos, 4, // Bytes\n'
' kFOOFreq, true, kNoRepeat, kDutyDefault);\n'
' kFOOFreq, kFOOMsbFirst, kNoRepeat, kDutyDefault);\n'
' pos += 4; // Adjust by how many bytes of data we sent\n'
' }\n'
'}\n'
Expand Down Expand Up @@ -1068,7 +1079,8 @@ def test_unusual_gaps(self):
' // e.g. data_result.data = 0x5F5F4040, nbits = 32\n'
' data_result = matchData(&(results->rawbuf[offset]), 32,\n'
' kFOOBitMark, kFOOOneSpace,\n'
' kFOOBitMark, kFOOZeroSpace);\n'
' kFOOBitMark, kFOOZeroSpace,\n'
' kUseDefTol, kMarkExcess, kFOOMsbFirst);\n'
' offset += data_result.used;\n'
' if (data_result.success == false) return false; // Fail\n'
' data <<= 32; // Make room for the new bits of data.\n'
Expand All @@ -1084,7 +1096,8 @@ def test_unusual_gaps(self):
' // e.g. data_result.data = 0x5F5F4040, nbits = 32\n'
' data_result = matchData(&(results->rawbuf[offset]), 32,\n'
' kFOOBitMark, kFOOOneSpace,\n'
' kFOOBitMark, kFOOZeroSpace);\n'
' kFOOBitMark, kFOOZeroSpace,\n'
' kUseDefTol, kMarkExcess, kFOOMsbFirst);\n'
' offset += data_result.used;\n'
' if (data_result.success == false) return false; // Fail\n'
' data <<= 32; // Make room for the new bits of data.\n'
Expand Down Expand Up @@ -1112,7 +1125,8 @@ def test_unusual_gaps(self):
' // e.g. data_result.data = 0x2F2F6C6C, nbits = 32\n'
' data_result = matchData(&(results->rawbuf[offset]), 32,\n'
' kFOOBitMark, kFOOOneSpace,\n'
' kFOOBitMark, kFOOZeroSpace);\n'
' kFOOBitMark, kFOOZeroSpace,\n'
' kUseDefTol, kMarkExcess, kFOOMsbFirst);\n'
' offset += data_result.used;\n'
' if (data_result.success == false) return false; // Fail\n'
' data <<= 32; // Make room for the new bits of data.\n'
Expand All @@ -1128,7 +1142,8 @@ def test_unusual_gaps(self):
' // e.g. data_result.data = 0x2F2F6C6C, nbits = 32\n'
' data_result = matchData(&(results->rawbuf[offset]), 32,\n'
' kFOOBitMark, kFOOOneSpace,\n'
' kFOOBitMark, kFOOZeroSpace);\n'
' kFOOBitMark, kFOOZeroSpace,\n'
' kUseDefTol, kMarkExcess, kFOOMsbFirst);\n'
' offset += data_result.used;\n'
' if (data_result.success == false) return false; // Fail\n'
' data <<= 32; // Make room for the new bits of data.\n'
Expand Down Expand Up @@ -1189,7 +1204,7 @@ def test_unusual_gaps(self):
' kFOOHdrMark, kFOOHdrSpace,\n'
' kFOOBitMark, kFOOOneSpace,\n'
' kFOOBitMark, kFOOZeroSpace,\n'
' kFOOHdrMark, kFOOHdrSpace, true);\n'
' kFOOHdrMark, kFOOHdrSpace, kFOOMsbFirst);\n'
' if (used == 0) return false; // We failed to find any data.\n'
' offset += used; // Adjust for how much of the message we read.\n'
' pos += 4; // Adjust by how many bytes of data we read\n'
Expand All @@ -1204,7 +1219,7 @@ def test_unusual_gaps(self):
' kFOOHdrMark, kFOOHdrSpace,\n'
' kFOOBitMark, kFOOOneSpace,\n'
' kFOOBitMark, kFOOZeroSpace,\n'
' kFOOHdrMark, kFOOHdrSpace, true);\n'
' kFOOHdrMark, kFOOHdrSpace, kFOOMsbFirst);\n'
' if (used == 0) return false; // We failed to find any data.\n'
' offset += used; // Adjust for how much of the message we read.\n'
' pos += 4; // Adjust by how many bytes of data we read\n'
Expand All @@ -1219,7 +1234,7 @@ def test_unusual_gaps(self):
' kFOOHdrMark, kFOOHdrSpace,\n'
' kFOOBitMark, kFOOOneSpace,\n'
' kFOOBitMark, kFOOZeroSpace,\n'
' kFOOHdrMark, kFOOHdrSpace, true);\n'
' kFOOHdrMark, kFOOHdrSpace, kFOOMsbFirst);\n'
' if (used == 0) return false; // We failed to find any data.\n'
' offset += used; // Adjust for how much of the message we read.\n'
' pos += 4; // Adjust by how many bytes of data we read\n'
Expand All @@ -1234,7 +1249,7 @@ def test_unusual_gaps(self):
' kFOOHdrMark, kFOOHdrSpace,\n'
' kFOOBitMark, kFOOOneSpace,\n'
' kFOOBitMark, kFOOZeroSpace,\n'
' kFOOHdrMark, kFOOHdrSpace, true);\n'
' kFOOHdrMark, kFOOHdrSpace, kFOOMsbFirst);\n'
' if (used == 0) return false; // We failed to find any data.\n'
' offset += used; // Adjust for how much of the message we read.\n'
' pos += 4; // Adjust by how many bytes of data we read\n'
Expand Down Expand Up @@ -1333,6 +1348,7 @@ def test_no_headers(self):
'const uint16_t kZeroSpace = 547;\n'
'const uint16_t kFreq = 38000; // Hz. (Guessing the most common'
' frequency.)\n'
'const bool kMsbFirst = true; // default assumption\n'
'const uint16_t kBits = 128; // Move to IRremoteESP8266.h\n'
'const uint16_t kStateLength = 16; // Move to IRremoteESP8266.h\n'
'const uint16_t kOverhead = 1;\n'
Expand All @@ -1354,7 +1370,7 @@ def test_no_headers(self):
' // Data Section #1\n'
' // e.g. data = 0xA55A0000400000000000000000000080, nbits = 128\n'
' sendData(kBitMark, kOneSpace, kBitMark, kZeroSpace, send_data,'
' 128, true);\n'
' 128, kMsbFirst);\n'
' send_data >>= 128;\n'
' // Footer\n'
' mark(kBitMark);\n'
Expand Down Expand Up @@ -1393,7 +1409,7 @@ def test_no_headers(self):
' kBitMark, kZeroSpace,\n'
' kBitMark, kDefaultMessageGap,\n'
' data + pos, 16, // Bytes\n'
' kFreq, true, kNoRepeat, kDutyDefault);\n'
' kFreq, kMsbFirst, kNoRepeat, kDutyDefault);\n'
' pos += 16; // Adjust by how many bytes of data we sent\n'
' }\n'
'}\n'
Expand Down Expand Up @@ -1429,7 +1445,8 @@ def test_no_headers(self):
' = 128\n'
' data_result = matchData(&(results->rawbuf[offset]), 128,\n'
' kBitMark, kOneSpace,\n'
' kBitMark, kZeroSpace);\n'
' kBitMark, kZeroSpace,\n'
' kUseDefTol, kMarkExcess, kMsbFirst);\n'
' offset += data_result.used;\n'
' if (data_result.success == false) return false; // Fail\n'
' data <<= 128; // Make room for the new bits of data.\n'
Expand Down Expand Up @@ -1483,7 +1500,7 @@ def test_no_headers(self):
' 0, 0,\n'
' kBitMark, kOneSpace,\n'
' kBitMark, kZeroSpace,\n'
' kBitMark, kDefaultMessageGap, true);\n'
' kBitMark, kDefaultMessageGap, kMsbFirst);\n'
' if (used == 0) return false; // We failed to find any data.\n'
' offset += used; // Adjust for how much of the message we read.\n'
' pos += 16; // Adjust by how many bytes of data we read\n'
Expand Down

0 comments on commit a02bf4f

Please sign in to comment.