1
Fork 0

enable on start

This commit is contained in:
Andy Killorin 2025-02-02 15:50:10 -05:00
parent 91ed6eeb14
commit ecd0800891
Signed by: ank
GPG key ID: 23F9463ECB67FE8C
2 changed files with 19 additions and 4 deletions

View file

@ -27,7 +27,7 @@ pub struct Response {
pub uptime_micros: u64, pub uptime_micros: u64,
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug, Clone)]
pub enum SensorData { pub enum SensorData {
/// degrees per second /// degrees per second
Gyro(Vector3<f32>), Gyro(Vector3<f32>),

View file

@ -4,6 +4,7 @@ use anyhow::{Context, Result};
use common::{Command, Response, BAUDRATE}; use common::{Command, Response, BAUDRATE};
use framed_codec::FramedCodec; use framed_codec::FramedCodec;
use futures::{SinkExt, StreamExt}; use futures::{SinkExt, StreamExt};
use tokio::sync::broadcast;
use tokio_serial::SerialPortBuilderExt; use tokio_serial::SerialPortBuilderExt;
use tokio_util::codec::Framed; use tokio_util::codec::Framed;
@ -13,6 +14,8 @@ mod framed_codec;
async fn main() -> Result<()> { async fn main() -> Result<()> {
let mut serial = tokio_serial::new("/dev/ttyAMA0", BAUDRATE).open_native_async()?; let mut serial = tokio_serial::new("/dev/ttyAMA0", BAUDRATE).open_native_async()?;
let (sensor_sender, sensor_data) = broadcast::channel(5);
serial.set_exclusive(false)?; serial.set_exclusive(false)?;
let (mut write, read) = Framed::new(serial, FramedCodec::new()).split(); let (mut write, read) = Framed::new(serial, FramedCodec::new()).split();
@ -21,11 +24,23 @@ async fn main() -> Result<()> {
Ok(postcard::from_bytes::<Response>(&data.ok().context("decode err")?)?) Ok(postcard::from_bytes::<Response>(&data.ok().context("decode err")?)?)
}); });
println!("starting");
write.send(Command::Enable).await?;
while let Some(data) = read.next().await { while let Some(Ok(data)) = read.next().await {
dbg!(data?); if data.enabled {
write.send(Command::FeedWatchdog).await?;
write.send(Command::Enable).await?; } else {
println!("enabled southbridge");
write.send(Command::Enable).await?;
}
dbg!(&data);
if let Some(data) = data.sensor_data {
let _ = sensor_sender.send(data);
}
} }
Ok(()) Ok(())