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
|
||||
Reference in New Issue
Block a user