From 1bc575d06cf4d664b20b6cdc83ef51d1a041a7ef Mon Sep 17 00:00:00 2001 From: Frederik Menke Date: Mon, 17 Oct 2022 22:42:47 +0200 Subject: [PATCH] Fix M114 throughput issues We must wait for Marlin to boot before sending any commands. Otherwise it doesn't reply anymore. --- green/Marlin | 2 +- red/justfile | 4 ++-- red/src/main.rs | 19 +++++++++---------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/green/Marlin b/green/Marlin index 076afd2..b58bbb5 160000 --- a/green/Marlin +++ b/green/Marlin @@ -1 +1 @@ -Subproject commit 076afd2c617110c8f2e7df062329e32bd0f0269b +Subproject commit b58bbb57e5ca2a5e6d7af0ade2c191b2e89f6081 diff --git a/red/justfile b/red/justfile index e29dbb7..a02cc9b 100644 --- a/red/justfile +++ b/red/justfile @@ -3,5 +3,5 @@ build: rrun: #scp -r ./src olimex@muele.local:red/ - rsync -rv --filter=':- .gitignore' ../red olimex@muele.local: - ssh olimex@muele.local "cd red; /home/olimex/.cargo/bin/cargo run" \ No newline at end of file + rsync -rvu --filter=':- .gitignore' ../red olimex@muele.local: + ssh olimex@muele.local "cd red; /home/olimex/.cargo/bin/cargo run;" \ No newline at end of file diff --git a/red/src/main.rs b/red/src/main.rs index dae3285..075327e 100644 --- a/red/src/main.rs +++ b/red/src/main.rs @@ -57,21 +57,20 @@ async fn main() -> tokio_serial::Result<()> { let (mut writer, mut reader) = LineCodec.framed(port).split(); println!("Starting read."); let reader_task = async move { + let mut counter = 0; while let Some(line_result) = reader.next().await { let line = line_result.expect("Failed to read line"); - println!("{}", line); - } - }; - let writer_task = async move { - loop { - if let Err(e) = writer.send("M114\n".into()).await { - println!("{:?}", e); - break; + if line.contains("ok") || line.contains("Loaded") { + if let Err(e) = writer.send("M114\n".into()).await { + println!("{:?}", e); + break; + } } - tokio::time::sleep(std::time::Duration::from_secs(1)).await; + counter += 1; + println!("updates received: {}", counter); } }; - tokio::join!(writer_task, reader_task); + reader_task.await; Ok(()) } \ No newline at end of file