| Crates.io | gpsd_client |
| lib.rs | gpsd_client |
| version | 0.1.6 |
| created_at | 2024-01-09 19:32:18.275333+00 |
| updated_at | 2024-06-11 13:49:57.300228+00 |
| description | Simple gpsd client that get the information from a gps device. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1094440 |
| size | 22,682 |
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.
You now have the ability to change the time format from %Y-%m-%dT%H:%M:%S.%fZ. The connection has now been set up to tell gpsd to use NMEA
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.
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();
}