Skip to content

Commit

Permalink
remove printlns for logging macros and update the logging library
Browse files Browse the repository at this point in the history
  • Loading branch information
fredclausen committed Feb 3, 2024
1 parent 42501d9 commit 46566fa
Show file tree
Hide file tree
Showing 17 changed files with 245 additions and 84 deletions.
103 changes: 78 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
52 changes: 32 additions & 20 deletions src/decoders/helpers/cpr_calculators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -611,6 +613,7 @@ mod tests {

#[test]
fn calculate_surface_position() {
"debug".enable_logging();
let even = Position {
latitude: 115609.0,
longitude: 116941.0,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -733,6 +739,7 @@ mod tests {

#[test]
fn decode_from_raw_surface_position() {
"debug".enable_logging();
let message = "8CAAC4BB401C0175F7E88A134707";

// DF: 10001 (17/ADSB)
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand All @@ -796,14 +803,15 @@ mod tests {
}
_ => {
// return an error
println!("Not a surface position");
error!("Not a surface position");
}
}
}
}

#[test]
fn calculate_local_unambiguous() {
"debug".enable_logging();
let aircraft_frame = Position {
latitude: 93000.0,
longitude: 51372.0,
Expand All @@ -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,
Expand All @@ -831,6 +839,7 @@ mod tests {

#[test]
fn cpr_calculate_position() {
"debug".enable_logging();
let odd = Position {
latitude: 74158.0,
longitude: 50194.0,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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.
Expand All @@ -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,
Expand Down
Loading

0 comments on commit 46566fa

Please sign in to comment.