use crate::uds::{UDSCommand, UdsDiagnosticServer};
use crate::DiagnosticServer;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum CommunicationLevel {
EnableRxAndTx,
EnableRxDisableTx,
DisableRxEnableTx,
DisableRxAndTx,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum EcuCommunicationType {
NormalCommunication,
NetworkManagement,
All,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Subnet {
All,
Custom(u8),
RxOnly,
}
impl UdsDiagnosticServer {
pub fn control_communication(
&mut self,
communication_type: EcuCommunicationType,
subnet: Subnet,
comm_level: CommunicationLevel,
) -> super::DiagServerResult<()> {
let mut communication_type: u8 = match communication_type {
EcuCommunicationType::NormalCommunication => 0x01,
EcuCommunicationType::NetworkManagement => 0x02,
EcuCommunicationType::All => 0x03,
};
communication_type |= (match subnet {
Subnet::All => 0x00,
Subnet::Custom(x) => x << 4,
Subnet::RxOnly => 0x0F,
}) << 4;
let level: u8 = match comm_level {
CommunicationLevel::EnableRxAndTx => 0x00,
CommunicationLevel::EnableRxDisableTx => 0x01,
CommunicationLevel::DisableRxEnableTx => 0x02,
CommunicationLevel::DisableRxAndTx => 0x03,
};
self.execute_command_with_response(
UDSCommand::CommunicationControl,
&[level, communication_type],
)
.map(|_| ())
}
}