1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

examples/rust-gcoap: Add ping, passive ping and nib resources

This commit is contained in:
chrysn 2024-09-16 20:07:32 +02:00
parent 84354ffb80
commit d8808cb748
4 changed files with 21 additions and 3 deletions

Binary file not shown.

View File

@ -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"

View File

@ -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

View File

@ -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<gnrc::netreg::callback::Slot<riot_coap_handler_demos::ping::PingCallback>> = static_cell::StaticCell::new();
PINGS.register(SLOT.init(Default::default()));
static PASSIVE_SLOT: static_cell::StaticCell<gnrc::netreg::callback::Slot<&'static riot_coap_handler_demos::ping_passive::PingHistoryMutex<{ riot_coap_handler_demos::ping_passive::DEFAULT_SIZE }>>> = 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));
}
})
}