pub mod ap;
pub mod hash_table;
pub mod jt72;
#[cfg(feature = "packet-bytes")]
pub mod packet_bytes;
pub mod pipeline_ap;
#[cfg(feature = "q65")]
pub mod q65;
pub mod wsjt77;
pub mod wspr;
pub use ap::ApHint;
pub use hash_table::CallsignHashTable;
pub use jt72::{Jt72Codec, Jt72Message};
#[cfg(feature = "packet-bytes")]
pub use packet_bytes::PacketBytesMessage;
#[cfg(feature = "q65")]
pub use q65::Q65Message;
pub use wspr::{Wspr50Message, WsprMessage};
use crate::core::{DecodeContext, MessageCodec, MessageFields};
#[derive(Copy, Clone, Debug, Default)]
pub struct Wsjt77Message;
impl MessageCodec for Wsjt77Message {
type Unpacked = String;
const PAYLOAD_BITS: u32 = 77;
const CRC_BITS: u32 = 14;
fn pack(&self, fields: &MessageFields) -> Option<Vec<u8>> {
if let Some(txt) = &fields.free_text {
return wsjt77::pack77_free_text(txt).map(|a| a.to_vec());
}
let call1 = fields.call1.as_deref()?;
let call2 = fields.call2.as_deref()?;
let report = if let Some(g) = &fields.grid {
g.clone()
} else if let Some(r) = fields.report {
if r >= 0 {
format!("+{:02}", r)
} else {
format!("{:03}", r)
}
} else {
return None;
};
wsjt77::pack77(call1, call2, &report).map(|a| a.to_vec())
}
fn unpack(&self, payload: &[u8], ctx: &DecodeContext) -> Option<Self::Unpacked> {
if payload.len() != 77 {
return None;
}
let mut buf = [0u8; 77];
buf.copy_from_slice(payload);
if let Some(any) = ctx.callsign_hash_table.as_ref()
&& let Some(ht) = any.downcast_ref::<CallsignHashTable>()
{
return wsjt77::unpack77_with_hash(&buf, ht);
}
wsjt77::unpack77(&buf)
}
fn verify_info(info: &[u8]) -> bool {
match info.len() {
91 => crate::fec::ldpc::check_crc14(info),
101 => crate::fec::ldpc240_101::check_crc24(info),
_ => false,
}
}
}