From 1631dd0964ec6e03004ef9c42a7c630f881cbb4f Mon Sep 17 00:00:00 2001 From: Sean Young Date: Thu, 23 May 2024 11:27:19 +0100 Subject: [PATCH] cir decode should try all protocols if none are specified Signed-off-by: Sean Young --- TODO | 1 - cir/src/bin/cir.rs | 4 ++-- cir/src/bin/commands/decode.rs | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index 5ab8601..b6cf185 100644 --- a/TODO +++ b/TODO @@ -10,7 +10,6 @@ Necessary: correct protocol numbers Nice to have: -- cir decode irp should try all protocols if nothing specified - pcmak leading gap not decoded - encoding toggle_bit_mask not used when popcount > 1 - compare against kernel encoder/decoder diff --git a/cir/src/bin/cir.rs b/cir/src/bin/cir.rs index ae57b3b..deed769 100644 --- a/cir/src/bin/cir.rs +++ b/cir/src/bin/cir.rs @@ -90,11 +90,11 @@ struct Decode { rawir: Vec, /// IRP Notation - #[arg(long = "irp", short = 'i', required_unless_present = "keymap")] + #[arg(long = "irp", short = 'i')] irp: Vec, /// Keymap or lircd.conf file - #[arg(long = "keymap", short = 'k', required_unless_present = "irp")] + #[arg(long = "keymap", short = 'k')] keymap: Vec, #[clap(flatten)] diff --git a/cir/src/bin/commands/decode.rs b/cir/src/bin/commands/decode.rs index 7e2dbd8..ef26677 100644 --- a/cir/src/bin/commands/decode.rs +++ b/cir/src/bin/commands/decode.rs @@ -70,6 +70,34 @@ pub fn decode(global: &crate::App, decode: &crate::Decode) { } } + if decode.irp.is_empty() && decode.keymap.is_empty() { + match get_irp_protocols(&global.irp_protocols) { + Ok(res) => { + irp_protocols_xml = res; + } + Err(e) => { + log::error!("{}: {e}", &global.irp_protocols.display()); + std::process::exit(2); + } + } + + for protocol in irp_protocols_xml.iter().filter(|e| { + e.decodable && e.irp != "{38.4k,msb,564}<1,-1|1,-3>(16,-8,data:length,-50m) " + }) { + log::debug!("decoding IRP: {} {}", protocol.name, protocol.irp); + + let irp = match Irp::parse(&protocol.irp) { + Ok(m) => m, + Err(s) => { + eprintln!("unable to parse irp ‘{}’: {s}", protocol.irp); + std::process::exit(2); + } + }; + + irps.push((&protocol.name, &protocol.irp, irp)); + } + } + let input_on_cli = !decode.file.is_empty() || !decode.rawir.is_empty(); #[cfg(target_os = "linux")]