From 13dc607eb72d73b12434a1ddad5054b112a97b40 Mon Sep 17 00:00:00 2001 From: Maik Lorenz Date: Mon, 11 Mar 2024 16:02:49 +0100 Subject: [PATCH 01/19] add Matter OnOff Light example in Rust --- examples/rust-matter-light/.gitignore | 2 + examples/rust-matter-light/Cargo.lock | 2419 ++++++++++++++++++++ examples/rust-matter-light/Cargo.toml | 44 + examples/rust-matter-light/LICENSE | 201 ++ examples/rust-matter-light/Makefile | 58 + examples/rust-matter-light/src/dev_att.rs | 164 ++ examples/rust-matter-light/src/gpio.rs | 34 + examples/rust-matter-light/src/lib.rs | 301 +++ examples/rust-matter-light/src/light.rs | 79 + examples/rust-matter-light/src/logging.rs | 27 + examples/rust-matter-light/src/network.rs | 153 ++ examples/rust-matter-light/src/persist.rs | 46 + examples/rust-matter-light/src/saul_reg.rs | 119 + examples/rust-matter-light/src/shell.rs | 30 + examples/rust-matter-light/src/tests.rs | 87 + 15 files changed, 3764 insertions(+) create mode 100644 examples/rust-matter-light/.gitignore create mode 100644 examples/rust-matter-light/Cargo.lock create mode 100644 examples/rust-matter-light/Cargo.toml create mode 100644 examples/rust-matter-light/LICENSE create mode 100644 examples/rust-matter-light/Makefile create mode 100644 examples/rust-matter-light/src/dev_att.rs create mode 100644 examples/rust-matter-light/src/gpio.rs create mode 100644 examples/rust-matter-light/src/lib.rs create mode 100644 examples/rust-matter-light/src/light.rs create mode 100644 examples/rust-matter-light/src/logging.rs create mode 100644 examples/rust-matter-light/src/network.rs create mode 100644 examples/rust-matter-light/src/persist.rs create mode 100644 examples/rust-matter-light/src/saul_reg.rs create mode 100644 examples/rust-matter-light/src/shell.rs create mode 100644 examples/rust-matter-light/src/tests.rs diff --git a/examples/rust-matter-light/.gitignore b/examples/rust-matter-light/.gitignore new file mode 100644 index 000000000000..bcbfeee8e0e6 --- /dev/null +++ b/examples/rust-matter-light/.gitignore @@ -0,0 +1,2 @@ +.vscode/ +target/ diff --git a/examples/rust-matter-light/Cargo.lock b/examples/rust-matter-light/Cargo.lock new file mode 100644 index 000000000000..b8c1dd663093 --- /dev/null +++ b/examples/rust-matter-light/Cargo.lock @@ -0,0 +1,2419 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "aead" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" +dependencies = [ + "crypto-common", + "generic-array", +] + +[[package]] +name = "aes" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + +[[package]] +name = "anstream" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" + +[[package]] +name = "anstyle-parse" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +dependencies = [ + "anstyle", + "windows-sys", +] + +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + +[[package]] +name = "astro-dnssd" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cba40a960b341f156b5123e823c7589d0850f4e6bd46a206106f5b2a5b8a73de" +dependencies = [ + "libc", + "log", + "pkg-config", + "thiserror", + "widestring", + "winapi", +] + +[[package]] +name = "atomic-polyfill" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cf2bce30dfe09ef0bfaef228b9d414faaf7e563035494d7fe092dba54b300f4" +dependencies = [ + "critical-section", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "backtrace" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "backtrace-ext" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "537beee3be4a18fb023b570f80e3ae28003db9167a751266b259926e25539d50" +dependencies = [ + "backtrace", +] + +[[package]] +name = "bare-metal" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fe8f5a8a398345e52358e18ff07cc17a568fbca5c6f73873d3a62056309603" + +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "bindgen" +version = "0.64.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4243e6031260db77ede97ad86c27e501d646a27ab57b59a574f725d98ab1fb4" +dependencies = [ + "bitflags 1.3.2", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex 1.3.0", + "syn 1.0.109", + "which", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "brownstone" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5839ee4f953e811bfdcf223f509cb2c6a3e1447959b0bff459405575bc17f22" +dependencies = [ + "arrayvec", +] + +[[package]] +name = "build_const" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ae4235e6dac0694637c763029ecea1a2ec9e4e06ec2729bd21ba4d9c863eb7" + +[[package]] +name = "bytecount" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1e5f035d16fc623ae5f74981db80a439803888314e3a555fd6f04acd51a3205" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "c2rust-asm-casts" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99883a495b2e1ea1c26a2b5fd08ff58490d127b638582cc4a0f7e336ccbea178" + +[[package]] +name = "c2rust-bitfields" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb34f0c0ace43530b2df7f18bc69ee0c4082158aa451ece29602f8c841e73764" +dependencies = [ + "c2rust-bitfields-derive", +] + +[[package]] +name = "c2rust-bitfields-derive" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dd1601a7b828ab874d890e5a895563ca8ad485bdd3d2a359f148c8b72537241" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "cc" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0ba8f7aaa012f30d5b2861462f6708eccd49c3c39863fe083a308035f63d723" + +[[package]] +name = "ccm" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ae3c82e4355234767756212c570e29833699ab63e6ffd161887314cc5b43847" +dependencies = [ + "aead", + "cipher", + "ctr", + "subtle", +] + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + +[[package]] +name = "clang-sys" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67523a3b4be3ce1989d607a828d036249522dd9c1c8de7f4dd2dae43a37369d1" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "clap" +version = "4.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c918d541ef2913577a0f9566e9ce27cb35b6df072075769e0b26cb5a554520da" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f3e7391dad68afb0c2ede1bf619f579a3dc9c2ec67f089baa397123a2f3d1eb" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim 0.11.0", +] + +[[package]] +name = "clap_derive" +version = "4.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "307bc0538d5f0f83b8248db3087aa92fe504e4691294d0c96c0eabc33f47ba47" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.52", +] + +[[package]] +name = "clap_lex" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" + +[[package]] +name = "coap-handler" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98a2c21db09a4ce20cdf7153ed88b678f728aa8698109203e7f3087b12628e19" +dependencies = [ + "byteorder", + "coap-message 0.2.3", + "coap-numbers", + "crc 1.8.1", + "serde", + "serde_cbor", + "windowed-infinity", +] + +[[package]] +name = "coap-handler" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8600ae8e54c9be6e0c5273fad0503e12f827742e4e3fea5a521412478d603b72" +dependencies = [ + "coap-message 0.3.1", + "coap-numbers", +] + +[[package]] +name = "coap-message" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cc888e15f6be910b58fda4f056f673f58fb9348ea45da014283a14e6d2b58ec" + +[[package]] +name = "coap-message" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae18782d02e6afdfcfaf48eb7ec591b0cae57b67b637441a490752d4a57db02f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "coap-numbers" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e766be4563107bc11c281c017ab922c3f3079345c9aa0fe747b4f9abc13411ac" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "cpufeatures" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +dependencies = [ + "libc", +] + +[[package]] +name = "crc" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb" +dependencies = [ + "build_const", +] + +[[package]] +name = "crc" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86ec7a15cbe22e59248fc7eadb1907dab5ba09372595da4d73dd805ed4417dfe" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + +[[package]] +name = "critical-section" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216" + +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "cstr" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8aa998c33a6d3271e3678950a22134cd7dd27cef86dee1b611b5b14207d1d90b" +dependencies = [ + "proc-macro2", + "quote", +] + +[[package]] +name = "ctr" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" +dependencies = [ + "cipher", +] + +[[package]] +name = "cty" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" + +[[package]] +name = "darling" +version = "0.20.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54e36fcd13ed84ffdfda6f5be89b31287cbb80c439841fe69e04841435464391" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c2cf1c23a687a1feeb728783b993c4e1ad83d99f351801977dd809b48d0a70f" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim 0.10.0", + "syn 2.0.52", +] + +[[package]] +name = "darling_macro" +version = "0.20.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.52", +] + +[[package]] +name = "der" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" +dependencies = [ + "const-oid", + "der_derive", + "flagset", + "pem-rfc7468", + "zeroize", +] + +[[package]] +name = "der_derive" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fe87ce4529967e0ba1dcf8450bab64d97dfd5010a6256187ffe2e43e6f0e049" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.52", +] + +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "document-features" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef5282ad69563b5fc40319526ba27e0e7363d552a896f0297d54f767717f9b95" +dependencies = [ + "litrs", +] + +[[package]] +name = "domain" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e853e3f6d4c6e52a4d73a94c1810c66ad71958fbe24934a7119b447f425aed76" +dependencies = [ + "heapless 0.7.17", + "octseq", + "time", +] + +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der", + "digest", + "elliptic-curve", + "rfc6979", + "signature", +] + +[[package]] +name = "either" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" + +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest", + "ff", + "generic-array", + "group", + "hkdf", + "rand_core", + "sec1", + "subtle", + "zeroize", +] + +[[package]] +name = "embassy-executor" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec648daedd2143466eff4b3e8002024f9f6c1de4ab7666bb679688752624c925" +dependencies = [ + "critical-section", + "document-features", + "embassy-executor-macros", +] + +[[package]] +name = "embassy-executor-macros" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad454accf80050e9cf7a51e994132ba0e56286b31f9317b68703897c328c59b5" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.52", +] + +[[package]] +name = "embassy-executor-riot" +version = "0.1.0" +source = "git+https://gitlab.com/etonomy/riot-module-examples#26a7d27b4c0d518be1d26d07403f57261ee37cd5" +dependencies = [ + "embassy-executor", + "riot-sys", + "riot-wrappers", +] + +[[package]] +name = "embassy-futures" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f878075b9794c1e4ac788c95b728f26aa6366d32eeb10c7051389f898f7d067" + +[[package]] +name = "embassy-sync" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd938f25c0798db4280fcd8026bf4c2f48789aebf8f77b6e5cf8a7693ba114ec" +dependencies = [ + "cfg-if", + "critical-section", + "embedded-io-async", + "futures-util", + "heapless 0.8.0", +] + +[[package]] +name = "embassy-time" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9c844070d9f80dc66ee739299183312baee2e1cdeb6e90b4ea2af44f4676da5" +dependencies = [ + "cfg-if", + "critical-section", + "document-features", + "embassy-time-driver", + "embassy-time-queue-driver", + "embedded-hal 0.2.7", + "embedded-hal 1.0.0", + "embedded-hal-async", + "futures-util", + "heapless 0.8.0", +] + +[[package]] +name = "embassy-time-driver" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e0c214077aaa9206958b16411c157961fb7990d4ea628120a78d1a5a28aed24" +dependencies = [ + "document-features", +] + +[[package]] +name = "embassy-time-queue-driver" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1177859559ebf42cd24ae7ba8fe6ee707489b01d0bf471f8827b7b12dcb0bc0" + +[[package]] +name = "embedded-alloc" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddae17915accbac2cfbc64ea0ae6e3b330e6ea124ba108dada63646fd3c6f815" +dependencies = [ + "critical-section", + "linked_list_allocator", +] + +[[package]] +name = "embedded-graphics" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40a69991ceb896bd4810a0cf2bcc46fc94b7860573c71f965d8e5b3d66942fed" +dependencies = [ + "byteorder", +] + +[[package]] +name = "embedded-hal" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35949884794ad573cf46071e41c9b60efb0cb311e3ca01f7af807af1debc66ff" +dependencies = [ + "nb 0.1.3", + "void", +] + +[[package]] +name = "embedded-hal" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "361a90feb7004eca4019fb28352a9465666b24f840f5c3cddf0ff13920590b89" + +[[package]] +name = "embedded-hal-async" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4c685bbef7fe13c3c6dd4da26841ed3980ef33e841cddfa15ce8a8fb3f1884" +dependencies = [ + "embedded-hal 1.0.0", +] + +[[package]] +name = "embedded-io" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef1a6892d9eef45c8fa6b9e0086428a2cca8491aca8f787c534a3d6d0bcb3ced" + +[[package]] +name = "embedded-io" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d" + +[[package]] +name = "embedded-io-async" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ff09972d4073aa8c299395be75161d582e7629cd663171d62af73c8d50dba3f" +dependencies = [ + "embedded-io 0.6.1", +] + +[[package]] +name = "embedded-nal" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "447416d161ba378782c13e82b11b267d6d2104b4913679a7c5640e7e94f96ea7" +dependencies = [ + "heapless 0.7.17", + "nb 1.1.0", + "no-std-net", +] + +[[package]] +name = "embedded-nal" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a943fad5ed3d3f8a00f1e80f6bba371f1e7f0df28ec38477535eb318dc19cc" +dependencies = [ + "nb 1.1.0", + "no-std-net", +] + +[[package]] +name = "embedded-nal-async" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0f75f0ac83505f354443332324ef1399463902718b95b4ce153ae9b3660f341" +dependencies = [ + "embedded-io-async", + "embedded-nal 0.7.0", + "heapless 0.7.17", + "no-std-net", +] + +[[package]] +name = "embedded-nal-async" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72229137a4fc12d239b0b7f50f04b30790678da6d782a0f3f1909bf57ec4b759" +dependencies = [ + "embedded-io-async", + "embedded-nal 0.8.0", + "no-std-net", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "rand_core", + "subtle", +] + +[[package]] +name = "flagset" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdeb3aa5e95cf9aabc17f060cfa0ced7b83f042390760ca53bf09df9968acaa1" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "pin-utils", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", + "zeroize", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core", + "subtle", +] + +[[package]] +name = "half" +version = "1.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b43ede17f21864e81be2fa654110bf1e793774238d86ef8555c37e6519c0403" + +[[package]] +name = "hash32" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" +dependencies = [ + "byteorder", +] + +[[package]] +name = "hash32" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" +dependencies = [ + "byteorder", +] + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + +[[package]] +name = "heapless" +version = "0.7.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdc6457c0eb62c71aac4bc17216026d8410337c4126773b9c5daba343f17964f" +dependencies = [ + "atomic-polyfill", + "hash32 0.2.1", + "rustc_version", + "spin", + "stable_deref_trait", +] + +[[package]] +name = "heapless" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" +dependencies = [ + "hash32 0.3.1", + "stable_deref_trait", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hkdf" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" +dependencies = [ + "hmac", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "indent_write" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cfe9645a18782869361d9c8732246be7b410ad4e919d3609ebabdac00ba12c3" + +[[package]] +name = "indexmap" +version = "2.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b0b929d511467233429c45a44ac1dcaa21ba0f5ba11e4879e6ed28ddb4f9df4" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "inout" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" +dependencies = [ + "generic-array", +] + +[[package]] +name = "is-terminal" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys", +] + +[[package]] +name = "is_ci" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7655c9839580ee829dfacba1d1278c2b7883e50a277ff7541299489d6bdfdc45" + +[[package]] +name = "itoa" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" + +[[package]] +name = "joinery" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72167d68f5fce3b8655487b8038691a3c9984ee769590f93f2a631f4ad64e4f5" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + +[[package]] +name = "libc" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "libloading" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2caa5afb8bf9f3a2652760ce7d4f62d21c4d5a423e68466fca30df82f2330164" +dependencies = [ + "cfg-if", + "windows-targets", +] + +[[package]] +name = "linked_list_allocator" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286" + +[[package]] +name = "linux-raw-sys" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" + +[[package]] +name = "litrs" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ce301924b7887e9d637144fdade93f9dfff9b60981d4ac161db09720d39aa5" + +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "memchr" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" + +[[package]] +name = "miette" +version = "5.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59bb584eaeeab6bd0226ccf3509a69d7936d148cf3d036ad350abe35e8c6856e" +dependencies = [ + "backtrace", + "backtrace-ext", + "is-terminal", + "miette-derive", + "once_cell", + "owo-colors 3.5.0", + "supports-color", + "supports-hyperlinks", + "supports-unicode", + "terminal_size", + "textwrap", + "thiserror", + "unicode-width", +] + +[[package]] +name = "miette-derive" +version = "5.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.52", +] + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mutex-trait" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4bb1638d419e12f8b1c43d9e639abd0d1424285bdea2f76aa231e233c63cd3a" + +[[package]] +name = "nb" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "801d31da0513b6ec5214e9bf433a77966320625a37860f910be265be6e18d06f" +dependencies = [ + "nb 1.1.0", +] + +[[package]] +name = "nb" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d" + +[[package]] +name = "no-std-net" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43794a0ace135be66a25d3ae77d41b91615fb68ae937f904090203e81f755b65" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "nom-greedyerror" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73f359007d505b20cd6e4974ff0d5c8e4565f0f9e15823937238221ccb74b516" +dependencies = [ + "nom", + "nom_locate", +] + +[[package]] +name = "nom-supreme" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bd3ae6c901f1959588759ff51c95d24b491ecb9ff91aa9c2ef4acc5b1dcab27" +dependencies = [ + "brownstone", + "indent_write", + "joinery", + "memchr", + "nom", +] + +[[package]] +name = "nom_locate" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e3c83c053b0713da60c5b8de47fe8e494fe3ece5267b2f23090a07a053ba8f3" +dependencies = [ + "bytecount", + "memchr", + "nom", +] + +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + +[[package]] +name = "num" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05180d69e3da0e530ba2a1dae5110317e49e3b7f3d41be227dc5f92e49ee7af" +dependencies = [ + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + +[[package]] +name = "num-complex" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23c6602fda94a57c990fe0df199a035d83576b496aa29f4e634a8ac6004e68a6" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "num-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.52", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d869c01cc0c455284163fd0092f1f93835385ccab5a98a0dcc497b2f8bf055a9" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "octseq" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d92b38a4aabbacf619b8083841713216e7668178422decfe06bbc70643024c5d" +dependencies = [ + "heapless 0.7.17", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + +[[package]] +name = "owo-colors" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" + +[[package]] +name = "owo-colors" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caff54706df99d2a78a5a4e3455ff45448d81ef1bb63c22cd14052ca0e993a3f" + +[[package]] +name = "p256" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9863ad85fa8f4460f9c48cb909d38a0d689dba1f6f6988a5e3e0d31071bcd4b" +dependencies = [ + "ecdsa", + "elliptic-curve", + "primeorder", + "sha2", +] + +[[package]] +name = "pbkdf2" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" +dependencies = [ + "digest", + "hmac", +] + +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + +[[package]] +name = "pin-project" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0302c4a0442c456bd56f841aee5c3bfd17967563f6fadc9ceb9f9c23cf3807e0" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.52", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + +[[package]] +name = "portable-atomic" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0" + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "primeorder" +version = "0.13.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "353e1ca18966c16d9deb1c69278edbc5f194139612772bd9537af60ac231e1e6" +dependencies = [ + "elliptic-curve", +] + +[[package]] +name = "proc-macro-crate" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" +dependencies = [ + "toml_edit", +] + +[[package]] +name = "proc-macro2" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "qrcodegen-no-heap" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0e2c0bf8be8a1c4a4f48973dabf26943f05da2bfc2d3180aae62409dbba6f0c" + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + +[[package]] +name = "regex" +version = "1.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] + +[[package]] +name = "riot-sys" +version = "0.7.10" +source = "git+https://github.com/RIOT-OS/rust-riot-sys#297c670d8c674eae20b2b398c4338d27e2d2d346" +dependencies = [ + "bindgen", + "c2rust-asm-casts", + "c2rust-bitfields", + "cty", + "regex", + "serde", + "serde_json", + "shlex 1.3.0", +] + +[[package]] +name = "riot-wrappers" +version = "0.8.2" +source = "git+https://github.com/RIOT-OS/rust-riot-wrappers.git#82bb9a4decedcc624a9540f7fd8013910044be9e" +dependencies = [ + "bare-metal", + "coap-handler 0.1.6", + "coap-handler 0.2.0", + "coap-message 0.2.3", + "coap-message 0.3.1", + "coap-numbers", + "critical-section", + "cstr", + "embedded-graphics", + "embedded-hal 0.2.7", + "embedded-hal 1.0.0", + "embedded-hal-async", + "embedded-io-async", + "embedded-nal-async 0.6.0", + "embedded-nal-async 0.7.1", + "heapless 0.7.17", + "hex", + "mutex-trait", + "nb 0.1.3", + "num-traits", + "pin-project", + "pin-utils", + "rand_core", + "riot-sys", + "shlex 0.1.1", + "switch-hal", + "syn 1.0.109", +] + +[[package]] +name = "rs-matter" +version = "0.1.2" +source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#8c791266bad99264cce45ea971eb5714205826af" +dependencies = [ + "aes", + "astro-dnssd", + "bitflags 1.3.2", + "byteorder", + "ccm", + "critical-section", + "crypto-bigint", + "domain", + "elliptic-curve", + "embassy-futures", + "embassy-sync", + "embassy-time", + "embedded-hal-async", + "embedded-nal-async 0.7.1", + "heapless 0.7.17", + "heapless 0.8.0", + "hkdf", + "hmac", + "log", + "no-std-net", + "num", + "num-derive", + "num-traits", + "octseq", + "owo-colors 4.0.0", + "p256", + "pbkdf2", + "portable-atomic", + "qrcodegen-no-heap", + "rand_core", + "riot-wrappers", + "rs-matter-macros", + "safemem", + "sha2", + "strum", + "subtle", + "time", + "verhoeff", + "x509-cert", +] + +[[package]] +name = "rs-matter-data-model" +version = "0.1.0" +source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#8c791266bad99264cce45ea971eb5714205826af" +dependencies = [ + "clap", + "miette", + "nom", + "nom-greedyerror", + "nom-supreme", + "nom_locate", + "thiserror", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "rs-matter-macros" +version = "0.1.0" +source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#8c791266bad99264cce45ea971eb5714205826af" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "rs-matter-data-model", + "rs-matter-macros-impl", + "syn 2.0.52", +] + +[[package]] +name = "rs-matter-macros-impl" +version = "0.1.0" +source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#8c791266bad99264cce45ea971eb5714205826af" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rs-matter-data-model", + "syn 2.0.52", +] + +[[package]] +name = "rust-matter-light" +version = "0.1.0" +dependencies = [ + "embassy-executor", + "embassy-executor-riot", + "embassy-futures", + "embassy-sync", + "embedded-alloc", + "embedded-hal-async", + "embedded-nal-async 0.7.1", + "log", + "riot-sys", + "riot-wrappers", + "rs-matter", + "rust_riotmodules", + "static_cell", +] + +[[package]] +name = "rust_riotmodules" +version = "0.1.0" + +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + +[[package]] +name = "rustix" +version = "0.38.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" +dependencies = [ + "bitflags 2.4.2", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "rustversion" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" + +[[package]] +name = "ryu" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" + +[[package]] +name = "safemem" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "subtle", + "zeroize", +] + +[[package]] +name = "semver" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" + +[[package]] +name = "serde" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_cbor" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5" +dependencies = [ + "half", + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.52", +] + +[[package]] +name = "serde_json" +version = "1.0.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shlex" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core", +] + +[[package]] +name = "smallvec" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" + +[[package]] +name = "smawk" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c" + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "static_cell" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa6ba4cf83bf80d3eb25f098ea5e790a0a1fcb5e357442259b231e412c2d3ca0" +dependencies = [ + "portable-atomic", +] + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "strsim" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" + +[[package]] +name = "strum" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "723b93e8addf9aa965ebe2d11da6d7540fa2283fcea14b3371ff055f7ba13f5f" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a3417fc93d76740d974a01654a09777cb500428cc874ca9f45edfe0c4d4cd18" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.52", +] + +[[package]] +name = "subtle" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" + +[[package]] +name = "supports-color" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6398cde53adc3c4557306a96ce67b302968513830a77a95b2b17305d9719a89" +dependencies = [ + "is-terminal", + "is_ci", +] + +[[package]] +name = "supports-hyperlinks" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f84231692eb0d4d41e4cdd0cabfdd2e6cd9e255e65f80c9aa7c98dd502b4233d" +dependencies = [ + "is-terminal", +] + +[[package]] +name = "supports-unicode" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f850c19edd184a205e883199a261ed44471c81e39bd95b1357f5febbef00e77a" +dependencies = [ + "is-terminal", +] + +[[package]] +name = "switch-hal" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90a4adc8cbd1726249b161898e48e0f3f1ce74d34dc784cbbc98fba4ed283fbf" +dependencies = [ + "embedded-hal 0.2.7", +] + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "terminal_size" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "textwrap" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7b3e525a49ec206798b40326a44121291b530c963cfb01018f63e135bac543d" +dependencies = [ + "smawk", + "unicode-linebreak", + "unicode-width", +] + +[[package]] +name = "thiserror" +version = "1.0.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.52", +] + +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", +] + +[[package]] +name = "time" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749" +dependencies = [ + "deranged", + "num-conv", + "powerfmt", + "time-core", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "toml_datetime" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" + +[[package]] +name = "toml_edit" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.52", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-serde" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1" +dependencies = [ + "serde", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "nu-ansi-term", + "regex", + "serde", + "serde_json", + "sharded-slab", + "smallvec", + "thread_local", + "tracing-core", + "tracing-log", + "tracing-serde", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-linebreak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" + +[[package]] +name = "unicode-segmentation" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" + +[[package]] +name = "unicode-width" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + +[[package]] +name = "verhoeff" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffb16c19000204197604686ecda606fbeecb2626cfa664dd468d072d99698417" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" + +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] + +[[package]] +name = "widestring" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windowed-infinity" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9487d1d565a9db59e1fd0b3c2d3f0c277bc375d348a6c46ff2b322917fbc035" +dependencies = [ + "crc 3.0.1", + "digest", + "embedded-io 0.4.0", + "serde", + "serde_cbor", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" + +[[package]] +name = "winnow" +version = "0.5.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" +dependencies = [ + "memchr", +] + +[[package]] +name = "x509-cert" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1301e935010a701ae5f8655edc0ad17c44bad3ac5ce8c39185f75453b720ae94" +dependencies = [ + "const-oid", + "der", + "spki", +] + +[[package]] +name = "zeroize" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/examples/rust-matter-light/Cargo.toml b/examples/rust-matter-light/Cargo.toml new file mode 100644 index 000000000000..274b2f642ac4 --- /dev/null +++ b/examples/rust-matter-light/Cargo.toml @@ -0,0 +1,44 @@ +[package] +name = "rust-matter-light" +version = "0.1.0" +authors = ["Maik Lorenz "] +edition = "2021" +resolver = "2" + +[lib] +crate-type = ["staticlib"] + +[profile.release] +# Setting the panic mode has little effect on the built code (as Rust on RIOT +# supports no unwinding), but setting it allows builds on native without using +# the nightly-only lang_items feature. +panic = "abort" +#debug = true +opt-level = "s" +codegen-units = 1 +lto = true + +[dependencies] +riot-wrappers = { git = "https://github.com/RIOT-OS/rust-riot-wrappers.git", features = [ "set_panic_handler", "panic_handler_format", "panic_handler_crash", "with_embedded_nal_async", "provide_critical_section_1_0", "with_embedded_hal_async" ] } +riot-sys = "*" +embedded-nal-async = "0.7.1" +embedded-hal-async = { version = "1.0.0"} +embassy-sync = "0.5.0" +log = "0.4.21" +embedded-alloc = "0.5.1" + +# 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.0.0" +embassy-executor-riot = { git = "https://gitlab.com/etonomy/riot-module-examples" } +embassy-executor = { version = "0.5", features = ["task-arena-size-196608"] } +embassy-futures = "0.1.1" +rs-matter = { version = "0.1.0", default-features = false, features = ["riot-os"] } + +[patch.crates-io] +#rs-matter = { path = "../../../rs-matter/rs-matter" } +rs-matter = { git = "https://github.com/maikerlab/rs-matter", branch = "feature/RIOT_OS" } \ No newline at end of file diff --git a/examples/rust-matter-light/LICENSE b/examples/rust-matter-light/LICENSE new file mode 100644 index 000000000000..261eeb9e9f8b --- /dev/null +++ b/examples/rust-matter-light/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/examples/rust-matter-light/Makefile b/examples/rust-matter-light/Makefile new file mode 100644 index 000000000000..72481d476629 --- /dev/null +++ b/examples/rust-matter-light/Makefile @@ -0,0 +1,58 @@ +# name of your application +APPLICATION = rust-matter-light + +# If no BOARD is found in the environment, use this default: +BOARD ?= native64 + +# This has to be the absolute path to the RIOT base directory: +RIOTBASE ?= $(CURDIR)/../.. + +# Comment this out to disable code in RIOT that does safety checking +# which is not needed in a production environment but helps in the +# development process: +DEVELHELP ?= 1 + +# Change this to 0 show compiler invocation lines by default: +QUIET ?= 1 + +# for embedded +#CFLAGS += '-DTHREAD_STACKSIZE_MAIN=(THREAD_STACKSIZE_DEFAULT + 64000)' +#CFLAGS += '-DISR_STACKSIZE=(THREAD_STACKSIZE_DEFAULT + 10000)' + +# for native can be bigger (may decrease after development) +CFLAGS += '-DTHREAD_STACKSIZE_MAIN=(THREAD_STACKSIZE_DEFAULT + 180*1024)' +CFLAGS += '-DTHREAD_STACKSIZE_IDLE=(THREAD_STACKSIZE_DEFAULT + 180*1024)' +CFLAGS += '-DISR_STACKSIZE=(THREAD_STACKSIZE_DEFAULT + 180*1024)' + +# The name of crate (as per Cargo.toml package name, but with '-' replaced with '_') +APPLICATION_RUST_MODULE = rust_matter_light +BASELIBS += $(APPLICATION_RUST_MODULE).module + +FEATURES_REQUIRED += rust_target + +USEMODULE += saul +USEMODULE += saul_default +USEMODULE += shell +USEMODULE += shell_cmds_default +USEMODULE += periph_gpio +USEMODULE += ztimer +USEMODULE += ztimer_msec +USEMODULE += ztimer_usec +USEMODULE += ps + +# networking +USEMODULE += netdev_default +USEMODULE += auto_init_gnrc_netif +USEMODULE += gnrc_ipv6_default +USEMODULE += gnrc_icmpv6_echo +USEMODULE += gnrc_icmpv6_error +USEMODULE += shell_cmd_gnrc_udp +USEMODULE += sock_udp +USEMODULE += sock_async +USEMODULE += sock_aux_local +USEMODULE += ipv6 +USEMODULE += netstats_l2 +USEMODULE += netstats_ipv6 +USEMODULE += netstats_rpl + +include $(RIOTBASE)/Makefile.include diff --git a/examples/rust-matter-light/src/dev_att.rs b/examples/rust-matter-light/src/dev_att.rs new file mode 100644 index 000000000000..5c1ff5084276 --- /dev/null +++ b/examples/rust-matter-light/src/dev_att.rs @@ -0,0 +1,164 @@ +/* + * + * Copyright (c) 2020-2022 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +use rs_matter::data_model::sdm::dev_att::{DataType, DevAttDataFetcher}; +use rs_matter::error::{Error, ErrorCode}; + +pub struct HardCodedDevAtt {} + +impl HardCodedDevAtt { + pub fn new() -> Self { + Self {} + } +} + +// credentials/examples/ExamplePAI.cpp FFF1 +const PAI_CERT: [u8; 463] = [ + 0x30, 0x82, 0x01, 0xcb, 0x30, 0x82, 0x01, 0x71, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x08, 0x56, + 0xad, 0x82, 0x22, 0xad, 0x94, 0x5b, 0x64, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, + 0x04, 0x03, 0x02, 0x30, 0x30, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, + 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x50, 0x41, 0x41, 0x31, + 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x02, 0x01, 0x0c, + 0x04, 0x46, 0x46, 0x46, 0x31, 0x30, 0x20, 0x17, 0x0d, 0x32, 0x32, 0x30, 0x32, 0x30, 0x35, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x5a, 0x18, 0x0f, 0x39, 0x39, 0x39, 0x39, 0x31, 0x32, 0x33, 0x31, + 0x32, 0x33, 0x35, 0x39, 0x35, 0x39, 0x5a, 0x30, 0x3d, 0x31, 0x25, 0x30, 0x23, 0x06, 0x03, 0x55, + 0x04, 0x03, 0x0c, 0x1c, 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, 0x44, 0x65, 0x76, 0x20, 0x50, + 0x41, 0x49, 0x20, 0x30, 0x78, 0x46, 0x46, 0x46, 0x31, 0x20, 0x6e, 0x6f, 0x20, 0x50, 0x49, 0x44, + 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x02, 0x01, + 0x0c, 0x04, 0x46, 0x46, 0x46, 0x31, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, + 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, + 0x04, 0x41, 0x9a, 0x93, 0x15, 0xc2, 0x17, 0x3e, 0x0c, 0x8c, 0x87, 0x6d, 0x03, 0xcc, 0xfc, 0x94, + 0x48, 0x52, 0x64, 0x7f, 0x7f, 0xec, 0x5e, 0x50, 0x82, 0xf4, 0x05, 0x99, 0x28, 0xec, 0xa8, 0x94, + 0xc5, 0x94, 0x15, 0x13, 0x09, 0xac, 0x63, 0x1e, 0x4c, 0xb0, 0x33, 0x92, 0xaf, 0x68, 0x4b, 0x0b, + 0xaf, 0xb7, 0xe6, 0x5b, 0x3b, 0x81, 0x62, 0xc2, 0xf5, 0x2b, 0xf9, 0x31, 0xb8, 0xe7, 0x7a, 0xaa, + 0x82, 0xa3, 0x66, 0x30, 0x64, 0x30, 0x12, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, + 0x08, 0x30, 0x06, 0x01, 0x01, 0xff, 0x02, 0x01, 0x00, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, + 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x01, 0x06, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, + 0x04, 0x16, 0x04, 0x14, 0x63, 0x54, 0x0e, 0x47, 0xf6, 0x4b, 0x1c, 0x38, 0xd1, 0x38, 0x84, 0xa4, + 0x62, 0xd1, 0x6c, 0x19, 0x5d, 0x8f, 0xfb, 0x3c, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, + 0x18, 0x30, 0x16, 0x80, 0x14, 0x6a, 0xfd, 0x22, 0x77, 0x1f, 0x51, 0x1f, 0xec, 0xbf, 0x16, 0x41, + 0x97, 0x67, 0x10, 0xdc, 0xdc, 0x31, 0xa1, 0x71, 0x7e, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, + 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x48, 0x00, 0x30, 0x45, 0x02, 0x21, 0x00, 0xb2, 0xef, 0x27, + 0xf4, 0x9a, 0xe9, 0xb5, 0x0f, 0xb9, 0x1e, 0xea, 0xc9, 0x4c, 0x4d, 0x0b, 0xdb, 0xb8, 0xd7, 0x92, + 0x9c, 0x6c, 0xb8, 0x8f, 0xac, 0xe5, 0x29, 0x36, 0x8d, 0x12, 0x05, 0x4c, 0x0c, 0x02, 0x20, 0x65, + 0x5d, 0xc9, 0x2b, 0x86, 0xbd, 0x90, 0x98, 0x82, 0xa6, 0xc6, 0x21, 0x77, 0xb8, 0x25, 0xd7, 0xd0, + 0x5e, 0xdb, 0xe7, 0xc2, 0x2f, 0x9f, 0xea, 0x71, 0x22, 0x0e, 0x7e, 0xa7, 0x03, 0xf8, 0x91, +]; + +// credentials/examples/ExampleDACs.cpp FFF1-8000-0002-Cert +const DAC_CERT: [u8; 492] = [ + 0x30, 0x82, 0x01, 0xe8, 0x30, 0x82, 0x01, 0x8e, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x08, 0x52, + 0x72, 0x4d, 0x21, 0xe2, 0xc1, 0x74, 0xaf, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, + 0x04, 0x03, 0x02, 0x30, 0x3d, 0x31, 0x25, 0x30, 0x23, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x1c, + 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, 0x44, 0x65, 0x76, 0x20, 0x50, 0x41, 0x49, 0x20, 0x30, + 0x78, 0x46, 0x46, 0x46, 0x31, 0x20, 0x6e, 0x6f, 0x20, 0x50, 0x49, 0x44, 0x31, 0x14, 0x30, 0x12, + 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x02, 0x01, 0x0c, 0x04, 0x46, 0x46, + 0x46, 0x31, 0x30, 0x20, 0x17, 0x0d, 0x32, 0x32, 0x30, 0x32, 0x30, 0x35, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x5a, 0x18, 0x0f, 0x39, 0x39, 0x39, 0x39, 0x31, 0x32, 0x33, 0x31, 0x32, 0x33, 0x35, + 0x39, 0x35, 0x39, 0x5a, 0x30, 0x53, 0x31, 0x25, 0x30, 0x23, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, + 0x1c, 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, 0x44, 0x65, 0x76, 0x20, 0x44, 0x41, 0x43, 0x20, + 0x30, 0x78, 0x46, 0x46, 0x46, 0x31, 0x2f, 0x30, 0x78, 0x38, 0x30, 0x30, 0x32, 0x31, 0x14, 0x30, + 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x02, 0x01, 0x0c, 0x04, 0x46, + 0x46, 0x46, 0x31, 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, + 0x7c, 0x02, 0x02, 0x0c, 0x04, 0x38, 0x30, 0x30, 0x32, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, + 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, + 0x03, 0x42, 0x00, 0x04, 0xda, 0x93, 0xf1, 0x67, 0x36, 0x25, 0x67, 0x50, 0xd9, 0x03, 0xb0, 0x34, + 0xba, 0x45, 0x88, 0xab, 0xaf, 0x58, 0x95, 0x4f, 0x77, 0xaa, 0x9f, 0xd9, 0x98, 0x9d, 0xfd, 0x40, + 0x0d, 0x7a, 0xb3, 0xfd, 0xc9, 0x75, 0x3b, 0x3b, 0x92, 0x1b, 0x29, 0x4c, 0x95, 0x0f, 0xd9, 0xd2, + 0x80, 0xd1, 0x4c, 0x43, 0x86, 0x2f, 0x16, 0xdc, 0x85, 0x4b, 0x00, 0xed, 0x39, 0xe7, 0x50, 0xba, + 0xbf, 0x1d, 0xc4, 0xca, 0xa3, 0x60, 0x30, 0x5e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, + 0x01, 0xff, 0x04, 0x02, 0x30, 0x00, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, + 0x04, 0x04, 0x03, 0x02, 0x07, 0x80, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, + 0x14, 0xef, 0x06, 0x56, 0x11, 0x9c, 0x1c, 0x91, 0xa7, 0x9a, 0x94, 0xe6, 0xdc, 0xf3, 0x79, 0x79, + 0xdb, 0xd0, 0x7f, 0xf8, 0xa3, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, + 0x80, 0x14, 0x63, 0x54, 0x0e, 0x47, 0xf6, 0x4b, 0x1c, 0x38, 0xd1, 0x38, 0x84, 0xa4, 0x62, 0xd1, + 0x6c, 0x19, 0x5d, 0x8f, 0xfb, 0x3c, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, + 0x03, 0x02, 0x03, 0x48, 0x00, 0x30, 0x45, 0x02, 0x20, 0x46, 0x86, 0x81, 0x07, 0x33, 0xbf, 0x0d, + 0xc8, 0xff, 0x4c, 0xb5, 0x14, 0x5a, 0x6b, 0xfa, 0x1a, 0xec, 0xff, 0xa8, 0xb6, 0xda, 0xb6, 0xc3, + 0x51, 0xaa, 0xee, 0xcd, 0xaf, 0xb8, 0xbe, 0x95, 0x7d, 0x02, 0x21, 0x00, 0xe8, 0xc2, 0x8d, 0x6b, + 0xfc, 0xc8, 0x7a, 0x7d, 0x54, 0x2e, 0xad, 0x6e, 0xda, 0xca, 0x14, 0x8d, 0x5f, 0xa5, 0x06, 0x1e, + 0x51, 0x7c, 0xbe, 0x4f, 0x24, 0xa7, 0x20, 0xe1, 0xc0, 0x59, 0xde, 0x1a, +]; + +const DAC_PUBKEY: [u8; 65] = [ + 0x04, 0xda, 0x93, 0xf1, 0x67, 0x36, 0x25, 0x67, 0x50, 0xd9, 0x03, 0xb0, 0x34, 0xba, 0x45, 0x88, + 0xab, 0xaf, 0x58, 0x95, 0x4f, 0x77, 0xaa, 0x9f, 0xd9, 0x98, 0x9d, 0xfd, 0x40, 0x0d, 0x7a, 0xb3, + 0xfd, 0xc9, 0x75, 0x3b, 0x3b, 0x92, 0x1b, 0x29, 0x4c, 0x95, 0x0f, 0xd9, 0xd2, 0x80, 0xd1, 0x4c, + 0x43, 0x86, 0x2f, 0x16, 0xdc, 0x85, 0x4b, 0x00, 0xed, 0x39, 0xe7, 0x50, 0xba, 0xbf, 0x1d, 0xc4, + 0xca, +]; + +const DAC_PRIVKEY: [u8; 32] = [ + 0xda, 0xf2, 0x1a, 0x7e, 0xa4, 0x7a, 0x70, 0x48, 0x02, 0xa7, 0xe6, 0x6c, 0x50, 0xeb, 0x10, 0xba, + 0xc3, 0xbd, 0xd1, 0x68, 0x80, 0x39, 0x80, 0x66, 0xff, 0xda, 0xd7, 0xf5, 0x20, 0x98, 0xb6, 0x85, +]; + +const CERT_DECLARATION: [u8; 541] = [ + 0x30, 0x82, 0x02, 0x19, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02, 0xa0, + 0x82, 0x02, 0x0a, 0x30, 0x82, 0x02, 0x06, 0x02, 0x01, 0x03, 0x31, 0x0d, 0x30, 0x0b, 0x06, 0x09, + 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x30, 0x82, 0x01, 0x71, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0xa0, 0x82, 0x01, 0x62, 0x04, 0x82, 0x01, 0x5e, + 0x15, 0x24, 0x00, 0x01, 0x25, 0x01, 0xf1, 0xff, 0x36, 0x02, 0x05, 0x00, 0x80, 0x05, 0x01, 0x80, + 0x05, 0x02, 0x80, 0x05, 0x03, 0x80, 0x05, 0x04, 0x80, 0x05, 0x05, 0x80, 0x05, 0x06, 0x80, 0x05, + 0x07, 0x80, 0x05, 0x08, 0x80, 0x05, 0x09, 0x80, 0x05, 0x0a, 0x80, 0x05, 0x0b, 0x80, 0x05, 0x0c, + 0x80, 0x05, 0x0d, 0x80, 0x05, 0x0e, 0x80, 0x05, 0x0f, 0x80, 0x05, 0x10, 0x80, 0x05, 0x11, 0x80, + 0x05, 0x12, 0x80, 0x05, 0x13, 0x80, 0x05, 0x14, 0x80, 0x05, 0x15, 0x80, 0x05, 0x16, 0x80, 0x05, + 0x17, 0x80, 0x05, 0x18, 0x80, 0x05, 0x19, 0x80, 0x05, 0x1a, 0x80, 0x05, 0x1b, 0x80, 0x05, 0x1c, + 0x80, 0x05, 0x1d, 0x80, 0x05, 0x1e, 0x80, 0x05, 0x1f, 0x80, 0x05, 0x20, 0x80, 0x05, 0x21, 0x80, + 0x05, 0x22, 0x80, 0x05, 0x23, 0x80, 0x05, 0x24, 0x80, 0x05, 0x25, 0x80, 0x05, 0x26, 0x80, 0x05, + 0x27, 0x80, 0x05, 0x28, 0x80, 0x05, 0x29, 0x80, 0x05, 0x2a, 0x80, 0x05, 0x2b, 0x80, 0x05, 0x2c, + 0x80, 0x05, 0x2d, 0x80, 0x05, 0x2e, 0x80, 0x05, 0x2f, 0x80, 0x05, 0x30, 0x80, 0x05, 0x31, 0x80, + 0x05, 0x32, 0x80, 0x05, 0x33, 0x80, 0x05, 0x34, 0x80, 0x05, 0x35, 0x80, 0x05, 0x36, 0x80, 0x05, + 0x37, 0x80, 0x05, 0x38, 0x80, 0x05, 0x39, 0x80, 0x05, 0x3a, 0x80, 0x05, 0x3b, 0x80, 0x05, 0x3c, + 0x80, 0x05, 0x3d, 0x80, 0x05, 0x3e, 0x80, 0x05, 0x3f, 0x80, 0x05, 0x40, 0x80, 0x05, 0x41, 0x80, + 0x05, 0x42, 0x80, 0x05, 0x43, 0x80, 0x05, 0x44, 0x80, 0x05, 0x45, 0x80, 0x05, 0x46, 0x80, 0x05, + 0x47, 0x80, 0x05, 0x48, 0x80, 0x05, 0x49, 0x80, 0x05, 0x4a, 0x80, 0x05, 0x4b, 0x80, 0x05, 0x4c, + 0x80, 0x05, 0x4d, 0x80, 0x05, 0x4e, 0x80, 0x05, 0x4f, 0x80, 0x05, 0x50, 0x80, 0x05, 0x51, 0x80, + 0x05, 0x52, 0x80, 0x05, 0x53, 0x80, 0x05, 0x54, 0x80, 0x05, 0x55, 0x80, 0x05, 0x56, 0x80, 0x05, + 0x57, 0x80, 0x05, 0x58, 0x80, 0x05, 0x59, 0x80, 0x05, 0x5a, 0x80, 0x05, 0x5b, 0x80, 0x05, 0x5c, + 0x80, 0x05, 0x5d, 0x80, 0x05, 0x5e, 0x80, 0x05, 0x5f, 0x80, 0x05, 0x60, 0x80, 0x05, 0x61, 0x80, + 0x05, 0x62, 0x80, 0x05, 0x63, 0x80, 0x18, 0x24, 0x03, 0x16, 0x2c, 0x04, 0x13, 0x5a, 0x49, 0x47, + 0x32, 0x30, 0x31, 0x34, 0x32, 0x5a, 0x42, 0x33, 0x33, 0x30, 0x30, 0x30, 0x33, 0x2d, 0x32, 0x34, + 0x24, 0x05, 0x00, 0x24, 0x06, 0x00, 0x25, 0x07, 0x94, 0x26, 0x24, 0x08, 0x00, 0x18, 0x31, 0x7d, + 0x30, 0x7b, 0x02, 0x01, 0x03, 0x80, 0x14, 0x62, 0xfa, 0x82, 0x33, 0x59, 0xac, 0xfa, 0xa9, 0x96, + 0x3e, 0x1c, 0xfa, 0x14, 0x0a, 0xdd, 0xf5, 0x04, 0xf3, 0x71, 0x60, 0x30, 0x0b, 0x06, 0x09, 0x60, + 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, + 0x3d, 0x04, 0x03, 0x02, 0x04, 0x47, 0x30, 0x45, 0x02, 0x20, 0x24, 0xe5, 0xd1, 0xf4, 0x7a, 0x7d, + 0x7b, 0x0d, 0x20, 0x6a, 0x26, 0xef, 0x69, 0x9b, 0x7c, 0x97, 0x57, 0xb7, 0x2d, 0x46, 0x90, 0x89, + 0xde, 0x31, 0x92, 0xe6, 0x78, 0xc7, 0x45, 0xe7, 0xf6, 0x0c, 0x02, 0x21, 0x00, 0xf8, 0xaa, 0x2f, + 0xa7, 0x11, 0xfc, 0xb7, 0x9b, 0x97, 0xe3, 0x97, 0xce, 0xda, 0x66, 0x7b, 0xae, 0x46, 0x4e, 0x2b, + 0xd3, 0xff, 0xdf, 0xc3, 0xcc, 0xed, 0x7a, 0xa8, 0xca, 0x5f, 0x4c, 0x1a, 0x7c, +]; + +impl DevAttDataFetcher for HardCodedDevAtt { + fn get_devatt_data(&self, data_type: DataType, data: &mut [u8]) -> Result { + let src = match data_type { + DataType::CertDeclaration => &CERT_DECLARATION[..], + DataType::PAI => &PAI_CERT[..], + DataType::DAC => &DAC_CERT[..], + DataType::DACPubKey => &DAC_PUBKEY[..], + DataType::DACPrivKey => &DAC_PRIVKEY[..], + }; + if src.len() <= data.len() { + let data = &mut data[0..src.len()]; + data.copy_from_slice(src); + Ok(src.len()) + } else { + Err(ErrorCode::NoSpace.into()) + } + } +} diff --git a/examples/rust-matter-light/src/gpio.rs b/examples/rust-matter-light/src/gpio.rs new file mode 100644 index 000000000000..e3971384ecee --- /dev/null +++ b/examples/rust-matter-light/src/gpio.rs @@ -0,0 +1,34 @@ +// periph_gpio module +use riot_wrappers::gpio::{GPIO, OutputGPIO, OutputMode, InputGPIO, InputMode}; + + +// Application-specific constants +// User LED port and pin on used boards +pub const LED_PORT: u32 = 0; +pub const LED_PIN: u32 = 5; + +// RGB LED port and pin +pub const RGB_PORT: u32 = 0; +pub const RGB_RED_PIN: u32 = 7; +pub const RGB_GREEN_PIN: u32 = 6; +pub const RGB_BLUE_PIN: u32 = 5; + + +// TODO: Make GPIO's static members +pub fn get_output(port: u32, pin: u32) -> OutputGPIO { + GPIO::from_port_and_pin(port, pin) + .expect("Error configuring pin") + .configure_as_output(OutputMode::Out) + .expect("Error configuring GPIO output") +} + +pub fn get_input(port: u32, pin: u32) -> InputGPIO { + GPIO::from_port_and_pin(port, pin) + .expect("Error configuring pin") + .configure_as_input(InputMode::In) + .expect("Error configuring GPIO input") +} + +pub fn set_output(port: u32, pin: u32, on: bool) { + get_output(port, pin).set_state(on); +} \ No newline at end of file diff --git a/examples/rust-matter-light/src/lib.rs b/examples/rust-matter-light/src/lib.rs new file mode 100644 index 000000000000..24a68fc01e77 --- /dev/null +++ b/examples/rust-matter-light/src/lib.rs @@ -0,0 +1,301 @@ +// Copyright (C) 2024 Maik Lorenz +// +// This file is subject to the terms and conditions of the GNU Lesser +// General Public License v2.1. See the file LICENSE in the top level +// directory for more details. +#![no_std] + + +// declare internal modules +mod dev_att; +mod network; +#[allow(unused)] +mod persist; +mod logging; + +#[allow(unused)] +pub mod gpio; +#[allow(unused)] +pub mod light; +#[allow(unused)] +pub mod saul_reg; +#[allow(unused)] +mod tests; + +// internal modules imports +use network::utils::{initialize_network}; +use logging::init_logger; +use network::UdpSocketWrapper; + +// core library +use core::{borrow::Borrow, pin::pin}; +use core::cell::Cell; + +// external crates +use static_cell::StaticCell; +use embedded_nal_async::{Ipv4Addr, UdpStack as _}; +use embedded_alloc::Heap; +use log::{debug, info, error}; + +// RIOT OS modules +extern crate rust_riotmodules; +use riot_wrappers::riot_main; + +// rs-matter +use rs_matter::{CommissioningData, MATTER_PORT}; +use rs_matter::transport::network::UdpBuffers; +use rs_matter::transport::core::{PacketBuffers, MATTER_SOCKET_BIND_ADDR}; +use rs_matter::core::Matter; +use rs_matter::data_model::{ + cluster_basic_information::BasicInfoConfig, + cluster_on_off, + device_types::DEV_TYPE_ON_OFF_LIGHT, + objects::*, + root_endpoint, + system_model::descriptor +}; +use rs_matter::data_model::cluster_on_off::OnOffCluster; +use rs_matter::error::Error; +use rs_matter::mdns::MdnsService; +use rs_matter::mdns::builtin::{ + MDNS_IPV6_BROADCAST_ADDR, MDNS_SOCKET_BIND_ADDR, +}; +use rs_matter::secure_channel::spake2p::VerifierData; +use rs_matter::tlv::TLVElement; +use rs_matter::transport::exchange::Exchange; + +// Node object with endpoints supporting device type 'OnOff Light' +const NODE: Node<'static> = Node { + id: 0, + endpoints: &[ + root_endpoint::endpoint(0), + Endpoint { + id: 1, + device_type: DEV_TYPE_ON_OFF_LIGHT, + clusters: &[descriptor::CLUSTER, cluster_on_off::CLUSTER], + }, + ], +}; + +static DEV_DET: BasicInfoConfig = BasicInfoConfig { + vid: 0xFFF1, + pid: 0x8000, + hw_ver: 2, + sw_ver: 1, + sw_ver_str: "1", + serial_no: "aabbccddd", + device_name: "OnOff Light", + product_name: "Light123", + vendor_name: "Vendor 123", +}; + +#[allow(dead_code)] +struct MyOnOffCluster { + cluster: OnOffCluster, + on: Cell, +} + +impl MyOnOffCluster { + fn new(cluster: OnOffCluster) -> Self { + Self { + cluster, + on: Cell::new(false), + } + } +} + +impl Handler for MyOnOffCluster { + fn read(&self, attr: &AttrDetails, encoder: AttrDataEncoder) -> Result<(), Error> { + info!("MyOnOffCluster - read: {:?}", attr); + OnOffCluster::read(&self.cluster, attr, encoder) + } + + fn write(&self, attr: &AttrDetails, data: AttrData) -> Result<(), Error> { + info!("MyOnOffCluster - write: {:?}", attr); + OnOffCluster::write(&self.cluster, attr, data) + } + + fn invoke(&self, exchange: &Exchange, cmd: &CmdDetails, data: &TLVElement, encoder: CmdDataEncoder) -> Result<(), Error> { + info!("MyOnOffCluster - invoke: cmd={:?}, data={:?}", cmd, data.u32()); + OnOffCluster::invoke(&self.cluster, exchange, cmd, data, encoder) + } +} +impl NonBlockingHandler for MyOnOffCluster {} + +// Handler for endpoint 1 (Descriptor + OnOff Cluster) +fn matter_handler<'a>(matter: &'a Matter<'a>) -> impl Metadata + NonBlockingHandler + 'a { + ( + NODE, + root_endpoint::handler(0, matter) + .chain( + 1, + descriptor::ID, + descriptor::DescriptorCluster::new(*matter.borrow()), + ) + .chain( + 1, + cluster_on_off::ID, + //cluster_on_off::OnOffCluster::new(*matter.borrow()), + MyOnOffCluster::new(cluster_on_off::OnOffCluster::new(*matter.borrow())), + ), + ) +} + +#[global_allocator] +static HEAP: Heap = Heap::empty(); + +riot_main!(main); + +fn main() -> ! { + { + use core::mem::MaybeUninit; + const HEAP_SIZE: usize = 1024 * 180; + static mut HEAP_MEM: [MaybeUninit; HEAP_SIZE] = [MaybeUninit::uninit(); HEAP_SIZE]; + unsafe { HEAP.init(HEAP_MEM.as_ptr() as usize, HEAP_SIZE) } + } + + init_logger().expect("Error initializing logger"); + + info!("Hello Matter on RIOT!"); + + let (ipv6_addr, interface) = initialize_network().expect("Error getting network interface and IP addresses"); + + static MDNS: StaticCell = StaticCell::new(); + let mdns_service: &'static MdnsService = MDNS.init(MdnsService::new( + 0, + "rs-matter-demo", + Ipv4Addr::UNSPECIFIED.octets(), + Some((ipv6_addr.octets(), interface)), + &DEV_DET, + MATTER_PORT, + )); + + // Get Device attestation (hard-coded atm) + static DEV_ATT: StaticCell = StaticCell::new(); + let dev_att: &'static dev_att::HardCodedDevAtt = DEV_ATT.init(dev_att::HardCodedDevAtt::new()); + + // TODO: Provide own epoch and rand functions + let epoch = rs_matter::utils::epoch::riot_epoch; + let rand = rs_matter::utils::rand::riot_rand; + + static MATTER: StaticCell = StaticCell::new(); + let matter: &'static Matter = MATTER.init(Matter::new( + // vid/pid should match those in the DAC + &DEV_DET, + dev_att, + mdns_service, + epoch, + rand, + MATTER_PORT, + )); + + info!("Starting all services..."); + + // TODO: Maybe run shell in seperate thread + let mut _shell_thread = || { + debug!("Shell is running"); + saul_reg::run_shell_with_saul(); + }; + + static EXECUTOR: StaticCell = StaticCell::new(); + let executor: &'static mut _ = EXECUTOR.init(embassy_executor_riot::Executor::new()); + executor.run(|spawner| { + spawner.spawn(run_mdns(mdns_service)).unwrap(); + spawner.spawn(run_matter(matter)).unwrap(); + spawner.spawn(run_psm(matter)).unwrap(); + }); + + +} + +#[embassy_executor::task] +async fn run_mdns(mdns: &'static MdnsService<'_>) { + // Create UDP socket and bind to port 5353 + static UDP_MDNS_SOCKET: StaticCell = StaticCell::new(); + let udp_stack = riot_wrappers::socket_embedded_nal_async_udp::UdpStack::new(|| UDP_MDNS_SOCKET.try_uninit()); + let (mdns_addr, mdns_sock) = udp_stack + .bind_single(MDNS_SOCKET_BIND_ADDR) + .await + .expect("Can't create a socket"); + let socket = UdpSocketWrapper::new(mdns_addr, mdns_sock); + debug!("Created UDP socket for mDNS at {:?}", &mdns_addr); + + // TODO: Join IPv6 Multicast group (MDNS_IPV6_BROADCAST_ADDR) + + // Finally run the MDNS service + let mut mdns_udp_buffers = UdpBuffers::new(); + let mdns_runner = pin!(mdns.run( + &socket, + &socket, + &mut mdns_udp_buffers) + ); + + debug!("Starting MDNS...."); + match mdns_runner.await { + Ok(_) => { + info!("MDNS terminated without errors!"); + } + Err(err) => { + error!("MDNS terminated with error: {:?}", err); + } + } +} + +#[embassy_executor::task] +async fn run_matter(matter: &'static Matter<'_>) { + // Create UDP socket and bind to port 5540 + static UDP_MATTER_SOCKET: StaticCell = StaticCell::new(); + let udp_stack = riot_wrappers::socket_embedded_nal_async_udp::UdpStack::new(|| UDP_MATTER_SOCKET.try_uninit()); + let (matter_addr, matter_sock) = udp_stack + .bind_single(MATTER_SOCKET_BIND_ADDR) + .await + .expect("Can't create a socket"); + let socket = UdpSocketWrapper::new(matter_addr, matter_sock); + debug!("Created UDP socket for Matter at {:?}", &matter_addr); + + let handler = HandlerCompat(matter_handler(&matter)); + + let mut matter_udp_buffers = UdpBuffers::new(); + let mut matter_packet_buffers = PacketBuffers::new(); + + // Finally create the Matter service and run on port 5540/UDP + let matter_runner = pin!(matter.run( + &socket, + &socket, + &mut matter_udp_buffers, + &mut matter_packet_buffers, + CommissioningData { + // TODO: Hard-coded for now + verifier: VerifierData::new_with_pw(123456, *matter.borrow()), + discriminator: 250, + }, + &handler) + ); + let matter_runner = pin!(matter_runner); + + info!("Starting Matter..."); + match matter_runner.await { + Ok(_) => { + info!("Matter service terminated without errors!"); + } + Err(err) => { + error!("Matter service terminated with error: {:?}", err); + } + } +} + +#[embassy_executor::task] +async fn run_psm(matter: &'static Matter<'_>) { + info!("Starting Persistence Manager...."); + // TODO: Develop own 'Persistence Manager' using RIOT OS modules + let mut psm = persist::Psm::new(&matter).expect("Error creating PSM"); + let psm_runner = pin!(psm.run()); + match psm_runner.await { + Ok(_) => { + info!("Persistence Manager terminated without errors!"); + } + Err(err) => { + error!("Persistence Manager terminated with errors: {:?}", err); + } + } +} diff --git a/examples/rust-matter-light/src/light.rs b/examples/rust-matter-light/src/light.rs new file mode 100644 index 000000000000..789cd32e34ad --- /dev/null +++ b/examples/rust-matter-light/src/light.rs @@ -0,0 +1,79 @@ +use core::fmt::Debug; + +// riot modules +use riot_wrappers::println; + +pub trait OnOffDevice { + fn onoff_set(&mut self, on: bool); + fn is_on(&self) -> bool; +} + +pub trait ColorLight { + fn set_color(&mut self, color: RgbColor); + fn get_current_color(&self) -> Option<&RgbColor>; +} + +#[derive(Debug, Clone, Default)] +pub struct RgbColor { + red: u8, + green: u8, + blue: u8, +} + +pub struct ColorTemperatureLight { + pub on: bool, + portpin_red: (u32, u32), + portpin_green: (u32, u32), + portpin_blue: (u32, u32), + current_color: RgbColor, +} + +impl ColorTemperatureLight { + pub fn new(red_port: u32, red_pin: u32, green_port: u32, green_pin: u32, blue_port: u32, blue_pin: u32, ) -> Self { + Self { + on: false, + portpin_red: (red_port, red_pin), + portpin_green: (green_port, green_pin), + portpin_blue: (blue_port, blue_pin), + current_color: RgbColor::default(), + } + } +} + +impl Debug for ColorTemperatureLight { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("ColorTemperatureLight") + .field("on", &self.on) + .field("current_color", &self.current_color) + .finish() + } +} + +impl ColorLight for ColorTemperatureLight { + fn set_color(&mut self, color: RgbColor) { + println!("Setting color: {:?}", &color); + // TODO: Control GPIO's and set color + self.current_color = color; + } + + fn get_current_color(&self) -> Option<&RgbColor> { + if !self.on { + return None + } + Some(&self.current_color) + } +} + +mod test { + use super::*; + + #[test] + fn test_color_temperature_light_new() { + let light = ColorTemperatureLight::new(0, 1, 1, 2, 2, 2); + assert_eq!(false, light.on); + let color = light.current_color; + assert_eq!(0, color.red); + assert_eq!(0, color.green); + assert_eq!(0, color.blue); + } +} \ No newline at end of file diff --git a/examples/rust-matter-light/src/logging.rs b/examples/rust-matter-light/src/logging.rs new file mode 100644 index 000000000000..1684d7796084 --- /dev/null +++ b/examples/rust-matter-light/src/logging.rs @@ -0,0 +1,27 @@ +use log::{Level, LevelFilter, Log, Record, SetLoggerError}; +use riot_wrappers::println; + +struct RiotLogger; + +impl Log for RiotLogger { + fn enabled(&self, metadata: &log::Metadata) -> bool { + metadata.level() >= Level::Info + } + + fn log(&self, record: &Record) { + if self.enabled(record.metadata()) { + println!("[{}] {}", record.level(), record.args()); + } + } + + fn flush(&self) {} +} + +static LOGGER: RiotLogger = RiotLogger; + +pub fn init_logger() -> Result<(), SetLoggerError> { + //let log_level: &'static str = env!("RIOT_LOG_LEVEL"); + //println!("the RIOT_LOG_LEVEL variable at the time of compiling was: {log_level}"); + log::set_logger(&LOGGER) + .map(|_| log::set_max_level(LevelFilter::Debug)) +} \ No newline at end of file diff --git a/examples/rust-matter-light/src/network.rs b/examples/rust-matter-light/src/network.rs new file mode 100644 index 000000000000..4b6562cd04ab --- /dev/null +++ b/examples/rust-matter-light/src/network.rs @@ -0,0 +1,153 @@ +use rs_matter::error::Error as MatterError; +use riot_wrappers::gnrc::Netif; +use embedded_nal_async::{Ipv6Addr, SocketAddr, UnconnectedUdp}; + +use embassy_futures::select::{Either, select}; +use riot_wrappers::mutex::Mutex; +use riot_wrappers::ztimer; +use riot_wrappers::socket_embedded_nal_async_udp::UnconnectedUdpSocket; +use rs_matter::error::{Error, ErrorCode}; +use rs_matter::transport::network::{UdpReceive, UdpSend}; +use embassy_sync::{ + signal::Signal, + blocking_mutex::raw::NoopRawMutex +}; +use embedded_hal_async::delay::DelayNs; +use log::{debug, error, warn}; + +pub type Notification = Signal; + +pub struct UdpSocketWrapper { + local_addr: SocketAddr, + socket: Mutex, + release_socket_notification: Notification, + socket_released_notification: Notification, +} + +impl UdpSocketWrapper { + pub fn new(local_addr: SocketAddr, socket: UnconnectedUdpSocket) -> Self { + Self { + local_addr, + socket: Mutex::new(socket), + release_socket_notification: Notification::new(), + socket_released_notification: Notification::new(), + } + } +} + +impl UdpSend for &UdpSocketWrapper { + async fn send_to(&mut self, data: &[u8], addr: SocketAddr) -> Result<(), Error> { + debug!("(UDP) sending {} bytes to {:?}", data.len(), &addr); + if addr.is_ipv4() { + // IPv4 not supported on RIOT OS + warn!("(UDP) Is IPv4 -> ignore send!"); + return Ok(()); + } + // tell receiver to release mutex within max. 10ms + self.release_socket_notification.signal(()); + ztimer::Delay.delay_ms(5).await; + let mut sock = self.socket.try_lock().expect("receiver should have ensured that this mutex is free"); + sock.send(self.local_addr, addr, data) + .await + .map_err(|_| Error::new(ErrorCode::StdIoError))?; + // tell receiver sending is finished + drop(sock); + self.socket_released_notification.signal(()); + Ok(()) + } +} + +impl UdpReceive for &UdpSocketWrapper { + async fn recv_from(&mut self, buffer: &mut [u8]) -> Result<(usize, SocketAddr), Error> { + loop { + let mut sock = self.socket.try_lock().expect("sender should have ensured that this mutex is free"); + match select( + self.release_socket_notification.wait(), + sock.receive_into(buffer) + ).await { + Either::First(_) => { + // give up mutex for sender + drop(sock); + // ... and wait until available again + self.socket_released_notification.wait().await; + continue; + } + Either::Second(res) => { + match res { + Ok((bytes_recvd, local_addr, remote_addr)) => { + debug!("(UDP) received {} bytes from {:?} to {:?}", bytes_recvd, &remote_addr, &local_addr); + if remote_addr.is_ipv4() { + warn!("(UDP) Is IPv4 -> ignoring receive data!"); + return Ok((bytes_recvd, remote_addr)); + } + } + Err(_) => { error!("Error during UDP receive!"); } + } + // return receive result + let (bytes_recvd, remote_addr) = res.map(|(bytes_recvd, _, remote_addr)| + (bytes_recvd, remote_addr) + ).map_err(|_| Error::new(ErrorCode::StdIoError))?; + return Ok((bytes_recvd, remote_addr)); + } + } + } + } +} + +pub mod utils { + use log::{debug, error, info}; + use super::*; + + pub fn get_ipv6_address(ifc: &Netif) -> Option { + let all_addresses = ifc.ipv6_addrs(); + if all_addresses.is_err() { + return None; + } + + return match all_addresses.unwrap().first() { + Some(a) => { + let ipv6_raw = a.raw(); + Some(Ipv6Addr::new( + ((ipv6_raw[0] as u16) << 8) | ipv6_raw[1] as u16, + ((ipv6_raw[2] as u16) << 8) | ipv6_raw[3] as u16, + ((ipv6_raw[4] as u16) << 8) | ipv6_raw[5] as u16, + ((ipv6_raw[6] as u16) << 8) | ipv6_raw[7] as u16, + ((ipv6_raw[8] as u16) << 8) | ipv6_raw[9] as u16, + ((ipv6_raw[10] as u16) << 8) | ipv6_raw[11] as u16, + ((ipv6_raw[12] as u16) << 8) | ipv6_raw[13] as u16, + ((ipv6_raw[14] as u16) << 8) | ipv6_raw[15] as u16, + )) + }, + None => None, + }; + } + + #[inline(never)] + pub fn initialize_network() -> Result<(Ipv6Addr, u32), MatterError> { + // Get available network interface(s) + let mut interfaces = Netif::all(); + + // Get first available interface + let ifc: Netif = match interfaces.next() { + Some(ifc) => Ok(ifc), + None => { + error!("ERROR: No network interface was found!"); + Err(MatterError::new(ErrorCode::NoNetworkInterface)) + }, + }?; + + // atm only for debugging: Check name and status of KernelPID + let pid = ifc.pid(); + let ifc_name: &str = pid.get_name().unwrap(); + debug!("Kernel PID status of network interface {:?}: {:?}", pid.get_name().unwrap(), pid.status().unwrap()); + + // Get available IPv6 link-local address + match get_ipv6_address(&ifc) { + Some(ipv6) => { + info!("Found network interface {} with IP {}", ifc_name, ipv6); + Ok((ipv6, 0 as _)) + }, + None => Err(MatterError::new(ErrorCode::StdIoError)), + } + } +} \ No newline at end of file diff --git a/examples/rust-matter-light/src/persist.rs b/examples/rust-matter-light/src/persist.rs new file mode 100644 index 000000000000..05d0e74f06a3 --- /dev/null +++ b/examples/rust-matter-light/src/persist.rs @@ -0,0 +1,46 @@ +use log::debug; +use rs_matter::error::Error; +use rs_matter::core::Matter; + +pub struct Psm<'a> { + matter: &'a Matter<'a>, + buf: [u8; 4096], + dir: &'a str, +} + +impl<'a> Psm<'a> { + #[inline(always)] + pub fn new(matter: &'a Matter<'a>) -> Result { + let mut buf = [0; 4096]; + Ok(Self { matter, buf, dir: "test" }) + } + + pub async fn run(&mut self) -> Result<(), Error> { + debug!("PSM running..."); + loop { + self.matter.wait_changed().await; + + if self.matter.is_changed() { + if let Some(data) = self.matter.store_acls(&mut self.buf)? { + debug!("Store ACL data..."); + Self::store("acls", data)?; + } + + if let Some(data) = self.matter.store_fabrics(&mut self.buf)? { + debug!("Store fabric data..."); + Self::store("fabrics", data)?; + } + } + } + } + + fn load<'b>(key: &str, buf: &'b mut [u8]) -> Result, Error> { + debug!("Load data"); + Ok(None) + } + + fn store(key: &str, data: &[u8]) -> Result<(), Error> { + debug!("Store data"); + Ok(()) + } +} \ No newline at end of file diff --git a/examples/rust-matter-light/src/saul_reg.rs b/examples/rust-matter-light/src/saul_reg.rs new file mode 100644 index 000000000000..76f82eb29340 --- /dev/null +++ b/examples/rust-matter-light/src/saul_reg.rs @@ -0,0 +1,119 @@ +use core::ffi::CStr; +use riot_wrappers::println; + +// saul module +use riot_wrappers::saul::{ + registration::{Drivable, Driver, Error, register_and_then}, + Class, ActuatorClass, Phydat, RegistryEntry +}; +// shell module +use riot_wrappers::shell::{self, CommandList}; +use crate::gpio::{RGB_BLUE_PIN, RGB_GREEN_PIN, RGB_PORT, RGB_RED_PIN, set_output}; + +pub struct RgbLed { + name: &'static str, + portpin_red: (u32, u32), + portpin_green: (u32, u32), + portpin_blue: (u32, u32), +} + +impl RgbLed { + pub fn new(name: &'static str, red: (u32, u32), green: (u32, u32), blue: (u32, u32)) -> Self { + RgbLed { + name, + portpin_red: red, + portpin_green: green, + portpin_blue: blue, + } + } +} + +struct CurrentColor { + red: i16, + green: i16, + blue: i16, +} + +static mut RGB_CURRENT: CurrentColor = CurrentColor { + red: 0, + green: 0, + blue: 0 +}; + +pub static RGB_LED_DRIVER: Driver = Driver::new(); + +impl Drivable for &RgbLed { + const CLASS: Class = Class::Actuator(Some(ActuatorClass::LedRgb)); + const HAS_READ: bool = true; + const HAS_WRITE: bool = true; + + fn read(self) -> Result { + let value = Phydat::new(&[ + unsafe { RGB_CURRENT.red }, + unsafe { RGB_CURRENT.green }, + unsafe { RGB_CURRENT.blue }], + None, + 0 + ); + println!("Reading from RGB LED: {:?}", value); + Ok(value) + } + + fn write(self, data: &Phydat) -> Result { + println!("Writing {:?} to {}", data, self.name); + let values = data.value(); + + set_output(self.portpin_red.0, self.portpin_red.1, values[0] > 0); + set_output(self.portpin_green.0, self.portpin_green.1, values[1] > 0); + set_output(self.portpin_blue.0, self.portpin_blue.1, values[2] > 0); + +/* // obtain GPIO outputs for RGB LED's and set values + let mut red = get_output(self.portpin_red.0, self.portpin_red.1); + red.set_state(values[0] > 0); + let mut green = get_output(self.portpin_green.0, self.portpin_green.1); + green.set_state(values[1] > 0); + let mut blue = get_output(self.portpin_blue.0, self.portpin_blue.1); + blue.set_state(values[2] > 0); */ + + // save current RGB values + unsafe { + RGB_CURRENT.red = values[0]; + RGB_CURRENT.green = values[1]; + RGB_CURRENT.blue = values[2]; + } + + Ok(1) + } +} + +pub fn find_actuator(actuator_type: ActuatorClass) -> Option { + let mut rgb_led: Option = None; + // Find RGB LED at SAUL registry and write values to it + RegistryEntry::all().for_each(|entry| { + if let Some(Class::Actuator(Some(actuator_type))) = entry.type_() { + rgb_led = Some(entry); + } + } + ); + + rgb_led +} + +pub fn run_shell_with_saul() -> ! { + let rgb_led = RgbLed::new( + "Color Temperature Light", + (RGB_PORT, RGB_RED_PIN), + (RGB_PORT, RGB_GREEN_PIN), + (RGB_PORT, RGB_BLUE_PIN), + ); + + register_and_then( + &RGB_LED_DRIVER, + &rgb_led, + Some(CStr::from_bytes_with_nul(b"Color Temperature Light\0").unwrap()), + || { + println!("RGB LED registered as SAUL actuator"); + shell::new().run_forever_providing_buf() + }, + ); +} \ No newline at end of file diff --git a/examples/rust-matter-light/src/shell.rs b/examples/rust-matter-light/src/shell.rs new file mode 100644 index 000000000000..c8597962affc --- /dev/null +++ b/examples/rust-matter-light/src/shell.rs @@ -0,0 +1,30 @@ +fn cmd_onoff(_stdio: &mut stdio::Stdio, args: shell::Args<'_>) { + let arg_state = args.get(1); + match arg_state { + Some(state_str) => { + let is_on: bool; + match state_str { + "on" => is_on = true, + "off" => is_on = false, + _ => { + println!("Invalid argument for LED state (must be 'on' or 'off')"); + return; + } + } + use riot_wrappers::saul::{Phydat, ActuatorClass}; + let rgb_led = saul_reg::find_actuator(ActuatorClass::LedRgb).expect("No registered RGB LED was found!"); + let data: Phydat; + if is_on { + data = Phydat::new(&[1, 1, 1], None, 0); + } else { + data = Phydat::new(&[0, 0, 0], None, 0); + } + let _ = rgb_led.write(data); + } + None => { + println!("Usage: onoff [on|off]"); + } + } +} + +static_command!(cmd_onoff, "onoff", "Turn the Color Light on or off", cmd_onoff); \ No newline at end of file diff --git a/examples/rust-matter-light/src/tests.rs b/examples/rust-matter-light/src/tests.rs new file mode 100644 index 000000000000..0571729a4a9a --- /dev/null +++ b/examples/rust-matter-light/src/tests.rs @@ -0,0 +1,87 @@ +use embedded_nal_async::{SocketAddr, UdpStack, UnconnectedUdp}; +use log::{debug, error, info}; +use riot_wrappers::socket_embedded_nal_async_udp::UnconnectedUdpSocket; +use rs_matter::error::Error; +use rs_matter::transport::core::MATTER_SOCKET_BIND_ADDR; +use rs_matter::transport::network::{UdpReceive, UdpSend}; +use static_cell::StaticCell; +use core::str; +use riot_wrappers::error::{EAGAIN, NumericError}; +use crate::init_logger; +use crate::network::UdpSocketWrapper; +use crate::network::utils::initialize_network; + +// Set this as entry point with 'riot_main!' macro to run 'integration tests' +fn run_tests() -> ! { + init_logger().expect("Error initializing logger"); + static EXECUTOR: StaticCell = StaticCell::new(); + let executor: &'static mut _ = EXECUTOR.init(embassy_executor_riot::Executor::new()); + executor.run(|spawner| { + spawner.spawn(test_udp()).unwrap(); + }); +} + +async fn udp_send(mut send: S, data: &mut [u8], remote_addr: SocketAddr) -> Result<(), NumericError> + where S: UdpSend { + //let mut buffer: &mut [u8] = &mut [0u8; 255usize]; + return match send.send_to(data, remote_addr).await { + Ok(_) => { + info!("Sent echo!"); + Ok(()) + } + Err(_) => { + error!("Error sending echo!"); + Err(EAGAIN) + } + } +} + +async fn udp_receive(mut recv: R) -> Result<(SocketAddr, [u8; 255], usize), NumericError> + where R: UdpReceive +{ + let mut buffer: [u8; 255] = [0u8; 255usize]; + return match recv.recv_from(&mut buffer).await { + Ok((bytes_recvd, remote_addr)) => { + info!("{} bytes received from {:?}", bytes_recvd, remote_addr); + let as_str = str::from_utf8(&buffer).unwrap().trim_matches('\0'); + debug!("Received data: {:?}", as_str); + debug!("as bytes: {:?}", &buffer[..bytes_recvd]); + Ok((remote_addr, buffer, bytes_recvd)) + } + Err(err) => { + error!("Error during receive: {:?}", err); + Err(EAGAIN) + } + } +} + +#[embassy_executor::task] +async fn test_udp() { + let (ipv6_addr, interface) = initialize_network().expect("Error getting network interface and IP addresses"); + + static UDP_MDNS_SOCKET: StaticCell = StaticCell::new(); + let udp_stack = riot_wrappers::socket_embedded_nal_async_udp::UdpStack::new(|| UDP_MDNS_SOCKET.try_uninit()); + let (addr, mut sock) = udp_stack + .bind_single(MATTER_SOCKET_BIND_ADDR) + .await + .expect("Can't create a socket"); + let mut socket = &UdpSocketWrapper::new(addr, sock); + info!("Listening on [{:?}]:5540", &ipv6_addr); + + let mut buffer: [u8; 255] =[0u8; 255usize]; + loop { + info!("Waiting for incoming packets..."); + match udp_receive(socket).await { + Ok((remote_addr, mut data, len)) => { + info!("{} bytes received from {:?}", len, remote_addr); + let as_str = str::from_utf8(&data).unwrap().trim_matches('\0'); + debug!("Received data: {:?}", as_str); + debug!("as bytes: {:?}", &data[..len]); + udp_send(socket, &mut data[..len], remote_addr).await.expect("error sending response"); + } + Err(err) => { + error!("Error during receive: {:?}", err); + } + } + } +} \ No newline at end of file From f10dc9b59f05766e9dd8b8fa2dfd58b317a08ec0 Mon Sep 17 00:00:00 2001 From: Maik Lorenz Date: Tue, 12 Mar 2024 13:55:38 +0100 Subject: [PATCH 02/19] examples/rust-matter-light: Join mDNS IPv6 multicast group (quick+dirty) The device now answers mDNS queries sent to [FF02::FB]:5353. --- examples/rust-matter-light/src/lib.rs | 8 +++-- examples/rust-matter-light/src/network.rs | 40 +++++++++++------------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/examples/rust-matter-light/src/lib.rs b/examples/rust-matter-light/src/lib.rs index 24a68fc01e77..dcf1db3cdccb 100644 --- a/examples/rust-matter-light/src/lib.rs +++ b/examples/rust-matter-light/src/lib.rs @@ -42,6 +42,10 @@ extern crate rust_riotmodules; use riot_wrappers::riot_main; // rs-matter +#[allow(unused_variables)] +#[allow(dead_code)] +extern crate rs_matter; + use rs_matter::{CommissioningData, MATTER_PORT}; use rs_matter::transport::network::UdpBuffers; use rs_matter::transport::core::{PacketBuffers, MATTER_SOCKET_BIND_ADDR}; @@ -57,9 +61,7 @@ use rs_matter::data_model::{ use rs_matter::data_model::cluster_on_off::OnOffCluster; use rs_matter::error::Error; use rs_matter::mdns::MdnsService; -use rs_matter::mdns::builtin::{ - MDNS_IPV6_BROADCAST_ADDR, MDNS_SOCKET_BIND_ADDR, -}; +use rs_matter::mdns::builtin::MDNS_SOCKET_BIND_ADDR; use rs_matter::secure_channel::spake2p::VerifierData; use rs_matter::tlv::TLVElement; use rs_matter::transport::exchange::Exchange; diff --git a/examples/rust-matter-light/src/network.rs b/examples/rust-matter-light/src/network.rs index 4b6562cd04ab..4237fc69893e 100644 --- a/examples/rust-matter-light/src/network.rs +++ b/examples/rust-matter-light/src/network.rs @@ -95,8 +95,12 @@ impl UdpReceive for &UdpSocketWrapper { } pub mod utils { - use log::{debug, error, info}; use super::*; + use core::ffi::c_void; + use log::info; + use riot_sys::inline::gnrc_netapi_set; + use riot_sys::{netopt_t_NETOPT_IPV6_GROUP, size_t}; + use rs_matter::mdns::builtin::MDNS_IPV6_BROADCAST_ADDR; pub fn get_ipv6_address(ifc: &Netif) -> Option { let all_addresses = ifc.ipv6_addrs(); @@ -124,30 +128,24 @@ pub mod utils { #[inline(never)] pub fn initialize_network() -> Result<(Ipv6Addr, u32), MatterError> { - // Get available network interface(s) - let mut interfaces = Netif::all(); - // Get first available interface - let ifc: Netif = match interfaces.next() { - Some(ifc) => Ok(ifc), - None => { - error!("ERROR: No network interface was found!"); - Err(MatterError::new(ErrorCode::NoNetworkInterface)) - }, - }?; + let ifc: Netif = Netif::all().next().ok_or(ErrorCode::NoNetworkInterface)?; // atm only for debugging: Check name and status of KernelPID let pid = ifc.pid(); - let ifc_name: &str = pid.get_name().unwrap(); - debug!("Kernel PID status of network interface {:?}: {:?}", pid.get_name().unwrap(), pid.status().unwrap()); - - // Get available IPv6 link-local address - match get_ipv6_address(&ifc) { - Some(ipv6) => { - info!("Found network interface {} with IP {}", ifc_name, ipv6); - Ok((ipv6, 0 as _)) - }, - None => Err(MatterError::new(ErrorCode::StdIoError)), + let ifc_name: &str = pid.get_name().unwrap_or("unknown"); + + // TODO: This should be in riot-wrappers! + unsafe { + let addr = MDNS_IPV6_BROADCAST_ADDR.octets(); + let addr_ptr = addr.as_ptr() as *const c_void; + let _ = gnrc_netapi_set(pid.into(), netopt_t_NETOPT_IPV6_GROUP, 0, addr_ptr, addr.len() as size_t); } + info!("Joined IPV6 multicast group @ {:?}", MDNS_IPV6_BROADCAST_ADDR); + + // Get available IPv6 link-local address + let ipv6 = get_ipv6_address(&ifc).ok_or(ErrorCode::StdIoError)?; + info!("Found network interface '{}' with IP {}", ifc_name, ipv6); + Ok((ipv6, 0 as _)) } } \ No newline at end of file From 401db6a5d88ec4f26ecb5a84fc40c3ff2157e34f Mon Sep 17 00:00:00 2001 From: Maik Lorenz Date: Wed, 13 Mar 2024 14:37:14 +0100 Subject: [PATCH 03/19] examples/rust-matter-light: Adjust stack size for nucleo-f429zi and toggle Board LED's Enabled 'nightly' feature for embassy-executor, so memory for tasks will be statically allocated at compile time. Commands On,Off,Toggle are now handled so all switches (LEDs) registered at SAUL will be turned on/off. Also did some refactoring and added config.toml for compatibility with rust-analyzer. --- examples/rust-matter-light/.cargo/config.toml | 7 + examples/rust-matter-light/Cargo.lock | 9 +- examples/rust-matter-light/Cargo.toml | 11 +- examples/rust-matter-light/Makefile | 13 +- examples/rust-matter-light/src/gpio.rs | 34 ----- examples/rust-matter-light/src/lib.rs | 140 ++++++++++++------ examples/rust-matter-light/src/light.rs | 79 ---------- examples/rust-matter-light/src/logging.rs | 2 +- examples/rust-matter-light/src/rgb_led.rs | 45 ++++++ examples/rust-matter-light/src/saul_reg.rs | 119 --------------- examples/rust-matter-light/src/shell.rs | 30 ---- 11 files changed, 166 insertions(+), 323 deletions(-) create mode 100644 examples/rust-matter-light/.cargo/config.toml delete mode 100644 examples/rust-matter-light/src/gpio.rs delete mode 100644 examples/rust-matter-light/src/light.rs create mode 100644 examples/rust-matter-light/src/rgb_led.rs delete mode 100644 examples/rust-matter-light/src/saul_reg.rs delete mode 100644 examples/rust-matter-light/src/shell.rs diff --git a/examples/rust-matter-light/.cargo/config.toml b/examples/rust-matter-light/.cargo/config.toml new file mode 100644 index 000000000000..7cfa0b2edb8b --- /dev/null +++ b/examples/rust-matter-light/.cargo/config.toml @@ -0,0 +1,7 @@ +[env] +RIOTBUILD_CONFIG_HEADER_C = { value = "bin/native64/riotbuild/riotbuild.h", relative = true } +RIOT_COMPILE_COMMANDS_JSON = { value = "bin/native64/cargo-compile-commands.json", relative = true } + +[build] +target = "i686-unknown-linux-gnu" +message-format = "json" \ No newline at end of file diff --git a/examples/rust-matter-light/Cargo.lock b/examples/rust-matter-light/Cargo.lock index b8c1dd663093..d993b7e32903 100644 --- a/examples/rust-matter-light/Cargo.lock +++ b/examples/rust-matter-light/Cargo.lock @@ -1644,7 +1644,7 @@ dependencies = [ [[package]] name = "rs-matter" version = "0.1.2" -source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#8c791266bad99264cce45ea971eb5714205826af" +source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#abd482eea52bed5cca549a4a468a1659d73a4e3c" dependencies = [ "aes", "astro-dnssd", @@ -1690,7 +1690,7 @@ dependencies = [ [[package]] name = "rs-matter-data-model" version = "0.1.0" -source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#8c791266bad99264cce45ea971eb5714205826af" +source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#abd482eea52bed5cca549a4a468a1659d73a4e3c" dependencies = [ "clap", "miette", @@ -1706,7 +1706,7 @@ dependencies = [ [[package]] name = "rs-matter-macros" version = "0.1.0" -source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#8c791266bad99264cce45ea971eb5714205826af" +source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#abd482eea52bed5cca549a4a468a1659d73a4e3c" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -1719,7 +1719,7 @@ dependencies = [ [[package]] name = "rs-matter-macros-impl" version = "0.1.0" -source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#8c791266bad99264cce45ea971eb5714205826af" +source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#abd482eea52bed5cca549a4a468a1659d73a4e3c" dependencies = [ "convert_case", "proc-macro2", @@ -1737,6 +1737,7 @@ dependencies = [ "embassy-futures", "embassy-sync", "embedded-alloc", + "embedded-hal 1.0.0", "embedded-hal-async", "embedded-nal-async 0.7.1", "log", diff --git a/examples/rust-matter-light/Cargo.toml b/examples/rust-matter-light/Cargo.toml index 274b2f642ac4..c861c2870779 100644 --- a/examples/rust-matter-light/Cargo.toml +++ b/examples/rust-matter-light/Cargo.toml @@ -13,11 +13,15 @@ crate-type = ["staticlib"] # supports no unwinding), but setting it allows builds on native without using # the nightly-only lang_items feature. panic = "abort" -#debug = true -opt-level = "s" +opt-level = 3 codegen-units = 1 lto = true +[profile.dev] +panic = "abort" +debug = true +opt-level = 3 + [dependencies] riot-wrappers = { git = "https://github.com/RIOT-OS/rust-riot-wrappers.git", features = [ "set_panic_handler", "panic_handler_format", "panic_handler_crash", "with_embedded_nal_async", "provide_critical_section_1_0", "with_embedded_hal_async" ] } riot-sys = "*" @@ -35,7 +39,8 @@ rust_riotmodules = { path = "../../sys/rust_riotmodules/" } static_cell = "2.0.0" embassy-executor-riot = { git = "https://gitlab.com/etonomy/riot-module-examples" } -embassy-executor = { version = "0.5", features = ["task-arena-size-196608"] } +embassy-executor = { version = "0.5", features = ["nightly"] } +embedded-hal = "1.0.0" embassy-futures = "0.1.1" rs-matter = { version = "0.1.0", default-features = false, features = ["riot-os"] } diff --git a/examples/rust-matter-light/Makefile b/examples/rust-matter-light/Makefile index 72481d476629..632575c9950a 100644 --- a/examples/rust-matter-light/Makefile +++ b/examples/rust-matter-light/Makefile @@ -15,14 +15,11 @@ DEVELHELP ?= 1 # Change this to 0 show compiler invocation lines by default: QUIET ?= 1 -# for embedded -#CFLAGS += '-DTHREAD_STACKSIZE_MAIN=(THREAD_STACKSIZE_DEFAULT + 64000)' -#CFLAGS += '-DISR_STACKSIZE=(THREAD_STACKSIZE_DEFAULT + 10000)' - -# for native can be bigger (may decrease after development) -CFLAGS += '-DTHREAD_STACKSIZE_MAIN=(THREAD_STACKSIZE_DEFAULT + 180*1024)' -CFLAGS += '-DTHREAD_STACKSIZE_IDLE=(THREAD_STACKSIZE_DEFAULT + 180*1024)' -CFLAGS += '-DISR_STACKSIZE=(THREAD_STACKSIZE_DEFAULT + 180*1024)' +# Estimated minimum usage (critical parts): +# - UDP and Packet Buffers: 26 kB (Stack and during embassy polling ISR) +# - embassy_executor tasks: statically allocated at compile time (nightly feature) +CFLAGS += '-DTHREAD_STACKSIZE_MAIN=(THREAD_STACKSIZE_DEFAULT + 20000)' +CFLAGS += '-DISR_STACKSIZE=(THREAD_STACKSIZE_DEFAULT + 30000)' # The name of crate (as per Cargo.toml package name, but with '-' replaced with '_') APPLICATION_RUST_MODULE = rust_matter_light diff --git a/examples/rust-matter-light/src/gpio.rs b/examples/rust-matter-light/src/gpio.rs deleted file mode 100644 index e3971384ecee..000000000000 --- a/examples/rust-matter-light/src/gpio.rs +++ /dev/null @@ -1,34 +0,0 @@ -// periph_gpio module -use riot_wrappers::gpio::{GPIO, OutputGPIO, OutputMode, InputGPIO, InputMode}; - - -// Application-specific constants -// User LED port and pin on used boards -pub const LED_PORT: u32 = 0; -pub const LED_PIN: u32 = 5; - -// RGB LED port and pin -pub const RGB_PORT: u32 = 0; -pub const RGB_RED_PIN: u32 = 7; -pub const RGB_GREEN_PIN: u32 = 6; -pub const RGB_BLUE_PIN: u32 = 5; - - -// TODO: Make GPIO's static members -pub fn get_output(port: u32, pin: u32) -> OutputGPIO { - GPIO::from_port_and_pin(port, pin) - .expect("Error configuring pin") - .configure_as_output(OutputMode::Out) - .expect("Error configuring GPIO output") -} - -pub fn get_input(port: u32, pin: u32) -> InputGPIO { - GPIO::from_port_and_pin(port, pin) - .expect("Error configuring pin") - .configure_as_input(InputMode::In) - .expect("Error configuring GPIO input") -} - -pub fn set_output(port: u32, pin: u32, on: bool) { - get_output(port, pin).set_state(on); -} \ No newline at end of file diff --git a/examples/rust-matter-light/src/lib.rs b/examples/rust-matter-light/src/lib.rs index dcf1db3cdccb..92861114bc1d 100644 --- a/examples/rust-matter-light/src/lib.rs +++ b/examples/rust-matter-light/src/lib.rs @@ -4,48 +4,51 @@ // General Public License v2.1. See the file LICENSE in the top level // directory for more details. #![no_std] - +#![feature(type_alias_impl_trait)] // declare internal modules mod dev_att; mod network; +#[allow(dead_code)] +mod rgb_led; #[allow(unused)] mod persist; mod logging; - -#[allow(unused)] -pub mod gpio; -#[allow(unused)] -pub mod light; -#[allow(unused)] -pub mod saul_reg; +// TODO: Enable attribute or feature to be able to run integration tests inside this module under RIOT OS #[allow(unused)] mod tests; // internal modules imports -use network::utils::{initialize_network}; -use logging::init_logger; use network::UdpSocketWrapper; +use network::utils::initialize_network; +use logging::init_logger; +use dev_att::HardCodedDevAtt; +use rgb_led::{RGB_LED_DRIVER, RgbLed, RGB_BLUE_PIN, RGB_GREEN_PIN, RGB_PORT, RGB_RED_PIN}; // core library use core::{borrow::Borrow, pin::pin}; use core::cell::Cell; +use core::ffi::CStr; // external crates use static_cell::StaticCell; use embedded_nal_async::{Ipv4Addr, UdpStack as _}; use embedded_alloc::Heap; -use log::{debug, info, error}; +use embedded_hal::delay::DelayNs as _; +use log::{debug, info, error, warn}; // RIOT OS modules extern crate rust_riotmodules; use riot_wrappers::riot_main; +use riot_wrappers::ztimer; +use riot_wrappers::saul::{ActuatorClass, Class, Phydat, RegistryEntry}; +use riot_wrappers::saul::registration::register_and_then; +use riot_wrappers::shell::{self, CommandList as _}; // rs-matter #[allow(unused_variables)] #[allow(dead_code)] extern crate rs_matter; - use rs_matter::{CommissioningData, MATTER_PORT}; use rs_matter::transport::network::UdpBuffers; use rs_matter::transport::core::{PacketBuffers, MATTER_SOCKET_BIND_ADDR}; @@ -79,25 +82,13 @@ const NODE: Node<'static> = Node { ], }; -static DEV_DET: BasicInfoConfig = BasicInfoConfig { - vid: 0xFFF1, - pid: 0x8000, - hw_ver: 2, - sw_ver: 1, - sw_ver_str: "1", - serial_no: "aabbccddd", - device_name: "OnOff Light", - product_name: "Light123", - vendor_name: "Vendor 123", -}; - #[allow(dead_code)] -struct MyOnOffCluster { +struct OnOffHandler { cluster: OnOffCluster, on: Cell, } -impl MyOnOffCluster { +impl OnOffHandler { fn new(cluster: OnOffCluster) -> Self { Self { cluster, @@ -106,25 +97,36 @@ impl MyOnOffCluster { } } -impl Handler for MyOnOffCluster { +impl Handler for OnOffHandler { fn read(&self, attr: &AttrDetails, encoder: AttrDataEncoder) -> Result<(), Error> { - info!("MyOnOffCluster - read: {:?}", attr); - OnOffCluster::read(&self.cluster, attr, encoder) + info!("OnOffCluster: Read attribute {:#04x} @ Endpoint {}", attr.attr_id, attr.endpoint_id); + self.cluster.read(attr, encoder) } fn write(&self, attr: &AttrDetails, data: AttrData) -> Result<(), Error> { - info!("MyOnOffCluster - write: {:?}", attr); - OnOffCluster::write(&self.cluster, attr, data) + info!("OnOffCluster: Write attribute {:#04x} @ Endpoint {}", attr.attr_id, attr.endpoint_id); + self.cluster.write(attr, data) } fn invoke(&self, exchange: &Exchange, cmd: &CmdDetails, data: &TLVElement, encoder: CmdDataEncoder) -> Result<(), Error> { - info!("MyOnOffCluster - invoke: cmd={:?}, data={:?}", cmd, data.u32()); - OnOffCluster::invoke(&self.cluster, exchange, cmd, data, encoder) + info!("OnOffCluster: Invoke cmd {:#02x} (data: {}) @ Endpoint {}", cmd.cmd_id, data.u32().unwrap_or(0), cmd.endpoint_id); + // Handle command by ID -> 0x00: Off, 0x01: On, 0x02: Toggle + match cmd.cmd_id { + 0 => led_onoff(false), + 1 => led_onoff(true), + 2 => { + let new_state = !self.on.get(); + self.on.set(new_state); + led_onoff(new_state); + }, + _ => { warn!("Unsupported command by application -> ignored!"); } + } + self.cluster.invoke(exchange, cmd, data, encoder) } } -impl NonBlockingHandler for MyOnOffCluster {} +impl NonBlockingHandler for OnOffHandler {} -// Handler for endpoint 1 (Descriptor + OnOff Cluster) +// Handler for endpoints 0 (Root) and 1 (Descriptor + OnOff Cluster) fn matter_handler<'a>(matter: &'a Matter<'a>) -> impl Metadata + NonBlockingHandler + 'a { ( NODE, @@ -137,8 +139,7 @@ fn matter_handler<'a>(matter: &'a Matter<'a>) -> impl Metadata + NonBlockingHand .chain( 1, cluster_on_off::ID, - //cluster_on_off::OnOffCluster::new(*matter.borrow()), - MyOnOffCluster::new(cluster_on_off::OnOffCluster::new(*matter.borrow())), + OnOffHandler::new(cluster_on_off::OnOffCluster::new(*matter.borrow())), ), ) } @@ -148,19 +149,56 @@ static HEAP: Heap = Heap::empty(); riot_main!(main); +fn led_onoff(on: bool) { + // Iterate through all SAUL registry entries and set all switches to the desired state + RegistryEntry::all().for_each(|entry| { + if let Some(Class::Actuator(Some(ActuatorClass::Switch))) = entry.type_() { + info!("Writing to {}", entry.name().unwrap_or("n/a")); + let data = Phydat::new(&[on as i16], None, 0); + entry.write(data).expect("Error while trying to set LED"); + info!("LED was set to {:?}", on); + } + } + ); +} + fn main() -> ! { { use core::mem::MaybeUninit; - const HEAP_SIZE: usize = 1024 * 180; + const HEAP_SIZE: usize = 4192; static mut HEAP_MEM: [MaybeUninit; HEAP_SIZE] = [MaybeUninit::uninit(); HEAP_SIZE]; unsafe { HEAP.init(HEAP_MEM.as_ptr() as usize, HEAP_SIZE) } } init_logger().expect("Error initializing logger"); + let mut clock = ztimer::Clock::msec(); + clock.delay_ms(1000); info!("Hello Matter on RIOT!"); - let (ipv6_addr, interface) = initialize_network().expect("Error getting network interface and IP addresses"); + use core::mem::size_of; + info!("Matter memory usage: UdpBuffers={}, PacketBuffers={}, \ + MdnsService={}, Matter={}", + size_of::(), + size_of::(), + size_of::(), + size_of::(), + ); + + let (ipv6_addr, interface) = initialize_network() + .expect("Error getting network interface and IP addresses"); + + static DEV_DET: BasicInfoConfig = BasicInfoConfig { + vid: 0xFFF1, + pid: 0x8000, + hw_ver: 2, + sw_ver: 1, + sw_ver_str: "1", + serial_no: "aabbccddd", + device_name: "OnOff Light", + product_name: "Light123", + vendor_name: "Vendor 123", + }; static MDNS: StaticCell = StaticCell::new(); let mdns_service: &'static MdnsService = MDNS.init(MdnsService::new( @@ -173,8 +211,8 @@ fn main() -> ! { )); // Get Device attestation (hard-coded atm) - static DEV_ATT: StaticCell = StaticCell::new(); - let dev_att: &'static dev_att::HardCodedDevAtt = DEV_ATT.init(dev_att::HardCodedDevAtt::new()); + static DEV_ATT: StaticCell = StaticCell::new(); + let dev_att: &'static HardCodedDevAtt = DEV_ATT.init(HardCodedDevAtt::new()); // TODO: Provide own epoch and rand functions let epoch = rs_matter::utils::epoch::riot_epoch; @@ -193,10 +231,24 @@ fn main() -> ! { info!("Starting all services..."); - // TODO: Maybe run shell in seperate thread + // TODO: Register RGB-LED at SAUL and run shell in seperate thread let mut _shell_thread = || { debug!("Shell is running"); - saul_reg::run_shell_with_saul(); + let rgb_led = RgbLed::new( + "Extended Color Light", + (RGB_PORT, RGB_RED_PIN), + (RGB_PORT, RGB_GREEN_PIN), + (RGB_PORT, RGB_BLUE_PIN), + ); + register_and_then( + &RGB_LED_DRIVER, + &rgb_led, + Some(CStr::from_bytes_with_nul(b"Extended Color Light\0").unwrap()), + || { + info!("RGB-LED registered as SAUL actuator"); + shell::new().run_forever_providing_buf() + }, + ); }; static EXECUTOR: StaticCell = StaticCell::new(); @@ -222,8 +274,6 @@ async fn run_mdns(mdns: &'static MdnsService<'_>) { let socket = UdpSocketWrapper::new(mdns_addr, mdns_sock); debug!("Created UDP socket for mDNS at {:?}", &mdns_addr); - // TODO: Join IPv6 Multicast group (MDNS_IPV6_BROADCAST_ADDR) - // Finally run the MDNS service let mut mdns_udp_buffers = UdpBuffers::new(); let mdns_runner = pin!(mdns.run( diff --git a/examples/rust-matter-light/src/light.rs b/examples/rust-matter-light/src/light.rs deleted file mode 100644 index 789cd32e34ad..000000000000 --- a/examples/rust-matter-light/src/light.rs +++ /dev/null @@ -1,79 +0,0 @@ -use core::fmt::Debug; - -// riot modules -use riot_wrappers::println; - -pub trait OnOffDevice { - fn onoff_set(&mut self, on: bool); - fn is_on(&self) -> bool; -} - -pub trait ColorLight { - fn set_color(&mut self, color: RgbColor); - fn get_current_color(&self) -> Option<&RgbColor>; -} - -#[derive(Debug, Clone, Default)] -pub struct RgbColor { - red: u8, - green: u8, - blue: u8, -} - -pub struct ColorTemperatureLight { - pub on: bool, - portpin_red: (u32, u32), - portpin_green: (u32, u32), - portpin_blue: (u32, u32), - current_color: RgbColor, -} - -impl ColorTemperatureLight { - pub fn new(red_port: u32, red_pin: u32, green_port: u32, green_pin: u32, blue_port: u32, blue_pin: u32, ) -> Self { - Self { - on: false, - portpin_red: (red_port, red_pin), - portpin_green: (green_port, green_pin), - portpin_blue: (blue_port, blue_pin), - current_color: RgbColor::default(), - } - } -} - -impl Debug for ColorTemperatureLight { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.debug_struct("ColorTemperatureLight") - .field("on", &self.on) - .field("current_color", &self.current_color) - .finish() - } -} - -impl ColorLight for ColorTemperatureLight { - fn set_color(&mut self, color: RgbColor) { - println!("Setting color: {:?}", &color); - // TODO: Control GPIO's and set color - self.current_color = color; - } - - fn get_current_color(&self) -> Option<&RgbColor> { - if !self.on { - return None - } - Some(&self.current_color) - } -} - -mod test { - use super::*; - - #[test] - fn test_color_temperature_light_new() { - let light = ColorTemperatureLight::new(0, 1, 1, 2, 2, 2); - assert_eq!(false, light.on); - let color = light.current_color; - assert_eq!(0, color.red); - assert_eq!(0, color.green); - assert_eq!(0, color.blue); - } -} \ No newline at end of file diff --git a/examples/rust-matter-light/src/logging.rs b/examples/rust-matter-light/src/logging.rs index 1684d7796084..bd9995173a9d 100644 --- a/examples/rust-matter-light/src/logging.rs +++ b/examples/rust-matter-light/src/logging.rs @@ -23,5 +23,5 @@ pub fn init_logger() -> Result<(), SetLoggerError> { //let log_level: &'static str = env!("RIOT_LOG_LEVEL"); //println!("the RIOT_LOG_LEVEL variable at the time of compiling was: {log_level}"); log::set_logger(&LOGGER) - .map(|_| log::set_max_level(LevelFilter::Debug)) + .map(|_| log::set_max_level(LevelFilter::Info)) } \ No newline at end of file diff --git a/examples/rust-matter-light/src/rgb_led.rs b/examples/rust-matter-light/src/rgb_led.rs new file mode 100644 index 000000000000..1ea9b1a801d6 --- /dev/null +++ b/examples/rust-matter-light/src/rgb_led.rs @@ -0,0 +1,45 @@ +use log::info; +use riot_wrappers::saul::{ActuatorClass, Class, Phydat}; +use riot_wrappers::saul::registration::{Drivable, Driver, Error}; + +pub const RGB_PORT: u32 = 0; +pub const RGB_RED_PIN: u32 = 7; +pub const RGB_GREEN_PIN: u32 = 6; +pub const RGB_BLUE_PIN: u32 = 5; + +pub struct RgbLed { + name: &'static str, + portpin_red: (u32, u32), + portpin_green: (u32, u32), + portpin_blue: (u32, u32), +} + +impl RgbLed { + pub fn new(name: &'static str, red: (u32, u32), green: (u32, u32), blue: (u32, u32)) -> Self { + RgbLed { + name, + portpin_red: red, + portpin_green: green, + portpin_blue: blue, + } + } +} + +pub static RGB_LED_DRIVER: Driver = Driver::new(); + +impl Drivable for &RgbLed { + const CLASS: Class = Class::Actuator(Some(ActuatorClass::LedRgb)); + const HAS_READ: bool = true; + const HAS_WRITE: bool = true; + + fn read(self) -> Result { + let value = Phydat::new(&[0,0,0], None, 0); + info!("Reading from RGB LED: {:?}", value); + Ok(value) + } + + fn write(self, data: &Phydat) -> Result { + info!("Writing {:?} to {}", data, self.name); + Ok(1) + } +} \ No newline at end of file diff --git a/examples/rust-matter-light/src/saul_reg.rs b/examples/rust-matter-light/src/saul_reg.rs deleted file mode 100644 index 76f82eb29340..000000000000 --- a/examples/rust-matter-light/src/saul_reg.rs +++ /dev/null @@ -1,119 +0,0 @@ -use core::ffi::CStr; -use riot_wrappers::println; - -// saul module -use riot_wrappers::saul::{ - registration::{Drivable, Driver, Error, register_and_then}, - Class, ActuatorClass, Phydat, RegistryEntry -}; -// shell module -use riot_wrappers::shell::{self, CommandList}; -use crate::gpio::{RGB_BLUE_PIN, RGB_GREEN_PIN, RGB_PORT, RGB_RED_PIN, set_output}; - -pub struct RgbLed { - name: &'static str, - portpin_red: (u32, u32), - portpin_green: (u32, u32), - portpin_blue: (u32, u32), -} - -impl RgbLed { - pub fn new(name: &'static str, red: (u32, u32), green: (u32, u32), blue: (u32, u32)) -> Self { - RgbLed { - name, - portpin_red: red, - portpin_green: green, - portpin_blue: blue, - } - } -} - -struct CurrentColor { - red: i16, - green: i16, - blue: i16, -} - -static mut RGB_CURRENT: CurrentColor = CurrentColor { - red: 0, - green: 0, - blue: 0 -}; - -pub static RGB_LED_DRIVER: Driver = Driver::new(); - -impl Drivable for &RgbLed { - const CLASS: Class = Class::Actuator(Some(ActuatorClass::LedRgb)); - const HAS_READ: bool = true; - const HAS_WRITE: bool = true; - - fn read(self) -> Result { - let value = Phydat::new(&[ - unsafe { RGB_CURRENT.red }, - unsafe { RGB_CURRENT.green }, - unsafe { RGB_CURRENT.blue }], - None, - 0 - ); - println!("Reading from RGB LED: {:?}", value); - Ok(value) - } - - fn write(self, data: &Phydat) -> Result { - println!("Writing {:?} to {}", data, self.name); - let values = data.value(); - - set_output(self.portpin_red.0, self.portpin_red.1, values[0] > 0); - set_output(self.portpin_green.0, self.portpin_green.1, values[1] > 0); - set_output(self.portpin_blue.0, self.portpin_blue.1, values[2] > 0); - -/* // obtain GPIO outputs for RGB LED's and set values - let mut red = get_output(self.portpin_red.0, self.portpin_red.1); - red.set_state(values[0] > 0); - let mut green = get_output(self.portpin_green.0, self.portpin_green.1); - green.set_state(values[1] > 0); - let mut blue = get_output(self.portpin_blue.0, self.portpin_blue.1); - blue.set_state(values[2] > 0); */ - - // save current RGB values - unsafe { - RGB_CURRENT.red = values[0]; - RGB_CURRENT.green = values[1]; - RGB_CURRENT.blue = values[2]; - } - - Ok(1) - } -} - -pub fn find_actuator(actuator_type: ActuatorClass) -> Option { - let mut rgb_led: Option = None; - // Find RGB LED at SAUL registry and write values to it - RegistryEntry::all().for_each(|entry| { - if let Some(Class::Actuator(Some(actuator_type))) = entry.type_() { - rgb_led = Some(entry); - } - } - ); - - rgb_led -} - -pub fn run_shell_with_saul() -> ! { - let rgb_led = RgbLed::new( - "Color Temperature Light", - (RGB_PORT, RGB_RED_PIN), - (RGB_PORT, RGB_GREEN_PIN), - (RGB_PORT, RGB_BLUE_PIN), - ); - - register_and_then( - &RGB_LED_DRIVER, - &rgb_led, - Some(CStr::from_bytes_with_nul(b"Color Temperature Light\0").unwrap()), - || { - println!("RGB LED registered as SAUL actuator"); - shell::new().run_forever_providing_buf() - }, - ); -} \ No newline at end of file diff --git a/examples/rust-matter-light/src/shell.rs b/examples/rust-matter-light/src/shell.rs deleted file mode 100644 index c8597962affc..000000000000 --- a/examples/rust-matter-light/src/shell.rs +++ /dev/null @@ -1,30 +0,0 @@ -fn cmd_onoff(_stdio: &mut stdio::Stdio, args: shell::Args<'_>) { - let arg_state = args.get(1); - match arg_state { - Some(state_str) => { - let is_on: bool; - match state_str { - "on" => is_on = true, - "off" => is_on = false, - _ => { - println!("Invalid argument for LED state (must be 'on' or 'off')"); - return; - } - } - use riot_wrappers::saul::{Phydat, ActuatorClass}; - let rgb_led = saul_reg::find_actuator(ActuatorClass::LedRgb).expect("No registered RGB LED was found!"); - let data: Phydat; - if is_on { - data = Phydat::new(&[1, 1, 1], None, 0); - } else { - data = Phydat::new(&[0, 0, 0], None, 0); - } - let _ = rgb_led.write(data); - } - None => { - println!("Usage: onoff [on|off]"); - } - } -} - -static_command!(cmd_onoff, "onoff", "Turn the Color Light on or off", cmd_onoff); \ No newline at end of file From 96f67e437b218bed0aa42c3075dd340d7b84a699 Mon Sep 17 00:00:00 2001 From: Maik Lorenz Date: Tue, 19 Mar 2024 11:45:37 +0100 Subject: [PATCH 04/19] examples/rust-matter-light: Adjust optimizations; Refactoring; Remove unused modules --- examples/rust-matter-light/Cargo.lock | 4 --- examples/rust-matter-light/Cargo.toml | 8 +++--- examples/rust-matter-light/Makefile | 22 ++++++++-------- examples/rust-matter-light/src/lib.rs | 31 +++++++++++++---------- examples/rust-matter-light/src/logging.rs | 4 +-- examples/rust-matter-light/src/network.rs | 4 +-- examples/rust-matter-light/src/tests.rs | 4 +-- 7 files changed, 39 insertions(+), 38 deletions(-) diff --git a/examples/rust-matter-light/Cargo.lock b/examples/rust-matter-light/Cargo.lock index d993b7e32903..6ded13f4787d 100644 --- a/examples/rust-matter-light/Cargo.lock +++ b/examples/rust-matter-light/Cargo.lock @@ -1644,7 +1644,6 @@ dependencies = [ [[package]] name = "rs-matter" version = "0.1.2" -source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#abd482eea52bed5cca549a4a468a1659d73a4e3c" dependencies = [ "aes", "astro-dnssd", @@ -1690,7 +1689,6 @@ dependencies = [ [[package]] name = "rs-matter-data-model" version = "0.1.0" -source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#abd482eea52bed5cca549a4a468a1659d73a4e3c" dependencies = [ "clap", "miette", @@ -1706,7 +1704,6 @@ dependencies = [ [[package]] name = "rs-matter-macros" version = "0.1.0" -source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#abd482eea52bed5cca549a4a468a1659d73a4e3c" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -1719,7 +1716,6 @@ dependencies = [ [[package]] name = "rs-matter-macros-impl" version = "0.1.0" -source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#abd482eea52bed5cca549a4a468a1659d73a4e3c" dependencies = [ "convert_case", "proc-macro2", diff --git a/examples/rust-matter-light/Cargo.toml b/examples/rust-matter-light/Cargo.toml index c861c2870779..315a56632843 100644 --- a/examples/rust-matter-light/Cargo.toml +++ b/examples/rust-matter-light/Cargo.toml @@ -13,9 +13,11 @@ crate-type = ["staticlib"] # supports no unwinding), but setting it allows builds on native without using # the nightly-only lang_items feature. panic = "abort" -opt-level = 3 +opt-level = "s" codegen-units = 1 +debug = false lto = true +strip="debuginfo" [profile.dev] panic = "abort" @@ -45,5 +47,5 @@ embassy-futures = "0.1.1" rs-matter = { version = "0.1.0", default-features = false, features = ["riot-os"] } [patch.crates-io] -#rs-matter = { path = "../../../rs-matter/rs-matter" } -rs-matter = { git = "https://github.com/maikerlab/rs-matter", branch = "feature/RIOT_OS" } \ No newline at end of file +rs-matter = { path = "../../../rs-matter/rs-matter" } +#rs-matter = { git = "https://github.com/maikerlab/rs-matter", branch = "feature/RIOT_OS" } \ No newline at end of file diff --git a/examples/rust-matter-light/Makefile b/examples/rust-matter-light/Makefile index 632575c9950a..7a77c42a6ff4 100644 --- a/examples/rust-matter-light/Makefile +++ b/examples/rust-matter-light/Makefile @@ -18,8 +18,8 @@ QUIET ?= 1 # Estimated minimum usage (critical parts): # - UDP and Packet Buffers: 26 kB (Stack and during embassy polling ISR) # - embassy_executor tasks: statically allocated at compile time (nightly feature) -CFLAGS += '-DTHREAD_STACKSIZE_MAIN=(THREAD_STACKSIZE_DEFAULT + 20000)' -CFLAGS += '-DISR_STACKSIZE=(THREAD_STACKSIZE_DEFAULT + 30000)' +CFLAGS += '-DTHREAD_STACKSIZE_MAIN=(THREAD_STACKSIZE_DEFAULT + 40000)' +CFLAGS += '-DISR_STACKSIZE=(THREAD_STACKSIZE_DEFAULT + 20000)' # The name of crate (as per Cargo.toml package name, but with '-' replaced with '_') APPLICATION_RUST_MODULE = rust_matter_light @@ -29,13 +29,13 @@ FEATURES_REQUIRED += rust_target USEMODULE += saul USEMODULE += saul_default -USEMODULE += shell -USEMODULE += shell_cmds_default -USEMODULE += periph_gpio +#USEMODULE += shell +#USEMODULE += shell_cmds_default +#USEMODULE += periph_gpio USEMODULE += ztimer USEMODULE += ztimer_msec USEMODULE += ztimer_usec -USEMODULE += ps +#USEMODULE += ps # networking USEMODULE += netdev_default @@ -43,13 +43,13 @@ USEMODULE += auto_init_gnrc_netif USEMODULE += gnrc_ipv6_default USEMODULE += gnrc_icmpv6_echo USEMODULE += gnrc_icmpv6_error -USEMODULE += shell_cmd_gnrc_udp +#USEMODULE += shell_cmd_gnrc_udp USEMODULE += sock_udp USEMODULE += sock_async USEMODULE += sock_aux_local -USEMODULE += ipv6 -USEMODULE += netstats_l2 -USEMODULE += netstats_ipv6 -USEMODULE += netstats_rpl +#USEMODULE += ipv6 +#USEMODULE += netstats_l2 +#USEMODULE += netstats_ipv6 +#USEMODULE += netstats_rpl include $(RIOTBASE)/Makefile.include diff --git a/examples/rust-matter-light/src/lib.rs b/examples/rust-matter-light/src/lib.rs index 92861114bc1d..d488a4ac900c 100644 --- a/examples/rust-matter-light/src/lib.rs +++ b/examples/rust-matter-light/src/lib.rs @@ -35,7 +35,7 @@ use static_cell::StaticCell; use embedded_nal_async::{Ipv4Addr, UdpStack as _}; use embedded_alloc::Heap; use embedded_hal::delay::DelayNs as _; -use log::{debug, info, error, warn}; +use log::{debug, info, error, warn, LevelFilter}; // RIOT OS modules extern crate rust_riotmodules; @@ -43,7 +43,6 @@ use riot_wrappers::riot_main; use riot_wrappers::ztimer; use riot_wrappers::saul::{ActuatorClass, Class, Phydat, RegistryEntry}; use riot_wrappers::saul::registration::register_and_then; -use riot_wrappers::shell::{self, CommandList as _}; // rs-matter #[allow(unused_variables)] @@ -61,7 +60,7 @@ use rs_matter::data_model::{ root_endpoint, system_model::descriptor }; -use rs_matter::data_model::cluster_on_off::OnOffCluster; +use rs_matter::data_model::cluster_on_off::{Commands, OnOffCluster}; use rs_matter::error::Error; use rs_matter::mdns::MdnsService; use rs_matter::mdns::builtin::MDNS_SOCKET_BIND_ADDR; @@ -111,15 +110,18 @@ impl Handler for OnOffHandler { fn invoke(&self, exchange: &Exchange, cmd: &CmdDetails, data: &TLVElement, encoder: CmdDataEncoder) -> Result<(), Error> { info!("OnOffCluster: Invoke cmd {:#02x} (data: {}) @ Endpoint {}", cmd.cmd_id, data.u32().unwrap_or(0), cmd.endpoint_id); // Handle command by ID -> 0x00: Off, 0x01: On, 0x02: Toggle - match cmd.cmd_id { - 0 => led_onoff(false), - 1 => led_onoff(true), - 2 => { + match cmd.cmd_id.try_into()? { + Commands::On => led_onoff(true), + Commands::Off => led_onoff(false), + Commands::Toggle => { let new_state = !self.on.get(); self.on.set(new_state); led_onoff(new_state); }, - _ => { warn!("Unsupported command by application -> ignored!"); } + Commands::OffWithEffect => info!("OffWithEffect ..."), + Commands::OnWithRecallGlobalScene => info!("OnWithRecallGlobalScene ..."), + Commands::OnWithTimedOff => info!("OnWithTimedOff ..."), + //_ => { warn!("Unsupported command by application -> ignored!"); } } self.cluster.invoke(exchange, cmd, data, encoder) } @@ -158,8 +160,10 @@ fn led_onoff(on: bool) { entry.write(data).expect("Error while trying to set LED"); info!("LED was set to {:?}", on); } - } - ); + }); +} + +const fn led_timed_on(on_time: u16) { } fn main() -> ! { @@ -170,7 +174,7 @@ fn main() -> ! { unsafe { HEAP.init(HEAP_MEM.as_ptr() as usize, HEAP_SIZE) } } - init_logger().expect("Error initializing logger"); + init_logger(LevelFilter::Debug).expect("Error initializing logger"); let mut clock = ztimer::Clock::msec(); clock.delay_ms(1000); @@ -246,7 +250,8 @@ fn main() -> ! { Some(CStr::from_bytes_with_nul(b"Extended Color Light\0").unwrap()), || { info!("RGB-LED registered as SAUL actuator"); - shell::new().run_forever_providing_buf() + //shell::new().run_forever_providing_buf() + loop {} }, ); }; @@ -258,8 +263,6 @@ fn main() -> ! { spawner.spawn(run_matter(matter)).unwrap(); spawner.spawn(run_psm(matter)).unwrap(); }); - - } #[embassy_executor::task] diff --git a/examples/rust-matter-light/src/logging.rs b/examples/rust-matter-light/src/logging.rs index bd9995173a9d..568a1344e5f6 100644 --- a/examples/rust-matter-light/src/logging.rs +++ b/examples/rust-matter-light/src/logging.rs @@ -19,9 +19,9 @@ impl Log for RiotLogger { static LOGGER: RiotLogger = RiotLogger; -pub fn init_logger() -> Result<(), SetLoggerError> { +pub fn init_logger(level: LevelFilter) -> Result<(), SetLoggerError> { //let log_level: &'static str = env!("RIOT_LOG_LEVEL"); //println!("the RIOT_LOG_LEVEL variable at the time of compiling was: {log_level}"); log::set_logger(&LOGGER) - .map(|_| log::set_max_level(LevelFilter::Info)) + .map(|_| log::set_max_level(level)) } \ No newline at end of file diff --git a/examples/rust-matter-light/src/network.rs b/examples/rust-matter-light/src/network.rs index 4237fc69893e..f688096137e8 100644 --- a/examples/rust-matter-light/src/network.rs +++ b/examples/rust-matter-light/src/network.rs @@ -45,7 +45,7 @@ impl UdpSend for &UdpSocketWrapper { } // tell receiver to release mutex within max. 10ms self.release_socket_notification.signal(()); - ztimer::Delay.delay_ms(5).await; + ztimer::Delay.delay_ms(10).await; let mut sock = self.socket.try_lock().expect("receiver should have ensured that this mutex is free"); sock.send(self.local_addr, addr, data) .await @@ -148,4 +148,4 @@ pub mod utils { info!("Found network interface '{}' with IP {}", ifc_name, ipv6); Ok((ipv6, 0 as _)) } -} \ No newline at end of file +} diff --git a/examples/rust-matter-light/src/tests.rs b/examples/rust-matter-light/src/tests.rs index 0571729a4a9a..6e94a7a3327f 100644 --- a/examples/rust-matter-light/src/tests.rs +++ b/examples/rust-matter-light/src/tests.rs @@ -1,5 +1,5 @@ use embedded_nal_async::{SocketAddr, UdpStack, UnconnectedUdp}; -use log::{debug, error, info}; +use log::{debug, error, info, LevelFilter}; use riot_wrappers::socket_embedded_nal_async_udp::UnconnectedUdpSocket; use rs_matter::error::Error; use rs_matter::transport::core::MATTER_SOCKET_BIND_ADDR; @@ -13,7 +13,7 @@ use crate::network::utils::initialize_network; // Set this as entry point with 'riot_main!' macro to run 'integration tests' fn run_tests() -> ! { - init_logger().expect("Error initializing logger"); + init_logger(LevelFilter::Debug).expect("Error initializing logger"); static EXECUTOR: StaticCell = StaticCell::new(); let executor: &'static mut _ = EXECUTOR.init(embassy_executor_riot::Executor::new()); executor.run(|spawner| { From 5128ec3b997e76090752117eac30e19588f66904 Mon Sep 17 00:00:00 2001 From: Maik Lorenz Date: Tue, 19 Mar 2024 11:46:33 +0100 Subject: [PATCH 05/19] examples/rust-matter-light: Add rust-toolchain.toml for docker build (native and native64 target) --- examples/rust-matter-light/rust-toolchain.toml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 examples/rust-matter-light/rust-toolchain.toml diff --git a/examples/rust-matter-light/rust-toolchain.toml b/examples/rust-matter-light/rust-toolchain.toml new file mode 100644 index 000000000000..32c067a86544 --- /dev/null +++ b/examples/rust-matter-light/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "nightly" +targets = [ "i686-unknown-linux-gnu", "x86_64-unknown-linux-gnu" ] \ No newline at end of file From 2f11b35c2aeb5b1748e9b0267d92cd815e030e5f Mon Sep 17 00:00:00 2001 From: Maik Lorenz Date: Tue, 19 Mar 2024 18:01:44 +0100 Subject: [PATCH 06/19] examples/rust-matter-light: Run shell and matter in seperate thread; cleanup Makefile deps --- examples/rust-matter-light/Makefile | 23 ++-- examples/rust-matter-light/src/lib.rs | 181 +++++++++++++++----------- 2 files changed, 116 insertions(+), 88 deletions(-) diff --git a/examples/rust-matter-light/Makefile b/examples/rust-matter-light/Makefile index 7a77c42a6ff4..eb030a2abbe3 100644 --- a/examples/rust-matter-light/Makefile +++ b/examples/rust-matter-light/Makefile @@ -16,10 +16,11 @@ DEVELHELP ?= 1 QUIET ?= 1 # Estimated minimum usage (critical parts): -# - UDP and Packet Buffers: 26 kB (Stack and during embassy polling ISR) -# - embassy_executor tasks: statically allocated at compile time (nightly feature) -CFLAGS += '-DTHREAD_STACKSIZE_MAIN=(THREAD_STACKSIZE_DEFAULT + 40000)' -CFLAGS += '-DISR_STACKSIZE=(THREAD_STACKSIZE_DEFAULT + 20000)' +# - Matter service: 18 kB +# - Packet Buffers: 24 kB +# - UDP Buffers: 3 kB +CFLAGS += '-DTHREAD_STACKSIZE_MAIN=(THREAD_STACKSIZE_DEFAULT + 50000)' +#CFLAGS += '-DISR_STACKSIZE=(THREAD_STACKSIZE_DEFAULT + 20000)' # The name of crate (as per Cargo.toml package name, but with '-' replaced with '_') APPLICATION_RUST_MODULE = rust_matter_light @@ -29,13 +30,14 @@ FEATURES_REQUIRED += rust_target USEMODULE += saul USEMODULE += saul_default -#USEMODULE += shell -#USEMODULE += shell_cmds_default -#USEMODULE += periph_gpio +USEMODULE += shell +USEMODULE += shell_cmds_default +USEMODULE += shell_cmd_heap USEMODULE += ztimer USEMODULE += ztimer_msec USEMODULE += ztimer_usec -#USEMODULE += ps +USEMODULE += ps +USEMODULE += vfs # networking USEMODULE += netdev_default @@ -43,13 +45,8 @@ USEMODULE += auto_init_gnrc_netif USEMODULE += gnrc_ipv6_default USEMODULE += gnrc_icmpv6_echo USEMODULE += gnrc_icmpv6_error -#USEMODULE += shell_cmd_gnrc_udp USEMODULE += sock_udp USEMODULE += sock_async USEMODULE += sock_aux_local -#USEMODULE += ipv6 -#USEMODULE += netstats_l2 -#USEMODULE += netstats_ipv6 -#USEMODULE += netstats_rpl include $(RIOTBASE)/Makefile.include diff --git a/examples/rust-matter-light/src/lib.rs b/examples/rust-matter-light/src/lib.rs index d488a4ac900c..026f6c332a38 100644 --- a/examples/rust-matter-light/src/lib.rs +++ b/examples/rust-matter-light/src/lib.rs @@ -23,31 +23,34 @@ use network::UdpSocketWrapper; use network::utils::initialize_network; use logging::init_logger; use dev_att::HardCodedDevAtt; -use rgb_led::{RGB_LED_DRIVER, RgbLed, RGB_BLUE_PIN, RGB_GREEN_PIN, RGB_PORT, RGB_RED_PIN}; // core library use core::{borrow::Borrow, pin::pin}; use core::cell::Cell; -use core::ffi::CStr; // external crates use static_cell::StaticCell; use embedded_nal_async::{Ipv4Addr, UdpStack as _}; use embedded_alloc::Heap; use embedded_hal::delay::DelayNs as _; -use log::{debug, info, error, warn, LevelFilter}; +use log::{debug, info, error, LevelFilter}; // RIOT OS modules extern crate rust_riotmodules; -use riot_wrappers::riot_main; + +use riot_wrappers::{riot_main, static_command}; use riot_wrappers::ztimer; +use riot_wrappers::thread; +use riot_wrappers::mutex::Mutex; +use riot_wrappers::cstr::cstr; +use riot_wrappers::shell::{self, CommandList}; use riot_wrappers::saul::{ActuatorClass, Class, Phydat, RegistryEntry}; -use riot_wrappers::saul::registration::register_and_then; // rs-matter #[allow(unused_variables)] #[allow(dead_code)] extern crate rs_matter; + use rs_matter::{CommissioningData, MATTER_PORT}; use rs_matter::transport::network::UdpBuffers; use rs_matter::transport::core::{PacketBuffers, MATTER_SOCKET_BIND_ADDR}; @@ -58,7 +61,7 @@ use rs_matter::data_model::{ device_types::DEV_TYPE_ON_OFF_LIGHT, objects::*, root_endpoint, - system_model::descriptor + system_model::descriptor, }; use rs_matter::data_model::cluster_on_off::{Commands, OnOffCluster}; use rs_matter::error::Error; @@ -117,7 +120,7 @@ impl Handler for OnOffHandler { let new_state = !self.on.get(); self.on.set(new_state); led_onoff(new_state); - }, + } Commands::OffWithEffect => info!("OffWithEffect ..."), Commands::OnWithRecallGlobalScene => info!("OnWithRecallGlobalScene ..."), Commands::OnWithTimedOff => info!("OnWithTimedOff ..."), @@ -126,6 +129,7 @@ impl Handler for OnOffHandler { self.cluster.invoke(exchange, cmd, data, encoder) } } + impl NonBlockingHandler for OnOffHandler {} // Handler for endpoints 0 (Root) and 1 (Descriptor + OnOff Cluster) @@ -141,13 +145,29 @@ fn matter_handler<'a>(matter: &'a Matter<'a>) -> impl Metadata + NonBlockingHand .chain( 1, cluster_on_off::ID, - OnOffHandler::new(cluster_on_off::OnOffCluster::new(*matter.borrow())), + OnOffHandler::new(OnOffCluster::new(*matter.borrow())), ), ) } #[global_allocator] static HEAP: Heap = Heap::empty(); +static SHELL_THREAD_STACK: Mutex<[u8; 5120]> = Mutex::new([0; 5120]); +static MATTER_THREAD_STACK: Mutex<[u8; 50000]> = Mutex::new([0; 50000]); +static DEV_DET: BasicInfoConfig = BasicInfoConfig { + vid: 0xFFF1, + pid: 0x8000, + hw_ver: 2, + sw_ver: 1, + sw_ver_str: "1", + serial_no: "aabbccddd", + device_name: "OnOff Light", + product_name: "Light123", + vendor_name: "Vendor 123", +}; +static MDNS: StaticCell = StaticCell::new(); +static DEV_ATT: StaticCell = StaticCell::new(); +static MATTER: StaticCell = StaticCell::new(); riot_main!(main); @@ -155,56 +175,36 @@ fn led_onoff(on: bool) { // Iterate through all SAUL registry entries and set all switches to the desired state RegistryEntry::all().for_each(|entry| { if let Some(Class::Actuator(Some(ActuatorClass::Switch))) = entry.type_() { - info!("Writing to {}", entry.name().unwrap_or("n/a")); let data = Phydat::new(&[on as i16], None, 0); entry.write(data).expect("Error while trying to set LED"); - info!("LED was set to {:?}", on); + info!("LED {} was set to {:?}", entry.name().unwrap_or("n/a"), on); } }); } -const fn led_timed_on(on_time: u16) { +fn cmd_matter(_stdio: &mut riot_wrappers::stdio::Stdio, _args: shell::Args<'_>) { + // TODO: Support some useful commands for this Matter node or interacting with other nodes + info!("Endpoint Info:"); + NODE.endpoints.into_iter().for_each(|ep| { + info!("Endpoint No. {} - DeviceType={:#04x}", ep.id, ep.device_type.dtype); + ep.clusters.into_iter().for_each(|cluster| { + info!(" Cluster ID={:#04x}", cluster.id); + cluster.attributes.into_iter().for_each(|attr| info!(" Attribute {:#04x}", attr.id)) + }); + }); } -fn main() -> ! { - { - use core::mem::MaybeUninit; - const HEAP_SIZE: usize = 4192; - static mut HEAP_MEM: [MaybeUninit; HEAP_SIZE] = [MaybeUninit::uninit(); HEAP_SIZE]; - unsafe { HEAP.init(HEAP_MEM.as_ptr() as usize, HEAP_SIZE) } - } - - init_logger(LevelFilter::Debug).expect("Error initializing logger"); - let mut clock = ztimer::Clock::msec(); - clock.delay_ms(1000); - - info!("Hello Matter on RIOT!"); +static_command!(matter, "matter", "Interact with Matter devices", cmd_matter); - use core::mem::size_of; - info!("Matter memory usage: UdpBuffers={}, PacketBuffers={}, \ - MdnsService={}, Matter={}", - size_of::(), - size_of::(), - size_of::(), - size_of::(), - ); +fn run_shell() -> Result<(), ()> { + let mut shell = shell::new(); + shell.run_forever_providing_buf() +} +fn run_matter() -> Result<(), ()> { let (ipv6_addr, interface) = initialize_network() .expect("Error getting network interface and IP addresses"); - static DEV_DET: BasicInfoConfig = BasicInfoConfig { - vid: 0xFFF1, - pid: 0x8000, - hw_ver: 2, - sw_ver: 1, - sw_ver_str: "1", - serial_no: "aabbccddd", - device_name: "OnOff Light", - product_name: "Light123", - vendor_name: "Vendor 123", - }; - - static MDNS: StaticCell = StaticCell::new(); let mdns_service: &'static MdnsService = MDNS.init(MdnsService::new( 0, "rs-matter-demo", @@ -215,14 +215,12 @@ fn main() -> ! { )); // Get Device attestation (hard-coded atm) - static DEV_ATT: StaticCell = StaticCell::new(); let dev_att: &'static HardCodedDevAtt = DEV_ATT.init(HardCodedDevAtt::new()); // TODO: Provide own epoch and rand functions let epoch = rs_matter::utils::epoch::riot_epoch; let rand = rs_matter::utils::rand::riot_rand; - static MATTER: StaticCell = StaticCell::new(); let matter: &'static Matter = MATTER.init(Matter::new( // vid/pid should match those in the DAC &DEV_DET, @@ -234,39 +232,72 @@ fn main() -> ! { )); info!("Starting all services..."); - - // TODO: Register RGB-LED at SAUL and run shell in seperate thread - let mut _shell_thread = || { - debug!("Shell is running"); - let rgb_led = RgbLed::new( - "Extended Color Light", - (RGB_PORT, RGB_RED_PIN), - (RGB_PORT, RGB_GREEN_PIN), - (RGB_PORT, RGB_BLUE_PIN), - ); - register_and_then( - &RGB_LED_DRIVER, - &rgb_led, - Some(CStr::from_bytes_with_nul(b"Extended Color Light\0").unwrap()), - || { - info!("RGB-LED registered as SAUL actuator"); - //shell::new().run_forever_providing_buf() - loop {} - }, - ); - }; - static EXECUTOR: StaticCell = StaticCell::new(); let executor: &'static mut _ = EXECUTOR.init(embassy_executor_riot::Executor::new()); executor.run(|spawner| { - spawner.spawn(run_mdns(mdns_service)).unwrap(); - spawner.spawn(run_matter(matter)).unwrap(); - spawner.spawn(run_psm(matter)).unwrap(); + spawner.spawn(mdns_task(mdns_service)).unwrap(); + spawner.spawn(matter_task(matter)).unwrap(); + spawner.spawn(psm_task(matter)).unwrap(); + }); +} + +fn main() { + { + use core::mem::MaybeUninit; + const HEAP_SIZE: usize = 4192; + static mut HEAP_MEM: [MaybeUninit; HEAP_SIZE] = [MaybeUninit::uninit(); HEAP_SIZE]; + unsafe { HEAP.init(HEAP_MEM.as_ptr() as usize, HEAP_SIZE) } + } + + init_logger(LevelFilter::Info).expect("Error initializing logger"); + let mut clock = ztimer::Clock::msec(); + clock.delay_ms(1000); + + info!("Hello Matter on RIOT!"); + + use core::mem::size_of; + info!("Matter memory usage: UdpBuffers={}, PacketBuffers={}, \ + MdnsService={}, Matter={}", + size_of::(), + size_of::(), + size_of::(), + size_of::(), + ); + + // Run threads: Matter and RIOT Shell + let mut matter_thread_main = || run_matter().unwrap(); + let mut matter_thread_stacklock = MATTER_THREAD_STACK.lock(); + + let mut shell_thread_main = || run_shell().unwrap(); + let mut shell_thread_stacklock = SHELL_THREAD_STACK.lock(); + + thread::scope(|threadscope| { + let matter_thread = threadscope.spawn( + matter_thread_stacklock.as_mut(), + &mut matter_thread_main, + cstr!("matter"), + (riot_sys::THREAD_PRIORITY_MAIN - 2) as _, + (riot_sys::THREAD_CREATE_STACKTEST) as _, + ).expect("Failed to spawn Matter thread"); + info!("MATTER thread spawned as {:?} ({:?}), status {:?}", matter_thread.pid(), matter_thread.pid().get_name(), matter_thread.status()); + + let shell_thread = threadscope.spawn( + shell_thread_stacklock.as_mut(), + &mut shell_thread_main, + cstr!("shell"), + (riot_sys::THREAD_PRIORITY_MAIN - 1) as _, + (riot_sys::THREAD_CREATE_STACKTEST) as _, + ).expect("Failed to spawn shell thread"); + info!("SHELL thread spawned as {:?} ({:?}), status {:?}", shell_thread.pid(), shell_thread.pid().get_name(), shell_thread.status()); + + loop { + thread::sleep(); + } }); } #[embassy_executor::task] -async fn run_mdns(mdns: &'static MdnsService<'_>) { +async fn mdns_task(mdns: &'static MdnsService<'_>) { // Create UDP socket and bind to port 5353 static UDP_MDNS_SOCKET: StaticCell = StaticCell::new(); let udp_stack = riot_wrappers::socket_embedded_nal_async_udp::UdpStack::new(|| UDP_MDNS_SOCKET.try_uninit()); @@ -297,7 +328,7 @@ async fn run_mdns(mdns: &'static MdnsService<'_>) { } #[embassy_executor::task] -async fn run_matter(matter: &'static Matter<'_>) { +async fn matter_task(matter: &'static Matter<'_>) { // Create UDP socket and bind to port 5540 static UDP_MATTER_SOCKET: StaticCell = StaticCell::new(); let udp_stack = riot_wrappers::socket_embedded_nal_async_udp::UdpStack::new(|| UDP_MATTER_SOCKET.try_uninit()); @@ -340,7 +371,7 @@ async fn run_matter(matter: &'static Matter<'_>) { } #[embassy_executor::task] -async fn run_psm(matter: &'static Matter<'_>) { +async fn psm_task(matter: &'static Matter<'_>) { info!("Starting Persistence Manager...."); // TODO: Develop own 'Persistence Manager' using RIOT OS modules let mut psm = persist::Psm::new(&matter).expect("Error creating PSM"); From d2fd9a7b08aadfbe69e111fdca5fbb1501b18fa0 Mon Sep 17 00:00:00 2001 From: Maik Lorenz Date: Tue, 19 Mar 2024 19:09:17 +0100 Subject: [PATCH 07/19] examples/rust-matter-light: Only control LED specified by name --- examples/rust-matter-light/src/lib.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/rust-matter-light/src/lib.rs b/examples/rust-matter-light/src/lib.rs index 026f6c332a38..4c769cd46df6 100644 --- a/examples/rust-matter-light/src/lib.rs +++ b/examples/rust-matter-light/src/lib.rs @@ -33,7 +33,7 @@ use static_cell::StaticCell; use embedded_nal_async::{Ipv4Addr, UdpStack as _}; use embedded_alloc::Heap; use embedded_hal::delay::DelayNs as _; -use log::{debug, info, error, LevelFilter}; +use log::{debug, info, error, LevelFilter, warn}; // RIOT OS modules extern crate rust_riotmodules; @@ -169,17 +169,25 @@ static MDNS: StaticCell = StaticCell::new(); static DEV_ATT: StaticCell = StaticCell::new(); static MATTER: StaticCell = StaticCell::new(); +// Set this to the name of the LED, which should be controlled using SAUL registry +const ONOFF_LED_NAME: &str = "LD2(blue)"; + riot_main!(main); fn led_onoff(on: bool) { // Iterate through all SAUL registry entries and set all switches to the desired state + let mut success = false; RegistryEntry::all().for_each(|entry| { - if let Some(Class::Actuator(Some(ActuatorClass::Switch))) = entry.type_() { + if matches!(entry.type_(), Some(Class::Actuator(Some(ActuatorClass::Switch)))) + && entry.name().map_or(false, |name| name == ONOFF_LED_NAME) { + // Found LED in SAUL -> turn on/off let data = Phydat::new(&[on as i16], None, 0); entry.write(data).expect("Error while trying to set LED"); info!("LED {} was set to {:?}", entry.name().unwrap_or("n/a"), on); + success = true; } }); + warn!("LED {} was not found in SAUL registry!", ONOFF_LED_NAME); } fn cmd_matter(_stdio: &mut riot_wrappers::stdio::Stdio, _args: shell::Args<'_>) { From dc004694d482a504077df0cbe33f573bd5298cd1 Mon Sep 17 00:00:00 2001 From: Maik Lorenz Date: Tue, 9 Apr 2024 11:23:25 +0200 Subject: [PATCH 08/19] examples/rust-matter-light: Add feature 'psm' to make PersistenceManager optional --- examples/filesystem/Makefile | 6 +- examples/rust-hello-world/Cargo.lock | 239 ++++++++-------------- examples/rust-hello-world/Cargo.toml | 8 +- examples/rust-hello-world/Makefile | 8 +- examples/rust-hello-world/src/lib.rs | 55 +++++ examples/rust-matter-light/Cargo.lock | 188 +++++++++-------- examples/rust-matter-light/Cargo.toml | 7 +- examples/rust-matter-light/Makefile | 5 +- examples/rust-matter-light/src/lib.rs | 5 +- examples/rust-matter-light/src/persist.rs | 4 +- 10 files changed, 276 insertions(+), 249 deletions(-) diff --git a/examples/filesystem/Makefile b/examples/filesystem/Makefile index ca82326dac0f..3c5d2178e9b2 100644 --- a/examples/filesystem/Makefile +++ b/examples/filesystem/Makefile @@ -27,10 +27,12 @@ USEMODULE += ps # Use the default file system USEMODULE += vfs_default USEMODULE += constfs -# USEMODULE += devfs +#USEMODULE += devfs +#USEMODULE += littlefs +#USEMODULE += littlefs2 # Enable to automatically format if mount fails -#USEMODULE += vfs_auto_format +USEMODULE += vfs_auto_format # For LittleFS on real devices, the main stack size has to be # increased: diff --git a/examples/rust-hello-world/Cargo.lock b/examples/rust-hello-world/Cargo.lock index 5a2f25826e6b..9113160ad95e 100644 --- a/examples/rust-hello-world/Cargo.lock +++ b/examples/rust-hello-world/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "aho-corasick" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] @@ -22,9 +22,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" [[package]] name = "bare-metal" @@ -62,9 +62,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.2" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" [[package]] name = "block-buffer" @@ -227,9 +227,9 @@ dependencies = [ [[package]] name = "cstr" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8aa998c33a6d3271e3678950a22134cd7dd27cef86dee1b611b5b14207d1d90b" +checksum = "68523903c8ae5aacfa32a0d9ae60cadeb764e1da14ee0d26b1f3089f13a54636" dependencies = [ "proc-macro2", "quote", @@ -253,9 +253,9 @@ dependencies = [ [[package]] name = "either" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" [[package]] name = "embedded-graphics" @@ -295,7 +295,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -316,9 +316,9 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "half" -version = "1.8.2" +version = "1.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" +checksum = "1b43ede17f21864e81be2fa654110bf1e793774238d86ef8555c37e6519c0403" [[package]] name = "hash32" @@ -354,14 +354,14 @@ version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" dependencies = [ - "windows-sys 0.52.0", + "windows-sys", ] [[package]] name = "itoa" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "lazy_static" @@ -377,18 +377,18 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.152" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "libloading" -version = "0.8.1" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c571b676ddfc9a8c12f1f3d3085a7b163966a8fd8098a90640953ce5f6170161" +checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", - "windows-sys 0.48.0", + "windows-targets", ] [[package]] @@ -409,15 +409,15 @@ dependencies = [ [[package]] name = "log" -version = "0.4.20" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "memchr" -version = "2.7.1" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] name = "minimal-lexical" @@ -458,9 +458,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" dependencies = [ "autocfg", ] @@ -479,22 +479,22 @@ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" [[package]] name = "pin-project" -version = "1.1.4" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0302c4a0442c456bd56f841aee5c3bfd17967563f6fadc9ceb9f9c23cf3807e0" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.4" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.55", ] [[package]] @@ -505,9 +505,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "proc-macro2" -version = "1.0.78" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" dependencies = [ "unicode-ident", ] @@ -529,9 +529,9 @@ checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" [[package]] name = "regex" -version = "1.10.3" +version = "1.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" dependencies = [ "aho-corasick", "memchr", @@ -541,9 +541,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" dependencies = [ "aho-corasick", "memchr", @@ -552,14 +552,14 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" [[package]] name = "riot-sys" -version = "0.7.10" -source = "git+https://github.com/RIOT-OS/rust-riot-sys#297c670d8c674eae20b2b398c4338d27e2d2d346" +version = "0.7.12" +source = "git+https://github.com/RIOT-OS/rust-riot-sys#a3752271062299f68c5f6ba3c6e503ac725722c4" dependencies = [ "bindgen", "c2rust-asm-casts", @@ -573,8 +573,7 @@ dependencies = [ [[package]] name = "riot-wrappers" -version = "0.8.2" -source = "git+https://github.com/RIOT-OS/rust-riot-wrappers#82bb9a4decedcc624a9540f7fd8013910044be9e" +version = "0.8.3" dependencies = [ "bare-metal", "coap-handler 0.1.6", @@ -582,6 +581,7 @@ dependencies = [ "coap-message 0.2.3", "coap-message 0.3.1", "coap-numbers", + "critical-section", "cstr", "embedded-graphics", "embedded-hal 0.2.7", @@ -629,22 +629,22 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.30" +version = "0.38.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322394588aaf33c24007e8bb3238ee3e4c5c09c084ab32bc73890b99ff326bca" +checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "errno", "libc", "linux-raw-sys", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] name = "ryu" -version = "1.0.16" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" [[package]] name = "scopeguard" @@ -654,15 +654,15 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "semver" -version = "1.0.21" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" +checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" [[package]] name = "serde" -version = "1.0.195" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" dependencies = [ "serde_derive", ] @@ -679,20 +679,20 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.195" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.55", ] [[package]] name = "serde_json" -version = "1.0.111" +version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" +checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" dependencies = [ "itoa", "ryu", @@ -748,9 +748,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.48" +version = "2.0.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0" dependencies = [ "proc-macro2", "quote", @@ -806,134 +806,73 @@ dependencies = [ "serde_cbor", ] -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.0", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", + "windows-targets", ] [[package]] name = "windows-targets" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" dependencies = [ - "windows_aarch64_gnullvm 0.52.0", - "windows_aarch64_msvc 0.52.0", - "windows_i686_gnu 0.52.0", - "windows_i686_msvc 0.52.0", - "windows_x86_64_gnu 0.52.0", - "windows_x86_64_gnullvm 0.52.0", - "windows_x86_64_msvc 0.52.0", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" [[package]] name = "windows_aarch64_msvc" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" [[package]] name = "windows_i686_gnu" -version = "0.48.5" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" [[package]] name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" [[package]] name = "windows_x86_64_gnu" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.5" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" [[package]] name = "windows_x86_64_msvc" -version = "0.48.5" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" +[[patch.unused]] +name = "riot-wrappers" +version = "0.8.3" +source = "git+https://github.com/RIOT-OS/rust-riot-wrappers#409a5bea642c8b9aeb765676f62884763b3524f4" diff --git a/examples/rust-hello-world/Cargo.toml b/examples/rust-hello-world/Cargo.toml index 215d2fe63bfa..f0e58e182053 100644 --- a/examples/rust-hello-world/Cargo.toml +++ b/examples/rust-hello-world/Cargo.toml @@ -15,10 +15,16 @@ crate-type = ["staticlib"] panic = "abort" [dependencies] -riot-wrappers = { version = "0.8", features = [ "set_panic_handler" ] } +riot-wrappers = { path = "../../../rust-riot-wrappers", features = ["set_panic_handler", "panic_handler_crash", "panic_handler_format", "critical-section", "provide_critical_section_1_0", "with_msg_v2"] } +#riot-wrappers = { version = "0.8", features = [ "set_panic_handler" ] } +#riot-sys = "*" # While currently this example 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/" } + +[patch.crates-io] +#riot-wrappers = { path = "../../../rust-riot-wrappers" } +#riot-sys = { path = "../../../rust-riot-sys" } \ No newline at end of file diff --git a/examples/rust-hello-world/Makefile b/examples/rust-hello-world/Makefile index b6d08353e4af..c82e9be398c7 100644 --- a/examples/rust-hello-world/Makefile +++ b/examples/rust-hello-world/Makefile @@ -2,7 +2,11 @@ APPLICATION = hello-world # If no BOARD is found in the environment, use this default: -BOARD ?= native +BOARD ?= native64 + +USEMODULE += vfs +USEMODULE += vfs_default +USEMODULE += shell_cmds_default # This has to be the absolute path to the RIOT base directory: RIOTBASE ?= $(CURDIR)/../.. @@ -21,6 +25,8 @@ BASELIBS += $(APPLICATION_RUST_MODULE).module FEATURES_REQUIRED += rust_target + + # Currently unknown, something related to the LED_PORT definition that doesn't # pass C2Rust's transpilation BOARD_BLACKLIST := ek-lm4f120xl diff --git a/examples/rust-hello-world/src/lib.rs b/examples/rust-hello-world/src/lib.rs index 3f72a5615a3e..be1e81b77944 100644 --- a/examples/rust-hello-world/src/lib.rs +++ b/examples/rust-hello-world/src/lib.rs @@ -5,13 +5,68 @@ // directory for more details. #![no_std] +use riot_wrappers::error::NumericError; use riot_wrappers::riot_main; use riot_wrappers::println; extern crate rust_riotmodules; +use riot_wrappers::vfs::{Dir, File, FileMode, Mount, SeekFrom}; + riot_main!(main); +const BUF_SIZE: usize = 100; + fn main() { println!("Hello Rust!"); + + let mut mount_points = Mount::all(); + let mut mp = mount_points.next().expect("no mount point found"); + let dir = Dir::open("/nvm0"); + match dir { + Ok(dir) => { println!("Opened dir: {:?}", dir.count()) } + Err(_) => { println!("error opening dir"); } + } + println!("Mount point: {:?}, {} files", mp.mount_point(), mp.root_dir().count()); + + //let mut rw_file = File::open_with_mode("/nvm0/test", FileMode::ReadWrite(false)); + let mut rw_file = File::open_with_mode("/nvm0/test", FileMode::ReadWrite(false)); + //let mut rw_file = File::open_rw("/nvm0/test123"); + match rw_file { + Ok(mut f) => { + println!("File opened with R/W"); + let data = "hello".as_bytes(); + f.write(&data).expect("Error writing to file"); + println!("Write success!"); + + f.seek(SeekFrom::Start(0)).expect("seek failed"); + let mut content: [u8; BUF_SIZE] = [0; BUF_SIZE]; + f.read(&mut content).expect("Error reading from file"); + println!("Contents: {:?}", content); + drop(f); + } + Err(err) => { + println!("Error opening file: {:?}", err); + } + } + return; + + let mut f = File::open_rw("/nvm0/write_only"); + match f { + Ok(mut f) => { + println!("File opened!"); + let data = "hello".as_bytes(); + f.write(&data).expect("Error writing to file"); + println!("Contents written!"); + + f.seek(SeekFrom::Start(0)).expect("seek failed"); + let mut content: [u8; BUF_SIZE] = [0; BUF_SIZE]; + f.read(&mut content).expect("Error reading from file"); + println!("Contents: {:?}", content); + drop(f); + } + Err(err) => { + println!("Error opening file: {:?}", err); + } + } } diff --git a/examples/rust-matter-light/Cargo.lock b/examples/rust-matter-light/Cargo.lock index 6ded13f4787d..ded9262076f1 100644 --- a/examples/rust-matter-light/Cargo.lock +++ b/examples/rust-matter-light/Cargo.lock @@ -40,9 +40,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] @@ -103,9 +103,9 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "astro-dnssd" -version = "0.3.2" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cba40a960b341f156b5123e823c7589d0850f4e6bd46a206106f5b2a5b8a73de" +checksum = "1e78b5030667e39ab9baa494b9c3c68a0e8b4ae523a25a733041025be706772d" dependencies = [ "libc", "log", @@ -126,15 +126,15 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" [[package]] name = "backtrace" -version = "0.3.69" +version = "0.3.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" dependencies = [ "addr2line", "cc", @@ -202,9 +202,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.2" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" [[package]] name = "block-buffer" @@ -270,9 +270,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.89" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0ba8f7aaa012f30d5b2861462f6708eccd49c3c39863fe083a308035f63d723" +checksum = "2678b2e3449475e95b0aa6f9b506a28e61b3dc8996592b983695e8ebb58a8b41" [[package]] name = "ccm" @@ -324,9 +324,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.1" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c918d541ef2913577a0f9566e9ce27cb35b6df072075769e0b26cb5a554520da" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" dependencies = [ "clap_builder", "clap_derive", @@ -334,26 +334,26 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.1" +version = "4.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f3e7391dad68afb0c2ede1bf619f579a3dc9c2ec67f089baa397123a2f3d1eb" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" dependencies = [ "anstream", "anstyle", "clap_lex", - "strsim 0.11.0", + "strsim 0.11.1", ] [[package]] name = "clap_derive" -version = "4.5.0" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "307bc0538d5f0f83b8248db3087aa92fe504e4691294d0c96c0eabc33f47ba47" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" dependencies = [ - "heck", + "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.58", ] [[package]] @@ -449,9 +449,9 @@ dependencies = [ [[package]] name = "crc" -version = "3.0.1" +version = "3.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86ec7a15cbe22e59248fc7eadb1907dab5ba09372595da4d73dd805ed4417dfe" +checksum = "69e6e4d7b33a94f0991c26729976b10ebde1d34c3ee82408fb536164fa10d636" dependencies = [ "crc-catalog", ] @@ -492,9 +492,9 @@ dependencies = [ [[package]] name = "cstr" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8aa998c33a6d3271e3678950a22134cd7dd27cef86dee1b611b5b14207d1d90b" +checksum = "68523903c8ae5aacfa32a0d9ae60cadeb764e1da14ee0d26b1f3089f13a54636" dependencies = [ "proc-macro2", "quote", @@ -536,7 +536,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.10.0", - "syn 2.0.52", + "syn 2.0.58", ] [[package]] @@ -547,14 +547,14 @@ checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f" dependencies = [ "darling_core", "quote", - "syn 2.0.52", + "syn 2.0.58", ] [[package]] name = "der" -version = "0.7.8" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" dependencies = [ "const-oid", "der_derive", @@ -571,7 +571,7 @@ checksum = "5fe87ce4529967e0ba1dcf8450bab64d97dfd5010a6256187ffe2e43e6f0e049" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.58", ] [[package]] @@ -673,7 +673,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.58", ] [[package]] @@ -1002,6 +1002,12 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.3.9" @@ -1055,9 +1061,9 @@ checksum = "0cfe9645a18782869361d9c8732246be7b410ad4e919d3609ebabdac00ba12c3" [[package]] name = "indexmap" -version = "2.2.5" +version = "2.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b0b929d511467233429c45a44ac1dcaa21ba0f5ba11e4879e6ed28ddb4f9df4" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", "hashbrown", @@ -1091,9 +1097,9 @@ checksum = "7655c9839580ee829dfacba1d1278c2b7883e50a277ff7541299489d6bdfdc45" [[package]] name = "itoa" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "joinery" @@ -1121,9 +1127,9 @@ checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "libloading" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2caa5afb8bf9f3a2652760ce7d4f62d21c4d5a423e68466fca30df82f2330164" +checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", "windows-targets", @@ -1165,9 +1171,9 @@ checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "memchr" -version = "2.7.1" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] name = "miette" @@ -1198,7 +1204,7 @@ checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.58", ] [[package]] @@ -1333,7 +1339,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.58", ] [[package]] @@ -1457,29 +1463,29 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.1.4" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0302c4a0442c456bd56f841aee5c3bfd17967563f6fadc9ceb9f9c23cf3807e0" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.4" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.58", ] [[package]] name = "pin-project-lite" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" [[package]] name = "pin-utils" @@ -1525,9 +1531,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.78" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" dependencies = [ "unicode-ident", ] @@ -1555,9 +1561,9 @@ checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" [[package]] name = "regex" -version = "1.10.3" +version = "1.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" dependencies = [ "aho-corasick", "memchr", @@ -1578,9 +1584,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" [[package]] name = "rfc6979" @@ -1594,8 +1600,8 @@ dependencies = [ [[package]] name = "riot-sys" -version = "0.7.10" -source = "git+https://github.com/RIOT-OS/rust-riot-sys#297c670d8c674eae20b2b398c4338d27e2d2d346" +version = "0.7.12" +source = "git+https://github.com/RIOT-OS/rust-riot-sys#a3752271062299f68c5f6ba3c6e503ac725722c4" dependencies = [ "bindgen", "c2rust-asm-casts", @@ -1609,8 +1615,8 @@ dependencies = [ [[package]] name = "riot-wrappers" -version = "0.8.2" -source = "git+https://github.com/RIOT-OS/rust-riot-wrappers.git#82bb9a4decedcc624a9540f7fd8013910044be9e" +version = "0.8.3" +source = "git+https://github.com/RIOT-OS/rust-riot-wrappers.git#de348dce223543babe4763dda39196bd5f881c8d" dependencies = [ "bare-metal", "coap-handler 0.1.6", @@ -1644,6 +1650,7 @@ dependencies = [ [[package]] name = "rs-matter" version = "0.1.2" +source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#865adac5d0a1a760fe119a41fca9923a001b2706" dependencies = [ "aes", "astro-dnssd", @@ -1689,6 +1696,7 @@ dependencies = [ [[package]] name = "rs-matter-data-model" version = "0.1.0" +source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#865adac5d0a1a760fe119a41fca9923a001b2706" dependencies = [ "clap", "miette", @@ -1704,24 +1712,26 @@ dependencies = [ [[package]] name = "rs-matter-macros" version = "0.1.0" +source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#865adac5d0a1a760fe119a41fca9923a001b2706" dependencies = [ "proc-macro-crate", "proc-macro2", "quote", "rs-matter-data-model", "rs-matter-macros-impl", - "syn 2.0.52", + "syn 2.0.58", ] [[package]] name = "rs-matter-macros-impl" version = "0.1.0" +source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#865adac5d0a1a760fe119a41fca9923a001b2706" dependencies = [ "convert_case", "proc-macro2", "quote", "rs-matter-data-model", - "syn 2.0.52", + "syn 2.0.58", ] [[package]] @@ -1771,11 +1781,11 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.31" +version = "0.38.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" +checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "errno", "libc", "linux-raw-sys", @@ -1784,9 +1794,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" +checksum = "80af6f9131f277a45a3fba6ce8e2258037bb0477a67e610d3c1fe046ab31de47" [[package]] name = "ryu" @@ -1852,14 +1862,14 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.58", ] [[package]] name = "serde_json" -version = "1.0.114" +version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" +checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" dependencies = [ "itoa", "ryu", @@ -1910,9 +1920,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.13.1" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "smawk" @@ -1962,30 +1972,30 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "strsim" -version = "0.11.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "strum" -version = "0.26.1" +version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "723b93e8addf9aa965ebe2d11da6d7540fa2283fcea14b3371ff055f7ba13f5f" +checksum = "5d8cec3501a5194c432b2b7976db6b7d10ec95c253208b45f83f7136aa985e29" dependencies = [ "strum_macros", ] [[package]] name = "strum_macros" -version = "0.26.1" +version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a3417fc93d76740d974a01654a09777cb500428cc874ca9f45edfe0c4d4cd18" +checksum = "c6cf59daf282c0a494ba14fd21610a0325f9f90ec9d1231dea26bcb1d696c946" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro2", "quote", "rustversion", - "syn 2.0.52", + "syn 2.0.58", ] [[package]] @@ -2044,9 +2054,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.52" +version = "2.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07" +checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" dependencies = [ "proc-macro2", "quote", @@ -2076,22 +2086,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.57" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.57" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.58", ] [[package]] @@ -2158,7 +2168,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.58", ] [[package]] @@ -2284,9 +2294,9 @@ dependencies = [ [[package]] name = "widestring" -version = "1.0.2" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8" +checksum = "7219d36b6eac893fa81e84ebe06485e7dcbb616177469b142df14f1f4deb1311" [[package]] name = "winapi" @@ -2316,7 +2326,7 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c9487d1d565a9db59e1fd0b3c2d3f0c277bc375d348a6c46ff2b322917fbc035" dependencies = [ - "crc 3.0.1", + "crc 3.2.1", "digest", "embedded-io 0.4.0", "serde", diff --git a/examples/rust-matter-light/Cargo.toml b/examples/rust-matter-light/Cargo.toml index 315a56632843..76c7636cd6d6 100644 --- a/examples/rust-matter-light/Cargo.toml +++ b/examples/rust-matter-light/Cargo.toml @@ -8,6 +8,9 @@ resolver = "2" [lib] crate-type = ["staticlib"] +[features] +psm = [] + [profile.release] # Setting the panic mode has little effect on the built code (as Rust on RIOT # supports no unwinding), but setting it allows builds on native without using @@ -47,5 +50,5 @@ embassy-futures = "0.1.1" rs-matter = { version = "0.1.0", default-features = false, features = ["riot-os"] } [patch.crates-io] -rs-matter = { path = "../../../rs-matter/rs-matter" } -#rs-matter = { git = "https://github.com/maikerlab/rs-matter", branch = "feature/RIOT_OS" } \ No newline at end of file +#rs-matter = { path = "../../../rs-matter/rs-matter" } +rs-matter = { git = "https://github.com/maikerlab/rs-matter", branch = "feature/RIOT_OS" } \ No newline at end of file diff --git a/examples/rust-matter-light/Makefile b/examples/rust-matter-light/Makefile index eb030a2abbe3..94b457bb39b6 100644 --- a/examples/rust-matter-light/Makefile +++ b/examples/rust-matter-light/Makefile @@ -28,6 +28,10 @@ BASELIBS += $(APPLICATION_RUST_MODULE).module FEATURES_REQUIRED += rust_target +# Comment this line in to activate storing & loading runtime configurations +# NOTE: To use this feature, a PersistenceManager (in 'src/persist.rs') must be implemented for the target platform +#CARGO_OPTIONS += --features psm + USEMODULE += saul USEMODULE += saul_default USEMODULE += shell @@ -37,7 +41,6 @@ USEMODULE += ztimer USEMODULE += ztimer_msec USEMODULE += ztimer_usec USEMODULE += ps -USEMODULE += vfs # networking USEMODULE += netdev_default diff --git a/examples/rust-matter-light/src/lib.rs b/examples/rust-matter-light/src/lib.rs index 4c769cd46df6..c5f562b5a988 100644 --- a/examples/rust-matter-light/src/lib.rs +++ b/examples/rust-matter-light/src/lib.rs @@ -215,7 +215,7 @@ fn run_matter() -> Result<(), ()> { let mdns_service: &'static MdnsService = MDNS.init(MdnsService::new( 0, - "rs-matter-demo", + "riot-matter-demo", Ipv4Addr::UNSPECIFIED.octets(), Some((ipv6_addr.octets(), interface)), &DEV_DET, @@ -245,6 +245,9 @@ fn run_matter() -> Result<(), ()> { executor.run(|spawner| { spawner.spawn(mdns_task(mdns_service)).unwrap(); spawner.spawn(matter_task(matter)).unwrap(); + + // Run PersistenceManager only if 'psm' feature is activated + #[cfg(feature = "psm")] spawner.spawn(psm_task(matter)).unwrap(); }); } diff --git a/examples/rust-matter-light/src/persist.rs b/examples/rust-matter-light/src/persist.rs index 05d0e74f06a3..ac98270c74de 100644 --- a/examples/rust-matter-light/src/persist.rs +++ b/examples/rust-matter-light/src/persist.rs @@ -12,11 +12,11 @@ impl<'a> Psm<'a> { #[inline(always)] pub fn new(matter: &'a Matter<'a>) -> Result { let mut buf = [0; 4096]; - Ok(Self { matter, buf, dir: "test" }) + Ok(Self { matter, buf, dir: "data" }) } pub async fn run(&mut self) -> Result<(), Error> { - debug!("PSM running..."); + debug!("PersistenceManager running..."); loop { self.matter.wait_changed().await; From 4758555d5e4d206986f59b6201fca508872dfb49 Mon Sep 17 00:00:00 2001 From: Maik Lorenz Date: Tue, 9 Apr 2024 11:49:06 +0200 Subject: [PATCH 09/19] examples/rust-matter-light: Remove accidentally added files for PR --- examples/filesystem/Makefile | 6 +-- examples/rust-hello-world/Cargo.lock | 49 +++++++++++-------------- examples/rust-hello-world/Cargo.toml | 8 +--- examples/rust-hello-world/Makefile | 8 +--- examples/rust-hello-world/src/lib.rs | 55 ---------------------------- 5 files changed, 26 insertions(+), 100 deletions(-) diff --git a/examples/filesystem/Makefile b/examples/filesystem/Makefile index 3c5d2178e9b2..ca82326dac0f 100644 --- a/examples/filesystem/Makefile +++ b/examples/filesystem/Makefile @@ -27,12 +27,10 @@ USEMODULE += ps # Use the default file system USEMODULE += vfs_default USEMODULE += constfs -#USEMODULE += devfs -#USEMODULE += littlefs -#USEMODULE += littlefs2 +# USEMODULE += devfs # Enable to automatically format if mount fails -USEMODULE += vfs_auto_format +#USEMODULE += vfs_auto_format # For LittleFS on real devices, the main stack size has to be # increased: diff --git a/examples/rust-hello-world/Cargo.lock b/examples/rust-hello-world/Cargo.lock index 9113160ad95e..f28bf99b6272 100644 --- a/examples/rust-hello-world/Cargo.lock +++ b/examples/rust-hello-world/Cargo.lock @@ -22,9 +22,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.2.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bare-metal" @@ -227,9 +227,9 @@ dependencies = [ [[package]] name = "cstr" -version = "0.2.12" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68523903c8ae5aacfa32a0d9ae60cadeb764e1da14ee0d26b1f3089f13a54636" +checksum = "8aa998c33a6d3271e3678950a22134cd7dd27cef86dee1b611b5b14207d1d90b" dependencies = [ "proc-macro2", "quote", @@ -359,9 +359,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.11" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "lazy_static" @@ -415,9 +415,9 @@ checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "memchr" -version = "2.7.2" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "minimal-lexical" @@ -494,7 +494,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.53", ] [[package]] @@ -529,9 +529,9 @@ checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" [[package]] name = "regex" -version = "1.10.4" +version = "1.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" dependencies = [ "aho-corasick", "memchr", @@ -552,14 +552,14 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.3" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "riot-sys" -version = "0.7.12" -source = "git+https://github.com/RIOT-OS/rust-riot-sys#a3752271062299f68c5f6ba3c6e503ac725722c4" +version = "0.7.11" +source = "git+https://github.com/RIOT-OS/rust-riot-sys#3fcd2c1ac196795496be9962bc31919743a60d9a" dependencies = [ "bindgen", "c2rust-asm-casts", @@ -573,7 +573,8 @@ dependencies = [ [[package]] name = "riot-wrappers" -version = "0.8.3" +version = "0.8.2" +source = "git+https://github.com/RIOT-OS/rust-riot-wrappers#f17d22a75f7494a39f5b5e8b02e3cddd3b86d3d4" dependencies = [ "bare-metal", "coap-handler 0.1.6", @@ -581,7 +582,6 @@ dependencies = [ "coap-message 0.2.3", "coap-message 0.3.1", "coap-numbers", - "critical-section", "cstr", "embedded-graphics", "embedded-hal 0.2.7", @@ -685,14 +685,14 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.53", ] [[package]] name = "serde_json" -version = "1.0.115" +version = "1.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" +checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" dependencies = [ "itoa", "ryu", @@ -748,9 +748,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.55" +version = "2.0.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0" +checksum = "7383cd0e49fff4b6b90ca5670bfd3e9d6a733b3f90c686605aa7eec8c4996032" dependencies = [ "proc-macro2", "quote", @@ -871,8 +871,3 @@ name = "windows_x86_64_msvc" version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" - -[[patch.unused]] -name = "riot-wrappers" -version = "0.8.3" -source = "git+https://github.com/RIOT-OS/rust-riot-wrappers#409a5bea642c8b9aeb765676f62884763b3524f4" diff --git a/examples/rust-hello-world/Cargo.toml b/examples/rust-hello-world/Cargo.toml index f0e58e182053..215d2fe63bfa 100644 --- a/examples/rust-hello-world/Cargo.toml +++ b/examples/rust-hello-world/Cargo.toml @@ -15,16 +15,10 @@ crate-type = ["staticlib"] panic = "abort" [dependencies] -riot-wrappers = { path = "../../../rust-riot-wrappers", features = ["set_panic_handler", "panic_handler_crash", "panic_handler_format", "critical-section", "provide_critical_section_1_0", "with_msg_v2"] } -#riot-wrappers = { version = "0.8", features = [ "set_panic_handler" ] } -#riot-sys = "*" +riot-wrappers = { version = "0.8", features = [ "set_panic_handler" ] } # While currently this example 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/" } - -[patch.crates-io] -#riot-wrappers = { path = "../../../rust-riot-wrappers" } -#riot-sys = { path = "../../../rust-riot-sys" } \ No newline at end of file diff --git a/examples/rust-hello-world/Makefile b/examples/rust-hello-world/Makefile index c82e9be398c7..b6d08353e4af 100644 --- a/examples/rust-hello-world/Makefile +++ b/examples/rust-hello-world/Makefile @@ -2,11 +2,7 @@ APPLICATION = hello-world # If no BOARD is found in the environment, use this default: -BOARD ?= native64 - -USEMODULE += vfs -USEMODULE += vfs_default -USEMODULE += shell_cmds_default +BOARD ?= native # This has to be the absolute path to the RIOT base directory: RIOTBASE ?= $(CURDIR)/../.. @@ -25,8 +21,6 @@ BASELIBS += $(APPLICATION_RUST_MODULE).module FEATURES_REQUIRED += rust_target - - # Currently unknown, something related to the LED_PORT definition that doesn't # pass C2Rust's transpilation BOARD_BLACKLIST := ek-lm4f120xl diff --git a/examples/rust-hello-world/src/lib.rs b/examples/rust-hello-world/src/lib.rs index be1e81b77944..3f72a5615a3e 100644 --- a/examples/rust-hello-world/src/lib.rs +++ b/examples/rust-hello-world/src/lib.rs @@ -5,68 +5,13 @@ // directory for more details. #![no_std] -use riot_wrappers::error::NumericError; use riot_wrappers::riot_main; use riot_wrappers::println; extern crate rust_riotmodules; -use riot_wrappers::vfs::{Dir, File, FileMode, Mount, SeekFrom}; - riot_main!(main); -const BUF_SIZE: usize = 100; - fn main() { println!("Hello Rust!"); - - let mut mount_points = Mount::all(); - let mut mp = mount_points.next().expect("no mount point found"); - let dir = Dir::open("/nvm0"); - match dir { - Ok(dir) => { println!("Opened dir: {:?}", dir.count()) } - Err(_) => { println!("error opening dir"); } - } - println!("Mount point: {:?}, {} files", mp.mount_point(), mp.root_dir().count()); - - //let mut rw_file = File::open_with_mode("/nvm0/test", FileMode::ReadWrite(false)); - let mut rw_file = File::open_with_mode("/nvm0/test", FileMode::ReadWrite(false)); - //let mut rw_file = File::open_rw("/nvm0/test123"); - match rw_file { - Ok(mut f) => { - println!("File opened with R/W"); - let data = "hello".as_bytes(); - f.write(&data).expect("Error writing to file"); - println!("Write success!"); - - f.seek(SeekFrom::Start(0)).expect("seek failed"); - let mut content: [u8; BUF_SIZE] = [0; BUF_SIZE]; - f.read(&mut content).expect("Error reading from file"); - println!("Contents: {:?}", content); - drop(f); - } - Err(err) => { - println!("Error opening file: {:?}", err); - } - } - return; - - let mut f = File::open_rw("/nvm0/write_only"); - match f { - Ok(mut f) => { - println!("File opened!"); - let data = "hello".as_bytes(); - f.write(&data).expect("Error writing to file"); - println!("Contents written!"); - - f.seek(SeekFrom::Start(0)).expect("seek failed"); - let mut content: [u8; BUF_SIZE] = [0; BUF_SIZE]; - f.read(&mut content).expect("Error reading from file"); - println!("Contents: {:?}", content); - drop(f); - } - Err(err) => { - println!("Error opening file: {:?}", err); - } - } } From ebd58d9b3c0cbb02b09a5d88677511f46c35e8fb Mon Sep 17 00:00:00 2001 From: Maik Lorenz Date: Tue, 9 Apr 2024 11:52:47 +0200 Subject: [PATCH 10/19] examples/rust-matter-light: Remove accidentally added files for PR --- examples/rust-hello-world/Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/rust-hello-world/Cargo.lock b/examples/rust-hello-world/Cargo.lock index f28bf99b6272..2da593648a0b 100644 --- a/examples/rust-hello-world/Cargo.lock +++ b/examples/rust-hello-world/Cargo.lock @@ -573,8 +573,8 @@ dependencies = [ [[package]] name = "riot-wrappers" -version = "0.8.2" -source = "git+https://github.com/RIOT-OS/rust-riot-wrappers#f17d22a75f7494a39f5b5e8b02e3cddd3b86d3d4" +version = "0.8.3" +source = "git+https://github.com/RIOT-OS/rust-riot-wrappers#de348dce223543babe4763dda39196bd5f881c8d" dependencies = [ "bare-metal", "coap-handler 0.1.6", From 5f851ed7d1e0fd166416e4dd60c35db4cddbd7fd Mon Sep 17 00:00:00 2001 From: Maik Lorenz Date: Wed, 17 Apr 2024 21:15:54 +0200 Subject: [PATCH 11/19] examples/rust-matter-light: Include random module (needed for rs-matter); get epoch using RTC --- examples/rust-matter-light/Cargo.lock | 117 +++++++++++++----------- examples/rust-matter-light/Makefile | 6 +- examples/rust-matter-light/src/lib.rs | 3 +- examples/rust-matter-light/src/utils.rs | 16 ++++ examples/rust-matter-light/utils.c | 25 +++++ 5 files changed, 110 insertions(+), 57 deletions(-) create mode 100644 examples/rust-matter-light/src/utils.rs create mode 100644 examples/rust-matter-light/utils.c diff --git a/examples/rust-matter-light/Cargo.lock b/examples/rust-matter-light/Cargo.lock index ded9262076f1..8942c28fe8e7 100644 --- a/examples/rust-matter-light/Cargo.lock +++ b/examples/rust-matter-light/Cargo.lock @@ -270,9 +270,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.92" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2678b2e3449475e95b0aa6f9b506a28e61b3dc8996592b983695e8ebb58a8b41" +checksum = "17f6e324229dc011159fcc089755d1e2e216a90d43a7dea6853ca740b84f35e7" [[package]] name = "ccm" @@ -353,7 +353,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.59", ] [[package]] @@ -536,7 +536,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.10.0", - "syn 2.0.58", + "syn 2.0.59", ] [[package]] @@ -547,7 +547,7 @@ checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f" dependencies = [ "darling_core", "quote", - "syn 2.0.58", + "syn 2.0.59", ] [[package]] @@ -571,7 +571,7 @@ checksum = "5fe87ce4529967e0ba1dcf8450bab64d97dfd5010a6256187ffe2e43e6f0e049" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.59", ] [[package]] @@ -630,9 +630,9 @@ dependencies = [ [[package]] name = "either" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" +checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" [[package]] name = "elliptic-curve" @@ -673,7 +673,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.59", ] [[package]] @@ -1204,7 +1204,7 @@ checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.59", ] [[package]] @@ -1305,9 +1305,9 @@ dependencies = [ [[package]] name = "num" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b05180d69e3da0e530ba2a1dae5110317e49e3b7f3d41be227dc5f92e49ee7af" +checksum = "3135b08af27d103b0a51f2ae0f8632117b7b185ccf931445affa8df530576a41" dependencies = [ "num-complex", "num-integer", @@ -1339,7 +1339,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.59", ] [[package]] @@ -1478,7 +1478,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.59", ] [[package]] @@ -1531,9 +1531,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.79" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" dependencies = [ "unicode-ident", ] @@ -1546,9 +1546,9 @@ checksum = "d0e2c0bf8be8a1c4a4f48973dabf26943f05da2bfc2d3180aae62409dbba6f0c" [[package]] name = "quote" -version = "1.0.35" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -1616,7 +1616,7 @@ dependencies = [ [[package]] name = "riot-wrappers" version = "0.8.3" -source = "git+https://github.com/RIOT-OS/rust-riot-wrappers.git#de348dce223543babe4763dda39196bd5f881c8d" +source = "git+https://github.com/RIOT-OS/rust-riot-wrappers.git#ea8d7fad95c8cb256ba9bc178f7779d266cc0def" dependencies = [ "bare-metal", "coap-handler 0.1.6", @@ -1650,7 +1650,7 @@ dependencies = [ [[package]] name = "rs-matter" version = "0.1.2" -source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#865adac5d0a1a760fe119a41fca9923a001b2706" +source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#5f07349a2267aac2a2f83ce5ee356a768586aeda" dependencies = [ "aes", "astro-dnssd", @@ -1696,7 +1696,7 @@ dependencies = [ [[package]] name = "rs-matter-data-model" version = "0.1.0" -source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#865adac5d0a1a760fe119a41fca9923a001b2706" +source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#5f07349a2267aac2a2f83ce5ee356a768586aeda" dependencies = [ "clap", "miette", @@ -1712,26 +1712,26 @@ dependencies = [ [[package]] name = "rs-matter-macros" version = "0.1.0" -source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#865adac5d0a1a760fe119a41fca9923a001b2706" +source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#5f07349a2267aac2a2f83ce5ee356a768586aeda" dependencies = [ "proc-macro-crate", "proc-macro2", "quote", "rs-matter-data-model", "rs-matter-macros-impl", - "syn 2.0.58", + "syn 2.0.59", ] [[package]] name = "rs-matter-macros-impl" version = "0.1.0" -source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#865adac5d0a1a760fe119a41fca9923a001b2706" +source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#5f07349a2267aac2a2f83ce5ee356a768586aeda" dependencies = [ "convert_case", "proc-macro2", "quote", "rs-matter-data-model", - "syn 2.0.58", + "syn 2.0.59", ] [[package]] @@ -1837,9 +1837,9 @@ checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" [[package]] name = "serde" -version = "1.0.197" +version = "1.0.198" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" dependencies = [ "serde_derive", ] @@ -1856,20 +1856,20 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.197" +version = "1.0.198" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.59", ] [[package]] name = "serde_json" -version = "1.0.115" +version = "1.0.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" +checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" dependencies = [ "itoa", "ryu", @@ -1995,7 +1995,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.58", + "syn 2.0.59", ] [[package]] @@ -2054,9 +2054,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.58" +version = "2.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" +checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" dependencies = [ "proc-macro2", "quote", @@ -2101,7 +2101,7 @@ checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.59", ] [[package]] @@ -2116,9 +2116,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.34" +version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "num-conv", @@ -2168,7 +2168,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.59", ] [[package]] @@ -2344,13 +2344,14 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", + "windows_i686_gnullvm", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", @@ -2359,45 +2360,51 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" [[package]] name = "windows_aarch64_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" [[package]] name = "windows_i686_gnu" -version = "0.52.4" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" [[package]] name = "windows_i686_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" [[package]] name = "windows_x86_64_gnu" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" [[package]] name = "windows_x86_64_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "winnow" diff --git a/examples/rust-matter-light/Makefile b/examples/rust-matter-light/Makefile index 94b457bb39b6..b2c83b8578e9 100644 --- a/examples/rust-matter-light/Makefile +++ b/examples/rust-matter-light/Makefile @@ -20,13 +20,16 @@ QUIET ?= 1 # - Packet Buffers: 24 kB # - UDP Buffers: 3 kB CFLAGS += '-DTHREAD_STACKSIZE_MAIN=(THREAD_STACKSIZE_DEFAULT + 50000)' -#CFLAGS += '-DISR_STACKSIZE=(THREAD_STACKSIZE_DEFAULT + 20000)' +CFLAGS += '-DISR_STACKSIZE=2048' +CFLAGS += '-DGNRC_NETIF_MSG_QUEUE_SIZE=16' +CFLAGS += '-DCONFIG_GNRC_SOCK_MBOX_SIZE_EXP=8' # The name of crate (as per Cargo.toml package name, but with '-' replaced with '_') APPLICATION_RUST_MODULE = rust_matter_light BASELIBS += $(APPLICATION_RUST_MODULE).module FEATURES_REQUIRED += rust_target +FEATURES_REQUIRED += periph_rtc # Comment this line in to activate storing & loading runtime configurations # NOTE: To use this feature, a PersistenceManager (in 'src/persist.rs') must be implemented for the target platform @@ -41,6 +44,7 @@ USEMODULE += ztimer USEMODULE += ztimer_msec USEMODULE += ztimer_usec USEMODULE += ps +USEMODULE += random # networking USEMODULE += netdev_default diff --git a/examples/rust-matter-light/src/lib.rs b/examples/rust-matter-light/src/lib.rs index c5f562b5a988..246397a00e2c 100644 --- a/examples/rust-matter-light/src/lib.rs +++ b/examples/rust-matter-light/src/lib.rs @@ -17,6 +17,7 @@ mod logging; // TODO: Enable attribute or feature to be able to run integration tests inside this module under RIOT OS #[allow(unused)] mod tests; +mod utils; // internal modules imports use network::UdpSocketWrapper; @@ -226,7 +227,7 @@ fn run_matter() -> Result<(), ()> { let dev_att: &'static HardCodedDevAtt = DEV_ATT.init(HardCodedDevAtt::new()); // TODO: Provide own epoch and rand functions - let epoch = rs_matter::utils::epoch::riot_epoch; + let epoch = utils::get_epoch; let rand = rs_matter::utils::rand::riot_rand; let matter: &'static Matter = MATTER.init(Matter::new( diff --git a/examples/rust-matter-light/src/utils.rs b/examples/rust-matter-light/src/utils.rs new file mode 100644 index 000000000000..3bb2c1af1b69 --- /dev/null +++ b/examples/rust-matter-light/src/utils.rs @@ -0,0 +1,16 @@ +use core::time::Duration; +use log::info; +use rs_matter::utils::epoch::MATTER_EPOCH_SECS; + +extern "C" { + fn get_seconds_since_matter_epoch() -> u64; +} + +pub fn get_timestamp() -> u64 { + let rtc_seconds = unsafe { get_seconds_since_matter_epoch() }; + rtc_seconds + MATTER_EPOCH_SECS +} + +pub fn get_epoch() -> Duration { + Duration::from_secs(get_timestamp()) +} \ No newline at end of file diff --git a/examples/rust-matter-light/utils.c b/examples/rust-matter-light/utils.c new file mode 100644 index 000000000000..3e9a0adcefe9 --- /dev/null +++ b/examples/rust-matter-light/utils.c @@ -0,0 +1,25 @@ +#include "periph/rtc.h" +#include +#include + +// Matter Epoch: 2000/01/01 00:00:00 UTC +static struct tm matter_epoch = { + .tm_year = 100, // 2000 - 1900 + .tm_mon = 0, // January + .tm_mday = 1, // 1st day + .tm_hour = 0, // 0 hours + .tm_min = 0, // 0 minutes + .tm_sec = 0 // 0 seconds +}; + +int get_seconds_since_matter_epoch(void) { + // Get current time from RTC + struct tm now; + rtc_get_time(&now); + + // Convert both times to time_t (timestamp) + time_t start_ts = mktime(&matter_epoch); + time_t now_ts = mktime(&now); + double seconds_since_matter_epoch = difftime(now_ts, start_ts); + return (int)seconds_since_matter_epoch; +} From 1d35f0f24ea80ed28cead1e7d77bd6ece241a810 Mon Sep 17 00:00:00 2001 From: Maik Lorenz Date: Thu, 18 Apr 2024 11:38:19 +0200 Subject: [PATCH 12/19] examples/rust-matter-light: Add sys_rand function to utils.rs and use random module from riot-wrappers with HWRNG --- examples/rust-matter-light/Cargo.lock | 1 + examples/rust-matter-light/Cargo.toml | 1 + examples/rust-matter-light/Makefile | 2 ++ examples/rust-matter-light/src/lib.rs | 4 ++-- examples/rust-matter-light/src/utils.rs | 18 +++++++++--------- examples/rust-matter-light/utils.c | 24 ++++++------------------ 6 files changed, 21 insertions(+), 29 deletions(-) diff --git a/examples/rust-matter-light/Cargo.lock b/examples/rust-matter-light/Cargo.lock index 8942c28fe8e7..bf627b6890a6 100644 --- a/examples/rust-matter-light/Cargo.lock +++ b/examples/rust-matter-light/Cargo.lock @@ -1747,6 +1747,7 @@ dependencies = [ "embedded-hal-async", "embedded-nal-async 0.7.1", "log", + "rand_core", "riot-sys", "riot-wrappers", "rs-matter", diff --git a/examples/rust-matter-light/Cargo.toml b/examples/rust-matter-light/Cargo.toml index 76c7636cd6d6..caa05fc62848 100644 --- a/examples/rust-matter-light/Cargo.toml +++ b/examples/rust-matter-light/Cargo.toml @@ -48,6 +48,7 @@ embassy-executor = { version = "0.5", features = ["nightly"] } embedded-hal = "1.0.0" embassy-futures = "0.1.1" rs-matter = { version = "0.1.0", default-features = false, features = ["riot-os"] } +rand_core = "0.6.4" [patch.crates-io] #rs-matter = { path = "../../../rs-matter/rs-matter" } diff --git a/examples/rust-matter-light/Makefile b/examples/rust-matter-light/Makefile index b2c83b8578e9..cfee299722c0 100644 --- a/examples/rust-matter-light/Makefile +++ b/examples/rust-matter-light/Makefile @@ -45,6 +45,8 @@ USEMODULE += ztimer_msec USEMODULE += ztimer_usec USEMODULE += ps USEMODULE += random +USEMODULE += periph_hwrng +USEMODULE += prng_sha256prng # networking USEMODULE += netdev_default diff --git a/examples/rust-matter-light/src/lib.rs b/examples/rust-matter-light/src/lib.rs index 246397a00e2c..b9dce1492b07 100644 --- a/examples/rust-matter-light/src/lib.rs +++ b/examples/rust-matter-light/src/lib.rs @@ -227,8 +227,8 @@ fn run_matter() -> Result<(), ()> { let dev_att: &'static HardCodedDevAtt = DEV_ATT.init(HardCodedDevAtt::new()); // TODO: Provide own epoch and rand functions - let epoch = utils::get_epoch; - let rand = rs_matter::utils::rand::riot_rand; + let epoch = utils::sys_epoch; + let rand = utils::sys_rand; let matter: &'static Matter = MATTER.init(Matter::new( // vid/pid should match those in the DAC diff --git a/examples/rust-matter-light/src/utils.rs b/examples/rust-matter-light/src/utils.rs index 3bb2c1af1b69..d5dfed4aa91b 100644 --- a/examples/rust-matter-light/src/utils.rs +++ b/examples/rust-matter-light/src/utils.rs @@ -1,16 +1,16 @@ use core::time::Duration; -use log::info; -use rs_matter::utils::epoch::MATTER_EPOCH_SECS; +use riot_wrappers::random::Random; +use rand_core::RngCore as _; extern "C" { - fn get_seconds_since_matter_epoch() -> u64; + fn get_seconds_since_unix_epoch() -> u32; } -pub fn get_timestamp() -> u64 { - let rtc_seconds = unsafe { get_seconds_since_matter_epoch() }; - rtc_seconds + MATTER_EPOCH_SECS +pub fn sys_rand(buf: &mut [u8]) { + Random::new().fill_bytes(buf); } -pub fn get_epoch() -> Duration { - Duration::from_secs(get_timestamp()) -} \ No newline at end of file +pub fn sys_epoch() -> Duration { + let rtc_seconds = unsafe { get_seconds_since_unix_epoch() }; + Duration::from_secs(rtc_seconds as u64) +} diff --git a/examples/rust-matter-light/utils.c b/examples/rust-matter-light/utils.c index 3e9a0adcefe9..3f8ab3c36f4a 100644 --- a/examples/rust-matter-light/utils.c +++ b/examples/rust-matter-light/utils.c @@ -1,25 +1,13 @@ #include "periph/rtc.h" -#include #include -// Matter Epoch: 2000/01/01 00:00:00 UTC -static struct tm matter_epoch = { - .tm_year = 100, // 2000 - 1900 - .tm_mon = 0, // January - .tm_mday = 1, // 1st day - .tm_hour = 0, // 0 hours - .tm_min = 0, // 0 minutes - .tm_sec = 0 // 0 seconds -}; +// RIOT_EPOCH(2020) in seconds since UNIX Epoch +#define RIOT_EPOCH_SECS 1577833200; -int get_seconds_since_matter_epoch(void) { - // Get current time from RTC +uint32_t get_seconds_since_unix_epoch(void) { + // Get time since RIOT_EPOCH from RTC struct tm now; rtc_get_time(&now); - - // Convert both times to time_t (timestamp) - time_t start_ts = mktime(&matter_epoch); - time_t now_ts = mktime(&now); - double seconds_since_matter_epoch = difftime(now_ts, start_ts); - return (int)seconds_since_matter_epoch; + // Add to RIOT_EPOCH to get current seconds since UNIX epoch + return rtc_mktime(&now) + RIOT_EPOCH_SECS; } From c9573fc70ad6c0e5a9e9bb49a292abef7a15b7d2 Mon Sep 17 00:00:00 2001 From: Maik Lorenz Date: Fri, 19 Apr 2024 12:59:41 +0200 Subject: [PATCH 13/19] examples/rust-matter-light: Make periph_rtc feature optional. If not supported, get seconds since UNIX epoch from ztimer_sec --- examples/rust-matter-light/Makefile | 5 ++++- examples/rust-matter-light/utils.c | 19 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/examples/rust-matter-light/Makefile b/examples/rust-matter-light/Makefile index cfee299722c0..2e40565136d2 100644 --- a/examples/rust-matter-light/Makefile +++ b/examples/rust-matter-light/Makefile @@ -29,7 +29,9 @@ APPLICATION_RUST_MODULE = rust_matter_light BASELIBS += $(APPLICATION_RUST_MODULE).module FEATURES_REQUIRED += rust_target -FEATURES_REQUIRED += periph_rtc + +# Use RTC for sys_epoch, otherwise ztimer +FEATURES_OPTIONAL += periph_rtc # Comment this line in to activate storing & loading runtime configurations # NOTE: To use this feature, a PersistenceManager (in 'src/persist.rs') must be implemented for the target platform @@ -43,6 +45,7 @@ USEMODULE += shell_cmd_heap USEMODULE += ztimer USEMODULE += ztimer_msec USEMODULE += ztimer_usec +USEMODULE += ztimer_sec USEMODULE += ps USEMODULE += random USEMODULE += periph_hwrng diff --git a/examples/rust-matter-light/utils.c b/examples/rust-matter-light/utils.c index 3f8ab3c36f4a..86e582ace855 100644 --- a/examples/rust-matter-light/utils.c +++ b/examples/rust-matter-light/utils.c @@ -1,13 +1,24 @@ +#include +#include "modules.h" + +#if IS_USED(MODULE_PERIPH_RTC) #include "periph/rtc.h" -#include +#else +#include "ztimer.h" +#endif // RIOT_EPOCH(2020) in seconds since UNIX Epoch #define RIOT_EPOCH_SECS 1577833200; uint32_t get_seconds_since_unix_epoch(void) { - // Get time since RIOT_EPOCH from RTC +#if IS_USED(MODULE_PERIPH_RTC) + // Get seconds since RIOT_EPOCH from RTC struct tm now; rtc_get_time(&now); - // Add to RIOT_EPOCH to get current seconds since UNIX epoch - return rtc_mktime(&now) + RIOT_EPOCH_SECS; + // Add to RIOT_EPOCH to get seconds since UNIX epoch + return RIOT_EPOCH_SECS + rtc_mktime(&now); +#else + // Get elapsed seconds from ztimer + return RIOT_EPOCH_SECS + ztimer_now(ZTIMER_SEC); +#endif } From 4efe8fe529536935c11b98c8f38b75c8ae3a8a6c Mon Sep 17 00:00:00 2001 From: Maik Lorenz Date: Mon, 22 Apr 2024 10:52:27 +0200 Subject: [PATCH 14/19] examples/rust-matter-light: Fix: UNIX epoch must be in millisecond precision; print passcode and discriminator with matter shell cmd --- examples/rust-matter-light/Cargo.lock | 64 ++++++++++++------------- examples/rust-matter-light/src/lib.rs | 18 ++++--- examples/rust-matter-light/src/utils.rs | 31 ++++++++++-- examples/rust-matter-light/utils.c | 20 ++++---- 4 files changed, 78 insertions(+), 55 deletions(-) diff --git a/examples/rust-matter-light/Cargo.lock b/examples/rust-matter-light/Cargo.lock index bf627b6890a6..5b6b684124a4 100644 --- a/examples/rust-matter-light/Cargo.lock +++ b/examples/rust-matter-light/Cargo.lock @@ -232,9 +232,9 @@ checksum = "b4ae4235e6dac0694637c763029ecea1a2ec9e4e06ec2729bd21ba4d9c863eb7" [[package]] name = "bytecount" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1e5f035d16fc623ae5f74981db80a439803888314e3a555fd6f04acd51a3205" +checksum = "5ce89b21cab1437276d2650d57e971f9d548a2d9037cc231abdc0562b97498ce" [[package]] name = "byteorder" @@ -270,9 +270,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.94" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17f6e324229dc011159fcc089755d1e2e216a90d43a7dea6853ca740b84f35e7" +checksum = "d32a725bc159af97c3e629873bb9f88fb8cf8a4867175f76dc987815ea07c83b" [[package]] name = "ccm" @@ -353,7 +353,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] @@ -404,9 +404,9 @@ dependencies = [ [[package]] name = "coap-numbers" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e766be4563107bc11c281c017ab922c3f3079345c9aa0fe747b4f9abc13411ac" +checksum = "6d78a5634393ab2c11d173d66107200a730e200a3b3ca063c344d4459c90a5f9" [[package]] name = "colorchoice" @@ -536,7 +536,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.10.0", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] @@ -547,7 +547,7 @@ checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f" dependencies = [ "darling_core", "quote", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] @@ -571,7 +571,7 @@ checksum = "5fe87ce4529967e0ba1dcf8450bab64d97dfd5010a6256187ffe2e43e6f0e049" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] @@ -673,7 +673,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] @@ -1204,7 +1204,7 @@ checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] @@ -1339,7 +1339,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] @@ -1478,7 +1478,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] @@ -1650,7 +1650,7 @@ dependencies = [ [[package]] name = "rs-matter" version = "0.1.2" -source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#5f07349a2267aac2a2f83ce5ee356a768586aeda" +source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#040bb46aaf6a5af846c37c8dc8c34536f134395a" dependencies = [ "aes", "astro-dnssd", @@ -1696,7 +1696,7 @@ dependencies = [ [[package]] name = "rs-matter-data-model" version = "0.1.0" -source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#5f07349a2267aac2a2f83ce5ee356a768586aeda" +source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#040bb46aaf6a5af846c37c8dc8c34536f134395a" dependencies = [ "clap", "miette", @@ -1712,26 +1712,26 @@ dependencies = [ [[package]] name = "rs-matter-macros" version = "0.1.0" -source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#5f07349a2267aac2a2f83ce5ee356a768586aeda" +source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#040bb46aaf6a5af846c37c8dc8c34536f134395a" dependencies = [ "proc-macro-crate", "proc-macro2", "quote", "rs-matter-data-model", "rs-matter-macros-impl", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] name = "rs-matter-macros-impl" version = "0.1.0" -source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#5f07349a2267aac2a2f83ce5ee356a768586aeda" +source = "git+https://github.com/maikerlab/rs-matter?branch=feature/RIOT_OS#040bb46aaf6a5af846c37c8dc8c34536f134395a" dependencies = [ "convert_case", "proc-macro2", "quote", "rs-matter-data-model", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] @@ -1782,9 +1782,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.32" +version = "0.38.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" +checksum = "e3cc72858054fcff6d7dea32df2aeaee6a7c24227366d7ea429aada2f26b16ad" dependencies = [ "bitflags 2.5.0", "errno", @@ -1863,7 +1863,7 @@ checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] @@ -1996,7 +1996,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] @@ -2055,9 +2055,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.59" +version = "2.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" dependencies = [ "proc-macro2", "quote", @@ -2087,22 +2087,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.58" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.58" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] @@ -2169,7 +2169,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] diff --git a/examples/rust-matter-light/src/lib.rs b/examples/rust-matter-light/src/lib.rs index b9dce1492b07..89bdc9e5e9ae 100644 --- a/examples/rust-matter-light/src/lib.rs +++ b/examples/rust-matter-light/src/lib.rs @@ -173,6 +173,10 @@ static MATTER: StaticCell = StaticCell::new(); // Set this to the name of the LED, which should be controlled using SAUL registry const ONOFF_LED_NAME: &str = "LD2(blue)"; +// TODO: Passcode and discriminator should be provisioned safely during compilation +const PASSCODE: u32 = 123456; +const DISCRIMINATOR: u16 = 250; + riot_main!(main); fn led_onoff(on: bool) { @@ -193,14 +197,8 @@ fn led_onoff(on: bool) { fn cmd_matter(_stdio: &mut riot_wrappers::stdio::Stdio, _args: shell::Args<'_>) { // TODO: Support some useful commands for this Matter node or interacting with other nodes - info!("Endpoint Info:"); - NODE.endpoints.into_iter().for_each(|ep| { - info!("Endpoint No. {} - DeviceType={:#04x}", ep.id, ep.device_type.dtype); - ep.clusters.into_iter().for_each(|cluster| { - info!(" Cluster ID={:#04x}", cluster.id); - cluster.attributes.into_iter().for_each(|attr| info!(" Attribute {:#04x}", attr.id)) - }); - }); + info!("Discover device using discriminator: {}", DISCRIMINATOR); + info!("Pair device using passcode: {}", PASSCODE); } static_command!(matter, "matter", "Interact with Matter devices", cmd_matter); @@ -364,8 +362,8 @@ async fn matter_task(matter: &'static Matter<'_>) { &mut matter_packet_buffers, CommissioningData { // TODO: Hard-coded for now - verifier: VerifierData::new_with_pw(123456, *matter.borrow()), - discriminator: 250, + verifier: VerifierData::new_with_pw(PASSCODE, *matter.borrow()), + discriminator: DISCRIMINATOR, }, &handler) ); diff --git a/examples/rust-matter-light/src/utils.rs b/examples/rust-matter-light/src/utils.rs index d5dfed4aa91b..d3c92b7bffb9 100644 --- a/examples/rust-matter-light/src/utils.rs +++ b/examples/rust-matter-light/src/utils.rs @@ -1,16 +1,41 @@ use core::time::Duration; +use log::{debug, info}; use riot_wrappers::random::Random; use rand_core::RngCore as _; +use riot_wrappers::mutex::Mutex; +use rs_matter::utils::epoch::MATTER_EPOCH_SECS; + +// RIOT_EPOCH(2020) in seconds since UNIX Epoch +const RIOT_EPOCH_SECS: u64 = 1577833200; extern "C" { - fn get_seconds_since_unix_epoch() -> u32; + fn get_seconds_since_riot_epoch() -> u32; + fn get_milliseconds() -> u16; } +/// Generate random bytes using the RIOT random module pub fn sys_rand(buf: &mut [u8]) { Random::new().fill_bytes(buf); + debug!("RNG generated bytes: {:?}", buf); } +// Current UNIX Epoch - must be in ms precision +static CURRENT_DURATION: Mutex = Mutex::new(Duration::from_secs(RIOT_EPOCH_SECS)); + +/// Get the current time as UNIX Epoch with milliseconds precision +/// using periph_rtc (if supported) or ztimer module pub fn sys_epoch() -> Duration { - let rtc_seconds = unsafe { get_seconds_since_unix_epoch() }; - Duration::from_secs(rtc_seconds as u64) + let mut duration = CURRENT_DURATION.lock(); + let riot_sec = unsafe { get_seconds_since_riot_epoch() } as u64; + let riot_msec = unsafe { get_milliseconds() } as u32; + let unix_seconds = RIOT_EPOCH_SECS + riot_sec; + debug!("UNIX epoch (sec.ms): {}.{}", unix_seconds, riot_msec); + let new_duration = Duration::new(unix_seconds, riot_msec*1000000); + // make sure that we always get a new timestamp in rare cases if sec and msec didn't change + if *duration == new_duration { + *duration = Duration::new(unix_seconds, (riot_msec + 1)*1000000); + } else { + *duration = new_duration; + } + *duration } diff --git a/examples/rust-matter-light/utils.c b/examples/rust-matter-light/utils.c index 86e582ace855..c98e1b334255 100644 --- a/examples/rust-matter-light/utils.c +++ b/examples/rust-matter-light/utils.c @@ -1,24 +1,24 @@ #include #include "modules.h" - +#include +#include "ztimer.h" #if IS_USED(MODULE_PERIPH_RTC) #include "periph/rtc.h" -#else -#include "ztimer.h" #endif -// RIOT_EPOCH(2020) in seconds since UNIX Epoch -#define RIOT_EPOCH_SECS 1577833200; - -uint32_t get_seconds_since_unix_epoch(void) { +uint32_t get_seconds_since_riot_epoch(void) { #if IS_USED(MODULE_PERIPH_RTC) // Get seconds since RIOT_EPOCH from RTC struct tm now; rtc_get_time(&now); - // Add to RIOT_EPOCH to get seconds since UNIX epoch - return RIOT_EPOCH_SECS + rtc_mktime(&now); + rtc_tm_normalize(&now); + return rtc_mktime(&now); #else // Get elapsed seconds from ztimer - return RIOT_EPOCH_SECS + ztimer_now(ZTIMER_SEC); + return ztimer_now(ZTIMER_SEC); #endif } + +uint16_t get_milliseconds(void) { + return ztimer_now(ZTIMER_MSEC) % 1000; +} \ No newline at end of file From baae4fc145d991bb917d0465a843c161b06e1884 Mon Sep 17 00:00:00 2001 From: Maik Lorenz Date: Tue, 23 Apr 2024 17:37:37 +0200 Subject: [PATCH 15/19] examples/rust-matter-light: Move all "matter core" related stuff into maikerlab/rust-riot-wrappers (branch=with_matter) --- examples/rust-matter-light/Cargo.lock | 48 ++++++- examples/rust-matter-light/Cargo.toml | 6 +- examples/rust-matter-light/src/lib.rs | 38 ++---- examples/rust-matter-light/src/logging.rs | 27 ---- examples/rust-matter-light/src/network.rs | 151 ---------------------- examples/rust-matter-light/src/rgb_led.rs | 45 ------- examples/rust-matter-light/src/tests.rs | 5 +- examples/rust-matter-light/src/utils.rs | 60 ++++++++- 8 files changed, 115 insertions(+), 265 deletions(-) delete mode 100644 examples/rust-matter-light/src/logging.rs delete mode 100644 examples/rust-matter-light/src/network.rs delete mode 100644 examples/rust-matter-light/src/rgb_led.rs diff --git a/examples/rust-matter-light/Cargo.lock b/examples/rust-matter-light/Cargo.lock index 5b6b684124a4..e74b4d02fa35 100644 --- a/examples/rust-matter-light/Cargo.lock +++ b/examples/rust-matter-light/Cargo.lock @@ -683,7 +683,7 @@ source = "git+https://gitlab.com/etonomy/riot-module-examples#26a7d27b4c0d518be1 dependencies = [ "embassy-executor", "riot-sys", - "riot-wrappers", + "riot-wrappers 0.8.3 (git+https://github.com/RIOT-OS/rust-riot-wrappers.git)", ] [[package]] @@ -1616,7 +1616,7 @@ dependencies = [ [[package]] name = "riot-wrappers" version = "0.8.3" -source = "git+https://github.com/RIOT-OS/rust-riot-wrappers.git#ea8d7fad95c8cb256ba9bc178f7779d266cc0def" +source = "git+https://github.com/maikerlab/rust-riot-wrappers.git?branch=with_matter#093983d50e9f76be8e810d2f9820761498d00e8e" dependencies = [ "bare-metal", "coap-handler 0.1.6", @@ -1626,6 +1626,10 @@ dependencies = [ "coap-numbers", "critical-section", "cstr", + "embassy-executor", + "embassy-executor-riot", + "embassy-futures", + "embassy-sync", "embedded-graphics", "embedded-hal 0.2.7", "embedded-hal 1.0.0", @@ -1635,6 +1639,38 @@ dependencies = [ "embedded-nal-async 0.7.1", "heapless 0.7.17", "hex", + "log", + "mutex-trait", + "nb 0.1.3", + "num-traits", + "pin-project", + "pin-utils", + "rand_core", + "riot-sys", + "rs-matter", + "shlex 0.1.1", + "switch-hal", + "syn 1.0.109", +] + +[[package]] +name = "riot-wrappers" +version = "0.8.3" +source = "git+https://github.com/RIOT-OS/rust-riot-wrappers.git#ea8d7fad95c8cb256ba9bc178f7779d266cc0def" +dependencies = [ + "bare-metal", + "coap-handler 0.1.6", + "coap-handler 0.2.0", + "coap-message 0.2.3", + "coap-message 0.3.1", + "coap-numbers", + "cstr", + "embedded-graphics", + "embedded-hal 0.2.7", + "embedded-hal 1.0.0", + "embedded-hal-async", + "heapless 0.7.17", + "hex", "mutex-trait", "nb 0.1.3", "num-traits", @@ -1682,7 +1718,7 @@ dependencies = [ "portable-atomic", "qrcodegen-no-heap", "rand_core", - "riot-wrappers", + "riot-wrappers 0.8.3 (git+https://github.com/RIOT-OS/rust-riot-wrappers.git)", "rs-matter-macros", "safemem", "sha2", @@ -1749,7 +1785,7 @@ dependencies = [ "log", "rand_core", "riot-sys", - "riot-wrappers", + "riot-wrappers 0.8.3 (git+https://github.com/maikerlab/rust-riot-wrappers.git?branch=with_matter)", "rs-matter", "rust_riotmodules", "static_cell", @@ -1782,9 +1818,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.33" +version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3cc72858054fcff6d7dea32df2aeaee6a7c24227366d7ea429aada2f26b16ad" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ "bitflags 2.5.0", "errno", diff --git a/examples/rust-matter-light/Cargo.toml b/examples/rust-matter-light/Cargo.toml index caa05fc62848..cda7a97f738e 100644 --- a/examples/rust-matter-light/Cargo.toml +++ b/examples/rust-matter-light/Cargo.toml @@ -28,7 +28,8 @@ debug = true opt-level = 3 [dependencies] -riot-wrappers = { git = "https://github.com/RIOT-OS/rust-riot-wrappers.git", features = [ "set_panic_handler", "panic_handler_format", "panic_handler_crash", "with_embedded_nal_async", "provide_critical_section_1_0", "with_embedded_hal_async" ] } +#riot-wrappers = { git = "https://github.com/RIOT-OS/rust-riot-wrappers.git", features = [ "set_panic_handler", "panic_handler_format", "panic_handler_crash", "with_embedded_nal_async", "provide_critical_section_1_0", "with_embedded_hal_async" ] } +riot-wrappers = { git = "https://github.com/maikerlab/rust-riot-wrappers.git", branch = "with_matter", features = [ "set_panic_handler", "panic_handler_format", "panic_handler_crash", "with_embedded_nal_async", "provide_critical_section_1_0", "with_embedded_hal_async", "with_matter" ] } riot-sys = "*" embedded-nal-async = "0.7.1" embedded-hal-async = { version = "1.0.0"} @@ -52,4 +53,5 @@ rand_core = "0.6.4" [patch.crates-io] #rs-matter = { path = "../../../rs-matter/rs-matter" } -rs-matter = { git = "https://github.com/maikerlab/rs-matter", branch = "feature/RIOT_OS" } \ No newline at end of file +rs-matter = { git = "https://github.com/maikerlab/rs-matter", branch = "feature/RIOT_OS" } +riot-wrappers = { path = "../../../rust-riot-wrappers" } diff --git a/examples/rust-matter-light/src/lib.rs b/examples/rust-matter-light/src/lib.rs index 89bdc9e5e9ae..0b1259b0f00f 100644 --- a/examples/rust-matter-light/src/lib.rs +++ b/examples/rust-matter-light/src/lib.rs @@ -6,39 +6,27 @@ #![no_std] #![feature(type_alias_impl_trait)] -// declare internal modules +use core::{borrow::Borrow, pin::pin}; +use core::cell::Cell; +use static_cell::StaticCell; +use embedded_nal_async::{Ipv4Addr, UdpStack as _}; +use embedded_alloc::Heap; +use embedded_hal::delay::DelayNs as _; +use log::{debug, info, error, LevelFilter, warn}; + mod dev_att; -mod network; -#[allow(dead_code)] -mod rgb_led; #[allow(unused)] mod persist; -mod logging; // TODO: Enable attribute or feature to be able to run integration tests inside this module under RIOT OS #[allow(unused)] mod tests; mod utils; -// internal modules imports -use network::UdpSocketWrapper; -use network::utils::initialize_network; -use logging::init_logger; use dev_att::HardCodedDevAtt; - -// core library -use core::{borrow::Borrow, pin::pin}; -use core::cell::Cell; - -// external crates -use static_cell::StaticCell; -use embedded_nal_async::{Ipv4Addr, UdpStack as _}; -use embedded_alloc::Heap; -use embedded_hal::delay::DelayNs as _; -use log::{debug, info, error, LevelFilter, warn}; +use utils::initialize_network; // RIOT OS modules extern crate rust_riotmodules; - use riot_wrappers::{riot_main, static_command}; use riot_wrappers::ztimer; use riot_wrappers::thread; @@ -47,10 +35,8 @@ use riot_wrappers::cstr::cstr; use riot_wrappers::shell::{self, CommandList}; use riot_wrappers::saul::{ActuatorClass, Class, Phydat, RegistryEntry}; -// rs-matter -#[allow(unused_variables)] -#[allow(dead_code)] -extern crate rs_matter; +// the new 'matter' module in riot-wrappers, enabled by 'with_matter' feature +use riot_wrappers::matter::{init_logger, UdpSocketWrapper}; use rs_matter::{CommissioningData, MATTER_PORT}; use rs_matter::transport::network::UdpBuffers; @@ -72,7 +58,7 @@ use rs_matter::secure_channel::spake2p::VerifierData; use rs_matter::tlv::TLVElement; use rs_matter::transport::exchange::Exchange; -// Node object with endpoints supporting device type 'OnOff Light' +// Node object with endpoints supporting device type 'On/Off Light' const NODE: Node<'static> = Node { id: 0, endpoints: &[ diff --git a/examples/rust-matter-light/src/logging.rs b/examples/rust-matter-light/src/logging.rs deleted file mode 100644 index 568a1344e5f6..000000000000 --- a/examples/rust-matter-light/src/logging.rs +++ /dev/null @@ -1,27 +0,0 @@ -use log::{Level, LevelFilter, Log, Record, SetLoggerError}; -use riot_wrappers::println; - -struct RiotLogger; - -impl Log for RiotLogger { - fn enabled(&self, metadata: &log::Metadata) -> bool { - metadata.level() >= Level::Info - } - - fn log(&self, record: &Record) { - if self.enabled(record.metadata()) { - println!("[{}] {}", record.level(), record.args()); - } - } - - fn flush(&self) {} -} - -static LOGGER: RiotLogger = RiotLogger; - -pub fn init_logger(level: LevelFilter) -> Result<(), SetLoggerError> { - //let log_level: &'static str = env!("RIOT_LOG_LEVEL"); - //println!("the RIOT_LOG_LEVEL variable at the time of compiling was: {log_level}"); - log::set_logger(&LOGGER) - .map(|_| log::set_max_level(level)) -} \ No newline at end of file diff --git a/examples/rust-matter-light/src/network.rs b/examples/rust-matter-light/src/network.rs deleted file mode 100644 index f688096137e8..000000000000 --- a/examples/rust-matter-light/src/network.rs +++ /dev/null @@ -1,151 +0,0 @@ -use rs_matter::error::Error as MatterError; -use riot_wrappers::gnrc::Netif; -use embedded_nal_async::{Ipv6Addr, SocketAddr, UnconnectedUdp}; - -use embassy_futures::select::{Either, select}; -use riot_wrappers::mutex::Mutex; -use riot_wrappers::ztimer; -use riot_wrappers::socket_embedded_nal_async_udp::UnconnectedUdpSocket; -use rs_matter::error::{Error, ErrorCode}; -use rs_matter::transport::network::{UdpReceive, UdpSend}; -use embassy_sync::{ - signal::Signal, - blocking_mutex::raw::NoopRawMutex -}; -use embedded_hal_async::delay::DelayNs; -use log::{debug, error, warn}; - -pub type Notification = Signal; - -pub struct UdpSocketWrapper { - local_addr: SocketAddr, - socket: Mutex, - release_socket_notification: Notification, - socket_released_notification: Notification, -} - -impl UdpSocketWrapper { - pub fn new(local_addr: SocketAddr, socket: UnconnectedUdpSocket) -> Self { - Self { - local_addr, - socket: Mutex::new(socket), - release_socket_notification: Notification::new(), - socket_released_notification: Notification::new(), - } - } -} - -impl UdpSend for &UdpSocketWrapper { - async fn send_to(&mut self, data: &[u8], addr: SocketAddr) -> Result<(), Error> { - debug!("(UDP) sending {} bytes to {:?}", data.len(), &addr); - if addr.is_ipv4() { - // IPv4 not supported on RIOT OS - warn!("(UDP) Is IPv4 -> ignore send!"); - return Ok(()); - } - // tell receiver to release mutex within max. 10ms - self.release_socket_notification.signal(()); - ztimer::Delay.delay_ms(10).await; - let mut sock = self.socket.try_lock().expect("receiver should have ensured that this mutex is free"); - sock.send(self.local_addr, addr, data) - .await - .map_err(|_| Error::new(ErrorCode::StdIoError))?; - // tell receiver sending is finished - drop(sock); - self.socket_released_notification.signal(()); - Ok(()) - } -} - -impl UdpReceive for &UdpSocketWrapper { - async fn recv_from(&mut self, buffer: &mut [u8]) -> Result<(usize, SocketAddr), Error> { - loop { - let mut sock = self.socket.try_lock().expect("sender should have ensured that this mutex is free"); - match select( - self.release_socket_notification.wait(), - sock.receive_into(buffer) - ).await { - Either::First(_) => { - // give up mutex for sender - drop(sock); - // ... and wait until available again - self.socket_released_notification.wait().await; - continue; - } - Either::Second(res) => { - match res { - Ok((bytes_recvd, local_addr, remote_addr)) => { - debug!("(UDP) received {} bytes from {:?} to {:?}", bytes_recvd, &remote_addr, &local_addr); - if remote_addr.is_ipv4() { - warn!("(UDP) Is IPv4 -> ignoring receive data!"); - return Ok((bytes_recvd, remote_addr)); - } - } - Err(_) => { error!("Error during UDP receive!"); } - } - // return receive result - let (bytes_recvd, remote_addr) = res.map(|(bytes_recvd, _, remote_addr)| - (bytes_recvd, remote_addr) - ).map_err(|_| Error::new(ErrorCode::StdIoError))?; - return Ok((bytes_recvd, remote_addr)); - } - } - } - } -} - -pub mod utils { - use super::*; - use core::ffi::c_void; - use log::info; - use riot_sys::inline::gnrc_netapi_set; - use riot_sys::{netopt_t_NETOPT_IPV6_GROUP, size_t}; - use rs_matter::mdns::builtin::MDNS_IPV6_BROADCAST_ADDR; - - pub fn get_ipv6_address(ifc: &Netif) -> Option { - let all_addresses = ifc.ipv6_addrs(); - if all_addresses.is_err() { - return None; - } - - return match all_addresses.unwrap().first() { - Some(a) => { - let ipv6_raw = a.raw(); - Some(Ipv6Addr::new( - ((ipv6_raw[0] as u16) << 8) | ipv6_raw[1] as u16, - ((ipv6_raw[2] as u16) << 8) | ipv6_raw[3] as u16, - ((ipv6_raw[4] as u16) << 8) | ipv6_raw[5] as u16, - ((ipv6_raw[6] as u16) << 8) | ipv6_raw[7] as u16, - ((ipv6_raw[8] as u16) << 8) | ipv6_raw[9] as u16, - ((ipv6_raw[10] as u16) << 8) | ipv6_raw[11] as u16, - ((ipv6_raw[12] as u16) << 8) | ipv6_raw[13] as u16, - ((ipv6_raw[14] as u16) << 8) | ipv6_raw[15] as u16, - )) - }, - None => None, - }; - } - - #[inline(never)] - pub fn initialize_network() -> Result<(Ipv6Addr, u32), MatterError> { - // Get first available interface - let ifc: Netif = Netif::all().next().ok_or(ErrorCode::NoNetworkInterface)?; - - // atm only for debugging: Check name and status of KernelPID - let pid = ifc.pid(); - let ifc_name: &str = pid.get_name().unwrap_or("unknown"); - - // TODO: This should be in riot-wrappers! - unsafe { - let addr = MDNS_IPV6_BROADCAST_ADDR.octets(); - let addr_ptr = addr.as_ptr() as *const c_void; - let _ = gnrc_netapi_set(pid.into(), netopt_t_NETOPT_IPV6_GROUP, 0, addr_ptr, addr.len() as size_t); - } - info!("Joined IPV6 multicast group @ {:?}", MDNS_IPV6_BROADCAST_ADDR); - - // Get available IPv6 link-local address - let ipv6 = get_ipv6_address(&ifc).ok_or(ErrorCode::StdIoError)?; - info!("Found network interface '{}' with IP {}", ifc_name, ipv6); - Ok((ipv6, 0 as _)) - } -} diff --git a/examples/rust-matter-light/src/rgb_led.rs b/examples/rust-matter-light/src/rgb_led.rs deleted file mode 100644 index 1ea9b1a801d6..000000000000 --- a/examples/rust-matter-light/src/rgb_led.rs +++ /dev/null @@ -1,45 +0,0 @@ -use log::info; -use riot_wrappers::saul::{ActuatorClass, Class, Phydat}; -use riot_wrappers::saul::registration::{Drivable, Driver, Error}; - -pub const RGB_PORT: u32 = 0; -pub const RGB_RED_PIN: u32 = 7; -pub const RGB_GREEN_PIN: u32 = 6; -pub const RGB_BLUE_PIN: u32 = 5; - -pub struct RgbLed { - name: &'static str, - portpin_red: (u32, u32), - portpin_green: (u32, u32), - portpin_blue: (u32, u32), -} - -impl RgbLed { - pub fn new(name: &'static str, red: (u32, u32), green: (u32, u32), blue: (u32, u32)) -> Self { - RgbLed { - name, - portpin_red: red, - portpin_green: green, - portpin_blue: blue, - } - } -} - -pub static RGB_LED_DRIVER: Driver = Driver::new(); - -impl Drivable for &RgbLed { - const CLASS: Class = Class::Actuator(Some(ActuatorClass::LedRgb)); - const HAS_READ: bool = true; - const HAS_WRITE: bool = true; - - fn read(self) -> Result { - let value = Phydat::new(&[0,0,0], None, 0); - info!("Reading from RGB LED: {:?}", value); - Ok(value) - } - - fn write(self, data: &Phydat) -> Result { - info!("Writing {:?} to {}", data, self.name); - Ok(1) - } -} \ No newline at end of file diff --git a/examples/rust-matter-light/src/tests.rs b/examples/rust-matter-light/src/tests.rs index 6e94a7a3327f..8987f5bc8103 100644 --- a/examples/rust-matter-light/src/tests.rs +++ b/examples/rust-matter-light/src/tests.rs @@ -7,9 +7,8 @@ use rs_matter::transport::network::{UdpReceive, UdpSend}; use static_cell::StaticCell; use core::str; use riot_wrappers::error::{EAGAIN, NumericError}; -use crate::init_logger; -use crate::network::UdpSocketWrapper; -use crate::network::utils::initialize_network; +use riot_wrappers::matter::{init_logger, UdpSocketWrapper}; +use crate::utils::initialize_network; // Set this as entry point with 'riot_main!' macro to run 'integration tests' fn run_tests() -> ! { diff --git a/examples/rust-matter-light/src/utils.rs b/examples/rust-matter-light/src/utils.rs index d3c92b7bffb9..5e17e6a4859a 100644 --- a/examples/rust-matter-light/src/utils.rs +++ b/examples/rust-matter-light/src/utils.rs @@ -1,9 +1,14 @@ use core::time::Duration; +use embedded_nal_async::Ipv6Addr; use log::{debug, info}; use riot_wrappers::random::Random; use rand_core::RngCore as _; +use riot_wrappers::error::{EAGAIN, NumericError}; +use riot_wrappers::gnrc::Netif; use riot_wrappers::mutex::Mutex; -use rs_matter::utils::epoch::MATTER_EPOCH_SECS; +use rs_matter::error::ErrorCode; +use rs_matter::mdns::builtin::MDNS_IPV6_BROADCAST_ADDR; +use riot_wrappers::gnrc::netapi::join_multicast_v6; // RIOT_EPOCH(2020) in seconds since UNIX Epoch const RIOT_EPOCH_SECS: u64 = 1577833200; @@ -28,14 +33,59 @@ pub fn sys_epoch() -> Duration { let mut duration = CURRENT_DURATION.lock(); let riot_sec = unsafe { get_seconds_since_riot_epoch() } as u64; let riot_msec = unsafe { get_milliseconds() } as u32; - let unix_seconds = RIOT_EPOCH_SECS + riot_sec; - debug!("UNIX epoch (sec.ms): {}.{}", unix_seconds, riot_msec); - let new_duration = Duration::new(unix_seconds, riot_msec*1000000); + let unix_sec = RIOT_EPOCH_SECS + riot_sec; + debug!("UNIX epoch (sec.ms): {}.{}", unix_sec, riot_msec); + let new_duration = Duration::new(unix_sec, riot_msec*1000000); // make sure that we always get a new timestamp in rare cases if sec and msec didn't change if *duration == new_duration { - *duration = Duration::new(unix_seconds, (riot_msec + 1)*1000000); + *duration = Duration::new(unix_sec, (riot_msec + 1)*1000000); } else { *duration = new_duration; } *duration } + +#[inline(never)] +pub fn get_ipv6_address(ifc: &Netif) -> Option { + let all_addresses = ifc.ipv6_addrs(); + if all_addresses.is_err() { + return None; + } + + return match all_addresses.unwrap().first() { + Some(a) => { + let ipv6_raw = a.raw(); + Some(Ipv6Addr::new( + ((ipv6_raw[0] as u16) << 8) | ipv6_raw[1] as u16, + ((ipv6_raw[2] as u16) << 8) | ipv6_raw[3] as u16, + ((ipv6_raw[4] as u16) << 8) | ipv6_raw[5] as u16, + ((ipv6_raw[6] as u16) << 8) | ipv6_raw[7] as u16, + ((ipv6_raw[8] as u16) << 8) | ipv6_raw[9] as u16, + ((ipv6_raw[10] as u16) << 8) | ipv6_raw[11] as u16, + ((ipv6_raw[12] as u16) << 8) | ipv6_raw[13] as u16, + ((ipv6_raw[14] as u16) << 8) | ipv6_raw[15] as u16, + )) + }, + None => None, + }; +} + +#[inline(never)] +pub fn initialize_network() -> Result<(Ipv6Addr, u32), NumericError> { + // Get first available interface + let ifc: Netif = Netif::all().next().ok_or(ErrorCode::NoNetworkInterface) + .map_err(|_| EAGAIN)?; + + // atm only for debugging: Check name and status of KernelPID + let pid = ifc.pid(); + let ifc_name: &str = pid.get_name().unwrap_or("unknown"); + + join_multicast_v6(pid, &MDNS_IPV6_BROADCAST_ADDR.octets()); + info!("Joined IPV6 multicast group @ {:?}", MDNS_IPV6_BROADCAST_ADDR); + + // Get available IPv6 link-local address + let ipv6 = get_ipv6_address(&ifc).ok_or(ErrorCode::StdIoError) + .map_err(|_| EAGAIN)?; + info!("Found network interface '{}' with IP {}", ifc_name, ipv6); + Ok((ipv6, 0 as _)) +} \ No newline at end of file From 6ef71ea3b3dc7b157dc9b80074a28c1a8b5fc820 Mon Sep 17 00:00:00 2001 From: Maik Lorenz Date: Wed, 24 Apr 2024 21:58:29 +0200 Subject: [PATCH 16/19] examples/rust-matter-light: adapt to latest riot-wrappers/matter changes; delete "tests" --- examples/rust-matter-light/src/lib.rs | 9 +-- examples/rust-matter-light/src/tests.rs | 86 ------------------------- examples/rust-matter-light/src/utils.rs | 11 ++-- 3 files changed, 9 insertions(+), 97 deletions(-) delete mode 100644 examples/rust-matter-light/src/tests.rs diff --git a/examples/rust-matter-light/src/lib.rs b/examples/rust-matter-light/src/lib.rs index 0b1259b0f00f..cb843a50223a 100644 --- a/examples/rust-matter-light/src/lib.rs +++ b/examples/rust-matter-light/src/lib.rs @@ -17,9 +17,6 @@ use log::{debug, info, error, LevelFilter, warn}; mod dev_att; #[allow(unused)] mod persist; -// TODO: Enable attribute or feature to be able to run integration tests inside this module under RIOT OS -#[allow(unused)] -mod tests; mod utils; use dev_att::HardCodedDevAtt; @@ -36,7 +33,7 @@ use riot_wrappers::shell::{self, CommandList}; use riot_wrappers::saul::{ActuatorClass, Class, Phydat, RegistryEntry}; // the new 'matter' module in riot-wrappers, enabled by 'with_matter' feature -use riot_wrappers::matter::{init_logger, UdpSocketWrapper}; +use riot_wrappers::matter::{init_logger, MatterCompatUdpSocket}; use rs_matter::{CommissioningData, MATTER_PORT}; use rs_matter::transport::network::UdpBuffers; @@ -301,7 +298,7 @@ async fn mdns_task(mdns: &'static MdnsService<'_>) { .bind_single(MDNS_SOCKET_BIND_ADDR) .await .expect("Can't create a socket"); - let socket = UdpSocketWrapper::new(mdns_addr, mdns_sock); + let socket = MatterCompatUdpSocket::new(mdns_addr, mdns_sock); debug!("Created UDP socket for mDNS at {:?}", &mdns_addr); // Finally run the MDNS service @@ -332,7 +329,7 @@ async fn matter_task(matter: &'static Matter<'_>) { .bind_single(MATTER_SOCKET_BIND_ADDR) .await .expect("Can't create a socket"); - let socket = UdpSocketWrapper::new(matter_addr, matter_sock); + let socket = MatterCompatUdpSocket::new(matter_addr, matter_sock); debug!("Created UDP socket for Matter at {:?}", &matter_addr); let handler = HandlerCompat(matter_handler(&matter)); diff --git a/examples/rust-matter-light/src/tests.rs b/examples/rust-matter-light/src/tests.rs deleted file mode 100644 index 8987f5bc8103..000000000000 --- a/examples/rust-matter-light/src/tests.rs +++ /dev/null @@ -1,86 +0,0 @@ -use embedded_nal_async::{SocketAddr, UdpStack, UnconnectedUdp}; -use log::{debug, error, info, LevelFilter}; -use riot_wrappers::socket_embedded_nal_async_udp::UnconnectedUdpSocket; -use rs_matter::error::Error; -use rs_matter::transport::core::MATTER_SOCKET_BIND_ADDR; -use rs_matter::transport::network::{UdpReceive, UdpSend}; -use static_cell::StaticCell; -use core::str; -use riot_wrappers::error::{EAGAIN, NumericError}; -use riot_wrappers::matter::{init_logger, UdpSocketWrapper}; -use crate::utils::initialize_network; - -// Set this as entry point with 'riot_main!' macro to run 'integration tests' -fn run_tests() -> ! { - init_logger(LevelFilter::Debug).expect("Error initializing logger"); - static EXECUTOR: StaticCell = StaticCell::new(); - let executor: &'static mut _ = EXECUTOR.init(embassy_executor_riot::Executor::new()); - executor.run(|spawner| { - spawner.spawn(test_udp()).unwrap(); - }); -} - -async fn udp_send(mut send: S, data: &mut [u8], remote_addr: SocketAddr) -> Result<(), NumericError> - where S: UdpSend { - //let mut buffer: &mut [u8] = &mut [0u8; 255usize]; - return match send.send_to(data, remote_addr).await { - Ok(_) => { - info!("Sent echo!"); - Ok(()) - } - Err(_) => { - error!("Error sending echo!"); - Err(EAGAIN) - } - } -} - -async fn udp_receive(mut recv: R) -> Result<(SocketAddr, [u8; 255], usize), NumericError> - where R: UdpReceive -{ - let mut buffer: [u8; 255] = [0u8; 255usize]; - return match recv.recv_from(&mut buffer).await { - Ok((bytes_recvd, remote_addr)) => { - info!("{} bytes received from {:?}", bytes_recvd, remote_addr); - let as_str = str::from_utf8(&buffer).unwrap().trim_matches('\0'); - debug!("Received data: {:?}", as_str); - debug!("as bytes: {:?}", &buffer[..bytes_recvd]); - Ok((remote_addr, buffer, bytes_recvd)) - } - Err(err) => { - error!("Error during receive: {:?}", err); - Err(EAGAIN) - } - } -} - -#[embassy_executor::task] -async fn test_udp() { - let (ipv6_addr, interface) = initialize_network().expect("Error getting network interface and IP addresses"); - - static UDP_MDNS_SOCKET: StaticCell = StaticCell::new(); - let udp_stack = riot_wrappers::socket_embedded_nal_async_udp::UdpStack::new(|| UDP_MDNS_SOCKET.try_uninit()); - let (addr, mut sock) = udp_stack - .bind_single(MATTER_SOCKET_BIND_ADDR) - .await - .expect("Can't create a socket"); - let mut socket = &UdpSocketWrapper::new(addr, sock); - info!("Listening on [{:?}]:5540", &ipv6_addr); - - let mut buffer: [u8; 255] =[0u8; 255usize]; - loop { - info!("Waiting for incoming packets..."); - match udp_receive(socket).await { - Ok((remote_addr, mut data, len)) => { - info!("{} bytes received from {:?}", len, remote_addr); - let as_str = str::from_utf8(&data).unwrap().trim_matches('\0'); - debug!("Received data: {:?}", as_str); - debug!("as bytes: {:?}", &data[..len]); - udp_send(socket, &mut data[..len], remote_addr).await.expect("error sending response"); - } - Err(err) => { - error!("Error during receive: {:?}", err); - } - } - } -} \ No newline at end of file diff --git a/examples/rust-matter-light/src/utils.rs b/examples/rust-matter-light/src/utils.rs index 5e17e6a4859a..2b42a040d531 100644 --- a/examples/rust-matter-light/src/utils.rs +++ b/examples/rust-matter-light/src/utils.rs @@ -47,12 +47,13 @@ pub fn sys_epoch() -> Duration { #[inline(never)] pub fn get_ipv6_address(ifc: &Netif) -> Option { - let all_addresses = ifc.ipv6_addrs(); - if all_addresses.is_err() { - return None; - } + let all_addresses = ifc.ipv6_addrs().ok()?; + info!("Found {} addresses", all_addresses.len()); - return match all_addresses.unwrap().first() { + // TODO: Find a suitable IPv6 address for Matter communication + // this address will be sent with DNS-SD Reponses + let idx = if all_addresses.len() >= 2 { 1 } else { 0 }; + return match all_addresses.get(idx) { Some(a) => { let ipv6_raw = a.raw(); Some(Ipv6Addr::new( From 0c1d6d6d81772340acb4457ea4c1cb6dbf9f06c2 Mon Sep 17 00:00:00 2001 From: Maik Lorenz Date: Sun, 28 Apr 2024 16:59:53 +0200 Subject: [PATCH 17/19] examples/rust-matter-light: setup logger in lib.rs; Move PersistenceManager impl. to riot-wrappers; add files for commissioning and dev_att data to constfs filesystem --- examples/rust-matter-light/Cargo.lock | 26 +-- examples/rust-matter-light/Cargo.toml | 8 +- examples/rust-matter-light/Makefile | 2 + examples/rust-matter-light/data.c | 213 ++++++++++++++++++++++ examples/rust-matter-light/src/lib.rs | 50 ++++- examples/rust-matter-light/src/persist.rs | 46 ----- examples/rust-matter-light/src/utils.rs | 24 +-- 7 files changed, 283 insertions(+), 86 deletions(-) create mode 100644 examples/rust-matter-light/data.c delete mode 100644 examples/rust-matter-light/src/persist.rs diff --git a/examples/rust-matter-light/Cargo.lock b/examples/rust-matter-light/Cargo.lock index e74b4d02fa35..de3c0ed9ccd4 100644 --- a/examples/rust-matter-light/Cargo.lock +++ b/examples/rust-matter-light/Cargo.lock @@ -1155,9 +1155,9 @@ checksum = "b4ce301924b7887e9d637144fdade93f9dfff9b60981d4ac161db09720d39aa5" [[package]] name = "lock_api" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -1616,7 +1616,7 @@ dependencies = [ [[package]] name = "riot-wrappers" version = "0.8.3" -source = "git+https://github.com/maikerlab/rust-riot-wrappers.git?branch=with_matter#093983d50e9f76be8e810d2f9820761498d00e8e" +source = "git+https://github.com/maikerlab/rust-riot-wrappers?branch=with_matter#fe1aa078ba72709330e2486c80f54f2b6e9ad19d" dependencies = [ "bare-metal", "coap-handler 0.1.6", @@ -1639,9 +1639,9 @@ dependencies = [ "embedded-nal-async 0.7.1", "heapless 0.7.17", "hex", - "log", "mutex-trait", "nb 0.1.3", + "no-std-net", "num-traits", "pin-project", "pin-utils", @@ -1785,7 +1785,7 @@ dependencies = [ "log", "rand_core", "riot-sys", - "riot-wrappers 0.8.3 (git+https://github.com/maikerlab/rust-riot-wrappers.git?branch=with_matter)", + "riot-wrappers 0.8.3 (git+https://github.com/maikerlab/rust-riot-wrappers?branch=with_matter)", "rs-matter", "rust_riotmodules", "static_cell", @@ -1874,9 +1874,9 @@ checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" [[package]] name = "serde" -version = "1.0.198" +version = "1.0.199" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" +checksum = "0c9f6e76df036c77cd94996771fb40db98187f096dd0b9af39c6c6e452ba966a" dependencies = [ "serde_derive", ] @@ -1893,9 +1893,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.198" +version = "1.0.199" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" +checksum = "11bd257a6541e141e42ca6d24ae26f7714887b47e89aa739099104c7e4d3b7fc" dependencies = [ "proc-macro2", "quote", @@ -1994,9 +1994,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "static_cell" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa6ba4cf83bf80d3eb25f098ea5e790a0a1fcb5e357442259b231e412c2d3ca0" +checksum = "d89b0684884a883431282db1e4343f34afc2ff6996fe1f4a1664519b66e14c1e" dependencies = [ "portable-atomic", ] @@ -2283,9 +2283,9 @@ checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" [[package]] name = "unicode-width" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" +checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6" [[package]] name = "utf8parse" diff --git a/examples/rust-matter-light/Cargo.toml b/examples/rust-matter-light/Cargo.toml index cda7a97f738e..04d3e481a2eb 100644 --- a/examples/rust-matter-light/Cargo.toml +++ b/examples/rust-matter-light/Cargo.toml @@ -28,8 +28,8 @@ debug = true opt-level = 3 [dependencies] -#riot-wrappers = { git = "https://github.com/RIOT-OS/rust-riot-wrappers.git", features = [ "set_panic_handler", "panic_handler_format", "panic_handler_crash", "with_embedded_nal_async", "provide_critical_section_1_0", "with_embedded_hal_async" ] } -riot-wrappers = { git = "https://github.com/maikerlab/rust-riot-wrappers.git", branch = "with_matter", features = [ "set_panic_handler", "panic_handler_format", "panic_handler_crash", "with_embedded_nal_async", "provide_critical_section_1_0", "with_embedded_hal_async", "with_matter" ] } +riot-wrappers = { git = "https://github.com/maikerlab/rust-riot-wrappers", branch = "with_matter", features = [ "set_panic_handler", "panic_handler_format", "panic_handler_crash", "with_embedded_nal_async", "provide_critical_section_1_0", "with_embedded_hal_async", "with_matter" ] } +rs-matter = { git = "https://github.com/maikerlab/rs-matter", branch = "feature/RIOT_OS", default-features = false, features = ["riot-os"] } riot-sys = "*" embedded-nal-async = "0.7.1" embedded-hal-async = { version = "1.0.0"} @@ -48,10 +48,8 @@ embassy-executor-riot = { git = "https://gitlab.com/etonomy/riot-module-examples embassy-executor = { version = "0.5", features = ["nightly"] } embedded-hal = "1.0.0" embassy-futures = "0.1.1" -rs-matter = { version = "0.1.0", default-features = false, features = ["riot-os"] } rand_core = "0.6.4" [patch.crates-io] +#riot-wrappers = { path = "../../../rust-riot-wrappers" } #rs-matter = { path = "../../../rs-matter/rs-matter" } -rs-matter = { git = "https://github.com/maikerlab/rs-matter", branch = "feature/RIOT_OS" } -riot-wrappers = { path = "../../../rust-riot-wrappers" } diff --git a/examples/rust-matter-light/Makefile b/examples/rust-matter-light/Makefile index 2e40565136d2..233b31bd9b12 100644 --- a/examples/rust-matter-light/Makefile +++ b/examples/rust-matter-light/Makefile @@ -50,6 +50,8 @@ USEMODULE += ps USEMODULE += random USEMODULE += periph_hwrng USEMODULE += prng_sha256prng +USEMODULE += vfs_default +USEMODULE += constfs # networking USEMODULE += netdev_default diff --git a/examples/rust-matter-light/data.c b/examples/rust-matter-light/data.c new file mode 100644 index 000000000000..85e4f5b2ed0c --- /dev/null +++ b/examples/rust-matter-light/data.c @@ -0,0 +1,213 @@ +#include "fs/constfs.h" +#include +#include + +// TODO: Implement a way to safely provision files to constfs during build (for +// now dev_att example for On/Off Light is used) +const uint32_t MATTER_PASSCODE = 123456; +const uint16_t MATTER_DISCRIMINATOR = 250; + +// PAI Cert. (463 bytes) +const uint8_t MATTER_PAI[] = { + 0x30, 0x82, 0x01, 0xcb, 0x30, 0x82, 0x01, 0x71, 0xa0, 0x03, 0x02, 0x01, + 0x02, 0x02, 0x08, 0x56, 0xad, 0x82, 0x22, 0xad, 0x94, 0x5b, 0x64, 0x30, + 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x30, + 0x30, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, + 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, + 0x50, 0x41, 0x41, 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, + 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x02, 0x01, 0x0c, 0x04, 0x46, 0x46, 0x46, + 0x31, 0x30, 0x20, 0x17, 0x0d, 0x32, 0x32, 0x30, 0x32, 0x30, 0x35, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x5a, 0x18, 0x0f, 0x39, 0x39, 0x39, 0x39, + 0x31, 0x32, 0x33, 0x31, 0x32, 0x33, 0x35, 0x39, 0x35, 0x39, 0x5a, 0x30, + 0x3d, 0x31, 0x25, 0x30, 0x23, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x1c, + 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, 0x44, 0x65, 0x76, 0x20, 0x50, + 0x41, 0x49, 0x20, 0x30, 0x78, 0x46, 0x46, 0x46, 0x31, 0x20, 0x6e, 0x6f, + 0x20, 0x50, 0x49, 0x44, 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, + 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x02, 0x01, 0x0c, 0x04, 0x46, 0x46, + 0x46, 0x31, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, + 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, + 0x07, 0x03, 0x42, 0x00, 0x04, 0x41, 0x9a, 0x93, 0x15, 0xc2, 0x17, 0x3e, + 0x0c, 0x8c, 0x87, 0x6d, 0x03, 0xcc, 0xfc, 0x94, 0x48, 0x52, 0x64, 0x7f, + 0x7f, 0xec, 0x5e, 0x50, 0x82, 0xf4, 0x05, 0x99, 0x28, 0xec, 0xa8, 0x94, + 0xc5, 0x94, 0x15, 0x13, 0x09, 0xac, 0x63, 0x1e, 0x4c, 0xb0, 0x33, 0x92, + 0xaf, 0x68, 0x4b, 0x0b, 0xaf, 0xb7, 0xe6, 0x5b, 0x3b, 0x81, 0x62, 0xc2, + 0xf5, 0x2b, 0xf9, 0x31, 0xb8, 0xe7, 0x7a, 0xaa, 0x82, 0xa3, 0x66, 0x30, + 0x64, 0x30, 0x12, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, + 0x08, 0x30, 0x06, 0x01, 0x01, 0xff, 0x02, 0x01, 0x00, 0x30, 0x0e, 0x06, + 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x01, + 0x06, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, + 0x63, 0x54, 0x0e, 0x47, 0xf6, 0x4b, 0x1c, 0x38, 0xd1, 0x38, 0x84, 0xa4, + 0x62, 0xd1, 0x6c, 0x19, 0x5d, 0x8f, 0xfb, 0x3c, 0x30, 0x1f, 0x06, 0x03, + 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x6a, 0xfd, 0x22, + 0x77, 0x1f, 0x51, 0x1f, 0xec, 0xbf, 0x16, 0x41, 0x97, 0x67, 0x10, 0xdc, + 0xdc, 0x31, 0xa1, 0x71, 0x7e, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, + 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x48, 0x00, 0x30, 0x45, 0x02, 0x21, + 0x00, 0xb2, 0xef, 0x27, 0xf4, 0x9a, 0xe9, 0xb5, 0x0f, 0xb9, 0x1e, 0xea, + 0xc9, 0x4c, 0x4d, 0x0b, 0xdb, 0xb8, 0xd7, 0x92, 0x9c, 0x6c, 0xb8, 0x8f, + 0xac, 0xe5, 0x29, 0x36, 0x8d, 0x12, 0x05, 0x4c, 0x0c, 0x02, 0x20, 0x65, + 0x5d, 0xc9, 0x2b, 0x86, 0xbd, 0x90, 0x98, 0x82, 0xa6, 0xc6, 0x21, 0x77, + 0xb8, 0x25, 0xd7, 0xd0, 0x5e, 0xdb, 0xe7, 0xc2, 0x2f, 0x9f, 0xea, 0x71, + 0x22, 0x0e, 0x7e, 0xa7, 0x03, 0xf8, 0x91}; + +// DAC Cert (492 bytes) +const uint8_t MATTER_DAC[] = { + 0x30, 0x82, 0x01, 0xe8, 0x30, 0x82, 0x01, 0x8e, 0xa0, 0x03, 0x02, 0x01, + 0x02, 0x02, 0x08, 0x52, 0x72, 0x4d, 0x21, 0xe2, 0xc1, 0x74, 0xaf, 0x30, + 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x30, + 0x3d, 0x31, 0x25, 0x30, 0x23, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x1c, + 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, 0x44, 0x65, 0x76, 0x20, 0x50, + 0x41, 0x49, 0x20, 0x30, 0x78, 0x46, 0x46, 0x46, 0x31, 0x20, 0x6e, 0x6f, + 0x20, 0x50, 0x49, 0x44, 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, + 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x02, 0x01, 0x0c, 0x04, 0x46, 0x46, + 0x46, 0x31, 0x30, 0x20, 0x17, 0x0d, 0x32, 0x32, 0x30, 0x32, 0x30, 0x35, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x5a, 0x18, 0x0f, 0x39, 0x39, 0x39, + 0x39, 0x31, 0x32, 0x33, 0x31, 0x32, 0x33, 0x35, 0x39, 0x35, 0x39, 0x5a, + 0x30, 0x53, 0x31, 0x25, 0x30, 0x23, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, + 0x1c, 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, 0x44, 0x65, 0x76, 0x20, + 0x44, 0x41, 0x43, 0x20, 0x30, 0x78, 0x46, 0x46, 0x46, 0x31, 0x2f, 0x30, + 0x78, 0x38, 0x30, 0x30, 0x32, 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, + 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x02, 0x01, 0x0c, 0x04, 0x46, + 0x46, 0x46, 0x31, 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, + 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x02, 0x02, 0x0c, 0x04, 0x38, 0x30, 0x30, + 0x32, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, + 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, + 0x03, 0x42, 0x00, 0x04, 0xda, 0x93, 0xf1, 0x67, 0x36, 0x25, 0x67, 0x50, + 0xd9, 0x03, 0xb0, 0x34, 0xba, 0x45, 0x88, 0xab, 0xaf, 0x58, 0x95, 0x4f, + 0x77, 0xaa, 0x9f, 0xd9, 0x98, 0x9d, 0xfd, 0x40, 0x0d, 0x7a, 0xb3, 0xfd, + 0xc9, 0x75, 0x3b, 0x3b, 0x92, 0x1b, 0x29, 0x4c, 0x95, 0x0f, 0xd9, 0xd2, + 0x80, 0xd1, 0x4c, 0x43, 0x86, 0x2f, 0x16, 0xdc, 0x85, 0x4b, 0x00, 0xed, + 0x39, 0xe7, 0x50, 0xba, 0xbf, 0x1d, 0xc4, 0xca, 0xa3, 0x60, 0x30, 0x5e, + 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x02, + 0x30, 0x00, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, + 0x04, 0x04, 0x03, 0x02, 0x07, 0x80, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, + 0x0e, 0x04, 0x16, 0x04, 0x14, 0xef, 0x06, 0x56, 0x11, 0x9c, 0x1c, 0x91, + 0xa7, 0x9a, 0x94, 0xe6, 0xdc, 0xf3, 0x79, 0x79, 0xdb, 0xd0, 0x7f, 0xf8, + 0xa3, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, + 0x80, 0x14, 0x63, 0x54, 0x0e, 0x47, 0xf6, 0x4b, 0x1c, 0x38, 0xd1, 0x38, + 0x84, 0xa4, 0x62, 0xd1, 0x6c, 0x19, 0x5d, 0x8f, 0xfb, 0x3c, 0x30, 0x0a, + 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x48, + 0x00, 0x30, 0x45, 0x02, 0x20, 0x46, 0x86, 0x81, 0x07, 0x33, 0xbf, 0x0d, + 0xc8, 0xff, 0x4c, 0xb5, 0x14, 0x5a, 0x6b, 0xfa, 0x1a, 0xec, 0xff, 0xa8, + 0xb6, 0xda, 0xb6, 0xc3, 0x51, 0xaa, 0xee, 0xcd, 0xaf, 0xb8, 0xbe, 0x95, + 0x7d, 0x02, 0x21, 0x00, 0xe8, 0xc2, 0x8d, 0x6b, 0xfc, 0xc8, 0x7a, 0x7d, + 0x54, 0x2e, 0xad, 0x6e, 0xda, 0xca, 0x14, 0x8d, 0x5f, 0xa5, 0x06, 0x1e, + 0x51, 0x7c, 0xbe, 0x4f, 0x24, 0xa7, 0x20, 0xe1, 0xc0, 0x59, 0xde, 0x1a}; + +// DAC Public Key (65 bytes) +const uint8_t MATTER_DAC_PUBKEY[] = { + 0x04, 0xda, 0x93, 0xf1, 0x67, 0x36, 0x25, 0x67, 0x50, 0xd9, 0x03, + 0xb0, 0x34, 0xba, 0x45, 0x88, 0xab, 0xaf, 0x58, 0x95, 0x4f, 0x77, + 0xaa, 0x9f, 0xd9, 0x98, 0x9d, 0xfd, 0x40, 0x0d, 0x7a, 0xb3, 0xfd, + 0xc9, 0x75, 0x3b, 0x3b, 0x92, 0x1b, 0x29, 0x4c, 0x95, 0x0f, 0xd9, + 0xd2, 0x80, 0xd1, 0x4c, 0x43, 0x86, 0x2f, 0x16, 0xdc, 0x85, 0x4b, + 0x00, 0xed, 0x39, 0xe7, 0x50, 0xba, 0xbf, 0x1d, 0xc4, 0xca, +}; + +// DAC Private Key (32 bytes) +const uint8_t MATTER_DAC_PRIVKEY[] = { + 0xda, 0xf2, 0x1a, 0x7e, 0xa4, 0x7a, 0x70, 0x48, 0x02, 0xa7, 0xe6, + 0x6c, 0x50, 0xeb, 0x10, 0xba, 0xc3, 0xbd, 0xd1, 0x68, 0x80, 0x39, + 0x80, 0x66, 0xff, 0xda, 0xd7, 0xf5, 0x20, 0x98, 0xb6, 0x85, +}; + +// Certificate Declaration (541 bytes) +const uint8_t MATTER_CD[] = + { + 0x30, 0x82, 0x02, 0x19, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, + 0x01, 0x07, 0x02, 0xa0, 0x82, 0x02, 0x0a, 0x30, 0x82, 0x02, 0x06, 0x02, + 0x01, 0x03, 0x31, 0x0d, 0x30, 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, + 0x65, 0x03, 0x04, 0x02, 0x01, 0x30, 0x82, 0x01, 0x71, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0xa0, 0x82, 0x01, 0x62, + 0x04, 0x82, 0x01, 0x5e, 0x15, 0x24, 0x00, 0x01, 0x25, 0x01, 0xf1, 0xff, + 0x36, 0x02, 0x05, 0x00, 0x80, 0x05, 0x01, 0x80, 0x05, 0x02, 0x80, 0x05, + 0x03, 0x80, 0x05, 0x04, 0x80, 0x05, 0x05, 0x80, 0x05, 0x06, 0x80, 0x05, + 0x07, 0x80, 0x05, 0x08, 0x80, 0x05, 0x09, 0x80, 0x05, 0x0a, 0x80, 0x05, + 0x0b, 0x80, 0x05, 0x0c, 0x80, 0x05, 0x0d, 0x80, 0x05, 0x0e, 0x80, 0x05, + 0x0f, 0x80, 0x05, 0x10, 0x80, 0x05, 0x11, 0x80, 0x05, 0x12, 0x80, 0x05, + 0x13, 0x80, 0x05, 0x14, 0x80, 0x05, 0x15, 0x80, 0x05, 0x16, 0x80, 0x05, + 0x17, 0x80, 0x05, 0x18, 0x80, 0x05, 0x19, 0x80, 0x05, 0x1a, 0x80, 0x05, + 0x1b, 0x80, 0x05, 0x1c, 0x80, 0x05, 0x1d, 0x80, 0x05, 0x1e, 0x80, 0x05, + 0x1f, 0x80, 0x05, 0x20, 0x80, 0x05, 0x21, 0x80, 0x05, 0x22, 0x80, 0x05, + 0x23, 0x80, 0x05, 0x24, 0x80, 0x05, 0x25, 0x80, 0x05, 0x26, 0x80, 0x05, + 0x27, 0x80, 0x05, 0x28, 0x80, 0x05, 0x29, 0x80, 0x05, 0x2a, 0x80, 0x05, + 0x2b, 0x80, 0x05, 0x2c, 0x80, 0x05, 0x2d, 0x80, 0x05, 0x2e, 0x80, 0x05, + 0x2f, 0x80, 0x05, 0x30, 0x80, 0x05, 0x31, 0x80, 0x05, 0x32, 0x80, 0x05, + 0x33, 0x80, 0x05, 0x34, 0x80, 0x05, 0x35, 0x80, 0x05, 0x36, 0x80, 0x05, + 0x37, 0x80, 0x05, 0x38, 0x80, 0x05, 0x39, 0x80, 0x05, 0x3a, 0x80, 0x05, + 0x3b, 0x80, 0x05, 0x3c, 0x80, 0x05, 0x3d, 0x80, 0x05, 0x3e, 0x80, 0x05, + 0x3f, 0x80, 0x05, 0x40, 0x80, 0x05, 0x41, 0x80, 0x05, 0x42, 0x80, 0x05, + 0x43, 0x80, 0x05, 0x44, 0x80, 0x05, 0x45, 0x80, 0x05, 0x46, 0x80, 0x05, + 0x47, 0x80, 0x05, 0x48, 0x80, 0x05, 0x49, 0x80, 0x05, 0x4a, 0x80, 0x05, + 0x4b, 0x80, 0x05, 0x4c, 0x80, 0x05, 0x4d, 0x80, 0x05, 0x4e, 0x80, 0x05, + 0x4f, 0x80, 0x05, 0x50, 0x80, 0x05, 0x51, 0x80, 0x05, 0x52, 0x80, 0x05, + 0x53, 0x80, 0x05, 0x54, 0x80, 0x05, 0x55, 0x80, 0x05, 0x56, 0x80, 0x05, + 0x57, 0x80, 0x05, 0x58, 0x80, 0x05, 0x59, 0x80, 0x05, 0x5a, 0x80, 0x05, + 0x5b, 0x80, 0x05, 0x5c, 0x80, 0x05, 0x5d, 0x80, 0x05, 0x5e, 0x80, 0x05, + 0x5f, 0x80, 0x05, 0x60, 0x80, 0x05, 0x61, 0x80, 0x05, 0x62, 0x80, 0x05, + 0x63, 0x80, 0x18, 0x24, 0x03, 0x16, 0x2c, 0x04, 0x13, 0x5a, 0x49, 0x47, + 0x32, 0x30, 0x31, 0x34, 0x32, 0x5a, 0x42, 0x33, 0x33, 0x30, 0x30, 0x30, + 0x33, 0x2d, 0x32, 0x34, 0x24, 0x05, 0x00, 0x24, 0x06, 0x00, 0x25, 0x07, + 0x94, 0x26, 0x24, 0x08, 0x00, 0x18, 0x31, 0x7d, 0x30, 0x7b, 0x02, 0x01, + 0x03, 0x80, 0x14, 0x62, 0xfa, 0x82, 0x33, 0x59, 0xac, 0xfa, 0xa9, 0x96, + 0x3e, 0x1c, 0xfa, 0x14, 0x0a, 0xdd, 0xf5, 0x04, 0xf3, 0x71, 0x60, 0x30, + 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, + 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, + 0x04, 0x47, 0x30, 0x45, 0x02, 0x20, 0x24, 0xe5, 0xd1, 0xf4, 0x7a, 0x7d, + 0x7b, 0x0d, 0x20, 0x6a, 0x26, 0xef, 0x69, 0x9b, 0x7c, 0x97, 0x57, 0xb7, + 0x2d, 0x46, 0x90, 0x89, 0xde, 0x31, 0x92, 0xe6, 0x78, 0xc7, 0x45, 0xe7, + 0xf6, 0x0c, 0x02, 0x21, 0x00, 0xf8, 0xaa, 0x2f, 0xa7, 0x11, 0xfc, 0xb7, + 0x9b, 0x97, 0xe3, 0x97, 0xce, 0xda, 0x66, 0x7b, 0xae, 0x46, 0x4e, 0x2b, + 0xd3, 0xff, 0xdf, 0xc3, 0xcc, 0xed, 0x7a, 0xa8, 0xca, 0x5f, 0x4c, 0x1a, + 0x7c, +}; + +// Files needed for Commissioning and Device Attestation +static constfs_file_t constfs_files[] = { + { + .path = "/passcode", + .size = sizeof(MATTER_PASSCODE), + .data = (const uint8_t *)&MATTER_PASSCODE, + }, + { + .path = "/discriminator", + .size = sizeof(MATTER_DISCRIMINATOR), + .data = (const uint8_t *)&MATTER_DISCRIMINATOR, + }, + { + .path = "/pai", + .size = sizeof(MATTER_PAI), + .data = (const uint8_t *)MATTER_PAI, + }, + { + .path = "/dac", + .size = sizeof(MATTER_DAC), + .data = (const uint8_t *)MATTER_DAC, + }, + { + .path = "/dac_pubkey", + .size = sizeof(MATTER_DAC_PUBKEY), + .data = (const uint8_t *)MATTER_DAC_PUBKEY, + }, + { + .path = "/dac_privkey", + .size = sizeof(MATTER_DAC_PRIVKEY), + .data = (const uint8_t *)MATTER_DAC_PRIVKEY, + }, + { + .path = "/cd", + .size = sizeof(MATTER_CD), + .data = (const uint8_t *)MATTER_CD, + }}; + +static constfs_t constfs_desc = { + .nfiles = ARRAY_SIZE(constfs_files), + .files = constfs_files, +}; + +static vfs_mount_t const_mount = { + .fs = &constfs_file_system, + .mount_point = "/const", + .private_data = &constfs_desc, +}; + +int init_constfs(void) { return vfs_mount(&const_mount); } diff --git a/examples/rust-matter-light/src/lib.rs b/examples/rust-matter-light/src/lib.rs index cb843a50223a..24112aca4924 100644 --- a/examples/rust-matter-light/src/lib.rs +++ b/examples/rust-matter-light/src/lib.rs @@ -12,11 +12,9 @@ use static_cell::StaticCell; use embedded_nal_async::{Ipv4Addr, UdpStack as _}; use embedded_alloc::Heap; use embedded_hal::delay::DelayNs as _; -use log::{debug, info, error, LevelFilter, warn}; +use log::{debug, info, error, LevelFilter, warn, Log, Level, Record, SetLoggerError}; mod dev_att; -#[allow(unused)] -mod persist; mod utils; use dev_att::HardCodedDevAtt; @@ -24,7 +22,9 @@ use utils::initialize_network; // RIOT OS modules extern crate rust_riotmodules; -use riot_wrappers::{riot_main, static_command}; +extern crate alloc; + +use riot_wrappers::{println, riot_main, static_command}; use riot_wrappers::ztimer; use riot_wrappers::thread; use riot_wrappers::mutex::Mutex; @@ -33,7 +33,7 @@ use riot_wrappers::shell::{self, CommandList}; use riot_wrappers::saul::{ActuatorClass, Class, Phydat, RegistryEntry}; // the new 'matter' module in riot-wrappers, enabled by 'with_matter' feature -use riot_wrappers::matter::{init_logger, MatterCompatUdpSocket}; +use riot_wrappers::matter::{VfsDataFetcher, CommissioningDataFetcher, PersistenceManager, MatterCompatUdpSocket}; use rs_matter::{CommissioningData, MATTER_PORT}; use rs_matter::transport::network::UdpBuffers; @@ -48,6 +48,7 @@ use rs_matter::data_model::{ system_model::descriptor, }; use rs_matter::data_model::cluster_on_off::{Commands, OnOffCluster}; +use rs_matter::data_model::sdm::dev_att::{DataType, DevAttDataFetcher}; use rs_matter::error::Error; use rs_matter::mdns::MdnsService; use rs_matter::mdns::builtin::MDNS_SOCKET_BIND_ADDR; @@ -55,6 +56,27 @@ use rs_matter::secure_channel::spake2p::VerifierData; use rs_matter::tlv::TLVElement; use rs_matter::transport::exchange::Exchange; +struct RiotLogger; +static LOGGER: RiotLogger = RiotLogger; +impl Log for RiotLogger { + fn enabled(&self, metadata: &log::Metadata) -> bool { + metadata.level() >= Level::Info + } + + fn log(&self, record: &Record) { + if self.enabled(record.metadata()) { + println!("[{}] {}", record.level(), record.args()); + } + } + + fn flush(&self) {} +} + +pub fn init_logger(level: LevelFilter) -> Result<(), SetLoggerError> { + log::set_logger(&LOGGER) + .map(|_| log::set_max_level(level)) +} + // Node object with endpoints supporting device type 'On/Off Light' const NODE: Node<'static> = Node { id: 0, @@ -153,6 +175,9 @@ static MDNS: StaticCell = StaticCell::new(); static DEV_ATT: StaticCell = StaticCell::new(); static MATTER: StaticCell = StaticCell::new(); +// TODO: Instantiate `VfsDataFetcher` if fully implemented in riot-wrappers +// static FW_DATA: VfsDataFetcher = VfsDataFetcher; + // Set this to the name of the LED, which should be controlled using SAUL registry const ONOFF_LED_NAME: &str = "LD2(blue)"; @@ -204,12 +229,11 @@ fn run_matter() -> Result<(), ()> { MATTER_PORT, )); - // Get Device attestation (hard-coded atm) + // Get Device attestation (hard-coded atm) - TODO: Use VfsDataFetcher if implemented in riot-wrappers let dev_att: &'static HardCodedDevAtt = DEV_ATT.init(HardCodedDevAtt::new()); - // TODO: Provide own epoch and rand functions let epoch = utils::sys_epoch; - let rand = utils::sys_rand; + let rand = riot_wrappers::matter::sys_rand; let matter: &'static Matter = MATTER.init(Matter::new( // vid/pid should match those in the DAC @@ -248,6 +272,8 @@ fn main() { info!("Hello Matter on RIOT!"); + let _ = utils::init_vfs(); + use core::mem::size_of; info!("Matter memory usage: UdpBuffers={}, PacketBuffers={}, \ MdnsService={}, Matter={}", @@ -337,6 +363,9 @@ async fn matter_task(matter: &'static Matter<'_>) { let mut matter_udp_buffers = UdpBuffers::new(); let mut matter_packet_buffers = PacketBuffers::new(); + // TODO: Read commissioning data from VFS if implemented in riot-wrappers + //let (discriminator, passcode) = FW_DATA.read_commissioning_data().expect("error while reading commissioning data"); + // Finally create the Matter service and run on port 5540/UDP let matter_runner = pin!(matter.run( &socket, @@ -366,8 +395,9 @@ async fn matter_task(matter: &'static Matter<'_>) { #[embassy_executor::task] async fn psm_task(matter: &'static Matter<'_>) { info!("Starting Persistence Manager...."); - // TODO: Develop own 'Persistence Manager' using RIOT OS modules - let mut psm = persist::Psm::new(&matter).expect("Error creating PSM"); + // TODO: 'PersistenceManager' is not implemented yet in riot-wrappers + let mut psm = PersistenceManager::new(&matter) + .expect("Error creating PSM"); let psm_runner = pin!(psm.run()); match psm_runner.await { Ok(_) => { diff --git a/examples/rust-matter-light/src/persist.rs b/examples/rust-matter-light/src/persist.rs deleted file mode 100644 index ac98270c74de..000000000000 --- a/examples/rust-matter-light/src/persist.rs +++ /dev/null @@ -1,46 +0,0 @@ -use log::debug; -use rs_matter::error::Error; -use rs_matter::core::Matter; - -pub struct Psm<'a> { - matter: &'a Matter<'a>, - buf: [u8; 4096], - dir: &'a str, -} - -impl<'a> Psm<'a> { - #[inline(always)] - pub fn new(matter: &'a Matter<'a>) -> Result { - let mut buf = [0; 4096]; - Ok(Self { matter, buf, dir: "data" }) - } - - pub async fn run(&mut self) -> Result<(), Error> { - debug!("PersistenceManager running..."); - loop { - self.matter.wait_changed().await; - - if self.matter.is_changed() { - if let Some(data) = self.matter.store_acls(&mut self.buf)? { - debug!("Store ACL data..."); - Self::store("acls", data)?; - } - - if let Some(data) = self.matter.store_fabrics(&mut self.buf)? { - debug!("Store fabric data..."); - Self::store("fabrics", data)?; - } - } - } - } - - fn load<'b>(key: &str, buf: &'b mut [u8]) -> Result, Error> { - debug!("Load data"); - Ok(None) - } - - fn store(key: &str, data: &[u8]) -> Result<(), Error> { - debug!("Store data"); - Ok(()) - } -} \ No newline at end of file diff --git a/examples/rust-matter-light/src/utils.rs b/examples/rust-matter-light/src/utils.rs index 2b42a040d531..112d6837450f 100644 --- a/examples/rust-matter-light/src/utils.rs +++ b/examples/rust-matter-light/src/utils.rs @@ -1,9 +1,7 @@ use core::time::Duration; use embedded_nal_async::Ipv6Addr; use log::{debug, info}; -use riot_wrappers::random::Random; -use rand_core::RngCore as _; -use riot_wrappers::error::{EAGAIN, NumericError}; +use riot_wrappers::error::{NegativeErrorExt, NumericError, EAGAIN}; use riot_wrappers::gnrc::Netif; use riot_wrappers::mutex::Mutex; use rs_matter::error::ErrorCode; @@ -16,19 +14,21 @@ const RIOT_EPOCH_SECS: u64 = 1577833200; extern "C" { fn get_seconds_since_riot_epoch() -> u32; fn get_milliseconds() -> u16; -} - -/// Generate random bytes using the RIOT random module -pub fn sys_rand(buf: &mut [u8]) { - Random::new().fill_bytes(buf); - debug!("RNG generated bytes: {:?}", buf); + fn init_constfs() -> i32; } // Current UNIX Epoch - must be in ms precision static CURRENT_DURATION: Mutex = Mutex::new(Duration::from_secs(RIOT_EPOCH_SECS)); -/// Get the current time as UNIX Epoch with milliseconds precision -/// using periph_rtc (if supported) or ztimer module +pub fn init_vfs() -> Result<(), NumericError> { + unsafe { init_constfs() } + .negative_to_error() + .map(|_| ()) +} + +/// Get the current time as UNIX Epoch with milliseconds precision using periph_rtc (if supported) or ztimer module. +/// +/// TODO: This should be moved to the `matter` module in riot-wrappers pub fn sys_epoch() -> Duration { let mut duration = CURRENT_DURATION.lock(); let riot_sec = unsafe { get_seconds_since_riot_epoch() } as u64; @@ -81,7 +81,7 @@ pub fn initialize_network() -> Result<(Ipv6Addr, u32), NumericError> { let pid = ifc.pid(); let ifc_name: &str = pid.get_name().unwrap_or("unknown"); - join_multicast_v6(pid, &MDNS_IPV6_BROADCAST_ADDR.octets()); + join_multicast_v6(pid, MDNS_IPV6_BROADCAST_ADDR).expect("Unable to join IPv6 mDNS Multicast group"); info!("Joined IPV6 multicast group @ {:?}", MDNS_IPV6_BROADCAST_ADDR); // Get available IPv6 link-local address From 62c22bdfab3f67e73cdb8e64dad6259be95fa220 Mon Sep 17 00:00:00 2001 From: Maik Lorenz Date: Tue, 30 Apr 2024 18:59:09 +0200 Subject: [PATCH 18/19] examples/rust-matter-light: delete utils.c, because it was moved to riot-wrappers --- examples/rust-matter-light/src/lib.rs | 9 ++-- examples/rust-matter-light/src/utils.rs | 64 +++++++------------------ examples/rust-matter-light/utils.c | 24 ---------- 3 files changed, 21 insertions(+), 76 deletions(-) delete mode 100644 examples/rust-matter-light/utils.c diff --git a/examples/rust-matter-light/src/lib.rs b/examples/rust-matter-light/src/lib.rs index 24112aca4924..abd4941445f1 100644 --- a/examples/rust-matter-light/src/lib.rs +++ b/examples/rust-matter-light/src/lib.rs @@ -18,7 +18,7 @@ mod dev_att; mod utils; use dev_att::HardCodedDevAtt; -use utils::initialize_network; +use utils::{initialize_network, init_vfs}; // RIOT OS modules extern crate rust_riotmodules; @@ -33,6 +33,7 @@ use riot_wrappers::shell::{self, CommandList}; use riot_wrappers::saul::{ActuatorClass, Class, Phydat, RegistryEntry}; // the new 'matter' module in riot-wrappers, enabled by 'with_matter' feature +#[allow(unused_imports)] use riot_wrappers::matter::{VfsDataFetcher, CommissioningDataFetcher, PersistenceManager, MatterCompatUdpSocket}; use rs_matter::{CommissioningData, MATTER_PORT}; @@ -48,7 +49,6 @@ use rs_matter::data_model::{ system_model::descriptor, }; use rs_matter::data_model::cluster_on_off::{Commands, OnOffCluster}; -use rs_matter::data_model::sdm::dev_att::{DataType, DevAttDataFetcher}; use rs_matter::error::Error; use rs_matter::mdns::MdnsService; use rs_matter::mdns::builtin::MDNS_SOCKET_BIND_ADDR; @@ -232,7 +232,7 @@ fn run_matter() -> Result<(), ()> { // Get Device attestation (hard-coded atm) - TODO: Use VfsDataFetcher if implemented in riot-wrappers let dev_att: &'static HardCodedDevAtt = DEV_ATT.init(HardCodedDevAtt::new()); - let epoch = utils::sys_epoch; + let epoch = riot_wrappers::matter::sys_epoch; let rand = riot_wrappers::matter::sys_rand; let matter: &'static Matter = MATTER.init(Matter::new( @@ -272,7 +272,8 @@ fn main() { info!("Hello Matter on RIOT!"); - let _ = utils::init_vfs(); + init_vfs().expect("Error initializing VFS"); + info!("Virtual File System initialized!"); use core::mem::size_of; info!("Matter memory usage: UdpBuffers={}, PacketBuffers={}, \ diff --git a/examples/rust-matter-light/src/utils.rs b/examples/rust-matter-light/src/utils.rs index 112d6837450f..b80bf558ab6d 100644 --- a/examples/rust-matter-light/src/utils.rs +++ b/examples/rust-matter-light/src/utils.rs @@ -1,74 +1,42 @@ -use core::time::Duration; use embedded_nal_async::Ipv6Addr; -use log::{debug, info}; +use log::info; use riot_wrappers::error::{NegativeErrorExt, NumericError, EAGAIN}; use riot_wrappers::gnrc::Netif; -use riot_wrappers::mutex::Mutex; use rs_matter::error::ErrorCode; use rs_matter::mdns::builtin::MDNS_IPV6_BROADCAST_ADDR; use riot_wrappers::gnrc::netapi::join_multicast_v6; -// RIOT_EPOCH(2020) in seconds since UNIX Epoch -const RIOT_EPOCH_SECS: u64 = 1577833200; - extern "C" { - fn get_seconds_since_riot_epoch() -> u32; - fn get_milliseconds() -> u16; fn init_constfs() -> i32; } -// Current UNIX Epoch - must be in ms precision -static CURRENT_DURATION: Mutex = Mutex::new(Duration::from_secs(RIOT_EPOCH_SECS)); - pub fn init_vfs() -> Result<(), NumericError> { unsafe { init_constfs() } .negative_to_error() .map(|_| ()) } -/// Get the current time as UNIX Epoch with milliseconds precision using periph_rtc (if supported) or ztimer module. -/// -/// TODO: This should be moved to the `matter` module in riot-wrappers -pub fn sys_epoch() -> Duration { - let mut duration = CURRENT_DURATION.lock(); - let riot_sec = unsafe { get_seconds_since_riot_epoch() } as u64; - let riot_msec = unsafe { get_milliseconds() } as u32; - let unix_sec = RIOT_EPOCH_SECS + riot_sec; - debug!("UNIX epoch (sec.ms): {}.{}", unix_sec, riot_msec); - let new_duration = Duration::new(unix_sec, riot_msec*1000000); - // make sure that we always get a new timestamp in rare cases if sec and msec didn't change - if *duration == new_duration { - *duration = Duration::new(unix_sec, (riot_msec + 1)*1000000); - } else { - *duration = new_duration; - } - *duration -} - #[inline(never)] pub fn get_ipv6_address(ifc: &Netif) -> Option { let all_addresses = ifc.ipv6_addrs().ok()?; info!("Found {} addresses", all_addresses.len()); - // TODO: Find a suitable IPv6 address for Matter communication - // this address will be sent with DNS-SD Reponses + // TODO: Find the Link-Local IPv6 address used for Matter communication + // This address will be sent with DNS-SD Reponses let idx = if all_addresses.len() >= 2 { 1 } else { 0 }; - return match all_addresses.get(idx) { - Some(a) => { - let ipv6_raw = a.raw(); - Some(Ipv6Addr::new( - ((ipv6_raw[0] as u16) << 8) | ipv6_raw[1] as u16, - ((ipv6_raw[2] as u16) << 8) | ipv6_raw[3] as u16, - ((ipv6_raw[4] as u16) << 8) | ipv6_raw[5] as u16, - ((ipv6_raw[6] as u16) << 8) | ipv6_raw[7] as u16, - ((ipv6_raw[8] as u16) << 8) | ipv6_raw[9] as u16, - ((ipv6_raw[10] as u16) << 8) | ipv6_raw[11] as u16, - ((ipv6_raw[12] as u16) << 8) | ipv6_raw[13] as u16, - ((ipv6_raw[14] as u16) << 8) | ipv6_raw[15] as u16, - )) - }, - None => None, - }; + all_addresses.get(idx).map(|a| { + let ipv6_raw = a.raw(); + Ipv6Addr::new( + ((ipv6_raw[0] as u16) << 8) | ipv6_raw[1] as u16, + ((ipv6_raw[2] as u16) << 8) | ipv6_raw[3] as u16, + ((ipv6_raw[4] as u16) << 8) | ipv6_raw[5] as u16, + ((ipv6_raw[6] as u16) << 8) | ipv6_raw[7] as u16, + ((ipv6_raw[8] as u16) << 8) | ipv6_raw[9] as u16, + ((ipv6_raw[10] as u16) << 8) | ipv6_raw[11] as u16, + ((ipv6_raw[12] as u16) << 8) | ipv6_raw[13] as u16, + ((ipv6_raw[14] as u16) << 8) | ipv6_raw[15] as u16, + ) + }) } #[inline(never)] diff --git a/examples/rust-matter-light/utils.c b/examples/rust-matter-light/utils.c deleted file mode 100644 index c98e1b334255..000000000000 --- a/examples/rust-matter-light/utils.c +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include "modules.h" -#include -#include "ztimer.h" -#if IS_USED(MODULE_PERIPH_RTC) -#include "periph/rtc.h" -#endif - -uint32_t get_seconds_since_riot_epoch(void) { -#if IS_USED(MODULE_PERIPH_RTC) - // Get seconds since RIOT_EPOCH from RTC - struct tm now; - rtc_get_time(&now); - rtc_tm_normalize(&now); - return rtc_mktime(&now); -#else - // Get elapsed seconds from ztimer - return ztimer_now(ZTIMER_SEC); -#endif -} - -uint16_t get_milliseconds(void) { - return ztimer_now(ZTIMER_MSEC) % 1000; -} \ No newline at end of file From 17ce9068ca0bbd216c5b1225dd711d731f6b5b23 Mon Sep 17 00:00:00 2001 From: Maik Lorenz Date: Thu, 2 May 2024 09:30:08 +0200 Subject: [PATCH 19/19] examples/rust-matter-light: init PersistenceManager as static --- examples/rust-matter-light/src/lib.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/examples/rust-matter-light/src/lib.rs b/examples/rust-matter-light/src/lib.rs index abd4941445f1..0bb84949f7d6 100644 --- a/examples/rust-matter-light/src/lib.rs +++ b/examples/rust-matter-light/src/lib.rs @@ -174,6 +174,7 @@ static DEV_DET: BasicInfoConfig = BasicInfoConfig { static MDNS: StaticCell = StaticCell::new(); static DEV_ATT: StaticCell = StaticCell::new(); static MATTER: StaticCell = StaticCell::new(); +static PSM: StaticCell = StaticCell::new(); // TODO: Instantiate `VfsDataFetcher` if fully implemented in riot-wrappers // static FW_DATA: VfsDataFetcher = VfsDataFetcher; @@ -231,10 +232,8 @@ fn run_matter() -> Result<(), ()> { // Get Device attestation (hard-coded atm) - TODO: Use VfsDataFetcher if implemented in riot-wrappers let dev_att: &'static HardCodedDevAtt = DEV_ATT.init(HardCodedDevAtt::new()); - let epoch = riot_wrappers::matter::sys_epoch; let rand = riot_wrappers::matter::sys_rand; - let matter: &'static Matter = MATTER.init(Matter::new( // vid/pid should match those in the DAC &DEV_DET, @@ -245,6 +244,11 @@ fn run_matter() -> Result<(), ()> { MATTER_PORT, )); + // TODO: 'PersistenceManager' is not implemented yet in riot-wrappers + #[cfg(feature = "psm")] + let psm: &'static mut PersistenceManager = PSM.init(PersistenceManager::new(&matter) + .expect("Error creating PSM")); + info!("Starting all services..."); static EXECUTOR: StaticCell = StaticCell::new(); let executor: &'static mut _ = EXECUTOR.init(embassy_executor_riot::Executor::new()); @@ -254,7 +258,7 @@ fn run_matter() -> Result<(), ()> { // Run PersistenceManager only if 'psm' feature is activated #[cfg(feature = "psm")] - spawner.spawn(psm_task(matter)).unwrap(); + spawner.spawn(psm_task(psm)).unwrap(); }); } @@ -365,7 +369,9 @@ async fn matter_task(matter: &'static Matter<'_>) { let mut matter_packet_buffers = PacketBuffers::new(); // TODO: Read commissioning data from VFS if implemented in riot-wrappers - //let (discriminator, passcode) = FW_DATA.read_commissioning_data().expect("error while reading commissioning data"); + //let data_fetcher = VfsDataFetcher::new(); + //let (discriminator, passcode) = data_fetcher.read_commissioning_data().expect("error reading commissioning data from VFS"); + let (discriminator, passcode) = (DISCRIMINATOR, PASSCODE); // Finally create the Matter service and run on port 5540/UDP let matter_runner = pin!(matter.run( @@ -375,8 +381,8 @@ async fn matter_task(matter: &'static Matter<'_>) { &mut matter_packet_buffers, CommissioningData { // TODO: Hard-coded for now - verifier: VerifierData::new_with_pw(PASSCODE, *matter.borrow()), - discriminator: DISCRIMINATOR, + verifier: VerifierData::new_with_pw(passcode, *matter.borrow()), + discriminator, }, &handler) ); @@ -394,11 +400,8 @@ async fn matter_task(matter: &'static Matter<'_>) { } #[embassy_executor::task] -async fn psm_task(matter: &'static Matter<'_>) { +async fn psm_task(psm: &'static mut PersistenceManager<'_>) { info!("Starting Persistence Manager...."); - // TODO: 'PersistenceManager' is not implemented yet in riot-wrappers - let mut psm = PersistenceManager::new(&matter) - .expect("Error creating PSM"); let psm_runner = pin!(psm.run()); match psm_runner.await { Ok(_) => {