git commit -m "first commit for v2"
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
#!/usr/bin/env ../libs/bats-core/bin/bats
|
||||
load '../libs/bats-support/load.bash'
|
||||
load '../libs/bats-assert/load.bash'
|
||||
|
||||
setup_file() {
|
||||
. ./config_bats.sh
|
||||
|
||||
if [[ $binaryFileSize = "" ]] ; then
|
||||
export binaryFileSize=100000
|
||||
fi
|
||||
if [[ $binaryFileSegSize = "" ]] ; then
|
||||
export binaryFileSegSize=1000
|
||||
fi
|
||||
|
||||
export sedStr='s/^\([0-9]*\).*/\1/'
|
||||
}
|
||||
|
||||
teardown_file() {
|
||||
cat binaryFileReport >&3
|
||||
rm binaryFile*
|
||||
run rm fileWrittenByDomain
|
||||
}
|
||||
|
||||
@test 'Segmented transfer - set filename for upload' {
|
||||
assert $cocomm -n0 "set sdo_block 0"
|
||||
run $cocomm -n8 "[1] 0x$D2 w 0x2120 11 vs fileWrittenByDomain"
|
||||
assert_success
|
||||
assert_output "[1] $OK
|
||||
6$D2#2120210B13000000
|
||||
5$B2#6020210B00000000
|
||||
6$D2#0066696C65577269
|
||||
5$B2#2000000000000000
|
||||
6$D2#107474656E427944
|
||||
5$B2#3000000000000000
|
||||
6$D2#056F6D61696E0000
|
||||
5$B2#2000000000000000"
|
||||
}
|
||||
|
||||
@test "Block transfer, create $binaryFileSize bytes long random binaryFile" {
|
||||
assert openssl rand $binaryFileSize > binaryFile
|
||||
}
|
||||
|
||||
@test 'Block download binaryFile' {
|
||||
assert $cocomm -n0 "set sdo_block 1"
|
||||
time_begin=$(date +%s.%N)
|
||||
assert base64 -w0 binaryFile | $cocomm -n0 -i "[1] 0x$D2 w 0x2120 10 d"
|
||||
time_end=$(date +%s.%N)
|
||||
time_diff=$(echo "($time_end - $time_begin) * 1000" | bc | sed $sedStr)
|
||||
echo -n "# $binaryFileSize bytes block down/upload: $time_diff/" > binaryFileReport
|
||||
}
|
||||
|
||||
@test 'Block upload to binaryFileReceived - 2x' {
|
||||
assert $cocomm -n0 "set sdo_block 1"
|
||||
time_begin=$(date +%s.%N)
|
||||
assert $cocomm -n0 -odata "[1] 0x$D2 r 0x2120 10 d" | base64 -d > binaryFileReceived1
|
||||
assert $cocomm -n0 -odata "[1] 0x$D2 r 0x2120 10 d" | base64 -d > binaryFileReceived2
|
||||
time_end=$(date +%s.%N)
|
||||
time_diff=$(echo "($time_end - $time_begin) * 1000 / 2" | bc | sed $sedStr)
|
||||
echo "$time_diff milliseconds." >> binaryFileReport
|
||||
}
|
||||
|
||||
@test 'Block transfer, files equal' {
|
||||
assert cmp binaryFile binaryFileReceived1
|
||||
assert cmp binaryFile binaryFileReceived2
|
||||
}
|
||||
|
||||
@test "Segmented transfer, create $binaryFileSegSize bytes long random binaryFileSeg" {
|
||||
assert openssl rand $binaryFileSegSize > binaryFileSeg
|
||||
}
|
||||
|
||||
@test 'Segmented download binaryFileSeg' {
|
||||
assert $cocomm -n0 "set sdo_block 0"
|
||||
time_begin=$(date +%s.%N)
|
||||
assert base64 -w0 binaryFileSeg | $cocomm -n0 -i "[1] 0x$D2 w 0x2120 10 d"
|
||||
time_end=$(date +%s.%N)
|
||||
time_diff=$(echo "($time_end - $time_begin) * 1000" | bc | sed $sedStr)
|
||||
echo -n "# $binaryFileSegSize bytes segmented down/upload: $time_diff/" >> binaryFileReport
|
||||
}
|
||||
|
||||
@test 'Segmented upload to binaryFileSegReceived' {
|
||||
assert $cocomm -n0 "set sdo_block 0"
|
||||
time_begin=$(date +%s.%N)
|
||||
assert $cocomm -n0 -odata "[1] 0x$D2 r 0x2120 10 d" | base64 -d > binaryFileSegReceived
|
||||
time_end=$(date +%s.%N)
|
||||
time_diff=$(echo "($time_end - $time_begin) * 1000" | bc | sed $sedStr)
|
||||
echo "$time_diff milliseconds." >> binaryFileReport
|
||||
}
|
||||
|
||||
@test 'Segmented transfer, files equal' {
|
||||
assert cmp binaryFileSeg binaryFileSegReceived
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
#!/usr/bin/env ../libs/bats-core/bin/bats
|
||||
load '../libs/bats-support/load.bash'
|
||||
load '../libs/bats-assert/load.bash'
|
||||
|
||||
setup_file() {
|
||||
. ./config_bats.sh
|
||||
}
|
||||
|
||||
@test 'NMT: all preoperational' {
|
||||
# cocomm must exit with success (return value is 0 (and output is "[1] OK"))
|
||||
# and must receive at least one CAN message (option -n1) in time interval.
|
||||
assert $cocomm -n1 "0 preoperational"
|
||||
}
|
||||
|
||||
@test 'SDO: read heartbeat D1' {
|
||||
# cocomm must exit with success.
|
||||
# There is no can message, because SDO of master device works on itself.
|
||||
assert $cocomm -n0 "0x$D1 r 0x1017 0 i16"
|
||||
}
|
||||
|
||||
@test 'SDO: read heartbeat D2' {
|
||||
# cocomm must exit with success and must receive two CAN messages.
|
||||
assert $cocomm -n2 "0x$D2 r 0x1017 0 i16"
|
||||
}
|
||||
|
||||
@test 'SDO: disable heartbeats' {
|
||||
# Run cocomm with four commands, it must exit with success (response from
|
||||
# each command is success, none of responses is "ERROR").
|
||||
run $cocomm -n2 "[1] 0x$D1 w 0x1017 0 i16 0" \
|
||||
"[2] 0x$D2 w 0x1017 0 i16 0"
|
||||
# run must exit with success (none of command responses is "ERROR").
|
||||
assert_success
|
||||
# run output must match the string - exact match including newlines and '\r'
|
||||
assert_output "[1] $OK
|
||||
[2] $OK
|
||||
6$D2#2B17100000000000
|
||||
5$B2#6017100000000000"
|
||||
}
|
||||
|
||||
@test 'candump: no communication, 2sec' {
|
||||
sleep 0.2
|
||||
# cocomm must exit with error (timeout - no message within 2000 ms)
|
||||
refute $cocomm -n1 -T2000 "0x$D1 w 0x1017 0 i16 0"
|
||||
}
|
||||
|
||||
@test 'Heartbeats: all present' {
|
||||
assert $cocomm -n2 "[1] 0x$D1 w 0x1017 0 i16 0x$HB"
|
||||
assert $cocomm -n0 "[2] 0x$D1 w 0x1017 0 i16 0"
|
||||
assert $cocomm -n4 "[3] 0x$D2 w 0x1017 0 i16 0x$HB"
|
||||
assert $cocomm -n2 "[4] 0x$D2 w 0x1017 0 i16 0"
|
||||
}
|
||||
|
||||
@test 'NMT: reset communication - one' {
|
||||
run $cocomm -n2 "[1] 0x$D1 reset comm"
|
||||
assert_success
|
||||
assert_output "[1] $OK
|
||||
000#82$D1
|
||||
7$D1#00"
|
||||
run $cocomm -n2 "[2] 0x$D2 reset comm"
|
||||
assert_success
|
||||
assert_output "[2] $OK
|
||||
000#82$D2
|
||||
7$D2#00"
|
||||
}
|
||||
|
||||
@test 'NMT: reset communication - two' {
|
||||
run $cocomm -n2 "[1] 0x$D1 reset comm"
|
||||
assert_success
|
||||
assert_output "[1] $OK
|
||||
000#82$D1
|
||||
7$D1#00"
|
||||
run $cocomm -n2 "[2] 0x$D2 reset comm"
|
||||
assert_success
|
||||
assert_output "[2] $OK
|
||||
000#82$D2
|
||||
7$D2#00"
|
||||
}
|
||||
|
||||
@test 'NMT: reset communication - three' {
|
||||
run $cocomm -n2 "[1] 0x$D1 reset comm"
|
||||
assert_success
|
||||
assert_output "[1] $OK
|
||||
000#82$D1
|
||||
7$D1#00"
|
||||
run $cocomm -n2 "[2] 0x$D2 reset comm"
|
||||
assert_success
|
||||
assert_output "[2] $OK
|
||||
000#82$D2
|
||||
7$D2#00"
|
||||
}
|
||||
|
||||
@test 'all preoperational' {
|
||||
assert $cocomm -n1 "0 preoperational"
|
||||
}
|
||||
|
||||
@test 'SDO: disable all PDOs on D1' {
|
||||
run $cocomm -n0 "[11] 0x$D1 w 0x1400 1 u32 0x800002$D1" \
|
||||
"[12] 0x$D1 w 0x1401 1 u32 0x800003$D1" \
|
||||
"[13] 0x$D1 w 0x1402 1 u32 0x800004$D1" \
|
||||
"[14] 0x$D1 w 0x1403 1 u32 0x800005$D1" \
|
||||
"[15] 0x$D1 w 0x1800 1 u32 0x800001$B1" \
|
||||
"[16] 0x$D1 w 0x1801 1 u32 0x800002$B1" \
|
||||
"[17] 0x$D1 w 0x1802 1 u32 0x800003$B1" \
|
||||
"[18] 0x$D1 w 0x1803 1 u32 0x800004$B1"
|
||||
assert_success
|
||||
assert_output "[11] $OK
|
||||
[12] $OK
|
||||
[13] $OK
|
||||
[14] $OK
|
||||
[15] $OK
|
||||
[16] $OK
|
||||
[17] $OK
|
||||
[18] $OK"
|
||||
}
|
||||
@test 'SDO: disable all PDOs on D2' {
|
||||
run $cocomm -n16 "[21] 0x$D2 w 0x1400 1 u32 0x800002$D2" \
|
||||
"[22] 0x$D2 w 0x1401 1 u32 0x800003$D2" \
|
||||
"[23] 0x$D2 w 0x1402 1 u32 0x800004$D2" \
|
||||
"[24] 0x$D2 w 0x1403 1 u32 0x800005$D2" \
|
||||
"[25] 0x$D2 w 0x1800 1 u32 0x800001$B2" \
|
||||
"[26] 0x$D2 w 0x1801 1 u32 0x800002$B2" \
|
||||
"[27] 0x$D2 w 0x1802 1 u32 0x800003$B2" \
|
||||
"[28] 0x$D2 w 0x1803 1 u32 0x800004$B2"
|
||||
assert_success
|
||||
assert_output "[21] $OK
|
||||
[22] $OK
|
||||
[23] $OK
|
||||
[24] $OK
|
||||
[25] $OK
|
||||
[26] $OK
|
||||
[27] $OK
|
||||
[28] $OK
|
||||
6$D2#23001401"$D2"020080
|
||||
5$B2#6000140100000000
|
||||
6$D2#23011401"$D2"030080
|
||||
5$B2#6001140100000000
|
||||
6$D2#23021401"$D2"040080
|
||||
5$B2#6002140100000000
|
||||
6$D2#23031401"$D2"050080
|
||||
5$B2#6003140100000000
|
||||
6$D2#23001801"$B2"010080
|
||||
5$B2#6000180100000000
|
||||
6$D2#23011801"$B2"020080
|
||||
5$B2#6001180100000000
|
||||
6$D2#23021801"$B2"030080
|
||||
5$B2#6002180100000000
|
||||
6$D2#23031801"$B2"040080
|
||||
5$B2#6003180100000000"
|
||||
}
|
||||
|
||||
@test 'NMT: pre-operational D1' {
|
||||
run $cocomm -n2 "[1] 0x$D1 w 0x1017 0 i16 0x$HB"
|
||||
assert_success
|
||||
assert_output "[1] $OK
|
||||
7$D1#7F
|
||||
7$D1#7F"
|
||||
}
|
||||
@test 'NMT: operational D1' {
|
||||
run $cocomm -n3 "[1] 0x$D1 start"
|
||||
assert_success
|
||||
assert_output "[1] $OK
|
||||
000#01$D1
|
||||
7$D1#05
|
||||
7$D1#05"
|
||||
assert $cocomm -n0 "0x$D1 w 0x1017 0 i16 0"
|
||||
}
|
||||
|
||||
@test 'NMT: pre-operational D2' {
|
||||
run $cocomm -n4 "[1] 0x$D2 w 0x1017 0 i16 0x$HB"
|
||||
assert_success
|
||||
assert_output "[1] $OK
|
||||
6$D2#2B171000"$HB"000000
|
||||
5$B2#6017100000000000
|
||||
7$D2#7F
|
||||
7$D2#7F"
|
||||
}
|
||||
@test 'NMT: operational D2' {
|
||||
run $cocomm -n3 "[1] 0x$D2 start"
|
||||
assert $cocomm -n2 "0x$D2 w 0x1017 0 i16 0"
|
||||
assert_success
|
||||
assert_output "[1] $OK
|
||||
000#01$D2
|
||||
7$D2#05
|
||||
7$D2#05"
|
||||
}
|
||||
|
||||
@test 'finish: NMT all preoperational' {
|
||||
assert $cocomm -n1 "0 preoperational"
|
||||
}
|
||||
47
Devices/Libraries/Systems/CANopenSocket/test/running_canopen/config_bats.sh
Executable file
47
Devices/Libraries/Systems/CANopenSocket/test/running_canopen/config_bats.sh
Executable file
@@ -0,0 +1,47 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
# CAN device for candump
|
||||
if [[ $can_device = "" ]] ; then
|
||||
export can_device=vcan0
|
||||
fi
|
||||
|
||||
# Location of cocomm program
|
||||
if [[ $cocomm = "" ]] ; then
|
||||
export cocomm="../../cocomm/cocomm"
|
||||
fi
|
||||
|
||||
# Heartbeat producer time, 0xA0 = 160ms
|
||||
if [[ $HB = "" ]] ; then
|
||||
export HB=A0
|
||||
fi
|
||||
|
||||
# Heartbeat consumer timeout, 0xF0 = 240ms
|
||||
if [[ $HB_timeout = "" ]] ; then
|
||||
export HB_timeout=F0
|
||||
fi
|
||||
|
||||
# NodeId of device 1 (with command interface)
|
||||
if [[ $D1 = "" ]] ; then
|
||||
export D1=01
|
||||
fi
|
||||
# NodeId of device 1 + 0x80
|
||||
if [[ $B1 = "" ]] ; then
|
||||
export B1=81
|
||||
fi
|
||||
# NodeId of device 2 (tested device)
|
||||
if [[ $D2 = "" ]] ; then
|
||||
export D2=04
|
||||
fi
|
||||
# NodeId of device 2 + 0x80
|
||||
if [[ $B2 = "" ]] ; then
|
||||
export B2=84
|
||||
fi
|
||||
|
||||
# Other
|
||||
export OK=$'OK\r'
|
||||
export cocomm_flat=1
|
||||
export cocomm_candump=$can_device
|
||||
# export cocomm_socket=/tmp/CO_command_socket #default
|
||||
# export cocomm_host=
|
||||
# export cocomm_port=
|
||||
@@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env ../libs/bats-core/bin/bats
|
||||
load '../libs/bats-support/load.bash'
|
||||
load '../libs/bats-assert/load.bash'
|
||||
|
||||
setup_file() {
|
||||
. ./config_bats.sh
|
||||
}
|
||||
|
||||
@test 'Start heartbeat producer on D1 only' {
|
||||
assert $cocomm -n8 "[1] 0x$D2 w 0x1017 0 i16 0" \
|
||||
"[2] 0x$D2 w 0x1016 2 u32 0" \
|
||||
"[3] 0 reset communication" \
|
||||
"[4] 0x$D1 w 0x1017 0 i16 0x$HB"
|
||||
run $cocomm -n2 "0 preoperational"
|
||||
assert_success
|
||||
assert_output "[1] $OK
|
||||
000#8000
|
||||
7$D1#7F"
|
||||
}
|
||||
|
||||
@test 'Start heartbeat consumer on D2' {
|
||||
run $cocomm -n4 "[1] 0x$D2 w 0x1016 2 u32 0x00"$D1"00$HB_timeout"
|
||||
assert_success
|
||||
assert_output "[1] $OK
|
||||
6$D2#23161002"$HB_timeout"000100
|
||||
5$B2#6016100200000000
|
||||
7$D1#7F
|
||||
7$D1#7F"
|
||||
}
|
||||
|
||||
@test 'Heartbeat producer D1 missing' {
|
||||
run $cocomm -n1 "[1] 0x$D1 w 0x1017 0 i16 0"
|
||||
assert_success
|
||||
assert_output "[1] $OK
|
||||
0$B2#3081101B01000000"
|
||||
}
|
||||
|
||||
@test 'Heartbeat producer D1 established' {
|
||||
run $cocomm -n3 "[1] 0x$D1 w 0x1017 0 i16 0x$HB"
|
||||
assert_success
|
||||
assert_output "[1] $OK
|
||||
7$D1#7F
|
||||
0$B2#0000001B00000000
|
||||
7$D1#7F"
|
||||
}
|
||||
|
||||
@test 'Bootup message D1' {
|
||||
run $cocomm -n6 "0x$D1 reset communication"
|
||||
assert_success
|
||||
assert_output "[1] $OK
|
||||
000#8201
|
||||
7$D1#00
|
||||
0$B2#3081101C01000000
|
||||
7$D1#05
|
||||
0$B2#0000001C00000000
|
||||
7$D1#05"
|
||||
}
|
||||
|
||||
@test 'Second HB consumer configuration' {
|
||||
assert $cocomm -n2 "[1] 0x$D2 w 0x1016 3 u32 0x005500$HB_timeout"
|
||||
}
|
||||
|
||||
@test 'Illegal HB consumer configuration (duplicate nodeId)' {
|
||||
refute $cocomm -n2 "[1] 0x$D2 w 0x1016 3 u32 0x00"$D1"00$HB_timeout"
|
||||
}
|
||||
|
||||
@test 'Cleanup' {
|
||||
assert $cocomm -n7 "[1] 0x$D1 w 0x1017 0 i16 0" \
|
||||
"[2] 0x$D2 w 0x1016 2 u32 0" \
|
||||
"[2] 0x$D2 w 0x1016 3 u32 0" \
|
||||
"[3] 0 reset communication"
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ $1 = "" ]] ; then
|
||||
echo "Usage: $0 <CAN device>"
|
||||
exit
|
||||
else
|
||||
export can_device=$1
|
||||
fi
|
||||
|
||||
if [[ $co_device_1 = "" ]] ; then
|
||||
export co_device_1="../../CANopenNode/canopend"
|
||||
fi
|
||||
if [[ $co_device_4 = "" ]] ; then
|
||||
export co_device_4="../../examples/basicDevice/basicDevice"
|
||||
fi
|
||||
|
||||
export cleanup=tmp/stop_canopen.sh
|
||||
|
||||
# if "can_device" does not exist, create virtual CAN device
|
||||
if ! grep -q $can_device /proc/net/can/rcvlist_all ; then
|
||||
echo "ip link: adding and setting up virtual CAN device named '$can_device'"
|
||||
sudo modprobe vcan
|
||||
sudo ip link add dev $can_device type vcan
|
||||
sudo ip link set up $can_device
|
||||
fi
|
||||
|
||||
# prepare files for storage
|
||||
mkdir tmp
|
||||
|
||||
# prepare stop script and run CANopen devices in background
|
||||
echo "#!/bin/bash" > $cleanup
|
||||
chmod a+x $cleanup
|
||||
|
||||
echo "Running in background: '$co_device_1 $can_device -i 1 -s \"tmp/dev1_\" -c \"local-/tmp/CO_command_socket\"'"
|
||||
echo "-" > tmp/dev1_lss.persist
|
||||
echo "-" > tmp/dev1_od_comm.persist
|
||||
$co_device_1 $can_device -i 1 -s "tmp/dev1_" -c "local-/tmp/CO_command_socket"&
|
||||
echo kill $! >> $cleanup
|
||||
sleep 0.1
|
||||
echo
|
||||
|
||||
echo "Running in background: '$co_device_4 $can_device -i 4 -s \"tmp/dev4_\"'"
|
||||
echo "-" > tmp/dev4_lss.persist
|
||||
echo "-" > tmp/dev4_od_comm.persist
|
||||
echo "-" > tmp/dev4_od_test_auto.persist
|
||||
echo "-" > tmp/dev4_od_test.persist
|
||||
$co_device_4 $can_device -i 4 -s "tmp/dev4_"&
|
||||
echo kill $! >> $cleanup
|
||||
sleep 0.1
|
||||
echo
|
||||
|
||||
echo "rm -r tmp" >> $cleanup
|
||||
|
||||
echo "For cleanup run: $cleanup"
|
||||
echo
|
||||
34
Devices/Libraries/Systems/CANopenSocket/test/running_canopen/test_all.sh
Executable file
34
Devices/Libraries/Systems/CANopenSocket/test/running_canopen/test_all.sh
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ $1 = "" ]] ; then
|
||||
echo "No CAN device specified. Assuming two CANopen devices already running:"
|
||||
echo " - 'canopend' with nodeId=1 and gateway interface: 'local-/tmp/CO_command_socket'"
|
||||
echo " - 'basicDevice' with nodeId=4"
|
||||
echo "If that is not the case, read test.md or try: ./test_all.sh vcan0"
|
||||
else
|
||||
echo "Starting two CANopen devices in background with 'start_canopen.sh':"
|
||||
./start_canopen.sh $1
|
||||
fi
|
||||
|
||||
|
||||
START=$(date +%s.%N)
|
||||
|
||||
echo -e "\nRunning 'basic_NMT_SDO_heartbeat.bats':"
|
||||
./basic_NMT_SDO_heartbeat.bats
|
||||
echo -e "\nRunning 'heartbeat_consumer.bats':"
|
||||
./heartbeat_consumer.bats
|
||||
echo -e "\nRunning 'SDO_transfer.bats':"
|
||||
./SDO_transfer.bats
|
||||
|
||||
END=$(date +%s.%N)
|
||||
DIFF=$(echo "$END - $START" | bc)
|
||||
echo -e "Test duration: $DIFF sec\n"
|
||||
|
||||
|
||||
if [[ $1 != "" ]] ; then
|
||||
echo "Cleanup two CANopen devices:"
|
||||
tmp/stop_canopen.sh
|
||||
fi
|
||||
|
||||
echo -e "\nPress enter to close..."
|
||||
read
|
||||
83
Devices/Libraries/Systems/CANopenSocket/test/test.md
Executable file
83
Devices/Libraries/Systems/CANopenSocket/test/test.md
Executable file
@@ -0,0 +1,83 @@
|
||||
Test
|
||||
====
|
||||
|
||||
Tests in Running CANopen network
|
||||
--------------------------------
|
||||
|
||||
Tests on Running CANopen network are implemented with two CANopenNode devices, by default running on Linux virtual CAN interface. One of them has gateway interface and communicates with program `cocomm`.
|
||||
|
||||
Tests are run in Linux command line with [Bash Automated Testing System - BATS](https://github.com/bats-core/bats-core), which is included in CANopenSocket as three git submodules.
|
||||
|
||||
Test results are available in [test_report.md](test_report.md).
|
||||
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- Get CANopenSocket and all submodules as described in README.md
|
||||
- make `cocomm`, `canopend` and `basicDevice`
|
||||
|
||||
|
||||
### Run tests automatically
|
||||
|
||||
cd test/running_canopen$
|
||||
./test_canopend.sh vcan0
|
||||
|
||||
This will:
|
||||
1. start `vcan0` interface if not already existed.
|
||||
2. run two CANopenNode Linux devices in background (`start_canopen.sh` script):
|
||||
- `CANopenNode/canopend` with nodeId=1 and gateway interface: `local-/tmp/CO_command_socket`
|
||||
- `examples/basicDevice/basicDevice` with nodeId=4
|
||||
3. run tests and measure time
|
||||
4. cleanup (`tmp/stop_canopen.sh` script, generated by `start_canopen.sh`).
|
||||
|
||||
If argument `vcan0` or similar is omitted, it is assumed, two CANopen devices are already running in system. In that case steps 1, 2 and 4 are skipped.
|
||||
|
||||
|
||||
### Start two CANopen devices manually
|
||||
|
||||
`start_canopen.sh <CAN device>` script runs two CANopenNode Linux devices in background.
|
||||
|
||||
Possible configuration options can configure CANopenNode applications. To override default values run the commands from command line before running test scripts. Default configuration is:
|
||||
|
||||
export co_device_1="../../CANopenNode/canopend"
|
||||
export co_device_4="../../examples/basicDevice/basicDevice"
|
||||
|
||||
It is possible to run two CANopen devices without `start_canopen.sh` script and then run the tests. Devices can be connected with on real CAN bus and second device can run on any target system. By default this script runs following commands and prepares `tmp/stop_canopen.sh` script for cleanup:
|
||||
|
||||
sudo modprobe vcan
|
||||
sudo ip link add dev vcan0 type vcan
|
||||
sudo ip link set up vcan0
|
||||
|
||||
mkdir tmp
|
||||
echo "-" > tmp/dev1_lss.persist
|
||||
echo "-" > tmp/dev1_od_comm.persist
|
||||
../../CANopenNode/canopend vcan0 -i 1 -s "tmp/dev1_" -c "local-/tmp/CO_command_socket"
|
||||
|
||||
echo "-" > tmp/dev4_lss.persist
|
||||
echo "-" > tmp/dev4_od_comm.persist
|
||||
echo "-" > tmp/dev4_od_app_auto.persist
|
||||
echo "-" > tmp/dev4_od_app.persist
|
||||
../../examples/basicDevice/basicDevice vcan0 -i 4 -s "tmp/dev4_"
|
||||
|
||||
# after finish with testing terminate the programs and `rm -r tmp`
|
||||
|
||||
There is also a helper script, which runs only canopend and candump on specified interface in terminal:
|
||||
|
||||
cd tools
|
||||
./run_canopend_candump.sh <can device>
|
||||
|
||||
|
||||
### Run the tests manually
|
||||
|
||||
Before running the tests, specify cocomm location and CAN device, which will be used for monitoring CAN messages (candump). To override other configuration variables see file `config_bats.sh`. Default configuration is:
|
||||
|
||||
export can_device=vcan0
|
||||
export cocomm="../../cocomm/cocomm"
|
||||
|
||||
Then simply run the separate tests from the same terminal:
|
||||
|
||||
./basic_NMT_SDO_heartbeat.bats
|
||||
./heartbeat_consumer.bats
|
||||
./SDO_transfer.bats
|
||||
|
||||
Open the `*.bats` script file in text editor and examine the contents. Script is quite straightforward, see [BATS usage](https://bats-core.readthedocs.io/en/latest/writing-tests.html) and [BATS assert](https://github.com/bats-core/bats-assert) for information on testing commands. Command line program `cocomm` is used for running each test. For `cocomm` example usage see [basicDevice/README.md](../examples/basicDevice/README.md). Program uses here one additional functionality - it prints dump of actual CAN messages, which occur with each `cocomm` command. So BATS can verify the complete result.
|
||||
160
Devices/Libraries/Systems/CANopenSocket/test/test_report.md
Executable file
160
Devices/Libraries/Systems/CANopenSocket/test/test_report.md
Executable file
@@ -0,0 +1,160 @@
|
||||
TEST REPORTS
|
||||
============
|
||||
|
||||
Complete tests in running CANopen
|
||||
---------------------------------
|
||||
`running_canopen/test_all.sh`, two CAN devices, 1000 kbps:
|
||||
```
|
||||
No CAN device specified. Assuming two CANopen devices already running:
|
||||
- 'canopend' with nodeId=1 and gateway interface: 'local-/tmp/CO_command_socket'
|
||||
- 'basicDevice' with nodeId=4
|
||||
If that is not the case, read test.md or try: ./test_all.sh vcan0
|
||||
|
||||
Running 'basic_NMT_SDO_heartbeat.bats':
|
||||
✓ NMT: all preoperational
|
||||
✓ SDO: read heartbeat D1
|
||||
✓ SDO: read heartbeat D2
|
||||
✓ SDO: disable heartbeats
|
||||
✓ candump: no communication, 2sec
|
||||
✓ Heartbeats: all present
|
||||
✓ NMT: reset communication - one
|
||||
✓ NMT: reset communication - two
|
||||
✓ NMT: reset communication - three
|
||||
✓ all preoperational
|
||||
✓ SDO: disable all PDOs on D1
|
||||
✓ SDO: disable all PDOs on D2
|
||||
✓ NMT: pre-operational D1
|
||||
✓ NMT: operational D1
|
||||
✓ NMT: pre-operational D2
|
||||
✓ NMT: operational D2
|
||||
✓ finish: NMT all preoperational
|
||||
|
||||
17 tests, 0 failures
|
||||
|
||||
|
||||
Running 'heartbeat_consumer.bats':
|
||||
✓ Start heartbeat producer on D1 only
|
||||
✓ Start heartbeat consumer on D2
|
||||
✓ Heartbeat producer D1 missing
|
||||
✓ Heartbeat producer D1 established
|
||||
✓ Bootup message D1
|
||||
✓ Second HB consumer configuration
|
||||
✓ Illegal HB consumer configuration (duplicate nodeId)
|
||||
✓ Cleanup
|
||||
|
||||
8 tests, 0 failures
|
||||
|
||||
|
||||
Running 'SDO_transfer.bats':
|
||||
✓ Segmented transfer - set filename for upload
|
||||
✓ Block transfer, create 100000 bytes long random binaryFile
|
||||
✓ Block download binaryFile
|
||||
✓ Block upload to binaryFileReceived - 2x
|
||||
✓ Block transfer, files equal
|
||||
✓ Segmented transfer, create 1000 bytes long random binaryFileSeg
|
||||
✓ Segmented download binaryFileSeg
|
||||
✓ Segmented upload to binaryFileSegReceived
|
||||
✓ Segmented transfer, files equal
|
||||
100000 bytes block down/upload: 1845/2310 milliseconds.
|
||||
1000 bytes segmented down/upload: 256/280 milliseconds.
|
||||
|
||||
9 tests, 0 failures
|
||||
|
||||
Test duration: 13.637902731 sec
|
||||
```
|
||||
|
||||
|
||||
SDO transfer test reports for different target systems
|
||||
------------------------------------------------------
|
||||
|
||||
Running tests with `SDO_transfer.bats`, see test.md for preparation of devices.
|
||||
|
||||
### Devices tested 2021-05-02
|
||||
- systems:
|
||||
- Ubuntu 20.10, Linux 5.8.0-41-generic on desktop PC
|
||||
- Raspberry Pi OS 10 (buster) on RPI
|
||||
- canopend, testing SDO client and gateway:
|
||||
- versions CANopenNode:
|
||||
- "v4.0-25-g8855820"
|
||||
- "v2.0-6-gacd719e"
|
||||
- basicDevice, testing SDO server
|
||||
- version CANopenSocket "v4.0-2-geb7d5f3-dirty"
|
||||
- version CANopenNode "v4.0-25-g8855820" (v2.0 was not tested)
|
||||
- CAN interfaces:
|
||||
- CPC-USB, EMS Dr. Thomas Wuensche
|
||||
- PCAN-USB: PEAK-System PCAN-USB FD v1 fw v3.2.0 (1 channel, FD not used)
|
||||
- USBtin: USBtin EB v2.0 (slcand)
|
||||
- Raspberry Pi 2 (and 4) Model B
|
||||
- [CAN shield with MCP2515](https://www.sg-electronic-systems.com/can-bus-dual-iso-v2-1-shield-for-raspberry/)
|
||||
- CPC-USB (PCAN-USB didn't work)
|
||||
|
||||
### Virtual CAN device
|
||||
Test result:
|
||||
```
|
||||
✓ Segmented transfer - set filename for upload
|
||||
✓ Block transfer, create 100000 bytes long random binaryFile
|
||||
✓ Block download binaryFile
|
||||
✓ Block upload to binaryFileReceived - 2x
|
||||
✓ Block transfer, files equal
|
||||
✓ Segmented transfer, create 1000 bytes long random binaryFileSeg
|
||||
✓ Segmented download binaryFileSeg
|
||||
✓ Segmented upload to binaryFileSegReceived
|
||||
✓ Segmented transfer, files equal
|
||||
100000 bytes block down/upload: 70/145 milliseconds.
|
||||
1000 bytes segmented down/upload: 10/24 milliseconds.
|
||||
```
|
||||
|
||||
### CAN bus 1000 Kbps
|
||||
Test result:
|
||||
```
|
||||
✓ Segmented transfer - set filename for upload
|
||||
✓ Block transfer, create 100000 bytes long random binaryFile
|
||||
✓ Block download binaryFile
|
||||
✓ Block upload to binaryFileReceived - 2x
|
||||
✓ Block transfer, files equal
|
||||
✓ Segmented transfer, create 1000 bytes long random binaryFileSeg
|
||||
✓ Segmented download binaryFileSeg
|
||||
✓ Segmented upload to binaryFileSegReceived
|
||||
✓ Segmented transfer, files equal
|
||||
100000 bytes block down/upload: 2316/1840 milliseconds.
|
||||
1000 bytes segmented down/upload: 254/270 milliseconds.
|
||||
```
|
||||
#### Notes USBtin
|
||||
USBtin interface doesn't work when sending sequence of data. In block transfer it sends first CAN message in sub-block correctly, then there is a mess on the bus. However data was transferred correctly in all test cases, because of the robustness of the block transfer. But communication time is up to 300 times longer. Reception of the sequence of data as well as segmented transfer always works correctly with USBtin.
|
||||
|
||||
#### Notes Raspberry PI with CAN shield MCP2515
|
||||
Raspberry PI shows had problems with CAN overflow with received sequence of data. It couldn't process fast enough and there was socket overflow. RPI sends emergency message and sets error register. Otherwise data transfer was always correct and time to transfer was not significantly longer. With 250 Kbps there were still overflows, but less. Problem was the same, when RPI was basicDevice (multithreaded program) or canopend (single threaded program). Problem was also the same, when using RPI2 or RPI4. But everything works perfectly when using CPC-USB instead of CAN shield with RPI2 or RPI4.
|
||||
```
|
||||
basicDevice: (CO_CANerror_rxMsgError) Socket error msg ID: 0x20000004, Data[0..7]: 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 (can0)
|
||||
basicDevice: CAN Interface "can0" Rx buffer overflow. Message dropped
|
||||
canopend: CANopen Emergency message from node 0x04: errorCode=0x0013, errorRegister=0x10, errorBit=0x13, infoCode=0x00000000
|
||||
```
|
||||
|
||||
#### Notes other
|
||||
No problems were detected on other CAN interfaces.
|
||||
|
||||
|
||||
### CAN bus 10 Kbps
|
||||
Enlarge SDO timeout and reduce data size:
|
||||
```
|
||||
cocomm "set sdo_timeout 2000"
|
||||
export binaryFileSize=1000
|
||||
```
|
||||
|
||||
Test result:
|
||||
```
|
||||
✓ Segmented transfer - set filename for upload
|
||||
✓ Block transfer, create 1000 bytes long random binaryFile
|
||||
✓ Block download binaryFile
|
||||
✓ Block upload to binaryFileReceived - 2x
|
||||
✓ Block transfer, files equal
|
||||
✓ Segmented transfer, create 1000 bytes long random binaryFileSeg
|
||||
✓ Segmented download binaryFileSeg
|
||||
✓ Segmented upload to binaryFileSegReceived
|
||||
✓ Segmented transfer, files equal
|
||||
1000 bytes block down/upload: 1741/1731 milliseconds.
|
||||
1000 bytes segmented down/upload: 3611/3621 milliseconds.
|
||||
```
|
||||
|
||||
#### Notes
|
||||
USBtin shows the same problems as with 1000 Kbps. All others worked perfectly.
|
||||
Reference in New Issue
Block a user