From b1ca32e61c5e7f0a6b705a477acd38baecd5aeb8 Mon Sep 17 00:00:00 2001 From: Francesco Frassinelli Date: Sun, 26 May 2019 12:57:51 +0200 Subject: [PATCH] Replace RMC with GGA --- Cargo.lock | 40 ++++++++++++++++++++++++++++++++++++++-- Cargo.toml | 4 ++-- src/main.rs | 5 +++-- src/nmea.rs | 27 +++++++++++++++------------ 4 files changed, 58 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index afa46d6..f234b06 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,3 +1,8 @@ +[[package]] +name = "autocfg" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "bitflags" version = "1.0.4" @@ -14,10 +19,20 @@ version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "frakegps" -version = "0.1.0" +name = "chrono" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ + "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "frakegps" +version = "0.1.1" +dependencies = [ + "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "web-view 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -26,6 +41,23 @@ name = "libc" version = "0.2.55" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "num-integer" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-traits" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "pkg-config" version = "0.3.14" @@ -91,10 +123,14 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] +"checksum autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0e49efa51329a5fd37e7c79db4621af617cd4e3e5bc224939808d076077077bf" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" "checksum boxfnonce 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5988cb1d626264ac94100be357308f29ff7cbdd3b36bda27f450a4ee3f713426" "checksum cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)" = "39f75544d7bbaf57560d2168f28fd649ff9c76153874db88bdbdfd839b1a7e7d" +"checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" "checksum libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)" = "42914d39aad277d9e176efbdad68acb1d5443ab65afe0e0e4f0d49352a950880" +"checksum num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09" +"checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32" "checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c" "checksum redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)" = "12229c14a0f65c4f1cb046a3b52047cdd9da1f4b30f8a39c5063c8bae515e252" "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" diff --git a/Cargo.toml b/Cargo.toml index fbc9097..73eb358 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "frakegps" -version = "0.1.0" +version = "0.1.1" authors = ["Francesco Frassinelli "] edition = "2018" [dependencies] -time = "0.1" +chrono = "0.4" web-view = "0.4.1" diff --git a/src/main.rs b/src/main.rs index 018ad7a..397092e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ use web_view::*; fn main() -> WVResult { let html = format!(include_str!("dist/map.html"), - styles = inline_style(include_str!("dist/map.css")), + styles = inline_style(include_str!("dist/map.css")), scripts = inline_script(include_str!("dist/map.js")), ); let webview = web_view::builder() @@ -19,7 +19,8 @@ fn main() -> WVResult { let latlon: Vec<&str> = arg.split(",").collect(); let lat: f64 = latlon[0].parse().unwrap(); let lon: f64 = latlon[1].parse().unwrap(); - println!("{}", nmea::rmc(lat, lon)); + let alt: f64 = 0.0; + println!("{}", nmea::gga(lat, lon, alt)); Ok(()) }) .build()?; diff --git a/src/nmea.rs b/src/nmea.rs index aae311f..290130d 100644 --- a/src/nmea.rs +++ b/src/nmea.rs @@ -1,4 +1,5 @@ -extern crate time; +extern crate chrono; +use chrono::prelude::*; fn dec_to_dm(dec: f64) -> f64 { let deg = dec.abs().floor(); @@ -14,27 +15,29 @@ fn checksum(message: &String) -> String { format!("{:02X}", checksum) } -pub fn rmc(lat: f64, lon: f64) -> String { +pub fn gga(lat: f64, lon: f64, altitude: f64) -> String { let lat_nmea = format!("{:08.3}", dec_to_dm(lat)*100.0); let lon_nmea = format!("{:09.3}", dec_to_dm(lon)*100.0); let ns = if lat.is_sign_negative() { 'S' } else { 'N' }; let ew = if lon.is_sign_negative() { 'W' } else { 'E' }; - let now = time::now_utc(); - let date = now.strftime("%d%m%y").unwrap(); - let timestamp = now.strftime("%H%M%S").unwrap(); + let now: DateTime = Utc::now(); + let timestamp = now.format("%H%M%S.%3f"); let message = [ - "GPRMC", + "GPGGA", ×tamp.to_string(), - "A", // A: valid, V: invalid &lat_nmea, &ns.to_string(), &lon_nmea, &ew.to_string(), - "0", // speed over ground (knots) - "0", // course over ground (degrees) - &date.to_string(), - "", // magnetic variation (degrees) - "", // E/W (east/west) + "1", // Fix valid + "", // Satellites used + "", // HDOP + &altitude.to_string(), + "M", // meters + "0", // Geoid separation + "M", // meters + "", // DGPS + "0000", // DGPS station ID ].join(","); let checksum = checksum(&message); format!("${}*{}", message, checksum)