CAN Message Simulation: A Practical Automotive Engineering Guide

CAN message simulation is used to reproduce network traffic, stimulate an ECU, model a missing network participant or test how a system responds to defined communication conditions. A useful simulation must get more than the identifier right: frame format, DLC, payload, signal encoding, timing, message ownership and shutdown behavior all matter.

This article explains the practical lifecycle of a simulated CAN message using CAPL-style examples. Exact syntax and available APIs depend on the CAPL environment and installed tool version. Treat the code as a learning pattern and confirm it against the project database and tool documentation before using it in a real test configuration.

1. What does CAN message simulation mean?

A simulated CAN message is a frame generated by a software-based network participant rather than by the real ECU that normally owns that message. A simulation node can:

  • Transmit a message periodically using a timer.
  • Transmit a message in response to a received frame or another event.
  • Change payload bytes or database-defined signals before transmission.
  • Receive frames and update its internal simulation state.
  • Model counters, state transitions and selected fault conditions.
  • Stop transmission and reset state when measurement ends.

Simulation is commonly used when an ECU is not yet available, when a test needs controlled inputs, or when a specific network condition must be reproduced repeatedly.

Simulation versus real ECU communication

ActivityDescription
Real ECU transmissionA physical ECU sends a frame through its network interface
Message simulationA configured software node generates a frame
StimulationA simulated frame or signal is used as an input to another ECU
MonitoringA measurement setup observes frames without necessarily transmitting them
Automated testStimulus and observed behavior are evaluated against defined requirements

A simulation node should have an explicit responsibility. Do not allow it to unintentionally compete with a real ECU for ownership of the same message.

2. CAN message structure to understand before simulation

A CAN data frame contains an arbitration field, control information, a data field, CRC, acknowledgement and frame-ending bits. For message simulation, engineers most often configure or verify the identifier, frame format, DLC and payload.

FieldEngineering significance
IdentifierIdentifies the message and participates in arbitration priority
Frame formatStandard 11-bit identifier or extended 29-bit identifier
RTR / frame typeDistinguishes data and remote-frame behavior in Classical CAN; CAN FD uses data frames and does not support remote frames
DLCEncodes the data length according to the applicable CAN format
Data fieldCarries the raw payload bytes
CRC and ACKHandled by the CAN protocol controller; not normally populated manually in an application message object

For Classical CAN, the data field can contain up to 8 bytes. CAN FD supports up to 64 data bytes. The configured frame type and payload length must be supported by the network and every relevant controller.

Raw bytes and decoded signals

A database such as a DBC maps message identifiers and payload bits to named signals. A signal definition can specify start bit, length, byte order, signedness, factor, offset and unit.

For example, a raw payload byte may represent a physical value using:

Physical value=Raw value×Factor+Offset\text{Physical value} = \text{Raw value} \times \text{Factor} + \text{Offset}

The exact start-bit convention and byte-order interpretation must follow the database format and tool implementation. Always verify the decoded value against a known raw payload.

3. Simulation architecture and message lifecycle

A common message lifecycle is:

  1. Initialize simulation state when measurement starts.
  2. Configure an initial payload or signal value.
  3. Start a timer or wait for a triggering event.
  4. Update the message data.
  5. Transmit the message.
  6. Receive and process other messages as required.
  7. Cancel timers and reset state when measurement stops.
Rendering diagram...

The diagram describes a functional pattern, not a mandatory software architecture. Map each step to the actual simulation node and test configuration.

For every simulated message, document:

  • Message identifier and standard/extended format.
  • Data length and expected payload layout.
  • Transmitting node and channel.
  • Trigger type and nominal cycle time, if periodic.
  • Initial values and update rules.
  • Counter, checksum or freshness behavior, if required by the interface.
  • Timeout and invalid-data behavior expected by consumers.
  • Conditions for starting and stopping transmission.

4. CAPL message declaration and initialization

CAPL is an event-driven language used in supported automotive network simulation and test environments. A message object represents a CAN message that can be populated and transmitted by the simulation.

An illustrative declaration pattern is:

variables
{
  message 0x321 StatusMsg;
  msTimer statusTimer;
  byte counter = 0;
}

The identifier and message declaration syntax should be checked against the active database and CAPL version. In a database-driven configuration, using the symbolic message definition is generally preferable because the database provides the intended message and signal mapping.

Initialize the state when measurement starts:

on start
{
  counter = 0;
  setTimer(statusTimer, 100);
}

The 100 ms interval is only an example. Use the message cycle time and test requirement defined by the project.

5. Cyclic CAN message transmission

A cyclic message is transmitted repeatedly at a configured interval. This is useful for periodic ECU inputs such as vehicle state, sensor status or simulated body signals.

Example: transmit a message every 100 ms

variables
{
  message 0x321 StatusMsg;
  msTimer statusTimer;
  byte counter = 0;
}

on start
{
  counter = 0;
  setTimer(statusTimer, 100);
}

on timer statusTimer
{
  StatusMsg.dlc = 8;
  StatusMsg.byte(0) = counter;
  StatusMsg.byte(1) = 0x01;

  output(StatusMsg);

  counter++;
  setTimer(statusTimer, 100);
}

This is an illustrative CAPL-style example. Check the message-object declaration, byte access and timer APIs supported by the installed CAPL runtime. If the message is database-defined, prefer the configured symbolic message and signals where possible.

What the example does

  • Declares a message object and a timer.
  • Initializes the counter when measurement starts.
  • Starts the timer.
  • Sets the payload values when the timer expires.
  • Sends the message using output().
  • Increments the counter and schedules the next transmission.

A production simulation should define counter rollover, initial payload values, any checksum algorithm, transmission enable/disable conditions and cleanup behavior. Do not assume that a counter or checksum is required unless the network specification defines it.

6. Event-triggered transmission

Not every message needs to be sent periodically. Some messages are generated when a state changes, a request arrives or a test action occurs.

For example, a simulated ECU may transmit a response after receiving a request message. An illustrative event pattern is:

on message 0x456
{
  // Evaluate the received request and update simulation state.
  // Populate the response message according to the project definition.
  // Transmit only when the specified preconditions are satisfied.
}

The event handler should check more than the identifier when the test requires it. Relevant checks may include:

  • Expected DLC and frame format.
  • Request type or signal value.
  • Validity bits, counters or checksum status where applicable.
  • ECU operating state and test preconditions.
  • Whether the response is permitted at this point in the test.

Avoid placing long blocking operations in measurement event handlers. Keep event processing bounded and use timers or test-control mechanisms for delayed actions.

7. Receiving and analyzing CAN messages

A simulation node can also monitor incoming messages and update its internal state. Receiving a frame does not automatically mean its application data is valid.

For a received message, consider checking:

  1. Identifier and frame format.
  2. DLC and payload layout.
  3. Signal ranges and enumerated values.
  4. Alive counter or rolling-counter sequence, if specified.
  5. Checksum or end-to-end protection, if specified.
  6. Message freshness and expected cycle time.
  7. Operating-state preconditions.

A frame can be present in the trace but still contain stale, invalid or implausible data. Keep raw-frame evidence so that database decoding can be independently checked.

8. Raw-byte access versus database-defined signals

There are two common ways to populate a simulated message.

Raw-byte approach

Raw-byte access is useful when testing exact payload patterns, reserved bits, boundary values or malformed frames. It requires careful control of byte order and bit positions.

Illustrative pattern:

on timer statusTimer
{
  StatusMsg.dlc = 8;
  StatusMsg.byte(0) = 0x12;
  StatusMsg.byte(1) = 0x34;
  output(StatusMsg);
}

Symbolic-signal approach

When a communication database is loaded and the message is mapped correctly, symbolic signal access can make test logic easier to understand. The exact CAPL syntax depends on the database and tool configuration.

Illustrative pattern:

// Conceptual example only:
// StatusMsg.SomeSignal = desiredValue;
// output(StatusMsg);

Use symbolic signals for application-oriented tests and raw bytes when the test specifically targets payload encoding. For either approach, verify the transmitted bytes in the trace.

9. CAN arbitration and competing simulated messages

CAN uses non-destructive bitwise arbitration. A node that transmits a recessive bit but observes a dominant bit loses arbitration and stops transmitting; the winning frame continues.

For two standard-format identifiers, the lower numerical identifier has higher priority when comparing the identifier bits under the same relevant frame conditions.

Arbitration bit       b10 b9 b8 b7 b6 b5 b4 ...
Node A, ID 0x100       0   0  1  0  0  0  0  ...
Node B, ID 0x180       0   0  1  1  0  0  0  ...
Observed bus           0   0  1  0  0  0  0  ...
                                      ^
                     Node B sends recessive 1,
                     observes dominant 0 and loses arbitration

This symbolic example assumes both nodes begin arbitration together and use standard identifiers. A complete arbitration comparison includes the relevant frame-format and control bits. Standard and extended frames sharing the same 11-bit base identifier require special care because the standard frame wins at the relevant arbitration bit.

Avoid duplicate message ownership

A common bench problem occurs when a real ECU and a simulation node both transmit the same identifier. Depending on timing and payload, this can create arbitration interactions, unexpected data or error behavior.

Maintain a message ownership table:

MessageIntended transmitterPurpose
Vehicle speedReal powertrain ECU or designated simulatorProvide vehicle-speed input
Ignition stateBench simulatorSet ECU operating condition
ECU statusECU under testObserve actual ECU output

Only one source should own a message unless the test explicitly evaluates arbitration or competing transmitters.

10. Verification matrix for message simulation

Test areaStimulus or conditionEvidence to capture
Nominal transmissionValid operating stateIdentifier, DLC, payload and cycle time
Boundary valuesMinimum and maximum signal valuesCorrect raw encoding and decoded value
Invalid inputMissing, malformed, stale or out-of-range dataRejection, diagnostic state or fallback
TimingDelayed event or missed deadlineTimestamped latency and timeout verdict
Reset / restartRestart during initialization or active operationCorrect state recovery and timer behavior
Communication faultBus-off, missing frame or invalid frame as applicableError status, recovery and application behavior
Resource stressHigh bus load or competing trafficTiming and behavior under load
RegressionPreviously fixed defect and nominal scenariosRepeatable verdict against the baseline

Verify channel and database assignment, message direction, cycle time, initial values, counter/checksum behavior where specified, timeout behavior, bus load and simulation ownership. Inspect the trace to confirm the actual transmitted bytes.

11. Failure analysis and common implementation traps

SymptomPossible causeChecks
No simulated frame appearsTimer not started, node not active, wrong channel or transmit configurationMeasurement state, event execution, node assignment and channel
Wrong identifier or frame formatIncorrect message declaration or database mappingCompare configuration and trace
Wrong decoded signalIncorrect DBC revision, start bit, byte order, factor or offsetCompare raw bytes with database definition
Unexpected payloadInitialization or update logic is incorrectInspect state transitions and byte assignments
Duplicate messagesReal ECU and simulator both transmit the same messageCheck message ownership
Incorrect cycle timeTimer scheduling or load effectsInspect timestamp deltas and measurement conditions
ECU ignores simulated inputInvalid DLC, payload, checksum, counter, timeout or operating stateCompare against ECU interface requirements
Test passes inconsistentlyRace conditions, weak synchronization or undefined preconditionsMake stimulus and verdict timing explicit

Systematic debugging sequence

  1. Confirm ECU power, reset, wiring and network interface.
  2. Verify the measurement channel and CAN/CAN FD configuration.
  3. Confirm the simulation node is active and assigned to the intended channel.
  4. Check that the timer or event handler executes.
  5. Inspect the raw trace for identifier, frame format, DLC and payload.
  6. Compare raw bytes with the database signal definition.
  7. Check message ownership and bus load.
  8. Verify the ECU's operating state and input validity requirements.
  9. Save the configuration, trace and logs before changing the implementation.
  10. Add a regression test after correcting the root cause.

12. Engineering checklist

  • Message identifier and standard/extended format are correct.
  • Classical CAN or CAN FD format is selected correctly.
  • DLC and payload length match the interface definition.
  • Signal start bits, lengths, byte order, factor and offset are verified.
  • Transmission trigger and cycle time are defined.
  • Initial values and update behavior are deterministic.
  • Counter and checksum behavior follow the project specification, if applicable.
  • Real ECU and simulation-node message ownership is clear.
  • Timeout, invalid-data and shutdown behavior are defined.
  • Raw traces and test verdicts are retained.
  • Hardware, software, database and tool versions are recorded.

13. Check your understanding

  1. What is the difference between cyclic and event-triggered CAN message transmission?
  2. Why should an engineer inspect raw payload bytes when a decoded signal looks incorrect?
  3. What does output() do in the illustrative CAPL message lifecycle?
  4. Why should a simulation node not unintentionally transmit a message already owned by a real ECU?
  5. Which checks should be performed before treating a received frame as valid?
  6. Why must counter and checksum behavior be taken from the project communication specification rather than assumed?

Suggested answers

  1. Cyclic transmission is scheduled repeatedly at a defined interval; event-triggered transmission occurs in response to a specified event or condition.
  2. A database mapping error can produce an incorrect decoded value even when the raw frame is correct.
  3. It requests transmission of the configured message object through the simulation environment.
  4. Competing transmitters can cause arbitration interactions, unexpected payload behavior or communication errors.
  5. Check identifier, frame format, DLC, payload layout, signal ranges, counter/checksum where specified, freshness and operating-state preconditions.
  6. These mechanisms are project-specific; not every CAN message uses an application counter or checksum.

Related articles

Further reading

Use the standard edition, communication database, OEM network specification and CAPL documentation applicable to the target project. Confirm tool-version-specific syntax and behavior before using an example in a production test configuration.