Skip to content

Commit

Permalink
Report correct Altitude for Mode C message
Browse files Browse the repository at this point in the history
See rsadsb#13

Signed-off-by: wcampbell <wcampbell1995@gmail.com>
  • Loading branch information
wcampbell0x2a authored and wiseman committed Oct 26, 2021
1 parent bc1065a commit ac033c7
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix [#11](https://github.com/wcampbell0x2a/adsb_deku/issues/11) and [#12](https://github.com/wcampbell0x2a/adsb_deku/issues/12) - Add `ME::NoPosition` and `fmt::Display`
- Add `fmt::Display` for `ME::Reserved0`
- Add `fmt::Display` for `ME::Reserved1`
- Fix [#13](https://github.com/wcampbell0x2a/adsb_deku/issues/13) - Correct Altitude for Mode C Messages, thanks ([@wiseman](https://github.com/wiseman))

### Apps
- [radar] Enforce minimum constraint on size of tab text
Expand Down
23 changes: 4 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,10 @@ pub struct Altitude {
impl std::fmt::Display for Altitude {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, " Altitude: {} ft barometric", self.alt)?;
// TODO: fix me
writeln!(f, " CPR type: Airborne")?;
writeln!(f, " CPR odd flag: {}", self.odd_flag)?;
writeln!(f, " CPR latitude: ({})", self.lat_cpr)?;
writeln!(f, " CPR longitude: ({})", self.lon_cpr)?;
// TODO: fix me
//println!("{}", self.t);
Ok(())
}
}
Expand All @@ -450,20 +447,13 @@ impl Altitude {
let q = num & 0x10;

if q > 0 {
// regular
// TODO this is meters?
let n = ((num & 0x0fe0) >> 1) | (num & 0x000f);
let n = n * 25;
if n > 1000 {
Ok((rest, (n - 1000) as u32))
} else {
// TODO add error
Ok((rest, 0))
}
Ok((rest, (n - 1000) as u32))
} else {
// mode c?
// TODO this is feet
let n = ((num & 0x0fc0) << 1) | (num & 0x003f);
let mut n = ((num & 0x0fc0) << 1) | (num & 0x003f);
n = mode_ac::decode_id13_field(n);
n = mode_ac::mode_a_to_mode_c(n).unwrap();
Ok((rest, ((n as u32) * 100)))
}
}
Expand Down Expand Up @@ -648,11 +638,6 @@ mod mode_ac {
one_hundreds = 6 - one_hundreds;
}

// Check for invalid one_hundres
if one_hundreds < 13 {
return Err("Invalid one_hundred");
}

Ok((five_hundreds * 5) + one_hundreds - 13)
}
}
Expand Down
77 changes: 77 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,3 +759,80 @@ fn fix_issue_unknown() {
);
}

#[test]
fn fix_issue_13() {
// 1
let bytes = hex!("8dab92a2593e0664204c69d8fe84");
let frame = Frame::from_bytes((&bytes, 0)).unwrap().1;
let resulting_string = format!("{}", frame);
assert_eq!(
r#" Extended Squitter Airborne position (barometric altitude)
Address: ab92a2 (Mode S / ADS-B)
Air/Ground: airborne
Altitude: 10600 ft barometric
CPR type: Airborne
CPR odd flag: odd
CPR latitude: (78352)
CPR longitude: (19561)
"#,
resulting_string
);

// 2
let bytes = hex!("8dab92a299105e93001486608c6d");
let frame = Frame::from_bytes((&bytes, 0)).unwrap().1;
let resulting_string = format!("{}", frame);
assert_eq!(
r#" Extended Squitter Airborne velocity over ground, subsonic
Address: ab92a2 (Mode S / ADS-B)
Air/Ground: airborne
GNSS delta: -125 ft
Heading: 149
Speed: 177 kt groundspeed
Vertical rate: 256 ft/min barometric
"#,
resulting_string
);

// 3
let bytes = hex!("020007a0d08ff4");
let frame = Frame::from_bytes((&bytes, 0)).unwrap().1;
let resulting_string = format!("{}", frame);
assert_eq!(
r#" Short Air-Air Surveillance
ICAO Address: ab92a2 (Mode S / ADS-B)
Air/Ground: airborne?
Altitude: 10600 ft barometric
"#,
resulting_string
);

// 4
let bytes = hex!("5dab92a2b04912");
let frame = Frame::from_bytes((&bytes, 0)).unwrap().1;
let resulting_string = format!("{}", frame);
assert_eq!(
r#" All Call Reply
ICAO Address: ab92a2 (Mode S / ADS-B)
Air/Ground: airborne
"#,
resulting_string
);

// 4
let bytes = hex!("8dab92a2593e0664204c69d8fe84");
let frame = Frame::from_bytes((&bytes, 0)).unwrap().1;
let resulting_string = format!("{}", frame);
assert_eq!(
r#" Extended Squitter Airborne position (barometric altitude)
Address: ab92a2 (Mode S / ADS-B)
Air/Ground: airborne
Altitude: 10600 ft barometric
CPR type: Airborne
CPR odd flag: odd
CPR latitude: (78352)
CPR longitude: (19561)
"#,
resulting_string
);
}

0 comments on commit ac033c7

Please sign in to comment.