diff --git a/examples/rust-gcoap/Cargo.lock b/examples/rust-gcoap/Cargo.lock index 38bc8beb17..0cf8a67238 100644 Binary files a/examples/rust-gcoap/Cargo.lock and b/examples/rust-gcoap/Cargo.lock differ diff --git a/examples/rust-gcoap/Cargo.toml b/examples/rust-gcoap/Cargo.toml index 7bb7b50be4..c461e5e75b 100644 --- a/examples/rust-gcoap/Cargo.toml +++ b/examples/rust-gcoap/Cargo.toml @@ -23,10 +23,11 @@ riot-wrappers = { version = "^0.9.0", features = [ "set_panic_handler", "panic_h coap-message-demos = { git = "https://gitlab.com/chrysn/coap-message-demos/", default-features = false } coap-handler-implementations = "0.5" -riot-coap-handler-demos = { git = "https://gitlab.com/etonomy/riot-module-examples/", features = [ "vfs", "saul" ] } +riot-coap-handler-demos = { git = "https://gitlab.com/etonomy/riot-module-examples/", features = [ "vfs", "saul", "nib", "ping" ] } # While currently this exmple does not use any RIOT modules implemented in # Rust, that may change; it is best practice for any RIOT application that has # its own top-level Rust crate to include rust_riotmodules from inside # RIOTBASE. rust_riotmodules = { path = "../../sys/rust_riotmodules/" } +static_cell = "2.1.0" diff --git a/examples/rust-gcoap/Makefile b/examples/rust-gcoap/Makefile index 2137478bcd..980208bcaa 100644 --- a/examples/rust-gcoap/Makefile +++ b/examples/rust-gcoap/Makefile @@ -19,6 +19,8 @@ USEMODULE += ztimer_usec USEMODULE += ztimer_msec USEMODULE += ztimer_sec +USEMODULE += gnrc_netapi_callbacks + # for the "vfs" feature of riot-coap-handler-demos (and vfs.c) USEMODULE += vfs USEMODULE += constfs diff --git a/examples/rust-gcoap/src/lib.rs b/examples/rust-gcoap/src/lib.rs index a23dfd2e31..1b15ac8c09 100644 --- a/examples/rust-gcoap/src/lib.rs +++ b/examples/rust-gcoap/src/lib.rs @@ -6,7 +6,7 @@ #![no_std] use riot_wrappers::{riot_main, println}; -use riot_wrappers::{gcoap, thread, ztimer, gnrc}; +use riot_wrappers::{gcoap, ztimer, gnrc}; use coap_handler_implementations::{ReportingHandlerBuilder, HandlerBuilder}; @@ -21,18 +21,30 @@ fn main() { unsafe { do_vfs_init() }; + static PINGS: riot_coap_handler_demos::ping::PingPool = riot_coap_handler_demos::ping::PingPool::new(); + static PING_PASSIVE: riot_coap_handler_demos::ping_passive::PingHistoryMutex<{ riot_coap_handler_demos::ping_passive::DEFAULT_SIZE }> = riot_coap_handler_demos::ping_passive::PingHistoryMutex::new(); + let handler = coap_message_demos::full_application_tree(None) .below(&["ps"], riot_coap_handler_demos::ps::ps_tree()) .below(&["led"], riot_coap_handler_demos::led::all_leds()) .below(&["vfs"], riot_coap_handler_demos::vfs::vfs("")) .below(&["saul"], riot_coap_handler_demos::saul::SaulHandler::new(&["saul"])) .below(&["netif"], riot_coap_handler_demos::netif::netif()) + .below(&["nib", "neigh"], riot_coap_handler_demos::nib::neighbor_cache()) + .below(&["ping"], riot_coap_handler_demos::ping::ping_tree(&PINGS)) + .at(&["pinged"], riot_coap_handler_demos::ping_passive::resource(&PING_PASSIVE)) .with_wkc() ; let mut handler = riot_wrappers::coap_handler::v0_2::GcoapHandler(handler); let mut listener = gcoap::SingleHandlerListener::new_catch_all(&mut handler); + static SLOT: static_cell::StaticCell> = static_cell::StaticCell::new(); + PINGS.register(SLOT.init(Default::default())); + + static PASSIVE_SLOT: static_cell::StaticCell>> = static_cell::StaticCell::new(); + PING_PASSIVE.register(PASSIVE_SLOT.init(Default::default())); + gcoap::scope(|greg| { greg.register(&mut listener); @@ -57,6 +69,9 @@ fn main() { // Sending main thread to sleep; can't return or the Gcoap handler would need to be // deregistered (which it can't). - loop { thread::sleep(); } + loop { + PINGS.tick(); + sectimer.sleep(ztimer::Ticks(1)); + } }) }