iso14229_1/common/
session_ctrl.rs

1//! Commons of Service 10
2
3
4use crate::{Error, utils};
5
6#[repr(u8)]
7#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
8pub enum SessionType {
9    #[default]
10    Default = 0x01,
11    Programming = 0x02,
12    Extended = 0x03,
13    SafetySystemDiagnostic = 0x04,
14    VehicleManufacturerSpecific(u8),
15    SystemSupplierSpecific(u8),
16    Reserved(u8),
17}
18
19impl TryFrom<u8> for SessionType {
20    type Error = Error;
21    fn try_from(value: u8) -> Result<Self, Self::Error> {
22        match value {
23            0x01 => Ok(Self::Default),
24            0x02 => Ok(Self::Programming),
25            0x03 => Ok(Self::Extended),
26            0x04 => Ok(Self::SafetySystemDiagnostic),
27            0x05..=0x3F => Ok(Self::Reserved(value)),
28            0x40..=0x5F => Ok(Self::VehicleManufacturerSpecific(value)),
29            0x60..=0x7E => Ok(Self::SystemSupplierSpecific(value)),
30            0x7F => Ok(Self::Reserved(value)),
31            v => Err(Error::InvalidParam(utils::err_msg(v))),
32        }
33    }
34}
35
36impl Into<u8> for SessionType {
37    fn into(self) -> u8 {
38        match self {
39            Self::Default => 0x01,
40            Self::Programming => 0x02,
41            Self::Extended => 0x03,
42            Self::SafetySystemDiagnostic => 0x04,
43            Self::VehicleManufacturerSpecific(v) => v,
44            Self::SystemSupplierSpecific(v) => v,
45            Self::Reserved(v) => v,
46        }
47    }
48}