ethercatctl: allow to use the network device name instead of mac address

In the /etc/ethercat.conf file, the MASTERX_DEVICE string is given as a
mac address or a wildcard. When we want to deploy the (same) software (image)
to a bunch of different hardware, and these computers do have more than one
interface that matches the driver, we need a way to define the device by
network interface name. This allows to also define the network device by name
(e.g. eth0, eno1, ...)

Signed-off-by: Matthias Schoepfer <m.schoepfer@rethinkrobotics.com>
This commit is contained in:
Matthias Schoepfer 2021-07-06 16:04:46 +02:00
parent cd0d17d6a5
commit 162e5ef9eb
1 changed files with 10 additions and 3 deletions

View File

@ -37,6 +37,7 @@ LSMOD=/sbin/lsmod
MODPROBE=/sbin/modprobe
RMMOD=/sbin/rmmod
MODINFO=/sbin/modinfo
IP=/bin/ip
ETHERCAT=@bindir@/ethercat
@ -55,13 +56,19 @@ fi
#------------------------------------------------------------------------------
parse_mac_address() {
local DEVICENAMETOMAC
if [ -z "${1}" ]; then
MAC=""
elif echo "${1}" | grep -qE '^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$'; then
elif echo ${1} | grep -qE '^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$'; then
MAC=${1}
else
echo Invalid MAC address \""${1}"\" in ${ETHERCAT_CONFIG}
exit 1
DEVICENAMETOMAC=$("${IP}" address show dev "${1}" | awk '/link\/ether/ { print $2; }')
if echo "${DEVICENAMETOMAC}" | grep -qE '^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$'; then
MAC=${DEVICENAMETOMAC}
else
echo Invalid MAC address \""${1}"\" in ${ETHERCAT_CONFIG}
exit 1
fi
fi
}