Skip to content

Commit

Permalink
Reverse bit order & add a checksum test
Browse files Browse the repository at this point in the history
* Convert to LSBF order.
* Update unit tests accordingly.
* Add a checksum test for the protocol.

For #1486
  • Loading branch information
crankyoldgit committed Jun 24, 2021
1 parent 1bf8211 commit 8e0ecc6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
22 changes: 11 additions & 11 deletions src/ir_Teknopoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions test/ir_Teknopoint_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down

0 comments on commit 8e0ecc6

Please sign in to comment.