Crate gpsd_client

source ·
Expand description

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 and read and write information to gpsd. This package was modeled from the python3 gpsd package.

§Update

You now have the ability to change the time format from %Y-%m-%dT%H:%M:%S.%fZ.

§Testing

gpsd_client was tested with gpsd: 3.22 on Linux Debian Distro.

From more information about gpsd just check out the documentation at https://gpsd.io/index.html.

§Example

use gpsd_client::*;
use std::thread;
use std::time::Duration;
use std::process;

      // 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();

Structs§

  • This struct holds the connection to the gpsd socket server and version, watch and devices information from gpsd. For more information about version, watch and devices visit https://gpsd.io/gpsd_json.html.
  • Data from the gps device.

Enums§

  • Type of fix the gps device has.
  • Possible errors that can occur for parsing the data that comes from the gpsd socket server.

Functions§

  • Converts the time from this format “%Y-%m-%dT%H:%M:%S.%fZ” to what ever format you want. Just make sure if your converting the time to your Time Zone you did it first. Then run this function.