Skip to content

Commit 38408c5

Browse files
authored
Basic support for Airton Protocol (#1681)
* `sendAirton()` & `decodeAirton()` added. * Unit test coverage added. For #1670
1 parent d9deca1 commit 38408c5

File tree

9 files changed

+168
-3
lines changed

9 files changed

+168
-3
lines changed

src/IRrecv.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,10 @@ bool IRrecv::decode(decode_results *results, irparams_t *save,
10431043
DPRINTLN("Attempting Rhoss decode");
10441044
if (decodeRhoss(results, offset)) return true;
10451045
#endif // DECODE_RHOSS
1046+
#if DECODE_AIRTON
1047+
DPRINTLN("Attempting Airton decode");
1048+
if (decodeAirton(results, offset)) return true;
1049+
#endif // DECODE_AIRTON
10461050
// Typically new protocols are added above this line.
10471051
}
10481052
#if DECODE_HASH

src/IRrecv.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,11 @@ class IRrecv {
774774
bool decodeRhoss(decode_results *results, uint16_t offset = kStartOffset,
775775
const uint16_t nbits = kRhossBits, const bool strict = true);
776776
#endif // DECODE_RHOSS
777+
#if DECODE_AIRTON
778+
bool decodeAirton(decode_results *results, uint16_t offset = kStartOffset,
779+
const uint16_t nbits = kAirtonBits,
780+
const bool strict = true);
781+
#endif // DECODE_AIRTON
777782
};
778783

779784
#endif // IRRECV_H_

src/IRremoteESP8266.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -798,12 +798,19 @@
798798
#endif // SEND_ARRIS
799799

800800
#ifndef DECODE_RHOSS
801-
#define DECODE_RHOSS _IR_ENABLE_DEFAULT_
801+
#define DECODE_RHOSS _IR_ENABLE_DEFAULT_
802802
#endif // DECODE_RHOSS
803803
#ifndef SEND_RHOSS
804-
#define SEND_RHOSS _IR_ENABLE_DEFAULT_
804+
#define SEND_RHOSS _IR_ENABLE_DEFAULT_
805805
#endif // SEND_RHOSS
806806

807+
#ifndef DECODE_AIRTON
808+
#define DECODE_AIRTON _IR_ENABLE_DEFAULT_
809+
#endif // DECODE_AIRTON
810+
#ifndef SEND_AIRTON
811+
#define SEND_AIRTON _IR_ENABLE_DEFAULT_
812+
#endif // SEND_AIRTON
813+
807814
#if (DECODE_ARGO || DECODE_DAIKIN || DECODE_FUJITSU_AC || DECODE_GREE || \
808815
DECODE_KELVINATOR || DECODE_MITSUBISHI_AC || DECODE_TOSHIBA_AC || \
809816
DECODE_TROTEC || DECODE_HAIER_AC || DECODE_HITACHI_AC || \
@@ -967,14 +974,17 @@ enum decode_type_t {
967974
BOSE,
968975
ARRIS,
969976
RHOSS,
977+
AIRTON,
970978
// Add new entries before this one, and update it to point to the last entry.
971-
kLastDecodeType = RHOSS,
979+
kLastDecodeType = AIRTON,
972980
};
973981

974982
// Message lengths & required repeat values
975983
const uint16_t kNoRepeat = 0;
976984
const uint16_t kSingleRepeat = 1;
977985

986+
const uint16_t kAirtonBits = 56;
987+
const uint16_t kAirtonDefaultRepeat = kNoRepeat;
978988
const uint16_t kAirwellBits = 34;
979989
const uint16_t kAirwellMinRepeats = 2;
980990
const uint16_t kAiwaRcT501Bits = 15;

src/IRsend.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ uint16_t IRsend::defaultBits(const decode_type_t protocol) {
666666
case MIDEA:
667667
case PANASONIC:
668668
return 48;
669+
case AIRTON:
669670
case ECOCLIM:
670671
case MAGIQUEST:
671672
case VESTEL_AC:
@@ -784,6 +785,11 @@ bool IRsend::send(const decode_type_t type, const uint64_t data,
784785
uint16_t min_repeat __attribute__((unused)) =
785786
std::max(IRsend::minRepeats(type), repeat);
786787
switch (type) {
788+
#if SEND_AIRTON
789+
case AIRTON:
790+
sendAirton(data, nbits, min_repeat);
791+
break;
792+
#endif // SEND_AIRTON
787793
#if SEND_AIRWELL
788794
case AIRWELL:
789795
sendAirwell(data, nbits, min_repeat);

src/IRsend.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,10 @@ class IRsend {
766766
const uint16_t nbytes = kRhossStateLength,
767767
const uint16_t repeat = kRhossDefaultRepeat);
768768
#endif // SEND_RHOSS
769+
#if SEND_AIRTON
770+
void sendAirton(const uint64_t data, const uint16_t nbits = kAirtonBits,
771+
const uint16_t repeat = kAirtonDefaultRepeat);
772+
#endif // SEND_AIRTON
769773

770774
protected:
771775
#ifdef UNIT_TEST

src/IRtext.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ IRTEXT_CONST_BLOB_DECL(kAllProtocolNamesStr) {
381381
D_STR_BOSE "\x0"
382382
D_STR_ARRIS "\x0"
383383
D_STR_RHOSS "\x0"
384+
D_STR_AIRTON "\x0"
384385
///< New protocol strings should be added just above this line.
385386
"\x0" ///< This string requires double null termination.
386387
};

src/ir_Airton.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright 2021 David Conran (crankyoldgit)
2+
/// @file
3+
/// @brief Support for Airton protocol
4+
/// @see https://github.com/crankyoldgit/IRremoteESP8266/issues/1670
5+
6+
// Supports:
7+
// Brand: Airton, Model: SMVH09B-2A2A3NH ref. 409730 A/C
8+
// Brand: Airton, Model: RD1A1 remote
9+
10+
#include "IRrecv.h"
11+
#include "IRsend.h"
12+
#include "IRutils.h"
13+
14+
const uint16_t kAirtonHdrMark = 6630;
15+
const uint16_t kAirtonBitMark = 400;
16+
const uint16_t kAirtonHdrSpace = 3350;
17+
const uint16_t kAirtonOneSpace = 1260;
18+
const uint16_t kAirtonZeroSpace = 430;
19+
const uint16_t kAirtonFreq = 38000; // Hz. (Just a guess)
20+
21+
#if SEND_AIRTON
22+
// Function should be safe up to 64 bits.
23+
/// Send a Airton formatted message.
24+
/// Status: BETA / Probably works. Needs to be tested with a real device.
25+
/// @param[in] data containing the IR command.
26+
/// @param[in] nbits Nr. of bits to send. usually kAirtonBits
27+
/// @param[in] repeat Nr. of times the message is to be repeated.
28+
void IRsend::sendAirton(const uint64_t data, const uint16_t nbits,
29+
const uint16_t repeat) {
30+
sendGeneric(kAirtonHdrMark, kAirtonHdrSpace,
31+
kAirtonBitMark, kAirtonOneSpace,
32+
kAirtonBitMark, kAirtonZeroSpace,
33+
kAirtonBitMark, kDefaultMessageGap,
34+
data, nbits, kAirtonFreq, false, repeat, kDutyDefault);
35+
}
36+
#endif // SEND_AIRTON
37+
38+
#if DECODE_AIRTON
39+
/// Decode the supplied Airton message.
40+
/// Status: STABLE / Expected to work. LSBF ordering confirmed via temperature.
41+
/// @param[in,out] results Ptr to the data to decode & where to store the decode
42+
/// @param[in] offset The starting index to use when attempting to decode the
43+
/// raw data. Typically/Defaults to kStartOffset.
44+
/// @param[in] nbits The number of data bits to expect.
45+
/// @param[in] strict Flag indicating if we should perform strict matching.
46+
/// @return A boolean. True if it can decode it, false if it can't.
47+
bool IRrecv::decodeAirton(decode_results *results, uint16_t offset,
48+
const uint16_t nbits, const bool strict) {
49+
if (results->rawlen < 2 * nbits + kHeader + kFooter - offset)
50+
return false; // Too short a message to match.
51+
if (strict && nbits != kAirtonBits)
52+
return false;
53+
54+
// Header + Data + Footer
55+
if (!matchGeneric(&(results->rawbuf[offset]), &(results->value),
56+
results->rawlen - offset, nbits,
57+
kAirtonHdrMark, kAirtonHdrSpace,
58+
kAirtonBitMark, kAirtonOneSpace,
59+
kAirtonBitMark, kAirtonZeroSpace,
60+
kAirtonBitMark, kDefaultMessageGap,
61+
true, kUseDefTol, kMarkExcess, false)) return false;
62+
63+
// Success
64+
results->decode_type = decode_type_t::AIRTON;
65+
results->bits = nbits;
66+
results->command = 0;
67+
results->address = 0;
68+
return true;
69+
}
70+
#endif // DECODE_AIRTON

src/locale/defaults.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,9 @@
669669
#endif // D_STR_DG11J191
670670

671671
// Protocols Names
672+
#ifndef D_STR_AIRTON
673+
#define D_STR_AIRTON "AIRTON"
674+
#endif // D_STR_AIRTON
672675
#ifndef D_STR_AIRWELL
673676
#define D_STR_AIRWELL "AIRWELL"
674677
#endif // D_STR_AIRWELL

test/ir_Airton_test.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2021 crankyoldgit
2+
3+
#include "IRac.h"
4+
#include "IRrecv.h"
5+
#include "IRrecv_test.h"
6+
#include "IRsend.h"
7+
#include "IRsend_test.h"
8+
#include "gtest/gtest.h"
9+
10+
// Tests for decodeAirton().
11+
12+
TEST(TestDecodeAirton, RealExample) {
13+
IRsendTest irsend(kGpioUnused);
14+
IRrecv irrecv(kGpioUnused);
15+
const uint16_t rawData[115] = {
16+
6632, 3352,
17+
404, 1266, 404, 1264, 406, 430, 406, 430, 400, 1264, 406, 430, 402, 1264,
18+
408, 1262, 406, 1264, 404, 430, 402, 434, 402, 432, 402, 1264, 406, 430,
19+
404, 432, 400, 456, 376, 432, 402, 430, 402, 1264, 404, 1264, 404, 432,
20+
402, 434, 398, 434, 402, 430, 404, 1264, 404, 432, 402, 430, 404, 1264,
21+
406, 430, 402, 432, 400, 434, 402, 430, 402, 430, 404, 432, 402, 430,
22+
402, 432, 402, 432, 402, 430, 402, 432, 402, 430, 402, 434, 400, 432,
23+
402, 1264, 404, 430, 404, 1264, 404, 432, 402, 454, 378, 432, 402, 430,
24+
404, 1264, 404, 1264, 404, 1264, 378, 1292, 404, 432, 402, 1264, 404, 432,
25+
402};
26+
irsend.begin();
27+
irsend.reset();
28+
irsend.sendRaw(rawData, 115, 38);
29+
irsend.makeDecodeResult();
30+
31+
ASSERT_TRUE(irrecv.decode(&irsend.capture));
32+
ASSERT_EQ(decode_type_t::AIRTON, irsend.capture.decode_type);
33+
ASSERT_EQ(kAirtonBits, irsend.capture.bits);
34+
EXPECT_EQ(0x5E1400090C11D3, irsend.capture.value);
35+
EXPECT_EQ(0x0, irsend.capture.address);
36+
EXPECT_EQ(0x0, irsend.capture.command);
37+
}
38+
39+
TEST(TestDecodeAirton, SyntheticExample) {
40+
IRsendTest irsend(kGpioUnused);
41+
IRrecv irrecv(kGpioUnused);
42+
irsend.begin();
43+
irsend.reset();
44+
irsend.sendAirton(0x5E1400090C11D3);
45+
irsend.makeDecodeResult();
46+
47+
ASSERT_TRUE(irrecv.decode(&irsend.capture));
48+
ASSERT_EQ(decode_type_t::AIRTON, irsend.capture.decode_type);
49+
ASSERT_EQ(kAirtonBits, irsend.capture.bits);
50+
EXPECT_EQ(0x5E1400090C11D3, irsend.capture.value);
51+
EXPECT_EQ(0x0, irsend.capture.address);
52+
EXPECT_EQ(0x0, irsend.capture.command);
53+
}
54+
55+
TEST(TestUtils, Housekeeping) {
56+
ASSERT_EQ("AIRTON", typeToString(decode_type_t::AIRTON));
57+
ASSERT_EQ(decode_type_t::AIRTON, strToDecodeType("AIRTON"));
58+
ASSERT_FALSE(hasACState(decode_type_t::AIRTON));
59+
ASSERT_FALSE(IRac::isProtocolSupported(decode_type_t::AIRTON));
60+
ASSERT_EQ(kAirtonBits, IRsend::defaultBits(decode_type_t::AIRTON));
61+
ASSERT_EQ(kAirtonDefaultRepeat, IRsend::minRepeats(decode_type_t::AIRTON));
62+
}

0 commit comments

Comments
 (0)