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

Merge pull request #20838 from chrysn-pull-requests/rust-coap-expose-more

examples/gcoap-rust: Expose more functionality
This commit is contained in:
chrysn 2024-10-02 11:39:42 +00:00 committed by GitHub
commit 505433b8f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 46 additions and 10 deletions

Binary file not shown.

View File

@ -19,14 +19,22 @@ codegen-units = 1
opt-level = "s" opt-level = "s"
[dependencies] [dependencies]
riot-wrappers = { version = "^0.9.0", features = [ "set_panic_handler", "panic_handler_format", "with_coap_message", "with_coap_handler" ] } riot-wrappers = { version = "^0.9.0", features = [ "set_panic_handler", "panic_handler_format", "with_coap_message", "with_coap_handler", "provide_critical_section_1_0" ] }
portable-atomic = { version = "1", features = [ "critical-section" ] }
coap-message-demos = { git = "https://gitlab.com/chrysn/coap-message-demos/", default-features = false } coap-message-demos = { git = "https://gitlab.com/chrysn/coap-message-demos/", default-features = false }
coap-handler-implementations = "0.5" 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 # 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 # 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 # its own top-level Rust crate to include rust_riotmodules from inside
# RIOTBASE. # RIOTBASE.
rust_riotmodules = { path = "../../sys/rust_riotmodules/" } rust_riotmodules = { path = "../../sys/rust_riotmodules/" }
static_cell = "2.1.0"
[patch.crates-io]
# from https://github.com/seanmonstar/try-lock/pull/11, necessary for those
# platforms without atomics (which also needs provide_critical_section_1_0 from
# riot-wrappers, and portable-atomic/critical-section to bridge the gap)
try-lock = { git = "https://github.com/seanmonstar/try-lock", rev = "45c39685b56a4dba1b71bdbbbe5f731c3c77dc50" }

View File

@ -19,6 +19,8 @@ USEMODULE += ztimer_usec
USEMODULE += ztimer_msec USEMODULE += ztimer_msec
USEMODULE += ztimer_sec USEMODULE += ztimer_sec
USEMODULE += gnrc_netapi_callbacks
# for the "vfs" feature of riot-coap-handler-demos (and vfs.c) # for the "vfs" feature of riot-coap-handler-demos (and vfs.c)
USEMODULE += vfs USEMODULE += vfs
USEMODULE += constfs USEMODULE += constfs
@ -34,13 +36,12 @@ DEVELHELP ?= 1
# Change this to 0 show compiler invocation lines by default: # Change this to 0 show compiler invocation lines by default:
QUIET ?= 1 QUIET ?= 1
# Add 8k extra stack: The Rust examples take more of it than gcoap expects, # Add 12k extra stack: The Rust examples take more of it than gcoap expects,
# presumably because the example use the standard library's sting formatting # for reasons that are not fully understood (it's not the string formatter).
# instead of one of the more optimized formatters. CFLAGS += -DGCOAP_STACK_SIZE='(THREAD_STACKSIZE_DEFAULT+DEBUG_EXTRA_STACKSIZE+sizeof(coap_pkt_t)+12288)'
CFLAGS += -DGCOAP_STACK_SIZE='(THREAD_STACKSIZE_DEFAULT+DEBUG_EXTRA_STACKSIZE+sizeof(coap_pkt_t)+8192)'
# This thread needs some more stack for printing the addresses, once more being # This thread needs some more stack for printing the addresses, once more being
# hit by string formatting. # hit by string formatting.
CFLAGS += -DTHREAD_STACKSIZE_MAIN='(THREAD_STACKSIZE_DEFAULT+THREAD_EXTRA_STACKSIZE_PRINTF+2048)' CFLAGS += -DTHREAD_STACKSIZE_MAIN='(THREAD_STACKSIZE_DEFAULT+THREAD_EXTRA_STACKSIZE_PRINTF+1024)'
# The name of crate (as per Cargo.toml package name, but with '-' replaced with '_') # The name of crate (as per Cargo.toml package name, but with '-' replaced with '_')
APPLICATION_RUST_MODULE = rust_gcoap APPLICATION_RUST_MODULE = rust_gcoap

View File

@ -1,5 +1,6 @@
BOARD_INSUFFICIENT_MEMORY := \ BOARD_INSUFFICIENT_MEMORY := \
airfy-beacon \ airfy-beacon \
arduino-mkr1000 \
b-l072z-lrwan1 \ b-l072z-lrwan1 \
blackpill-stm32f103c8 \ blackpill-stm32f103c8 \
blackpill-stm32f103cb \ blackpill-stm32f103cb \
@ -12,6 +13,7 @@ BOARD_INSUFFICIENT_MEMORY := \
cc2650stk \ cc2650stk \
e104-bt5010a-tb \ e104-bt5010a-tb \
e104-bt5011a-tb \ e104-bt5011a-tb \
feather-m0-wifi \
gd32vf103c-start \ gd32vf103c-start \
hifive1 \ hifive1 \
hifive1b \ hifive1b \
@ -21,7 +23,6 @@ BOARD_INSUFFICIENT_MEMORY := \
lsn50 \ lsn50 \
maple-mini \ maple-mini \
microbit \ microbit \
microbit-v2 \
nrf51dongle \ nrf51dongle \
nrf6310 \ nrf6310 \
nucleo-c031c6 \ nucleo-c031c6 \
@ -34,10 +35,15 @@ BOARD_INSUFFICIENT_MEMORY := \
nucleo-f302r8 \ nucleo-f302r8 \
nucleo-f303k8 \ nucleo-f303k8 \
nucleo-f334r8 \ nucleo-f334r8 \
nucleo-f410rb \
nucleo-g070rb \
nucleo-g071rb \
nucleo-g431rb \
nucleo-l011k4 \ nucleo-l011k4 \
nucleo-l031k6 \ nucleo-l031k6 \
nucleo-l053r8 \ nucleo-l053r8 \
nucleo-l073rz \ nucleo-l073rz \
nucleo-l412kb \
olimexino-stm32 \ olimexino-stm32 \
opencm904 \ opencm904 \
samd10-xmini \ samd10-xmini \

View File

@ -51,3 +51,7 @@ Once that is ready, in a parallel shell, run:
``` ```
$ aiocoap-client 'coap://[2a02:0b18:c13b:8018:1234:56ff:fe78:90ab]/.well-known/core' $ aiocoap-client 'coap://[2a02:0b18:c13b:8018:1234:56ff:fe78:90ab]/.well-known/core'
``` ```
Note that no security is enabled by default so far; this is considered a bug.
To mitigate this, no controls that are expected to be harmful are exposed in this example.
(For example, while LEDs are exposed, GPIO pins are not, for they might not tolerate driving to some level depending on the hardware connected to them).

View File

@ -6,7 +6,7 @@
#![no_std] #![no_std]
use riot_wrappers::{riot_main, println}; 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}; use coap_handler_implementations::{ReportingHandlerBuilder, HandlerBuilder};
@ -21,16 +21,30 @@ fn main() {
unsafe { do_vfs_init() }; 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) let handler = coap_message_demos::full_application_tree(None)
.below(&["ps"], riot_coap_handler_demos::ps::ps_tree()) .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(&["vfs"], riot_coap_handler_demos::vfs::vfs(""))
.below(&["saul"], riot_coap_handler_demos::saul::SaulHandler::new(&["saul"])) .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() .with_wkc()
; ;
let mut handler = riot_wrappers::coap_handler::v0_2::GcoapHandler(handler); let mut handler = riot_wrappers::coap_handler::v0_2::GcoapHandler(handler);
let mut listener = gcoap::SingleHandlerListener::new_catch_all(&mut 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| { gcoap::scope(|greg| {
greg.register(&mut listener); greg.register(&mut listener);
@ -55,6 +69,9 @@ fn main() {
// Sending main thread to sleep; can't return or the Gcoap handler would need to be // Sending main thread to sleep; can't return or the Gcoap handler would need to be
// deregistered (which it can't). // deregistered (which it can't).
loop { thread::sleep(); } loop {
PINGS.tick();
sectimer.sleep(ztimer::Ticks(1));
}
}) })
} }