pub struct DynamicDiagSession { /* private fields */ }
Expand description

Dynamic diagnostic session

This is used if a target ECU has an unknown diagnostic protocol.

This also contains some useful wrappers for basic functions such as reading and clearing error codes.

Implementations§

source§

impl DynamicDiagSession

source

pub fn new_over_iso_tp<P, NRC, L>( protocol: P, channel: Box<dyn IsoTPChannel>, channel_cfg: IsoTPSettings, basic_opts: DiagServerBasicOptions, advanced_opts: Option<DiagServerAdvancedOptions>, logger: L ) -> DiagServerResult<Self>
where P: DiagProtocol<NRC> + 'static, NRC: EcuNRC, L: DiagServerLogger + 'static,

Creates a new diagnostic server with a given protocol and NRC format over an ISO-TP connection

source

pub fn send_command<T: Into<u8>>( &self, cmd: T, args: &[u8] ) -> DiagServerResult<()>

Send a command

source

pub fn send_byte_array(&self, p: &[u8]) -> DiagServerResult<()>

Send a byte array

source

pub fn send_command_with_response<T: Into<u8>>( &self, cmd: T, args: &[u8] ) -> DiagServerResult<Vec<u8>>

Send a command to the ECU and await its response

source

pub fn send_byte_array_with_response( &self, p: &[u8] ) -> DiagServerResult<Vec<u8>>

Send bytes to the ECU and await its response

§Params
  • p - Raw byte array to send
  • on_ecu_waiting_hook - Callback to call when the ECU responds with ResponsePending. Can be used to update a programs state such that the user is aware the ECU is just processing the request
source

pub fn is_ecu_connected(&self) -> bool

Returns true only if a hardware failure has resulted in the ECU disconnecting from the diagnostic server.

source

pub fn register_waiting_hook<F: Fn() + 'static>(&mut self, hook: F)

Register a hook that will be called whenever the ECU has replyed with a ‘Busy’ or ‘Please wait’ response

source

pub fn register_send_complete_hook<F: Fn(&[u8]) + 'static>(&mut self, hook: F)

Register a hook that will be called whenever data has been sent out to the ECU successfully

source

pub fn get_current_diag_mode(&self) -> Option<DiagSessionMode>

Returns the current diagnostic session mode that the ECU is in

source§

impl DynamicDiagSession

source

pub fn kwp_clear_dtc_range( &self, dtc_range: ClearDTCRange ) -> DiagServerResult<()>

Executes a DTC clear command on the ECU, given a range of DTCs to clear

source§

impl DynamicDiagSession

source

pub fn kwp_reset_ecu(&self, mode: ResetType) -> DiagServerResult<()>

Performs an ECU Reset operation

§Params
  • mode - [ResetMode] to send to the ECU
source§

impl DynamicDiagSession

source

pub fn kwp_disable_normal_message_transmission(&self) -> DiagServerResult<()>

Tells the ECU to switch off its normal communication paths with other ECUs. Normally message transmission will be resumed if the ECU looses power, or if [Kwp2000DiagnosticServer::enable_normal_message_transmission] is called.

NOTE: Calling this function can make a car go wild as it can no longer talk to the ECU being sent this command. Use with CAUTION!

source

pub fn kwp_enable_normal_message_transmission(&self) -> DiagServerResult<()>

Tells the ECU to re-enable its normal communication paths with other ECUs.

source§

impl DynamicDiagSession

source

pub fn kwp_read_data_by_identifier( &self, identifier: u16 ) -> DiagServerResult<Vec<u8>>

Reads ECU data using a given identifier

§Parameters
  • identifier - A 16 bit identifier to recall data from on the ECU
§Returns

If successful, this function returns the raw data stored at this identifier, without the identifier ID on the response itself.

source§

impl DynamicDiagSession

source

pub fn kwp_read_ecu_development_data(&self) -> DiagServerResult<DevelopmentData>

Reads development data from the ECU. NOT IMPLEMENTED YET (Will return DiagError::NotImplemented)

source

pub fn kwp_read_ecu_serial_number(&self) -> DiagServerResult<Vec<u8>>

Reads the ECU Serial number.

This function returns the bytes of just the serial number of the ECU, which can be interpreted as either ASCII (Daimler ECUs), or Model line specification (Varies from OEM to OEM)

source

pub fn kwp_read_ecu_dbcom_data(&self) -> DiagServerResult<DBComData>

Reads DBCom data from the ECU. NOT IMPLEMENTED YET (Will return DiagError::NotImplemented)

source

pub fn kwp_read_ecu_os_version(&self) -> DiagServerResult<String>

Reads the Operating system version on the ECU. NOT IMPLEMENTED YET (Will return DiagError::NotImplemented)

source

pub fn kwp_read_ecu_reprogramming_fault_report( &self ) -> DiagServerResult<Vec<u8>>

Reads reprogramming fault report. The format is binary. This is to be interpreted by GSP/SDE.

source

pub fn kwp_read_ecu_vehicle_info(&self) -> DiagServerResult<VehicleInfo>

Reads vehicle information from the ECU. NOT IMPLEMENTED YET (Will return DiagError::NotImplemented)

source

pub fn kwp_read_ecu_flash_info_1(&self) -> DiagServerResult<Vec<u8>>

Reads flash data from block 1. NOT IMPLEMENTED YET (Will return DiagError::NotImplemented)

source

pub fn kwp_read_ecu_flash_info_2(&self) -> DiagServerResult<Vec<u8>>

Reads flash data from block 2. NOT IMPLEMENTED YET (Will return DiagError::NotImplemented)

source

pub fn kwp_read_system_diag_general_param_data( &self ) -> DiagServerResult<DiagGeneralParamData>

Reads general diagnostic parameter data from the ECU (SDCOM). NOT IMPLEMENTED YET (Will return DiagError::NotImplemented)

source

pub fn kwp_read_system_diag_global_param_data( &self ) -> DiagServerResult<DiagGlobalParamData>

Reads global diagnostic parameter data from the ECU. NOT IMPLEMENTED YET (Will return DiagError::NotImplemented)

source

pub fn kwp_read_ecu_configuration(&self) -> DiagServerResult<Vec<u8>>

Reads the ECU’s current configuration status. NOT IMPLEMENTED YET (Will return DiagError::NotImplemented)

source

pub fn kwp_read_diag_protocol_info(&self) -> DiagServerResult<DiagProtocolInfo>

Reads ECU protocol information. NOT IMPLEMENTED YET (Will return DiagError::NotImplemented)

source

pub fn kwp_read_custom_local_identifier( &self, local_identifier: u8 ) -> DiagServerResult<Vec<u8>>

Reads data from a custom local identifier

§Supported local identifier ranges
  • 0x01-0x7F - Record local identifier
  • 0xA0-0xDF - Record local identifier
  • 0xF0-0xF9 - Dynamically defined local identifier
§Important notes:
  1. If the ECU supports commands for identification purposes, then asking for an identifier in the range of 0x86-0x9F will return ECU ident data.
source§

impl DynamicDiagSession

source

pub fn kwp_read_stored_dtcs_iso15031( &self, range: DTCRange ) -> DiagServerResult<Vec<DTC>>

Returns a list of stored DTCs on the ECU in ISO15031-6 format

source

pub fn kwp_read_supported_dtcs_iso15031( &self, range: DTCRange ) -> DiagServerResult<Vec<DTC>>

Returns a list of all supported DTCs on the ECU regardless of their status in ISO15031-6 format

source

pub fn kwp_read_stored_dtcs( &self, range: DTCRange ) -> DiagServerResult<Vec<DTC>>

Returns a list of stored DTCs on the ECU in KWP2000 format

source

pub fn kwp_read_supported_dtcs( &self, range: DTCRange ) -> DiagServerResult<Vec<DTC>>

Returns a list of all supported DTCs on the ECU regardless of their status, in KWP2000 format.

NOTE: Internally, this function will call [Kwp2000DiagnosticServer::read_extended_supported_dtcs] in a loop in order to read all DTCs regardless of transport layer limitations

source

pub fn kwp_get_most_recent_dtc( &self, range: DTCRange ) -> DiagServerResult<Option<DTC>>

Asks the ECU to report its most recent DTCs that has been stored. Only one DTC is returned if stored, otherwise no DTC is returned.

source

pub fn kwp_read_extended_supported_dtcs( &self, range: DTCRange ) -> DiagServerResult<u16>

Upon execution of [Kwp2000DiagnosticServer::read_supported_dtcs] or [Kwp2000DiagnosticServer::read_supported_dtcs_iso15031], if the transport layer restricts the number of DTCs that can be read, or the number of DTCs exceeds 255, then this function will return the number of remaining supported of DTCs to read. [Kwp2000DiagnosticServer::read_supported_dtcs] or [Kwp2000DiagnosticServer::read_supported_dtcs_iso15031] should be executed to read the rest of the DTCs again within the ECUs P3-MAX time window

source§

impl DynamicDiagSession

source

pub fn kwp_read_daimler_identification( &self ) -> DiagServerResult<DaimlerEcuIdent>

Reads Daimler ECU identification from ECU

source

pub fn kwp_read_daimler_mmc_identification( &self ) -> DiagServerResult<DaimlerMmcEcuIdent>

Reads Daimler and MMC ECU identification from ECU

source

pub fn kwp_read_original_vin(&self) -> DiagServerResult<String>

Reads the original VIN programmed onto the ECU from the manufacturer

source

pub fn kwp_read_diagnostic_variant_code(&self) -> DiagServerResult<u32>

Reads the unique diagnostic variant code of the ECU

source

pub fn kwp_read_current_vin(&self) -> DiagServerResult<String>

Reads the current VIN stored on the ECU

source

pub fn kwp_read_calibration_id(&self) -> DiagServerResult<String>

Reads the OBD Calibration ID from the ECU.

source

pub fn kwp_read_cvn(&self) -> DiagServerResult<[u8; 4]>

Reads the calibration verification number from the ECU

source

pub fn kwp_read_ecu_code_fingerprint( &self ) -> DiagServerResult<ModuleInformation>

Reads module information from the ECU’s code block

source

pub fn kwp_read_ecu_data_fingerprint( &self ) -> DiagServerResult<ModuleInformation>

Reads module information from the ECU’s data block

source

pub fn kwp_read_ecu_code_software_id( &self ) -> DiagServerResult<SoftwareBlockIdentification>

Reads code identification information from the ECU’s code block

source

pub fn kwp_read_ecu_data_software_id( &self ) -> DiagServerResult<SoftwareBlockIdentification>

Reads code identification information from the ECU’s data block

source

pub fn kwp_read_ecu_boot_software_id( &self ) -> DiagServerResult<SoftwareBlockIdentification>

Reads code identification information from the ECU’s boot block

source

pub fn kwp_read_ecu_boot_fingerprint( &self ) -> DiagServerResult<ModuleInformation>

Reads code identification information from the ECU’s boot block

source§

impl DynamicDiagSession

source

pub fn kwp_read_memory( &self, address: u32, size: u8 ) -> DiagServerResult<Vec<u8>>

Reads the contents of RAM memory on the ECU given a 3 byte address, and 1 byte size. The maximum value for address is 0xFFFFFF, any larger values will be clamped.

NOTE: This function is ONLY indented for ECU development. In production ECUs, use [Kwp2000DiagnosticServer::read_custom_local_identifier] instead

source§

impl DynamicDiagSession

source

pub fn kwp_read_status_of_dtc(&self, dtc: u16) -> DiagServerResult<Vec<u8>>

Reads the status of a given DTC.

This function returns bytes rather than a processed result as the environmental data varies from DTC to DTC and from ECU to ECU, so it is impossible to know what the data returned actually means.

§Returns

This function if successful will return the full ECUs response message without any additional processing.

The first 4 bytes of the response are as follows:

  1. DTC Number (Stored on ECU)
  2. DTC High byte
  3. DTC Low byte
  4. Status of DTC
source§

impl DynamicDiagSession

source

pub fn kwp_request_seed(&self, access_mode: u8) -> DiagServerResult<Vec<u8>>

Requests a seed from the ECU

§Parameters
  • server - The KWP2000 server
  • access_mode - The access mode. Only odd numbers between 0x01-0x7F are supported for the access level!
§Returns

This function will return an error if the access_mode parameter is not a valid mode! If the function succeeds, then just the ECUs key response is returned

source

pub fn kwp_unlock_ecu_with_key( &self, access_mode: u8, key: &[u8] ) -> DiagServerResult<()>

Attempts to unlock the access mode to the ECU, using a computed key using the seed provided with [Kwp2000DiagnosticServer::request_seed]

§Parameters
  • server - The KWP2000 server
  • access_mode - The access mode. Only odd numbers between 0x01-0x7F are supported for the access level!
§Returns

This function will return an error if the access_mode parameter is not a valid mode! The access_mode should be THE SAME as what was provided to [Kwp2000DiagnosticServer::request_seed]

source§

impl DynamicDiagSession

source

pub fn kwp_set_session(&self, mode: KwpSessionTypeByte) -> DiagServerResult<()>

Set KWP session mode

source§

impl DynamicDiagSession

source

pub fn obd_init_service_01(&self) -> DiagServerResult<Service01<'_>>

Initializes the service 01 wrapper. Automatically query’s the ECU on init for supported PIDs. NOTE: Unlike other functions, if this function encounters a ECU communication error, it will still return OK.

source§

impl DynamicDiagSession

source

pub fn obd_init_service_09(&self) -> DiagServerResult<Service09<'_>>

Initializes the service 09 wrapper. Automatically query’s the ECU on init for supported PIDs

source§

impl DynamicDiagSession

source

pub fn uds_clear_diagnostic_information( &self, dtc_mask: u32 ) -> DiagServerResult<()>

Clears diagnostic information (DTCs) from the ECU.

§Parameters
  • server - The UDS Diagnostic server
  • dtc_mask - Mask of DTCs to clear. Only the lower 3 bytes are used (from 0x00000000 - 0x00FFFFFF)
source§

impl DynamicDiagSession

source

pub fn uds_control_communication( &self, communication_type: EcuCommunicationType, subnet: Subnet, comm_level: CommunicationLevel ) -> DiagServerResult<()>

Modifies ECU communication settings. These settings persist until the ECU is power cycled

§Parameters
  • server - The UDS diagnostic server
  • communication_type - Communication layer to modify
  • Subnet - The subnet the ECU communicates with to modify
  • comm_level - Communication level
source§

impl DynamicDiagSession

source

pub fn uds_set_session_mode( &self, session_mode: UdsSessionTypeByte ) -> DiagServerResult<()>

Requests the ECU to go into a specific diagnostic session mode

source§

impl DynamicDiagSession

source

pub fn uds_ecu_hard_reset(&self) -> DiagServerResult<()>

Asks the ECU to perform a hard reset. See ResetType::HardReset for more details

§Parameters
  • server - The UDS Diagnostic server
source

pub fn uds_ecu_key_off_on_reset(&self) -> DiagServerResult<()>

Asks the ECU to perform a key off/on reset. See ResetType::KeyOffReset for more details

§Parameters
  • server - The UDS Diagnostic server
source

pub fn uds_ecu_soft_reset(&self) -> DiagServerResult<()>

Asks the ECU to perform a soft reset. See ResetType::SoftReset for more details

§Parameters
  • server - The UDS Diagnostic server
source

pub fn uds_enable_rapid_power_shutdown(&self) -> DiagServerResult<u8>

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

source

pub fn uds_disable_rapid_power_shutdown(&self) -> DiagServerResult<()>

Asks the ECU to disable rapid power shutdown mode

§Parameters
  • server - The UDS Diagnostic server
source§

impl DynamicDiagSession

source

pub fn uds_get_number_of_dtcs_by_status_mask( &self, status_mask: u8 ) -> DiagServerResult<(u8, DTCFormatType, u16)>

Returns the number of DTCs stored on the ECU matching the provided status_mask

§Returns

Returns a tuple of the given information:

  1. (u8) - DTCStatusAvailabilityMask
  2. (DTCFormatType) - Format of the DTCs
  3. (u16) - Number of DTCs which match the status mask
source

pub fn uds_get_dtcs_by_status_mask( &self, status_mask: u8 ) -> DiagServerResult<Vec<DTC>>

Returns a list of DTCs stored on the ECU matching the provided status_mask

source

pub fn uds_get_mirror_memory_dtcs_by_status_mask( &self, status_mask: u8 ) -> DiagServerResult<Vec<DTC>>

Returns a list of DTCs out of the DTC mirror memory who’s status_mask matches the provided mask

source

pub fn uds_get_number_of_mirror_memory_dtcs_by_status_mask( &self, status_mask: u8 ) -> DiagServerResult<(u8, DTCFormatType, u16)>

Returns the number of DTCs in DTC mirror memory who’s status_mask matches the provided mask

§Returns

Returns a tuple of the given information:

  1. (u8) - DTCStatusAvailabilityMask
  2. (DTCFormatType) - Format of the DTCs
  3. (u16) - Number of DTCs which match the status mask

Returns the number of OBD emissions related DTCs stored on the ECU who’s status mask matches the provided masks

§Returns

Returns a tuple of the given information:

  1. (u8) - DTCStatusAvailabilityMask
  2. (DTCFormatType) - Format of the DTCs
  3. (u16) - Number of DTCs which match the status mask

Returns a list of OBD emissions related DTCs stored on the ECU who’s status mask matches the provided mask

source

pub fn uds_get_dtc_snapshot_record_by_dtc_number( &self, dtc_mask_record: u32, snapshot_record_number: u8 ) -> DiagServerResult<u32>

source

pub fn uds_get_dtc_snapshot_identification(&self) -> DiagServerResult<u32>

Returns all DTC snapshot identifications (DTC number(s) and DTCSnapshot record number(s))

source

pub fn uds_get_dtc_snapshot_record_by_record_number( &self, snapshot_record_number: u8 ) -> DiagServerResult<u32>

Returns a list of snapshot records based on the mask of snapshot_record_number (0xFF for all records)

source

pub fn uds_get_dtc_extended_data_record_by_dtc_number( &self, dtc: u32, extended_data_record_number: u8 ) -> DiagServerResult<Vec<u8>>

Returns the DTCExtendedData record(s) associated with the provided DTC mask and record number. For the record_number, 0xFE implies all OBD records. and 0xFF implies all records.

§Returns

This function will return the ECUs full response if successful

source

pub fn uds_get_mirror_memory_dtc_extended_data_record_by_dtc_number( &self, dtc: u32, extended_data_record_number: u8 ) -> DiagServerResult<Vec<u8>>

Returns a list of extended data records stored in DTC mirror memory for a given DTC. 0xFF for extended_data_record means return all extended data records.

§Returns

This function will return the ECUs full response if successful

source

pub fn uds_get_number_of_dtcs_by_severity_mask_record( &self, severity_mask: u8, status_mask: u8 ) -> DiagServerResult<u32>

Returns the number of DTCs stored on the ECU that match the provided severity and status mask

source

pub fn uds_get_dtcs_by_severity_mask_record( &self, severity_mask: u8, status_mask: u8 ) -> DiagServerResult<Vec<DTC>>

Returns a list of DTCs who’s severity mask matches the provided mask

source

pub fn uds_get_severity_information_of_dtc( &self, dtc: u32 ) -> DiagServerResult<u32>

Returns the severity status of a provided DTC

source

pub fn uds_get_supported_dtc(&self) -> DiagServerResult<Vec<DTC>>

Returns a list of all DTCs that the ECU can return

source

pub fn uds_get_first_test_failed_dtc(&self) -> DiagServerResult<Option<DTC>>

Returns the first failed DTC to be detected since the last DTC clear operation

source

pub fn uds_get_first_confirmed_dtc(&self) -> DiagServerResult<Option<DTC>>

Returns the first confirmed DTC to be detected since the last DTC clear operation

source

pub fn uds_get_most_recent_test_failed_dtc( &self ) -> DiagServerResult<Option<DTC>>

Returns the most recent DTC to be detected since the last DTC clear operation

source

pub fn uds_get_most_recent_confirmed_dtc(&self) -> DiagServerResult<Option<DTC>>

Returns the most recent DTC to be detected since the last DTC clear operation

source

pub fn uds_get_dtc_fault_detection_counter( &self ) -> DiagServerResult<Vec<(u32, u8)>>

Returns the current number of ‘pre-failed’ DTCs on the ECU, which have not yet been confirmed as being either ‘pending’ or ‘confirmed’

§Returns

This function will return a vector of information, where each element is a tuple containing the following values:

  1. (u32) - DTC Code
  2. (u8) - Fault detection counter
source

pub fn uds_get_dtc_with_permanent_status(&self) -> DiagServerResult<Vec<DTC>>

Returns a list of DTCs that have a permanent status

source§

impl DynamicDiagSession

source

pub fn uds_request_seed(&self) -> DiagServerResult<Vec<u8>>

Requests a seed from the ECU for security access.

Once the key is calculated from the response seed, run [UdsDiagnosticServer::send_key] to send the computed key to the ECU

§Parameters
  • server - The UDS Diagnostic server
§Returns

Returns the security key’s seed

source

pub fn uds_send_key(&self, key: &[u8]) -> DiagServerResult<()>

Sends the computed key to the ECU.

If this function is successful, then the ECU has now allows access to security protected memory regions and functions

§Parameters
  • server - The UDS Diagnostic server
  • key - The computed key to send to the ECU

Trait Implementations§

source§

impl Debug for DynamicDiagSession

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for DynamicDiagSession

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Send for DynamicDiagSession

source§

impl Sync for DynamicDiagSession

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.