use snafu::Snafu;
use super::model::PointAddress;
use crate::{server::error::ServerError, types_id::TypeId};
#[derive(Debug, Snafu)]
#[snafu(visibility(pub), context(suffix(false)))]
pub enum SetPointError {
#[snafu(display("unknown point: {address}"))]
UnknownPoint { address: PointAddress },
#[snafu(display("type mismatch for point {address}: expected {expected:?}, got {got:?}"))]
TypeMismatch { address: PointAddress, expected: TypeId, got: TypeId },
#[snafu(display("failed to broadcast spontaneous ASDU"))]
BroadcastFailed { source: ServerError },
}
#[derive(Debug, Snafu)]
#[snafu(visibility(pub), context(suffix(false)))]
pub enum RtuHandleError {
#[snafu(display("RTU server is no longer running"))]
Disconnected,
#[snafu(display("RTU server actor stopped before responding"))]
ActorStopped,
#[snafu(display("Point already registered: {address}"))]
AlreadyRegistered { address: PointAddress },
#[snafu(display("register_points input contains duplicate point address(es)"))]
DuplicateAddressInInput,
#[snafu(display("Point not registered: {address}"))]
NotRegistered { address: PointAddress },
#[snafu(display("invalid interrogation group: {group} (expected 1..=16)"))]
InvalidInterrogationGroup { group: u8 },
#[snafu(display("invalid counter interrogation group: {group} (expected 1..=4)"))]
InvalidCounterInterrogationGroup { group: u8 },
#[snafu(display("counter interrogation group applies only to M_IT_* point values"))]
CounterGroupRequiresCounterPoint,
#[snafu(display("{source}"))]
SetPoint { source: SetPointError },
}
impl From<SetPointError> for RtuHandleError {
fn from(source: SetPointError) -> Self {
Self::SetPoint { source }
}
}
#[derive(Debug, Snafu)]
#[snafu(visibility(pub(crate)))]
pub(crate) enum InterrogationError {
#[snafu(display("not handled as interrogation by RTU server"))]
Skipped,
#[snafu(display("failed to send interrogation activation confirmation: {source}"))]
SendConfirmation { source: ServerError },
#[snafu(display("failed to send interrogation data ASDU: {source}"))]
SendData { source: ServerError },
#[snafu(display("failed to send interrogation activation termination: {source}"))]
SendTermination { source: ServerError },
}