Skip to content

Commit

Permalink
Replace RMC with GGA
Browse files Browse the repository at this point in the history
  • Loading branch information
frafra committed May 26, 2019
1 parent edd36f9 commit b1ca32e
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 18 deletions.
40 changes: 38 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "frakegps"
version = "0.1.0"
version = "0.1.1"
authors = ["Francesco Frassinelli <[email protected]>"]
edition = "2018"

[dependencies]
time = "0.1"
chrono = "0.4"
web-view = "0.4.1"
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()?;
Expand Down
27 changes: 15 additions & 12 deletions src/nmea.rs
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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> = Utc::now();
let timestamp = now.format("%H%M%S.%3f");
let message = [
"GPRMC",
"GPGGA",
&timestamp.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)
Expand Down

0 comments on commit b1ca32e

Please sign in to comment.