* Extracts the PGN from a 29-bit CAN identifier. * NMEA 2000 uses extended CAN IDs with PGN encoded in bits 8-25.
(canId)
| 157 | * NMEA 2000 uses extended CAN IDs with PGN encoded in bits 8-25. |
| 158 | */ |
| 159 | function 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 |