From 46566fa0f39943f6c8fe459ab3fbb6763ea555c8 Mon Sep 17 00:00:00 2001 From: Fred Clausen <43556888+fredclausen@users.noreply.github.com> Date: Sat, 3 Feb 2024 07:55:55 -0700 Subject: [PATCH] remove printlns for logging macros and update the logging library --- Cargo.lock | 103 +++++++++++++----- Cargo.toml | 2 +- src/decoders/helpers/cpr_calculators.rs | 52 +++++---- src/decoders/json.rs | 17 ++- .../json_types/geometricverticalaccuracy.rs | 16 ++- src/decoders/raw.rs | 6 +- src/decoders/raw_types/airbornevelocity.rs | 6 +- src/decoders/raw_types/aircraftstatus.rs | 6 +- src/decoders/raw_types/altitude.rs | 6 +- src/decoders/raw_types/identification.rs | 6 +- src/decoders/raw_types/me.rs | 30 ++++- src/decoders/raw_types/noposition.rs | 14 ++- src/decoders/raw_types/operationstatus.rs | 10 +- .../targetstateandstatusinformation.rs | 6 +- src/helpers/encode_adsb_beast_input.rs | 24 +++- src/lib.rs | 14 ++- src/state_machine/state.rs | 11 +- 17 files changed, 245 insertions(+), 84 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dcf4501..f69cc7a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -41,6 +41,54 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2faccea4cc4ab4a667ce676a30e8ec13922a692c99bb8f5b11f1502c72e04220" + +[[package]] +name = "anstyle-parse" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + [[package]] name = "async-stream" version = "0.3.5" @@ -187,6 +235,12 @@ dependencies = [ "windows-targets 0.52.0", ] +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "cookie" version = "0.18.0" @@ -362,17 +416,27 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "env_filter" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +dependencies = [ + "log", + "regex", +] + [[package]] name = "env_logger" -version = "0.10.2" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" +checksum = "05e7cf40684ae96ade6232ed84582f40ce0a66efcd43a5117aef610534f8e0b8" dependencies = [ + "anstream", + "anstyle", + "env_filter", "humantime", - "is-terminal", "log", - "regex", - "termcolor", ] [[package]] @@ -1293,10 +1357,11 @@ dependencies = [ [[package]] name = "sdre-rust-logging" -version = "0.2.2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1b575bfa4ea87f92fcd0ebe7685dab48e4625bcfab0e3ea8fe02360a0729e47" +checksum = "4f2f0ac448afaf15becb047d1a3e52c27ce671c7f7e794bc3b230bc33112d9a2" dependencies = [ + "anstyle", "chrono", "env_logger", "log", @@ -1490,15 +1555,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "termcolor" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" -dependencies = [ - "winapi-util", -] - [[package]] name = "thiserror" version = "1.0.56" @@ -1762,6 +1818,12 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "valuable" version = "0.1.0" @@ -1859,15 +1921,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[[package]] -name = "winapi-util" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" -dependencies = [ - "winapi", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index cebba3a..952fd0c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ serde = { version = "1.0.196", features = ["derive"] } serde_json = "1.0.113" log = "0.4.20" tokio = { version = "1.35.1", features = ["full"] } -sdre-rust-logging = "0.2.2" +sdre-rust-logging = "0.3.0" deku = { version = "0.16.0", optional = true } custom_error = "1.9.2" libm = { version = "0.2.8", optional = true } diff --git a/src/decoders/helpers/cpr_calculators.rs b/src/decoders/helpers/cpr_calculators.rs index 6647406..b2c3ca2 100644 --- a/src/decoders/helpers/cpr_calculators.rs +++ b/src/decoders/helpers/cpr_calculators.rs @@ -595,6 +595,8 @@ pub fn is_lat_lon_sane(position: Position) -> bool { #[cfg(test)] mod tests { + use sdre_rust_logging::SetupLogging; + use super::*; use crate::decoders::{ raw::NewAdsbRawMessage, @@ -611,6 +613,7 @@ mod tests { #[test] fn calculate_surface_position() { + "debug".enable_logging(); let even = Position { latitude: 115609.0, longitude: 116941.0, @@ -632,8 +635,8 @@ mod tests { .unwrap(); let expected_lat = 52.320607072215964; let expected_lon = 4.730472564697266; - println!("Calculated position: {:?}", position); - println!( + info!("Calculated position: {:?}", position); + info!( "Expected position: {:?}", Position { latitude: expected_lat, @@ -646,6 +649,7 @@ mod tests { #[test] fn calculate_surface_position_from_local() { + "debug".enable_logging(); let aircraft_frame = Position { latitude: 39195.0, longitude: 110320.0, @@ -662,8 +666,8 @@ mod tests { let position = get_position_from_locally_unabiguous_surface(&aircraft_frame, &local, CPRFormat::Odd); - println!("Calculated position: {:?}", position); - println!( + info!("Calculated position: {:?}", position); + info!( "Expected position: {:?}", Position { latitude: expected_lat, @@ -675,6 +679,7 @@ mod tests { #[test] fn calculate_surface_position_from_local_again() { + "debug".enable_logging(); let aircraft_frame = Position { latitude: 39199.0, longitude: 110269.0, @@ -691,8 +696,8 @@ mod tests { let position = get_position_from_locally_unabiguous_surface(&aircraft_frame, &local, CPRFormat::Odd); - println!("Calculated position: {:?}", position); - println!( + info!("Calculated position: {:?}", position); + info!( "Expected position: {:?}", Position { latitude: expected_lat, @@ -704,6 +709,7 @@ mod tests { #[test] fn calculate_surface_position_from_local_kabq() { + "debug".enable_logging(); let aircraft_frame = Position { latitude: 126995.0, longitude: 18218.0, @@ -720,8 +726,8 @@ mod tests { let position = get_position_from_locally_unabiguous_surface(&aircraft_frame, &local, CPRFormat::Odd); - println!("Calculated position: {:?}", position); - println!( + info!("Calculated position: {:?}", position); + info!( "Expected position: {:?}", Position { latitude: expected_lat, @@ -733,6 +739,7 @@ mod tests { #[test] fn decode_from_raw_surface_position() { + "debug".enable_logging(); let message = "8CAAC4BB401C0175F7E88A134707"; // DF: 10001 (17/ADSB) @@ -761,7 +768,7 @@ mod tests { match adsb.me { crate::decoders::raw_types::me::ME::SurfacePosition(surface_position) => { - println!("Surface position: {:?}", surface_position); + info!("Surface position: {:?}", surface_position); //assert_eq!(surface_position.mov.calculate(), Some(17.0)); //assert_eq!(surface_position.get_heading(), Some(14.1)); let local = Position { @@ -782,8 +789,8 @@ mod tests { &local, CPRFormat::Even, ); - println!("Calculated position: {:?}", position); - println!( + info!("Calculated position: {:?}", position); + info!( "Expected position: {:?}", Position { latitude: expected_lat, @@ -796,7 +803,7 @@ mod tests { } _ => { // return an error - println!("Not a surface position"); + error!("Not a surface position"); } } } @@ -804,6 +811,7 @@ mod tests { #[test] fn calculate_local_unambiguous() { + "debug".enable_logging(); let aircraft_frame = Position { latitude: 93000.0, longitude: 51372.0, @@ -817,8 +825,8 @@ mod tests { let expected_lon = 3.919_372_558_593_75; let position = get_position_from_locally_unabiguous_airborne(&aircraft_frame, &local, CPRFormat::Even); - println!("Calculated position: {:?}", position); - println!( + info!("Calculated position: {:?}", position); + info!( "Expected position: {:?}", Position { latitude: expected_lat, @@ -831,6 +839,7 @@ mod tests { #[test] fn cpr_calculate_position() { + "debug".enable_logging(); let odd = Position { latitude: 74158.0, longitude: 50194.0, @@ -845,8 +854,8 @@ mod tests { .unwrap(); let expected_lat = 52.257_202_148_437_5; let expected_lon = 3.919_372_558_593_75; - println!("Calculated position: {:?}", position); - println!( + info!("Calculated position: {:?}", position); + info!( "Expected position: {:?}", Position { latitude: expected_lat, @@ -859,6 +868,7 @@ mod tests { #[test] fn cpr_calculate_position_high_lat() { + "debug".enable_logging(); let even = Position { latitude: 108_011.0, longitude: 110_088.0, @@ -871,8 +881,8 @@ mod tests { get_position_from_even_odd_cpr_positions_airborne(&even, &odd, CPRFormat::Odd).unwrap(); let expected_lat = 88.917_474_261_784_96; let expected_lon = 101.011_047_363_281_25; - println!("Calculated position: {:?}", position); - println!( + info!("Calculated position: {:?}", position); + info!( "Expected position: {:?}", Position { latitude: expected_lat, @@ -885,6 +895,8 @@ mod tests { #[test] fn cpr_calculate_position_negative_m() { + "debug".enable_logging(); + /* * The `m` value can be negative. This test provides input * to test that code path. @@ -904,8 +916,8 @@ mod tests { get_position_from_even_odd_cpr_positions_airborne(&even, &odd, CPRFormat::Odd).unwrap(); let expected_lat = -35.840_195_478_019_1; let expected_lon = 150.283_852_435_172_9; - println!("Calculated position: {:?}", position); - println!( + info!("Calculated position: {:?}", position); + info!( "Expected position: {:?}", Position { latitude: expected_lat, diff --git a/src/decoders/json.rs b/src/decoders/json.rs index d49e518..3818cb3 100644 --- a/src/decoders/json.rs +++ b/src/decoders/json.rs @@ -778,6 +778,8 @@ pub struct JSONMessage { #[cfg(test)] mod tests { + use sdre_rust_logging::SetupLogging; + use super::*; use crate::DecodeMessage; use std::fs::{read_dir, File}; @@ -785,6 +787,7 @@ mod tests { #[test] fn decode_directly_as_json() { + "debug".enable_logging(); // open all json_*.json files in test data. convert to JSONMessage and then back to string let test_data: std::fs::ReadDir = read_dir("test_data").unwrap(); for entry in test_data { @@ -794,7 +797,7 @@ mod tests { let mut line_number: i32 = 1; let file_name: &str = path.file_name().unwrap().to_str().unwrap(); if file_name.starts_with("json_") && file_name.ends_with(".json") { - println!("Processing file: {file_name}"); + info!("Processing file: {file_name}"); let file: File = File::open(path).unwrap(); let reader: std::io::BufReader = std::io::BufReader::new(file); @@ -817,7 +820,7 @@ mod tests { ); let json_message = final_message_to_process.to_json(); - println!("JSONMessage: {:?}", json_message,); + info!("JSONMessage: {:?}", json_message,); assert!( json_message.is_ok(), @@ -825,7 +828,7 @@ mod tests { final_message_to_process ); } else { - println!("Skipping line {line_number}"); + info!("Skipping line {line_number}"); } line_number += 1; }); @@ -836,6 +839,7 @@ mod tests { #[test] fn decode_json_message_as_aircraft_json() { + "debug".enable_logging(); let test_data: std::fs::ReadDir = read_dir("test_data").unwrap(); for entry in test_data { let entry: std::fs::DirEntry = entry.unwrap(); @@ -844,7 +848,7 @@ mod tests { let mut line_number: i32 = 1; let file_name: &str = path.file_name().unwrap().to_str().unwrap(); if file_name.starts_with("json_") && file_name.ends_with(".json") { - println!("Processing file: {file_name}"); + info!("Processing file: {file_name}"); let file: File = File::open(path).unwrap(); let reader: std::io::BufReader = std::io::BufReader::new(file); @@ -866,7 +870,7 @@ mod tests { line_number ); let json_message = final_message_to_process.decode_message(); - println!("JSONMessage: {:?}", json_message,); + info!("JSONMessage: {:?}", json_message,); assert!( json_message.is_ok(), @@ -883,6 +887,7 @@ mod tests { #[test] fn decode_json_message_individually() { + "debug".enable_logging(); // open all json_*.json files in test data. convert to JSONMessage and then back to string let test_data: std::fs::ReadDir = read_dir("test_data").unwrap(); for entry in test_data { @@ -892,7 +897,7 @@ mod tests { let mut line_number: i32 = 1; let file_name: &str = path.file_name().unwrap().to_str().unwrap(); if file_name.starts_with("json_") && file_name.ends_with(".json") { - println!("Processing file: {file_name}"); + info!("Processing file: {file_name}"); let file: File = File::open(path).unwrap(); let reader: std::io::BufReader = std::io::BufReader::new(file); diff --git a/src/decoders/json_types/geometricverticalaccuracy.rs b/src/decoders/json_types/geometricverticalaccuracy.rs index 4216bd1..1c2a2f6 100644 --- a/src/decoders/json_types/geometricverticalaccuracy.rs +++ b/src/decoders/json_types/geometricverticalaccuracy.rs @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize}; use std::fmt; -#[derive(Serialize, Deserialize, Debug, Clone, Copy, Eq, PartialEq, PartialOrd)] +#[derive(Deserialize, Debug, Clone, Copy, Eq, PartialEq, PartialOrd)] #[serde(try_from = "u8")] pub enum GeometricVerticalAccuracy { UnknownOrGreaterThan150m, @@ -16,6 +16,20 @@ pub enum GeometricVerticalAccuracy { LessThanEqual10m, } +impl Serialize for GeometricVerticalAccuracy { + fn serialize(&self, serializer: S) -> Result + where + S: serde::ser::Serializer, + { + match self { + GeometricVerticalAccuracy::UnknownOrGreaterThan150m => serializer.serialize_u8(0), + GeometricVerticalAccuracy::LessThanEqual150m => serializer.serialize_u8(1), + GeometricVerticalAccuracy::LessThanEqual45m => serializer.serialize_u8(2), + GeometricVerticalAccuracy::LessThanEqual10m => serializer.serialize_u8(3), + } + } +} + impl From for GeometricVerticalAccuracy { fn from(value: u8) -> Self { match value { diff --git a/src/decoders/raw.rs b/src/decoders/raw.rs index f6d326d..e13a562 100644 --- a/src/decoders/raw.rs +++ b/src/decoders/raw.rs @@ -272,18 +272,20 @@ impl AdsbRawMessage { #[cfg(test)] mod tests { use super::*; + use sdre_rust_logging::SetupLogging; #[test] fn test_message_by_itself() { + "debug".enable_logging(); let input = "8DA0CA2DEA57F866C15C088DEF6F"; let result = input.to_adsb_raw(); - println!("Result: {:?}", result); + info!("Result: {:?}", result); assert!(result.is_ok(), "Failed to decode message: {:?}", result); let input = "8DAE54CAF8050002004AB867A40E"; let result = input.to_adsb_raw(); - println!("Result: {:?}", result); + info!("Result: {:?}", result); assert!(result.is_ok(), "Failed to decode message: {:?}", result); } } diff --git a/src/decoders/raw_types/airbornevelocity.rs b/src/decoders/raw_types/airbornevelocity.rs index e0b4233..3369fd9 100644 --- a/src/decoders/raw_types/airbornevelocity.rs +++ b/src/decoders/raw_types/airbornevelocity.rs @@ -102,6 +102,8 @@ impl AirborneVelocity { #[cfg(test)] mod tests { + use sdre_rust_logging::SetupLogging; + use super::*; use crate::decoders::{ raw::NewAdsbRawMessage, @@ -110,6 +112,8 @@ mod tests { #[test] fn test_airborne_velocity() { + "debug".enable_logging(); + let message = "8DC05BCF9909CF0DD00417286F1E"; let decoded = message.to_adsb_raw().unwrap(); @@ -132,7 +136,7 @@ mod tests { gnss_baro_diff: 550, }; - println!("Decoded Message: {:?}", &decoded); + info!("Decoded Message: {:?}", &decoded); if let DF::ADSB(adsb) = decoded.df { match adsb.me { diff --git a/src/decoders/raw_types/aircraftstatus.rs b/src/decoders/raw_types/aircraftstatus.rs index 435f34d..10f6f23 100644 --- a/src/decoders/raw_types/aircraftstatus.rs +++ b/src/decoders/raw_types/aircraftstatus.rs @@ -39,6 +39,8 @@ impl AircraftStatus { #[cfg(test)] pub mod test { + use sdre_rust_logging::SetupLogging; + use super::*; use crate::decoders::raw::NewAdsbRawMessage; use crate::decoders::raw_types::aircraftstatus::AircraftStatus; @@ -46,10 +48,12 @@ pub mod test { #[test] fn decode_aircraftstatus() { + "debug".enable_logging(); + let message = "8DAB44A7E10289000000008922C1"; let decoded = message.to_adsb_raw().unwrap(); - println!("{:?}", decoded); + info!("{:?}", decoded); let expected = AircraftStatus { sub_type: AircraftStatusType::EmergencyPriorityStatus, diff --git a/src/decoders/raw_types/altitude.rs b/src/decoders/raw_types/altitude.rs index 8c1c190..b95fedd 100644 --- a/src/decoders/raw_types/altitude.rs +++ b/src/decoders/raw_types/altitude.rs @@ -82,6 +82,8 @@ impl Altitude { #[cfg(test)] pub mod test { + use sdre_rust_logging::SetupLogging; + use super::*; use crate::decoders::raw::NewAdsbRawMessage; use crate::decoders::raw_types::df::DF; @@ -89,6 +91,8 @@ pub mod test { #[test] fn decode_altitude() { + "debug".enable_logging(); + let message = "8FA4955D597D8288F8C756559A37"; let decoded = message.to_adsb_raw().unwrap(); @@ -103,7 +107,7 @@ pub mod test { lon_cpr: 51030, }; - println!("Decoded Message: {:?}", &decoded); + info!("Decoded Message: {:?}", &decoded); if let DF::ADSB(adsb) = decoded.df { match adsb.me { diff --git a/src/decoders/raw_types/identification.rs b/src/decoders/raw_types/identification.rs index 39d2240..ffce83c 100644 --- a/src/decoders/raw_types/identification.rs +++ b/src/decoders/raw_types/identification.rs @@ -24,6 +24,8 @@ pub struct Identification { #[cfg(test)] pub mod test { + use sdre_rust_logging::SetupLogging; + use super::*; use crate::decoders::raw::NewAdsbRawMessage; use crate::decoders::raw_types::df::DF; @@ -31,10 +33,12 @@ pub mod test { #[test] fn decode_identification() { + "debug".enable_logging(); + let message = "8DA69B9C223B5CB5082820C97A87"; let decoded = message.to_adsb_raw().unwrap(); - println!("{:?}", decoded); + info!("{:?}", decoded); let expected = Identification { tc: TypeCoding::A, diff --git a/src/decoders/raw_types/me.rs b/src/decoders/raw_types/me.rs index a6cb5f0..bf50c7b 100644 --- a/src/decoders/raw_types/me.rs +++ b/src/decoders/raw_types/me.rs @@ -9,7 +9,21 @@ use serde::{Deserialize, Serialize}; use std::fmt::{Error, Write}; use super::{ - airbornevelocity::AirborneVelocity, airbornevelocitysubtype::AirborneVelocitySubType, aircraftstatus::AircraftStatus, altitude::Altitude, autopilot_modes::{AltitudeHold, ApproachMode, AutopilotEngaged, VNAVEngaged, LNAV, TCAS}, capability::Capability, heading::SelectedHeadingStatus, icao::ICAO, identification::Identification, noposition::NoPosition, operationstatus::OperationStatus, operationstatusairborne::OperationStatusAirborne, operationstatussurface::OperationStatusSurface, surfaceposition::SurfacePosition, targetstateandstatusinformation::TargetStateAndStatusInformation + airbornevelocity::AirborneVelocity, + airbornevelocitysubtype::AirborneVelocitySubType, + aircraftstatus::AircraftStatus, + altitude::Altitude, + autopilot_modes::{AltitudeHold, ApproachMode, AutopilotEngaged, VNAVEngaged, LNAV, TCAS}, + capability::Capability, + heading::SelectedHeadingStatus, + icao::ICAO, + identification::Identification, + noposition::NoPosition, + operationstatus::OperationStatus, + operationstatusairborne::OperationStatusAirborne, + operationstatussurface::OperationStatusSurface, + surfaceposition::SurfacePosition, + targetstateandstatusinformation::TargetStateAndStatusInformation, }; /// ADS-B Message, 5 first bits are known as Type Code (TC) /// @@ -242,7 +256,14 @@ impl ME { writeln!(f, " Address: {icao} {address_type}")?; } ME::AircraftOperationStatus(OperationStatus::Airborne(opstatus_airborne)) => { - let _ = print_operation_status_airborne(&mut f, transponder, icao, capability, address_type, opstatus_airborne); + let _ = print_operation_status_airborne( + &mut f, + transponder, + icao, + capability, + address_type, + opstatus_airborne, + ); } ME::AircraftOperationStatus(OperationStatus::Surface(opstatus_surface)) => { let _ = print_operation_status_surface( @@ -262,12 +283,13 @@ impl ME { } } -fn print_operation_status_airborne(f: &mut String, +fn print_operation_status_airborne( + f: &mut String, transponder: &str, icao: ICAO, capability: Capability, address_type: &str, - opstatus_airborne: &OperationStatusAirborne + opstatus_airborne: &OperationStatusAirborne, ) -> Result<(), Error> { writeln!( f, diff --git a/src/decoders/raw_types/noposition.rs b/src/decoders/raw_types/noposition.rs index 63033b7..4fb3a73 100644 --- a/src/decoders/raw_types/noposition.rs +++ b/src/decoders/raw_types/noposition.rs @@ -49,18 +49,22 @@ impl NoPosition { #[cfg(test)] mod tests { + use sdre_rust_logging::SetupLogging; + use super::*; use crate::decoders::raw::NewAdsbRawMessage; #[test] fn test_no_position_decoder() { + "debug".enable_logging(); + let message = "8DADC035002D8000000000B16E64"; let decoded = message.to_adsb_raw().unwrap(); let expected = NoPosition { st: 0, altitude: Some(8000), }; - println!("{:?}", decoded); + info!("{:?}", decoded); match decoded.df { crate::decoders::raw_types::df::DF::ADSB(adsb) => match adsb.me { crate::decoders::raw_types::me::ME::NoPosition(status) => { @@ -74,13 +78,15 @@ mod tests { #[test] fn test_no_position_alternate() { + "debug".enable_logging(); + let message = "8EADC035002D800000000059FDEC"; let decoded = message.to_adsb_raw().unwrap(); let expected = NoPosition { st: 0, altitude: Some(8000), }; - println!("{:?}", decoded); + info!("{:?}", decoded); match decoded.df { crate::decoders::raw_types::df::DF::ADSB(adsb) => match adsb.me { crate::decoders::raw_types::me::ME::NoPosition(status) => { @@ -94,13 +100,15 @@ mod tests { #[test] fn test_no_position_last() { + "debug".enable_logging(); + let message = "8EADC035002D7000000000B02845"; let decoded = message.to_adsb_raw().unwrap(); let expected = NoPosition { st: 0, altitude: Some(7975), }; - println!("{:?}", decoded); + info!("{:?}", decoded); match decoded.df { crate::decoders::raw_types::df::DF::ADSB(adsb) => match adsb.me { crate::decoders::raw_types::me::ME::NoPosition(status) => { diff --git a/src/decoders/raw_types/operationstatus.rs b/src/decoders/raw_types/operationstatus.rs index ac25d7c..83ae155 100644 --- a/src/decoders/raw_types/operationstatus.rs +++ b/src/decoders/raw_types/operationstatus.rs @@ -176,6 +176,8 @@ impl OperationStatus { #[cfg(test)] mod test { + use sdre_rust_logging::SetupLogging; + use super::*; use crate::decoders::common_types::sda::SystemDesignAssurance; use crate::decoders::raw::NewAdsbRawMessage; @@ -189,9 +191,11 @@ mod test { #[test] fn test_operation_status_airborne() { + "debug".enable_logging(); + let message = "8DABBD47F8230006004AB87B5E9E"; let decoded = message.to_adsb_raw().unwrap(); - println!("Decoded {:?}", decoded); + info!("Decoded {:?}", decoded); let expected = OperationStatus::Airborne(OperationStatusAirborne { capability_class: CapabilityClassAirborne { @@ -236,6 +240,8 @@ mod test { #[test] fn test_operational_status_surface() { + "debug".enable_logging(); + let message = "8CA231A6F9004402874A38F61073"; let decoded = message.to_adsb_raw().unwrap(); @@ -272,7 +278,7 @@ mod test { reserved1: 0, }); - println!("Decoded {:?}", decoded); + info!("Decoded {:?}", decoded); match decoded.df { DF::ADSB(adsb) => match adsb.me { diff --git a/src/decoders/raw_types/targetstateandstatusinformation.rs b/src/decoders/raw_types/targetstateandstatusinformation.rs index f6ecdaf..ba46760 100644 --- a/src/decoders/raw_types/targetstateandstatusinformation.rs +++ b/src/decoders/raw_types/targetstateandstatusinformation.rs @@ -69,6 +69,8 @@ impl TargetStateAndStatusInformation { #[cfg(test)] mod test { + use sdre_rust_logging::SetupLogging; + use crate::decoders::raw::NewAdsbRawMessage; use crate::decoders::raw_types::autopilot_modes::{LNAV, TCAS}; use crate::decoders::raw_types::df::DF; @@ -78,9 +80,11 @@ mod test { #[test] fn test_status_information() { + "debug".enable_logging(); + let message = "8DABEBE0EA36C866DD5C082732C5"; let decoded = message.to_adsb_raw().unwrap(); - println!("Decoded {:?}", decoded); + info!("Decoded {:?}", decoded); let expected = TargetStateAndStatusInformation { subtype: 1, diff --git a/src/helpers/encode_adsb_beast_input.rs b/src/helpers/encode_adsb_beast_input.rs index bb05568..7b195dd 100644 --- a/src/helpers/encode_adsb_beast_input.rs +++ b/src/helpers/encode_adsb_beast_input.rs @@ -258,10 +258,14 @@ pub fn format_adsb_beast_frames_from_bytes(bytes: &[u8]) -> ADSBBeastFrames { #[cfg(test)] mod tests { + use sdre_rust_logging::SetupLogging; + use super::*; #[test] fn test_adsb_beast_parsing_input() { + "debug".enable_logging(); + // there are 33 frames in this input. 5 of the are MODEAC frames, which we don't want to decode let raw_frames = [ 0x1a as u8, 0x31, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1a, 0x31, 0x0, 0x0, @@ -321,7 +325,7 @@ mod tests { let frames = format_adsb_beast_frames_from_bytes(&raw_frames); for frame in frames.frames.iter() { - println!("Frame: {:02X?}", frame); + info!("Frame: {:02X?}", frame); } assert!( frames.frames.len() == 38, @@ -349,6 +353,8 @@ mod tests { #[test] fn test_extra_bytes_in_input() { + "debug".enable_logging(); + // there are 33 frames in this input. 5 of the are MODEAC frames, which we don't want to decode let raw_frames = [ 0x1a as u8, 0x31, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1a, 0x31, 0x0, 0x0, @@ -408,7 +414,7 @@ mod tests { let frames = format_adsb_beast_frames_from_bytes(&raw_frames); for frame in frames.frames.iter() { - println!("Frame: {:02X?}", frame); + info!("Frame: {:02X?}", frame); } assert!( frames.frames.len() == 38, @@ -436,6 +442,8 @@ mod tests { #[test] fn test_extra_bytes_at_end_input() { + "debug".enable_logging(); + // there are 33 frames in this input. 5 of the are MODEAC frames, which we don't want to decode let raw_frames = [ 0x1a as u8, 0x31, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1a, 0x31, 0x0, 0x0, @@ -496,7 +504,7 @@ mod tests { let frames = format_adsb_beast_frames_from_bytes(&raw_frames); for frame in frames.frames.iter() { - println!("Frame: {:02X?}", frame); + info!("Frame: {:02X?}", frame); } assert!( frames.frames.len() == 38, @@ -524,6 +532,8 @@ mod tests { #[test] fn test_buffer_left_over_reassembly() { + "debug".enable_logging(); + let raw_frames = [ 0x1A as u8, 0x33, 0x01, 0x9B, 0x52, 0x68, 0xF7, 0xAE, 0x2F, 0x8D, 0xA6, 0x1F, 0x0E, 0x99, 0x15, 0x31, 0x19, 0xB0, 0x04, 0x13, 0x2C, 0xE9, 0xFC, 0x1A, 0x32, 0x01, 0x9B, @@ -577,10 +587,10 @@ mod tests { // grab the leftover bytes and prepend them to the next buffer let raw_frame = [frames.left_over, raw_frames.to_vec()].concat(); - println!("using this frame: {:02X?}", raw_frame); + info!("using this frame: {:02X?}", raw_frame); let frames = format_adsb_beast_frames_from_bytes(&raw_frame); for frame in frames.frames.iter() { - println!("Frame: {:02X?}", frame); + info!("Frame: {:02X?}", frame); } assert!( frames.frames.len() == 22, @@ -596,6 +606,8 @@ mod tests { #[test] fn test_double_ends_in_message_and_end_of_frame() { + "debug".enable_logging(); + let raw_frame = [ 0x1A as u8, 0x33, 0x01, 0xB5, 0xBF, 0x52, 0x0C, 0x77, 0x1D, 0x8D, 0xAB, 0x97, 0x40, 0x59, 0x2F, 0x16, 0x98, 0xB5, 0x94, 0x6E, 0xDE, 0x10, 0x8E, 0x1A, 0x33, 0x01, 0xB5, @@ -634,7 +646,7 @@ mod tests { let frames = format_adsb_beast_frames_from_bytes(&raw_frame); for frame in frames.frames.iter() { - println!("Frame: {:02X?}", frame); + info!("Frame: {:02X?}", frame); } assert!( diff --git a/src/lib.rs b/src/lib.rs index 3ea3685..13bfc78 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,11 @@ //! # Example //! //! ``` +//! use log::info; //! use sdre_rust_adsb_parser::DecodeMessage; +//! use sdre_rust_logging::SetupLogging; +//! +//! 3u8.enable_logging(); //! //! let message = "8EADC035002D7000000000B02845"; //! @@ -17,13 +21,13 @@ //! //! match decoded_message { //! sdre_rust_adsb_parser::ADSBMessage::JSONMessage(aircraft) => { -//! println!("ICAO: {}", aircraft.transponder_hex); -//! println!("Altitude: {:?} feet", aircraft.barometric_altitude); -//! println!("Latitude: {:?}", aircraft.latitude); -//! println!("Longitude: {:?}", aircraft.longitude); +//! info!("ICAO: {}", aircraft.transponder_hex); +//! info!("Altitude: {:?} feet", aircraft.barometric_altitude); +//! info!("Latitude: {:?}", aircraft.latitude); +//! info!("Longitude: {:?}", aircraft.longitude); //! } //! _ => { -//! println!("Invalid message type"); +//! info!("Invalid message type"); //! } //! } //! ``` diff --git a/src/state_machine/state.rs b/src/state_machine/state.rs index 121488f..b202c3f 100644 --- a/src/state_machine/state.rs +++ b/src/state_machine/state.rs @@ -11,9 +11,12 @@ /// use sdre_rust_adsb_parser::state_machine::state::MachineBuilder; /// use sdre_rust_adsb_parser::state_machine::state::ProcessMessageType; /// use sdre_rust_adsb_parser::decoders::helpers::cpr_calculators::Position; +/// use sdre_rust_logging::SetupLogging; +/// use log::info; /// use std::process::exit; /// /// async fn process_message() { +/// 3u8.enable_logging(); /// // Create a raw ADS-B message. Generally input will be from a receiver. /// let raw_message = "8D4840D6202CC371C32CE0576098".to_string(); /// // Create a new state machine with a timeout of 10 seconds for ADS-B messages @@ -26,7 +29,7 @@ /// let mut state_machine = match state_machine_builder.build() { /// Ok(state_machine) => state_machine, /// Err(e) => { -/// println!("Error building state machine: {}", e); +/// info!("Error building state machine: {}", e); /// exit(1); /// } /// }; @@ -239,8 +242,8 @@ impl Machine { pub async fn print_airplane_by_hex(&self, transponder_hex: &str) { match self.get_airplane_by_hex(transponder_hex).await { - Some(airplane) => println!("{airplane}"), - None => println!("No airplane found with transponder hex {transponder_hex}"), + Some(airplane) => info!("{airplane}"), + None => error!("No airplane found with transponder hex {transponder_hex}"), } } @@ -248,7 +251,7 @@ impl Machine { let airplanes = self.airplanes.lock().await; for (_, airplane) in airplanes.iter() { - println!("{airplane}"); + info!("{airplane}"); } }