Skip to content

Commit

Permalink
Add SPN renaming and feature, define constants for PGN and PDU length…
Browse files Browse the repository at this point in the history
…s, and implement source address enum
  • Loading branch information
yorickdewid committed Feb 1, 2024
1 parent ee52e89 commit e662cc9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![deny(warnings)]
#![no_std]

// TODO: Rename to SPN
// TODO: Make this a feature
pub mod decode;

Expand All @@ -13,8 +14,15 @@ pub use pgn::*;
#[cfg(feature = "can")]
pub mod can;

/// Maximum number of bytes in a PGN.
pub const PGN_MAX_LENGTH: usize = 3;
/// Maximum number of bytes in a PDU.
pub const PDU_MAX_LENGTH: usize = 8;

/// ASCII delimiter for variable length fields.
pub const FIELD_DELIMITER: u8 = b'*';


/// Protocol Data Unit Format.
///
/// There are two different PDU formats. PDU1 format is used for sending messages with a specific
Expand Down Expand Up @@ -112,6 +120,7 @@ impl Id {
((self.0 >> 8) & 0xff).try_into().unwrap()
}

// TODO: Return the source address enum.
/// Device source address
pub fn sa(&self) -> u8 {
(self.0 & 0xff).try_into().unwrap()
Expand Down Expand Up @@ -280,6 +289,7 @@ impl FrameBuilder {
}

/// Set the frame ID.
#[inline]
pub fn id(mut self, id: Id) -> Self {
self.id = id;
self
Expand All @@ -296,6 +306,7 @@ impl FrameBuilder {
}

/// Set PDU length.
#[inline]
pub fn set_len(mut self, len: usize) -> Self {
self.pdu_length = len;
self
Expand Down
12 changes: 12 additions & 0 deletions src/pgn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub enum PGN {
ElectronicEngineController1,
/// EEC2 - Electronic Engine Controller 2.
ElectronicEngineController2,
/// TCO1 - Tachoraph.
Tachoraph,
/// SOFT - Software Identification.
SoftwareIdentification,
/// RQST - Request.
Expand All @@ -55,6 +57,10 @@ pub enum PGN {
AddressClaimed,
/// PropA - Proprietary A.
ProprietaryA,
// EBC1 - Electronic Brake Controller 1.
ElectronicBrakeController1,
/// ETC1 - Transmission Message 1.
TransmissionMessage1,
/// CA - Commanded Address.
CommandedAddress,
/// TD - Time / Date.
Expand Down Expand Up @@ -117,8 +123,11 @@ impl From<u32> for PGN {
60_416 => PGN::TransportProtocolConnectionManagement,
60_928 => PGN::AddressClaimed,
61_184 => PGN::ProprietaryA,
61_441 => PGN::ElectronicBrakeController1,
61_442 => PGN::TransmissionMessage1,
61_443 => PGN::ElectronicEngineController2,
61_444 => PGN::ElectronicEngineController1,
65_132 => PGN::Tachoraph,
65_240 => PGN::CommandedAddress,
65_242 => PGN::SoftwareIdentification,
65_254 => PGN::TimeDate,
Expand Down Expand Up @@ -160,8 +169,11 @@ impl From<PGN> for u32 {
PGN::TransportProtocolConnectionManagement => 60_416,
PGN::AddressClaimed => 60_928,
PGN::ProprietaryA => 61_184,
PGN::ElectronicBrakeController1 => 61_441,
PGN::TransmissionMessage1 => 61_442,
PGN::ElectronicEngineController1 => 61_444,
PGN::ElectronicEngineController2 => 61_443,
PGN::Tachoraph => 65_132,
PGN::CommandedAddress => 65_240,
PGN::SoftwareIdentification => 65_242,
PGN::TimeDate => 65_254,
Expand Down

0 comments on commit e662cc9

Please sign in to comment.