#gpsd #gps #client #satellite #information #coordinates #devices

gpsd_client

Simple gpsd client that get the information from a gps device

3 releases

0.1.6 Jun 11, 2024
0.1.5 Feb 8, 2024
0.1.3 Jan 9, 2024

#2 in #gpsd

Download history 6/week @ 2024-07-19 8/week @ 2024-07-26 15/week @ 2024-09-20 7/week @ 2024-09-27

384 downloads per month

MIT and GPL-2.0 licenses

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