Browse Source

beast: switch from adsb to adsb_deku

master
Astro 8 months ago
parent
commit
9e6aff71ae
  1. 259
      Cargo.lock
  2. 4
      beast/Cargo.toml
  3. 99
      beast/src/aircrafts.rs
  4. 5
      beast/src/beast.rs
  5. 4
      collectd-stats/src/main.rs
  6. 2
      heliwatch/Cargo.toml
  7. 6
      heliwatch/src/adsb.rs
  8. 2
      http-json/Cargo.toml
  9. 10
      http-json/src/main.rs

259
Cargo.lock generated

@ -3,13 +3,12 @@
version = 3
[[package]]
name = "adsb"
version = "0.3.0"
name = "adsb_deku"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9245ecd631f63f1995269dc9f88fdda8fc8e9a308c4196315cfdedd1ccfccc07"
checksum = "2dea2b143d6e9fafc7c0649f7cf4d95f0cb0fdc03fb744e9a7e39e3f6aede330"
dependencies = [
"lazy_static",
"nom",
"deku",
]
[[package]]
@ -30,12 +29,6 @@ dependencies = [
"num-traits",
]
[[package]]
name = "arrayvec"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
[[package]]
name = "as-slice"
version = "0.1.5"
@ -50,9 +43,9 @@ dependencies = [
[[package]]
name = "async-trait"
version = "0.1.51"
version = "0.1.52"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44318e776df68115a881de9a8fd1b9e53368d7a4a5ce4cc48517da3393233a5e"
checksum = "061a7acccaa286c011ddc30970520b98fa40e00c9d644633fb26b5fc63a265e3"
dependencies = [
"proc-macro2",
"quote",
@ -73,9 +66,9 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
[[package]]
name = "beast"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"adsb",
"adsb_deku",
"futures",
"tokio",
]
@ -88,9 +81,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitvec"
version = "0.19.5"
version = "0.22.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8942c8d352ae1838c9dda0b0ca2ab657696ef2232a20147cf1b30ae1a9cb4321"
checksum = "5237f00a8c86130a0cc317830e558b966dd7850d48a953d998c813f01a41b527"
dependencies = [
"funty",
"radium",
@ -161,9 +154,9 @@ checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8"
[[package]]
name = "cc"
version = "1.0.71"
version = "1.0.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd"
checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee"
[[package]]
name = "cfg-if"
@ -243,7 +236,7 @@ checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1"
dependencies = [
"bstr",
"csv-core",
"itoa",
"itoa 0.4.8",
"ryu",
"serde",
]
@ -257,12 +250,70 @@ dependencies = [
"memchr",
]
[[package]]
name = "darling"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0d720b8683f8dd83c65155f0530560cba68cd2bf395f6513a483caee57ff7f4"
dependencies = [
"darling_core",
"darling_macro",
]
[[package]]
name = "darling_core"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a340f241d2ceed1deb47ae36c4144b2707ec7dd0b649f894cb39bb595986324"
dependencies = [
"fnv",
"ident_case",
"proc-macro2",
"quote",
"strsim",
"syn",
]
[[package]]
name = "darling_macro"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72c41b3b7352feb3211a0d743dc5700a4e3b60f51bd2b368892d1e0f9a95f44b"
dependencies = [
"darling_core",
"quote",
"syn",
]
[[package]]
name = "data-encoding"
version = "2.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57"
[[package]]
name = "deku"
version = "0.12.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6636cb8b0811013ab93bc37b88b460ca637ce3bdc97fb68ca79d7d7df4f16cba"
dependencies = [
"bitvec",
"deku_derive",
]
[[package]]
name = "deku_derive"
version = "0.12.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9bf7f0f5c5d6b9cc189dea2a0fece14c26a0bbb9df7b52d2fe7b6dd300dae1a0"
dependencies = [
"darling",
"proc-macro-crate",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "digest"
version = "0.9.0"
@ -317,9 +368,9 @@ dependencies = [
[[package]]
name = "funty"
version = "1.1.0"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7"
checksum = "1847abb9cb65d566acd5942e94aea9c8f547ad02c98e1649326fc0e8910b8b1e"
[[package]]
name = "futf"
@ -511,9 +562,9 @@ dependencies = [
[[package]]
name = "h2"
version = "0.3.7"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fd819562fcebdac5afc5c113c3ec36f902840b70fd4fc458799c8ce4607ae55"
checksum = "8f072413d126e57991455e0a922b31e4c8ba7c2ffbebf6b78b4f8521397d65cd"
dependencies = [
"bytes",
"fnv",
@ -593,7 +644,7 @@ dependencies = [
name = "heliwatch"
version = "0.1.0"
dependencies = [
"adsb",
"adsb_deku",
"beast",
"csv",
"futures",
@ -643,7 +694,7 @@ checksum = "1323096b05d41827dadeaee54c9981958c0f94e670bc94ed80037d1a7b8b186b"
dependencies = [
"bytes",
"fnv",
"itoa",
"itoa 0.4.8",
]
[[package]]
@ -661,7 +712,7 @@ dependencies = [
name = "http-json"
version = "0.1.0"
dependencies = [
"adsb",
"adsb_deku",
"beast",
"serde",
"serde_json",
@ -677,15 +728,15 @@ checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503"
[[package]]
name = "httpdate"
version = "1.0.1"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440"
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
[[package]]
name = "hyper"
version = "0.14.14"
version = "0.14.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b91bb1f221b6ea1f1e4371216b70f40748774c2fb5971b450c07773fb92d26b"
checksum = "b7ec3e62bdc98a2f0393a5048e4c30ef659440ea6e0e572965103e72bd836f55"
dependencies = [
"bytes",
"futures-channel",
@ -696,7 +747,7 @@ dependencies = [
"http-body",
"httparse",
"httpdate",
"itoa",
"itoa 0.4.8",
"pin-project-lite",
"socket2 0.4.2",
"tokio",
@ -705,6 +756,12 @@ dependencies = [
"want",
]
[[package]]
name = "ident_case"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]]
name = "idna"
version = "0.2.3"
@ -726,15 +783,6 @@ dependencies = [
"hashbrown",
]
[[package]]
name = "input_buffer"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f97967975f448f1a7ddb12b0bc41069d09ed6a1c161a92687e057325db35d413"
dependencies = [
"bytes",
]
[[package]]
name = "instant"
version = "0.1.12"
@ -768,6 +816,12 @@ version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
[[package]]
name = "itoa"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
[[package]]
name = "jid"
version = "0.9.2"
@ -789,19 +843,6 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "lexical-core"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe"
dependencies = [
"arrayvec",
"bitflags",
"cfg-if",
"ryu",
"static_assertions",
]
[[package]]
name = "libc"
version = "0.2.107"
@ -937,9 +978,9 @@ dependencies = [
[[package]]
name = "multipart"
version = "0.17.1"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d050aeedc89243f5347c3e237e3e13dc76fbe4ae3742a57b94dc14f69acf76d4"
checksum = "00dec633863867f29cb39df64a397cdf4a6354708ddd7759f70c7fb51c5f9182"
dependencies = [
"buf_redux",
"httparse",
@ -947,7 +988,7 @@ dependencies = [
"mime",
"mime_guess",
"quick-error",
"rand 0.7.3",
"rand 0.8.4",
"safemem",
"tempfile",
"twoway",
@ -1004,19 +1045,6 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54"
[[package]]
name = "nom"
version = "6.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c5c51b9083a3c620fa67a2a635d1ce7d95b897e957d6b28ff9a5da960a103a6"
dependencies = [
"bitvec",
"funty",
"lexical-core",
"memchr",
"version_check",
]
[[package]]
name = "ntapi"
version = "0.3.6"
@ -1110,9 +1138,9 @@ checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a"
[[package]]
name = "openssl-sys"
version = "0.9.70"
version = "0.9.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6517987b3f8226b5da3661dad65ff7f300cc59fb5ea8333ca191fc65fde3edf"
checksum = "7e46109c383602735fa0a2e48dd2b7c892b048e1bf69e5c3b1d804b7d9c203cb"
dependencies = [
"autocfg",
"cc",
@ -1267,9 +1295,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "pkg-config"
version = "0.3.22"
version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12295df4f294471248581bc09bef3c38a5e46f1e36d6a37353621a0c6c357e1f"
checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe"
[[package]]
name = "ppv-lite86"
@ -1283,6 +1311,16 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
[[package]]
name = "proc-macro-crate"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ebace6889caf889b4d3f76becee12e90353f2b8c7d875534a71e5742f8f6f83"
dependencies = [
"thiserror",
"toml",
]
[[package]]
name = "proc-macro-hack"
version = "0.5.19"
@ -1330,9 +1368,9 @@ dependencies = [
[[package]]
name = "radium"
version = "0.5.3"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "941ba9d78d8e2f7ce474c015eea4d9c6d25b6a3327f9832ee29a4de27f91bbb8"
checksum = "643f8f41a8ebc4c5dc4515c82bb8abd397b527fc20fd681b7c011c2aee5d44fb"
[[package]]
name = "rand"
@ -1482,9 +1520,9 @@ checksum = "e5864e7ef1a6b7bcf1d6ca3f655e65e724ed3b52546a0d0a663c991522f552ea"
[[package]]
name = "rstar"
version = "0.8.3"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce61d743ebe516592df4dd542dfe823577b811299f7bee1106feb1bbb993dbac"
checksum = "3a45c0e8804d37e4d97e55c6f258bc9ad9c5ee7b07437009dd152d764949a27c"
dependencies = [
"heapless",
"num-traits",
@ -1503,9 +1541,9 @@ dependencies = [
[[package]]
name = "ryu"
version = "1.0.5"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f"
[[package]]
name = "safemem"
@ -1612,11 +1650,11 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.69"
version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e466864e431129c7e0d3476b92f20458e5879919a0596c6472738d9fa2d342f8"
checksum = "bcbd0344bc6533bc7ec56df11d42fb70f1b912351c0825ccb7211b59d8af7cf5"
dependencies = [
"itoa",
"itoa 1.0.1",
"ryu",
"serde",
]
@ -1628,7 +1666,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9"
dependencies = [
"form_urlencoded",
"itoa",
"itoa 0.4.8",
"ryu",
"serde",
]
@ -1737,12 +1775,6 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]]
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "string_cache"
version = "0.8.2"
@ -1769,6 +1801,12 @@ dependencies = [
"quote",
]
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "subtle"
version = "2.4.1"
@ -1849,9 +1887,9 @@ dependencies = [
[[package]]
name = "tinyvec"
version = "1.5.0"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f83b2a3d4d9091d0abd7eba4dc2710b1718583bd4d8992e2190720ea38f391f7"
checksum = "2c1c1d5a42b6245520c249549ec267180beaffcc0615401ac8e31853d4b6d8d2"
dependencies = [
"tinyvec_macros",
]
@ -1916,9 +1954,9 @@ dependencies = [
[[package]]
name = "tokio-tungstenite"
version = "0.13.0"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1a5f475f1b9d077ea1017ecbc60890fda8e54942d680ca0b1d2b47cfa2d861b"
checksum = "511de3f85caf1c98983545490c3d09685fa8eb634e57eec22bb4db271f46cbd8"
dependencies = [
"futures-util",
"log",
@ -1943,9 +1981,9 @@ dependencies = [
[[package]]
name = "tokio-xmpp"
version = "3.0.0"
version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56ac9ffb7a7e49d8efe6f9eb7e3d08385f50197d5202c226cd46ffb4f5231a39"
checksum = "674515294bc09c894310945d0c4075e84e22d4346359351e349b2849eecdf677"
dependencies = [
"bytes",
"futures",
@ -1964,6 +2002,15 @@ dependencies = [
"xmpp-parsers",
]
[[package]]
name = "toml"
version = "0.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa"
dependencies = [
"serde",
]
[[package]]
name = "tower-service"
version = "0.3.1"
@ -2044,19 +2091,19 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642"
[[package]]
name = "tungstenite"
version = "0.12.0"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ada8297e8d70872fa9a551d93250a9f407beb9f37ef86494eb20012a2ff7c24"
checksum = "a0b2d8558abd2e276b0a8df5c05a2ec762609344191e5fd23e292c910e9165b5"
dependencies = [
"base64",
"byteorder",
"bytes",
"http",
"httparse",
"input_buffer",
"log",
"rand 0.8.4",
"sha-1",
"thiserror",
"url",
"utf-8",
]
@ -2160,12 +2207,13 @@ dependencies = [
[[package]]
name = "warp"
version = "0.3.1"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "332d47745e9a0c38636dbd454729b147d16bd1ed08ae67b3ab281c4506771054"
checksum = "3cef4e1e9114a4b7f1ac799f16ce71c14de5778500c5450ec6b7b920c55b587e"
dependencies = [
"bytes",
"futures",
"futures-channel",
"futures-util",
"headers",
"http",
"hyper",
@ -2238,9 +2286,12 @@ dependencies = [
[[package]]
name = "wyz"
version = "0.2.0"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214"
checksum = "129e027ad65ce1453680623c3fb5163cbf7107bfe1aa32257e7d0e63f9ced188"
dependencies = [
"tap",
]
[[package]]
name = "xml5ever"

4
beast/Cargo.toml

@ -1,10 +1,10 @@
[package]
name = "beast"
description = "Receive ADS-B data from readsb"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
[dependencies]
futures = "0.3"
tokio = { version = "1", features = ["full"] }
adsb = "0.3"
adsb_deku = "0.4"

99
beast/src/aircrafts.rs

@ -3,81 +3,85 @@ use std::sync::{Arc, RwLock};
use std::time::{Duration, Instant};
use futures::stream::StreamExt;
use tokio::sync::mpsc::channel;
use adsb::ICAOAddress;
use adsb_deku::ICAO;
use super::beast;
const JITTER_WINDOW: usize = 5;
#[derive(Default)]
pub struct Entry {
pub emitter_category: Option<u8>,
pub category: Option<(adsb_deku::adsb::TypeCoding, u8)>,
pub callsign: Option<String>,
pub altitude: Option<u16>,
cpr1: Option<adsb::CPRFrame>,
cpr2: Option<adsb::CPRFrame>,
positions: [Option<adsb::Position>; JITTER_WINDOW],
pub altitude: Option<u32>,
cpr1: Option<adsb_deku::Altitude>,
cpr2: Option<adsb_deku::Altitude>,
// jitter buffer
positions: [Option<adsb_deku::cpr::Position>; JITTER_WINDOW],
pub heading: Option<f64>,
pub ground_speed: Option<f64>,
pub speed: Option<f64>,
pub vertical_rate: Option<i16>,
pub vertical_rate_source: Option<adsb::VerticalRateSource>,
last_update: Option<Instant>,
}
impl Entry {
const MAX_AGE: u64 = 300;
fn update(&mut self, kind: adsb::ADSBMessageKind) {
fn update(&mut self, kind: adsb_deku::adsb::ME) {
match kind {
adsb::ADSBMessageKind::AirbornePosition {
altitude, cpr_frame
} => {
self.altitude = Some(altitude);
if self.cpr2.as_ref().map(|cpr2| cpr2.parity != cpr_frame.parity).unwrap_or(false) {
adsb_deku::adsb::ME::AirbornePositionBaroAltitude(altitude) |
adsb_deku::adsb::ME::AirbornePositionGNSSAltitude(altitude) => {
self.altitude = Some(altitude.alt);
if self.cpr2.map_or(false, |cpr2| cpr2.odd_flag != altitude.odd_flag) {
// if last altitude had a different odd flag,
// shift the entries
self.cpr1 = self.cpr2.take();
}
self.cpr2 = Some(cpr_frame);
// add the new entry
self.cpr2 = Some(altitude);
match (&self.cpr1, &self.cpr2) {
(Some(cpr1), Some(cpr2)) => {
match adsb::cpr::get_position((cpr1, cpr2)) {
Some(pos) if
pos.latitude >= -90.0 &&
pos.latitude <= 90.0 &&
pos.longitude >= -180.0 &&
pos.longitude <= 180.0 =>
if let Some(pos) = adsb_deku::cpr::get_position((cpr1, cpr2)) {
if pos.latitude < -90. || pos.latitude > 90. ||
pos.longitude < -180. || pos.longitude > 180.
{
eprintln!("invalid position: {:?}", pos);
} else {
// shift previous positions in jitter buffer
for i in 1..self.positions.len() {
self.positions[i - 1] = self.positions[i].take();
}
// add position to jitter buffer
self.positions[self.positions.len() - 1] = Some(pos);
}
_ => {}
}
}
_ => {}
}
}
adsb::ADSBMessageKind::AirborneVelocity {
heading, ground_speed,
vertical_rate, vertical_rate_source,
} => {
self.heading = Some(heading);
self.ground_speed = Some(ground_speed);
self.vertical_rate = Some(vertical_rate);
self.vertical_rate_source = Some(vertical_rate_source);
adsb_deku::adsb::ME::AirborneVelocity(velocity) => {
if let Some((heading, speed, vrate)) = velocity.calculate() {
self.heading = Some(heading);
self.speed = Some(speed);
self.vertical_rate = Some(vrate);
}
}
adsb_deku::adsb::ME::AircraftIdentification(ident) => {
self.category = Some((ident.tc, ident.ca));
self.callsign = Some(ident.cn);
}
adsb::ADSBMessageKind::AircraftIdentification {
emitter_category, callsign
} => {
self.emitter_category = Some(emitter_category);
self.callsign = Some(callsign);
adsb_deku::adsb::ME::TargetStateAndStatusInformation(_) => {}
adsb_deku::adsb::ME::AircraftStatus(_) => {}
adsb_deku::adsb::ME::AircraftOperationStatus(_) => {}
msg => {
eprintln!("unhandled adsb msg: {:?}", msg);
}
}
self.last_update = Some(Instant::now());
}
pub fn position(&self) -> Option<&adsb::Position> {
pub fn position(&self) -> Option<&adsb_deku::cpr::Position> {
let mut prev_lat = self.positions[0].as_ref()?.latitude;
let mut prev_lon = self.positions[0].as_ref()?.longitude;
for i in 1..self.positions.len() {
@ -89,6 +93,9 @@ impl Entry {
lon > prev_lon + 1.0
{
// erroneous jitter detected
eprintln!("{:?} error in: {:?}", self.callsign, self.positions.iter().filter_map(|pos| {
pos.as_ref().map(|pos| (pos.latitude as i32, pos.longitude as i32))
}).collect::<Vec<_>>());
return None;
}
prev_lat = lat;
@ -112,7 +119,7 @@ impl Entry {
#[derive(Clone)]
pub struct Aircrafts {
state: Arc<RwLock<HashMap<ICAOAddress, RwLock<Entry>>>>,
state: Arc<RwLock<HashMap<ICAO, RwLock<Entry>>>>,
}
impl Aircrafts {
@ -122,7 +129,7 @@ impl Aircrafts {
}
}
pub fn read(&self) -> std::sync::RwLockReadGuard<HashMap<ICAOAddress, RwLock<Entry>>> {
pub fn read(&self) -> std::sync::RwLockReadGuard<HashMap<ICAO, RwLock<Entry>>> {
self.state.read().unwrap()
}
@ -153,19 +160,15 @@ impl Aircrafts {
tokio::spawn(async move {
while let Some(frame) = rx.recv().await {
match frame.parse_adsb() {
Some(adsb::Message {
kind: adsb::MessageKind::ADSBMessage {
icao_address,
kind,
crc,
.. },
.. }) if crc =>
{
Some(adsb_deku::Frame { df: adsb_deku::DF::ADSB(adsb), crc }) => {
if crc != 0 {
eprintln!("crc: {:02X}", crc);
}
state.write().unwrap()
.entry(icao_address)
.entry(adsb.icao)
.or_default()
.write().unwrap()
.update(kind);
.update(adsb.me);
}
_ => {}
}

5
beast/src/beast.rs

@ -1,6 +1,7 @@
use futures::stream;
use tokio::io::AsyncReadExt;
use tokio::net::TcpStream;
use adsb_deku::deku::DekuContainerRead;
const DEFRAMER_DEFAULT_CAPACITY: usize = 22;
@ -109,10 +110,10 @@ impl Frame {
}
}
pub fn parse_adsb(&self) -> Option<adsb::Message> {
pub fn parse_adsb(&self) -> Option<adsb_deku::Frame> {
match self.frame_type() {
Some(FrameType::ModeSShort) | Some(FrameType::ModeSLong) => {
if let Ok((msg, _rest)) = adsb::parse_binary(&self.data[8..]) {
if let Ok((_rest, msg)) = adsb_deku::Frame::from_bytes((&self.data[8..], 0)) {
Some(msg)
} else {
eprintln!("adsb decode error");

4
collectd-stats/src/main.rs

@ -61,8 +61,8 @@ async fn main() {
update_min(&entry.altitude, &mut min_altitude);
update_max(&entry.altitude, &mut max_altitude);
update_min(&entry.ground_speed, &mut min_speed);
update_max(&entry.ground_speed, &mut max_speed);
update_min(&entry.speed, &mut min_speed);
update_max(&entry.speed, &mut max_speed);
if let Some(pos) = entry.position() {
let altitude_m = entry.altitude.unwrap_or(0) as f64 * 0.3048;

2
heliwatch/Cargo.toml

@ -12,5 +12,5 @@ geo = "0.18"
csv = "1.1"
tokio-xmpp = "3"
xmpp-parsers = "0.18"
adsb = "0.3"
adsb_deku = "0.4"
beast = { path = "../beast" }

6
heliwatch/src/adsb.rs

@ -6,7 +6,7 @@ use tokio::sync::mpsc::{channel, Receiver};
use super::location::Locations;
/// ft
const MAX_ALTITUDE: u16 = 5_000;
const MAX_ALTITUDE: u32 = 5_000;
/// s
const STATE_TIMEOUT: u64 = 180;
@ -45,7 +45,7 @@ pub struct Info {
struct State {
info: Info,
position: Option<adsb::Position>,
position: Option<adsb_deku::cpr::Position>,
location: Option<Arc<String>>,
last: Instant,
}
@ -133,7 +133,7 @@ pub fn run(host: &'static str, port: u16, locations: Locations) -> Receiver<Even
}
if entry.altitude.map(|altitude| altitude > MAX_ALTITUDE).unwrap_or(false) ||
entry.emitter_category.as_ref().map(|category| IGNORED_CATEGORIES.contains(category)).unwrap_or(false)
entry.category.as_ref().map(|category| IGNORED_CATEGORIES.contains(&category.1)).unwrap_or(false)
{
if !ignored.contains(&hex) {
ignored.insert(hex.clone());

2
http-json/Cargo.toml

@ -10,4 +10,4 @@ beast = { path = "../beast" }
warp = "0.3"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
adsb = "0.3"
adsb_deku = "0.4"

10
http-json/src/main.rs

@ -1,5 +1,5 @@
use warp::{http::Response, Filter};
use adsb::ICAOAddress;
use adsb_deku::ICAO;
use beast::aircrafts::Entry;
use serde::Serialize;
@ -11,23 +11,23 @@ pub struct Aircraft {
lat: Option<f64>,
lon: Option<f64>,
/// ft
altitude: Option<u16>,
altitude: Option<u32>,
track: Option<i16>,
/// kts
speed: Option<u16>,
}
impl Aircraft {
pub fn new(icao_address: &ICAOAddress, entry: &Entry) -> Self {
pub fn new(icao_address: &ICAO, entry: &Entry) -> Self {
Aircraft {
hex: format!("{}", icao_address),
flight: entry.callsign.clone(),
category: entry.emitter_category.clone(),
category: entry.category.map(|category| category.1),
lat: entry.position().map(|pos| pos.latitude),
lon: entry.position().map(|pos| pos.longitude),
altitude: entry.altitude.clone(),
track: entry.heading.map(|heading| heading as i16),
speed: entry.ground_speed.map(|speed| speed as u16),
speed: entry.speed.map(|speed| speed as u16),
}
}
}

Loading…
Cancel
Save