use crate::cli::*;
use crate::codes::ccsds::{AR4JACode, AR4JAInfoSize, AR4JARate};
use clap::Parser;
type Error = String;
type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Parser)]
#[command(about = "Generates the alist of CCSDS LDPCs")]
pub struct Args {
#[arg(short, long)]
pub rate: String,
#[arg(long)]
pub block_size: usize,
#[arg(long)]
pub girth: bool,
}
impl Args {
fn code(&self) -> Result<AR4JACode> {
let rate = match &*self.rate {
"1/2" => AR4JARate::R1_2,
"2/3" => AR4JARate::R2_3,
"4/5" => AR4JARate::R4_5,
r => return Err(format!("Invalid code rate {}", r)),
};
let info_size = match self.block_size {
1024 => AR4JAInfoSize::K1024,
4096 => AR4JAInfoSize::K4096,
16384 => AR4JAInfoSize::K16384,
s => return Err(format!("Invalid information block size k = {}", s)),
};
Ok(AR4JACode::new(rate, info_size))
}
}
impl Run for Args {
fn run(&self) -> std::result::Result<(), Box<dyn std::error::Error>> {
let h = self.code()?.h();
if self.girth {
if let Some(g) = h.girth() {
println!("Code girth = {}", g);
} else {
println!("Code girth is infinite");
}
} else {
print!("{}", h.alist());
}
Ok(())
}
}