Skip to content

Commit

Permalink
Handle the end of a capture better, plus more debug code. (#249)
Browse files Browse the repository at this point in the history
- [bug] Issue #243 uncovered an odd case where a zero length end gap is encountered.
- Add unit test to cover zero length space at the end.
- Add more debugging code for matchAtLeast()
- [bug] fix incorrect end of buffer calculation in decodes
  • Loading branch information
crankyoldgit authored Jun 15, 2017
1 parent 2e58f22 commit f9780d6
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 11 deletions.
16 changes: 16 additions & 0 deletions src/IRrecv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,22 @@ bool IRrecv::match(uint32_t measured_ticks, uint32_t desired_us,
// Boolean: true if it matches, false if it doesn't.
bool IRrecv::matchAtLeast(uint32_t measured_ticks, uint32_t desired_us,
uint8_t tolerance) {
DPRINT("Matching ATLEAST ");
DPRINT(measured_ticks * USECPERTICK);
DPRINT(" vs ");
DPRINT(desired_us);
DPRINT(". Matching: ");
DPRINT(measured_ticks);
DPRINT(" >= ");
DPRINT(ticksLow(std::min(desired_us, TIMEOUT_MS * 1000), tolerance));
DPRINT(" [min(");
DPRINT(ticksLow(desired_us, tolerance));
DPRINT(", ");
DPRINT(ticksLow(TIMEOUT_MS * 1000, tolerance));
DPRINTLN(")]");
// We really should never get a value of 0, except as the last value
// in the buffer. If that is the case, then assume infinity and return true.
if (measured_ticks == 0) return true;
return measured_ticks >= ticksLow(std::min(desired_us, TIMEOUT_MS * 1000),
tolerance);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ir_Coolix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ bool IRrecv::decodeCOOLIX(decode_results *results, uint16_t nbits,
// Footer
if (!matchMark(results->rawbuf[offset++], COOLIX_BIT_MARK))
return false;
if (offset <= results->rawlen &&
if (offset < results->rawlen &&
!matchAtLeast(results->rawbuf[offset], COOLIX_MIN_GAP))
return false;

Expand Down
2 changes: 1 addition & 1 deletion src/ir_JVC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ bool IRrecv::decodeJVC(decode_results *results, uint16_t nbits, bool strict) {
// Footer
if (!matchMark(results->rawbuf[offset++], JVC_BIT_MARK))
return false;
if (offset <= results->rawlen &&
if (offset < results->rawlen &&
!matchAtLeast(results->rawbuf[offset], JVC_MIN_GAP))
return false;

Expand Down
5 changes: 3 additions & 2 deletions src/ir_LG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ bool IRrecv::decodeLG(decode_results *results, uint16_t nbits, bool strict) {
// Footer
if (!matchMark(results->rawbuf[offset++], LG_BIT_MARK))
return false;
if (offset <= results->rawlen &&
if (offset < results->rawlen &&
!matchAtLeast(results->rawbuf[offset], LG_MIN_GAP))
return false;

Expand All @@ -191,7 +191,8 @@ bool IRrecv::decodeLG(decode_results *results, uint16_t nbits, bool strict) {
return false;
if (!matchMark(results->rawbuf[offset++], LG_BIT_MARK))
return false;
if (!matchAtLeast(results->rawbuf[offset], LG_MIN_GAP))
if (offset < results->rawlen &&
!matchAtLeast(results->rawbuf[offset], LG_MIN_GAP))
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ir_Mitsubishi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ bool IRrecv::decodeMitsubishi(decode_results *results, uint16_t nbits,
// Footer
if (!matchMark(results->rawbuf[offset++], MITSUBISHI_BIT_MARK, 30))
return false;
if (offset <= results->rawlen &&
if (offset < results->rawlen &&
!matchAtLeast(results->rawbuf[offset], MITSUBISHI_MIN_GAP))
return false;

Expand Down
2 changes: 1 addition & 1 deletion src/ir_Panasonic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ bool IRrecv::decodePanasonic(decode_results *results, uint16_t nbits,
// Footer
if (!match(results->rawbuf[offset++], PANASONIC_BIT_MARK))
return false;
if (offset <= results->rawlen &&
if (offset < results->rawlen &&
!matchAtLeast(results->rawbuf[offset], PANASONIC_END_GAP))
return false;

Expand Down
2 changes: 1 addition & 1 deletion src/ir_RCMM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ bool IRrecv::decodeRCMM(decode_results *results, uint16_t nbits, bool strict) {
// Footer decode
if (!matchMark(results->rawbuf[offset++], RCMM_BIT_MARK))
return false;
if (offset <= results->rawlen &&
if (offset < results->rawlen &&
!matchAtLeast(results->rawbuf[offset], RCMM_MIN_GAP))
return false;

Expand Down
2 changes: 1 addition & 1 deletion src/ir_Samsung.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ bool IRrecv::decodeSAMSUNG(decode_results *results, uint16_t nbits,
// Footer
if (!matchMark(results->rawbuf[offset++], SAMSUNG_BIT_MARK))
return false;
if (offset <= results->rawlen &&
if (offset < results->rawlen &&
!matchAtLeast(results->rawbuf[offset], SAMSUNG_MIN_GAP))
return false;

Expand Down
5 changes: 3 additions & 2 deletions src/ir_Sharp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ bool IRrecv::decodeSharp(decode_results *results, uint16_t nbits, bool strict,
// Footer
if (!match(results->rawbuf[offset++], SHARP_BIT_MARK))
return false;
if (offset <= results->rawlen &&
if (offset < results->rawlen &&
!matchAtLeast(results->rawbuf[offset], SHARP_GAP))
return false;

Expand Down Expand Up @@ -245,7 +245,8 @@ bool IRrecv::decodeSharp(decode_results *results, uint16_t nbits, bool strict,
// Footer
if (!match(results->rawbuf[offset++], SHARP_BIT_MARK))
return false;
if (!matchAtLeast(results->rawbuf[offset], SHARP_GAP))
if (offset < results->rawlen &&
!matchAtLeast(results->rawbuf[offset], SHARP_GAP))
return false;

// Check that second_data has been inverted correctly.
Expand Down
2 changes: 1 addition & 1 deletion src/ir_Whynter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ bool IRrecv::decodeWhynter(decode_results *results, uint16_t nbits,
// Footer
if (!matchMark(results->rawbuf[offset++], WHYNTER_BIT_MARK))
return false;
if (offset <= results->rawlen &&
if (offset < results->rawlen &&
!matchAtLeast(results->rawbuf[offset], WHYNTER_MIN_GAP))
return false;

Expand Down
9 changes: 9 additions & 0 deletions test/ir_NEC_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,13 @@ TEST(TestDecodeNEC, NoTrailingGap_Issue243) {
EXPECT_EQ(NEC, irsend.capture.decode_type);
EXPECT_EQ(NEC_BITS, irsend.capture.bits);
EXPECT_EQ(0x4BB640BF, irsend.capture.value);

// Add a zero length space to the message to test how it handles that as
// a end of command gap.
irsend.addGap(0);
irsend.makeDecodeResult();
ASSERT_TRUE(irrecv.decode(&irsend.capture));
EXPECT_EQ(NEC, irsend.capture.decode_type);
EXPECT_EQ(NEC_BITS, irsend.capture.bits);
EXPECT_EQ(0x4BB640BF, irsend.capture.value);
}

0 comments on commit f9780d6

Please sign in to comment.