18 lines
579 B
C++
18 lines
579 B
C++
// SPDX-License-Identifier: MIT
|
|
#ifndef J1939_H
|
|
#define J1939_H
|
|
|
|
#include <cstdint>
|
|
|
|
/** Extract an 18-bit PGN from a normalized 29-bit ID explicitly interpreted as J1939.
|
|
* Priority and source address are excluded. PDU1 also excludes destination address.
|
|
* Both data-page bits are retained; this does not validate the J1939 protocol.
|
|
*/
|
|
inline std::uint32_t ExtractJ1939Pgn(std::uint32_t canId) {
|
|
const std::uint32_t pf = (canId >> 16U) & 0xFFU;
|
|
const std::uint32_t pgn = (canId >> 8U) & 0x3FFFFU;
|
|
return pf < 240U ? pgn & 0x3FF00U : pgn;
|
|
}
|
|
|
|
#endif /* J1939_H */
|