switched northbridge -> southbridge communication to length-data

buffereduart peek does not appear to work, and
coms are very stable with shielded wire
This commit is contained in:
Andy Killorin 2025-02-04 13:06:38 -05:00
commit a9573dc8bc
Signed by: ank
GPG key ID: 23F9463ECB67FE8C
2 changed files with 40 additions and 47 deletions

View file

@ -37,9 +37,8 @@ impl Encoder<Vec<u8>> for FramedCodec {
type Error = framed::Error;
fn encode(&mut self, item: Vec<u8>, dst: &mut BytesMut) -> Result<(), Self::Error> {
let encoded = self.codec.encode_to_box(&item)?;
dst.extend_from_slice(&encoded);
dst.extend_from_slice(&item.len().to_be_bytes());
dst.extend_from_slice(&item);
Ok(())
}

View file

@ -30,26 +30,33 @@ async fn main() -> Result<()> {
println!("starting");
write.send(Command::Enable).await?;
write.flush().await?;
while let Some(Ok(data)) = read.next().await {
if data.enabled {
write.send(Command::FeedWatchdog).await?;
loop {
//let Some(Ok(data)) = read.next().await else {
// continue;
//};
//if data.enabled {
// write.send(Command::FeedWatchdog).await?;
// write.flush().await?;
} else {
println!("enabled southbridge");
write.send(Command::Enable).await?;
}
//} else {
// println!("enabled southbridge");
// write.send(Command::Enable).await?;
//}
dbg!(&data);
write.send(Command::Enable).await?;
write.flush().await?;
if let Some(data) = data.sensor_data {
let _ = sensor_sender.send(data);
}
//dbg!(&data);
write.send(commands.borrow().clone()).await?;
//if let Some(data) = data.sensor_data {
// let _ = sensor_sender.send(data);
//}
write.send(dbg!(commands.borrow().clone())).await?;
write.flush().await?;
}
Ok(())
}
async fn control(sender: Sender<Command>) -> Result<()> {