use crate::{DiagServerResult, DiagnosticServer};
use super::{KWP2000Command, Kwp2000DiagnosticServer};
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum SessionType {
Normal,
Reprogramming,
Standby,
Passive,
ExtendedDiagnostics,
Custom(u8),
}
impl From<SessionType> for u8 {
fn from(x: SessionType) -> Self {
match x {
SessionType::Normal => 0x81,
SessionType::Reprogramming => 0x85,
SessionType::Standby => 0x89,
SessionType::Passive => 0x90,
SessionType::ExtendedDiagnostics => 0x92,
SessionType::Custom(c) => c,
}
}
}
impl Kwp2000DiagnosticServer {
pub fn set_diagnostic_session_mode(&mut self, mode: SessionType) -> DiagServerResult<()> {
self.execute_command_with_response(KWP2000Command::StartDiagnosticSession, &[mode.into()])
.map(|_| ())
}
}