J1939 Documentation
Version 4.16.00
Loading...
Searching...
No Matches
ECU demo

This example simulates a simple ECU. The following PGNs are used by this ECU example:

PGN Parameter Group Label Acronym Repetition Rate Direction
0 Torque/Speed Control 1 TSC1 control purpose Receive
57088 Stop Start Broadcast DM13 - Receive
61440 Electronic Retarder Controller 1 ERC1 100 ms Transmit
61443 Electronic Engine Controller 2 EEC2 10 ms Transmit
61444 Electronic Engine Controller 1 EEC1 10 ms Transmit
65226 Active Diagnostic Trouble Codes DM1 1000 ms Transmit
65227 Previously Active Diagnostic Trouble Codes DM2 on request Transmit
65240 Commanded Address CA - Receive
65242 Software Identification SOFT on request Transmit
65247 Electronic Engine Controller 3 EEC3 250 ms Transmit
65251 Engine Configuration 1 EC1 on request Transmit
65253 Engine Hours, Revolutions HOURS on request Transmit
65260 Vehicle Identification VI on request Transmit
65262 Engine Temperature 1 ET1 1000 ms Transmit
65263 Engine Fluid Level/Pressure 1 EFL/P1 500 ms Transmit
65265 Cruise Control/Vehicle Speed 1 CCVS1 100 ms Transmit
65266 Fuel Economy (Liquid) LFE1 100 ms Transmit
65269 Ambient Conditions AMB 1000 ms Transmit
65270 Intake/Exhaust Conditions 1 IC1 500 ms Transmit
65271 Vehicle Electrical Power 1 VEP1 1000 ms Transmit

Implementation

The implementation is done in the file j1939_demo_ecu1.c.

//====================================================================================================================//
// File: j1939_ecu1.c //
// Description: Example code for a motor control ECU //
// //
// Copyright (C) MicroControl GmbH & Co. KG //
// 53844 Troisdorf - Germany //
// www.microcontrol.net //
// //
//--------------------------------------------------------------------------------------------------------------------//
// The copyright to the computer program(s) herein is the property of MicroControl GmbH & Co. KG, Germany. The //
// program(s) may be used and/or copied only with the written permission of MicroControl GmbH & Co. KG or in //
// accordance with the terms and conditions stipulated in the agreement/contract under which the program(s) have //
// been supplied. //
// //
//====================================================================================================================//
/*--------------------------------------------------------------------------------------------------------------------*\
** Include files **
** **
\*--------------------------------------------------------------------------------------------------------------------*/
#include "j1939_diag.h"
#include "j1939_mgr.h"
#include "j1939_nmt.h"
#include "j1939_pgn.h"
#include "j1939_demo_app.h"
#include <string.h>
/*--------------------------------------------------------------------------------------------------------------------*\
** Function prototypes **
** **
\*--------------------------------------------------------------------------------------------------------------------*/
static int16_t ECU_Pgn00000(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV);
static int16_t ECU_Pgn61440(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV);
static int16_t ECU_Pgn61443(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV);
static int16_t ECU_Pgn61444(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV);
static int16_t ECU_Pgn65240(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV);
static int16_t ECU_Pgn65242(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV);
static int16_t ECU_Pgn65247(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV);
static int16_t ECU_Pgn65251(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV);
static int16_t ECU_Pgn65253(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV);
static int16_t ECU_Pgn65260(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV);
static int16_t ECU_Pgn65262(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV);
static int16_t ECU_Pgn65263(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV);
static int16_t ECU_Pgn65265(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV);
static int16_t ECU_Pgn65266(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV);
static int16_t ECU_Pgn65269(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV);
static int16_t ECU_Pgn65270(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV);
static int16_t ECU_Pgn65271(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV);
/*--------------------------------------------------------------------------------------------------------------------*\
** Definitions **
** **
\*--------------------------------------------------------------------------------------------------------------------*/
#define PGN_TRANSMISSION_RATE 10 // 10 ms
/*--------------------------------------------------------------------------------------------------------------------*\
** Variables **
** **
\*--------------------------------------------------------------------------------------------------------------------*/
static const char szSoftwareVersionT[] = "Version 4.16*";
static const char szSoftwareDateT[] = "09/30/2024*";
typedef struct ECU_Control_s {
uint8_t ubDevice;
uint8_t ubMode;
uint8_t ubTorque;
uint16_t uwSpeed;
} ECU_Control_ts;
static ECU_Control_ts tsECU_ControlS;
//----------------------------------------------------------------------------------------------
// Torque/Speed Control 1 (TSC1)
//
{ J1939_PRIORITY_INFO | J1939_MSG_RCV, // PDU Control
(uint32_t) 0, // PGN value
(uint16_t) 2000, // Reception timeout value
(uint16_t) 0, // Counter
(uint8_t) 0, // DA
(uint8_t) 0, // reserved
(uint16_t) 8, // Data size
ECU_Pgn00000 // PGN handler
},
//----------------------------------------------------------------------------------------------
// Stop Start Broadcast (DM13)
//
{ J1939_PRIORITY_INFO | J1939_MSG_RCV, // PDU Control
(uint32_t) 57088, // PGN value
(uint16_t) 0, // Reception timeout
(uint16_t) 0, // Counter
(uint8_t) 0, // DA
(uint8_t) 0, // reserved
(uint16_t) 8, // Data size
ECU_Pgn57088 // PGN handler
},
//----------------------------------------------------------------------------------------------
// Electronic Retarder Controller 1 (ERC1)
//
{ J1939_PRIORITY_INFO | J1939_MSG_TRM, // PDU Control
(uint32_t) 61440, // PGN value
(uint16_t) (PGN_TRANSMISSION_RATE * 10), // Transmission rate
(uint16_t) 0, // Counter
(uint8_t) 0, // DA
(uint8_t) 0, // reserved
(uint16_t) 8, // Data size
ECU_Pgn61440 // PGN handler
},
//----------------------------------------------------------------------------------------------
// Electronic Engine Controller 2 (EEC2)
//
{ J1939_PRIORITY_CTRL | J1939_MSG_TRM, // PDU Control
(uint32_t) 61443, // PGN value
(uint16_t) (PGN_TRANSMISSION_RATE), // Transmission rate
(uint16_t) 0, // Counter
(uint8_t) 0, // DA
(uint8_t) 0, // reserved
(uint16_t) 8, // Data size
ECU_Pgn61443 // PGN handler
},
//----------------------------------------------------------------------------------------------
// Electronic Engine Controller 1 (EEC1)
//
{ J1939_PRIORITY_CTRL | J1939_MSG_TRM, // PDU Control
(uint32_t) 61444, // PGN value
(uint16_t) (PGN_TRANSMISSION_RATE), // Transmission rate
(uint16_t) 0, // Counter
(uint8_t) 0, // DA
(uint8_t) 0, // reserved
(uint16_t) 8, // Data size
ECU_Pgn61444 // PGN handler
},
//----------------------------------------------------------------------------------------------
// Active Diagnostic Trouble Codes (DM1)
//
{ J1939_PRIORITY_INFO | J1939_MSG_TRM, // PDU Control
(uint32_t) 65226, // PGN value
(uint16_t) 0, // Reception timeout
(uint16_t) 0, // Counter
(uint8_t) 0, // DA
(uint8_t) 0, // reserved
(uint16_t) 8, // Data size
ECU_Pgn65226 // PGN handler
},
//----------------------------------------------------------------------------------------------
// DM2
//
{ J1939_PRIORITY_INFO | J1939_MSG_TRM, // PDU Control
(uint32_t) 65227, // PGN value
(uint16_t) 0, // Reception timeout
(uint16_t) 0, // Counter
(uint8_t) 0, // DA
(uint8_t) 0, // reserved
(uint16_t) 8, // Data size
ECU_Pgn65227 // PGN handler
},
//----------------------------------------------------------------------------------------------
// Commanded Address (CA)
//
{ J1939_PRIORITY_INFO | J1939_MSG_RCV, // PDU Control
(uint32_t) 65240, // PGN value
(uint16_t) 0, // Reception timeout
(uint16_t) 0, // Counter
(uint8_t) 0, // DA
(uint8_t) 0, // reserved
(uint16_t) 9, // Data size
ECU_Pgn65240 // PGN handler
},
//----------------------------------------------------------------------------------------------
// Software Identification (SOFT)
//
{ J1939_PRIORITY_INFO | J1939_MSG_TRM, // PDU Control
(uint32_t) 65242, // PGN value
(uint16_t) 0, // Transmission - on request
(uint16_t) 0, // Counter
(uint8_t) 0, // DA
(uint8_t) 0, // reserved
(uint16_t) 25, // Data size
ECU_Pgn65242 // PGN handler
},
//----------------------------------------------------------------------------------------------
// Electronic Engine Controller 3 (EEC3)
//
{ J1939_PRIORITY_INFO | J1939_MSG_TRM, // PDU Control
(uint32_t) 65247, // PGN value
(uint16_t) (PGN_TRANSMISSION_RATE * 25), // Transmission rate
(uint16_t) 0, // Counter
(uint8_t) 0, // DA
(uint8_t) 0, // reserved
(uint16_t) 8, // Data size
ECU_Pgn65247 // PGN handler
},
//----------------------------------------------------------------------------------------------
// Engine Configuration 1 (EC1)
//
{ J1939_PRIORITY_INFO | J1939_MSG_TRM, // PDU Control
(uint32_t) 65251, // PGN value
(uint16_t) (PGN_TRANSMISSION_RATE * 500), // Transmission rate
(uint16_t) 0, // Counter
(uint8_t) 255, // DA
(uint8_t) 0, // reserved
(uint16_t) 40, // Data size
ECU_Pgn65251 // PGN handler
},
//----------------------------------------------------------------------------------------------
// Engine hours, revolutions (HOURS)
//
{ J1939_PRIORITY_INFO | J1939_MSG_TRM, // PDU Control
(uint32_t) 65253, // PGN value
(uint16_t) 0, // Transmission - on request
(uint16_t) 0, // Counter
(uint8_t) 0, // DA
(uint8_t) 0, // reserved
(uint16_t) 8, // Data size
ECU_Pgn65253 // PGN handler
},
//----------------------------------------------------------------------------------------------
// Vehicle identification (VI)
//
{ J1939_PRIORITY_INFO | J1939_MSG_TRM, // PDU Control
(uint32_t) 65260, // PGN value
(uint16_t) 0, // Transmission - on request
(uint16_t) 0, // Counter
(uint8_t) 0, // DA
(uint8_t) 0, // reserved
(uint16_t) 8, // Data size
ECU_Pgn65260 // PGN handler
},
//----------------------------------------------------------------------------------------------
// Engine temperature (ET1)
//
{ J1939_PRIORITY_INFO | J1939_MSG_TRM, // PDU Control
(uint32_t) 65262, // PGN value
(uint16_t) (PGN_TRANSMISSION_RATE * 100), // Transmission rate
(uint16_t) 0, // Counter
(uint8_t) 0, // DA
(uint8_t) 0, // reserved
(uint16_t) 8, // Data size
ECU_Pgn65262 // PGN handler
},
//----------------------------------------------------------------------------------------------
// Engine Fluid Level/Pressure 1 (EFL/P1)
//
{ J1939_PRIORITY_INFO | J1939_MSG_TRM, // PDU Control
(uint32_t) 65263, // PGN value
(uint16_t) (PGN_TRANSMISSION_RATE * 50), // Transmission rate
(uint16_t) 0, // Counter
(uint8_t) 0, // DA
(uint8_t) 0, // reserved
(uint16_t) 8, // Data size
ECU_Pgn65263 // PGN handler
},
//----------------------------------------------------------------------------------------------
// Cruise control
//
{ J1939_PRIORITY_INFO | J1939_MSG_TRM, // PDU Control
(uint32_t) 65265, // PGN value
(uint16_t) (PGN_TRANSMISSION_RATE * 10), // Transmission rate
(uint16_t) 0, // Counter
(uint8_t) 0, // DA
(uint8_t) 0, // reserved
(uint16_t) 8, // Data size
ECU_Pgn65265 // PGN handler
},
//----------------------------------------------------------------------------------------------
// Fuel economy
//
{ J1939_PRIORITY_INFO | J1939_MSG_TRM, // PDU Control
(uint32_t) 65266, // PGN value
(uint16_t) (PGN_TRANSMISSION_RATE * 10), // Transmission rate
(uint16_t) 0, // Counter
(uint8_t) 0, // DA
(uint8_t) 0, // reserved
(uint16_t) 8, // Data size
ECU_Pgn65266 // PGN handler
},
//----------------------------------------------------------------------------------------------
// Ambient conditions
//
{ J1939_PRIORITY_INFO | J1939_MSG_TRM, // PDU Control
(uint32_t) 65269, // PGN value
(uint16_t) (PGN_TRANSMISSION_RATE * 100), // Transmission rate
(uint16_t) 0, // Counter
(uint8_t) 0, // DA
(uint8_t) 0, // reserved
(uint16_t) 8, // Data size
ECU_Pgn65269 // PGN handler
},
//----------------------------------------------------------------------------------------------
// Intake/Exhaust Conditions 1
//
{ J1939_PRIORITY_INFO | J1939_MSG_TRM, // PDU Control
(uint32_t) 65270, // PGN value
(uint16_t) (PGN_TRANSMISSION_RATE * 50), // Transmission rate
(uint16_t) 0, // Counter
(uint8_t) 0, // DA
(uint8_t) 0, // reserved
(uint16_t) 8, // Data size
ECU_Pgn65270 // PGN handler
},
//----------------------------------------------------------------------------------------------
// Vehicle electrical power 1 (VEP1)
//
(uint32_t) 65271, // PGN value
(uint16_t) (PGN_TRANSMISSION_RATE * 100), // Transmission rate
(uint16_t) 0, // Counter
(uint8_t) 0, // DA
(uint8_t) 0, // reserved
(uint16_t) 8, // Data size
ECU_Pgn65271 // PGN handler
},
//----------------------------------------------------------------------------------------------
// Last entry
//
{ (uint16_t) 0xFFFF, 0, 0, 0, 0, 0, 0, 0L }
};
/*--------------------------------------------------------------------------------------------------------------------*\
** Functions **
** **
\*--------------------------------------------------------------------------------------------------------------------*/
//--------------------------------------------------------------------------------------------------------------------//
// ECU_Pgn00000() //
// Torque / Speed Control 1 (TSC1) //
//--------------------------------------------------------------------------------------------------------------------//
static int16_t ECU_Pgn00000(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV)
{
J1939_Payload_ts *ptsPayloadT = (J1939_Payload_ts *) pubDataV;
uint16_t uwSpeedT;
//---------------------------------------------------------------------------------------------------
// silence warning for unused parameters
//
(void) uwSizeV;
(void) ubSrcAddrV;
(void) ubNetV;
//---------------------------------------------------------------------------------------------------
// copy received data
//
uwSpeedT = ptsPayloadT->aubByte[2];
uwSpeedT <<= 8;
uwSpeedT += ptsPayloadT->aubByte[1];
tsECU_ControlS.ubDevice = ubSrcAddrV;
tsECU_ControlS.ubMode = ptsPayloadT->aubByte[0];
tsECU_ControlS.uwSpeed = uwSpeedT;
tsECU_ControlS.ubTorque = ptsPayloadT->aubByte[3];
return ((int16_t) eJ1939_HANDLER_RESULT_OK);
}
//--------------------------------------------------------------------------------------------------------------------//
// ECU_Pgn61440() //
// Electronic retarder controller 1 (ERC1) //
//--------------------------------------------------------------------------------------------------------------------//
static int16_t ECU_Pgn61440(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV)
{
J1939_Payload_ts *ptsPayloadT = (J1939_Payload_ts *) pubDataV;
//---------------------------------------------------------------------------------------------------
// silence warning for unused parameters
//
(void) uwSizeV;
(void) ubSrcAddrV;
(void) ubNetV;
ptsPayloadT->aubByte[0] = (uint8_t) 0x52; // retarder mode
ptsPayloadT->aubByte[1] = (uint8_t) 125; // Actual Retarder - Percent Torque, 1 % per bit, Offset -125
ptsPayloadT->aubByte[2] = (uint8_t) 125; // Intended Retarder Percent Torque, 1 % per bit, Offset -125
ptsPayloadT->aubByte[3] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[4] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[5] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[6] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[7] = J1939_UNUSED_UINT8;
return ((int16_t) eJ1939_HANDLER_RESULT_OK);
}
//--------------------------------------------------------------------------------------------------------------------//
// ECU_Pgn61443() //
// Electronic Engine Controller 2 (EEC2) //
//--------------------------------------------------------------------------------------------------------------------//
static int16_t ECU_Pgn61443(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV)
{
J1939_Payload_ts *ptsPayloadT = (J1939_Payload_ts *) pubDataV;
//---------------------------------------------------------------------------------------------------
// silence warning for unused parameters
//
(void) uwSizeV;
(void) ubSrcAddrV;
(void) ubNetV;
ptsPayloadT->aubByte[0] = 0x00; // pedal switches
ptsPayloadT->aubByte[1] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[2] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[3] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[4] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[5] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[6] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[7] = J1939_UNUSED_UINT8;
return ((int16_t) eJ1939_HANDLER_RESULT_OK);
}
//--------------------------------------------------------------------------------------------------------------------//
// ECU_Pgn61444() //
// Electronic Engine Controller 1 (EEC1) //
//--------------------------------------------------------------------------------------------------------------------//
static int16_t ECU_Pgn61444(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV)
{
J1939_Payload_ts *ptsPayloadT = (J1939_Payload_ts *) pubDataV;
static uint16_t uwSpeedS = 200 * 8; // 1 Bit = 0.125rpm
static uint8_t ubTorqueS = (uint8_t) 125; // 1 Bit = 1%, -125% Offset
static uint8_t ubSimDirS = 1; // direction of simulation
//---------------------------------------------------------------------------------------------------
// silence warning for unused parameters
//
(void) uwSizeV;
(void) ubSrcAddrV;
(void) ubNetV;
//---------------------------------------------------------------------------------------------------
// simulate torque
//
ubTorqueS += (uint8_t) 1;
if (ubTorqueS > ((uint8_t) 200))
{
ubTorqueS = (uint8_t) 125;
}
//---------------------------------------------------------------------------------------------------
// simulate engine speed in rpm between 200 and 2200
//
if (tsECU_ControlS.uwSpeed == (uint16_t) 0)
{
if (ubSimDirS == (uint8_t) 1)
{
uwSpeedS = uwSpeedS + (uint16_t) 8;
if (uwSpeedS / (uint16_t) 8 > (uint16_t) 2200)
{
ubSimDirS = 0;
}
}
else
{
uwSpeedS = uwSpeedS - (uint16_t) 8;
if (uwSpeedS / (uint16_t) 8 < (uint16_t) 200)
{
ubSimDirS = 1;
}
}
}
//---------------------------------------------------------------------------------------------------
// set engine speed to the requested value
//
else
{
//-------------------------------------------------------------------------------------------
// requested value is greater
//
if (tsECU_ControlS.uwSpeed > uwSpeedS)
{
uwSpeedS = uwSpeedS + (uint16_t) 8;
}
//-------------------------------------------------------------------------------------------
// requested value is smaller
//
if (tsECU_ControlS.uwSpeed < uwSpeedS)
{
uwSpeedS = uwSpeedS - (uint16_t) 8;
}
}
ptsPayloadT->aubByte[0] = 0x01;
ptsPayloadT->aubByte[1] = ubTorqueS; // SPN 512
ptsPayloadT->aubByte[2] = ubTorqueS; // SPN 513
ptsPayloadT->aubByte[3] = (uint8_t) uwSpeedS; // SPN 190
ptsPayloadT->aubByte[4] = (uint8_t) (uwSpeedS >> 8);
ptsPayloadT->aubByte[5] = tsECU_ControlS.ubDevice; // Controlling device
ptsPayloadT->aubByte[6] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[7] = J1939_UNUSED_UINT8;
return ((int16_t) eJ1939_HANDLER_RESULT_OK);
}
//--------------------------------------------------------------------------------------------------------------------//
// ECU_Pgn65240() //
// Commanded Address (CA) //
//--------------------------------------------------------------------------------------------------------------------//
static int16_t ECU_Pgn65240(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV)
{
uint8_t ubNewAddressT;
//---------------------------------------------------------------------------------------------------
// silence warning for unused parameters
//
(void) ubSrcAddrV;
(void) ubNetV;
//---------------------------------------------------------------------------------------------------
// retrieve size information
//
uwSizeV = uwSizeV & J1939_PGN_HANDLER_SIZE_MASK;
//---------------------------------------------------------------------------------------------------
// change address if data size == 9 and NAME is equal
//
if( (J1939_NmtCompareName(ubNetV, pubDataV) == (uint8_t) eJ1939_NAME_EQUAL) && (uwSizeV == (uint16_t) 9) )
{
ubNewAddressT = *(pubDataV + 8);
if(ubNewAddressT < J1939_ADDR_NULL)
{
(void) J1939_MgrInitMsgBuffer(ubNetV, ubNewAddressT);
J1939_NmtClaimAddress(ubNetV);
}
}
return ((int16_t) eJ1939_HANDLER_RESULT_OK);
}
//--------------------------------------------------------------------------------------------------------------------//
// ECU_Pgn65242() //
// Software Identification (SOFT) //
//--------------------------------------------------------------------------------------------------------------------//
static int16_t ECU_Pgn65242(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV)
{
uint8_t ubNumOfFieldsT = 2;
uint8_t ubDataCntT;
uint16_t uwSizeT;
//---------------------------------------------------------------------------------------------------
// silence warning for unused parameters
//
(void) uwSizeV;
(void) ubSrcAddrV;
(void) ubNetV;
//---------------------------------------------------------------------------------------------------
// get the size of the strings
//
uwSizeT = (uint16_t) (strlen(&szSoftwareVersionT[0]));
uwSizeT += (uint16_t) (strlen(&szSoftwareDateT[0]));
uwSizeT += (uint16_t) 1; // the first byte is the number of fields
//---------------------------------------------------------------------------------------------------
// pass size to the stack
//
(void) J1939_PgnSetDataSize(ubNetV, (uint32_t) 65242, uwSizeT);
//---------------------------------------------------------------------------------------------------
// copy the data
//
*pubDataV = ubNumOfFieldsT;
pubDataV++;
for (ubDataCntT = 0; ubDataCntT < strlen(&szSoftwareVersionT[0]); ubDataCntT++)
{
*pubDataV = (uint8_t) (szSoftwareVersionT[ubDataCntT]);
pubDataV++;
}
for(ubDataCntT = 0; ubDataCntT < strlen(&szSoftwareDateT[0]); ubDataCntT++)
{
*pubDataV = (uint8_t) (szSoftwareDateT[ubDataCntT]);
pubDataV++;
}
return ((int16_t) eJ1939_HANDLER_RESULT_OK);
}
//--------------------------------------------------------------------------------------------------------------------//
// ECU_Pgn65247() //
// Electronic Engine Controller 3 (EEC3) //
//--------------------------------------------------------------------------------------------------------------------//
static int16_t ECU_Pgn65247(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV)
{
J1939_Payload_ts *ptsPayloadT = (J1939_Payload_ts *) pubDataV;
uint16_t uwSpeedT;
//---------------------------------------------------------------------------------------------------
// silence warning for unused parameters
//
(void) uwSizeV;
(void) ubSrcAddrV;
(void) ubNetV;
ptsPayloadT->aubByte[0] = (uint8_t) 125; // nominal friction - 0
//---------------------------------------------------------------------------------------------------
// desired speed (rpm)
//
uwSpeedT = tsECU_ControlS.uwSpeed;
ptsPayloadT->aubByte[1] = (uint8_t) uwSpeedT;
uwSpeedT >>= 8;
ptsPayloadT->aubByte[2] = (uint8_t) uwSpeedT;
ptsPayloadT->aubByte[3] = J1939_UNUSED_UINT8;
//---------------------------------------------------------------------------------------------------
// Estimated Engine Parasitic Losses
//
ptsPayloadT->aubByte[4] = (uint8_t)(125 + 10); // offset -125 -> 10 %
ptsPayloadT->aubByte[5] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[6] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[7] = J1939_UNUSED_UINT8;
return ((int16_t) eJ1939_HANDLER_RESULT_OK);
}
//--------------------------------------------------------------------------------------------------------------------//
// ECU_Pgn65251() //
// Engine Configuration 1 (EC1) //
//--------------------------------------------------------------------------------------------------------------------//
static int16_t ECU_Pgn65251(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV)
{
static uint8_t aubEngineConfigS[40];
uint8_t ubCntT;
//---------------------------------------------------------------------------------------------------
// silence warning for unused parameters
//
(void) uwSizeV;
(void) ubSrcAddrV;
(void) ubNetV;
(void) memset(&aubEngineConfigS[0], J1939_UNUSED_UINT8, 40);
//---------------------------------------------------------------------------------------------------
// Engine Speed At Idle, Point 1, 0.125 rpm per bit, 800 rpm -> 6400 dec = 0x1900
//
aubEngineConfigS[0] = 0x00;
aubEngineConfigS[1] = 0x19;
for (ubCntT = 0; ubCntT < (uint8_t) 40; ubCntT++)
{
*pubDataV = aubEngineConfigS[ubCntT];
pubDataV++;
}
return ((int16_t) eJ1939_HANDLER_RESULT_OK);
}
//--------------------------------------------------------------------------------------------------------------------//
// ECU_Pgn65253() //
// Engine hours / revolutions (HOURS) //
//--------------------------------------------------------------------------------------------------------------------//
static int16_t ECU_Pgn65253(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV)
{
static uint32_t ulHoursS; // 0.05 hr/bit, 0 offset
static uint32_t ulRevolutionsS; // 1000 r/bit, 0 offset
uint32_t ulDataT;
J1939_Payload_ts *ptsPayloadT = (J1939_Payload_ts *) pubDataV;
//---------------------------------------------------------------------------------------------------
// silence warning for unused parameters
//
(void) uwSizeV;
(void) ubSrcAddrV;
(void) ubNetV;
ulRevolutionsS++;
ulRevolutionsS++;
ulHoursS++;
ulDataT = ulHoursS;
ptsPayloadT->aubByte[0] = (uint8_t) ulDataT;
ulDataT = ulDataT >> 8;
ptsPayloadT->aubByte[1] = (uint8_t) ulDataT;
ulDataT = ulDataT >> 8;
ptsPayloadT->aubByte[2] = (uint8_t) ulDataT;
ulDataT = ulDataT >> 8;
ptsPayloadT->aubByte[3] = (uint8_t) ulDataT;
ulDataT = ulRevolutionsS;
ptsPayloadT->aubByte[4] = (uint8_t) ulDataT;
ulDataT = ulDataT >> 8;
ptsPayloadT->aubByte[5] = (uint8_t) ulDataT;
ulDataT = ulDataT >> 8;
ptsPayloadT->aubByte[6] = (uint8_t) ulDataT;
ulDataT = ulDataT >> 8;
ptsPayloadT->aubByte[7] = (uint8_t) ulDataT;
return ((int16_t) eJ1939_HANDLER_RESULT_OK);
}
//--------------------------------------------------------------------------------------------------------------------//
// ECU_Pgn65260() //
// Vehicle Identification //
//--------------------------------------------------------------------------------------------------------------------//
static int16_t ECU_Pgn65260(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV)
{
const char szVehicleIdS[] = "SAE J1939 Stack*";
static uint16_t uwDataSizeT;
//---------------------------------------------------------------------------------------------------
// silence warning for unused parameters
//
(void) uwSizeV;
(void) ubSrcAddrV;
//---------------------------------------------------------------------------------------------------
// pass size to the stack
//
uwDataSizeT = (uint16_t) strlen(szVehicleIdS);
(void) J1939_PgnSetDataSize(ubNetV, (uint32_t) 65260, uwDataSizeT);
//---------------------------------------------------------------------------------------------------
// copy the string 'SAE J1939 Stack*', the '*' is the delimiter
//
(void) strncpy((char *) pubDataV, szVehicleIdS, uwDataSizeT);
return ((int16_t) eJ1939_HANDLER_RESULT_OK);
}
//--------------------------------------------------------------------------------------------------------------------//
// J1939_Pgn65262() //
// Engine temperature (ET1) //
//--------------------------------------------------------------------------------------------------------------------//
static int16_t ECU_Pgn65262(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV)
{
J1939_Payload_ts *ptsPayloadT = (J1939_Payload_ts *) pubDataV;
static uint8_t ubCoolantTempS = (uint8_t) 80; // offset -40 °C
static uint8_t ubFuelTempS = (uint8_t) 60; // offset -40 °C
static uint16_t uwOilTempS = (uint16_t)(10016); // offset -273°C, 1/32 °C per bit
static uint8_t ubIncrementS = (uint8_t) 1;
//---------------------------------------------------------------------------------------------------
// silence warning for unused parameters
//
(void) uwSizeV;
(void) ubSrcAddrV;
(void) ubNetV;
//---------------------------------------------------------------------------------------------------
// simulate coolant temperature
//
if (ubCoolantTempS > (uint8_t) 120)
{
ubIncrementS = 0;
}
if (ubCoolantTempS < (uint8_t) 100)
{
ubIncrementS = 1;
}
if (ubIncrementS > (uint8_t) 0)
{
ubCoolantTempS++;
uwOilTempS += (uint16_t) 16;
}
else
{
ubCoolantTempS--;
uwOilTempS -= (uint16_t) 16;
}
ptsPayloadT->aubByte[0] = ubCoolantTempS;
ptsPayloadT->aubByte[1] = ubFuelTempS;
ptsPayloadT->aubByte[2] = (uint8_t) uwOilTempS;
uwOilTempS >>= 8;
ptsPayloadT->aubByte[3] = (uint8_t) uwOilTempS;
ptsPayloadT->aubByte[4] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[5] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[6] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[7] = J1939_UNUSED_UINT8;
return ((int16_t) eJ1939_HANDLER_RESULT_OK);
}
//--------------------------------------------------------------------------------------------------------------------//
// ECU_Pgn65263() //
// Engine Fluid Level/Pressure 1 (EFL/P1) //
//--------------------------------------------------------------------------------------------------------------------//
static int16_t ECU_Pgn65263(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV)
{
J1939_Payload_ts *ptsPayloadT = (J1939_Payload_ts *) pubDataV;
//---------------------------------------------------------------------------------------------------
// silence warning for unused parameters
//
(void) uwSizeV;
(void) ubSrcAddrV;
(void) ubNetV;
ptsPayloadT->aubByte[0] = (uint8_t) 10; // Engine Fuel Delivery Pressure, 4 kPa per bit
ptsPayloadT->aubByte[1] = (uint8_t) 10; // Engine Extended Crankcase Blow-by Pressure, 0.05 kPa per bit
ptsPayloadT->aubByte[2] = (uint8_t) 250; // Engine Oil Level, 0.4 % per bit
ptsPayloadT->aubByte[3] = (uint8_t) 5; // Engine Oil Pressure, 4 kPa per bit
ptsPayloadT->aubByte[4] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[5] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[6] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[7] = J1939_UNUSED_UINT8;
return ((int16_t) eJ1939_HANDLER_RESULT_OK);
}
//--------------------------------------------------------------------------------------------------------------------//
// ECU_Pgn65265() //
// Cruise control //
//--------------------------------------------------------------------------------------------------------------------//
static int16_t ECU_Pgn65265(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV)
{
J1939_Payload_ts *ptsPayloadT = (J1939_Payload_ts *) pubDataV;
uint16_t uwWheelSpeedT;
//---------------------------------------------------------------------------------------------------
// silence warning for unused parameters
//
(void) uwSizeV;
(void) ubSrcAddrV;
(void) ubNetV;
ptsPayloadT->aubByte[0] = (uint8_t) 0xC3; // Parking Brake, Cruise Control Pause = off
uwWheelSpeedT = tsECU_ControlS.uwSpeed / ((uint16_t) 7); // Wheel-Based Vehicle Speed, approx. speed / 7
ptsPayloadT->aubByte[2] = (uint8_t) uwWheelSpeedT;
uwWheelSpeedT >>= 8;
ptsPayloadT->aubByte[3] = (uint8_t) uwWheelSpeedT;
ptsPayloadT->aubByte[4] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[5] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[6] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[7] = J1939_UNUSED_UINT8;
return ((int16_t) eJ1939_HANDLER_RESULT_OK);
}
//--------------------------------------------------------------------------------------------------------------------//
// ECU_Pgn65266() //
// Fuel economy //
//--------------------------------------------------------------------------------------------------------------------//
static int16_t ECU_Pgn65266(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV)
{
J1939_Payload_ts *ptsPayloadT = (J1939_Payload_ts *) pubDataV;
//---------------------------------------------------------------------------------------------------
// silence warning for unused parameters
//
(void) uwSizeV;
(void) ubSrcAddrV;
(void) ubNetV;
ptsPayloadT->aubByte[0] = 0x06;
ptsPayloadT->aubByte[1] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[2] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[3] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[4] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[5] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[6] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[7] = J1939_UNUSED_UINT8;
return ((int16_t) eJ1939_HANDLER_RESULT_OK);
}
//--------------------------------------------------------------------------------------------------------------------//
// ECU_Pgn65269() //
// Ambient conditions //
//--------------------------------------------------------------------------------------------------------------------//
static int16_t ECU_Pgn65269(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV)
{
J1939_Payload_ts *ptsPayloadT = (J1939_Payload_ts *) pubDataV;
//---------------------------------------------------------------------------------------------------
// silence warning for unused parameters
//
(void) uwSizeV;
(void) ubSrcAddrV;
(void) ubNetV;
ptsPayloadT->aubByte[0] = 0x09;
ptsPayloadT->aubByte[1] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[2] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[3] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[4] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[5] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[6] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[7] = J1939_UNUSED_UINT8;
return ((int16_t) eJ1939_HANDLER_RESULT_OK);
}
//--------------------------------------------------------------------------------------------------------------------//
// ECU_Pgn65270() //
// Inlet/Exhaust Conditions 1 //
//--------------------------------------------------------------------------------------------------------------------//
static int16_t ECU_Pgn65270(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV)
{
J1939_Payload_ts *ptsPayloadT = (J1939_Payload_ts *) pubDataV;
//---------------------------------------------------------------------------------------------------
// silence warning for unused parameters
//
(void) uwSizeV;
(void) ubSrcAddrV;
(void) ubNetV;
//---------------------------------------------------------------------------------------------------
// Engine Particulate Trap Inlet Pressure: 25 kPa
//
ptsPayloadT->aubByte[0] = (uint8_t)50;
//---------------------------------------------------------------------------------------------------
// Engine Turbocharger Boost Pressure: 100 kPa
//
ptsPayloadT->aubByte[1] = (uint8_t)50;
ptsPayloadT->aubByte[2] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[3] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[4] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[5] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[6] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[7] = J1939_UNUSED_UINT8;
return ((int16_t) eJ1939_HANDLER_RESULT_OK);
}
//--------------------------------------------------------------------------------------------------------------------//
// ECU_Pgn65271() //
// Vehicle Electrical Power //
//--------------------------------------------------------------------------------------------------------------------//
static int16_t ECU_Pgn65271(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV)
{
J1939_Payload_ts *ptsPayloadT = (J1939_Payload_ts *) pubDataV;
uint16_t uwVoltageT; // 50 mV / bit
//---------------------------------------------------------------------------------------------------
// silence warning for unused parameters
//
(void) uwSizeV;
(void) ubSrcAddrV;
(void) ubNetV;
//---------------------------------------------------------------------------------------------------
// net battery current, -125 A offset, 124 -> - 1 A
//
ptsPayloadT->aubByte[0] = (uint8_t) 124;
//---------------------------------------------------------------------------------------------------
// alternator current, 0 A offset, 8 -> + 8 A
//
ptsPayloadT->aubByte[1] = (uint8_t) 8;
//---------------------------------------------------------------------------------------------------
// alternator potential: 13,80 V -> 1380 / 5 = 276
//
uwVoltageT = (uint16_t) 276;
ptsPayloadT->aubByte[2] = (uint8_t) uwVoltageT;
uwVoltageT >>= 8;
ptsPayloadT->aubByte[3] = (uint8_t) uwVoltageT;
//---------------------------------------------------------------------------------------------------
// electrical potential: 12,75 V -> 1275 / 5 = 255
//
uwVoltageT = (uint16_t) 255;
ptsPayloadT->aubByte[4] = (uint8_t) uwVoltageT;
uwVoltageT >>= 8;
ptsPayloadT->aubByte[5] = (uint8_t) uwVoltageT;
ptsPayloadT->aubByte[6] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[7] = J1939_UNUSED_UINT8;
return ((int16_t) eJ1939_HANDLER_RESULT_OK);
}
//--------------------------------------------------------------------------------------------------------------------//
// J1939_PgnListUserInit() //
// Setup data for the ECU //
//--------------------------------------------------------------------------------------------------------------------//
void J1939_PgnListUserInit(uint8_t ubNetV)
{
//---------------------------------------------------------------------------------------------------
// silence warning for unused parameters
//
(void) ubNetV;
tsECU_ControlS.ubDevice = J1939_ADDR_NULL;
tsECU_ControlS.ubMode = 0;
tsECU_ControlS.ubTorque = 0;
tsECU_ControlS.uwSpeed = 0;
}
#define J1939_PRIORITY_INFO
Definition j1939_defs.h:231
#define J1939_MSG_TRM
Definition j1939_defs.h:257
#define J1939_MSG_RCV
Definition j1939_defs.h:248
#define J1939_PRIORITY_CTRL
Definition j1939_defs.h:222
#define J1939_ADDR_NULL
Definition j1939_defs.h:286
@ eJ1939_HANDLER_RESULT_OK
Definition j1939_defs.h:515
#define J1939_PGN_HANDLER_SIZE_MASK
Definition j1939_defs.h:334
J1939 demo application.
J1939_PGN_Entry_ts atsPgnListEcu1[]
J1939 Diagnostic Functions .
int16_t ECU_Pgn57088(uint8_t *pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV)
int16_t ECU_Pgn65226(uint8_t *pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV)
int16_t ECU_Pgn65227(uint8_t *pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV)
J1939 Management Functions .
J1939 Network management .
@ eJ1939_NAME_EQUAL
Definition j1939_nmt.h:125
J1939 Parameter Groups .
void J1939_PgnListUserInit(uint8_t ubNetV)
J1939_Status_tv J1939_PgnSetDataSize(uint8_t ubNetV, uint32_t ulPgnV, uint16_t uwSizeV)
Manage a single PGN.
Definition j1939_defs.h:572