can2can example

The example demonstrates use of the Controller Area Network (CAN) driver on the Radxa ROCK 3A hardware platform to forward a message between two CAN controllers represented in the system as the can0 and can1 network interfaces.

Example directory in the SDK

The code of the example and build scripts are available at the following path:

/opt/KasperskyOS-Community-Edition-<platform>-<version>/examples/can2can

List of programs

When you build an example for the target hardware platform, platform-specific drivers are automatically included in the solution:

Initialization description

The solution initialization description file named init.yaml is generated during the solution build process based on the ./einit/src/init.yaml.in template. Macros in @INIT_*@‌ ‌format contained in the template are automatically expanded in the resulting init.yaml file. For more details, refer to init.yaml.in template.

Security policy description

The security.psl file contains a description of a security policy for a KasperskyOS-based solution and is located in the ./einit/src directory. The declarations in the PSL file are provided with comments that explain the purpose of these declarations.

The security.psl file is a top-level file that includes a part of the solution security policy description in the form of a PSL file dynld.psl via the use declaration. The dynld.psl file contains the security policy description that is used when dynamically linking the solution components. The declarations in the PSL files are provided with comments that explain the purpose of these declarations.

Resources

The ./resources/xdl/can2can directory contains the CanClient.edl file, which is the EDL description for the CanClient program.

Operating scenario

The CanClient program performs the following actions:

  1. Initializes the CAN driver.
  2. Opens two CAN interfaces (can0 and can1) with the same baud rate defined by the CAN_BR_800KBS constant.

    The example uses the classic CAN settings, which establish a baud rate limit of 1 MB/s. When setting the baud rate, you must use only the following constants:

    • CAN_BR_1MBS
    • CAN_BR_800KBS
    • CAN_BR_500KBS
    • CAN_BR_250KBS
    • CAN_BR_125KBS
    • CAN_BR_62_5KBS
  3. Generates the test CAN packet that contains the packet ID, length of the data field, and the data. A description of the fields is provided in the CanFrame structure. For Classical CAN, the length of the data field is limited to 8 bytes.
  4. Transmits a prepared CAN packet via the can0 interface and waits 5000 ms for it to be received via the can1 interface. (The CAN driver does not impose any restrictions on the message sending direction.)
  5. Compares the received CAN packet with the sent packet to verify that the ID, length of the data field and all data bytes match.
  6. Closes the CAN interfaces and terminates with the EXIT_SUCCESS code upon successful completion of all operations, or shows the EXIT_FAILURE code if errors occurred.

Building and running the example

The CMake system, which is included with KasperskyOS Community Edition, is used to build and run the example.

This example is intended to run only on Radxa ROCK 3A. If you build and run this example in QEMU, an error will occur. This is the expected behavior, because there is no CAN driver for QEMU.

In contrast to the can_loopback example, which uses only one CAN interface and does not require additional equipment, this example requires two TJA1050 transceivers connected to the CAN_H and CAN_L lines.

For the example to work correctly, you must do the following:

See Building and running examples section.

Page top