diff --git a/etc/examples/nodes/can.conf b/etc/examples/nodes/can.conf index 4f9ffe2cf..8dbcec6f1 100644 --- a/etc/examples/nodes/can.conf +++ b/etc/examples/nodes/can.conf @@ -9,10 +9,10 @@ nodes = { { name = "sigin1", unit = "Volts", - type = "integer", + type = "float", enabled = true, can_id = 66, - can_size = 8, + can_size = 4, can_offset = 0 }, { @@ -20,18 +20,18 @@ nodes = { unit = "Volts", type = "float", enabled = true, - can_id = 67, + can_id = 66, can_size = 4, - can_offset = 0 + can_offset = 4 }, { name = "sigin3", unit = "Volts", - type = "integer", + type = "float", enabled = true, - can_id = 66, - can_size = 4, - can_offset = 4 + can_id = 67, + can_size = 8, + can_offset = 0 } ) } @@ -40,19 +40,19 @@ nodes = { signals = ( { type = "float", - can_id = 1, + can_id = 66, can_size = 4, can_offset = 0 }, { type = "float", - can_id = 1, + can_id = 66, can_size = 4, can_offset = 4 }, { type = "float", - can_id = 2, + can_id = 67, can_size = 8, can_offset = 0 } diff --git a/tests/integration/node-can.sh b/tests/integration/node-can.sh new file mode 100755 index 000000000..dadb326ef --- /dev/null +++ b/tests/integration/node-can.sh @@ -0,0 +1,77 @@ +#!/bin/bash +# +# Integration can test using villas-node. +# +# @author Niklas Eiling +# @copyright 2014-2020, Institute for Automation of Complex Power Systems, EONERC +# @license GNU General Public License (version 3) +# +# VILLASnode +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +################################################################################## + +SCRIPT=$(realpath $0) +SCRIPTPATH=$(dirname ${SCRIPT}) +source ${SCRIPTPATH}/../../tools/villas-helper.sh + +CONFIG_FILE=${SCRIPTPATH}/../../etc/examples/nodes/can.conf +INPUT_FILE=$(mktemp) +OUTPUT_FILE=$(mktemp) +CAN_OUT_FILE=$(mktemp) +CAN_IF=vcan0 + +NUM_SAMPLES=${NUM_SAMPLES:-10} +NUM_VALUES=${NUM_VALUES:-3} + + +#sudo modprobe vcan +#sudo ip link add dev vcan0 type vcan +#sudo ip link set vcan0 up + +# Generate test data +VILLAS_LOG_PREFIX=$(colorize "[Signal]") \ +villas-signal -v ${NUM_VALUES} -l ${NUM_SAMPLES} -n random > ${INPUT_FILE} + +# Start node +VILLAS_LOG_PREFIX=$(colorize "[Node] ") \ +villas-node ${CONFIG_FILE} & + +# Wait for node to complete init +sleep 1 + +candump -n ${NUM_SAMPLES} -T 1000 -L ${CAN_IF} | awk '{print $3}' > ${CAN_OUT_FILE} & +CANDUMP_PID=$! + +# Send / Receive data to node +VILLAS_LOG_PREFIX=$(colorize "[Pipe] ") \ +villas-pipe -l ${NUM_SAMPLES} ${CONFIG_FILE} can_node1 > ${OUTPUT_FILE} < ${INPUT_FILE} & + +wait ${CANDUMP_PID} +cat ${CAN_OUT_FILE} | xargs -I % cansend ${CAN_IF} % + +# Wait for node to handle samples +sleep 1 + +# Stop node +kill %1 + +# Compare data +villas-test-cmp ${INPUT_FILE} ${OUTPUT_FILE} +RC=$? + +#rm ${CAN_OUT_FILE} ${INPUT_FILE} ${OUTPUT_FILE} +rm ${INPUT_FILE} ${OUTPUT_FILE} + +exit $RC