Merge branch 'DasRoteSkelett/ethercat-feature/addDeviceNameToEthercatConf' into stable-1.5

This commit is contained in:
Florian Pose 2021-08-24 13:29:02 +02:00
commit cfec20492d
2 changed files with 22 additions and 6 deletions

View File

@ -17,6 +17,10 @@
# Specify the MAC address (hexadecimal with colons) of the Ethernet device to
# use. Example: "00:00:08:44:ab:66"
#
# Alternatively, a network interface name can be specified. The interface
# name will be resolved to a MAC address using the 'ip' command.
# Example: "eth0"
#
# The broadcast address "ff:ff:ff:ff:ff:ff" has a special meaning: It tells
# the master to accept the first device offered by any Ethernet driver.
#
@ -24,6 +28,10 @@
# created: A non-empty variable MASTER0_DEVICE will create one master, adding a
# non-empty variable MASTER1_DEVICE will create a second master, and so on.
#
# Examples:
# MASTER0_DEVICE="00:00:08:44:ab:66"
# MASTER0_DEVICE="eth0"
#
MASTER0_DEVICE=""
#MASTER1_DEVICE=""

View File

@ -4,9 +4,7 @@
#
# Start script for EtherCAT to use with systemd
#
# $Id$
#
# Copyright (C) 2006-2012 Florian Pose, Ingenieurgemeinschaft IgH
# Copyright (C) 2006-2021 Florian Pose, Ingenieurgemeinschaft IgH
#
# This file is part of the IgH EtherCAT Master.
#
@ -37,6 +35,7 @@ LSMOD=/sbin/lsmod
MODPROBE=/sbin/modprobe
RMMOD=/sbin/rmmod
MODINFO=/sbin/modinfo
IP=/bin/ip
ETHERCAT=@bindir@/ethercat
@ -55,13 +54,22 @@ 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 or interface name \""${1}"\" \
in ${ETHERCAT_CONFIG}
exit 1
fi
fi
}