diff --git a/src/gps.rs b/src/gps.rs index 9a2460f..8bf4812 100644 --- a/src/gps.rs +++ b/src/gps.rs @@ -4,9 +4,49 @@ use std::sync::mpsc::SyncSender; use std::thread; use std::time::Duration; +use esp_idf_hal::prelude::*; +use esp_idf_hal::serial; + +use ublox::*; + use crate::modem::Msg; -pub fn main(sender: SyncSender) -> Result<(), anyhow::Error> { +pub fn main( + rx: esp_idf_hal::gpio::Gpio32, + tx: esp_idf_hal::gpio::Gpio33, + uart: serial::UART2, + sender: SyncSender, +) -> Result<(), anyhow::Error> { + let serial_pins = serial::Pins { + tx, + rx, + cts: None, + rts: None, + }; + let _serial: serial::Serial = serial::Serial::new( + uart, + serial_pins, + serial::config::Config::default().baudrate(Hertz(9600)), + )?; + + let mut parser = Parser::default(); + let mut it = parser.consume(&raw_packet); + + loop { + match it.next() { + Some(Ok(packet)) => { + println!("We've received a &PacketRef, we can handle it ... {:?}", packet); + } + Some(Err(err)) => { + println!("Received a malformed packet {:?}", err); + } + None => { + println!("The internal buffer is now empty"); + break; + } + } + } + println!("entering GPS sender loop ..."); for i in 0..20 { println!("sending GPS message ({}) of 20 ...", i);