3 releases
0.1.6 | Jun 11, 2024 |
---|---|
0.1.5 | Feb 8, 2024 |
0.1.3 | Jan 9, 2024 |
#2 in #gpsd
384 downloads per month
23KB
376 lines
The gpsd_client
module contains types and functions to connect to
[gpsd] https://gpsd.io/index.html to get gps coordinates and how many
satellites you are receiving information from and how many satellites
the information is being used.
The gps-client
uses a TcpStream to connect to the gpsd socket server to read and
write information to gpsd
. This package was modeled from the python3 gpsd package.
Testing
gpsd_client
was test with gpsd: 3.22 on Linux Debian Distro.
From more information about gpsd just check out the documentation at https://gpsd.io/index.html.
Examples
use gpsd_client::*;
use std::thread;
use std::time::Duration;
use std::process;
fn main() {
// Connecting to the gpsd socket server.
let mut gps: GPS = match GPS::connect() {
Ok(t) => t,
Err(e) => {
println!("{e}");
process::exit(1);
}
};
let mut count: i32 = 0;
loop {
count += 1;
// Getting the data from the gps device.
let data: GPSData = gps.current_data().unwrap();
println!("{data:#?}");
let my_time: String = data.convert_time("America/Chicago").unwrap();
let mph: f32 = data.convert_speed(true);
let direction: String = data.travel_direction();
println!(
"Lat: {}, Lon: {}, Time: {}, Speed: {:.1}, Direction: {}",
data.lat, data.lon, my_time, mph, direction
);
if count == 5 { break; }
thread::sleep(Duration::from_millis(500));
}
// Closing the TcpStream and BufReader to the gpsd socket server.
gps.close();
}
Dependencies
~1.9–3MB
~48K SLoC