http-json: add fields squawk, seen, seen_pos
This commit is contained in:
parent
4fbe229eb0
commit
a14fabb53c
|
@ -21,12 +21,17 @@ pub struct Entry {
|
||||||
pub speed: Option<f64>,
|
pub speed: Option<f64>,
|
||||||
pub vertical_rate: Option<i16>,
|
pub vertical_rate: Option<i16>,
|
||||||
last_update: Option<Instant>,
|
last_update: Option<Instant>,
|
||||||
|
pub squawk: Option<u32>,
|
||||||
|
pub seen: Option<Instant>, // Option wrapper is just for derive Default
|
||||||
|
pub seen_pos: Option<Instant>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Entry {
|
impl Entry {
|
||||||
const MAX_AGE: u64 = 300;
|
const MAX_AGE: u64 = 300;
|
||||||
|
|
||||||
fn update(&mut self, kind: adsb_deku::adsb::ME) {
|
fn update(&mut self, kind: adsb_deku::adsb::ME) {
|
||||||
|
self.seen = Some(Instant::now());
|
||||||
|
|
||||||
match kind {
|
match kind {
|
||||||
adsb_deku::adsb::ME::AirbornePositionBaroAltitude(altitude) |
|
adsb_deku::adsb::ME::AirbornePositionBaroAltitude(altitude) |
|
||||||
adsb_deku::adsb::ME::AirbornePositionGNSSAltitude(altitude) => {
|
adsb_deku::adsb::ME::AirbornePositionGNSSAltitude(altitude) => {
|
||||||
|
@ -53,6 +58,7 @@ impl Entry {
|
||||||
}
|
}
|
||||||
// add position to jitter buffer
|
// add position to jitter buffer
|
||||||
self.positions[self.positions.len() - 1] = Some(pos);
|
self.positions[self.positions.len() - 1] = Some(pos);
|
||||||
|
self.seen_pos = Some(Instant::now());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,8 +76,10 @@ impl Entry {
|
||||||
self.category = Some((ident.tc, ident.ca));
|
self.category = Some((ident.tc, ident.ca));
|
||||||
self.callsign = Some(ident.cn);
|
self.callsign = Some(ident.cn);
|
||||||
}
|
}
|
||||||
|
adsb_deku::adsb::ME::AircraftStatus(status) => {
|
||||||
|
self.squawk = Some(status.squawk);
|
||||||
|
}
|
||||||
adsb_deku::adsb::ME::TargetStateAndStatusInformation(_) => {}
|
adsb_deku::adsb::ME::TargetStateAndStatusInformation(_) => {}
|
||||||
adsb_deku::adsb::ME::AircraftStatus(_) => {}
|
|
||||||
adsb_deku::adsb::ME::AircraftOperationStatus(_) => {}
|
adsb_deku::adsb::ME::AircraftOperationStatus(_) => {}
|
||||||
msg => {
|
msg => {
|
||||||
eprintln!("unhandled adsb msg: {:?}", msg);
|
eprintln!("unhandled adsb msg: {:?}", msg);
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use std::time::Instant;
|
||||||
use warp::{http::Response, Filter};
|
use warp::{http::Response, Filter};
|
||||||
use adsb_deku::ICAO;
|
use adsb_deku::ICAO;
|
||||||
use beast::aircrafts::Entry;
|
use beast::aircrafts::Entry;
|
||||||
|
@ -6,6 +7,7 @@ use serde::Serialize;
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct Aircraft {
|
pub struct Aircraft {
|
||||||
hex: String,
|
hex: String,
|
||||||
|
squawk: Option<u32>,
|
||||||
flight: Option<String>,
|
flight: Option<String>,
|
||||||
category: Option<u8>,
|
category: Option<u8>,
|
||||||
lat: Option<f64>,
|
lat: Option<f64>,
|
||||||
|
@ -15,12 +17,17 @@ pub struct Aircraft {
|
||||||
track: Option<i16>,
|
track: Option<i16>,
|
||||||
/// kts
|
/// kts
|
||||||
speed: Option<u16>,
|
speed: Option<u16>,
|
||||||
|
seen: Option<f32>,
|
||||||
|
seen_pos: Option<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Aircraft {
|
impl Aircraft {
|
||||||
pub fn new(icao_address: &ICAO, entry: &Entry) -> Self {
|
pub fn new(icao_address: &ICAO, entry: &Entry) -> Self {
|
||||||
|
let now = Instant::now();
|
||||||
|
|
||||||
Aircraft {
|
Aircraft {
|
||||||
hex: format!("{}", icao_address),
|
hex: format!("{}", icao_address),
|
||||||
|
squawk: entry.squawk.clone(),
|
||||||
flight: entry.callsign.clone(),
|
flight: entry.callsign.clone(),
|
||||||
category: entry.category.map(|category| category.1),
|
category: entry.category.map(|category| category.1),
|
||||||
lat: entry.position().map(|pos| pos.latitude),
|
lat: entry.position().map(|pos| pos.latitude),
|
||||||
|
@ -28,6 +35,8 @@ impl Aircraft {
|
||||||
altitude: entry.altitude.clone(),
|
altitude: entry.altitude.clone(),
|
||||||
track: entry.heading.map(|heading| heading as i16),
|
track: entry.heading.map(|heading| heading as i16),
|
||||||
speed: entry.speed.map(|speed| speed as u16),
|
speed: entry.speed.map(|speed| speed as u16),
|
||||||
|
seen: entry.seen.map(|seen| (now - seen).as_secs_f32()),
|
||||||
|
seen_pos: entry.seen_pos.map(|seen_pos| (now - seen_pos).as_secs_f32()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue