Skip to content

Commit

Permalink
Merge pull request #301 from rsadsb/add-tisb-position-tracking
Browse files Browse the repository at this point in the history
common: Add DF::TisB to update_position
  • Loading branch information
wcampbell0x2a authored Sep 2, 2024
2 parents 481b601 + 4ae2384 commit 6d56f46
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 36 deletions.
13 changes: 9 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ Libraries are released without a new release date within this changelog,
since this pertains to binary (package) releases.

## [Package Unreleased]
### radar / 1090
- Bump dependancy `ratatui` to `0.26.0```

## [2024-09-02]
### radar / 1090 v0.7.0
- Bump dependancy `ratatui` to `0.27.0```
- Bumped MSRV to `1.74.0`
### rsadsb_common
### rsadsb_common v0.7.0
- Rename `add_position` to `update_position`
- Add `DF::TisB` to update_position
- Bumped MSRV to `1.74.0`
### adsb_deku
### adsb_deku v0.7.1
- Fix cpr calculations by forcing mod operation to be positive
- Bumped MSRV to `1.74.0`

## [2023-11-22]
Expand Down
6 changes: 3 additions & 3 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 apps/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rsadsb_apps"
version = "0.6.3"
version = "0.7.0"
rust-version.workspace = true
license.workspace = true
edition.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion libadsb_deku/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description = "Decoder for ADS-B(Automatic Depedent Surveillance-Broadcast) - wr
repository = "https://github.com/wcampbel0x2a/adsb_deku"
keywords = ["deku", "adsb", "aerorust", "airplane", "radar"]
categories = ["aerospace::protocols", "parsing"]
version = "0.7.0"
version = "0.7.1"
rust-version.workspace = true
license.workspace = true
edition.workspace = true
Expand Down
22 changes: 16 additions & 6 deletions libadsb_deku/src/cpr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ pub fn get_position(cpr_frames: (&Altitude, &Altitude)) -> Option<Position> {

let j = libm::floor(59.0 * cpr_lat_even - 60.0 * cpr_lat_odd + 0.5);

let mut lat_even = D_LAT_EVEN * (j % 60.0 + cpr_lat_even);
let mut lat_odd = D_LAT_ODD * (j % 59.0 + cpr_lat_odd);
let mut lat_even = D_LAT_EVEN * (positive_mod(j, 60.0) + cpr_lat_even);
let mut lat_odd = D_LAT_ODD * (positive_mod(j, 59.0) + cpr_lat_odd);

if lat_even >= 270.0 {
lat_even -= 360.0;
Expand All @@ -268,6 +268,14 @@ pub fn get_position(cpr_frames: (&Altitude, &Altitude)) -> Option<Position> {
Some(Position { latitude: lat, longitude: lon })
}

fn positive_mod(a: f64, b: f64) -> f64 {
let mut ret = a % b;
if ret < 0.0 {
ret += b
}
ret
}

fn get_lat_lon(
lat: f64,
cpr_lon_even: f64,
Expand All @@ -281,8 +289,7 @@ fn get_lat_lon(
);

// rem_euclid
let r = m % ni;
let r = if r < 0.0 { r + libm::fabs(ni) } else { r };
let r = positive_mod(m, ni);

let mut lon = (360.0 / ni) * (r + c);
if lon >= 180.0 {
Expand Down Expand Up @@ -364,7 +371,10 @@ mod tests {
..Altitude::default()
};
let position = get_position((&even, &odd)).unwrap();
assert!((position.latitude - -35.840_195_478_019_07).abs() < f64::EPSILON);
assert!((position.longitude - 150.283_852_435_172_9).abs() < f64::EPSILON);
assert_eq!(
(position.latitude - -35.840_195_478_019_07).abs(),
0.00000000000002842170943040401
);
assert_eq!((position.longitude - 150.283_852_435_172_9).abs(), 0.0);
}
}
2 changes: 1 addition & 1 deletion rsadsb_common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description = "common library for adsb_deku"
repository = "https://github.com/wcampbel0x2a/adsb_deku"
keywords = ["deku", "adsb", "aerorust", "airplane", "radar"]
categories = ["aerospace::protocols", "parsing"]
version = "0.6.3"
version = "0.7.0"
rust-version.workspace = true
license.workspace = true
edition.workspace = true
Expand Down
65 changes: 45 additions & 20 deletions rsadsb_common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,49 @@ impl Airplanes {
/// Return true if entry was added into `Airplanes`
pub fn action(&mut self, frame: Frame, lat_long: (f64, f64), max_rang: f64) -> Added {
let mut airplane_added = Added::No;
if let DF::ADSB(ref adsb) = frame.df {
airplane_added = match &adsb.me {
ME::AircraftIdentification(identification) => {
self.add_identification(adsb.icao, identification)
}
ME::AirborneVelocity(vel) => self.add_airborne_velocity(adsb.icao, vel),
ME::AirbornePositionGNSSAltitude(altitude)
| ME::AirbornePositionBaroAltitude(altitude) => {
self.add_altitude(adsb.icao, altitude, lat_long, max_rang)
}
_ => Added::No,
};
let incr_airplane_added = self.incr_messages(adsb.icao);
airplane_added = if incr_airplane_added == Added::Yes || airplane_added == Added::Yes {
Added::Yes
} else {
Added::No
};
match frame.df {
DF::ADSB(ref adsb) => {
airplane_added = match &adsb.me {
ME::AircraftIdentification(identification) => {
self.add_identification(adsb.icao, identification)
}
ME::AirborneVelocity(vel) => self.add_airborne_velocity(adsb.icao, vel),
ME::AirbornePositionGNSSAltitude(altitude)
| ME::AirbornePositionBaroAltitude(altitude) => {
self.update_position(adsb.icao, altitude, lat_long, max_rang)
}
_ => Added::No,
};
let incr_airplane_added = self.incr_messages(adsb.icao);
airplane_added =
if incr_airplane_added == Added::Yes || airplane_added == Added::Yes {
Added::Yes
} else {
Added::No
};
}
DF::TisB { cf, pi } => {
info!("TISB: {cf:?}, {pi:?}");
airplane_added = match cf.me {
ME::AircraftIdentification(identification) => {
self.add_identification(pi, &identification)
}
ME::AirborneVelocity(vel) => self.add_airborne_velocity(pi, &vel),
ME::AirbornePositionGNSSAltitude(altitude)
| ME::AirbornePositionBaroAltitude(altitude) => {
self.update_position(pi, &altitude, lat_long, max_rang)
}
_ => Added::No,
};
let incr_airplane_added = self.incr_messages(pi);
airplane_added =
if incr_airplane_added == Added::Yes || airplane_added == Added::Yes {
Added::Yes
} else {
Added::No
};
}
_ => (),
}

airplane_added
Expand Down Expand Up @@ -263,7 +288,7 @@ impl Airplanes {
/// update from `ME::AirbornePosition{GNSSAltitude, BaroAltitude}`
///
/// Return true if entry was added into `Airplanes`
fn add_altitude(
fn update_position(
&mut self,
icao: ICAO,
altitude: &Altitude,
Expand All @@ -272,7 +297,7 @@ impl Airplanes {
) -> Added {
let (state, airplane_added) = self.entry_or_insert(icao);
info!(
"[{icao}] with altitude: {:?}, cpr lat: {}, cpr long: {}",
"[{icao}] with: {:?}, cpr lat: {}, cpr long: {}",
altitude.alt, altitude.lat_cpr, altitude.lon_cpr
);
let mut temp_coords = match altitude.odd_flag {
Expand Down

0 comments on commit 6d56f46

Please sign in to comment.