use rpi_embedded::uart::{Uart,Parity};
use std::string::String;
pub enum Settings {
Baudgps,
Baudarduino,
Data,
Stopbit,
}
impl Settings{
pub fn get_baud(&self) -> u32{
let value : u32;
match self{
Settings::Baudgps => {value = 9600}
Settings::Baudarduino => {value = 115_200}
Settings::Data =>{value = 8}
Settings::Stopbit =>{value = 1}
}
value
}
}
struct GPS{
pub longitude: String,
pub latitude: String,
pub altitude: String,
pub time: String,
pub satellites: String,
pub indicator: String
}
impl GPS{
pub fn new() -> Self{
let mut _out = Self{
longitude: "".to_string(), latitude: "".to_string(),
altitude: "".to_string(),
time:"".to_string(),
satellites: "".to_string(),
indicator:"".to_string(),
};
_out
}
pub fn spliting(&mut self,string_read:String){
let reading = string_read.split(',');
let read_vec: Vec<&str> = reading.collect();
self.indicator = read_vec[0].to_string();
if read_vec[0] == "$GPGGA"{
self.gps_system(read_vec);
self.gps_print();
}
}
pub fn gps_system(&mut self,read_vec: Vec<&str>){ self.latitude = read_vec[2].to_string() + "" + &read_vec[3].to_string();
self.longitude = read_vec[4].to_string()+ "" + &read_vec[5].to_string();
self.altitude = read_vec[9].to_string() + "" + &read_vec[10].to_string();
self.time = read_vec[1].to_string();
self.satellites = read_vec[7].to_string();
}
pub fn gps_print(&mut self){ let print_str=format! (
"\n
Time: {}h{}m{}s \n
Latitude: {} \n
Longitude: {} \n
Altitude: {} \n
Number of Satellites: {} \n",&self.time[0..2],&self.time[2..4],&self.time[4..6],self.latitude,self.longitude,self.altitude,self.satellites);
println!("Useful data: {}",print_str);
}
}