Skip to main content

mcumgr_toolkit/
lib.rs

1#![deny(missing_docs)]
2#![deny(unreachable_pub)]
3#![forbid(unsafe_code)]
4#![doc = include_str!("../README.md")]
5#![doc(issue_tracker_base_url = "https://github.com/Finomnis/mcumgr-toolkit/issues")]
6// That's just a bad lint, in many cases I want two ifs for readability
7#![allow(clippy::collapsible_if)]
8#![cfg_attr(docsrs, feature(doc_cfg))]
9
10/// A high-level client for Zephyr's MCUmgr SMP functionality
11pub mod client;
12pub use client::MCUmgrClient;
13
14mod errno;
15pub use errno::Errno;
16
17/// [MCUmgr command group](https://docs.zephyrproject.org/latest/services/device_mgmt/smp_protocol.html#specifications-of-management-groups-supported-by-zephyr) definitions
18pub mod commands;
19
20/// [SMP protocol layer](https://docs.zephyrproject.org/latest/services/device_mgmt/smp_protocol.html) implementation
21pub mod connection;
22
23/// [SMP transport layer](https://docs.zephyrproject.org/latest/services/device_mgmt/smp_transport.html) implementation
24pub mod transport;
25
26/// Zephyr SMP error definitions
27pub mod smp_errors;
28
29/// Bootloader related definitions
30pub mod bootloader;
31
32/// MCUboot specific algorithms
33pub mod mcuboot;
34
35/// See [`enum mcumgr_group_t`](https://docs.zephyrproject.org/latest/doxygen/html/mgmt__defines_8h.html).
36#[derive(strum::FromRepr, strum::Display, Debug, Copy, Clone, PartialEq, Eq)]
37#[repr(u16)]
38#[allow(non_camel_case_types)]
39#[allow(missing_docs)]
40pub enum MCUmgrGroup {
41    MGMT_GROUP_ID_OS = 0,
42    MGMT_GROUP_ID_IMAGE,
43    MGMT_GROUP_ID_STAT,
44    MGMT_GROUP_ID_SETTINGS,
45    MGMT_GROUP_ID_LOG,
46    MGMT_GROUP_ID_CRASH,
47    MGMT_GROUP_ID_SPLIT,
48    MGMT_GROUP_ID_RUN,
49    MGMT_GROUP_ID_FS,
50    MGMT_GROUP_ID_SHELL,
51    MGMT_GROUP_ID_ENUM,
52    ZEPHYR_MGMT_GRP_BASIC = 63,
53    MGMT_GROUP_ID_PERUSER = 64,
54}
55
56impl MCUmgrGroup {
57    /// Converts a raw group id to a string
58    pub fn group_id_to_string(group_id: u16) -> String {
59        const PERUSER: MCUmgrGroup = MCUmgrGroup::MGMT_GROUP_ID_PERUSER;
60        if group_id < PERUSER as u16 {
61            if let Some(group_enum) = Self::from_repr(group_id) {
62                format!("{group_enum}")
63            } else {
64                format!("MGMT_GROUP_ID_UNKNOWN({group_id})")
65            }
66        } else {
67            format!("{PERUSER}({group_id})")
68        }
69    }
70}
71
72/// The default timeout used by this crate
73pub const DEFAULT_TIMEOUT_MS: u64 = 1000;
74
75/// The default retry count used by this crate
76pub const DEFAULT_RETRIES: u8 = 5;