Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Titan » The Titan SocketCAN test port(CAN bus, J1939, CAN RAW, CAN BCM, ISOTP)
The Titan SocketCAN test port [message #1818499] Tue, 17 December 2019 14:45
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 1063
Registered: January 2015
Senior Member
Dear all,

we will present below a Titan test port that can be used to access and run tests over a CAN bus.
This test port is the work of our contributor Michael Josenhans.



A Controller Area Network (CAN bus) is a robust vehicle bus standard designed to allow
microcontrollers and devices to communicate with each others' applications without a
host computer. It is a message-based protocol, designed originally for multiplex electrical
wiring within automobiles to save on copper, but can also be used in many other contexts.
For each device the data in a packet is transmitted sequentially but in such a way that
if more than one device transmits at the same time the highest priority device is able
to continue while the others back off. Packets are received by all devices,
including by the transmitting device.

Development of the CAN bus started in 1983 at Robert Bosch GmbH.
The protocol was officially released in 1986 at the Society of Automotive Engineers (SAE) conference in Detroit, Michigan. The first CAN controller chips, produced by Intel and Philips, came on the market in 1987. Released in 1991, the Mercedes-Benz W140 was the first production vehicle to feature
a CAN-based multiplex wiring system.

Applications:
-Passenger vehicles, trucks, buses (gasoline vehicles and electric vehicles)
-Agricultural equipment
-Electronic equipment for aviation and navigation
-Industrial automation and mechanical control
-Elevators, escalators
-Building automation
-Medical instruments and equipment

(see https://en.wikipedia.org/wiki/CAN_bus)


The brief presentation below mainly reproduces the content of the README file in the /doc folder created by Michael:



# titan.TestPorts.SocketCANasp

Main project page:

https://git.eclipse.org/c/titan/titan.TestPorts.SocketCANasp.git/


References:
https://www.kernel.org/doc/Documentation/networking/can.txt

Other useful documentation:
https://elinux.org/TTCN
https://docs.python.org/3/library/socket.html (search for: "AF_CAN")
https://media.readthedocs.org/pdf/python-can/latest/python-can.pdf
http://www.can-cia.de/fileadmin/resources/documents/proceedings/2012_hartkopp.pdf
http://v2.can-newsletter.org/uploads/media/raw/46c15d02e1fdd3b04e671693ec548ff7.pdf



# See file: demo/initscript.sh:

#--------------------------------------
#!/bin/bash


# create a virtual can interface:

sudo modprobe vcan
sudo ip link add dev vcan0 type vcan
sudo ip link set vcan0 up

#!/bin/bash

# Add vcan module to kernel
sudo modprobe vcan

# Setup of virtual can vcan0
sudo ip link add dev vcan0 type vcan
# set it up at as a canfd capable can interface
sudo ip link set vcan0 mtu 72
sudo ip link set vcan0 up

# or create a physical can interface
# sudo ip link set can0 up type can bitrate 1000000

ip a

#--------------------------------------

cd src
./demo/initscript.sh

or alternatively
source demo/initscript.sh

make clean; make

ttcn3_start SocketCAN SocketCAN.cfg
or
ttcn3_start SocketCAN CAN_matrix_test.cfg

or to run a certain testcase:

ttcn3_start SocketCAN SocketCAN.cfg SocketCAN_RAW_test.tc_can_raw_send_and_receive_can_frame SocketCAN_RAW_test.tc_can_raw_setsockopt_CAN_RAW_FILTER

Review the newly created log files in the src directory
and use e.g. Wireshark to trace the CAN interfacce.

#--------------------------------------
Notes:
-Using multiple Test interfaces:
Currently the init script sets up multiple virtual can interfaces ("vcan0",
"vcan1" in order to allow using multiple CAN interfaces.
The CAN interfaces have to be defined in the TTCN configuration files or may
alternatively be defined in the optional parameters of port messages commands
ioctl and send_data.

Handling of multiple CAN interfaces is work in progress and no test cases are
provided. In order to configure usage with multiple test interfaces,
test interfaces for each interface have to be defined in the MTC.

-CAN RAW:
CAN FD has been implemented, however not been tested.
Depending on the availability of the C-code #define "CAN_FD_FRAME"
in /usr/include/linux/can/bcm.h, CAN-FD support is enabled at compile time.
The RAW setsockopt has path coverage. However no test coverage that insures the setsockopt functionality provided by the kernel is working correctly.
For this purpose in the future might be added additional test cases.

-CAN BCM:
TX_SETUP, TX_DELETE have been tested, TX_READ is known to fail test cases.
Some tests have indicated, that that SocketCAN BCM does not support concurrently active BCM channels.
The BCM has test coverage for TX_SETUP and TX_DELETE. However no test coverage that insures the BCM functionality provided by the kernel is working correctly.
For this purpose in the future might be added additional test cases.
Return values other than the error code by the BCM are not yet supported.
BCM with CAN FD frames has not been tested yet.

-ISOTP:
Iso TP functionality has been added, however currently no options like padding are supported. Feel free to request needed options.

First install the isotp kernel module as described here:
https://github.com/hartkopp/can-isotp-modules

./make_isotp.sh
sudo insmod ./can-isotp.ko


There is one endlessly running test case:
ttcn3_start SocketCAN SocketCAN.cfg Isotptest.tc_Isotp_Example001

-CAN J1939:
Configure CAN J1939 as following (requires Kernel 5.4 and compiled with can-j1939 kernel module):
sudo modprobe vcan
sudo ip link add vcan0 type vcan
sudo ip link set vcan0 up
sudo modprobe can-j1939

For the following test cases, the messages are so huge that screen output of the log file takes too long.
Thus comment out as following the following lines in J1939.cfg:
//FileMask := LOG_ALL | DEBUG | MATCHING
//ConsoleMask := LOG_ALL | DEBUG | MATCHING

ttcn3_start SocketCAN J1939.cfg SocketCAN_J1939_test.tc_can_j1939_send_and_receive_can_frame
ttcn3_start SocketCAN J1939.cfg SocketCAN_J1939_test.tc_can_j1939_send_and_receive_can_frame_parallel

Here above lines can be commented in:
ttcn3_start SocketCAN J1939.cfg SocketCAN_J1939_test.tc_can_f_j1939_address_claim
ttcn3_start SocketCAN J1939.cfg SocketCAN_J1939_test.tc_can_f_j1939_address_claim2


-Merging of logfiles:
To merge the logfiles from multiple Parallel Test Components (PTCs) from a single execution in timely order into a single file, run:
$TTCN3_DIR/bin/ttcn3_logmerge -o log_merged.txt *.log
The merged log-file is found at log_merged.txt

-Dumping CAN Frames using SocketCAN:
To dump all received can frames of e.g. "vcan0" run a separate terminal:
$ candump "vcan0"




Best regards
Elemer

[Updated on: Tue, 17 December 2019 17:08]

Report message to a moderator

Previous Topic:Design of Broadband Micro-Power Wireless Communication Test System Based on TTCN-3
Next Topic:ttcn3 in container environment
Goto Forum:
  


Current Time: Tue Jul 07 15:46:12 GMT 2020

Powered by FUDForum. Page generated in 0.01238 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top