AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
Loading...
Searching...
No Matches
can_identifier.cpp
Go to the documentation of this file.
1//================================================================================================
9//================================================================================================
11
12namespace isobus
13{
14 CANIdentifier::CANIdentifier(std::uint32_t rawIdentifierData) :
15 m_RawIdentifier(rawIdentifierData)
16 {
17 }
18
20 std::uint32_t pgn,
21 CANPriority priority,
22 std::uint8_t destinationAddress,
23 std::uint8_t sourceAddress) :
24 m_RawIdentifier(0)
25 {
26 if (Type::Extended == identifierType)
27 {
28 m_RawIdentifier = (static_cast<std::uint32_t>(priority) << PRIORITY_DATA_BIT_OFFSET);
29
31 {
33 pgn = (pgn << PARAMTER_GROUP_NUMBER_OFFSET);
34 m_RawIdentifier |= pgn;
35 m_RawIdentifier |= (static_cast<std::uint32_t>(destinationAddress) << PARAMTER_GROUP_NUMBER_OFFSET);
36 }
37 else
38 {
40 }
41 }
42 m_RawIdentifier |= static_cast<std::uint32_t>(sourceAddress);
43 }
44
46 {
47 const std::uint8_t EXTENDED_IDENTIFIER_MASK = 0x07;
48
49 CANPriority retVal;
50
52 {
53 retVal = static_cast<CANPriority>((m_RawIdentifier >> PRIORITY_DATA_BIT_OFFSET) & EXTENDED_IDENTIFIER_MASK);
54 }
55 else
56 {
58 }
59 return retVal;
60 }
61
62 std::uint32_t CANIdentifier::get_identifier() const
63 {
65 }
66
68 {
69 const std::uint32_t STANDARD_ID_11_BIT_SIZE = 0x7FF;
70 Type retVal;
71
72 if (m_RawIdentifier <= STANDARD_ID_11_BIT_SIZE)
73 {
74 retVal = Type::Standard;
75 }
76 else
77 {
78 retVal = Type::Extended;
79 }
80 return retVal;
81 }
82
84 {
85 std::uint32_t retVal = UNDEFINED_PARAMETER_GROUP_NUMBER;
86
88 {
90 {
92 }
93 else
94 {
96 }
97 }
98 return retVal;
99 }
100
102 {
103 const std::uint8_t ADDRESS_BITS_SIZE = 0xFF;
104 const std::uint8_t ADDRESS_DATA_OFFSET = 8;
105
106 std::uint8_t retVal = GLOBAL_ADDRESS;
107
110 {
111 retVal = ((m_RawIdentifier >> ADDRESS_DATA_OFFSET) & ADDRESS_BITS_SIZE);
112 }
113 return retVal;
114 }
115
117 {
118 const std::uint8_t ADDRESS_BITS_SIZE = 0xFF;
119 std::uint8_t retVal = CANIdentifier::GLOBAL_ADDRESS;
120
122 {
123 retVal = (m_RawIdentifier & ADDRESS_BITS_SIZE);
124 }
125 return retVal;
126 }
127
129 {
130 const std::uint32_t EXTENDED_ID_29_BIT_SIZE = 0x1FFFFFFF;
131 const std::uint32_t STANDARD_ID_11_BIT_SIZE = 0x7FF;
132 bool retVal;
133
135 {
136 retVal = (m_RawIdentifier <= EXTENDED_ID_29_BIT_SIZE);
137 }
138 else
139 {
140 retVal = (m_RawIdentifier <= STANDARD_ID_11_BIT_SIZE);
141 }
142 return retVal;
143 }
144
145} // namespace isobus
A representation of a classical CAN identifier with utility functions for ectracting values that are ...
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.
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.
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...