diff --git a/liblircd/tests/transmit.rs b/liblircd/tests/transmit.rs index e30e8042..e209f020 100644 --- a/liblircd/tests/transmit.rs +++ b/liblircd/tests/transmit.rs @@ -160,4 +160,58 @@ fn encode() { let result = remote.decode(&data); assert_eq!(result, vec![0x42BD]); + + // now test decoder of a remote with an ignore_mask + + let conf = read_to_string("../testdata/lircd_conf/apple/A1156.lircd.conf").unwrap(); + + //unsafe { lirc_log_set_stdout() }; + + let conf = LircdConf::parse(&conf).unwrap(); + + let lircd_conf: Vec<_> = conf.iter().collect(); + + assert_eq!(lircd_conf.len(), 1); + + let remote = &lircd_conf[0]; + + assert_eq!(remote.name(), "Apple_A1156"); + + // encode + let code = remote + .codes_iter() + .find(|code| code.name() == "KEY_FASTFORWARD") + .unwrap(); + + let data = code.encode().unwrap(); + + let result = remote.decode(&data); + + assert_eq!(result, vec![0xe0]); + + // cargo run transmit irp '{msb}<574,-547|574,-1668>(9065,-4484,0x77e1:16,(CODE^0x80):8,0xc5:8,567,-37.6m,(9031,-2242,567,-37.6m)*) [CODE:0..255]' -fCODE=0xe0 + let data = [ + 9065, 4484, 574, 547, 574, 1668, 574, 1668, 574, 1668, 574, 547, 574, 1668, 574, 1668, 574, + 1668, 574, 1668, 574, 1668, 574, 1668, 574, 547, 574, 547, 574, 547, 574, 547, 574, 1668, + 574, 547, 574, 1668, 574, 1668, 574, 547, 574, 547, 574, 547, 574, 547, 574, 547, 574, + 1668, 574, 1668, 574, 547, 574, 547, 574, 547, 574, 1668, 574, 547, 574, 1668, 567, 37600, + 9031, 2242, 567, 37600, + ]; + + let result = remote.decode(&data); + + assert_eq!(result, vec![0xe0, 0xe0]); + + // cargo run transmit irp '{msb}<574,-547|574,-1668>(9065,-4484,0x77e1:16,(CODE^0x80):8,(0xc5^0xff):8,567,-37.6m,(9031,-2242,567,-37.6m)*) [CODE:0..255]' -fCODE=0xe0 + let data = [ + 9065, 4484, 574, 547, 574, 1668, 574, 1668, 574, 1668, 574, 547, 574, 1668, 574, 1668, 574, + 1668, 574, 1668, 574, 1668, 574, 1668, 574, 547, 574, 547, 574, 547, 574, 547, 574, 1668, + 574, 547, 574, 1668, 574, 1668, 574, 547, 574, 547, 574, 547, 574, 547, 574, 547, 574, 547, + 574, 547, 574, 1668, 574, 1668, 574, 1668, 574, 547, 574, 1668, 574, 547, 567, 37600, 9031, + 2242, 567, 37600, + ]; + + let result = remote.decode(&data); + + assert_eq!(result, vec![0xe0, 0xe0]); } diff --git a/src/lircd_conf/decode.rs b/src/lircd_conf/decode.rs index 8d2d73af..75d0f01f 100644 --- a/src/lircd_conf/decode.rs +++ b/src/lircd_conf/decode.rs @@ -56,11 +56,10 @@ impl<'a> LircDecoder<'a> { self.decoder.nfa_input(ir, &self.nfa, |_, vars| { if let Some(decoded) = vars.get("CODE") { if self.remote.raw_codes.is_empty() { - // TODO: ignore mask let (mask, toggle_bit_mask) = if self.remote.toggle_bit_mask.count_ones() == 1 { - (!self.remote.toggle_bit_mask, 0) + (!(self.remote.toggle_bit_mask | self.remote.ignore_mask), 0) } else { - (!0, self.remote.toggle_bit_mask) + (!self.remote.ignore_mask, self.remote.toggle_bit_mask) }; let decoded = *decoded as u64; diff --git a/tests/decode_tests.rs b/tests/decode_tests.rs index ace6feed..dba3e339 100644 --- a/tests/decode_tests.rs +++ b/tests/decode_tests.rs @@ -24,4 +24,56 @@ fn toggle_bit_mask() { decoded: remote:DLink_DSM-10 code:KEY_1 "# ); + + // FIXME: toggle_bit_mask in post data +} + +#[test] +fn ignore_mask() { + let mut cmd = Command::cargo_bin("cir").unwrap(); + + let assert = cmd + .args([ + "decode", "lircd", "testdata/lircd_conf/apple/A1156.lircd.conf", "-q", "-r", + "+9065 -4484 +574 -547 +574 -1668 +574 -1668 +574 -1668 +574 -547 +574 -1668 +574 -1668 +574 -1668 +574 -1668 +574 -1668 +574 -1668 +574 -547 +574 -547 +574 -547 +574 -547 +574 -1668 +574 -547 +574 -1668 +574 -1668 +574 -547 +574 -547 +574 -547 +574 -547 +574 -547 +574 -1668 +574 -1668 +574 -547 +574 -547 +574 -547 +574 -1668 +574 -547 +574 -1668 +567 -37600 +9031 -2242 +567 -37600" + ]) + .assert(); + + let output = assert.get_output(); + + let stdout = String::from_utf8_lossy(&output.stdout); + let stderr = String::from_utf8_lossy(&output.stderr); + + assert_eq!(stderr, ""); + + assert_eq!( + stdout, + r#"decoded: remote:Apple_A1156 code:KEY_PLAY +decoded: remote:Apple_A1156 code:KEY_PLAY +"# + ); + + // FIXME: post data is not ignored + // let mut cmd = Command::cargo_bin("cir").unwrap(); + + // let assert = cmd + // .args([ + // "decode", "lircd", "testdata/lircd_conf/apple/A1156.lircd.conf", "-q", "-r", + // "+9065 -4484 +574 -547 +574 -1668 +574 -1668 +574 -1668 +574 -547 +574 -1668 +574 -1668 +574 -1668 +574 -1668 +574 -1668 +574 -1668 +574 -547 +574 -547 +574 -547 +574 -547 +574 -1668 +574 -547 +574 -1668 +574 -1668 +574 -547 +574 -547 +574 -547 +574 -547 +574 -547 +574 -547 +574 -547 +574 -1668 +574 -1668 +574 -1668 +574 -547 +574 -1668 +574 -547 +567 -37600 +9031 -2242 +567 -37600" + // ]) + // .assert(); + + // let output = assert.get_output(); + + // let stdout = String::from_utf8_lossy(&output.stdout); + // let stderr = String::from_utf8_lossy(&output.stderr); + + // assert_eq!(stderr, ""); + + // assert_eq!( + // stdout, + // r#"decoded: remote:Apple_A1156 code:KEY_PLAY + // decoded: remote:Apple_A1156 code:KEY_PLAY + // "# + // ); }