From 8e0ecc683444d38c71a944234270a0b13c1e0d93 Mon Sep 17 00:00:00 2001 From: crankyoldgit Date: Thu, 24 Jun 2021 19:58:16 +1000 Subject: [PATCH] Reverse bit order & add a checksum test * Convert to LSBF order. * Update unit tests accordingly. * Add a checksum test for the protocol. For #1486 --- src/ir_Teknopoint.cpp | 22 +++++++++++----------- test/ir_Teknopoint_test.cpp | 8 ++++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/ir_Teknopoint.cpp b/src/ir_Teknopoint.cpp index d085e950b..0feee6d70 100644 --- a/src/ir_Teknopoint.cpp +++ b/src/ir_Teknopoint.cpp @@ -22,15 +22,8 @@ const uint8_t kTeknopointExtraTol = 10; // Extra tolerance percentage. #if SEND_TEKNOPOINT /// Send a Teknopoint formatted message. -/// Status: BETA / Probably works however the bit order is not yet determined. +/// Status: BETA / Probably works. /// @param[in] data An array of bytes containing the IR command. -/// It is assumed to be in MSB order for this code. -/// e.g. -/// @code -/// uint8_t data[kTeknopointStateLength] = { -/// 0xC4, 0xD3, 0x64, 0x80, 0x00, 0x24, 0xC0, -/// 0xF0, 0x10, 0x00, 0x00, 0x00, 0x00, 0xCA}; -/// @endcode /// @param[in] nbytes Nr. of bytes of data in the array. /// @param[in] repeat Nr. of times the message is to be repeated. void IRsend::sendTeknopoint(const uint8_t data[], const uint16_t nbytes, @@ -40,13 +33,13 @@ void IRsend::sendTeknopoint(const uint8_t data[], const uint16_t nbytes, kTeknopointBitMark, kTeknopointZeroSpace, kTeknopointBitMark, kDefaultMessageGap, data, nbytes, // Bytes - kTeknopointFreq, true, repeat, kDutyDefault); + kTeknopointFreq, false, repeat, kDutyDefault); } #endif // SEND_TEKNOPOINT #if DECODE_TEKNOPOINT /// Decode the supplied Teknopoint message. -/// Status: Alpha / Probably works however the bit order is not yet determined. +/// Status: Alpha / Probably works. /// @param[in,out] results Ptr to the data to decode & where to store the decode /// @param[in] offset The starting index to use when attempting to decode the /// raw data. Typically/Defaults to kStartOffset. @@ -66,7 +59,14 @@ bool IRrecv::decodeTeknopoint(decode_results *results, uint16_t offset, kTeknopointBitMark, kTeknopointOneSpace, kTeknopointBitMark, kTeknopointZeroSpace, kTeknopointBitMark, kDefaultMessageGap, - true, _tolerance + kTeknopointExtraTol)) return false; + true, _tolerance + kTeknopointExtraTol, + kMarkExcess, false)) return false; + // Compliance + if (strict) { + // Is the checksum valid? + if (sumBytes(results->state, kTeknopointStateLength - 1) != + results->state[kTeknopointStateLength - 1]) return false; + } // Success results->decode_type = decode_type_t::TEKNOPOINT; results->bits = nbits; diff --git a/test/ir_Teknopoint_test.cpp b/test/ir_Teknopoint_test.cpp index cc2bd27b3..009b2a41b 100644 --- a/test/ir_Teknopoint_test.cpp +++ b/test/ir_Teknopoint_test.cpp @@ -32,8 +32,8 @@ TEST(TestDecodeTeknopoint, RealExample) { 454, 550, 366, 638, 474, 526, 474, 550, 454, 1210, 414, 1270, 394, 610, 390, 614, 470, 1214, 366, 638, 470, 1190, 474, 554, 390}; const uint8_t expectedState[kTeknopointStateLength] = { - 0xC4, 0xD3, 0x64, 0x80, 0x00, 0x24, 0xC0, - 0xF0, 0x10, 0x00, 0x00, 0x00, 0x00, 0xCA}; + 0x23, 0xCB, 0x26, 0x01, 0x00, 0x24, 0x03, + 0x0F, 0x08, 0x00, 0x00, 0x00, 0x00, 0x53}; irsend.begin(); irsend.reset(); irsend.sendRaw(rawData, 227, 38); @@ -56,8 +56,8 @@ TEST(TestDecodeTeknopoint, SyntheticExample) { // "On" const uint8_t expectedState[kTeknopointStateLength] = { - 0xC4, 0xD3, 0x64, 0x80, 0x00, 0x24, 0xC0, - 0xF0, 0x10, 0x00, 0x00, 0x00, 0x00, 0xCA}; + 0x23, 0xCB, 0x26, 0x01, 0x00, 0x24, 0x03, + 0x0F, 0x08, 0x00, 0x00, 0x00, 0x00, 0x53}; irsend.sendTeknopoint(expectedState); irsend.makeDecodeResult();