Skip to content

Commit 8b3686c

Browse files
committed
Get gcoap::gcoap_get_blockwise() to work, refactor
1 parent e4208ac commit 8b3686c

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

examples/xbd-net/debug.setup.bash

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ alias nnn='nn-notap'
44
alias ee-wifi='make run-esp32-wroom32'
55

66
alias mr='EMU_NATIVE_TAP=tap1 make native-run-riot'
7+
alias tb='mr | a debug' # ()> b
78

89
alias ee='echo "assuming tap0/br0 is already set up" && make build-esp32 && RIOT_BOARD=esp32-ethernet-kit-v1_0 EMU_ESP32_NIC="tap,model=open_eth,ifname=tap0,script=no,downscript=no" make esp32-run-riot'
910
alias nn='echo "assuming tap1 is already set up" && IPV6_AUTO=0 IPV6_ADDR=fe80::78ec:5fff:febd:add9 make build-native && EMU_NATIVE_TAP=tap1 make native-run-riot'

examples/xbd-net/src/lib.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,13 @@ async fn xbd_main() -> Result<(), i8> {
151151
Ok(())
152152
}
153153

154-
use futures_util::stream::StreamExt;
155-
use xbd::{BlockwiseError, BLOCKWISE_STATES_MAX, blockwise_states_print, blockwise_states_debug};
154+
use xbd::gcoap::{
155+
BlockwiseError, BLOCKWISE_STATES_MAX,
156+
blockwise_states_print, blockwise_states_debug};
156157

157158
async fn test_blockwise(addr_self: &str) -> Result<(), BlockwiseError> {
158-
use xbd::gcoap::{gcoap_get, GcoapMemoState};
159+
use xbd::gcoap::{gcoap_get, gcoap_get_blockwise, GcoapMemoState};
160+
use futures_util::StreamExt;
159161

160162
if 0 == 1 { // !! do test with alias='nns'
161163
println!("🧪 debug NEW [gcoap-dtls]");
@@ -211,7 +213,7 @@ $ libcoap/local/bin/coap-client -m get coaps://[::1]/.well-known/core -k "secret
211213

212214
//
213215

214-
let get_blockwise = || Xbd::async_gcoap_get_blockwise(addr_self, "/const/song.txt");
216+
let get_blockwise = || gcoap_get_blockwise(addr_self, "/const/song.txt");
215217

216218
//
217219

@@ -292,7 +294,7 @@ $ libcoap/local/bin/coap-client -m get coaps://[::1]/.well-known/core -k "secret
292294
//
293295

294296
println!("🧪 debug NEW [blockwise-timeout]");
295-
let get_blockwise_timeout = || Xbd::async_gcoap_get_blockwise(
297+
let get_blockwise_timeout = || gcoap_get_blockwise(
296298
"[::1]:5680", "/const/song.txt"); // induce `Timeout`, not 5683
297299

298300
let mut bs = get_blockwise_timeout()?;
@@ -306,7 +308,7 @@ $ libcoap/local/bin/coap-client -m get coaps://[::1]/.well-known/core -k "secret
306308
//
307309

308310
println!("🧪 debug NEW [blockwise-resp-none]");
309-
let get_blockwise_resp_none = || Xbd::async_gcoap_get_blockwise(
311+
let get_blockwise_resp_none = || gcoap_get_blockwise(
310312
"[::1]:5683", "/const/song2.txt"); // induce `Resp(None)`
311313

312314
let mut bs = get_blockwise_resp_none()?;

examples/xbd-net/src/xbd/gcoap.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use core::{future::Future, pin::Pin, task::{Context, Poll, Waker}};
22
use core::ffi::c_void;
33
use futures_util::task::AtomicWaker;
4-
use super::{BlockwiseData, BLOCKWISE_HDR_MAX};
54
use mcu_if::utils::u8_slice_from;
65

76
pub const REQ_ADDR_MAX: usize = 64;
@@ -75,6 +74,14 @@ const COAP_METHOD_PUT : CoapMethod = 0x03;
7574

7675
//
7776

77+
pub use super::blockwise::{
78+
BlockwiseError, BLOCKWISE_STATES_MAX,
79+
blockwise_states_print, blockwise_states_debug};
80+
81+
use super::blockwise::{BlockwiseStream, BlockwiseData, BLOCKWISE_HDR_MAX};
82+
pub fn gcoap_get_blockwise(addr: &str, uri: &str) -> Result<BlockwiseStream, BlockwiseError> {
83+
BlockwiseData::send_blockwise_req(None, Some((addr, uri)), None)
84+
}
7885

7986
pub fn gcoap_get(addr: &str, uri: &str) -> impl Future<Output = GcoapMemoState> + 'static {
8087
Req::new(COAP_METHOD_GET, addr, uri, None)

examples/xbd-net/src/xbd/mod.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,10 @@ pub use shell::process_shell_stream;
1313

1414
mod stream;
1515

16-
mod blockwise;
17-
use blockwise::{BlockwiseStream, BlockwiseData, BLOCKWISE_HDR_MAX};
18-
pub use blockwise::{
19-
BlockwiseError, BLOCKWISE_STATES_MAX,
20-
blockwise_states_print, blockwise_states_debug};
21-
2216
mod timeout;
2317
use timeout::Timeout;
2418

19+
mod blockwise;
2520
pub mod gcoap;
2621

2722
use core::future::Future;
@@ -107,9 +102,4 @@ impl Xbd {
107102
pub fn async_set_timeout<F>(msec: u32, cb: F) -> impl Future<Output = ()> + 'static where F: FnOnce() + 'static {
108103
Timeout::new(msec, Some(Box::new(cb)))
109104
}
110-
111-
// !!!!
112-
pub fn async_gcoap_get_blockwise(addr: &str, uri: &str) -> Result<BlockwiseStream, BlockwiseError> {
113-
BlockwiseData::send_blockwise_req(None, Some((addr, uri)), None)
114-
}
115105
}

examples/xbd-net/src/xbd/shell.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ async fn test_blockwise_all() {
216216
async fn test_async_blockwise() {
217217
println!("test_async_blockwise(): ^^");
218218

219-
let mut bs = crate::Xbd::async_gcoap_get_blockwise(
219+
let mut bs = crate::xbd::gcoap::gcoap_get_blockwise(
220220
"[::1]:5683", "/const/song.txt").unwrap();
221221
while let Some(req) = bs.next().await {
222222
println!("@@ out: {:?}", req.await);

0 commit comments

Comments
 (0)