poststation_sim_icd/
lib.rs

1//! Interface definitions used for poststation simulators
2
3/// The `simulator` module is used for `--simulator-devices` usage
4pub mod simulator {
5    use postcard_rpc::{endpoints, topics, TopicDirection};
6    use postcard_schema::Schema;
7    use serde::{Deserialize, Serialize};
8
9    #[derive(Serialize, Deserialize, Schema, Debug, PartialEq, Copy, Clone)]
10    pub struct Rgb8 {
11        pub r: u8,
12        pub g: u8,
13        pub b: u8,
14    }
15
16    #[derive(Serialize, Deserialize, Schema, Debug, PartialEq, Clone)]
17    pub struct Temperature {
18        pub temp: f64,
19    }
20
21
22    endpoints! {
23        list = ENDPOINT_LIST;
24        | EndpointTy            | RequestTy     | ResponseTy    | Path                          |
25        | ----------            | ---------     | ----------    | ----                          |
26        | GetUniqueIdEndpoint   | ()            | u64           | "poststation/unique_id/get"   |
27        | RebootToPicoBoot      | ()            | ()            | "simulator/picoboot/reset"    |
28        | SetStatusLed          | Rgb8          | ()            | "simulator/status_led/set"    |
29        | GetStatusLed          | ()            | Rgb8          | "simulator/status_led/get"    |
30    }
31
32    topics! {
33       list = TOPICS_IN_LIST;
34       direction = TopicDirection::ToServer;
35       | TopicTy        | MessageTy     | Path              |
36       | -------        | ---------     | ----              |
37    }
38
39    topics! {
40       list = TOPICS_OUT_LIST;
41       direction = TopicDirection::ToClient;
42       | TopicTy        | MessageTy     | Path                      |
43       | -------        | ---------     | ----                      |
44       | SomeNumber     | Temperature   | "simulator/temperature"   |
45    }
46}
47
48/// The `interface_tester` module is used for `--interface-testers` usage
49pub mod interface_tester {
50    use std::collections::HashMap;
51    use postcard_rpc::{endpoints, topics, TopicDirection};
52    use postcard_schema::Schema;
53    use serde::{Deserialize, Serialize};
54
55    // ------
56    pub type OptString = Option<String>;
57    pub type OptNum = Option<f64>;
58    pub type VecString = Vec<String>;
59    pub type VecNum = Vec<f64>;
60    pub type OneTup = (f64,);
61    pub type TwoTup = (bool, String);
62    pub type ThreeTup = (i8, u16, i32);
63    pub type StringNumMap = HashMap<String, f64>;
64    pub type StringStringMap = HashMap<String, String>;
65
66    #[derive(Serialize, Deserialize, Debug, Schema)]
67    pub struct MyUnitStruct;
68
69    #[derive(Serialize, Deserialize, Debug, Schema)]
70    pub struct MyNtStruct(pub f64);
71
72    #[derive(Serialize, Deserialize, Debug, Schema)]
73    pub struct OneTupStruct(f64);
74
75    #[derive(Serialize, Deserialize, Debug, Schema)]
76    pub struct TwoTupStruct(bool, String);
77
78    #[derive(Serialize, Deserialize, Debug, Schema)]
79    pub struct ThreeTupStruct(i8, u16, i32);
80
81    #[derive(Serialize, Deserialize, Debug, Schema)]
82    pub struct AlphaUnsigned {
83        pub a: u8,
84        pub b: u16,
85        pub c: u32,
86        pub d: u64,
87        pub e: u128,
88    }
89
90    #[derive(Serialize, Deserialize, Debug, Schema)]
91    pub struct AlphaSigned {
92        pub a: i8,
93        pub b: i16,
94        pub c: i32,
95        pub d: i64,
96        pub e: i128,
97    }
98
99    #[derive(Serialize, Deserialize, Debug, Schema)]
100    pub struct Beta {
101        pub in_left: AlphaUnsigned,
102        pub in_right: AlphaUnsigned,
103    }
104
105    #[derive(Serialize, Deserialize, Debug, Schema)]
106    pub struct Delta {
107        pub add_wrapping: AlphaUnsigned,
108        pub add_saturating: AlphaUnsigned,
109        pub any_add_outrange: bool,
110        pub sub_wrapping: AlphaUnsigned,
111        pub sub_saturating: AlphaUnsigned,
112        pub any_sub_outrange: bool,
113    }
114
115    #[derive(Serialize, Deserialize, Debug, Schema)]
116    pub enum ExampleEnum {
117        UnitVariant,
118        NewtypeVariant(f32),
119        TupleVariant(u8, bool, String),
120        StructVariant { alpha: u8, beta: bool },
121    }
122
123    endpoints! {
124        list = ENDPOINT_LIST;
125        | EndpointTy                | RequestTy         | ResponseTy        | Path                              |
126        | ----------                | ---------         | ----------        | ----                              |
127        | GetUniqueIdEndpoint       | ()                | u64               | "poststation/unique_id/get"       |
128        | RebootToPicoBoot          | ()                | ()                | "simulator/picoboot/reset"        |
129        | InvertEndpoint            | bool              | bool              | "simulator/invert"                |
130        | U8toI8Endpoint            | u8                | i8                | "simulator/convert/u8i8"          |
131        | U16toI16Endpoint          | u16               | i16               | "simulator/convert/u16i16"        |
132        | U32toI32Endpoint          | u32               | i32               | "simulator/convert/u32i32"        |
133        | U64toI64Endpoint          | u64               | i64               | "simulator/convert/u64i64"        |
134        | U128toI128Endpoint        | u128              | i128              | "simulator/convert/u128i128"      |
135        | I8toU8Endpoint            | i8                | u8                | "simulator/convert/i8u8"          |
136        | I16toU16Endpoint          | i16               | u16               | "simulator/convert/i16u16"        |
137        | I32toU32Endpoint          | i32               | u32               | "simulator/convert/i32u32"        |
138        | I64toU64Endpoint          | i64               | u64               | "simulator/convert/i64u64"        |
139        | I128toU128Endpoint        | i128              | u128              | "simulator/convert/i128u128"      |
140        | SineF32Endpoint           | f32               | f32               | "simulator/sine/f32"              |
141        | CosF64Endpoint            | f64               | f64               | "simulator/sine/f64"              |
142        | StringToLowerEndpoint     | String            | String            | "simulator/convert/lowercase"     |
143        | OptionStrNumEndpoint      | OptString         | OptNum            | "simulator/convert/optstrnum"     |
144        | UnitEndpoint              | ()                | ()                | "simulator/echo/unit"             |
145        | UnitStructEndpoint        | MyUnitStruct      | MyUnitStruct      | "simulator/echo/unitstruct"       |
146        | NTStructSineEndpoint      | MyNtStruct        | MyNtStruct        | "simulator/sine/nt"               |
147        | SeqStrNumEndpoint         | VecString         | VecNum            | "simulator/convert/seqstrnum"     |
148        | OneTupEchoEndpoint        | OneTup            | OneTup            | "simulator/echo/onetup"           |
149        | TwoTupEchoEndpoint        | TwoTup            | TwoTup            | "simulator/echo/twotup"           |
150        | ThreeTupEchoEndpoint      | ThreeTup          | ThreeTup          | "simulator/echo/threetup"         |
151        | OneTupSEchoEndpoint       | OneTupStruct      | OneTupStruct      | "simulator/echo/onetupstruct"     |
152        | TwoTupSEchoEndpoint       | TwoTupStruct      | TwoTupStruct      | "simulator/echo/twotupstruct"     |
153        | ThreeTupSEchoEndpoint     | ThreeTupStruct    | ThreeTupStruct    | "simulator/echo/threetupstruct"   |
154        | MapStrNumEndpoint         | StringNumMap      | StringStringMap   | "simulator/convert/mapstrnum"     |
155        | StructToSignedEndpoint    | AlphaUnsigned     | AlphaSigned       | "simulator/convert/structutoi"    |
156        | StructMathEndpoint        | Beta              | Delta             | "simulator/math/struct"           |
157        | EnumEchoEndpoint          | ExampleEnum       | ExampleEnum       | "simulator/echo/enum"             |
158    }
159
160    topics! {
161       list = TOPICS_IN_LIST;
162       direction = TopicDirection::ToServer;
163       | TopicTy        | MessageTy     | Path              |
164       | -------        | ---------     | ----              |
165    }
166
167    topics! {
168       list = TOPICS_OUT_LIST;
169       direction = TopicDirection::ToClient;
170       | TopicTy        | MessageTy     | Path                      |
171       | -------        | ---------     | ----                      |
172    }
173}