From ecd0800891563611875320cdabe175d454e83b6a Mon Sep 17 00:00:00 2001 From: Andy Killorin <37423245+Speedy6451@users.noreply.github.com> Date: Sun, 2 Feb 2025 15:50:10 -0500 Subject: [PATCH] enable on start --- common/src/lib.rs | 2 +- northbridge/src/main.rs | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/common/src/lib.rs b/common/src/lib.rs index ca63774..f7004cd 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -27,7 +27,7 @@ pub struct Response { pub uptime_micros: u64, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Clone)] pub enum SensorData { /// degrees per second Gyro(Vector3), diff --git a/northbridge/src/main.rs b/northbridge/src/main.rs index 396ee97..62179dd 100644 --- a/northbridge/src/main.rs +++ b/northbridge/src/main.rs @@ -4,6 +4,7 @@ use anyhow::{Context, Result}; use common::{Command, Response, BAUDRATE}; use framed_codec::FramedCodec; use futures::{SinkExt, StreamExt}; +use tokio::sync::broadcast; use tokio_serial::SerialPortBuilderExt; use tokio_util::codec::Framed; @@ -13,6 +14,8 @@ mod framed_codec; async fn main() -> Result<()> { let mut serial = tokio_serial::new("/dev/ttyAMA0", BAUDRATE).open_native_async()?; + let (sensor_sender, sensor_data) = broadcast::channel(5); + serial.set_exclusive(false)?; let (mut write, read) = Framed::new(serial, FramedCodec::new()).split(); @@ -21,11 +24,23 @@ async fn main() -> Result<()> { Ok(postcard::from_bytes::(&data.ok().context("decode err")?)?) }); + println!("starting"); + write.send(Command::Enable).await?; - while let Some(data) = read.next().await { - dbg!(data?); + while let Some(Ok(data)) = read.next().await { + 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(())