1use core::fmt::Write;
2use heapless::String;
3use miniconf::Tree;
4use smoltcp_nal::smoltcp::wire::EthernetAddress;
5
6#[derive(Clone, Debug, Tree)]
8#[tree(meta(doc, typename))]
9pub struct NetSettings {
10 pub broker: String<255>,
12
13 pub id: String<23>,
15
16 pub ip: String<15>,
19
20 #[tree(skip)]
21 pub mac: EthernetAddress,
23}
24
25impl Default for NetSettings {
26 fn default() -> Self {
27 Self {
28 broker: String::try_from("mqtt").unwrap(),
29 ip: String::try_from("0.0.0.0").unwrap(),
30 id: String::try_from("<mac>").unwrap(),
31 mac: EthernetAddress::default(),
32 }
33 }
34}
35
36impl NetSettings {
37 pub fn new(mac: EthernetAddress) -> Self {
38 let mut id = String::new();
39 write!(&mut id, "{mac}").unwrap();
40
41 Self {
42 id,
43 mac,
44 ..Default::default()
45 }
46 }
47}
48
49pub trait AppSettings {
50 fn new(net: NetSettings) -> Self;
52
53 fn net(&self) -> &NetSettings;
55}