-
Notifications
You must be signed in to change notification settings - Fork 844
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experimental basic support for Teknopoint A/C protocol (#1504)
* Basic support added via `sendTeknopoint()` & `decodeTeknopoint()` * Unit test coverage for the additions/changes. * Minor code style clean-up. * Checksum validation. Note: Bit ordering now determined (_LSBF_) via Temp range & checksum calc. For #1486
1 parent
609abce
commit fa774c8
Showing
10 changed files
with
218 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2021 David Conran (crankyoldgit) | ||
/// @file | ||
/// @brief Support for the Teknopoint protocol | ||
/// @see https://github.com/crankyoldgit/IRremoteESP8266/issues/1486 | ||
|
||
// Supports: | ||
// Brand: Teknopoint, Model: Allegro SSA-09H A/C | ||
// Brand: Teknopoint, Model: GZ-055B-E1 remote | ||
|
||
#include "IRrecv.h" | ||
#include "IRsend.h" | ||
#include "IRutils.h" | ||
|
||
// Protocol timings | ||
const uint16_t kTeknopointHdrMark = 3600; | ||
const uint16_t kTeknopointBitMark = 477; | ||
const uint16_t kTeknopointHdrSpace = 1600; | ||
const uint16_t kTeknopointOneSpace = 1200; | ||
const uint16_t kTeknopointZeroSpace = 530; | ||
const uint16_t kTeknopointFreq = 38000; // Hz. (Guess Only) | ||
const uint8_t kTeknopointExtraTol = 10; // Extra tolerance percentage. | ||
|
||
#if SEND_TEKNOPOINT | ||
/// Send a Teknopoint formatted message. | ||
/// Status: BETA / Probably works. | ||
/// @param[in] data An array of bytes containing the IR command. | ||
/// @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, | ||
const uint16_t repeat) { | ||
sendGeneric(kTeknopointHdrMark, kTeknopointHdrSpace, | ||
kTeknopointBitMark, kTeknopointOneSpace, | ||
kTeknopointBitMark, kTeknopointZeroSpace, | ||
kTeknopointBitMark, kDefaultMessageGap, | ||
data, nbytes, // Bytes | ||
kTeknopointFreq, false, repeat, kDutyDefault); | ||
} | ||
#endif // SEND_TEKNOPOINT | ||
|
||
#if DECODE_TEKNOPOINT | ||
/// Decode the supplied Teknopoint message. | ||
/// 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. | ||
/// @param[in] nbits The number of data bits to expect. | ||
/// @param[in] strict Flag indicating if we should perform strict matching. | ||
/// @return A boolean. True if it can decode it, false if it can't. | ||
bool IRrecv::decodeTeknopoint(decode_results *results, uint16_t offset, | ||
const uint16_t nbits, const bool strict) { | ||
if (results->rawlen < 2 * nbits + kHeader + kFooter - 1 - offset) | ||
return false; // Too short a message to match. | ||
if (strict && nbits != kTeknopointBits) | ||
return false; | ||
|
||
if (!matchGeneric(results->rawbuf + offset, results->state, | ||
results->rawlen - offset, nbits, | ||
kTeknopointHdrMark, kTeknopointHdrSpace, | ||
kTeknopointBitMark, kTeknopointOneSpace, | ||
kTeknopointBitMark, kTeknopointZeroSpace, | ||
kTeknopointBitMark, kDefaultMessageGap, | ||
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; | ||
return true; | ||
} | ||
#endif // DECODE_TEKNOPOINT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Copyright 2021 David Conran (crankyoldgit) | ||
|
||
#include "IRac.h" | ||
#include "IRrecv.h" | ||
#include "IRrecv_test.h" | ||
#include "IRsend.h" | ||
#include "IRsend_test.h" | ||
#include "gtest/gtest.h" | ||
|
||
// Tests for decodeTeknopoint(). | ||
|
||
TEST(TestDecodeTeknopoint, RealExample) { | ||
IRsendTest irsend(kGpioUnused); | ||
IRrecv irrecv(kGpioUnused); | ||
// "On" | ||
// Ref: https://github.com/crankyoldgit/IRremoteESP8266/issues/1486#issue-904276382 | ||
const uint16_t rawData[227] = { | ||
3614, 1610, 474, 1210, 390, 1294, 454, 550, 394, 606, 474, 530, 474, 1186, | ||
394, 634, 390, 638, 450, 1210, 366, 1318, 450, 554, 394, 1270, 470, 554, | ||
450, 530, 390, 1318, 450, 1214, 470, 530, 474, 1210, 370, 1294, 474, 550, | ||
450, 554, 470, 1214, 450, 550, 394, 614, 466, 1218, 450, 550, 370, 634, | ||
474, 530, 474, 550, 450, 550, 450, 554, 366, 634, 502, 554, 446, 554, 450, | ||
550, 450, 554, 390, 614, 474, 526, 478, 526, 474, 550, 450, 534, 406, 614, | ||
390, 1294, 394, 610, 390, 614, 470, 1214, 366, 638, 470, 554, 450, 1214, | ||
366, 1318, 450, 550, 454, 550, 474, 530, 470, 530, 474, 550, 454, 550, | ||
450, 1238, 450, 1210, 470, 1214, 454, 1210, 474, 550, 450, 554, 394, 582, | ||
394, 634, 474, 526, 478, 550, 450, 526, 474, 1214, 474, 550, 454, 550, | ||
394, 606, 370, 634, 474, 526, 478, 550, 450, 550, 394, 610, 366, 638, 414, | ||
586, 478, 546, 454, 550, 422, 606, 390, 610, 474, 554, 450, 550, 454, 550, | ||
450, 530, 410, 614, 478, 526, 474, 550, 450, 550, 454, 550, 390, 614, 474, | ||
526, 474, 550, 454, 550, 450, 554, 366, 634, 474, 526, 478, 550, 450, 550, | ||
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] = { | ||
0x23, 0xCB, 0x26, 0x01, 0x00, 0x24, 0x03, | ||
0x0F, 0x08, 0x00, 0x00, 0x00, 0x00, 0x53}; | ||
irsend.begin(); | ||
irsend.reset(); | ||
irsend.sendRaw(rawData, 227, 38); | ||
irsend.makeDecodeResult(); | ||
|
||
ASSERT_TRUE(irrecv.decode(&irsend.capture)); | ||
ASSERT_EQ(decode_type_t::TEKNOPOINT, irsend.capture.decode_type); | ||
ASSERT_EQ(kTeknopointBits, irsend.capture.bits); | ||
EXPECT_STATE_EQ(expectedState, irsend.capture.state, irsend.capture.bits); | ||
EXPECT_EQ( | ||
"", | ||
IRAcUtils::resultAcToString(&irsend.capture)); | ||
} | ||
|
||
TEST(TestDecodeTeknopoint, SyntheticExample) { | ||
IRsendTest irsend(kGpioUnused); | ||
IRrecv irrecv(kGpioUnused); | ||
irsend.begin(); | ||
irsend.reset(); | ||
|
||
// "On" | ||
const uint8_t expectedState[kTeknopointStateLength] = { | ||
0x23, 0xCB, 0x26, 0x01, 0x00, 0x24, 0x03, | ||
0x0F, 0x08, 0x00, 0x00, 0x00, 0x00, 0x53}; | ||
|
||
irsend.sendTeknopoint(expectedState); | ||
irsend.makeDecodeResult(); | ||
|
||
ASSERT_TRUE(irrecv.decode(&irsend.capture)); | ||
ASSERT_EQ(decode_type_t::TEKNOPOINT, irsend.capture.decode_type); | ||
ASSERT_EQ(kTeknopointBits, irsend.capture.bits); | ||
EXPECT_STATE_EQ(expectedState, irsend.capture.state, irsend.capture.bits); | ||
EXPECT_EQ( | ||
"", | ||
IRAcUtils::resultAcToString(&irsend.capture)); | ||
|
||
EXPECT_EQ( | ||
"f38000d50" | ||
"m3600s1600" | ||
"m477s1200m477s1200m477s530m477s530m477s530m477s1200m477s530m477s530" | ||
"m477s1200m477s1200m477s530m477s1200m477s530m477s530m477s1200m477s1200" | ||
"m477s530m477s1200m477s1200m477s530m477s530m477s1200m477s530m477s530" | ||
"m477s1200m477s530m477s530m477s530m477s530m477s530m477s530m477s530" | ||
"m477s530m477s530m477s530m477s530m477s530m477s530m477s530m477s530" | ||
"m477s530m477s530m477s1200m477s530m477s530m477s1200m477s530m477s530" | ||
"m477s1200m477s1200m477s530m477s530m477s530m477s530m477s530m477s530" | ||
"m477s1200m477s1200m477s1200m477s1200m477s530m477s530m477s530m477s530" | ||
"m477s530m477s530m477s530m477s1200m477s530m477s530m477s530m477s530" | ||
"m477s530m477s530m477s530m477s530m477s530m477s530m477s530m477s530" | ||
"m477s530m477s530m477s530m477s530m477s530m477s530m477s530m477s530" | ||
"m477s530m477s530m477s530m477s530m477s530m477s530m477s530m477s530" | ||
"m477s530m477s530m477s530m477s530m477s530m477s530m477s530m477s530" | ||
"m477s1200m477s1200m477s530m477s530m477s1200m477s530m477s1200m477s530" | ||
"m477s100000", | ||
irsend.outputStr()); | ||
} | ||
|
||
TEST(TestUtils, Housekeeping) { | ||
ASSERT_EQ("TEKNOPOINT", typeToString(decode_type_t::TEKNOPOINT)); | ||
ASSERT_EQ(decode_type_t::TEKNOPOINT, strToDecodeType("TEKNOPOINT")); | ||
ASSERT_TRUE(hasACState(decode_type_t::TEKNOPOINT)); | ||
ASSERT_FALSE(IRac::isProtocolSupported(decode_type_t::TEKNOPOINT)); | ||
ASSERT_EQ(kTeknopointBits, IRsend::defaultBits(decode_type_t::TEKNOPOINT)); | ||
ASSERT_EQ(kNoRepeat, IRsend::minRepeats(decode_type_t::TEKNOPOINT)); | ||
} |