http-json: add rssi
This commit is contained in:
parent
04f4332c4d
commit
7b4f31c8f9
|
@ -21,13 +21,15 @@ pub struct Entry {
|
|||
pub squawk: Option<u32>,
|
||||
pub seen: Option<Instant>, // Option wrapper is just for derive Default
|
||||
pub seen_pos: Option<Instant>,
|
||||
pub rssi: Option<f32>,
|
||||
}
|
||||
|
||||
impl Entry {
|
||||
const MAX_AGE: u64 = 300;
|
||||
|
||||
fn update(&mut self, kind: adsb_deku::adsb::ME) {
|
||||
fn update(&mut self, kind: adsb_deku::adsb::ME, rssi: Option<f32>) {
|
||||
self.seen = Some(Instant::now());
|
||||
rssi.map(|rssi| self.rssi = Some(rssi));
|
||||
|
||||
match kind {
|
||||
adsb_deku::adsb::ME::AirbornePositionBaroAltitude(altitude) |
|
||||
|
@ -146,7 +148,7 @@ impl Aircrafts {
|
|||
.entry(adsb.icao)
|
||||
.or_default()
|
||||
.write().unwrap()
|
||||
.update(adsb.me);
|
||||
.update(adsb.me, frame.rssi());
|
||||
} else {
|
||||
eprintln!("crc: {:02X}", crc);
|
||||
}
|
||||
|
|
|
@ -99,14 +99,16 @@ impl Frame {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn signal(&self) -> u8 {
|
||||
match self.frame_type() {
|
||||
Some(FrameType::ModeAC) |
|
||||
Some(FrameType::ModeSShort) |
|
||||
Some(FrameType::ModeSLong) => {
|
||||
self.data[7]
|
||||
}
|
||||
_ => 255
|
||||
/// dbfs
|
||||
pub fn rssi(&self) -> Option<f32> {
|
||||
if self.data.len() < 8 {
|
||||
None
|
||||
} else if self.data[7] == 0xff {
|
||||
None
|
||||
} else {
|
||||
Some(
|
||||
10.0 * (((self.data[7] as f32) / 256.0).powi(2) + 1.0e-5).log10()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ pub struct Aircraft {
|
|||
speed: Option<u16>,
|
||||
seen: Option<f32>,
|
||||
seen_pos: Option<f32>,
|
||||
rssi: Option<f32>,
|
||||
}
|
||||
|
||||
impl Aircraft {
|
||||
|
@ -37,6 +38,7 @@ impl Aircraft {
|
|||
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()),
|
||||
rssi: entry.rssi.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue