dataGPS 0.1.1

Adafruit Ultimate GPS: read data like longitude and latitude about the GPS module
Documentation
//! # test of DataGPS
//!
//! `DataGPS` is a collection of utilities to read GPS adafruit data.
//! Print of all important data of GPS adafruit like Altitude, Latitude, Longitude
//!
//! # Examples of getting data
//!
//! ```
//!
//! let x = DataGPS::new(Bauds::Baud9600);
//! x.read_all_data();
//!
//!
//! ```

use std::{time::Duration};
use rpi_embedded::uart::{Parity, Uart};
    /// Enum to be able to set the settings
pub enum Bauds{
    Baud9600,
    Baud57600,
    Baud115200
}

impl Bauds{
    pub fn get_value(&self) -> u32{
        let v: u32;
        match self{
            Bauds::Baud9600 => { v = 9600 }
            Bauds::Baud57600 => { v = 57600 }
            Bauds::Baud115200 => { v = 115200 }
        }
        v
    }
}
/// Struct of DataGPS for latitude, longitude, altitude, time and uart
pub struct DataGPS{ //$GPGGA
    uart: Uart,
    time:String,
    latitude:String,
    longitude:String,
    altitude:String,
}
/// Implementation of functions for DataGPS
impl DataGPS{
    ///Create a new Uart connections and the object DataGPS
    pub fn new(baud: Bauds) -> Self{
        let mut _uart = Uart::new(baud.get_value(), Parity::None, 8, 1).expect("Error UART");
        _uart.set_read_mode(1, Duration::default()).expect("Error setting read mode");

        Self{
            uart: _uart,
            time: "".to_string(),
            latitude: "".to_string(),
            longitude: "".to_string(),
            altitude: "".to_string()
        }
    }
    ///Read the data from the GPS module and put in the values of the struct with a println
    pub fn read_all_data(&mut self) {
        let input = self.uart.read_line().expect("Error reading from Arduino");
        if input.contains("$GPGGA"){
            let x : Vec<&str> = input.split(",").collect();
            self.set_data(x[1].to_string(), x[2].to_string()+x[3], x[4].to_string()+x[5], x[9].to_string()+x[10]);
            println!("Latitude: {:?}, Longitude: {:?},Time: {:?},Altitude: {:?}", self.latitude, self.longitude, self.time, self.altitude);
        }
    }
    ///Set the important data
    fn set_data(&mut self, time:String, latitude: String, longitude: String, altitude: String){
        self.time = time;
        self.latitude = latitude;
        self.longitude = longitude;
        self.altitude = altitude;

    }
    ///Return altitude if it is present
    pub fn get_altitude(&mut self) -> String{
        if self.altitude.is_empty(){
           "No altitude".to_string()
        }else{
           self.altitude.to_string()
        }
    }

/// # Examples of get_altitude
///
/// ```
///
/// let x = DataGPS::new(Bauds::Baud9600);
/// x.read_all_data();
/// println!("Altitude: {:?}",x.get_altitude());
///
///
/// ```

    ///Return latitude if it is present
    pub fn get_latitude(&mut self) -> String{
        if self.latitude.is_empty(){
            "No latitude".to_string()
        }else{
            self.latitude.to_string()
        }
    }
    ///Return time if it is present
    pub fn get_time(&mut self) -> String{
        if self.time.is_empty(){
            "No value".to_string()
        }else{
            self.time.to_string()
        }
    }
    ///Return longitude if it is present
    pub fn get_longitude(&mut self) -> String{
        if self.longitude.is_empty(){
            "No value".to_string()
        }else{
            self.longitude.to_string()
        }
    }
    ///Return baud rate
    pub fn get_baud_rate(&self) -> u32{
        self.uart.baud_rate()
    }
    ///Set baud rate of UART connection
    pub fn set_baud_rate(&mut self,baud_rate:&Bauds) {
        self.uart.set_baud_rate(baud_rate.get_value()).expect("Error setting baud rate");
    }
}