MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / extractPGN

Function extractPGN

app/rcc/scripts/parser/js/nmea_2000.js:159–170  ·  view source on GitHub ↗

* Extracts the PGN from a 29-bit CAN identifier. * NMEA 2000 uses extended CAN IDs with PGN encoded in bits 8-25.

(canId)

Source from the content-addressed store, hash-verified

157 * NMEA 2000 uses extended CAN IDs with PGN encoded in bits 8-25.
158 */
159function extractPGN(canId) {
160 var pf = (canId >> 16) & 0xFF;
161 var ps = (canId >> 8) & 0xFF;
162 var dp = (canId >> 24) & 0x01;
163
164 // PDU1 (PF < 240): destination-specific, PGN excludes PS field
165 if (pf < 240)
166 return (dp << 16) | (pf << 8);
167
168 // PDU2 (PF >= 240): broadcast, PGN includes PS field
169 return (dp << 16) | (pf << 8) | ps;
170}
171
172//------------------------------------------------------------------------------
173// Frame Parser Function

Callers 1

parseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected