From d8808cb7481a0aef4f579fbe9cbe11715ad700ac Mon Sep 17 00:00:00 2001 From: chrysn Date: Mon, 16 Sep 2024 20:07:32 +0200 Subject: [PATCH] examples/rust-gcoap: Add ping, passive ping and nib resources --- examples/rust-gcoap/Cargo.lock | Bin 27155 -> 28904 bytes examples/rust-gcoap/Cargo.toml | 3 ++- examples/rust-gcoap/Makefile | 2 ++ examples/rust-gcoap/src/lib.rs | 19 +++++++++++++++++-- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/examples/rust-gcoap/Cargo.lock b/examples/rust-gcoap/Cargo.lock index 38bc8beb17d497f73675a49ea89a949dcea559e2..0cf8a6723822a731743d896d983bcee9b4ba9f33 100644 GIT binary patch delta 1721 zcma)7OK(+G6wc+gflCVl(%#l8xm4l{d)@E7wn18gP(XtPL9LI-eyklE%Dqi{W5kJZ z?jvE3aKzNaf#k$6!jW;}07;xH#zg)Aaq7C4@+cEMqqFxpXRq~r>-)Y_eyiQSRr`Mb zaK(qqNcntxVJ;xEfZ$~286f%~ISQXa2D%)JNoPQZPD@acwp36$LekQvoKfnsvpHUF zoZC@8-TB#6i?z9H^XV72wx%yEb(Ui2uF{@RZFOmWtlGY7rM`LnopNYos=7S(!)W6p zzdYmDE_P!1a<89bQAGnf1k5%gmr+KOl1g3}P#lwVz%WaRw2CQZ&viubkOLtAP^C6H zR{mJrR_AS2Zo!k~$n;Mm7Xqe)X{O_s%efIhn}WlPF=*?9R@plaRs$`S2MpU`}eSEwe-o3lo2`%2HLIc2^?#x<`YGAM2+%q-#P|cZMT)|Iz z*jZcZcGk+f2MA^sXqCy@C}|;UE$MJbU>JZ-R-yNxvoa!t1U3b!z)KW1<|vJjY#nB! z-iLJMXtUf|Y*t&IUf5L*H^$0$syWmrz3e@+FzW)UY#1t@6DkWq8s{JYfZ$FU@3W6u zG1O8!j@G20r4!t<7=_SbQ0crrR@ZHQ_dM&9VM0X4lsEKgW;qC;MyW3&xk}nAOwk&P z+Vlkzqkg}eSNk-zUTIC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-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)); + } }) }