improved telemetry link
reduced send speed and improved receive logic to recover faster a next step is to try forgoing tokio-serial and the codec trait for (hopefully) better real-time performance
This commit is contained in:
parent
ad1f552151
commit
ad82a25329
2 changed files with 32 additions and 13 deletions
|
|
@ -3,7 +3,7 @@ use std::result;
|
|||
use anyhow::{anyhow, Ok};
|
||||
use common::{Response, RobotState};
|
||||
use framed::{BoxPayload, FRAME_END_SYMBOL};
|
||||
use tokio_util::{bytes::BytesMut, codec::{Decoder, Encoder}};
|
||||
use tokio_util::{bytes::{Buf, BytesMut}, codec::{Decoder, Encoder}};
|
||||
|
||||
pub struct FramedCodec {
|
||||
codec: framed::bytes::Codec,
|
||||
|
|
@ -25,11 +25,27 @@ impl Decoder for FramedCodec {
|
|||
return Ok(None);
|
||||
}
|
||||
|
||||
let terminator_idx = src.iter().position(|b| *b == 0).unwrap();
|
||||
|
||||
let (message, remainder) = match postcard::take_from_bytes_cobs(src) {
|
||||
result::Result::Ok(v) => v,
|
||||
result::Result::Err(e) => {
|
||||
src.clear();
|
||||
Err(e)?
|
||||
println!("telem err: {e}");
|
||||
// skip to the next terminator and try one more time
|
||||
src.advance(terminator_idx+1);
|
||||
if !src.contains(&0) {
|
||||
println!("incomplete frame");
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
match postcard::take_from_bytes_cobs(src) {
|
||||
result::Result::Ok(v) => v,
|
||||
result::Result::Err(e) => {
|
||||
src.clear();
|
||||
println!("telem err: {e}, cleared");
|
||||
return Ok(None);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use crossbeam::queue::ArrayQueue;
|
|||
use framed_codec::FramedCodec;
|
||||
use futures::{FutureExt, SinkExt, StreamExt, TryStreamExt};
|
||||
use nalgebra::{SimdPartialOrd, SimdValue, Vector3};
|
||||
use tokio::{io::{AsyncReadExt, AsyncWriteExt}, net::{TcpListener, TcpSocket}, sync::{broadcast::{self, error::RecvError, Receiver, Sender}, watch::{self, channel }, RwLock}, task::JoinHandle, time::{error::Elapsed, timeout}};
|
||||
use tokio::{io::{AsyncReadExt, AsyncWriteExt}, net::{TcpListener, TcpSocket}, sync::{broadcast::{self, error::RecvError, Receiver, Sender}, watch::{self, channel }, RwLock}, task::JoinHandle, time::{error::Elapsed, sleep, timeout}};
|
||||
use tokio_serial::SerialPortBuilderExt;
|
||||
use tokio_util::codec::Framed;
|
||||
|
||||
|
|
@ -29,10 +29,6 @@ async fn main() -> Result<()> {
|
|||
|
||||
let (mut write, mut read) = Framed::new(serial, FramedCodec::new()).split();
|
||||
|
||||
loop {
|
||||
write.send(RobotState::stopped()).await?;
|
||||
}
|
||||
|
||||
let (sender, mut command_receiver) = channel(RobotState::stopped());
|
||||
|
||||
let state = Arc::new(RwLock::new(RobotInfo {
|
||||
|
|
|
|||
Loading…
Reference in a new issue