Skip to main content

mcumgr_toolkit/commands/
stats.rs

1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5use super::macros::impl_serialize_as_empty_map;
6
7/// [Statistics: group data](https://docs.zephyrproject.org/latest/services/device_mgmt/smp_groups/smp_group_2.html#statistics-group-data) command
8#[derive(Clone, Debug, Serialize, Eq, PartialEq)]
9pub struct GroupData<'a> {
10    /// group name
11    pub name: &'a str,
12}
13
14/// Response for [`GroupData`] command
15#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
16pub struct GroupDataResponse {
17    /// name of group the response contains data for
18    pub name: String,
19    /// map of entries within given group
20    pub fields: HashMap<String, u64>,
21}
22
23/// [Statistics: list of groups](https://docs.zephyrproject.org/latest/services/device_mgmt/smp_groups/smp_group_2.html#statistics-list-of-groups) command
24#[derive(Clone, Debug, Eq, PartialEq)]
25pub struct ListGroups;
26impl_serialize_as_empty_map!(ListGroups);
27
28/// Response for [`ListGroups`] command
29#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
30pub struct ListGroupsResponse {
31    /// array of strings representing group names
32    pub stat_list: Vec<String>,
33}
34
35#[cfg(test)]
36mod tests {
37    use super::super::macros::command_encode_decode_test;
38    use super::*;
39    use ciborium::cbor;
40
41    command_encode_decode_test! {
42        group_data,
43        (0, 2, 0),
44        GroupData{name: "foo"},
45        cbor!({"name" => "foo"}),
46        cbor!({
47            "name" => "bar",
48            "fields" => {
49                "abc" => 10,
50                "foo50" => 0xFFFFFFFFFFFFFFFFu64,
51            }
52        }),
53        GroupDataResponse{
54            name: "bar".to_string(),
55            fields: HashMap::from([
56                ("abc".to_string(), 10),
57                ("foo50".to_string(), u64::MAX),
58            ])
59        },
60    }
61
62    command_encode_decode_test! {
63        list_groups,
64        (0, 2, 1),
65        ListGroups,
66        cbor!({}),
67        cbor!({"stat_list" => ["foo", "bar"]}),
68        ListGroupsResponse{ stat_list: vec!["foo".to_string(), "bar".to_string()] },
69    }
70}