ldpc_toolbox/cli/
ccsds.rs1use crate::cli::*;
21use crate::codes::ccsds::{AR4JACode, AR4JAInfoSize, AR4JARate};
22use clap::Parser;
23
24type Error = String;
25type Result<T> = std::result::Result<T, Error>;
26
27#[derive(Debug, Parser)]
29#[command(about = "Generates the alist of CCSDS LDPCs")]
30pub struct Args {
31 #[arg(short, long)]
33 pub rate: String,
34 #[arg(long)]
36 pub block_size: usize,
37 #[arg(long)]
39 pub girth: bool,
40}
41
42impl Args {
43 fn code(&self) -> Result<AR4JACode> {
44 let rate = match &*self.rate {
45 "1/2" => AR4JARate::R1_2,
46 "2/3" => AR4JARate::R2_3,
47 "4/5" => AR4JARate::R4_5,
48 r => return Err(format!("Invalid code rate {}", r)),
49 };
50 let info_size = match self.block_size {
51 1024 => AR4JAInfoSize::K1024,
52 4096 => AR4JAInfoSize::K4096,
53 16384 => AR4JAInfoSize::K16384,
54 s => return Err(format!("Invalid information block size k = {}", s)),
55 };
56 Ok(AR4JACode::new(rate, info_size))
57 }
58}
59
60impl Run for Args {
61 fn run(&self) -> std::result::Result<(), Box<dyn std::error::Error>> {
62 let h = self.code()?.h();
63 if self.girth {
64 if let Some(g) = h.girth() {
65 println!("Code girth = {}", g);
66 } else {
67 println!("Code girth is infinite");
68 }
69 } else {
70 print!("{}", h.alist());
71 }
72 Ok(())
73 }
74}