mod error;
mod router;
mod tunnel;
pub mod tunnel_server;
mod url;
pub mod discovery;
pub mod multiplex;
pub mod ops;
pub use error::KnxIpError;
pub use multiplex::{MultiplexHandle, Multiplexer};
pub use router::{KNX_MULTICAST_ADDR, KNX_PORT, RouterConnection};
pub use tunnel::{TunnelConfig, TunnelConnection};
pub use tunnel_server::{DeviceServer, ServerEvent};
pub use url::{ConnectionSpec, connect, parse_url};
use core::future::Future;
use core::pin::Pin;
use knx_rs_core::cemi::CemiFrame;
pub type KnxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
pub trait KnxConnection: Send {
fn send(&self, frame: CemiFrame) -> KnxFuture<'_, Result<(), KnxIpError>>;
fn recv(&mut self) -> KnxFuture<'_, Option<CemiFrame>>;
fn close(&mut self) -> KnxFuture<'_, ()>;
}
pub enum AnyConnection {
Tunnel(TunnelConnection),
Router(RouterConnection),
}
impl KnxConnection for AnyConnection {
fn send(&self, frame: CemiFrame) -> KnxFuture<'_, Result<(), KnxIpError>> {
match self {
Self::Tunnel(c) => c.send(frame),
Self::Router(c) => c.send(frame),
}
}
fn recv(&mut self) -> KnxFuture<'_, Option<CemiFrame>> {
match self {
Self::Tunnel(c) => c.recv(),
Self::Router(c) => c.recv(),
}
}
fn close(&mut self) -> KnxFuture<'_, ()> {
match self {
Self::Tunnel(c) => c.close(),
Self::Router(c) => c.close(),
}
}
}