use crate::{
telegram101::{Config, Telegram101},
telegram104::Telegram104_I,
types::{datatype::DataType, DataBuffer, COT},
};
#[derive(Clone, Debug)]
pub struct Event {
adsu: u16,
iou_addr: u32,
tid: DataType,
cot: COT,
data: DataBuffer,
}
impl Event {
pub fn new(
adsu: u16,
iou_addr: u32,
tid: DataType,
cot: COT,
data: impl Into<DataBuffer>,
) -> Self {
Self {
adsu,
iou_addr,
tid,
cot,
data: data.into(),
}
}
pub fn adsu(&self) -> u16 {
self.adsu
}
pub fn iou_addr(&self) -> u32 {
self.iou_addr
}
pub fn tid(&self) -> DataType {
self.tid
}
pub fn cot(&self) -> COT {
self.cot
}
pub fn data(&self) -> DataBuffer {
self.data
}
pub fn into_telegram_104_i(self) -> Telegram104_I {
self.into()
}
pub fn into_telegram_101(self, config: Config) -> Telegram101 {
let mut telegram = Telegram101::new(self.tid, self.cot, self.adsu, config);
telegram.append_iou(self.iou_addr, self.data);
telegram
}
}
impl From<Event> for Telegram104_I {
fn from(event: Event) -> Self {
let mut telegram = Telegram104_I::new(event.tid, event.cot, event.adsu);
telegram.append_iou(event.iou_addr, event.data);
telegram
}
}