Skip to main content

J1939GetChecksumAndCounter

Open topic with navigation CAPL Functions » J1939 » Function Overview » J1939GetChecksumAndCounter

Tool Availability

Valid for: CANoe DE • CANoe4SW DE

Function Syntax

long J1939GetChecksumAndCounter(pg * msg, char[] calculationMethod, dword & checksum, dword & counter)

Description

This function returns the checksum and the message counter of the given parameter group. The available calculation methods are described in J1939 Functional Safety – Messages With Integrated Checksum and Counter and are used to determine the alignment of the checksum and message counter in the given parameter group. After calling this function the parameters checksum and counter contain the values that were transmitted in the message, and the return value indicates if an error occurred.

Parameters

  • msg: The parameter group to get the checksum and counter from.
  • calculationMethod: Two letters in the form [A-E][a-f] (e.g. Bc) that define the calculation rule and position of the checksum and message counter.
  • checksum: The checksum retrieved from the given parameter group.
  • counter: The message counter retrieved from the given parameter group.

Return Values

  • 0: Checksum successfully filled.
  • -1: Error: calculation method is invalid.

Example

on pg *
{
  long err;
  dword checksum;
  dword counter;
  switch(this.pgn)
  {
    case 0xF123: //DCDC4OS
      err = J1939GetChecksumAndCounter(this, "Aa", checksum, counter);
      if(err != 0)
      {
        write("Invalid calculation method");
      }
      write("Checksum: %d", checksum);
      write("Message Counter: %d", counter);
      break;
    default:
      break;
  }
}