Skip to content

Commit

Permalink
Honour ignore_mask during decoding
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Young <[email protected]>
  • Loading branch information
seanyoung committed Mar 26, 2024
1 parent 196bfe4 commit 5035c20
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 3 deletions.
54 changes: 54 additions & 0 deletions liblircd/tests/transmit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
5 changes: 2 additions & 3 deletions src/lircd_conf/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
52 changes: 52 additions & 0 deletions tests/decode_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
// "#
// );
}

0 comments on commit 5035c20

Please sign in to comment.