Update IRRemoteESP8266 version to 2.5.5

factorize IR send signal function between the 2 types of receiving
Add new IRRemoteESP8266 protocols
replace pins on mega according schema
remove unecessaries spaces
This commit is contained in:
Florian committed 2019-02-08 16:50:37 +01:00
1 parent 0180a0dbd5
commit f0305236db
149 files changed
+20957 -7850

No files matched your search

+28 -4
View File
@@ -22,7 +22,7 @@ CPPFLAGS += -DUNIT_TEST
# Flags passed to the C++ compiler.
CXXFLAGS += -g -Wall -Wextra -pthread
all : gc_decode
all : gc_decode mode2_decode
run_tests : all
failed=""; \
@@ -37,7 +37,7 @@ run_tests : all
fi
clean :
rm -f *.o *.pyc gc_decode
rm -f *.o *.pyc gc_decode mode2_decode
# All the IR protocol object files.
@@ -47,7 +47,8 @@ PROTOCOLS = ir_NEC.o ir_Sony.o ir_Samsung.o ir_JVC.o ir_RCMM.o ir_RC5_RC6.o \
ir_Aiwa.o ir_Sherwood.o ir_Kelvinator.o ir_Daikin.o ir_Gree.o \
ir_Pronto.o ir_GlobalCache.o ir_Nikai.o ir_Toshiba.o ir_Midea.o \
ir_Magiquest.o ir_Lasertag.o ir_Carrier.o ir_Haier.o ir_Hitachi.o \
ir_GICable.o
ir_GICable.o ir_Whirlpool.o ir_Lutron.o ir_Electra.o ir_Pioneer.o \
ir_MWM.o ir_Vestel.o
# Common object files
COMMON_OBJ = IRutils.o IRtimer.o IRsend.o IRrecv.o $(PROTOCOLS)
@@ -64,6 +65,11 @@ gc_decode.o : gc_decode.cpp $(COMMON_TEST_DEPS) $(GTEST_HEADERS)
gc_decode : $(COMMON_OBJ) gc_decode.o
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
mode2_decode.o : mode2_decode.cpp $(COMMON_TEST_DEPS) $(GTEST_HEADERS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -I$(USER_DIR) -I$(TEST_DIR) -c mode2_decode.cpp
mode2_decode : $(COMMON_OBJ) mode2_decode.o
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
IRutils.o : $(USER_DIR)/IRutils.cpp $(USER_DIR)/IRutils.h $(USER_DIR)/IRremoteESP8266.h
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/IRutils.cpp
@@ -90,7 +96,7 @@ ir_Sherwood.o : $(USER_DIR)/ir_Sherwood.cpp $(COMMON_DEPS)
ir_Sony.o : $(USER_DIR)/ir_Sony.cpp $(COMMON_DEPS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/ir_Sony.cpp
ir_Samsung.o : $(USER_DIR)/ir_Samsung.cpp $(COMMON_DEPS)
ir_Samsung.o : $(USER_DIR)/ir_Samsung.cpp $(USER_DIR)/ir_Samsung.h $(COMMON_DEPS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/ir_Samsung.cpp
ir_Kelvinator.o : $(USER_DIR)/ir_Kelvinator.cpp $(USER_DIR)/ir_Kelvinator.h $(COMMON_DEPS)
@@ -173,3 +179,21 @@ ir_Hitachi.o : $(USER_DIR)/ir_Hitachi.cpp $(GTEST_HEADERS)
ir_GICable.o : $(USER_DIR)/ir_GICable.cpp $(GTEST_HEADERS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/ir_GICable.cpp
ir_Whirlpool.o : $(USER_DIR)/ir_Whirlpool.cpp $(GTEST_HEADERS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/ir_Whirlpool.cpp
ir_Lutron.o : $(USER_DIR)/ir_Lutron.cpp $(GTEST_HEADERS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/ir_Lutron.cpp
ir_Electra.o : $(USER_DIR)/ir_Electra.cpp $(GTEST_HEADERS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/ir_Electra.cpp
ir_Pioneer.o : $(USER_DIR)/ir_Pioneer.cpp $(GTEST_HEADERS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/ir_Pioneer.cpp
ir_MWM.o : $(USER_DIR)/ir_MWM.cpp $(USER_DIR)/ir_RC5_RC6.cpp $(COMMON_DEPS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/ir_MWM.cpp
ir_Vestel.o : $(USER_DIR)/ir_Vestel.cpp $(GTEST_HEADERS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/ir_Vestel.cpp
@@ -1,7 +1,7 @@
#!/usr/bin/python
"""Attempt an automatic analysis of IRremoteESP8266's Raw data output.
Makes suggestions on key values and tried to break down the message
into likely chuncks."""
into likely chunks."""
#
# Copyright 2018 David Conran
import argparse
@@ -22,7 +22,9 @@ class RawIRMessage(object):
self.gaps = []
self.margin = margin
self.marks = []
self.mark_buckets = {}
self.spaces = []
self.space_buckets = {}
self.output = output
self.verbose = verbose
if len(timings) <= 3:
@@ -40,22 +42,26 @@ class RawIRMessage(object):
self.marks.append(usecs)
else:
self.spaces.append(usecs)
self.marks = self._reduce_list(self.marks)
self.spaces = self._reduce_list(self.spaces)
self.marks, self.mark_buckets = self.reduce_list(self.marks)
self.spaces, self.space_buckets = self.reduce_list(self.spaces)
def _reduce_list(self, items):
"""Reduce the list of numbers into buckets that are atleast margin apart."""
def reduce_list(self, items):
"""Reduce a list of numbers into buckets that are at least margin apart."""
result = []
last = -1
buckets = {}
for item in sorted(items, reverse=True):
if last == -1 or item < last - self.margin:
result.append(item)
last = item
return result
buckets[last] = [item]
else:
buckets[last].append(item)
return result, buckets
def _usec_compare(self, seen, expected):
"""Compare two usec values and see if they match within a
subtrative margin."""
subtractive margin."""
return seen <= expected and seen > expected - self.margin
def _usec_compares(self, usecs, expecteds):
@@ -79,21 +85,22 @@ class RawIRMessage(object):
" %s (LSB first)\n"
" Bin: 0b%s (MSB first)\n"
" 0b%s (LSB first)\n" %
(bits, "0x{0:0{1}X}".format(num, bits / 4),
"0x{0:0{1}X}".format(rev_num, bits / 4), num, rev_num,
binary_str, rev_binary_str))
(bits, ("0x{0:0%dX}" % (bits / 4)).format(num),
("0x{0:0%dX}" % (bits / 4)).format(rev_num), num,
rev_num, binary_str, rev_binary_str))
def add_data_code(self, bin_str):
def add_data_code(self, bin_str, footer=True):
"""Add the common "data" sequence of code to send the bulk of a message."""
# pylint: disable=no-self-use
code = []
code.append(" // Data")
code.append(" // e.g. data = 0x%X, nbits = %d" % (int(bin_str, 2),
len(bin_str)))
code.append(" sendData(BIT_MARK, ONE_SPACE, BIT_MARK, ZERO_SPACE, data, "
code.append(" sendData(kBitMark, kOneSpace, kBitMark, kZeroSpace, data, "
"nbits, true);")
code.append(" // Footer")
code.append(" mark(BIT_MARK);")
if footer:
code.append(" // Footer")
code.append(" mark(kBitMark);")
return code
def _calc_values(self):
@@ -104,7 +111,7 @@ class RawIRMessage(object):
"%s\n"
"Potential Space Candidates:\n"
"%s\n" % (str(self.marks), str(self.spaces)))
# Largest mark is likely the HDR_MARK
# Largest mark is likely the kHdrMark
self.hdr_mark = self.marks[0]
# The bit mark is likely to be the smallest mark.
self.bit_mark = self.marks[-1]
@@ -150,8 +157,15 @@ class RawIRMessage(object):
return self._usec_compares(usec, self.gaps)
def avg_list(items):
"""Return the average of a list of numbers."""
if items:
return sum(items) / len(items)
return 0
def add_bit(so_far, bit, output=sys.stdout):
"""Add a bit to the end of the bits collected so far. """
"""Add a bit to the end of the bits collected so far."""
if bit == "reset":
return ""
output.write(str(bit)) # This effectively displays in LSB first order.
@@ -179,30 +193,36 @@ def convert_rawdata(data_str):
def dump_constants(message, defines, output=sys.stdout):
"""Dump the key constants and generate the C++ #defines."""
output.write("Guessing key value:\n"
"HDR_MARK = %d\n"
"HDR_SPACE = %d\n"
"BIT_MARK = %d\n"
"ONE_SPACE = %d\n"
"ZERO_SPACE = %d\n" %
(message.hdr_mark, message.hdr_space, message.bit_mark,
message.one_space, message.zero_space))
defines.append("#define HDR_MARK %dU" % message.hdr_mark)
defines.append("#define BIT_MARK %dU" % message.bit_mark)
defines.append("#define HDR_SPACE %dU" % message.hdr_space)
defines.append("#define ONE_SPACE %dU" % message.one_space)
defines.append("#define ZERO_SPACE %dU" % message.zero_space)
hdr_mark = avg_list(message.mark_buckets[message.hdr_mark])
bit_mark = avg_list(message.mark_buckets[message.bit_mark])
hdr_space = avg_list(message.space_buckets[message.hdr_space])
one_space = avg_list(message.space_buckets[message.one_space])
zero_space = avg_list(message.space_buckets[message.zero_space])
output.write("Guessing key value:\n"
"kHdrMark = %d\n"
"kHdrSpace = %d\n"
"kBitMark = %d\n"
"kOneSpace = %d\n"
"kZeroSpace = %d\n" % (hdr_mark, hdr_space, bit_mark, one_space,
zero_space))
defines.append("const uint16_t kHdrMark = %d;" % hdr_mark)
defines.append("const uint16_t kBitMark = %d;" % bit_mark)
defines.append("const uint16_t kHdrSpace = %d;" % hdr_space)
defines.append("const uint16_t kOneSpace = %d;" % one_space)
defines.append("const uint16_t kZeroSpace = %d;" % zero_space)
avg_gaps = [avg_list(message.space_buckets[x]) for x in message.gaps]
if len(message.gaps) == 1:
output.write("SPACE_GAP = %d\n" % message.gaps[0])
defines.append("#define SPACE_GAP = %dU" % message.gaps[0])
output.write("kSpaceGap = %d\n" % avg_gaps[0])
defines.append("const uint16_t kSpaceGap = %d;" % avg_gaps[0])
else:
count = 0
for gap in message.gaps:
for gap in avg_gaps:
# We probably (still) have a gap in the protocol.
count = count + 1
output.write("SPACE_GAP%d = %d\n" % (count, gap))
defines.append("#define SPACE_GAP%d = %dU" % (count, gap))
output.write("kSpaceGap%d = %d\n" % (count, gap))
defines.append("const uint16_t kSpaceGap%d = %d;" % (count, gap))
def parse_and_report(rawdata_str, margin, gen_code=False, output=sys.stdout):
@@ -244,7 +264,7 @@ def decode_data(message, defines, function_code, output=sys.stdout):
function_code.extend([
"// Function should be safe up to 64 bits.",
"void IRsend::sendXYZ(const uint64_t data, const uint16_t"
"void IRsend::sendXyz(const uint64_t data, const uint16_t"
" nbits, const uint16_t repeat) {",
" enableIROut(38); // A guess. Most common frequency.",
" for (uint16_t r = 0; r <= repeat; r++) {"
@@ -256,12 +276,12 @@ def decode_data(message, defines, function_code, output=sys.stdout):
state = "HM"
if binary_value:
message.display_binary(binary_value)
function_code.extend(message.add_data_code(binary_value, False))
total_bits = total_bits + binary_value
output.write(state)
binary_value = add_bit(binary_value, "reset")
output.write("HDR_MARK+")
function_code.extend([" // Header", " mark(HDR_MARK);"])
elif (message.is_hdr_space(usec) and not message.is_one_space(usec)):
output.write("kHdrMark+")
function_code.extend([" // Header", " mark(kHdrMark);"])
elif message.is_hdr_space(usec) and not message.is_one_space(usec):
if state != "HM":
if binary_value:
message.display_binary(binary_value)
@@ -270,48 +290,53 @@ def decode_data(message, defines, function_code, output=sys.stdout):
binary_value = add_bit(binary_value, "reset")
output.write("UNEXPECTED->")
state = "HS"
output.write("HDR_SPACE+")
function_code.append(" space(HDR_SPACE);")
output.write("kHdrSpace+")
function_code.append(" space(kHdrSpace);")
elif message.is_bit_mark(usec) and count % 2:
if state != "HS" and state != "BS":
output.write("BIT_MARK(UNEXPECTED)")
output.write("kBitMark(UNEXPECTED)")
state = "BM"
elif message.is_zero_space(usec):
if state != "BM":
output.write("ZERO_SPACE(UNEXPECTED)")
output.write("kZeroSpace(UNEXPECTED)")
state = "BS"
binary_value = add_bit(binary_value, 0, output)
elif message.is_one_space(usec):
if state != "BM":
output.write("ONE_SPACE(UNEXPECTED)")
output.write("kOneSpace(UNEXPECTED)")
state = "BS"
binary_value = add_bit(binary_value, 1, output)
elif message.is_gap(usec):
if state != "BM":
output.write("UNEXPECTED->")
state = "GS"
output.write(" GAP(%d)" % usec)
message.display_binary(binary_value)
function_code.extend(message.add_data_code(binary_value))
function_code.append(" space(SPACE_GAP);")
output.write("GAP(%d)" % usec)
if binary_value:
message.display_binary(binary_value)
function_code.extend(message.add_data_code(binary_value))
else:
function_code.extend([" // Gap", " mark(kBitMark);"])
function_code.append(" space(kSpaceGap);")
total_bits = total_bits + binary_value
binary_value = add_bit(binary_value, "reset")
else:
output.write("UNKNOWN(%d)" % usec)
state = "UNK"
count = count + 1
message.display_binary(binary_value)
function_code.extend(message.add_data_code(binary_value))
if binary_value:
message.display_binary(binary_value)
function_code.extend(message.add_data_code(binary_value))
function_code.extend([
" space(100000); // A 100% made up guess of the gap"
" between messages.", " }", "}"
])
total_bits = total_bits + binary_value
output.write("Total Nr. of suspected bits: %d\n" % len(total_bits))
defines.append("#define XYZ_BITS %dU" % len(total_bits))
output.write("\nTotal Nr. of suspected bits: %d\n" % len(total_bits))
defines.append("const uint16_t kXyzBits = %d;" % len(total_bits))
if len(total_bits) > 64:
defines.append("#define XYZ_STATE_LENGTH %dU" % (len(total_bits) / 8))
defines.append("const uint16_t kXyzStateLength = %d;" %
(len(total_bits) / 8))
return total_bits
@@ -333,23 +358,24 @@ def generate_irsend_code(defines, normal, bits_str, output=sys.stdout):
if len(bits_str) > 64: # Will it fit in a uint64_t?
output.write("\n\n// Alternative >64 bit Function\n"
"void IRsend::sendXYZ(uint8_t data[], uint16_t nbytes,"
"void IRsend::sendXyz(uint8_t data[], uint16_t nbytes,"
" uint16_t repeat) {\n"
" // nbytes should typically be XYZ_STATE_LENGTH\n"
" // nbytes should typically be kXyzStateLength\n"
" // data should typically be:\n"
" // uint8_t data[XYZ_STATE_LENGTH] = {0x%s};\n"
" // uint8_t data[kXyzStateLength] = {0x%s};\n"
" // data[] is assumed to be in MSB order for this code.\n"
" for (uint16_t r = 0; r <= repeat; r++) {\n"
" sendGeneric(HDR_MARK, HDR_SPACE,\n"
" BIT_MARK, ONE_SPACE,\n"
" BIT_MARK, ZERO_SPACE,\n"
" BIT_MARK\n"
" sendGeneric(kHdrMark, kHdrSpace,\n"
" kBitMark, kOneSpace,\n"
" kBitMark, kZeroSpace,\n"
" kBitMark,\n"
" 100000, // 100%% made-up guess at the"
" message gap.\n"
" data, nbytes,\n"
" 38000, // Complete guess of the modulation"
" frequency.\n"
" true, 0, 50);\n"
" }\n"
"}\n" % ", 0x".join("%02X" % int(bits_str[i:i + 8], 2)
for i in range(0, len(bits_str), 8)))
@@ -8,6 +8,8 @@ import auto_analyse_raw_data as analyse
class TestRawIRMessage(unittest.TestCase):
"""Unit tests for the RawIRMessage class."""
# pylint: disable=too-many-public-methods
def test_display_binary(self):
"""Test the display_binary() method."""
output = StringIO.StringIO()
@@ -46,6 +48,8 @@ class TestRawIRMessage(unittest.TestCase):
class TestAutoAnalyseRawData(unittest.TestCase):
"""Unit tests for the functions in AutoAnalyseRawData."""
# pylint: disable=too-many-public-methods
def test_dump_constants_simple(self):
"""Simple tests for the dump_constants() function."""
ignore = StringIO.StringIO()
@@ -58,16 +62,16 @@ class TestAutoAnalyseRawData(unittest.TestCase):
], ignore)
analyse.dump_constants(message, defs, output)
self.assertEqual(defs, [
'#define HDR_MARK 7930U', '#define BIT_MARK 520U',
'#define HDR_SPACE 3978U', '#define ONE_SPACE 1508U',
'#define ZERO_SPACE 520U'
'const uint16_t kHdrMark = 7930;', 'const uint16_t kBitMark = 496;',
'const uint16_t kHdrSpace = 3965;', 'const uint16_t kOneSpace = 1485;',
'const uint16_t kZeroSpace = 520;'
])
self.assertEqual(output.getvalue(), 'Guessing key value:\n'
'HDR_MARK = 7930\n'
'HDR_SPACE = 3978\n'
'BIT_MARK = 520\n'
'ONE_SPACE = 1508\n'
'ZERO_SPACE = 520\n')
'kHdrMark = 7930\n'
'kHdrSpace = 3965\n'
'kBitMark = 496\n'
'kOneSpace = 1485\n'
'kZeroSpace = 520\n')
def test_dump_constants_aircon(self):
"""More complex tests for the dump_constants() function."""
@@ -89,17 +93,17 @@ class TestAutoAnalyseRawData(unittest.TestCase):
], ignore)
analyse.dump_constants(message, defs, output)
self.assertEqual(defs, [
'#define HDR_MARK 9008U', '#define BIT_MARK 676U',
'#define HDR_SPACE 4496U', '#define ONE_SPACE 1680U',
'#define ZERO_SPACE 584U', '#define SPACE_GAP = 19990U'
'const uint16_t kHdrMark = 9008;', 'const uint16_t kBitMark = 650;',
'const uint16_t kHdrSpace = 4496;', 'const uint16_t kOneSpace = 1657;',
'const uint16_t kZeroSpace = 554;', 'const uint16_t kSpaceGap = 19990;'
])
self.assertEqual(output.getvalue(), 'Guessing key value:\n'
'HDR_MARK = 9008\n'
'HDR_SPACE = 4496\n'
'BIT_MARK = 676\n'
'ONE_SPACE = 1680\n'
'ZERO_SPACE = 584\n'
'SPACE_GAP = 19990\n')
'kHdrMark = 9008\n'
'kHdrSpace = 4496\n'
'kBitMark = 650\n'
'kOneSpace = 1657\n'
'kZeroSpace = 554\n'
'kSpaceGap = 19990\n')
def test_convert_rawdata(self):
"""Tests for the convert_rawdata() function."""
@@ -177,16 +181,16 @@ class TestAutoAnalyseRawData(unittest.TestCase):
'Looks like it uses space encoding. Yay!\n'
'\n'
'Guessing key value:\n'
'HDR_MARK = 9008\n'
'HDR_SPACE = 4496\n'
'BIT_MARK = 676\n'
'ONE_SPACE = 1680\n'
'ZERO_SPACE = 584\n'
'SPACE_GAP = 19990\n'
'kHdrMark = 9008\n'
'kHdrSpace = 4496\n'
'kBitMark = 650\n'
'kOneSpace = 1657\n'
'kZeroSpace = 554\n'
'kSpaceGap = 19990\n'
'\n'
'Decoding protocol based on analysis so far:\n'
'\n'
'HDR_MARK+HDR_SPACE+10011000010100000000011000001010010 GAP(19990)\n'
'kHdrMark+kHdrSpace+10011000010100000000011000001010010GAP(19990)\n'
' Bits: 35\n'
' Hex: 0x4C2803052 (MSB first)\n'
' 0x250600A19 (LSB first)\n'
@@ -194,7 +198,7 @@ class TestAutoAnalyseRawData(unittest.TestCase):
' 9938405913 (LSB first)\n'
' Bin: 0b10011000010100000000011000001010010 (MSB first)\n'
' 0b01001010000011000000000101000011001 (LSB first)\n'
'BIT_MARK(UNEXPECTED)01000000110001000000000000001111\n'
'kBitMark(UNEXPECTED)01000000110001000000000000001111\n'
' Bits: 32\n'
' Hex: 0x40C4000F (MSB first)\n'
' 0xF0002302 (LSB first)\n'
@@ -202,6 +206,7 @@ class TestAutoAnalyseRawData(unittest.TestCase):
' 4026540802 (LSB first)\n'
' Bin: 0b01000000110001000000000000001111 (MSB first)\n'
' 0b11110000000000000010001100000010 (LSB first)\n'
'\n'
'Total Nr. of suspected bits: 67\n')
# With code generation.
@@ -223,15 +228,15 @@ class TestAutoAnalyseRawData(unittest.TestCase):
'Looks like it uses space encoding. Yay!\n'
'\n'
'Guessing key value:\n'
'HDR_MARK = 7930\n'
'HDR_SPACE = 3978\n'
'BIT_MARK = 520\n'
'ONE_SPACE = 1508\n'
'ZERO_SPACE = 520\n'
'kHdrMark = 7930\n'
'kHdrSpace = 3965\n'
'kBitMark = 496\n'
'kOneSpace = 1485\n'
'kZeroSpace = 520\n'
'\n'
'Decoding protocol based on analysis so far:\n'
'\n'
'HDR_MARK+HDR_SPACE+11101011\n'
'kHdrMark+kHdrSpace+11101011\n'
' Bits: 8\n'
' Hex: 0xEB (MSB first)\n'
' 0xD7 (LSB first)\n'
@@ -239,50 +244,249 @@ class TestAutoAnalyseRawData(unittest.TestCase):
' 215 (LSB first)\n'
' Bin: 0b11101011 (MSB first)\n'
' 0b11010111 (LSB first)\n'
'UNEXPECTED->HDR_SPACE+00000001\n'
' Bits: 8\n Hex: 0x01 (MSB first)\n'
'UNEXPECTED->kHdrSpace+00000001\n'
' Bits: 8\n'
' Hex: 0x01 (MSB first)\n'
' 0x80 (LSB first)\n'
' Dec: 1 (MSB first)\n'
' 128 (LSB first)\n'
' Bin: 0b00000001 (MSB first)\n'
' 0b10000000 (LSB first)\n'
'\n'
'Total Nr. of suspected bits: 16\n'
'\n'
'Generating a VERY rough code outline:\n'
'\n'
"// WARNING: This probably isn't directly usable. It's a guide only.\n"
'#define HDR_MARK 7930U\n'
'#define BIT_MARK 520U\n'
'#define HDR_SPACE 3978U\n'
'#define ONE_SPACE 1508U\n'
'#define ZERO_SPACE 520U\n'
'#define XYZ_BITS 16U\n'
'const uint16_t kHdrMark = 7930;\n'
'const uint16_t kBitMark = 496;\n'
'const uint16_t kHdrSpace = 3965;\n'
'const uint16_t kOneSpace = 1485;\n'
'const uint16_t kZeroSpace = 520;\n'
'const uint16_t kXyzBits = 16;\n'
'// Function should be safe up to 64 bits.\n'
'void IRsend::sendXYZ(const uint64_t data, const uint16_t nbits,'
'void IRsend::sendXyz(const uint64_t data, const uint16_t nbits,'
' const uint16_t repeat) {\n'
' enableIROut(38); // A guess. Most common frequency.\n'
' for (uint16_t r = 0; r <= repeat; r++) {\n'
' // Header\n'
' mark(HDR_MARK);\n'
' space(HDR_SPACE);\n'
' mark(kHdrMark);\n'
' space(kHdrSpace);\n'
' // Data\n'
' // e.g. data = 0xEB, nbits = 8\n'
' sendData(BIT_MARK, ONE_SPACE, BIT_MARK, ZERO_SPACE, data, nbits,'
' sendData(kBitMark, kOneSpace, kBitMark, kZeroSpace, data, nbits,'
' true);\n'
' // Footer\n'
' mark(BIT_MARK);\n'
' space(HDR_SPACE);\n'
' mark(kBitMark);\n'
' space(kHdrSpace);\n'
' // Data\n'
' // e.g. data = 0x1, nbits = 8\n'
' sendData(BIT_MARK, ONE_SPACE, BIT_MARK, ZERO_SPACE, data, nbits,'
' sendData(kBitMark, kOneSpace, kBitMark, kZeroSpace, data, nbits,'
' true);\n'
' // Footer\n'
' mark(BIT_MARK);\n'
' mark(kBitMark);\n'
' space(100000); // A 100% made up guess of the gap between'
' messages.\n'
' }\n'
'}\n')
def test_unusual_gaps(self):
"""Tests for unusual Space Gaps in parse_and_report() function."""
# Tests for unusual Gaps. (Issue #482)
output = StringIO.StringIO()
input_str = """
uint16_t rawbuf[272] = {3485, 3512, 864, 864, 864, 2620, 864, 864,
864, 2620, 864, 2620, 864, 2620, 864, 2620, 864, 2620, 864, 864,
864, 2620, 864, 864, 864, 2620, 864, 2620, 864, 2620, 864, 2620,
864, 2620, 864, 864, 864, 2620, 864, 864, 864, 864, 864, 864,
864, 864, 864, 864, 864, 864, 864, 864, 864, 2620, 864, 864,
864, 864, 864, 864, 864, 864, 864, 864, 864, 864,
3485, 3512, 864, 864, 864, 2620, 864, 864, 864, 2620, 864, 2620,
864, 2620, 864, 2620, 864, 2620, 864, 864, 864, 2620, 864, 864,
864, 2620, 864, 2620, 864, 2620, 864, 2620, 864, 2620, 864, 864,
864, 2620, 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, 864,
864, 864, 864, 864, 2620, 864, 864, 864, 864, 864, 864, 864, 864,
864, 864, 864, 864,
3485, 3512, 864, 13996,
3485, 3512, 864, 864, 864, 864, 864, 2620, 864, 864, 864, 2620,
864, 2620, 864, 2620, 864, 2620, 864, 864, 864, 864, 864, 2620,
864, 864, 864, 2620, 864, 2620, 864, 2620, 864, 2620, 864, 864,
864, 2620, 864, 2620, 864, 864, 864, 2620, 864, 2620, 864, 864,
864, 864, 864, 864, 864, 2620, 864, 2620, 864, 864, 864, 2620,
864, 2620, 864, 864, 864, 864,
3485, 3512, 864, 864, 864, 864, 864, 2620, 864, 864, 864, 2620,
864, 2620, 864, 2620, 864, 2620, 864, 864, 864, 864, 864, 2620,
864, 864, 864, 2620, 864, 2620, 864, 2620, 864, 2620, 864, 864,
864, 2620, 864, 2620, 864, 864, 864, 2620, 864, 2620, 864, 864,
864, 864, 864, 864, 864, 2620, 864, 2620, 864, 864, 864, 2620,
864, 2620, 864, 864, 864, 864, 3485, 3512, 864, 13996};"""
analyse.parse_and_report(input_str, 200, True, output)
self.assertEqual(
output.getvalue(), 'Found 272 timing entries.\n'
'Potential Mark Candidates:\n'
'[3485, 864]\n'
'Potential Space Candidates:\n'
'[13996, 3512, 2620, 864]\n'
'\n'
'Guessing encoding type:\n'
'Looks like it uses space encoding. Yay!\n'
'\n'
'Guessing key value:\n'
'kHdrMark = 3485\n'
'kHdrSpace = 3512\n'
'kBitMark = 864\n'
'kOneSpace = 2620\n'
'kZeroSpace = 864\n'
'kSpaceGap = 13996\n'
'\n'
'Decoding protocol based on analysis so far:\n'
'\n'
'kHdrMark+kHdrSpace+01011111010111110100000001000000\n'
' Bits: 32\n'
' Hex: 0x5F5F4040 (MSB first)\n'
' 0x0202FAFA (LSB first)\n'
' Dec: 1600077888 (MSB first)\n'
' 33749754 (LSB first)\n'
' Bin: 0b01011111010111110100000001000000 (MSB first)\n'
' 0b00000010000000101111101011111010 (LSB first)\n'
'kHdrMark+kHdrSpace+01011111010111110100000001000000\n'
' Bits: 32\n'
' Hex: 0x5F5F4040 (MSB first)\n'
' 0x0202FAFA (LSB first)\n'
' Dec: 1600077888 (MSB first)\n'
' 33749754 (LSB first)\n'
' Bin: 0b01011111010111110100000001000000 (MSB first)\n'
' 0b00000010000000101111101011111010 (LSB first)\n'
'kHdrMark+kHdrSpace+GAP(13996)'
'kHdrMark+kHdrSpace+00101111001011110110110001101100\n'
' Bits: 32\n'
' Hex: 0x2F2F6C6C (MSB first)\n'
' 0x3636F4F4 (LSB first)\n'
' Dec: 791637100 (MSB first)\n'
' 909571316 (LSB first)\n'
' Bin: 0b00101111001011110110110001101100 (MSB first)\n'
' 0b00110110001101101111010011110100 (LSB first)\n'
'kHdrMark+kHdrSpace+00101111001011110110110001101100\n'
' Bits: 32\n'
' Hex: 0x2F2F6C6C (MSB first)\n'
' 0x3636F4F4 (LSB first)\n'
' Dec: 791637100 (MSB first)\n'
' 909571316 (LSB first)\n'
' Bin: 0b00101111001011110110110001101100 (MSB first)\n'
' 0b00110110001101101111010011110100 (LSB first)\n'
'kHdrMark+kHdrSpace+GAP(13996)\n'
'Total Nr. of suspected bits: 128\n'
'\n'
'Generating a VERY rough code outline:\n'
'\n'
"// WARNING: This probably isn't directly usable. It's a guide only.\n"
'const uint16_t kHdrMark = 3485;\n'
'const uint16_t kBitMark = 864;\n'
'const uint16_t kHdrSpace = 3512;\n'
'const uint16_t kOneSpace = 2620;\n'
'const uint16_t kZeroSpace = 864;\n'
'const uint16_t kSpaceGap = 13996;\n'
'const uint16_t kXyzBits = 128;\n'
'const uint16_t kXyzStateLength = 16;\n'
"// DANGER: More than 64 bits detected. A uint64_t for 'data' won't"
' work!\n'
'// Function should be safe up to 64 bits.\n'
'void IRsend::sendXyz(const uint64_t data, const uint16_t nbits,'
' const uint16_t repeat) {\n'
' enableIROut(38); // A guess. Most common frequency.\n'
' for (uint16_t r = 0; r <= repeat; r++) {\n'
' // Header\n'
' mark(kHdrMark);\n'
' space(kHdrSpace);\n'
' // Data\n'
' // e.g. data = 0x5F5F4040, nbits = 32\n'
' sendData(kBitMark, kOneSpace, kBitMark, kZeroSpace, data, nbits,'
' true);\n'
' // Header\n'
' mark(kHdrMark);\n'
' space(kHdrSpace);\n'
' // Data\n'
' // e.g. data = 0x5F5F4040, nbits = 32\n'
' sendData(kBitMark, kOneSpace, kBitMark, kZeroSpace, data, nbits,'
' true);\n'
' // Header\n'
' mark(kHdrMark);\n'
' space(kHdrSpace);\n'
' // Gap\n'
' mark(kBitMark);\n'
' space(kSpaceGap);\n'
' // Header\n'
' mark(kHdrMark);\n'
' space(kHdrSpace);\n'
' // Data\n'
' // e.g. data = 0x2F2F6C6C, nbits = 32\n'
' sendData(kBitMark, kOneSpace, kBitMark, kZeroSpace, data, nbits,'
' true);\n'
' // Header\n'
' mark(kHdrMark);\n'
' space(kHdrSpace);\n'
' // Data\n'
' // e.g. data = 0x2F2F6C6C, nbits = 32\n'
' sendData(kBitMark, kOneSpace, kBitMark, kZeroSpace, data, nbits,'
' true);\n'
' // Header\n'
' mark(kHdrMark);\n'
' space(kHdrSpace);\n'
' // Gap\n'
' mark(kBitMark);\n'
' space(kSpaceGap);\n'
' space(100000); // A 100% made up guess of the gap between'
' messages.\n'
' }\n'
'}\n'
'\n'
'\n'
'// Alternative >64 bit Function\n'
'void IRsend::sendXyz(uint8_t data[], uint16_t nbytes, uint16_t repeat)'
' {\n'
' // nbytes should typically be kXyzStateLength\n'
' // data should typically be:\n'
' // uint8_t data[kXyzStateLength] = {0x5F, 0x5F, 0x40, 0x40, 0x5F,'
' 0x5F, 0x40, 0x40, 0x2F, 0x2F, 0x6C, 0x6C, 0x2F, 0x2F, 0x6C, 0x6C};\n'
' // data[] is assumed to be in MSB order for this code.\n'
' for (uint16_t r = 0; r <= repeat; r++) {\n'
' sendGeneric(kHdrMark, kHdrSpace,\n'
' kBitMark, kOneSpace,\n'
' kBitMark, kZeroSpace,\n'
' kBitMark,\n'
' 100000, // 100% made-up guess at the message gap.\n'
' data, nbytes,\n'
' 38000, // Complete guess of the modulation'
' frequency.\n'
' true, 0, 50);\n'
' }\n'
'}\n')
def test_reduce_list(self):
"""Tests for the reduce_list method."""
ignore = StringIO.StringIO()
message = analyse.RawIRMessage(200, [
7930, 3952, 494, 1482, 520, 1482, 494, 1508, 494, 520, 494, 1482, 494,
520, 494, 1482, 494, 1482, 494, 3978, 494, 520, 494, 520, 494, 520, 494,
520, 520, 520, 494, 520, 494, 520, 494, 1482, 494
], ignore)
test_space_data = [4496, 1660, 530, 558, 1636, 1660, 556]
result_list, result_dict = message.reduce_list(test_space_data)
self.assertEqual([4496, 1660, 558], result_list)
self.assertEqual({
558: [558, 556, 530],
1660: [1660, 1660, 1636],
4496: [4496]
}, result_dict)
def test_avg_list(self):
"""Tests for the avg_list method."""
self.assertEqual(0, analyse.avg_list([]))
self.assertEqual(23, analyse.avg_list([10, 20, 40]))
if __name__ == '__main__':
unittest.main(verbosity=2)
+24 -23
View File
@@ -11,24 +11,25 @@
#include "IRsend_test.h"
#include "IRutils.h"
#define MAX_GC_CODE_LENGTH 10000
const uint16_t kMaxGcCodeLength = 10000;
void str_to_uint16(char *str, uint16_t *res, uint8_t base) {
char *end;
errno = 0;
intmax_t val = strtoimax(str, &end, base);
if (errno == ERANGE || val < 0 || val > UINT16_MAX ||
end == str || *end != '\0')
if (errno == ERANGE || val < 0 || val > UINT16_MAX || end == str ||
*end != '\0')
return;
*res = (uint16_t) val;
*res = (uint16_t)val;
}
void usage_error(char * name) {
void usage_error(char *name) {
std::cerr << "Usage: " << name << " [-raw] <global_code>" << std::endl
<< "Usage: " << name << " -prontohex [-raw] <prontohex_code>" << std::endl;
<< "Usage: " << name << " -prontohex [-raw] <prontohex_code>"
<< std::endl;
}
int main(int argc, char * argv[]) {
int main(int argc, char *argv[]) {
int argv_offset = 1;
bool dumpraw = false;
bool prontohex = false;
@@ -52,7 +53,7 @@ int main(int argc, char * argv[]) {
return 1;
}
uint16_t gc_test[MAX_GC_CODE_LENGTH];
uint16_t gc_test[kMaxGcCodeLength];
int index = 0;
char *pch;
char *saveptr1;
@@ -60,12 +61,12 @@ int main(int argc, char * argv[]) {
int codebase = 10;
if (prontohex) {
sep = const_cast<char *>(" ");
codebase = 16;
sep = const_cast<char *>(" ");
codebase = 16;
}
pch = strtok_r(argv[argv_offset], sep, &saveptr1);
while (pch != NULL && index < MAX_GC_CODE_LENGTH) {
while (pch != NULL && index < kMaxGcCodeLength) {
str_to_uint16(pch, &gc_test[index], codebase);
pch = strtok_r(NULL, sep, &saveptr1);
index++;
@@ -77,32 +78,32 @@ int main(int argc, char * argv[]) {
irsend.reset();
if (prontohex) {
irsend.sendPronto(gc_test, index);
irsend.sendPronto(gc_test, index);
} else {
irsend.sendGC(gc_test, index);
irsend.sendGC(gc_test, index);
}
irsend.makeDecodeResult();
irrecv.decode(&irsend.capture);
std::cout << "Code length " << index << std::endl
<< "Code type " << irsend.capture.decode_type
<< " (" << typeToString(irsend.capture.decode_type) << ")" << std::endl
<< "Code bits " << irsend.capture.bits << std::endl;
<< "Code type " << irsend.capture.decode_type << " ("
<< typeToString(irsend.capture.decode_type) << ")" << std::endl
<< "Code bits " << irsend.capture.bits << std::endl;
if (hasACState(irsend.capture.decode_type)) {
std::cout << "State value 0x";
for (uint16_t i = 0; i < irsend.capture.bits / 8; i++)
printf("%02X", irsend.capture.state[i]);
std::cout << std::endl;
} else {
std::cout << "Code value 0x" <<
std::hex << irsend.capture.value << std::endl <<
"Code address 0x" << std::hex << irsend.capture.address << std::endl
<< "Code command 0x" << std::hex << irsend.capture.command <<
std::endl;
std::cout << "Code value 0x" << std::hex << irsend.capture.value
<< std::endl
<< "Code address 0x" << std::hex << irsend.capture.address
<< std::endl
<< "Code command 0x" << std::hex << irsend.capture.command
<< std::endl;
}
if (dumpraw || irsend.capture.decode_type == UNKNOWN)
irsend.dumpRawResult();
if (dumpraw || irsend.capture.decode_type == UNKNOWN) irsend.dumpRawResult();
return 0;
}
+3 -1
View File
@@ -64,6 +64,8 @@ LITERALS=$(grep "^#define [A-Z]" src/*.cpp src/*.h |
echo ${define};
done | sort -u |
grep -v [\(\)] | grep -v ^_ | grep -v _\$ | grep -v VIRTUAL)
CONSTS=$(grep "^const " src/*.cpp src/*.h |
sed 's/\[.*\] =.*//;s/ =.*//;s/^.* k/k/')
ENUMS=$(cat src/*.h | while read a b; do
if [[ ${a} == "};" ]]; then
ENUM=0;
@@ -75,6 +77,6 @@ ENUMS=$(cat src/*.h | while read a b; do
ENUM=1;
fi;
done)
for i in ${LITERALS} ${ENUMS}; do
for i in ${LITERALS} ${CONSTS} ${ENUMS}; do
echo -e "${i}\tLITERAL1"
done | sort -u
+122
View File
@@ -0,0 +1,122 @@
// Quick and dirty tool to decode mode2 data from LIRC
// Copyright 2018 Brett T. Warden
// based on c2_decode.cpp, Copyright 2017 Jorge Cisneros
// Usage example:
// mode2 -H udp -d 5000 | ./mode2_decode
/* Sample input (alternating space and pulse durations in microseconds):
space 500000
pulse 915
space 793
pulse 488
space 366
pulse 915
space 793
pulse 427
space 500000
*/
#include <errno.h>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <sstream>
#include <string>
#include "IRsend.h"
#include "IRsend_test.h"
#include "IRutils.h"
const uint16_t kMaxGcCodeLength = 10000;
void str_to_uint16(char *str, uint16_t *res, uint8_t base) {
char *end;
errno = 0;
intmax_t val = strtoimax(str, &end, base);
if (errno == ERANGE || val < 0 || val > UINT16_MAX || end == str ||
*end != '\0')
return;
*res = (uint16_t)val;
}
void usage_error(char *name) {
std::cerr << "Usage: " << name << " [-raw]" << std::endl;
}
int main(int argc, char *argv[]) {
bool dumpraw = false;
// Check the invocation/calling usage.
if (argc > 2) {
usage_error(argv[0]);
return 1;
}
if (argc == 2 && strncmp("-raw", argv[1], 4) == 0) {
dumpraw = true;
}
int index = 0;
std::string line, type;
std::string pulse = "pulse";
std::string space = "space";
int duration;
IRsendTest irsend(4);
IRrecv irrecv(4);
irsend.begin();
irsend.reset();
while (getline(std::cin, line)) {
std::istringstream iss1(line);
iss1 >> type;
iss1 >> duration;
// Clamp duration to int16_t
if (duration > 0xFFFF) {
duration = 0xFFFF;
}
if (pulse.compare(type) == 0) {
irsend.mark(duration);
} else if (space.compare(type) == 0) {
irsend.space(duration);
}
index++;
if (duration > 20000 || index >= kMaxGcCodeLength) {
// Skip long spaces at beginning
if (index > 1) {
irsend.makeDecodeResult();
irrecv.decode(&irsend.capture);
std::cout << "Code length " << index << std::endl
<< "Code type " << irsend.capture.decode_type << " ("
<< typeToString(irsend.capture.decode_type) << ")"
<< std::endl
<< "Code bits " << irsend.capture.bits << std::endl;
if (hasACState(irsend.capture.decode_type)) {
std::cout << "State value 0x";
for (uint16_t i = 0; i < irsend.capture.bits / 8; i++)
printf("%02X", irsend.capture.state[i]);
std::cout << std::endl;
} else {
std::cout << "Code value 0x" << std::hex << irsend.capture.value
<< std::endl
<< "Code address 0x" << std::hex << irsend.capture.address
<< std::endl
<< "Code command 0x" << std::hex << irsend.capture.command
<< std::endl;
}
if (dumpraw || irsend.capture.decode_type == UNKNOWN)
irsend.dumpRawResult();
}
irsend.reset();
index = 0;
}
}
return 0;
}