zigbee_core/aps/frame/
mod.rs1use byte::BytesExt;
2
3use crate::aps::frame::command::Command;
4use crate::aps::frame::frame_control::FrameType;
5use crate::aps::frame::header::Header;
6
7pub mod command;
8pub mod frame_control;
9pub mod header;
10
11#[derive(Debug)]
13pub enum Frame<'a> {
14 Data(DataFrame<'a>),
15 ApsCommand(CommandFrame),
16 Acknowledgement(Header),
17}
18
19impl<'a> Frame<'a> {
20 pub fn from_payload(header: Header, payload: &'a [u8]) -> byte::Result<Self> {
21 match header.frame_control.frame_type() {
22 FrameType::Data => Ok(Self::Data(DataFrame { header, payload })),
23 FrameType::Command => Ok(Self::ApsCommand(CommandFrame {
24 header,
25 command: payload.read_with(&mut 0, ())?,
26 })),
27 FrameType::Acknowledgement => Ok(Self::Acknowledgement(header)),
28 FrameType::InterPan => unimplemented!("InterPan frames not supported"),
29 }
30 }
31
32 pub fn header(&self) -> &Header {
33 match self {
34 Frame::Data(data_frame) => &data_frame.header,
35 Frame::ApsCommand(command_frame) => &command_frame.header,
36 Frame::Acknowledgement(header) => header,
37 }
38 }
39}
40
41#[derive(Debug)]
42pub struct DataFrame<'a> {
43 pub header: Header,
44 pub payload: &'a [u8],
45}
46
47#[derive(Debug)]
48pub struct CommandFrame {
49 pub header: Header,
50 pub command: Command,
51}