KasperskyOS Community Edition 1.3

can2can example

Example use of the CAN driver.

This example demonstrates use of the CAN driver to forward a message between two CAN interfaces.

In contrast to the can_loopback example, which uses only one CAN interface and does not require additional equipment, this example requires two transceivers that are connected to the CAN_H and CAN_L lines. A description of the ways to connect transceivers to the built-in CAN controllers is provided in the example directory.

The example sends a CAN packet between the can0 and can1 interfaces. The example uses the Classical CAN settings, which assumes a transfer rate limit of 1 MBps.

When configuring the transfer 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

The CAN driver does not impose restrictions on the direction of message transmission. In the example, a message is sent from can0 to can1, but you can also send it in the reverse direction when using the CanTransmitFrame function.

The test CAN packet 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.

Example files

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

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

Building and running 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.

See Building and running examples section.