Expand description
§yahboom_gps
yahboom_gps
is a Rust library for initializing and reading GPS data from a Yahboom GPS module via a serial port.
§Example
Here is a complete example demonstrating how to use the yahboom_gps
library to initialize the GPS module, read GPS messages, and parse GPS data.
use yahboom_gps::{gps_init, read_complete_gps_message, parse_gps_data};
use anyhow::Result;
fn main() -> Result<()> {
// Initialize the GPS module
let mut port = gps_init("COM3", 9600)?;
// Continuously read and parse GPS messages
while let Ok(Some(message)) = read_complete_gps_message(&mut port) {
// Parse the GPS data
let parsed_data = parse_gps_data(&message);
// Print the parsed GPS data
println!("Parsed GPS Data: {}", serde_json::to_string_pretty(&parsed_data)?);
println!("--- End of message ---");
}
Ok(())
}
Successful output should look like this:
Parsed GPS Data: {
"BDGSA": {
"fix_type": "1",
"hdop": "2.5",
"mode": "A",
"pdop": "251.5",
"vdop": "0.5*13"
},
"BDGSV": {
"message_number": "1",
"num_of_messages": "1",
"satellites_in_view": "00*168"
},
"GNGGA": {
"altitude": "",
"fix_quality": "0",
"height_of_geoid": "",
"horizontal_dilution": "1.5",
"latitude": "",
"longitude": "",
"num_of_satellites": "00",
"time": ""
},
"GNGLL": {
"latitude": "",
"longitude": "",
"status": "V",
"time": ""
},
"GNRMC": {
"date": "",
"latitude": "",
"longitude": "",
"speed": "",
"status": "V",
"time": "",
"variation": ""
},
"GNVTG": {
"speed_kmph": "",
"speed_knots": "",
"track_degrees_magnetic": "",
"track_degrees_true": ""
},
"GNZDA": {
"day": "",
"local_zone_hours": "",
"local_zone_minutes": "*6",
"month": "",
"time": "",
"year": ""
},
"GPGSA": {
"fix_type": "1",
"hdop": "2.5",
"mode": "A",
"pdop": "5.0",
"vdop": "2.0*02"
},
"GPGSV": {
"message_number": "1",
"num_of_messages": "1",
"satellites_in_view": "0*79"
},
"GPTXT": {
"text": "01,01,01,ANTENNA OPEN*25"
}
}
--- End of message ---
Functions§
- gps_
init - Initializes the GPS module
- parse_
gps_ data - Parses GPS data from an NMEA sentence
- read_
complete_ gps_ message - Reads a complete GPS message from the serial port