File syn_j1939.c¶
FileList > proto > syn_j1939.c
Go to the source code of this file
SAE J1939 Heavy-Duty Vehicle CAN Protocol Stack implementation.
#include "../util/syn_assert.h"#include "../util/syn_pack.h"#include "syn_j1939.h"#include <string.h>
Public Functions¶
| Type | Name |
|---|---|
| SYN_Status | syn_j1939_build_address_claim (const SYN_J1939_Node * node, SYN_CAN_Frame * frame) Build an Address Claim CAN frame for the node. |
| SYN_Status | syn_j1939_build_request (uint8_t sa, uint8_t da, uint32_t requested_pgn, SYN_CAN_Frame * frame) Build a Request PGN CAN frame (PGN 59904). |
| SYN_Status | syn_j1939_build_tp_bam (uint8_t sa, uint32_t pgn, uint16_t total_bytes, SYN_CAN_Frame * frame) Build a Transport Protocol Broadcast Announce Message (TP.CM_BAM). |
| SYN_Status | syn_j1939_build_tp_dt (uint8_t sa, uint8_t sequence, const uint8_t * payload, size_t payload_len, SYN_CAN_Frame * frame) Build a Transport Protocol Data Transfer packet (TP.DT). |
| uint32_t | syn_j1939_calc_pgn (uint8_t dp, uint8_t pf, uint8_t ps) Compute 24-bit Parameter Group Number from Data Page, PF, and PS. |
| SYN_Status | syn_j1939_dtc_add_active (SYN_J1939_DTCLog * log, uint32_t spn, uint8_t fmi) Add an active Diagnostic Trouble Code (DM1). |
| SYN_Status | syn_j1939_dtc_clear_active (SYN_J1939_DTCLog * log, uint32_t spn, uint8_t fmi) Clear an active DTC and move it to previously active log (DM2). |
| void | syn_j1939_dtc_clear_dm11 (SYN_J1939_DTCLog * log) Clear all active DTCs (DM11 Request handling). |
| void | syn_j1939_dtc_clear_dm3 (SYN_J1939_DTCLog * log) Clear all previously active DTCs (DM3 Request handling). |
| void | syn_j1939_dtc_log_init (SYN_J1939_DTCLog * log) Initialize a J1939 Diagnostic Trouble Code logger. |
| size_t | syn_j1939_encode_dm1 (uint8_t * buf, size_t buf_size, const SYN_J1939_DTC * dtc_list, size_t dtc_count, uint8_t mil_lamp_status) Encode Active Diagnostic Trouble Codes into a DM1 buffer (PGN 65226). |
| size_t | syn_j1939_encode_dm2 (uint8_t * buf, size_t buf_size, const SYN_J1939_DTC * dtc_list, size_t dtc_count, uint8_t mil_lamp_status) Encode a J1939 DM2 payload (Previously Active Diagnostic Trouble Codes). |
| uint32_t | syn_j1939_id_pack (uint8_t priority, uint32_t pgn, uint8_t sa, uint8_t da) Pack J1939 bitfields into a 29-bit CAN Identifier. |
| SYN_Status | syn_j1939_id_unpack (uint32_t can_id, SYN_J1939_Header * header) Unpack a 29-bit CAN Identifier into a J1939 Header structure. |
| void | syn_j1939_name_decode (const uint8_t buf, SYN_J1939_Name * name) Decode an 8-byte buffer into a 64-bit J1939 NAME structure. |
| void | syn_j1939_name_encode (const SYN_J1939_Name * name, uint8_t buf) Encode a 64-bit J1939 NAME into an 8-byte buffer. |
| SYN_Status | syn_j1939_node_init (SYN_J1939_Node * node, uint8_t sa, const SYN_J1939_Name * name) Initialize a J1939 Node instance. |
| SYN_Status | syn_j1939_process_frame (SYN_J1939_Node * node, const SYN_CAN_Frame * frame, uint32_t * out_pgn, const uint8_t ** out_data, size_t * out_len) Process an incoming CAN frame in the J1939 node state machine. |
Public Functions Documentation¶
function syn_j1939_build_address_claim¶
Build an Address Claim CAN frame for the node.
Parameters:
nodePointer to J1939 node instance.frameOutput CAN frame.
Returns:
SYN_OK on success.
function syn_j1939_build_request¶
Build a Request PGN CAN frame (PGN 59904).
SYN_Status syn_j1939_build_request (
uint8_t sa,
uint8_t da,
uint32_t requested_pgn,
SYN_CAN_Frame * frame
)
Parameters:
saSource address sending request.daDestination address requested (0xFF for broadcast).requested_pgnPGN being requested.frameOutput CAN frame.
Returns:
SYN_OK on success.
function syn_j1939_build_tp_bam¶
Build a Transport Protocol Broadcast Announce Message (TP.CM_BAM).
SYN_Status syn_j1939_build_tp_bam (
uint8_t sa,
uint32_t pgn,
uint16_t total_bytes,
SYN_CAN_Frame * frame
)
Parameters:
saSource address.pgnPGN of payload.total_bytesTotal payload length in bytes (9 to 1785).frameOutput CAN frame.
Returns:
SYN_OK on success.
function syn_j1939_build_tp_dt¶
Build a Transport Protocol Data Transfer packet (TP.DT).
SYN_Status syn_j1939_build_tp_dt (
uint8_t sa,
uint8_t sequence,
const uint8_t * payload,
size_t payload_len,
SYN_CAN_Frame * frame
)
Parameters:
saSource address.sequencePacket sequence number (1 to 255).payloadPointer to payload chunk (up to 7 bytes).payload_lenLength of chunk (1 to 7 bytes).frameOutput CAN frame.
Returns:
SYN_OK on success.
function syn_j1939_calc_pgn¶
Compute 24-bit Parameter Group Number from Data Page, PF, and PS.
Parameters:
dpData Page (0 or 1).pfPDU Format (0-255).psPDU Specific (0-255).
Returns:
24-bit PGN value.
function syn_j1939_dtc_add_active¶
Add an active Diagnostic Trouble Code (DM1).
function syn_j1939_dtc_clear_active¶
Clear an active DTC and move it to previously active log (DM2).
function syn_j1939_dtc_clear_dm11¶
Clear all active DTCs (DM11 Request handling).
function syn_j1939_dtc_clear_dm3¶
Clear all previously active DTCs (DM3 Request handling).
function syn_j1939_dtc_log_init¶
Initialize a J1939 Diagnostic Trouble Code logger.
function syn_j1939_encode_dm1¶
Encode Active Diagnostic Trouble Codes into a DM1 buffer (PGN 65226).
size_t syn_j1939_encode_dm1 (
uint8_t * buf,
size_t buf_size,
const SYN_J1939_DTC * dtc_list,
size_t dtc_count,
uint8_t mil_lamp_status
)
Parameters:
bufOutput buffer.buf_sizeBuffer capacity.dtc_listArray of DTC structures.dtc_countNumber of DTCs in list.mil_lamp_status2-bit MIL status.
Returns:
Total bytes written to buffer.
function syn_j1939_encode_dm2¶
Encode a J1939 DM2 payload (Previously Active Diagnostic Trouble Codes).
size_t syn_j1939_encode_dm2 (
uint8_t * buf,
size_t buf_size,
const SYN_J1939_DTC * dtc_list,
size_t dtc_count,
uint8_t mil_lamp_status
)
function syn_j1939_id_pack¶
Pack J1939 bitfields into a 29-bit CAN Identifier.
Parameters:
priorityPriority (0-7, typically 6).pgnParameter Group Number (18-bit).saSource Address (0-255).daDestination Address (used if PGN is PDU1 format).
Returns:
29-bit CAN ID.
function syn_j1939_id_unpack¶
Unpack a 29-bit CAN Identifier into a J1939 Header structure.
Parameters:
can_id29-bit Extended CAN Identifier.headerOutput structure receiving parsed fields.
Returns:
SYN_OK on success, or SYN_INVALID_PARAM if header is NULL.
function syn_j1939_name_decode¶
Decode an 8-byte buffer into a 64-bit J1939 NAME structure.
Parameters:
bufSource 8-byte buffer.nameOutput NAME structure.
function syn_j1939_name_encode¶
Encode a 64-bit J1939 NAME into an 8-byte buffer.
Parameters:
nameSource NAME structure.bufOutput 8-byte buffer.
function syn_j1939_node_init¶
Initialize a J1939 Node instance.
Parameters:
nodePointer to node instance.saPreferred Source Address (0-253).nameDevice 64-bit NAME configuration.
Returns:
SYN_OK on success.
function syn_j1939_process_frame¶
Process an incoming CAN frame in the J1939 node state machine.
SYN_Status syn_j1939_process_frame (
SYN_J1939_Node * node,
const SYN_CAN_Frame * frame,
uint32_t * out_pgn,
const uint8_t ** out_data,
size_t * out_len
)
Parameters:
nodePointer to node.frameIncoming CAN frame.out_pgnOutput received PGN.out_dataPointer to receiving reassembled or single-frame payload.out_lenOutput payload length.
Returns:
SYN_OK if a complete J1939 message is ready, or SYN_BUSY if multi-packet assembly is in progress.
The documentation for this class was generated from the following file src/syntropic/proto/syn_j1939.c