Tasmota/lib/IRremoteESP8266-2.2.1.02/test/ir_Sanyo_test.cpp
arendst 3403ca1e0a v5.10.0
5.10.0 20171201
 * Upgrade library ArduinoJson to 5.11.2
 * Upgrade
library IRRemoteEsp8266 to 2.2.1 + 2 commits but disabled some protocols
(code size reduction)
 * Upgrade library NeoPixelBus to 2.2.9
 * Upgrade
library OneWire to 2.3.3 + 6 commits and disabled CRC lookup-table
(#define ONEWIRE_CRC8_TABLE 0) (code size reduction)
 * Update library
PubSubClient to 2.6 + 9 commits and additional delay (#790)
 * Update
core_esp8266_wiring_digital.c to latest (staged) level
 * Patch library
I2Cdevlib-Core for esp8266-core 2.4.0-rc2 compatibility
 * Remove
command EnergyReset 1..3 now replaced by ENergyReset1 to EnergyReset3
 *
Remove spaces in JSON messages (code size reduction)
 * Renamed
xsns_05_ds18x20.ino to xsns_05_ds18x20_legacy.ino still using library
OneWire and providing dynamic sensor scan
 * Fix possible iram1_0_seg
compile error by shrinking ICACHE_RAM_ATTR code usage
 * Fix PWM
watchdog timeout if Dimmer is set to 100 or Color set to 0xFF (#1146)
 *
Fix Sonoff Bridge Learn Mode hang caused by unrecognised RF code
(#1181)
 * Fix blank console log window by using XML character encoding
(#1187)
 * Fix wrong response name for command HlwISet (#1214)
 * Fix
DHT type sensor timeout recognition by distinguish "signal already
there" from "timeout" (#1233)
 * Add fixed color options 1..12 to
command Color
 * Add + (plus) and - (minus) to commands Dimmer
(+10/-10), Speed and Scheme
 * Add + (plus) and - (minus) to command
Color to select 1 out of 12 preset colors
 * Add + (plus) and - (minus)
to command Ct to control ColdWarm led ColorTemperature (+34/-34)
 * Add
commands EnergyReset1 0..42500, EnergyReset2 0..42500 and EnergyReset3
0..42500000
 *  to (Re)set Energy Today, Yesterday or Total respectively
in Wh (#406, #685, #1202)
 * Add optional ADS1115 driver as alternative
for unsupported I2Cdevlib in esp8266-core 2.4.0-rc2
 * Add support for
INA219 Voltage and Current sensor to be enabled in user_config.h with
define USE_INA219
 * Add support for Arilux LC11 (Clearing RF home code
when selecting no Arilux module)
 * Add support for WS2812 RGBW
ledstrips to be enabled in user_config.h with define USE_WS2812_CTYPE
(#1156)
 * Add SettingsSaveAll routine to command SaveData to be used
before controlled power down (#1202)
 * Add option PUSHBUTTON_TOGGLE
(SwitchMode 7) to allow toggling on any switch change (#1221)
 * Add new
xdrv_05_ds18x20.ino free from library OneWire and add the following
features:
 *  Add support for DS1822
 *  Add forced setting of 12-bit
resolution for selected device types (#1222)
 *  Add read temperature
retry counter (#1215)
 *  Fix lost sensors by performing sensor probe at
restart only thereby removing dynamic sensor probe (#1215)
 *  Fix
sensor address sorting using ascending sort on sensor type followed by
sensor address
 *  Rewrite JSON resulting in shorter message allowing
more sensors in default firmware image:
 *
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}

* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
 * Add clock support for more different
pixel counts (#1226)
 * Add support for Sonoff Dual R2 (#1249)
 * Add
FriendlyName to web page tab and add program information to web page
footer (#1275)
2017-12-01 14:42:22 +01:00

243 lines
9.2 KiB
C++

// Copyright 2017 David Conran
#include "IRsend.h"
#include "IRsend_test.h"
#include "gtest/gtest.h"
// Tests for encodeSanyoLC7461().
TEST(TestEncodeSanyoLC7461, NormalEncoding) {
IRsendTest irsend(4);
EXPECT_EQ(0x1FFF00FF, irsend.encodeSanyoLC7461(0, 0));
EXPECT_EQ(0x3FFE01FE, irsend.encodeSanyoLC7461(1, 1));
EXPECT_EQ(0x3FFE02FD, irsend.encodeSanyoLC7461(1, 2));
EXPECT_EQ(0x3FFE000FF00, irsend.encodeSanyoLC7461(0x1FFF, 0xFF));
EXPECT_EQ(0x2AAAAAA55AA, irsend.encodeSanyoLC7461(0x1555, 0x55));
EXPECT_EQ(0x3FFE000FF00, irsend.encodeSanyoLC7461(0xFFFF, 0xFF));
EXPECT_EQ(0x1D8113F00FF, irsend.encodeSanyoLC7461(0xEC0, 0x0));
}
// Tests for sendSanyoLC7461().
// Test sending typical data only.
TEST(TestEncodeSanyoLC7461, SendDataOnly) {
IRsendTest irsend(4);
irsend.begin();
irsend.reset();
irsend.sendSanyoLC7461(0x1D8113F00FF);
EXPECT_EQ(
"m8960s4480"
"m560s560m560s1680m560s1680m560s1680m560s560m560s1680m560s1680m560s560"
"m560s560m560s560m560s560m560s560m560s560m560s1680m560s560m560s560"
"m560s560m560s1680m560s560m560s560m560s1680m560s1680m560s1680m560s1680"
"m560s1680m560s1680m560s560m560s560m560s560m560s560m560s560m560s560"
"m560s560m560s560m560s1680m560s1680m560s1680m560s1680m560s1680m560s1680"
"m560s1680m560s1680m560s108080", irsend.outputStr());
}
// Test sending with different repeats.
TEST(TestEncodeSanyoLC7461, SendWithRepeats) {
IRsendTest irsend(4);
irsend.begin();
irsend.reset();
irsend.sendSanyoLC7461(0x1D8113F00FF, SANYO_LC7461_BITS, 1); // 1 repeat.
EXPECT_EQ(
"m8960s4480"
"m560s560m560s1680m560s1680m560s1680m560s560m560s1680m560s1680m560s560"
"m560s560m560s560m560s560m560s560m560s560m560s1680m560s560m560s560"
"m560s560m560s1680m560s560m560s560m560s1680m560s1680m560s1680m560s1680"
"m560s1680m560s1680m560s560m560s560m560s560m560s560m560s560m560s560"
"m560s560m560s560m560s1680m560s1680m560s1680m560s1680m560s1680m560s1680"
"m560s1680m560s1680m560s108080"
"m8960s2240m560s108080", irsend.outputStr());
}
// Tests for decodeSanyoLC7461().
// Decode normal Sanyo LC7461 messages.
TEST(TestDecodeSanyoLC7461, NormalDecodeWithStrict) {
IRsendTest irsend(4);
IRrecv irrecv(4);
irsend.begin();
// Normal Sanyo LC7461 42-bit message.
irsend.reset();
irsend.sendSanyoLC7461(0x1D8113F00FF);
irsend.makeDecodeResult();
ASSERT_TRUE(irrecv.decodeSanyoLC7461(&irsend.capture, SANYO_LC7461_BITS,
true));
EXPECT_EQ(SANYO_LC7461, irsend.capture.decode_type);
EXPECT_EQ(SANYO_LC7461_BITS, irsend.capture.bits);
EXPECT_EQ(0x1D8113F00FF, irsend.capture.value);
EXPECT_EQ(0xEC0, irsend.capture.address);
EXPECT_EQ(0x0, irsend.capture.command);
EXPECT_FALSE(irsend.capture.repeat);
// Synthesised Normal Sanyo LC7461 42-bit message.
irsend.reset();
irsend.sendSanyoLC7461(irsend.encodeSanyoLC7461(0x1234, 0x56));
irsend.makeDecodeResult();
ASSERT_TRUE(irrecv.decodeSanyoLC7461(&irsend.capture, SANYO_LC7461_BITS,
true));
EXPECT_EQ(SANYO_LC7461, irsend.capture.decode_type);
EXPECT_EQ(SANYO_LC7461_BITS, irsend.capture.bits);
EXPECT_EQ(0x2468DCB56A9, irsend.capture.value);
EXPECT_EQ(0x1234, irsend.capture.address);
EXPECT_EQ(0x56, irsend.capture.command);
EXPECT_FALSE(irsend.capture.repeat);
// Synthesised Normal Sanyo LC7461 42-bit message.
irsend.reset();
irsend.sendSanyoLC7461(irsend.encodeSanyoLC7461(0x1, 0x1));
irsend.makeDecodeResult();
ASSERT_TRUE(irrecv.decodeSanyoLC7461(&irsend.capture, SANYO_LC7461_BITS,
true));
EXPECT_EQ(SANYO_LC7461, irsend.capture.decode_type);
EXPECT_EQ(SANYO_LC7461_BITS, irsend.capture.bits);
EXPECT_EQ(0x3FFE01FE, irsend.capture.value);
EXPECT_EQ(0x1, irsend.capture.address);
EXPECT_EQ(0x1, irsend.capture.command);
EXPECT_FALSE(irsend.capture.repeat);
}
// Decode normal repeated Sanyo LC7461 messages.
TEST(TestDecodeSanyoLC7461, NormalDecodeWithRepeatAndStrict) {
IRsendTest irsend(4);
IRrecv irrecv(4);
irsend.begin();
// Normal Sanyo LC7461 16-bit message with 1 repeat.
irsend.reset();
irsend.sendSanyoLC7461(0x3FFE01FE, SANYO_LC7461_BITS, 1);
irsend.makeDecodeResult();
ASSERT_TRUE(irrecv.decodeSanyoLC7461(&irsend.capture, SANYO_LC7461_BITS,
true));
EXPECT_EQ(SANYO_LC7461, irsend.capture.decode_type);
EXPECT_EQ(SANYO_LC7461_BITS, irsend.capture.bits);
EXPECT_EQ(0x3FFE01FE, irsend.capture.value);
EXPECT_EQ(0x1, irsend.capture.address);
EXPECT_EQ(0x1, irsend.capture.command);
EXPECT_FALSE(irsend.capture.repeat);
}
// Decode unsupported Sanyo LC7461 messages.
TEST(TestDecodeSanyoLC7461, DecodeWithNonStrictValues) {
IRsendTest irsend(4);
IRrecv irrecv(4);
irsend.begin();
irsend.reset();
irsend.sendSanyoLC7461(0x0); // Illegal value Sanyo LC7461 message.
irsend.makeDecodeResult();
// Should fail with strict on.
ASSERT_FALSE(irrecv.decodeSanyoLC7461(&irsend.capture, SANYO_LC7461_BITS,
true));
// Should pass if strict off.
ASSERT_TRUE(irrecv.decodeSanyoLC7461(&irsend.capture, SANYO_LC7461_BITS,
false));
EXPECT_EQ(SANYO_LC7461, irsend.capture.decode_type);
EXPECT_EQ(SANYO_LC7461_BITS, irsend.capture.bits);
EXPECT_EQ(0x0, irsend.capture.value);
EXPECT_EQ(0x0, irsend.capture.address);
EXPECT_EQ(0x0, irsend.capture.command);
irsend.reset();
// Illegal value Sanyo LC7461 42-bit message.
irsend.sendSanyoLC7461(0x1234567890A);
irsend.makeDecodeResult();
ASSERT_FALSE(irrecv.decodeSanyoLC7461(&irsend.capture, SANYO_LC7461_BITS,
true));
// Should fail with strict when we ask for the wrong bit size.
ASSERT_FALSE(irrecv.decodeSanyoLC7461(&irsend.capture, 32,
true));
ASSERT_FALSE(irrecv.decodeSanyoLC7461(&irsend.capture, 64,
true));
// And should fail for a bad value.
ASSERT_FALSE(irrecv.decodeSanyoLC7461(&irsend.capture, SANYO_LC7461_BITS,
true));
// Should pass if strict off.
ASSERT_TRUE(irrecv.decodeSanyoLC7461(&irsend.capture, SANYO_LC7461_BITS,
false));
EXPECT_EQ(SANYO_LC7461, irsend.capture.decode_type);
EXPECT_EQ(SANYO_LC7461_BITS, irsend.capture.bits);
EXPECT_EQ(0x1234567890A, irsend.capture.value);
EXPECT_EQ(0x91A, irsend.capture.address);
EXPECT_EQ(0x89, irsend.capture.command);
// Shouldn't pass if strict off and looking for a smaller size.
ASSERT_FALSE(irrecv.decodeSanyoLC7461(&irsend.capture, 34, false));
}
// Decode (non-standard) 64-bit messages.
TEST(TestDecodeSanyoLC7461, Decode64BitMessages) {
IRsendTest irsend(4);
IRrecv irrecv(4);
irsend.begin();
irsend.reset();
// Illegal value & size Sanyo LC7461 64-bit message.
irsend.sendSanyoLC7461(0xFFFFFFFFFFFFFFFF, 64);
irsend.makeDecodeResult();
// Should work with a 'normal' match (not strict)
ASSERT_TRUE(irrecv.decodeSanyoLC7461(&irsend.capture, 64, false));
EXPECT_EQ(SANYO_LC7461, irsend.capture.decode_type);
EXPECT_EQ(64, irsend.capture.bits);
EXPECT_EQ(0xFFFFFFFFFFFFFFFF, irsend.capture.value);
EXPECT_EQ(0xFFFF, irsend.capture.address);
EXPECT_EQ(0xFF, irsend.capture.command);
}
// Decode a 'real' example via GlobalCache
TEST(TestDecodeSanyoLC7461, DecodeGlobalCacheExample) {
IRsendTest irsend(4);
IRrecv irrecv(4);
irsend.begin();
irsend.reset();
uint16_t gc_test[95] = {38000, 1, 89, 342, 171, 21, 21, 21, 64, 21, 64,
21, 64, 21, 21, 21, 64, 21, 64, 21, 21, 21, 21,
21, 21, 21, 21, 21, 21, 21, 21, 21, 64, 21, 21,
21, 21, 21, 21, 21, 64, 21, 21, 21, 21, 21, 64,
21, 64, 21, 64, 21, 64, 21, 64, 21, 64, 21, 21,
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
21, 21, 21, 64, 21, 64, 21, 64, 21, 64, 21, 64,
21, 64, 21, 64, 21, 64, 21, 875, 342, 171, 21, 3565};
irsend.sendGC(gc_test, 95);
irsend.makeDecodeResult();
ASSERT_TRUE(irrecv.decodeSanyoLC7461(&irsend.capture, SANYO_LC7461_BITS, true));
EXPECT_EQ(SANYO_LC7461, irsend.capture.decode_type);
EXPECT_EQ(SANYO_LC7461_BITS, irsend.capture.bits);
EXPECT_EQ(0x1D8113F00FF, irsend.capture.value);
EXPECT_EQ(0xEC0, irsend.capture.address);
EXPECT_EQ(0x0, irsend.capture.command);
EXPECT_FALSE(irsend.capture.repeat);
// Confirm what the 42-bit NEC decode is.
ASSERT_TRUE(irrecv.decodeNEC(&irsend.capture, 42, false));
EXPECT_EQ(0x1D8113F00FF, irsend.capture.value);
}
// Fail to decode a non-Sanyo LC7461 example via GlobalCache
TEST(TestDecodeSanyoLC7461, FailToDecodeNonSanyoLC7461Example) {
IRsendTest irsend(4);
IRrecv irrecv(4);
irsend.begin();
irsend.reset();
// Modified a few entries to unexpected values, based on previous test case.
uint16_t gc_test[39] = {38000, 1, 1, 322, 162, 20, 61, 20, 61, 20, 20, 20, 20,
20, 20, 20, 127, 20, 61, 9, 20, 20, 61, 20, 20, 20,
61, 20, 61, 20, 61, 20, 20, 20, 20, 20, 20, 20, 884};
irsend.sendGC(gc_test, 39);
irsend.makeDecodeResult();
ASSERT_FALSE(irrecv.decodeSanyoLC7461(&irsend.capture));
ASSERT_FALSE(irrecv.decodeSanyoLC7461(&irsend.capture, SANYO_LC7461_BITS,
false));
}