2025-01-14 14:42:39 +00:00
|
|
|
#!/usr/bin/env bash
|
2020-07-08 16:08:05 +02:00
|
|
|
#
|
2021-09-22 10:42:03 +02:00
|
|
|
# Integration can test using villas node.
|
2020-07-08 16:08:05 +02:00
|
|
|
#
|
2025-01-14 14:42:39 +00:00
|
|
|
# Author: Niklas Eiling <niklas.eiling@eonerc.rwth-aachen.de>
|
|
|
|
# SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
# To set up vcan interface use the following commands
|
2020-07-08 16:08:12 +02:00
|
|
|
# sudo modprobe vcan
|
|
|
|
# sudo ip link add dev vcan0 type vcan
|
|
|
|
# sudo ip link set vcan0 up
|
2020-07-08 16:08:05 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
set -e
|
2020-07-08 16:08:05 +02:00
|
|
|
|
2020-07-08 16:08:12 +02:00
|
|
|
CAN_IF=$(ip link show type vcan | head -n1 | awk '{match($2, /(.*):/,a)}END{print a[1]}')
|
|
|
|
|
|
|
|
if [[ ! ${CAN_IF} ]]; then
|
|
|
|
echo "Did not find any vcan interface"
|
|
|
|
exit 99
|
|
|
|
fi
|
|
|
|
|
2020-07-08 16:08:09 +02:00
|
|
|
# Check if vcan0 interface is present
|
|
|
|
if [[ ! $(ip link show "${CAN_IF}" up) ]]; then
|
2020-07-08 16:08:12 +02:00
|
|
|
echo "Interface ${CAN_IF} is not up"
|
2020-07-08 16:08:09 +02:00
|
|
|
exit 99
|
|
|
|
fi
|
2020-07-08 16:08:05 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
DIR=$(mktemp -d)
|
|
|
|
pushd ${DIR}
|
|
|
|
|
|
|
|
function finish {
|
2025-01-14 14:42:39 +00:00
|
|
|
popd
|
|
|
|
rm -rf ${DIR}
|
2021-08-10 10:12:48 -04:00
|
|
|
}
|
|
|
|
trap finish EXIT
|
2020-07-08 16:08:12 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
NUM_SAMPLES=${NUM_SAMPLES:-10}
|
|
|
|
NUM_VALUES=${NUM_VALUES:-3}
|
|
|
|
|
|
|
|
cat > config.json << EOF
|
|
|
|
{
|
2025-01-14 14:42:39 +00:00
|
|
|
"nodes": {
|
|
|
|
"can_node1": {
|
|
|
|
"type": "can",
|
|
|
|
"interface_name": "${CAN_IF}",
|
|
|
|
"sample_rate": 500000,
|
|
|
|
"in": {
|
|
|
|
"signals": [
|
|
|
|
{
|
|
|
|
"name": "sigin1",
|
|
|
|
"unit": "Volts",
|
|
|
|
"type": "float",
|
|
|
|
"enabled": true,
|
|
|
|
"can_id": 66,
|
|
|
|
"can_size": 4,
|
|
|
|
"can_offset": 0
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "sigin2",
|
|
|
|
"unit": "Volts",
|
|
|
|
"type": "float",
|
|
|
|
"enabled": true,
|
|
|
|
"can_id": 66,
|
|
|
|
"can_size": 4,
|
|
|
|
"can_offset": 4
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "sigin3",
|
|
|
|
"unit": "Volts",
|
|
|
|
"type": "float",
|
|
|
|
"enabled": true,
|
|
|
|
"can_id": 67,
|
|
|
|
"can_size": 8,
|
|
|
|
"can_offset": 0
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
"out": {
|
|
|
|
"signals": [
|
|
|
|
{
|
|
|
|
"type": "float",
|
|
|
|
"can_id": 66,
|
|
|
|
"can_size": 4,
|
|
|
|
"can_offset": 0
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "float",
|
|
|
|
"can_id": 66,
|
|
|
|
"can_size": 4,
|
|
|
|
"can_offset": 4
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "float",
|
|
|
|
"can_id": 67,
|
|
|
|
"can_size": 8,
|
|
|
|
"can_offset": 0
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-08 16:08:12 +02:00
|
|
|
}
|
|
|
|
EOF
|
2020-07-08 16:08:05 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
villas signal -v ${NUM_VALUES} -l ${NUM_SAMPLES} -n random > input.dat
|
2020-07-08 16:08:05 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
villas node config.json &
|
2020-07-08 16:08:05 +02:00
|
|
|
|
|
|
|
# Wait for node to complete init
|
|
|
|
sleep 1
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
candump -n ${NUM_SAMPLES} -T 1000 -L ${CAN_IF} | awk '{print $3}' > can_out.dat &
|
2020-07-08 16:08:05 +02:00
|
|
|
|
|
|
|
# Send / Receive data to node
|
2021-08-10 10:12:48 -04:00
|
|
|
villas pipe -l ${NUM_SAMPLES} config.json can_node1 > output.dat < input.dat &
|
2020-07-08 16:08:05 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
wait $candump
|
|
|
|
|
|
|
|
cat can_out.dat | xargs -I % cansend ${CAN_IF} %
|
2020-07-08 16:08:05 +02:00
|
|
|
|
|
|
|
# Wait for node to handle samples
|
|
|
|
sleep 1
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
kill %villas
|
|
|
|
wait %villas
|
2020-07-08 16:08:05 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
villas compare input.dat output.dat
|