Skip to content

Commit

Permalink
Increase tolerance to improve matching.
Browse files Browse the repository at this point in the history
* Increase tolerance for this protocol by 5%.
* Add unit test based on previously not-recognised capture.
* Fix typos in unit tests.
* Update decode status to STABLE.

For #1943
  • Loading branch information
crankyoldgit committed Jan 18, 2023
1 parent 21f4c13 commit df2112f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/ir_Carrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const uint16_t kCarrierAc84One = 430;
const uint16_t kCarrierAc84HdrSpace = kCarrierAc84Zero;
const uint32_t kCarrierAc84Gap = kDefaultMessageGap; // A guess.
const uint8_t kCarrierAc84ExtraBits = 4;
const uint8_t kCarrierAc84ExtraTolerance = 5;

const uint16_t kCarrierAc128HdrMark = 4600;
const uint16_t kCarrierAc128HdrSpace = 2600;
Expand Down Expand Up @@ -686,7 +687,7 @@ void IRsend::sendCarrierAC84(const uint8_t data[], const uint16_t nbytes,

#if DECODE_CARRIER_AC84
/// Decode the supplied Carroer A/C 84 Bit formatted message.
/// Status: BETA / Untested but probably works.
/// Status: STABLE / Confirmed Working.
/// @param[in,out] results Ptr to the data to decode & where to store the decode
/// result.
/// @param[in] offset The starting index to use when attempting to decode the
Expand Down Expand Up @@ -718,7 +719,10 @@ bool IRrecv::decodeCarrierAC84(decode_results *results, uint16_t offset,
// Data
kCarrierAc84Zero, kCarrierAc84One,
// No Footer
0, 0, false, kUseDefTol, kMarkExcess, false);
0, 0,
false,
_tolerance + kCarrierAc84ExtraTolerance,
kMarkExcess, false);
if (!used) return false;
// Stuff the captured data so far into the first byte of the state.
*results->state = data;
Expand All @@ -731,7 +735,8 @@ bool IRrecv::decodeCarrierAC84(decode_results *results, uint16_t offset,
kCarrierAc84Zero, kCarrierAc84One, // Data
kCarrierAc84One, kCarrierAc84Zero,
kCarrierAc84Zero, kDefaultMessageGap, true,
kUseDefTol, kMarkExcess, false)) return false;
_tolerance + kCarrierAc84ExtraTolerance,
kMarkExcess, false)) return false;

// Success
results->decode_type = decode_type_t::CARRIER_AC84;
Expand Down
46 changes: 44 additions & 2 deletions test/ir_Carrier_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ TEST(TestDecodeCarrierAC128, SyntheticExample) {
ASSERT_FALSE(IRAcUtils::decodeToState(&irsend.capture, &r, &p));
}

// Decode a "real" Carrier 80bit example message.
// Decode a "real" Carrier 84bit example message.
TEST(TestDecodeCarrierAC84, RealExample) {
IRsendTest irsend(kGpioUnused);
IRrecv irrecv(kGpioUnused);
Expand Down Expand Up @@ -749,7 +749,7 @@ TEST(TestDecodeCarrierAC84, RealExample) {
resultToHumanReadableBasic(&irsend.capture));
}

// Decode a synthetic Carrier AC 80-bit message.
// Decode a synthetic Carrier AC 84-bit message.
TEST(TestDecodeCarrierAC84, SyntheticExample) {
IRsendTest irsend(kGpioUnused);
IRrecv irrecv(kGpioUnused);
Expand All @@ -771,3 +771,45 @@ TEST(TestDecodeCarrierAC84, SyntheticExample) {
stdAc::state_t r, p;
ASSERT_FALSE(IRAcUtils::decodeToState(&irsend.capture, &r, &p));
}

// Decode a "real" troublesome Carrier 84bit example message.
TEST(TestDecodeCarrierAC84, RealExample2) {
IRsendTest irsend(kGpioUnused);
IRrecv irrecv(kGpioUnused);
const uint8_t expected_state[kCarrierAc84StateLength] = {
0x03, 0x00, 0x03, 0x32, 0x00, 0x12, 0x00, 0x12, 0x33, 0x11, 0xDC};
irsend.begin();

irsend.reset();
// Data from:
// https://github.com/crankyoldgit/IRremoteESP8266/issues/1943#issuecomment-1374434085
const uint16_t rawData[171] = {
5828, 1158, 1148, 464, 1148, 494, 384, 1200, 414, 1202, 412, 1202, 410,
1204, 408, 1204, 408, 1206, 408, 1228, 386, 1202, 408, 1232, 386, 1202,
1148, 464, 1146, 468, 412, 1200, 384, 1230, 412, 1200, 412, 1200, 410,
1204, 412, 1200, 412, 1202, 1146, 468, 410, 1202, 410, 1204, 1146, 466,
1146, 464, 410, 1230, 386, 1198, 414, 1200, 412, 1202, 410, 1202, 410,
1200, 410, 1204, 408, 1204, 410, 1202, 412, 1226, 386, 1202, 1144, 468,
408, 1204, 410, 1200, 1146, 468, 412, 1198, 410, 1206, 408, 1202, 410,
1228, 384, 1228, 386, 1202, 410, 1202, 412, 1202, 408, 1202, 410, 1202,
408, 1202, 410, 1204, 1146, 464, 412, 1202, 412, 1200, 1146, 468, 408,
1202, 412, 1200, 382, 1232, 1146, 488, 1122, 466, 410, 1228, 386, 1200,
1146, 492, 1118, 466, 412, 1202, 410, 1204, 1146, 464, 414, 1198, 410,
1204, 410, 1202, 1150, 464, 410, 1202, 412, 1202, 410, 1226, 386, 1200,
410, 1228, 1148, 440, 1148, 466, 1144, 468, 408, 1202, 1144, 470, 1144,
492, 1120}; // UNKNOWN 4CC7BE54

irsend.sendRaw(rawData, 171, 38000);
irsend.makeDecodeResult();
ASSERT_TRUE(irrecv.decode(&irsend.capture));
EXPECT_EQ(CARRIER_AC84, irsend.capture.decode_type);
EXPECT_EQ(kCarrierAc84Bits, irsend.capture.bits);
EXPECT_STATE_EQ(expected_state, irsend.capture.state, irsend.capture.bits);
EXPECT_EQ(
"",
IRAcUtils::resultAcToString(&irsend.capture));
EXPECT_EQ(
"Protocol : CARRIER_AC84\n"
"Code : 0x03000332001200123311DC (84 Bits)\n",
resultToHumanReadableBasic(&irsend.capture));
}

0 comments on commit df2112f

Please sign in to comment.