From 69b3d477543d71b0590cb08f86b1313dd10531f5 Mon Sep 17 00:00:00 2001 From: James Munns Date: Mon, 4 Nov 2024 17:03:52 +0100 Subject: [PATCH] Correct timeout for schema retrieval --- example/firmware/Cargo.lock | 2 +- example/workbook-host/Cargo.lock | 2 +- source/postcard-rpc-test/Cargo.lock | 2 +- source/postcard-rpc/Cargo.toml | 2 +- .../src/server/impls/embassy_usb_v0_3.rs | 26 ++++++++----------- 5 files changed, 15 insertions(+), 19 deletions(-) diff --git a/example/firmware/Cargo.lock b/example/firmware/Cargo.lock index d5db64d..f724e21 100644 --- a/example/firmware/Cargo.lock +++ b/example/firmware/Cargo.lock @@ -1135,7 +1135,7 @@ dependencies = [ [[package]] name = "postcard-rpc" -version = "0.10.4" +version = "0.10.5" dependencies = [ "embassy-executor", "embassy-futures 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/example/workbook-host/Cargo.lock b/example/workbook-host/Cargo.lock index bba80a6..bbe3116 100644 --- a/example/workbook-host/Cargo.lock +++ b/example/workbook-host/Cargo.lock @@ -470,7 +470,7 @@ dependencies = [ [[package]] name = "postcard-rpc" -version = "0.10.4" +version = "0.10.5" dependencies = [ "heapless 0.8.0", "maitake-sync", diff --git a/source/postcard-rpc-test/Cargo.lock b/source/postcard-rpc-test/Cargo.lock index 74172e5..97cc136 100644 --- a/source/postcard-rpc-test/Cargo.lock +++ b/source/postcard-rpc-test/Cargo.lock @@ -396,7 +396,7 @@ dependencies = [ [[package]] name = "postcard-rpc" -version = "0.10.4" +version = "0.10.5" dependencies = [ "heapless 0.8.0", "maitake-sync", diff --git a/source/postcard-rpc/Cargo.toml b/source/postcard-rpc/Cargo.toml index 778ab59..a07b972 100644 --- a/source/postcard-rpc/Cargo.toml +++ b/source/postcard-rpc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "postcard-rpc" -version = "0.10.4" +version = "0.10.5" authors = ["James Munns "] edition = "2021" repository = "https://github.com/jamesmunns/postcard-rpc" diff --git a/source/postcard-rpc/src/server/impls/embassy_usb_v0_3.rs b/source/postcard-rpc/src/server/impls/embassy_usb_v0_3.rs index 9a8f08d..9268d6c 100644 --- a/source/postcard-rpc/src/server/impls/embassy_usb_v0_3.rs +++ b/source/postcard-rpc/src/server/impls/embassy_usb_v0_3.rs @@ -1,29 +1,25 @@ //! Implementation using `embassy-usb` and bulk interfaces +use crate::{ + header::{VarHeader, VarKey, VarKeyKind, VarSeq}, + server::{WireRx, WireRxErrorKind, WireSpawn, WireTx, WireTxErrorKind}, + standard_icd::LoggingTopic, + Topic, +}; use core::fmt::Arguments; +use core::sync::atomic::{AtomicU8, Ordering}; use embassy_executor::{SpawnError, SpawnToken, Spawner}; use embassy_futures::select::{select, Either}; use embassy_sync::{blocking_mutex::raw::RawMutex, mutex::Mutex}; use embassy_time::Timer; use embassy_usb_driver::{Driver, EndpointError, EndpointIn, EndpointOut}; use serde::Serialize; - -use crate::{ - header::{VarHeader, VarKey, VarKeyKind, VarSeq}, - server::{WireRx, WireRxErrorKind, WireSpawn, WireTx, WireTxErrorKind}, - standard_icd::LoggingTopic, - Topic, -}; - -use core::sync::atomic::{Ordering, AtomicU8}; use static_cell::ConstStaticCell; -struct PoststationHandler { - -} +struct PoststationHandler {} static STINDX: AtomicU8 = AtomicU8::new(0xFF); -static HDLR: ConstStaticCell = ConstStaticCell::new(PoststationHandler { }); +static HDLR: ConstStaticCell = ConstStaticCell::new(PoststationHandler {}); impl embassy_usb::Handler for PoststationHandler { fn get_string(&mut self, index: embassy_usb::types::StringIndex, lang_id: u16) -> Option<&str> { @@ -412,8 +408,8 @@ where } // Calculate an estimated timeout based on the number of frames we need to send - // For now, we use 2ms/frame - let frames = out.len() / 64; + // For now, we use 2ms/frame, rounded UP + let frames = (out.len() + 63) / 64; let timeout_ms = frames * 2; let send_fut = async {