From d5009ce5ef1a6c0771f349554dae5eb7ed0e32de Mon Sep 17 00:00:00 2001 From: j-devel <38098238+j-devel@users.noreply.github.com> Date: Mon, 25 Mar 2024 12:43:29 +0700 Subject: [PATCH] Add state checkpoints, `blockwise::{blockwise_states_print,blockwise_states_debug}` --- examples/xbd-net/modules/minerva_xbd/gcoap.c | 6 ++---- examples/xbd-net/src/lib.rs | 12 +++++++----- examples/xbd-net/src/xbd/blockwise.rs | 14 +++++++++++++- examples/xbd-net/src/xbd/mod.rs | 1 + 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/examples/xbd-net/modules/minerva_xbd/gcoap.c b/examples/xbd-net/modules/minerva_xbd/gcoap.c index 1bd270f..57eb321 100644 --- a/examples/xbd-net/modules/minerva_xbd/gcoap.c +++ b/examples/xbd-net/modules/minerva_xbd/gcoap.c @@ -30,7 +30,6 @@ extern size_t xbd_blockwise_state_index(void); extern char * xbd_blockwise_addr_ptr(size_t idx); extern char * xbd_blockwise_uri_ptr(size_t idx); - extern size_t xbd_blockwise_hdr_copy(const uint8_t *buf, size_t buf_sz, size_t idx); extern void xbd_blockwise_async_gcoap_req( @@ -97,7 +96,7 @@ void xbd_gcoap_req_send( printf("@@ xbd_gcoap_req_send(): addr: %s, uri: %s hdr_len: %u\n", addr, uri, hdr_len); if (blockwise) { - printf("@@ sending (blockwise_state_index: %u)\n", idx); + printf("@@ debug - blockwise_state_index: %u\n", idx); } printf("@@ payload: %p payload_len: %d\n", payload, payload_len); @@ -207,8 +206,7 @@ static void _resp_handler_blockwise_async(const gcoap_request_memo_t *memo, coap last_addr, strlen(last_addr), last_uri, last_uri_len, (char *)pdu->hdr, len); - } - else { // @@ WIP similar cleanup logic on blockwise timeout + } else { puts("--- blockwise complete ---"); xbd_blockwise_async_gcoap_complete(idx); } diff --git a/examples/xbd-net/src/lib.rs b/examples/xbd-net/src/lib.rs index 498298f..b830284 100644 --- a/examples/xbd-net/src/lib.rs +++ b/examples/xbd-net/src/lib.rs @@ -158,9 +158,10 @@ async fn xbd_main() { // use futures_util::stream::StreamExt; + use xbd::{blockwise_states_print,blockwise_states_debug}; let mut debug_count = 0; - println!("!! sending NEW [blockwise-1]"); + println!("!! debug NEW [blockwise-1]"); let mut bs = Xbd::async_gcoap_get_blockwise(addr_self, "/const/song.txt").unwrap(); while let Some(Some(req)) = bs.next().await { println!("req: {:?}", req); @@ -170,17 +171,18 @@ async fn xbd_main() { debug_count += 1; if debug_count == 3 { // !!!! - //if debug_count == 9 { // !!!! right after [blockwise-1] done - println!("!! sending NEW [blockwise-2]"); + println!("!! debug NEW [blockwise-2]"); let mut bs = Xbd::async_gcoap_get_blockwise(addr_self, "/const/song.txt").unwrap(); while let Some(Some(req)) = bs.next().await { let out = req.await; println!("@@ out_2: {:?}", out); - //panic!("!!"); } - //panic!("$$"); + blockwise_states_print(); // !!!! + assert_eq!(blockwise_states_debug()[0], false, "debug"); // !!!! } } + assert_eq!(blockwise_states_debug()[1], false, "debug"); // !!!! + panic!("ok"); // !!!! } } diff --git a/examples/xbd-net/src/xbd/blockwise.rs b/examples/xbd-net/src/xbd/blockwise.rs index 52c8188..4fb4b80 100644 --- a/examples/xbd-net/src/xbd/blockwise.rs +++ b/examples/xbd-net/src/xbd/blockwise.rs @@ -88,6 +88,17 @@ static mut BLOCKWISE_STATES: &'static mut [Option] = &mut [ARRAY // +pub fn blockwise_states_print() { + crate::println!("blockwise_states_print(): states: {:?}", BlockwiseData::states()); +} + +pub fn blockwise_states_debug() -> heapless::Vec { + BlockwiseData::states() + .iter() + .map(|x| x.is_some()) + .collect::<_>() +} + pub struct BlockwiseData(); impl BlockwiseData { @@ -150,6 +161,7 @@ impl BlockwiseData { } else { // stat.add_to_stream(None); BlockwiseData::set_state_last(None); + crate::println!("!!!! debug - set None to {}", idx); } return None; @@ -164,7 +176,7 @@ impl BlockwiseData { let bs = state.get_stream(); // makes sure stream is initialized before `.add_to_stream()` let states = Self::states(); - crate::println!("sending , via idx={}/{}, where states: {:?}", + crate::println!("debug , via idx={}/{}, where states: {:?}", idx, states.len(), states); let (addr, uri) = addr_uri.unwrap(); diff --git a/examples/xbd-net/src/xbd/mod.rs b/examples/xbd-net/src/xbd/mod.rs index 9b049f3..46e95ea 100644 --- a/examples/xbd-net/src/xbd/mod.rs +++ b/examples/xbd-net/src/xbd/mod.rs @@ -11,6 +11,7 @@ mod stream; mod blockwise; use blockwise::{BlockwiseStream, BlockwiseData}; +pub use blockwise::{blockwise_states_print,blockwise_states_debug}; mod timeout; use timeout::Timeout;