1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//! Provides methods to reset the ECU in order to simulate power cycling and resetting memory regions
//!
use crate::{
dynamic_diag::{DynamicDiagSession, EcuNRC},
DiagError, DiagServerResult,
};
pub use automotive_diag::uds::ResetType;
use automotive_diag::uds::{UdsCommand, UdsError};
use automotive_diag::ByteWrapper::Standard;
impl DynamicDiagSession {
/// Asks the ECU to perform a hard reset. See [ResetType::HardReset] for more details
///
/// ## Parameters
/// * server - The UDS Diagnostic server
pub fn uds_ecu_hard_reset(&self) -> DiagServerResult<()> {
self.send_command_with_response(UdsCommand::ECUReset, &[ResetType::HardReset.into()])?;
Ok(())
}
/// Asks the ECU to perform a key off/on reset. See [ResetType::KeyOffReset] for more details
///
/// ## Parameters
/// * server - The UDS Diagnostic server
pub fn uds_ecu_key_off_on_reset(&self) -> DiagServerResult<()> {
self.send_command_with_response(UdsCommand::ECUReset, &[ResetType::KeyOffReset.into()])?;
Ok(())
}
/// Asks the ECU to perform a soft reset. See [ResetType::SoftReset] for more details
///
/// ## Parameters
/// * server - The UDS Diagnostic server
pub fn uds_ecu_soft_reset(&self) -> DiagServerResult<()> {
self.send_command_with_response(UdsCommand::ECUReset, &[ResetType::SoftReset.into()])?;
Ok(())
}
/// Asks the ECU to enable rapid power shutdown mode. See [ResetType::EnableRapidPowerShutDown] for more details
///
/// ## Parameters
/// * server - The UDS Diagnostic server
///
/// ## Returns
/// If successful, this function will return the minimum time in seconds that the ECU will remain in the power-down sequence
pub fn uds_enable_rapid_power_shutdown(&self) -> DiagServerResult<u8> {
let res = self.send_command_with_response(
UdsCommand::ECUReset,
&[ResetType::EnableRapidPowerShutDown.into()],
)?;
match res.get(2) {
Some(&time) if time == 0xFF => Err(DiagError::ECUError {
code: UdsError::GeneralReject.into(),
def: Some(Standard(UdsError::GeneralReject).desc()),
}), // General reject
Some(&time) => Ok(time),
None => Err(DiagError::InvalidResponseLength),
}
}
/// Asks the ECU to disable rapid power shutdown mode
///
/// ## Parameters
/// * server - The UDS Diagnostic server
pub fn uds_disable_rapid_power_shutdown(&self) -> DiagServerResult<()> {
self.send_command_with_response(
UdsCommand::ECUReset,
&[ResetType::DisableRapidPowerShutDown.into()],
)?;
Ok(())
}
}