use crate::{
socket_can::CanSocketTx,
uds_client::{DiagError, PciByte, UdsClient},
};
use automotive_diag::uds::UdsCommand;
#[repr(u8)]
#[derive(Debug)]
pub enum ResetType {
RealTime = 0x40,
Telematic = 0x41,
Imx = 0x42,
Esp32Wifi = 0x43,
Esp32Ble = 0x44,
Lte = 0x45,
Lizard = 0x46,
Cendric = 0x47,
}
impl From<ResetType> for u8 {
fn from(reset_type: ResetType) -> Self {
reset_type as u8
}
}
impl TryFrom<i32> for ResetType {
type Error = ();
fn try_from(reset_type: i32) -> Result<Self, Self::Error> {
match reset_type as u8 {
0x40 => Ok(ResetType::RealTime),
0x41 => Ok(ResetType::Telematic),
0x42 => Ok(ResetType::Imx),
0x43 => Ok(ResetType::Esp32Wifi),
0x44 => Ok(ResetType::Esp32Ble),
0x45 => Ok(ResetType::Lte),
0x46 => Ok(ResetType::Lizard),
0x47 => Ok(ResetType::Cendric),
_ => Err(()),
}
}
}
#[allow(dead_code)]
impl<T: CanSocketTx> UdsClient<'_, T> {
pub async fn uds_reset_118(&mut self) -> Result<(), DiagError> {
dbg!("UDS: send reset 118");
let pci_byte = PciByte::new(crate::uds_client::PciType::SingleFrame, 2);
self.send_command_with_response(
pci_byte,
UdsCommand::ECUReset,
&[ResetType::RealTime.into()],
)
.await?;
Ok(())
}
pub async fn uds_reset_148(&mut self) -> Result<(), DiagError> {
dbg!("UDS: send reset 148");
let pci_byte = PciByte::new(crate::uds_client::PciType::SingleFrame, 2);
self.send_command_with_response(
pci_byte,
UdsCommand::ECUReset,
&[ResetType::Telematic.into()],
)
.await?;
Ok(())
}
pub async fn uds_reset_imx(&mut self) -> Result<(), DiagError> {
dbg!("UDS: send reset imx");
let pci_byte = PciByte::new(crate::uds_client::PciType::SingleFrame, 2);
self.send_command_with_response(pci_byte, UdsCommand::ECUReset, &[ResetType::Imx.into()])
.await?;
Ok(())
}
pub async fn uds_reset_esp32_wifi(&mut self) -> Result<(), DiagError> {
dbg!("UDS: send reset esp-wifi");
let pci_byte = PciByte::new(crate::uds_client::PciType::SingleFrame, 2);
self.send_command_with_response(
pci_byte,
UdsCommand::ECUReset,
&[ResetType::Esp32Wifi.into()],
)
.await?;
Ok(())
}
pub async fn uds_reset_esp32_ble(&mut self) -> Result<(), DiagError> {
dbg!("UDS: send reset esp-ble");
let pci_byte = PciByte::new(crate::uds_client::PciType::SingleFrame, 2);
self.send_command_with_response(
pci_byte,
UdsCommand::ECUReset,
&[ResetType::Esp32Ble.into()],
)
.await?;
Ok(())
}
pub async fn uds_reset_lte(&mut self) -> Result<(), DiagError> {
dbg!("UDS: send reset lte");
let pci_byte = PciByte::new(crate::uds_client::PciType::SingleFrame, 2);
self.send_command_with_response(pci_byte, UdsCommand::ECUReset, &[ResetType::Lte.into()])
.await?;
Ok(())
}
pub async fn uds_reset_lizard(&mut self) -> Result<(), DiagError> {
dbg!("UDS: send reset lizard");
let pci_byte = PciByte::new(crate::uds_client::PciType::SingleFrame, 2);
self.send_command_with_response(
pci_byte,
UdsCommand::ECUReset,
&[ResetType::Lizard.into()],
)
.await?;
Ok(())
}
pub async fn uds_reset_cendric(&mut self) -> Result<(), DiagError> {
dbg!("UDS: send reset cendric");
let pci_byte = PciByte::new(crate::uds_client::PciType::SingleFrame, 2);
self.send_command_with_response(
pci_byte,
UdsCommand::ECUReset,
&[ResetType::Cendric.into()],
)
.await?;
Ok(())
}
}