AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
Loading...
Searching...
No Matches
can_identifier.hpp
Go to the documentation of this file.
1//================================================================================================
9//================================================================================================
10
11#ifndef CAN_IDENTIFIER_HPP
12#define CAN_IDENTIFIER_HPP
13
14#include <cstdint>
15
16namespace isobus
17{
18 //================================================================================================
22 //================================================================================================
24 {
25 public:
27 enum class CANPriority
28 {
30 Priority1 = 1,
31 Priority2 = 2,
32 Priority3 = 3,
33 Priority4 = 4,
34 Priority5 = 5,
37 };
38
40 enum class Type
41 {
42 Standard = 0,
43 Extended = 1
44 };
45
48 explicit CANIdentifier(std::uint32_t rawIdentifierData);
49
56 CANIdentifier(Type identifierType,
57 std::uint32_t pgn,
58 CANPriority priority,
59 std::uint8_t destinationAddress,
60 std::uint8_t sourceAddress);
61
63 ~CANIdentifier() = default;
64
67 std::uint32_t get_identifier() const;
68
72
75 std::uint32_t get_parameter_group_number() const;
76
80
83 std::uint8_t get_destination_address() const;
84
87 std::uint8_t get_source_address() const;
88
91 bool get_is_valid() const;
92
93 static constexpr std::uint32_t IDENTIFIER_TYPE_BIT_MASK = 0x80000000;
94 static constexpr std::uint32_t UNDEFINED_PARAMETER_GROUP_NUMBER = 0xFFFFFFFF;
95 static constexpr std::uint8_t GLOBAL_ADDRESS = 0xFF;
96 static constexpr std::uint8_t NULL_ADDRESS = 0xFE;
97
98 private:
99 static constexpr std::uint32_t BROADCAST_PGN_MASK = 0x0003FFFF;
100 static constexpr std::uint32_t DESTINATION_SPECIFIC_PGN_MASK = 0x0003FF00;
101 static constexpr std::uint32_t PDU2_FORMAT_MASK = 0x00F00000;
102 static constexpr std::uint8_t PARAMTER_GROUP_NUMBER_OFFSET = 8;
103 static constexpr std::uint8_t PRIORITY_DATA_BIT_OFFSET = 26;
104
105 std::uint32_t m_RawIdentifier;
106 };
107
108} // namespace isobus
109
110#endif // CAN_IDENTIFIER_HPP
A utility class that allows easy interpretation of a 32 bit CAN identifier.
static constexpr std::uint32_t DESTINATION_SPECIFIC_PGN_MASK
Destination specific PGNs mask the destination out of the PGN itself.
static constexpr std::uint32_t IDENTIFIER_TYPE_BIT_MASK
This bit denotes if the frame is standard or extended format.
static constexpr std::uint32_t UNDEFINED_PARAMETER_GROUP_NUMBER
A fake PGN used internally to denote a NULL PGN.
CANPriority
Defines all the CAN frame priorities that can be encoded in a frame ID.
@ PriorityHighest0
Highest CAN priority.
@ Priority3
Priority highest - 3 (Control messages priority)
@ Priority1
Priority highest - 1.
@ Priority4
Priority highest - 4.
@ PriorityLowest7
The lowest priority.
@ Priority2
Priority highest - 2.
@ PriorityDefault6
The default priority.
@ Priority5
Priority highest - 5.
static constexpr std::uint8_t NULL_ADDRESS
The NULL CAN address as defined by ISO11783.
std::uint32_t get_identifier() const
Returns the raw encoded ID of the CAN identifier.
std::uint8_t get_source_address() const
Returns the source address of the frame encoded in the identifier.
~CANIdentifier()=default
Destructor for the CANIdentifier.
CANPriority get_priority() const
Returns the priority of the frame encoded in the identifier.
CANIdentifier(std::uint32_t rawIdentifierData)
Constructor for a CAN Identifier class based on a raw 32 bit ID.
std::uint32_t get_parameter_group_number() const
Returns the PGN encoded in the identifier.
static constexpr std::uint8_t PARAMTER_GROUP_NUMBER_OFFSET
PGN is offset 8 bits into the ID.
static constexpr std::uint8_t PRIORITY_DATA_BIT_OFFSET
Priority is offset 26 bits into the ID.
static constexpr std::uint8_t GLOBAL_ADDRESS
The broadcast CAN address.
static constexpr std::uint32_t BROADCAST_PGN_MASK
Broadcast PGNs don't mask off the bits used for destination in the PGN.
Type get_identifier_type() const
Returns the identifier type (standard vs extended)
static constexpr std::uint32_t PDU2_FORMAT_MASK
Mask that denotes the ID as being PDU2 format.
Type
Defines if a frame is a standard (11 bit) or extended (29 bit) ID frame.
@ Standard
Frame is an 11bit ID standard (legacy) message with no PGN and highest priority.
@ Extended
Frame is a modern 29 bit ID CAN frame.
bool get_is_valid() const
Returns if the ID is valid based on some range checking.
std::uint32_t m_RawIdentifier
The raw encoded 29 bit ID.
std::uint8_t get_destination_address() const
Returns the destination address of the frame encoded in the identifier.
This namespace encompasses all of the ISO11783 stack's functionality to reduce global namespace pollu...