|
| 1 | +// Copyright 2022 David Conran |
| 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 | + |
| 11 | +TEST(TestUtils, Housekeeping) { |
| 12 | + // Bosch144 |
| 13 | + ASSERT_EQ("BOSCH144", typeToString(decode_type_t::BOSCH144)); |
| 14 | + ASSERT_EQ(decode_type_t::BOSCH144, strToDecodeType("BOSCH144")); |
| 15 | + ASSERT_TRUE(hasACState(decode_type_t::BOSCH144)); |
| 16 | + ASSERT_FALSE(IRac::isProtocolSupported(decode_type_t::BOSCH144)); |
| 17 | + ASSERT_EQ(kBosch144Bits, IRsend::defaultBits(decode_type_t::BOSCH144)); |
| 18 | + ASSERT_EQ(kNoRepeat, IRsend::minRepeats(decode_type_t::BOSCH144)); |
| 19 | +} |
| 20 | + |
| 21 | +// Tests for decodeBosch144(). |
| 22 | + |
| 23 | +// Decode normal Bosch144 messages. |
| 24 | +TEST(TestDecodeBosch144, RealExample) { |
| 25 | + IRsendTest irsend(kGpioUnused); |
| 26 | + IRrecv irrecv(kGpioUnused); |
| 27 | + |
| 28 | + // Ref: https://github.com/crankyoldgit/IRremoteESP8266/issues/1787#issuecomment-1099993189 |
| 29 | + // Mode: Cool; Fan: 100% ; Temp: 16°C |
| 30 | + const uint16_t rawData[299] = { |
| 31 | + 4380, 4400, |
| 32 | + 528, 1646, 504, 570, 504, 1646, 504, 1646, 504, 572, 502, 570, 504, 1646, |
| 33 | + 504, 570, 504, 572, 502, 1646, 504, 570, 502, 570, 502, 1648, 502, 1646, |
| 34 | + 502, 570, 502, 1646, 504, 572, 502, 572, 502, 1644, 504, 1646, 504, 1646, |
| 35 | + 504, 1646, 502, 1648, 500, 1646, 504, 1646, 504, 1646, 504, 572, 502, 570, |
| 36 | + 504, 570, 504, 570, 504, 570, 504, 570, 506, 570, 502, 572, 502, 570, 502, |
| 37 | + 572, 502, 572, 502, 572, 502, 572, 502, 572, 500, 1648, 502, 1644, 502, |
| 38 | + 1646, 504, 1646, 502, 1646, 504, 1646, 504, 1644, 504, 1646, |
| 39 | + 504, 5234, |
| 40 | + 4360, 4422, |
| 41 | + 504, 1646, 502, 596, 478, 1670, 478, 1646, 504, 570, 504, 572, 500, 1646, |
| 42 | + 502, 572, 502, 572, 502, 1644, 506, 570, 502, 570, 504, 1644, 506, 1644, |
| 43 | + 502, 574, 502, 1644, 504, 570, 504, 570, 504, 1644, 504, 1646, 504, 1644, |
| 44 | + 506, 1644, 504, 1646, 504, 1646, 504, 1644, 504, 1646, 502, 570, 504, 570, |
| 45 | + 504, 570, 504, 570, 502, 570, 504, 570, 502, 572, 502, 570, 504, 570, 504, |
| 46 | + 570, 504, 570, 502, 572, 502, 570, 506, 570, 504, 1646, 502, 1646, 504, |
| 47 | + 1646, 504, 1646, 504, 1646, 502, 1644, 504, 1644, 504, 1646, |
| 48 | + 502, 5236, |
| 49 | + 4360, 4424, |
| 50 | + 504, 1646, 504, 1646, 502, 572, 504, 1644, 504, 570, 504, 1646, 504, 570, |
| 51 | + 502, 1644, 504, 570, 504, 1644, 506, 1646, 502, 572, 502, 572, 502, 1646, |
| 52 | + 504, 570, 504, 570, 504, 570, 502, 572, 504, 570, 504, 570, 504, 570, 502, |
| 53 | + 572, 502, 570, 504, 570, 502, 570, 504, 572, 502, 572, 502, 1646, 504, |
| 54 | + 570, 504, 570, 504, 570, 502, 574, 502, 572, 502, 572, 502, 572, 502, 572, |
| 55 | + 502, 572, 502, 570, 504, 572, 502, 572, 502, 572, 502, 1646, 504, 572, |
| 56 | + 502, 570, 502, 1646, 504, 572, 504, 570, 504, 1644, |
| 57 | + 504}; // COOLIX B23F00 |
| 58 | + const uint8_t expectedState[kBosch144StateLength] = { |
| 59 | + 0xB2, 0x4D, 0x3F, 0xC0, 0x00, 0xFF, |
| 60 | + 0xB2, 0x4D, 0x3F, 0xC0, 0x00, 0xFF, |
| 61 | + 0xD5, 0x64, 0x00, 0x10, 0x00, 0x49}; |
| 62 | + irsend.begin(); |
| 63 | + irsend.reset(); |
| 64 | + |
| 65 | + irsend.sendRaw(rawData, 299, 38000); |
| 66 | + irsend.makeDecodeResult(); |
| 67 | + ASSERT_TRUE(irrecv.decode(&irsend.capture)); |
| 68 | + EXPECT_EQ(decode_type_t::BOSCH144, irsend.capture.decode_type); |
| 69 | + EXPECT_EQ(kBosch144Bits, irsend.capture.bits); |
| 70 | + EXPECT_STATE_EQ(expectedState, irsend.capture.state, irsend.capture.bits); |
| 71 | + EXPECT_EQ( |
| 72 | + "", |
| 73 | + IRAcUtils::resultAcToString(&irsend.capture)); |
| 74 | + stdAc::state_t result, prev; |
| 75 | + ASSERT_FALSE(IRAcUtils::decodeToState(&irsend.capture, &result, &prev)); |
| 76 | +} |
| 77 | + |
| 78 | +TEST(TestDecodeBosch144, SyntheticSelfDecode) { |
| 79 | + IRsendTest irsend(kGpioUnused); |
| 80 | + IRrecv irrecv(kGpioUnused); |
| 81 | + irsend.begin(); |
| 82 | + |
| 83 | + irsend.reset(); |
| 84 | + const uint8_t expectedState[kBosch144StateLength] = { |
| 85 | + 0xB2, 0x4D, 0x3F, 0xC0, 0x00, 0xFF, |
| 86 | + 0xB2, 0x4D, 0x3F, 0xC0, 0x00, 0xFF, |
| 87 | + 0xD5, 0x64, 0x00, 0x10, 0x00, 0x49}; |
| 88 | + irsend.sendBosch144(expectedState); |
| 89 | + irsend.makeDecodeResult(); |
| 90 | + |
| 91 | + ASSERT_TRUE(irrecv.decode(&irsend.capture)); |
| 92 | + EXPECT_EQ(decode_type_t::BOSCH144, irsend.capture.decode_type); |
| 93 | + EXPECT_EQ(kBosch144Bits, irsend.capture.bits); |
| 94 | + EXPECT_STATE_EQ(expectedState, irsend.capture.state, irsend.capture.bits); |
| 95 | + EXPECT_EQ( |
| 96 | + "", |
| 97 | + IRAcUtils::resultAcToString(&irsend.capture)); |
| 98 | + stdAc::state_t result, prev; |
| 99 | + ASSERT_FALSE(IRAcUtils::decodeToState(&irsend.capture, &result, &prev)); |
| 100 | +} |
0 commit comments