Skip to content

Commit

Permalink
clippy pedantic
Browse files Browse the repository at this point in the history
  • Loading branch information
fredclausen committed Feb 3, 2024
1 parent a66dd97 commit 49a0922
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 55 deletions.
2 changes: 2 additions & 0 deletions src/decoders/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ impl JSONMessage {
self.pretty_print_with_options()
}

// FIXME: Can/should this be refactored in to less lines?
#[allow(clippy::too_many_lines)]
fn pretty_print_with_options(&self) -> String {
// Go through each field and print it out
let mut output: String = String::new();
Expand Down
165 changes: 113 additions & 52 deletions src/decoders/raw_types/me.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use super::{
altitude::Altitude,
autopilot_modes::{AltitudeHold, ApproachMode, AutopilotEngaged, VNAVEngaged, LNAV, TCAS},
capability::Capability,
emergencystate::EmergencyState,
heading::SelectedHeadingStatus,
icao::ICAO,
identification::Identification,
Expand Down Expand Up @@ -74,6 +75,8 @@ pub enum ME {

impl ME {
/// `to_string` with DF.id() input
// FIXME: Can/should this be refactored in to less lines?
#[allow(clippy::too_many_lines)]
pub(crate) fn to_string(
&self,
icao: ICAO,
Expand Down Expand Up @@ -200,89 +203,147 @@ impl ME {
squawk,
..
}) => {
writeln!(
f,
" Extended Squitter{transponder}Emergency/priority status",
print_aircraft_status(
&mut f,
transponder,
icao,
capability,
address_type,
*emergency_state,
*squawk,
)?;
writeln!(f, " Address: {icao} {address_type}")?;
writeln!(f, " Air/Ground: {capability}")?;
writeln!(f, " Squawk: {squawk:02X?}")?;
writeln!(f, " Emergency/priority: {emergency_state}")?;
}
ME::TargetStateAndStatusInformation(target_info) => {
writeln!(
f,
" Extended Squitter{transponder}Target state and status (V2)",
print_target_state_and_status_information(
&mut f,
transponder,
icao,
capability,
address_type,
target_info,
)?;
writeln!(f, " Address: {icao} {address_type}")?;
writeln!(f, " Air/Ground: {capability}")?;
writeln!(f, " Target State and Status:")?;
writeln!(f, " Target altitude: MCP, {} ft", target_info.altitude)?;
writeln!(f, " Altimeter setting: {} millibars", target_info.qnh)?;
if target_info.is_heading == SelectedHeadingStatus::Valid {
writeln!(f, " Target heading: {}", target_info.heading)?;
}
if target_info.tcas == TCAS::Engaged {
write!(f, " ACAS: operational ")?;
if target_info.autopilot == AutopilotEngaged::Engaged {
write!(f, "autopilot ")?;
}
if target_info.vnac == VNAVEngaged::Engaged {
write!(f, "vnav ")?;
}
if target_info.alt_hold == AltitudeHold::Engaged {
write!(f, "altitude-hold ")?;
}
if target_info.approach == ApproachMode::Engaged {
write!(f, " approach")?;
}
if target_info.lnav == LNAV::Engaged {
write!(f, " lnav")?;
}
writeln!(f)?;
} else {
writeln!(f, " ACAS: NOT operational")?;
}
writeln!(f, " NACp: {}", target_info.nacp)?;
writeln!(f, " NICbaro: {}", target_info.nicbaro)?;
writeln!(f, " SIL: {} (per sample)", target_info.sil)?;
writeln!(f, " QNH: {} millibars", target_info.qnh)?;
}
ME::AircraftOperationalCoordination(_) => {
writeln!(
f,
" Extended Squitter{transponder}Aircraft Operational Coordination",
print_aircraft_operational_coordination_message(
&mut f,
transponder,
icao,
address_type,
)?;
writeln!(f, " Address: {icao} {address_type}")?;
}
ME::AircraftOperationStatus(OperationStatus::Airborne(opstatus_airborne)) => {
let _ = print_operation_status_airborne(
print_operation_status_airborne(
&mut f,
transponder,
icao,
capability,
address_type,
opstatus_airborne,
);
)?;
}
ME::AircraftOperationStatus(OperationStatus::Surface(opstatus_surface)) => {
let _ = print_operation_status_surface(
print_operation_status_surface(
&mut f,
transponder,
icao,
capability,
address_type,
opstatus_surface,
);
)?;
}
ME::AircraftOperationStatus(OperationStatus::Reserved(..)) => {
let _ = print_operation_status_reserved(&mut f, transponder, icao, address_type);
print_operation_status_reserved(&mut f, transponder, icao, address_type)?;
}
}
Ok(f)
}
}

fn print_aircraft_status(
f: &mut String,
transponder: &str,
icao: ICAO,
capability: Capability,
address_type: &str,
emergency_state: EmergencyState,
squawk: u32,
) -> Result<(), Error> {
writeln!(
f,
" Extended Squitter{transponder}Emergency/priority status",
)?;
writeln!(f, " Address: {icao} {address_type}")?;
writeln!(f, " Air/Ground: {capability}")?;
writeln!(f, " Squawk: {squawk:02X?}")?;
writeln!(f, " Emergency/priority: {emergency_state}")?;

Ok(())
}

fn print_target_state_and_status_information(
f: &mut String,
transponder: &str,
icao: ICAO,
capability: Capability,
address_type: &str,
target_info: &TargetStateAndStatusInformation,
) -> Result<(), Error> {
writeln!(
f,
" Extended Squitter{transponder}Target state and status (V2)",
)?;
writeln!(f, " Address: {icao} {address_type}")?;
writeln!(f, " Air/Ground: {capability}")?;
writeln!(f, " Target State and Status:")?;
writeln!(f, " Target altitude: MCP, {} ft", target_info.altitude)?;
writeln!(f, " Altimeter setting: {} millibars", target_info.qnh)?;
if target_info.is_heading == SelectedHeadingStatus::Valid {
writeln!(f, " Target heading: {}", target_info.heading)?;
}
if target_info.tcas == TCAS::Engaged {
write!(f, " ACAS: operational ")?;
if target_info.autopilot == AutopilotEngaged::Engaged {
write!(f, "autopilot ")?;
}
if target_info.vnac == VNAVEngaged::Engaged {
write!(f, "vnav ")?;
}
if target_info.alt_hold == AltitudeHold::Engaged {
write!(f, "altitude-hold ")?;
}
if target_info.approach == ApproachMode::Engaged {
write!(f, " approach")?;
}
if target_info.lnav == LNAV::Engaged {
write!(f, " lnav")?;
}
writeln!(f)?;
} else {
writeln!(f, " ACAS: NOT operational")?;
}
writeln!(f, " NACp: {}", target_info.nacp)?;
writeln!(f, " NICbaro: {}", target_info.nicbaro)?;
writeln!(f, " SIL: {} (per sample)", target_info.sil)?;
writeln!(f, " QNH: {} millibars", target_info.qnh)?;

Ok(())
}

fn print_aircraft_operational_coordination_message(
f: &mut String,
transponder: &str,
icao: ICAO,
address_type: &str,
) -> Result<(), Error> {
writeln!(
f,
" Extended Squitter{transponder}Aircraft Operational Coordination",
)?;
writeln!(f, " Address: {icao} {address_type}")?;

Ok(())
}

fn print_operation_status_airborne(
f: &mut String,
transponder: &str,
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/encode_adsb_beast_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ enum FrameType {
/// Returns a vector of bytes, with each element of the array being a frame that can be passed in to the ADSB Beast parser.

#[must_use]
// FIXME: Can/should this be refactored in to less lines?
#[allow(clippy::too_many_lines)]
pub fn format_adsb_beast_frames_from_bytes(bytes: &[u8]) -> ADSBBeastFrames {
let mut formatted_frames: Vec<Vec<u8>> = Vec::new();
let mut leftbytes: Vec<u8> = Vec::new();
Expand Down
7 changes: 4 additions & 3 deletions src/state_machine/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,10 @@ impl Machine {
}

pub async fn print_airplane_by_hex(&self, transponder_hex: &str) {
match self.get_airplane_by_hex(transponder_hex).await {
Some(airplane) => info!("{airplane}"),
None => error!("No airplane found with transponder hex {transponder_hex}"),
if let Some(airplane) = self.get_airplane_by_hex(transponder_hex).await {
info!("{airplane}");
} else {
error!("No airplane found with transponder hex {transponder_hex}");
}
}

Expand Down

0 comments on commit 49a0922

Please sign in to comment.