Skip to content

Commit

Permalink
Add state checkpoints, `blockwise::{blockwise_states_print,blockwise_…
Browse files Browse the repository at this point in the history
…states_debug}`
  • Loading branch information
j-devel committed Mar 25, 2024
1 parent 0de4575 commit d5009ce
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
6 changes: 2 additions & 4 deletions examples/xbd-net/modules/minerva_xbd/gcoap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
12 changes: 7 additions & 5 deletions examples/xbd-net/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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"); // !!!!
}
}
Expand Down
14 changes: 13 additions & 1 deletion examples/xbd-net/src/xbd/blockwise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ static mut BLOCKWISE_STATES: &'static mut [Option<BlockwiseState>] = &mut [ARRAY

//

pub fn blockwise_states_print() {
crate::println!("blockwise_states_print(): states: {:?}", BlockwiseData::states());
}

pub fn blockwise_states_debug() -> heapless::Vec<bool, BLOCKWISE_STATES_MAX> {
BlockwiseData::states()
.iter()
.map(|x| x.is_some())
.collect::<_>()
}

pub struct BlockwiseData();

impl BlockwiseData {
Expand Down Expand Up @@ -150,6 +161,7 @@ impl BlockwiseData {
} else { // <blockwise COMPLETE>
stat.add_to_stream(None);
BlockwiseData::set_state_last(None);
crate::println!("!!!! debug - set None to {}", idx);
}

return None;
Expand All @@ -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 <blockwise NEW>, via idx={}/{}, where states: {:?}",
crate::println!("debug <blockwise NEW>, via idx={}/{}, where states: {:?}",
idx, states.len(), states);

let (addr, uri) = addr_uri.unwrap();
Expand Down
1 change: 1 addition & 0 deletions examples/xbd-net/src/xbd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d5009ce

Please sign in to comment.