Skip to content

Commit

Permalink
Fix cir transmit -R 2 -S …
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Young <[email protected]>
  • Loading branch information
seanyoung committed May 20, 2024
1 parent 2a84c14 commit 809a378
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 46 deletions.
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Necessary:
Nice to have:
- ir encode/send needs to read xml file
- cir decode irp should read IrpProtocols.xml
- cir transmit -S sony15:12 -R 2 ??
- pcmak leading gap not decoded
- encoding toggle_bit_mask not used when popcount > 1
- compare against kernel encoder/decoder
Expand Down
1 change: 1 addition & 0 deletions cir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ serde_json = "1.0"
liblircd = { workspace = true }
libirctl = { workspace = true }
rand = "0.8"
pretty_assertions = "1.4"
41 changes: 16 additions & 25 deletions cir/src/bin/commands/transmit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ pub fn transmit(transmit: &crate::Transmit) {
}
}

fn encode_args(transmit: &crate::Transmit) -> Message {
fn encode_args(args: &crate::Transmit) -> Message {
let mut vars = irp::Vartable::new();

for field in &transmit.arguments {
for field in &args.arguments {
let list: Vec<&str> = field.trim().split('=').collect();

if list.len() != 2 {
Expand All @@ -146,12 +146,12 @@ fn encode_args(transmit: &crate::Transmit) -> Message {
vars.set(list[0].to_string(), value);
}

let (lircd_conf, keymap) = if let Some(path) = &transmit.keymap {
let (lircd_conf, keymap) = if let Some(path) = &args.keymap {
if path.to_string_lossy().ends_with(".lircd.conf") {
match lircd_conf::parse(path) {
Ok(r) => {
if transmit.list_codes {
list_lircd_remotes(path, &r, transmit.remote.as_deref());
if args.list_codes {
list_lircd_remotes(path, &r, args.remote.as_deref());

std::process::exit(0);
}
Expand All @@ -163,8 +163,8 @@ fn encode_args(transmit: &crate::Transmit) -> Message {
} else {
match Keymap::parse_file(path) {
Ok(r) => {
if transmit.list_codes {
list_keymap_remotes(path, &r, transmit.remote.as_deref());
if args.list_codes {
list_keymap_remotes(path, &r, args.remote.as_deref());

std::process::exit(0);
}
Expand All @@ -188,7 +188,7 @@ fn encode_args(transmit: &crate::Transmit) -> Message {

let mut part = Vec::new();

for tx in &transmit.transmitables {
for tx in &args.transmitables {
match tx {
crate::Transmitables::File(filename) => {
let input = match fs::read_to_string(filename) {
Expand Down Expand Up @@ -230,7 +230,7 @@ fn encode_args(transmit: &crate::Transmit) -> Message {
}
},
crate::Transmitables::Scancode((protocol, scancode)) => {
match encode_scancode(protocol, *scancode) {
match encode_scancode(protocol, *scancode, args.repeats) {
Ok(m) => {
part.push(Part::Raw(m));
}
Expand All @@ -252,7 +252,7 @@ fn encode_args(transmit: &crate::Transmit) -> Message {
}
};

let m = p.encode(transmit.repeats as usize);
let m = p.encode(args.repeats as usize);

part.push(Part::Raw(m));
}
Expand All @@ -264,7 +264,7 @@ fn encode_args(transmit: &crate::Transmit) -> Message {
std::process::exit(2);
}
};
match irp.encode_raw(vars.clone(), transmit.repeats) {
match irp.encode_raw(vars.clone(), args.repeats) {
Ok(m) => {
part.push(Part::Raw(m));
}
Expand All @@ -276,12 +276,8 @@ fn encode_args(transmit: &crate::Transmit) -> Message {
}
crate::Transmitables::Code(code) => {
if let Some(lircd_conf) = &lircd_conf {
match lircd_conf::encode(
lircd_conf,
transmit.remote.as_deref(),
code,
transmit.repeats,
) {
match lircd_conf::encode(lircd_conf, args.remote.as_deref(), code, args.repeats)
{
Ok(m) => {
part.push(Part::Raw(m));
}
Expand All @@ -291,12 +287,7 @@ fn encode_args(transmit: &crate::Transmit) -> Message {
}
}
} else if let Some(keymap) = &keymap {
match cir::keymap::encode(
keymap,
transmit.remote.as_deref(),
code,
transmit.repeats,
) {
match cir::keymap::encode(keymap, args.remote.as_deref(), code, args.repeats) {
Ok(m) => {
part.push(Part::Raw(m));
}
Expand Down Expand Up @@ -465,7 +456,7 @@ fn list_lircd_remotes(filename: &Path, remotes: &[lircd_conf::Remote], needle: O
}
}

fn encode_scancode(protocol: &str, mut scancode: u64) -> Result<Message, String> {
fn encode_scancode(protocol: &str, mut scancode: u64, repeats: u64) -> Result<Message, String> {
let Some(linux) = LinuxProtocol::find_like(protocol) else {
return Err(format!("protocol {protocol} is not known"));
};
Expand All @@ -487,5 +478,5 @@ fn encode_scancode(protocol: &str, mut scancode: u64) -> Result<Message, String>

vars.set("CODE".into(), scancode as i64);

irp.encode_raw(vars, 1)
irp.encode_raw(vars, repeats)
}
32 changes: 16 additions & 16 deletions cir/src/keymap/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,22 @@ const LINUX_PROTOCOLS: &[LinuxProtocol] = &[
name: "rc5",
decoder: "rc-5",
irp: Some(
"{36k,msb,889}<1,-1|-1,1>(1,~CODE:1:6,T:1,CODE:5:8,CODE:6,^114m) [CODE:0..0x1FFF,T:0..1=0]",
"{36k,msb,889}<1,-1|-1,1>(1,~CODE:1:6,T:1,CODE:5:8,CODE:6,^114m)+ [CODE:0..0x1FFF,T:0..1=0]",
),
scancode_mask: 0x1f7f,
protocol_no: 2,
},
LinuxProtocol {
name: "rc5x_20",
decoder: "rc-5",
irp: Some("{36k,msb,889}<1,-1|-1,1>(1,~CODE:1:14,T:1,CODE:5:16,-4,CODE:6:8,CODE:6,^114m) [CODE:0..0x1fffff,T:0..1=0]"),
irp: Some("{36k,msb,889}<1,-1|-1,1>(1,~CODE:1:14,T:1,CODE:5:16,-4,CODE:6:8,CODE:6,^114m)+ [CODE:0..0x1fffff,T:0..1=0]"),
scancode_mask: 0x1f7f3f,
protocol_no: 3,
},
LinuxProtocol {
name: "rc5_sz",
decoder: "rc-5-sz",
irp: Some("{36k,msb,889}<1,-1|-1,1>(1,CODE:1:13,T:1,CODE:12,^114m) [CODE:0..0x2fff,T:0..1=0]"),
irp: Some("{36k,msb,889}<1,-1|-1,1>(1,CODE:1:13,T:1,CODE:12,^114m)+ [CODE:0..0x2fff,T:0..1=0]"),
scancode_mask: 0x2fff,
protocol_no: 4,
},
Expand All @@ -81,21 +81,21 @@ const LINUX_PROTOCOLS: &[LinuxProtocol] = &[
LinuxProtocol {
name: "sony12",
decoder: "sony",
irp: Some("{40k,600}<1,-1|2,-1>(4,-1,CODE:7,CODE:5:16,^45m) [CODE:0..0x1fffff]"),
irp: Some("{40k,600}<1,-1|2,-1>(4,-1,CODE:7,CODE:5:16,^45m)+ [CODE:0..0x1fffff]"),
scancode_mask: 0x1f007f,
protocol_no: 6,
},
LinuxProtocol {
name: "sony15",
decoder: "sony",
irp: Some("{40k,600}<1,-1|2,-1>(4,-1,CODE:7,CODE:8:16,^45m) [CODE:0..0xffffff]"),
irp: Some("{40k,600}<1,-1|2,-1>(4,-1,CODE:7,CODE:8:16,^45m)+ [CODE:0..0xffffff]"),
scancode_mask: 0xff007f,
protocol_no: 7,
},
LinuxProtocol {
name: "sony20",
decoder: "sony",
irp: Some("{40k,600}<1,-1|2,-1>(4,-1,CODE:7,CODE:5:16,CODE:8:8,^45m) [CODE:0..0x1fffff]"),
irp: Some("{40k,600}<1,-1|2,-1>(4,-1,CODE:7,CODE:5:16,CODE:8:8,^45m)+ [CODE:0..0x1fffff]"),
scancode_mask: 0x1fff7f,
protocol_no: 8,
},
Expand Down Expand Up @@ -144,42 +144,42 @@ const LINUX_PROTOCOLS: &[LinuxProtocol] = &[
LinuxProtocol {
name: "rc6_0",
decoder: "rc-6",
irp: Some("{36k,444,msb}<-1,1|1,-1>(6,-2,1:1,0:3,<-2,2|2,-2>(T:1),CODE:16,^107m) [CODE:0..0xffff,T@:0..1=0]"),
irp: Some("{36k,444,msb}<-1,1|1,-1>(6,-2,1:1,0:3,<-2,2|2,-2>(T:1),CODE:16,^107m)+ [CODE:0..0xffff,T@:0..1=0]"),
scancode_mask: 0xffff,
protocol_no: 15,
},
LinuxProtocol {
name: "rc6_6a_20",
decoder: "rc-6",
irp: Some("{36k,444,msb}<-1,1|1,-1>(6,-2,1:1,6:3,<-2,2|2,-2>(T:1),CODE:20,-100m) [CODE:0..0xfffff,T@:0..1=0]"),
irp: Some("{36k,444,msb}<-1,1|1,-1>(6,-2,1:1,6:3,<-2,2|2,-2>(T:1),CODE:20,-100m)+ [CODE:0..0xfffff,T@:0..1=0]"),
scancode_mask: 0xf_ffff,
protocol_no: 16,
},
LinuxProtocol {
name: "rc6_6a_24",
decoder: "rc-6",
irp: Some("{36k,444,msb}<-1,1|1,-1>(6,-2,1:1,6:3,<-2,2|2,-2>(T:1),CODE:24,^105m) [CODE:0..0xffffff,T@:0..1=0]"),
irp: Some("{36k,444,msb}<-1,1|1,-1>(6,-2,1:1,6:3,<-2,2|2,-2>(T:1),CODE:24,^105m)+ [CODE:0..0xffffff,T@:0..1=0]"),
scancode_mask: 0xff_ff_ff,
protocol_no: 17,
},
LinuxProtocol {
name: "rc6_6a_32",
decoder: "rc-6",
irp: Some("{36k,444,msb}<-1,1|1,-1>(6,-2,1:1,6:3,<-2,2|2,-2>(T:1),CODE:32,MCE=(CODE>>16)==0x800f||(CODE>>16)==0x8034||(CODE>>16)==0x8046,^105m){MCE=0}[CODE:0..0xffffffff,T@:0..1=0]"),
irp: Some("{36k,444,msb}<-1,1|1,-1>(6,-2,1:1,6:3,<-2,2|2,-2>(T:1),CODE:32,MCE=(CODE>>16)==0x800f||(CODE>>16)==0x8034||(CODE>>16)==0x8046,^105m)+{MCE=0}[CODE:0..0xffffffff,T@:0..1=0]"),
scancode_mask: 0xffff_ffff,
protocol_no: 18,
},
LinuxProtocol {
name: "rc6_mce",
decoder: "rc-6",
irp: Some("{36k,444,msb}<-1,1|1,-1>(6,-2,1:1,6:3,-2,2,CODE:16:16,T:1,CODE:15,MCE=(CODE>>16)==0x800f||(CODE>>16)==0x8034||(CODE>>16)==0x8046,^105m){MCE=1}[CODE:0..0xffffffff,T@:0..1=0]"),
irp: Some("{36k,444,msb}<-1,1|1,-1>(6,-2,1:1,6:3,-2,2,CODE:16:16,T:1,CODE:15,MCE=(CODE>>16)==0x800f||(CODE>>16)==0x8034||(CODE>>16)==0x8046,^105m)+{MCE=1}[CODE:0..0xffffffff,T@:0..1=0]"),
scancode_mask: 0xffff_7fff,
protocol_no: 19,
},
LinuxProtocol {
name: "sharp",
decoder: "sharp",
irp: Some("{38k,264}<1,-3|1,-7>(CODE:5:8,CODE:8,1:2,1,-165,CODE:5:8,~CODE:8,2:2,1,-165) [CODE:0..0x1fff]"),
irp: Some("{38k,264}<1,-3|1,-7>(CODE:5:8,CODE:8,1:2,1,-165,CODE:5:8,~CODE:8,2:2,1,-165)+ [CODE:0..0x1fff]"),
scancode_mask: 0x1fff,
protocol_no: 20,
},
Expand Down Expand Up @@ -209,30 +209,30 @@ const LINUX_PROTOCOLS: &[LinuxProtocol] = &[
LinuxProtocol {
name: "rc-mm-12",
decoder: "rc-mm",
irp: Some("{36k,msb}<166.7,-277.8|166.7,-444.4|166.7,-611.1|166.7,-777.8>(416.7,-277.8,CODE:12,166.7,^27.778m) [CODE:0..0xfff]"),
irp: Some("{36k,msb}<166.7,-277.8|166.7,-444.4|166.7,-611.1|166.7,-777.8>(416.7,-277.8,CODE:12,166.7,^27.778m)+ [CODE:0..0xfff]"),
scancode_mask: 0xfff,
protocol_no: 24,
},
LinuxProtocol {
name: "rc-mm-24",
decoder: "rc-mm",
irp: Some("{36k,msb}<166.7,-277.8|166.7,-444.4|166.7,-611.1|166.7,-777.8>(416.7,-277.8,CODE:24,166.7,^27.778m) [CODE:0..0xffffff]"),
irp: Some("{36k,msb}<166.7,-277.8|166.7,-444.4|166.7,-611.1|166.7,-777.8>(416.7,-277.8,CODE:24,166.7,^27.778m)+ [CODE:0..0xffffff]"),
scancode_mask: 0xfff_fff,
protocol_no: 25,
},
LinuxProtocol {
name: "rc-mm-32",
decoder: "rc-mm",
// toggle?
irp: Some("{36k,msb}<166.7,-277.8|166.7,-444.4|166.7,-611.1|166.7,-777.8>(416.7,-277.8,CODE:32,166.7,^27.778m) [CODE:0..0xffffffff]"),
irp: Some("{36k,msb}<166.7,-277.8|166.7,-444.4|166.7,-611.1|166.7,-777.8>(416.7,-277.8,CODE:32,166.7,^27.778m)+ [CODE:0..0xffffffff]"),
scancode_mask: 0xffff_ffff,
protocol_no: 26,
},
LinuxProtocol {
name: "xbox-dvd",
decoder: "xbox-dvd",
// trailing space is a guess, should be verified on real hardware
irp: Some("{38k,msb}<550,-900|550,-1900>(4000,-3900,~CODE:12,CODE:12,550,^100m) [CODE:0..0xfff]"),
irp: Some("{38k,msb}<550,-900|550,-1900>(4000,-3900,~CODE:12,CODE:12,550,^100m)+ [CODE:0..0xfff]"),
scancode_mask: 0xfff,
protocol_no: 27,
}
Expand Down
7 changes: 4 additions & 3 deletions cir/tests/decode_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use assert_cmd::Command;
use pretty_assertions::assert_eq;

#[test]
fn toggle_bit_mask() {
Expand Down Expand Up @@ -94,9 +95,9 @@ fn keymap() {

assert_eq!(
stderr,
r#"debug: decoding irp {40k,600}<1,-1|2,-1>(4,-1,CODE:7,CODE:5:16,^45m) [CODE:0..0x1fffff] for keymap Sony-RM-U305C
debug: decoding irp {40k,600}<1,-1|2,-1>(4,-1,CODE:7,CODE:8:16,^45m) [CODE:0..0xffffff] for keymap Sony-RM-U305C
debug: decoding irp {40k,600}<1,-1|2,-1>(4,-1,CODE:7,CODE:5:16,CODE:8:8,^45m) [CODE:0..0x1fffff] for keymap Sony-RM-U305C
r#"debug: decoding irp {40k,600}<1,-1|2,-1>(4,-1,CODE:7,CODE:5:16,^45m)+ [CODE:0..0x1fffff] for keymap Sony-RM-U305C
debug: decoding irp {40k,600}<1,-1|2,-1>(4,-1,CODE:7,CODE:8:16,^45m)+ [CODE:0..0xffffff] for keymap Sony-RM-U305C
debug: decoding irp {40k,600}<1,-1|2,-1>(4,-1,CODE:7,CODE:5:16,CODE:8:8,^45m)+ [CODE:0..0x1fffff] for keymap Sony-RM-U305C
debug: generated NFA for Sony-RM-U305C
debug: generated DFA for Sony-RM-U305C
debug: generated NFA for Sony-RM-U305C
Expand Down
3 changes: 2 additions & 1 deletion cir/tests/encode_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use assert_cmd::Command;
use pretty_assertions::assert_eq;

#[test]
fn encode_test() {
Expand Down Expand Up @@ -347,7 +348,7 @@ info: rawir: +2369 -637 +1166 -637 +565 -637 +565 -637 +1166 -637 +565 -637 +565

assert_eq!(
stderr,
r#"debug: using irp for encoding: {36k,444,msb}<-1,1|1,-1>(6,-2,1:1,6:3,-2,2,CODE:16:16,T:1,CODE:15,MCE=(CODE>>16)==0x800f||(CODE>>16)==0x8034||(CODE>>16)==0x8046,^105m){MCE=1}[CODE:0..0xffffffff,T@:0..1=0]
r#"debug: using irp for encoding: {36k,444,msb}<-1,1|1,-1>(6,-2,1:1,6:3,-2,2,CODE:16:16,T:1,CODE:15,MCE=(CODE>>16)==0x800f||(CODE>>16)==0x8034||(CODE>>16)==0x8046,^105m)+{MCE=1}[CODE:0..0xffffffff,T@:0..1=0]
info: carrier: 36000Hz
info: rawir: +2664 -888 +444 -444 +444 -444 +444 -888 +444 -888 +1332 -888 +444 -444 +444 -444 +444 -444 +444 -444 +444 -444 +444 -444 +444 -444 +444 -444 +444 -444 +444 -444 +888 -444 +444 -444 +444 -444 +444 -888 +444 -444 +444 -444 +444 -444 +444 -444 +888 -888 +444 -444 +444 -444 +444 -444 +444 -444 +444 -444 +888 -888 +888 -444 +444 -68148
"#
Expand Down

0 comments on commit 809a378

Please sign in to comment.