1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00
VILLASnode/tests/integration/node-can.sh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

128 lines
3 KiB
Bash
Raw Permalink Normal View History

#!/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
#
# 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
# 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
set -e
2020-07-08 16:08:05 +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
# Check if vcan0 interface is present
if [[ ! $(ip link show "${CAN_IF}" up) ]]; then
echo "Interface ${CAN_IF} is not up"
exit 99
fi
2020-07-08 16:08:05 +02:00
DIR=$(mktemp -d)
pushd ${DIR}
function finish {
popd
rm -rf ${DIR}
}
trap finish EXIT
NUM_SAMPLES=${NUM_SAMPLES:-10}
NUM_VALUES=${NUM_VALUES:-3}
cat > config.json << EOF
{
"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
}
]
}
}
}
}
EOF
2020-07-08 16:08:05 +02:00
villas signal -v ${NUM_VALUES} -l ${NUM_SAMPLES} -n random > input.dat
2020-07-08 16:08:05 +02:00
villas node config.json &
2020-07-08 16:08:05 +02:00
# Wait for node to complete init
sleep 1
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
villas pipe -l ${NUM_SAMPLES} config.json can_node1 > output.dat < input.dat &
2020-07-08 16:08:05 +02: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
kill %villas
wait %villas
2020-07-08 16:08:05 +02:00
villas compare input.dat output.dat