Start answering hello commands

This commit is contained in:
Joscha 2022-02-12 00:54:27 +01:00
parent fec541b7aa
commit 6cc8670291
5 changed files with 207 additions and 182 deletions

View file

@ -43,6 +43,12 @@ macro_rules! packets {
}
}
}
impl From<$cmd> for Cmd {
fn from(cmd: $cmd) -> Self {
Self::$cmdName(cmd)
}
}
)*
#[derive(Debug, Deserialize, Serialize)]
@ -61,6 +67,12 @@ macro_rules! packets {
}
}
}
impl From<$rpl> for Rpl {
fn from(rpl: $rpl) -> Self {
Self::$cmdName(rpl)
}
}
)*
#[derive(Debug, Deserialize, Serialize)]
@ -79,6 +91,12 @@ macro_rules! packets {
}
}
}
impl From<$ntf> for Ntf {
fn from(ntf: $ntf) -> Self {
Self::$ntfName(ntf)
}
}
)*
};
}

View file

@ -115,3 +115,23 @@ pub enum Packet {
ntf: Ntf,
},
}
impl Packet {
pub fn cmd<C: Into<Cmd>>(id: u64, cmd: C) -> Self {
Self::Cmd {
id,
cmd: cmd.into(),
}
}
pub fn rpl<R: Into<Rpl>>(id: u64, rpl: R) -> Self {
Self::Rpl {
id,
rpl: rpl.into(),
}
}
pub fn ntf<N: Into<Ntf>>(ntf: N) -> Self {
Self::Ntf { ntf: ntf.into() }
}
}