[fix](trx-ftx): clear decoder warnings

Quiet compiler and clippy warnings in the translated decoder modules.

Co-authored-by: OpenAI Codex <codex@openai.com>
Signed-off-by: Stan Grams <sjg@haxx.space>
This commit is contained in:
2026-03-18 22:34:55 +01:00
parent 7cc8490024
commit 2609ce668a
11 changed files with 36 additions and 42 deletions
+1 -3
View File
@@ -37,9 +37,7 @@ pub fn ftx_extract_crc(a91: &[u8]) -> u16 {
/// `payload` contains 77 bits of payload data, `a91` receives 91 bits (payload + CRC).
pub fn ftx_add_crc(payload: &[u8], a91: &mut [u8]) {
// Copy 77 bits of payload data
for i in 0..10 {
a91[i] = payload[i];
}
a91[..10].copy_from_slice(&payload[..10]);
// Clear 3 bits after the payload to make 82 bits
a91[9] &= 0xF8;
+2 -2
View File
@@ -252,7 +252,7 @@ pub fn ftx_find_candidates(wf: &Waterfall, max_candidates: usize, min_score: i32
ft8_sync_score(wf, &cand)
};
if score >= min_score as i32 {
if score >= min_score {
if heap_size == max_candidates && score > heap[0].score as i32 {
heap_size -= 1;
heap[0] = heap[heap_size];
@@ -469,7 +469,7 @@ fn ftx_normalize_logl(log174: &mut [f32; FTX_LDPC_N]) {
/// Pack bits into bytes (MSB first).
pub fn pack_bits(bit_array: &[u8], num_bits: usize, packed: &mut [u8]) {
let num_bytes = (num_bits + 7) / 8;
let num_bytes = num_bits.div_ceil(8);
for b in packed[..num_bytes].iter_mut() { *b = 0; }
let mut mask: u8 = 0x80;
let mut byte_idx = 0;
+1 -1
View File
@@ -47,7 +47,7 @@ fn encode174(message: &[u8], codeword: &mut [u8]) {
nsum ^= parity8(message[j] & FTX_LDPC_GENERATOR[i][j]);
}
if nsum % 2 != 0 {
if !nsum.is_multiple_of(2) {
codeword[col_idx] |= col_mask;
}
@@ -266,10 +266,6 @@ mod tests {
#[test]
fn normalize_metric_nonzero() {
let mut m: Vec<f32> = (0..100).map(|i| (i as f32 - 50.0) * 0.1).collect();
let orig_variance: f32 = {
let mean: f32 = m.iter().sum::<f32>() / m.len() as f32;
m.iter().map(|&v| (v - mean) * (v - mean)).sum::<f32>() / m.len() as f32
};
normalize_metric(&mut m);
// After normalization, standard deviation should be ~1.0
let mean: f32 = m.iter().sum::<f32>() / m.len() as f32;
+4 -7
View File
@@ -296,7 +296,7 @@ impl Ft2Pipeline {
};
let freq_hz = (bin as f32 + delta) * df + ft2_frequency_offset_hz();
if freq_hz < 200.0 || freq_hz > 4910.0 {
if !(200.0..=4910.0).contains(&freq_hz) {
bin += 1;
continue;
}
@@ -368,7 +368,7 @@ impl Ft2Pipeline {
// Fine refinement
for idf in (best_idf - 4)..=(best_idf + 4) {
if idf < FT2_SYNC_TWEAK_MIN || idf > FT2_SYNC_TWEAK_MAX {
if !(FT2_SYNC_TWEAK_MIN..=FT2_SYNC_TWEAK_MAX).contains(&idf) {
continue;
}
for start in (best_start - 5)..=(best_start + 5) {
@@ -427,7 +427,7 @@ impl Ft2Pipeline {
let mut best_idf = hit.idf;
for idf in (hit.idf - 4)..=(hit.idf + 4) {
if idf < FT2_SYNC_TWEAK_MIN || idf > FT2_SYNC_TWEAK_MAX {
if !(FT2_SYNC_TWEAK_MIN..=FT2_SYNC_TWEAK_MAX).contains(&idf) {
continue;
}
for start in (hit.start - 5)..=(hit.start + 5) {
@@ -463,10 +463,7 @@ impl Ft2Pipeline {
extract_signal_region(&cb[..produced2], best_start, &mut signal);
// Extract bit metrics
let bitmetrics = match bitmetrics::extract_bitmetrics_raw(&signal) {
Some(bm) => bm,
None => return None,
};
let bitmetrics = bitmetrics::extract_bitmetrics_raw(&signal)?;
// Sync quality check using known Costas bit patterns
let sync_bits_a: [u8; 8] = [0, 0, 0, 1, 1, 0, 1, 1];
+2 -4
View File
@@ -69,7 +69,7 @@ fn platanh(x: f32) -> f32 {
/// Pack bit array into bytes (MSB first).
fn pack_bits91(bit_array: &[u8], num_bits: usize, packed: &mut [u8]) {
let num_bytes = (num_bits + 7) / 8;
let num_bytes = num_bits.div_ceil(8);
for b in packed[..num_bytes].iter_mut() {
*b = 0;
}
@@ -364,9 +364,7 @@ pub fn osd174_91(
// Swap columns id and col
if col != id {
for row in 0..k {
let a = genmrb[row * n + id];
genmrb[row * n + id] = genmrb[row * n + col];
genmrb[row * n + col] = a;
genmrb.swap(row * n + id, row * n + col);
}
indices.swap(id, col);
}
+1 -1
View File
@@ -152,7 +152,7 @@ pub fn refine_sync(
let mut best_idf = center_idf;
for idf in (center_idf - idf_range)..=(center_idf + idf_range) {
if idf < FT2_SYNC_TWEAK_MIN || idf > FT2_SYNC_TWEAK_MAX {
if !(FT2_SYNC_TWEAK_MIN..=FT2_SYNC_TWEAK_MAX).contains(&idf) {
continue;
}
for start in (center_start - start_range)..=(center_start + start_range) {
+11
View File
@@ -6,12 +6,23 @@ pub mod protocol;
pub mod constants;
pub mod crc;
pub mod text;
#[allow(clippy::manual_memcpy, clippy::needless_range_loop)]
pub mod ldpc;
#[allow(clippy::needless_range_loop)]
pub mod encode;
pub mod callsign_hash;
#[allow(clippy::explicit_counter_loop, clippy::needless_range_loop)]
pub mod message;
#[allow(dead_code)]
pub mod monitor;
#[allow(dead_code, clippy::needless_range_loop)]
pub mod decode;
#[allow(
dead_code,
clippy::manual_memcpy,
clippy::needless_range_loop,
clippy::too_many_arguments
)]
pub mod ft2;
mod decoder;
+9 -15
View File
@@ -179,18 +179,13 @@ fn is_space(c: u8) -> bool {
fn copy_token(input: &str) -> (&str, String) {
let input = input.trim_start();
let end = input
.find(|c: char| c == ' ')
.find(' ')
.unwrap_or(input.len());
let token = &input[..end];
let rest = &input[end..].trim_start();
(rest, token.to_string())
}
/// Trim leading and trailing whitespace.
fn trim(s: &str) -> &str {
s.trim()
}
/// Trim leading occurrences of a specific character.
fn trim_front(s: &str, c: char) -> &str {
s.trim_start_matches(c)
@@ -405,7 +400,7 @@ fn pack28(
return Some(((NTOKENS + MAX22) as i32 + n28, ip));
}
if length >= 3 && length <= 11 {
if (3..=11).contains(&length) {
// Non-standard callsign: compute 22-bit hash
let (n22, _, _) = save_callsign(hash_table, callsign)?;
ip = 0;
@@ -616,11 +611,13 @@ fn packgrid(grid4: &str) -> u16 {
if bytes[0] == b'R' {
let dd = dd_to_int(&grid4[1..]);
let irpt = (35 + dd) as u16;
return (MAXGRID4 + irpt) | 0x8000; // ir = 1
// ir = 1
(MAXGRID4 + irpt) | 0x8000
} else {
let dd = dd_to_int(grid4);
let irpt = (35 + dd) as u16;
return MAXGRID4 + irpt; // ir = 0
// ir = 0
MAXGRID4 + irpt
}
}
@@ -688,9 +685,6 @@ pub fn ftx_message_encode(
message_text: &str,
) -> FtxMessageRc {
let mut call_to: String;
let call_de: String;
let extra: String;
let mut parse_pos = message_text;
let is_cq = starts_with(message_text, "CQ ");
@@ -715,11 +709,11 @@ pub fn ftx_message_encode(
}
let (rest, token) = copy_token(parse_pos);
call_de = token;
let call_de: String = token;
parse_pos = rest;
let (rest, token) = copy_token(parse_pos);
extra = token;
let extra: String = token;
parse_pos = rest;
// Check token lengths
@@ -1490,7 +1484,7 @@ mod tests {
// i3 is in bits 74..76: payload[9] bits 5..3
// For i3=0, n3=5 (binary 101): bit2=1, bit1=0, bit0=1
msg.payload[8] = (msg.payload[8] & 0xFE) | 1; // n3 bit2 = 1
msg.payload[9] = (0b01 << 6); // n3 bits 1..0 = 01, i3 = 0
msg.payload[9] = 0b01 << 6; // n3 bits 1..0 = 01, i3 = 0
assert_eq!(msg.get_type(), FtxMessageType::Telemetry);
+2 -2
View File
@@ -104,8 +104,8 @@ pub const FT2_SYNC_OFFSET: usize = FT4_SYNC_OFFSET;
pub const FTX_LDPC_N: usize = 174;
pub const FTX_LDPC_K: usize = 91;
pub const FTX_LDPC_M: usize = 83;
pub const FTX_LDPC_N_BYTES: usize = (FTX_LDPC_N + 7) / 8;
pub const FTX_LDPC_K_BYTES: usize = (FTX_LDPC_K + 7) / 8;
pub const FTX_LDPC_N_BYTES: usize = FTX_LDPC_N.div_ceil(8);
pub const FTX_LDPC_K_BYTES: usize = FTX_LDPC_K.div_ceil(8);
// CRC parameters
pub const FT8_CRC_POLYNOMIAL: u16 = 0x2757;
+3 -3
View File
@@ -92,7 +92,7 @@ pub fn nchar(c: char, table: CharTable) -> Option<i32> {
// Digits
if table != CharTable::LettersSpace {
if c >= '0' && c <= '9' {
if c.is_ascii_digit() {
return Some(n + (c as i32 - '0' as i32));
}
n += 10;
@@ -100,7 +100,7 @@ pub fn nchar(c: char, table: CharTable) -> Option<i32> {
// Letters
if table != CharTable::Numeric {
if c >= 'A' && c <= 'Z' {
if c.is_ascii_uppercase() {
return Some(n + (c as i32 - 'A' as i32));
}
n += 26;
@@ -132,7 +132,7 @@ pub fn nchar(c: char, table: CharTable) -> Option<i32> {
/// Convert a character to uppercase ASCII. Non-letter characters are returned
/// unchanged.
pub fn to_upper(c: char) -> char {
if c >= 'a' && c <= 'z' {
if c.is_ascii_lowercase() {
char::from(c as u8 - b'a' + b'A')
} else {
c