Skip to main content

J1939Id

Struct J1939Id 

Source
pub struct J1939Id { /* private fields */ }
Expand description

The fields a J1939 message packs into its 29-bit identifier.

§Examples

use pamoja_can::{CanId, J1939Id};

// The standard engine-speed broadcast, identifier 0x0CF00400.
let message = J1939Id::from_id(CanId::extended(0x0CF0_0400)).unwrap();
assert_eq!(message.priority(), 3);
assert_eq!(message.pgn(), 61_444);
assert_eq!(message.source(), 0x00);
assert!(message.is_broadcast());
assert_eq!(message.destination(), None);

Implementations§

Source§

impl J1939Id

Source

pub fn from_id(id: CanId) -> Option<J1939Id>

Decodes a J1939 identifier from an extended CAN identifier.

§Arguments
  • id - the CAN identifier to decode.
§Returns

The decoded fields, or None if id is a standard identifier, which J1939 does not use.

Source

pub fn broadcast(priority: u8, pgn: u32, source: u8) -> J1939Id

Builds the identifier for a message addressed to every node.

A broadcast parameter group has no destination, so this fills in BROADCAST_ADDRESS rather than making a caller remember it.

§Arguments
  • priority - the three-bit priority; priority names the usual ones.
  • pgn - the parameter group number the message belongs to.
  • source - the address of the node sending it.
§Returns

The identifier fields.

Source

pub fn from_parts( priority: u8, pgn: u32, source: u8, destination: u8, ) -> J1939Id

Composes a J1939 identifier from its fields.

§Arguments
  • priority - the message priority, masked to its low three bits.
  • pgn - the parameter group number.
  • source - the source address.
  • destination - the destination address, used only for an addressed (PDU1) parameter group and ignored for a broadcast (PDU2) one.
§Returns

The identifier fields.

Source

pub fn priority(&self) -> u8

Returns the message priority, 0 (highest) to 7.

§Returns

The priority.

Source

pub fn pgn(&self) -> u32

Returns the parameter group number, which names what the message carries.

§Returns

The PGN.

Source

pub fn source(&self) -> u8

Returns the source address: the node that sent the message.

§Returns

The source address.

Source

pub fn pdu_format(&self) -> u8

Returns the PDU format byte of the parameter group.

§Returns

The PDU format.

Source

pub fn destination(&self) -> Option<u8>

Returns the destination address, for an addressed message.

§Returns

The destination address for a PDU1 message, or None for a broadcast PDU2 one.

Source

pub fn is_broadcast(&self) -> bool

Reports whether the message is a broadcast.

§Returns

true for a broadcast (PDU2) message, false for an addressed (PDU1) one.

Source

pub fn to_id(&self) -> CanId

Composes the extended CAN identifier these fields describe.

§Returns

The extended CanId.

Trait Implementations§

Source§

impl Clone for J1939Id

Source§

fn clone(&self) -> J1939Id

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for J1939Id

Source§

impl Debug for J1939Id

Source§

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

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

impl Eq for J1939Id

Source§

impl PartialEq for J1939Id

Source§

fn eq(&self, other: &J1939Id) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for J1939Id

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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>,

Source§

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>,

Source§

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.