Skip to content

Commit 5ec2e7f

Browse files
authored
feat: add several new UDS enums (#85)
* `DataDefinitionType` * `DtcSettingType` * `FileTransferMode` * `InputOutputControlParameter` * `LinkControlType` * `PeriodicTransmissionMode`
1 parent 03339a4 commit 5ec2e7f

9 files changed

Lines changed: 215 additions & 9 deletions

src/doip/protocol_version.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ python_test!(doip, ProtocolVersion, V2010, V2012);
2222
#[cfg_attr(feature = "pyo3", pyo3::pyclass(eq, eq_int, from_py_object))]
2323
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2424
pub enum ProtocolVersion {
25-
// TODO: needed? This seems like a placeholder that shouldn't be used in Rust
26-
// /// Reserved Version
27-
// ReservedVer = 0x00,
2825
/// `DoIP` Payload Version: ISO-13400 2010 Version
2926
V2010 = 0x01,
3027

@@ -36,9 +33,6 @@ pub enum ProtocolVersion {
3633

3734
/// `DoIP` Payload Version: ISO-13400 `2019_AMD1` Version
3835
V2019amd1 = 0x04,
39-
// TODO: needed? This seems like a placeholder that shouldn't be used in Rust
40-
// /// `DoIP` Payload Version: Default Version
41-
// DefaultValue = 0xFF,
4236
}
4337

4438
#[cfg(all(test, feature = "serde"))]

src/uds/commands.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use crate::utils::{enum_wrapper, python_test};
22

3-
enum_wrapper!(uds, UdsCommand, UdsCommandByte, display = @"10111100423397497463");
3+
// The display constant ensures we do not accidentally change doc strings below.
4+
// We treat them as display strings too, so a change to the first line of the doc str is a code change.
5+
// Use `just bless` to update the expected value.
6+
enum_wrapper!(uds, UdsCommand, UdsCommandByte, display = @"2468007968532925220");
47
python_test!(uds, UdsCommand, DiagnosticSessionControl, ECUReset);
58

69
/// UDS Command Service IDs
@@ -16,24 +19,31 @@ python_test!(uds, UdsCommand, DiagnosticSessionControl, ECUReset);
1619
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1720
pub enum UdsCommand {
1821
/// The client requests to control a diagnostic session with a server(s).
22+
/// See also [`crate::uds::UdsSessionType`].
1923
DiagnosticSessionControl = 0x10,
2024
/// The client forces the server(s) to perform a reset.
25+
/// See also [`crate::uds::ResetType`].
2126
ECUReset = 0x11,
2227
/// The client requests to unlock a secured server(s).
28+
/// See also [`crate::uds::SecurityOperation`].
2329
SecurityAccess = 0x27,
2430
/// The client controls the setting of communication parameters in the server (e.g. communication baud-rate).
31+
/// See also [`crate::uds::CommunicationLevel`].
2532
CommunicationControl = 0x28,
2633
/// The client indicates to the server(s) that it is still present.
2734
TesterPresent = 0x3E,
2835
/// The client requests to access the server(s) with a specific access mode.
36+
/// See also [`crate::uds::AuthenticationSubFunction`].
2937
Authentication = 0x29,
3038
/// The client uses this service to perform data transmission with an extended data link security.
3139
SecuredDataTransmission = 0x84,
3240
/// The client controls the setting of DTCs in the server.
41+
/// See also [`crate::uds::DtcSettingType`].
3342
ControlDTCSetting = 0x85,
3443
/// The client requests to set up and/or control an event mechanism in the server.
3544
ResponseOnEvent = 0x86,
3645
/// The client requests control of the communication baud-rate.
46+
/// See also [`crate::uds::LinkControlType`].
3747
LinkControl = 0x87,
3848
/// The client requests to read the current value of a record identified by a provided dataIdentifier.
3949
ReadDataByIdentifier = 0x22,
@@ -42,8 +52,10 @@ pub enum UdsCommand {
4252
/// The client requests to read the scaling information of a record identified by a provided dataIdentifier.
4353
ReadScalingDataByIdentifier = 0x24,
4454
/// The client requests to schedule data in the server for periodic transmission.
55+
/// See also [`crate::uds::PeriodicTransmissionMode`].
4556
ReadDataByPeriodicIdentifier = 0x2A,
46-
/// The client requests to dynamically define data Identifiers that may subsequently be read by the [`UdsCommand::ReadDataByIdentifier`] service.
57+
/// The client requests to dynamically define data identifiers that may subsequently be read by the `ReadDataByIdentifier` service.
58+
/// See also [`UdsCommand::ReadDataByIdentifier`] and [`crate::uds::DataDefinitionType`].
4759
DynamicallyDefineDataIdentifier = 0x2C,
4860
/// The client requests to write a record specified by a provided dataIdentifier.
4961
WriteDataByIdentifier = 0x2E,
@@ -52,10 +64,13 @@ pub enum UdsCommand {
5264
/// Allows the client to clear diagnostic information from the server (including DTCs, captured data, etc.).
5365
ClearDiagnosticInformation = 0x14,
5466
/// Allows the client to request diagnostic information from the server (including DTCs, captured data, etc.).
67+
/// See also [`crate::uds::DtcSubFunction`].
5568
ReadDTCInformation = 0x19,
5669
/// The client requests the control of an input/output specific to the server.
70+
/// See also [`crate::uds::InputOutputControlParameter`].
5771
InputOutputControlByIdentifier = 0x2F,
58-
/// The client requests to start, stop a routine in the server(s) or requests the routine results. See also [`crate::uds::RoutineControlType`].
72+
/// The client requests to start, stop a routine in the server(s) or requests the routine results.
73+
/// See also [`crate::uds::RoutineControlType`].
5974
RoutineControl = 0x31,
6075
/// The client requests the negotiation of a data transfer from the client to the server.
6176
RequestDownload = 0x34,
@@ -66,6 +81,7 @@ pub enum UdsCommand {
6681
/// The client requests the termination of a data transfer.
6782
RequestTransferExit = 0x37,
6883
/// The client requests the negotiation of a file transfer between server and client.
84+
/// See also [`crate::uds::FileTransferMode`].
6985
RequestFileTransfer = 0x38,
7086
}
7187

src/uds/data_definition_type.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use crate::utils::{enum_wrapper, python_test};
2+
3+
enum_wrapper!(uds, DataDefinitionType, DataDefinitionTypeByte);
4+
python_test!(
5+
uds,
6+
DataDefinitionType,
7+
DefineByIdentifier,
8+
ClearDynamicallyDefinedDataIdentifier
9+
);
10+
11+
/// [`UdsCommand::DynamicallyDefineDataIdentifier`](crate::uds::UdsCommand::DynamicallyDefineDataIdentifier) sub-function definitions
12+
#[repr(u8)]
13+
#[derive(strum::FromRepr, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
14+
#[cfg_attr(feature = "bin-proto", derive(bin_proto::BitEncode))]
15+
#[cfg_attr(feature = "bin-proto", derive(bin_proto::BitDecode))]
16+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
17+
#[cfg_attr(feature = "iter", derive(strum::EnumIter))]
18+
#[cfg_attr(feature = "pyo3", pyo3::pyclass(eq, eq_int, from_py_object))]
19+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
20+
pub enum DataDefinitionType {
21+
/// Defines the dynamic data identifier via a reference to an existing data identifier
22+
DefineByIdentifier = 0x01,
23+
24+
/// Defines the dynamic data identifier via an absolute memory address and length
25+
DefineByMemoryAddress = 0x02,
26+
27+
/// Clears the specified dynamically defined data identifier; the server responds positively
28+
/// even if the identifier does not currently exist
29+
ClearDynamicallyDefinedDataIdentifier = 0x03,
30+
}

src/uds/dtc_setting_type.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use crate::utils::{enum_wrapper, python_test};
2+
3+
enum_wrapper!(uds, DtcSettingType, DtcSettingTypeByte);
4+
python_test!(uds, DtcSettingType, On, Off);
5+
6+
/// [`UdsCommand::ControlDTCSetting`](crate::uds::UdsCommand::ControlDTCSetting) sub-function definitions
7+
#[repr(u8)]
8+
#[derive(strum::FromRepr, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
9+
#[cfg_attr(feature = "bin-proto", derive(bin_proto::BitEncode))]
10+
#[cfg_attr(feature = "bin-proto", derive(bin_proto::BitDecode))]
11+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
12+
#[cfg_attr(feature = "iter", derive(strum::EnumIter))]
13+
#[cfg_attr(feature = "pyo3", pyo3::pyclass(eq, eq_int, from_py_object))]
14+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
15+
pub enum DtcSettingType {
16+
/// Resumes the updating of DTC status bits according to normal operating conditions
17+
On = 0x01,
18+
19+
/// Stops the updating of DTC status bits in the server
20+
Off = 0x02,
21+
}

src/uds/file_transfer_mode.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use crate::utils::{enum_wrapper, python_test};
2+
3+
enum_wrapper!(uds, FileTransferMode, FileTransferModeByte);
4+
python_test!(uds, FileTransferMode, AddFile, ReadFile);
5+
6+
/// `modeOfOperation` data-parameter for
7+
/// [`UdsCommand::RequestFileTransfer`](crate::uds::UdsCommand::RequestFileTransfer)
8+
#[repr(u8)]
9+
#[derive(strum::FromRepr, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
10+
#[cfg_attr(feature = "bin-proto", derive(bin_proto::BitEncode))]
11+
#[cfg_attr(feature = "bin-proto", derive(bin_proto::BitDecode))]
12+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
13+
#[cfg_attr(feature = "iter", derive(strum::EnumIter))]
14+
#[cfg_attr(feature = "pyo3", pyo3::pyclass(eq, eq_int, from_py_object))]
15+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
16+
pub enum FileTransferMode {
17+
/// Downloads (adds) a new file to the server at the path specified by `filePathAndName`
18+
AddFile = 0x01,
19+
20+
/// Deletes the file at the path specified by `filePathAndName` from the server
21+
DeleteFile = 0x02,
22+
23+
/// Downloads and replaces the file at the path specified by `filePathAndName`;
24+
/// adds the file if it does not already exist on the server
25+
ReplaceFile = 0x03,
26+
27+
/// Uploads (reads) the file at the path specified by `filePathAndName` from the server
28+
ReadFile = 0x04,
29+
30+
/// Reads the directory listing at the path specified by `filePathAndName` from the server;
31+
/// `filePathAndName` indicates a directory, not a file name
32+
ReadDir = 0x05,
33+
34+
/// Resumes a previously interrupted file download at the file position returned by the server
35+
ResumeFile = 0x06,
36+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use crate::utils::{enum_wrapper, python_test};
2+
3+
enum_wrapper!(
4+
uds,
5+
InputOutputControlParameter,
6+
InputOutputControlParameterByte
7+
);
8+
python_test!(
9+
uds,
10+
InputOutputControlParameter,
11+
ReturnControlToEcu,
12+
ShortTermAdjustment
13+
);
14+
15+
/// `inputOutputControlParameter` data-parameter for
16+
/// [`UdsCommand::InputOutputControlByIdentifier`](crate::uds::UdsCommand::InputOutputControlByIdentifier)
17+
#[repr(u8)]
18+
#[derive(strum::FromRepr, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
19+
#[cfg_attr(feature = "bin-proto", derive(bin_proto::BitEncode))]
20+
#[cfg_attr(feature = "bin-proto", derive(bin_proto::BitDecode))]
21+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
22+
#[cfg_attr(feature = "iter", derive(strum::EnumIter))]
23+
#[cfg_attr(feature = "pyo3", pyo3::pyclass(eq, eq_int, from_py_object))]
24+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
25+
pub enum InputOutputControlParameter {
26+
/// Returns control of the input/output signals referenced by the dataIdentifier back to the ECU
27+
ReturnControlToEcu = 0x00,
28+
29+
/// Resets the input/output signals referenced by the dataIdentifier to their default state
30+
ResetToDefault = 0x01,
31+
32+
/// Freezes the current state of the input/output signals referenced by the dataIdentifier
33+
FreezeCurrentState = 0x02,
34+
35+
/// Adjusts the input/output signals referenced by the dataIdentifier to the values
36+
/// provided in the `controlState` bytes of the `controlOptionRecord`
37+
ShortTermAdjustment = 0x03,
38+
}

src/uds/link_control_type.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use crate::utils::{enum_wrapper, python_test};
2+
3+
enum_wrapper!(uds, LinkControlType, LinkControlTypeByte);
4+
python_test!(
5+
uds,
6+
LinkControlType,
7+
VerifyModeTransitionWithFixedParameter,
8+
TransitionMode
9+
);
10+
11+
/// [`UdsCommand::LinkControl`](crate::uds::UdsCommand::LinkControl) sub-function definitions
12+
#[repr(u8)]
13+
#[derive(strum::FromRepr, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
14+
#[cfg_attr(feature = "bin-proto", derive(bin_proto::BitEncode))]
15+
#[cfg_attr(feature = "bin-proto", derive(bin_proto::BitDecode))]
16+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
17+
#[cfg_attr(feature = "iter", derive(strum::EnumIter))]
18+
#[cfg_attr(feature = "pyo3", pyo3::pyclass(eq, eq_int, from_py_object))]
19+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
20+
pub enum LinkControlType {
21+
/// Verifies whether a mode transition with a predefined parameter,
22+
/// specified by the `linkControlModeIdentifier` data-parameter, can be performed
23+
VerifyModeTransitionWithFixedParameter = 0x01,
24+
25+
/// Verifies whether a mode transition with a specific parameter,
26+
/// specified by the `linkRecord` data-parameter, can be performed
27+
VerifyModeTransitionWithSpecificParameter = 0x02,
28+
29+
/// Requests the server to transition the data link into the mode verified in the preceding request
30+
TransitionMode = 0x03,
31+
}

src/uds/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ mod authentication;
44
mod comm_control;
55
mod comm_level;
66
mod commands;
7+
mod data_definition_type;
8+
mod dtc_setting_type;
79
mod errors;
10+
mod file_transfer_mode;
11+
mod input_output_control_parameter;
12+
mod link_control_type;
13+
mod periodic_transmission_mode;
814
mod read_dtc_information;
915
mod reset_types;
1016
mod routine;
@@ -17,7 +23,13 @@ pub use authentication::*;
1723
pub use comm_control::*;
1824
pub use comm_level::*;
1925
pub use commands::*;
26+
pub use data_definition_type::*;
27+
pub use dtc_setting_type::*;
2028
pub use errors::*;
29+
pub use file_transfer_mode::*;
30+
pub use input_output_control_parameter::*;
31+
pub use link_control_type::*;
32+
pub use periodic_transmission_mode::*;
2133
pub use read_dtc_information::*;
2234
pub use reset_types::*;
2335
pub use routine::*;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use crate::utils::{enum_wrapper, python_test};
2+
3+
enum_wrapper!(uds, PeriodicTransmissionMode, PeriodicTransmissionModeByte);
4+
python_test!(uds, PeriodicTransmissionMode, SendAtSlowRate, StopSending);
5+
6+
/// `transmissionMode` data-parameter for
7+
/// [`UdsCommand::ReadDataByPeriodicIdentifier`](crate::uds::UdsCommand::ReadDataByPeriodicIdentifier)
8+
#[repr(u8)]
9+
#[derive(strum::FromRepr, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
10+
#[cfg_attr(feature = "bin-proto", derive(bin_proto::BitEncode))]
11+
#[cfg_attr(feature = "bin-proto", derive(bin_proto::BitDecode))]
12+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
13+
#[cfg_attr(feature = "iter", derive(strum::EnumIter))]
14+
#[cfg_attr(feature = "pyo3", pyo3::pyclass(eq, eq_int, from_py_object))]
15+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
16+
pub enum PeriodicTransmissionMode {
17+
/// Requests periodic transmission at a slow, vehicle manufacturer-defined rate
18+
SendAtSlowRate = 0x01,
19+
20+
/// Requests periodic transmission at a medium, vehicle manufacturer-defined rate
21+
SendAtMediumRate = 0x02,
22+
23+
/// Requests periodic transmission at a fast, vehicle manufacturer-defined rate
24+
SendAtFastRate = 0x03,
25+
26+
/// Stops the server from periodically transmitting the specified data record(s)
27+
StopSending = 0x04,
28+
}

0 commit comments

Comments
 (0)