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 rate: String,
34
35 #[arg(long)]
37 block_size: usize,
38
39 #[arg(long)]
41 girth: bool,
42}
43
44impl Args {
45 fn code(&self) -> Result<AR4JACode> {
46 let rate = match &*self.rate {
47 "1/2" => AR4JARate::R1_2,
48 "2/3" => AR4JARate::R2_3,
49 "4/5" => AR4JARate::R4_5,
50 r => return Err(format!("Invalid code rate {}", r)),
51 };
52 let info_size = match self.block_size {
53 1024 => AR4JAInfoSize::K1024,
54 4096 => AR4JAInfoSize::K4096,
55 16384 => AR4JAInfoSize::K16384,
56 s => return Err(format!("Invalid information block size k = {}", s)),
57 };
58 Ok(AR4JACode::new(rate, info_size))
59 }
60}
61
62impl Run for Args {
63 fn run(&self) -> std::result::Result<(), Box<dyn std::error::Error>> {
64 let h = self.code()?.h();
65 if self.girth {
66 if let Some(g) = h.girth() {
67 println!("Code girth = {}", g);
68 } else {
69 println!("Code girth is infinite");
70 }
71 } else {
72 print!("{}", h.alist());
73 }
74 Ok(())
75 }
76}