| Crates.io | gpsd-json |
| lib.rs | gpsd-json |
| version | 0.1.0 |
| created_at | 2025-09-09 06:33:09.141129+00 |
| updated_at | 2025-09-09 06:33:09.141129+00 |
| description | A Rust library for parsing GPSD JSON protocol messages without dependencies on libgps. |
| homepage | |
| repository | https://github.com/Kato-emb/gpsd-json |
| max_upload_size | |
| id | 1830320 |
| size | 144,161 |
A Rust library for parsing GPSD JSON protocol messages without dependencies on libgps.
Add this to your Cargo.toml:
[dependencies]
gpsd-json = "0.1.0"
use gpsd_json::client::{GpsdClient, StreamOptions};
use futures::StreamExt;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to GPSD server
let mut client = GpsdClient::connect("127.0.0.1:2947").await?;
// Start streaming JSON data
let mut stream = client.stream(StreamOptions::json()).await?;
// Process GPS data
while let Some(Ok(msg)) = stream.next().await {
println!("Received: {:?}", msg);
}
Ok(())
}
use gpsd_json::client::{blocking, StreamOptions};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to GPSD server
let mut client = blocking::GpsdClient::connect("127.0.0.1:2947")?;
// Start streaming JSON data
let mut stream = client.stream(StreamOptions::json())?;
// Process GPS data
while let Some(Ok(msg)) = stream.next() {
println!("Received: {:?}", msg);
}
Ok(())
}
use gpsd_json::{
client::{GpsdClient, StreamOptions},
protocol::v3::ResponseMessage,
};
use futures::StreamExt;
#[tokio::main]
async fn main() {
let mut client = GpsdClient::connect("127.0.0.1:2947").await.unwrap();
// Start streaming with JSON format
let opts = StreamOptions::json()
.pps(true) // Enable PPS timing
.timing(true); // Enable timing info
let mut stream = client.stream(opts).await.unwrap();
// Receive and process data
while let Some(Ok(msg)) = stream.next().await {
match msg {
ResponseMessage::Tpv(tpv) => {
if let (Some(lat), Some(lon)) = (tpv.lat, tpv.lon) {
println!("Position: lat {}, lon {}", lat, lon);
}
}
ResponseMessage::Sky(sky) => {
println!("Satellites in view: {}", sky.satellites.len());
}
_ => {}
}
}
}
use gpsd_json::client::{GpsdClient, StreamOptions};
use futures::StreamExt;
#[tokio::main]
async fn main() {
let mut client = GpsdClient::connect("127.0.0.1:2947").await.unwrap();
// Stream raw data
let opts = StreamOptions::raw();
let mut stream = client.stream(opts).await.unwrap();
while let Some(Ok(data)) = stream.next().await {
let msg = String::from_utf8_lossy(&data);
println!("Raw data: {}", msg.trim_end());
}
}
See the examples directory for more usage examples:
tcp_simple.rs - Async TCP connection and JSON streaming with tokiotcp_blocking.rs - Blocking TCP connection and JSON streamingraw_stream.rs - Raw data streaming example with asyncFor detailed API documentation, please visit docs.rs/gpsd-json.
This project is licensed under the BSD-2-Clause License, following GPSD's licensing terms. See the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.