industrial_protocols_kernel/sdk/
mod.rs1pub mod types;
27
28use crate::bridge::Transport;
29use crate::connection::Connection;
30use crate::error::Result;
31pub use types::*;
32
33pub trait Protocol: Send + Sync {
37 fn name(&self) -> &'static str;
39 fn version(&self) -> &'static str;
41 fn category(&self) -> ProtocolCategory;
43 fn supported_variants(&self) -> &'static [&'static str];
45}
46
47pub trait ProtocolRead: Protocol {
51 type Address: AddressLike;
53 type Value: ValueLike;
55 fn read(&self, conn: &mut dyn Connection, addr: &Self::Address) -> Result<Self::Value>;
57 fn read_batch(
59 &self,
60 conn: &mut dyn Connection,
61 addrs: &[Self::Address],
62 ) -> Result<Vec<Self::Value>>;
63 fn read_range(
65 &self,
66 conn: &mut dyn Connection,
67 start: &Self::Address,
68 count: u16,
69 ) -> Result<Vec<Self::Value>>;
70}
71
72pub trait ProtocolWrite: Protocol {
74 type Address: AddressLike;
75 type Value: ValueLike;
76 fn write(
78 &self,
79 conn: &mut dyn Connection,
80 addr: &Self::Address,
81 value: &Self::Value,
82 ) -> Result<()>;
83 fn write_batch(
85 &self,
86 conn: &mut dyn Connection,
87 items: &[(Self::Address, Self::Value)],
88 ) -> Result<()>;
89}
90
91pub trait ProtocolSubscribe: Protocol {
93 type SubscriptionId: Clone + Send + Sync;
95 type Address: AddressLike;
96 fn subscribe(
98 &self,
99 conn: &mut dyn Connection,
100 addrs: &[Self::Address],
101 ) -> Result<Self::SubscriptionId>;
102 fn unsubscribe(&self, conn: &mut dyn Connection, sub_id: &Self::SubscriptionId) -> Result<()>;
104 fn poll(
106 &self,
107 conn: &mut dyn Connection,
108 ) -> Result<Vec<SubscriptionUpdate<Self::SubscriptionId>>>;
109}
110
111pub trait ProtocolDiscover {
113 fn discover(&self, transport: &mut dyn Transport) -> Result<Vec<DiscoveredDevice>>;
115}
116
117pub trait ProtocolHealth: Protocol {
119 fn health(&self, conn: &mut dyn Connection) -> Result<HealthStatus>;
121}
122
123pub trait ProtocolDiagnostics: Protocol {
125 fn diagnostics(&self, conn: &mut dyn Connection) -> Result<DiagnosticsReport>;
127}