Skip to content

Commit

Permalink
Configure NAV-TIMEGPS if Gpsd is used.
Browse files Browse the repository at this point in the history
  • Loading branch information
brocaar committed Oct 3, 2024
1 parent f7db643 commit efaa1b7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions libconcentratord/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
anyhow = "1.0"
thiserror = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
23 changes: 23 additions & 0 deletions libconcentratord/src/gpsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ use std::net::TcpStream;

use anyhow::Result;
use log::{debug, info};
use serde::Deserialize;

#[derive(Debug, Clone, Deserialize)]
struct DevicesResponse {
pub devices: Vec<DevicesResponseDevice>,
}

#[derive(Debug, Clone, Deserialize)]
struct DevicesResponseDevice {
pub path: String,
pub driver: String,
}

pub fn get_reader(server: &str) -> Result<BufReader<TcpStream>> {
info!("Connecting to gpsd, server: {}", server);
Expand All @@ -22,12 +34,23 @@ pub fn get_reader(server: &str) -> Result<BufReader<TcpStream>> {
// DEVICES
let mut b = Vec::new();
reader.read_until(b'\n', &mut b)?;
let resp: DevicesResponse = serde_json::from_slice(&b)?;
debug!("Devices response: {}", String::from_utf8(b.clone())?);

// WATCH
let mut b = Vec::new();
reader.read_until(b'\n', &mut b)?;
debug!("Watch response: {}", String::from_utf8(b.clone())?);

for device in &resp.devices {
if device.driver == "u-blox" {
debug!("Configuring uBlox device {} for NAV-TIMEGPS", device.path);
writer.write_all(
format!("&{}=b5620601080001200001010000003294", device.path).as_bytes(),
)?;
writer.flush()?;
}
}

Ok(reader)
}

0 comments on commit efaa1b7

Please sign in to comment.