1use crate::{
2 telegram101::{Config, Telegram101},
3 telegram104::Telegram104_I,
4 types::{datatype::DataType, DataBuffer, COT},
5};
6
7#[derive(Clone, Debug)]
9pub struct Event {
10 adsu: u16,
11 iou_addr: u32,
12 tid: DataType,
13 cot: COT,
14 data: DataBuffer,
15}
16
17impl Event {
18 pub fn new(
20 adsu: u16,
21 iou_addr: u32,
22 tid: DataType,
23 cot: COT,
24 data: impl Into<DataBuffer>,
25 ) -> Self {
26 Self {
27 adsu,
28 iou_addr,
29 tid,
30 cot,
31 data: data.into(),
32 }
33 }
34 pub fn adsu(&self) -> u16 {
36 self.adsu
37 }
38 pub fn iou_addr(&self) -> u32 {
40 self.iou_addr
41 }
42 pub fn tid(&self) -> DataType {
44 self.tid
45 }
46 pub fn cot(&self) -> COT {
48 self.cot
49 }
50 pub fn data(&self) -> DataBuffer {
52 self.data
53 }
54 pub fn into_telegram_104_i(self) -> Telegram104_I {
56 self.into()
57 }
58 pub fn into_telegram_101(self, config: Config) -> Telegram101 {
60 let mut telegram = Telegram101::new(self.tid, self.cot, self.adsu, config);
61 telegram.append_iou(self.iou_addr, self.data);
62 telegram
63 }
64}
65
66impl From<Event> for Telegram104_I {
67 fn from(event: Event) -> Self {
68 let mut telegram = Telegram104_I::new(event.tid, event.cot, event.adsu);
69 telegram.append_iou(event.iou_addr, event.data);
70 telegram
71 }
72}