R이번 글에서는 CAN J1939 프로토콜에 대해서 알아본다.
메시지 포멧
먼저 메시지 포멧과 Identifier의 구조를 살펴보겠다.
Identifier는 총 29-bit의 크기로 이루어진다.
세부적은 비트의 구성은 다음과 같다.

첫 3 bit는 이름 그대로 우선순위를 의미하며 낮음 숫자일 수록 높은 우선순위를 의미한다. 즉, 0이라면 가장 높은 우선순위를 의미한다.
뒤에 오는 reserved는 뭘 위한건지 잘 파악되지 않는다. 레퍼런스로 사용한 문서에서는 다음과 같이 말한다.
The next bit of the identifier is reserved for future use and should be set to 0 for transmitted messages.
하지만 뭘 위한 부분인지는 명시되지 않아서, 자유롭게 클라이언트와 결정하여 사용하는게 아닐까 생각된다.
아래는 번역 없이 나머지 파라미터에 대한 설명을 발췌한 것이다. 필요시 참조.
The next bit in the identifier is the data page selector. This bit expands the number of possible Parameter Groups that can be represented by the identifier.
The PDU format (PF) determines whether the message can be transmitted with a destination address or if the message is always transmitted as a broadcast message.
The interpretation of the PDU specific (PS) field changes based on the PF value:
- If the PF is between 0 and 239, the message is addressable (PDU1) and the PS field contains the destination address.
- If the PF is between 240 and 255, the message can only be broadcast (PDU2) and the PS field contains a Group Extension.
The Group extension expands the number of possible broadcast Parameter Groups that can be represented by the identifier.
The term Parameter Group Number (PGN) is used to refer to the value of the Reserve bit, DP, PF, and PS fields combined into a single 18 bit value.

J1939-21은 29bit를 사용하므로 앞의 3bit는 0으로 채워진다.
두 가지 전송 프로토콜
J1939-21의 TP는 크게 두 가지로 나누어진다.
- PDU1
- PDU2
이 둘의 차이는 PF의 값 범위로 구분되며, 이에 따라서 PS가 어떻게 해석될지 갈리게 된다.
- If the PF is between 0 and 239, the message is addressable (PDU1) and the PS field contains the destination address.
- If the PF is between 240 and 255, the message can only be broadcast (PDU2) and the PS field contains a Group Extension. [출쳐]https://kvaser.com/about-can/higher-layer-protocols/j1939-introduction/?srsltid=AfmBOorYFT8P6wh4nGueCI4CiJQAUu-P8FkSvfo8x5f0UXCc-Die-L50
특수한 PGN 값 (CM, DT)
PGN값으로 사용될 수 있는 값 중에서 특수한 용도를 가지는 표준 PGN이 존재하는데, 이 중 일부를 알아보겠다.
- TP.CM: TP - Connection Management (0xEC00 i.e. 60416)
- TP.DT: TP - Data Transfer (0xEB00 i.e. 60160)
둘 모두, PF에 위치한 값을 의미하며, 239(0xEF) 이하의 값을 가지므로, PGN에 PS는 포함되지 않는다.
구체적으로는 다음과 같은 역할을 가진다.
- TP.CM: 멀티패킷 전송의 제어/관리
- 시작 시 RTS 또는 BAM
- 중간에 CTS
- 종료 시 EoMA 또는 Abort
- TP.DT: 멀티패킷의 실제 데이터 조각 전송
- 여러 번 반복해서 전송됨
구체적인 과정을 이미지로 본다면 다음과 같다. 각각 RTS/CTS, BAM을 의미한다.

참조 링크
https://www.csselectronics.com/pages/j1939-explained-simple-intro-tutorial?utm
https://www.csselectronics.com/pages/j1939-pgn-conversion-tool