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:
parent
cd0d17d6a5
commit
162e5ef9eb
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue