UM-0086-A2
CANgate User’s Manual
Page 28
Notes and Examples
Extracting and Formatting Bit Fields
In the following example two 16-bit fields plus four 4-bit fields are packed into the CAN message with identifier 0x118. The
most recent value for each of these fields will be returned when polled by the host.
CONNECT 1 500 'Enable CAN port 1 at 500kbps
BEGIN
12 RECV 1 0x118 1 2 FORMAT "P1:%d\n"
13 RECV 1 0x118 3 4
14 RECV 1 0x118 5.8 5.5
15 RECV 1 0x118 5.4 5.1 FORMAT 10 -40
16 RECV 1 0x118 6.8 6.5 FORMAT .25 "Gibble Freq. %6.3f Hz\n"
17 RECV 1 0x118 6.4 6.1
END
So if the last message that CANgate received (with CAN ID 0x118) happened to have the following 64-bit data field:
019266401A9F0000
and the above six memory slots were polled, for example using the command:
RP 12 17
then the following data would be returned:
P1:402
(bytes 1-2 = 0x0192 = 402)
6640
(bytes 3-4 = 0x6640)
01
(byte 5 = 0x1A, bits 8-5 = 0x1)
60.00
(byte 5 = 0x1A, bits 4-1 = 0xA, scaled by 10 with offset -40 = 60)
Gibble Freq. 2.250 Hz
(byte 6 = 0x9F, bits 8-5 = 0x9, scaled by 0.25 = 2.25)
0F
(byte 6 = 0x9F, bits 4-1 = 0xF)
In this case three of the memory slots use the
FORMAT
specifier to return their values in scaled engineering units, rather than
raw hexadecimal. Slot #15 uses the default format string of
"%f\n"
, ie. floating point, 2 decimal places, followed by CRLF.
J1939 PGNs & SPNs
Broadcast PGNs
J1939 based systems typically have a multitude of SPNs (Suspect Parameter Numbers), each representing an individual
measured quantity or status. A group of related SPNs will be broadcast over the CAN network under a particular Parameter
Group Number (PGN), which is specified as part of the 29 bit identifier.
Each 29 bit identifier carries with it one 64 bit packet of CAN data. Some PGNs with a data length larger the 64 bits require
several packets to send them. CANgate automatically uses the J1939 transport protocol to send or receive large PGNs.
Refer to
(P20)
or the SAE J1939/21 (Data Link Layer) standard for a more detailed description
on PGN numbers and how they are encoded into CAN identifiers.
An example of a J1939 SPN would be “Engine Speed”. In order to capture engine speed using CANgate, it is first necessary
to determine the PGN which contains this parameter. This can be found in SAE J1939/71 (Vehicle Application Layer), which
specifies:
Electronic Engine Controller #1
Update rate:
Engine speed dependent
Data length:
8 bytes
Data
page:
0
PDU
format: 240
PDU
specific: 4
Default
priority
3
Parameter Group Number:
61,444
(0x00F004)
Byte:
1
Status_EEC1
Bit: 8-5
Not defined
Bit: 4-1
Engine/retarder torque mode
Byte: 2
Driver’s demand engine – percent torque
Byte: 3
Actual engine – percent torque
Byte: 4-5
Engine Speed
Byte: 6-8
Not defined
The precise format of each SPN is also specified in SAE J1939/71:
Engine Speed
Data Length:
2 bytes
Resolution:
0.125 rpm/bit gain, 0 rpm offset