initial gps read/write and publish

This commit is contained in:
Vladan Popovic 2022-07-11 16:17:17 +02:00
parent df46a56cc3
commit 1fc1218ba6

View file

@ -4,9 +4,49 @@ use std::sync::mpsc::SyncSender;
use std::thread; use std::thread;
use std::time::Duration; use std::time::Duration;
use esp_idf_hal::prelude::*;
use esp_idf_hal::serial;
use ublox::*;
use crate::modem::Msg; use crate::modem::Msg;
pub fn main(sender: SyncSender<Msg>) -> Result<(), anyhow::Error> { pub fn main<T: Sync + Send>(
rx: esp_idf_hal::gpio::Gpio32<T>,
tx: esp_idf_hal::gpio::Gpio33<T>,
uart: serial::UART2,
sender: SyncSender<Msg>,
) -> Result<(), anyhow::Error> {
let serial_pins = serial::Pins {
tx,
rx,
cts: None,
rts: None,
};
let _serial: serial::Serial<serial::UART2, _, _> = 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 ..."); println!("entering GPS sender loop ...");
for i in 0..20 { for i in 0..20 {
println!("sending GPS message ({}) of 20 ...", i); println!("sending GPS message ({}) of 20 ...", i);