Created scripts directory and improved install and init scripts.
authorFlorian Pose <fp@igh-essen.com>
Fri, 19 May 2006 09:56:55 +0000
changeset 250 440ae5f6d2c3
parent 249 ee1d766dbc6b
child 251 c1d0b63a9302
Created scripts directory and improved install and init scripts.
Makefile
ethercat.conf.tmpl
ethercat.sh
install.sh
script/ec_list.pl
script/ethercat.sh
script/install.sh
script/sysconfig
tools/ec_list.pl
--- a/Makefile	Thu May 18 17:49:52 2006 +0000
+++ b/Makefile	Fri May 19 09:56:55 2006 +0000
@@ -33,34 +33,32 @@
 #
 #------------------------------------------------------------------------------
 
-ifneq ($(KERNELRELEASE),)
-
 #------------------------------------------------------------------------------
 #  kbuild section
 
+ifneq ($(KERNELRELEASE),)
+
 obj-m := master/ devices/
 
 #------------------------------------------------------------------------------
+#  default section
 
 else
 
-#------------------------------------------------------------------------------
-#  default section
-
 ifneq ($(wildcard ethercat.conf),)
 include ethercat.conf
 else
-KERNEL := `uname -r`
-DEVICEINDEX := 99
+KERNEL := $(shell uname -r)
 endif
 
-KERNELDIR := /lib/modules/$(KERNEL)/build
+KERNEL_DIR := /lib/modules/$(KERNEL)/build
+CURRENT_DIR := $(shell pwd)
 
 modules:
-	$(MAKE) -C $(KERNELDIR) M=`pwd`
+	$(MAKE) -C $(KERNEL_DIR) M=$(CURRENT_DIR)
 
 clean: cleandoc
-	$(MAKE) -C $(KERNELDIR) M=`pwd` clean
+	$(MAKE) -C $(KERNEL_DIR) M=$(CURRENT_DIR) clean
 
 doc:
 	doxygen Doxyfile
@@ -69,7 +67,7 @@
 	@rm -rf doc
 
 install:
-	@./install.sh $(KERNEL) $(DEVICEINDEX)
+	@script/install.sh $(KERNEL)
 
 #------------------------------------------------------------------------------
 
--- a/ethercat.conf.tmpl	Thu May 18 17:49:52 2006 +0000
+++ b/ethercat.conf.tmpl	Fri May 19 09:56:55 2006 +0000
@@ -9,10 +9,9 @@
 #
 #------------------------------------------------------------------------------
 
+#
 # The kernel to compile the EtherCAT sources against
+#
 KERNEL := `uname -r`
 
-# PCI index of the EtherCAT device
-DEVICEINDEX := 99
-
 #------------------------------------------------------------------------------
--- a/ethercat.sh	Thu May 18 17:49:52 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,125 +0,0 @@
-#!/bin/sh
-
-#------------------------------------------------------------------------------
-#
-#  Init script for EtherCAT
-#
-#  $Id$
-#
-#  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
-#
-#  This file is part of the IgH EtherCAT Master.
-#
-#  The IgH EtherCAT Master 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 2 of the
-#  License, or (at your option) any later version.
-#
-#  The IgH EtherCAT Master 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 the IgH EtherCAT Master; if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#
-#  The right to use EtherCAT Technology is granted and comes free of
-#  charge under condition of compatibility of product made by
-#  Licensee. People intending to distribute/sell products based on the
-#  code, have to sign an agreement to guarantee that products using
-#  software based on IgH EtherCAT master stay compatible with the actual
-#  EtherCAT specification (which are released themselves as an open
-#  standard) as the (only) precondition to have the right to use EtherCAT
-#  Technology, IP and trade marks.
-#
-#------------------------------------------------------------------------------
-
-### BEGIN INIT INFO
-# Provides:          ethercat
-# Required-Start:    $local_fs $syslog $network
-# Should-Start:      $time
-# Required-Stop:     $local_fs $syslog $network
-# Should-Stop:       $time
-# Default-Start:     3 5
-# Default-Stop:      0 1 2 6
-# Short-Description: IgH EtherCAT master modules
-# Description:
-### END INIT INFO
-
-#------------------------------------------------------------------------------
-
-ETHERCAT_CONFIG=/etc/sysconfig/ethercat
-
-test -r $ETHERCAT_CONFIG || { echo "$ETHERCAT_CONFIG not existing";
-	if [ "$1" = "stop" ]; then exit 0;
-	else exit 6; fi; }
-
-. $ETHERCAT_CONFIG
-
-#------------------------------------------------------------------------------
-
-. /etc/rc.status
-rc_reset
-
-case "$1" in
-    start)
-	echo -n "Starting EtherCAT master... "
-
-	for mod in 8139too 8139cp; do
-		if lsmod | grep "^$mod " > /dev/null; then
-			if ! rmmod $mod; then
-				/bin/false
-				rc_status -v
-				rc_exit
-			fi;
-		fi;
-	done
-
-	modprobe ec_8139too ec_device_index=$DEVICEINDEX
-
-	rc_status -v
-	;;
-
-    stop)
-	echo -n "Shutting down EtherCAT master... "
-
-	for mod in ec_8139too ec_master; do
-		if lsmod | grep "^$mod " > /dev/null; then
-			if ! rmmod $mod; then
-				/bin/false
-				rc_status -v
-				rc_exit
-			fi;
-		fi;
-	done
-
-	if ! modprobe 8139too; then
-	    echo "Warning: Failed to restore 8139too module."
-	fi
-
-	rc_status -v
-	;;
-
-    restart)
-	$0 stop
-	$0 start
-
-	rc_status
-	;;
-
-    status)
-	echo -n "Checking for EtherCAT... "
-
-	lsmod | grep "^ec_master " > /dev/null
-	master_running=$?
-	lsmod | grep "^ec_8139too " > /dev/null
-	device_running=$?
-	test $master_running -eq 0 -a $device_running -eq 0
-
-	rc_status -v
-	;;
-esac
-rc_exit
-
-#------------------------------------------------------------------------------
--- a/install.sh	Thu May 18 17:49:52 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,105 +0,0 @@
-#!/bin/sh
-
-#------------------------------------------------------------------------------
-#
-#  EtherCAT install script
-#
-#  $Id$
-#
-#  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
-#
-#  This file is part of the IgH EtherCAT Master.
-#
-#  The IgH EtherCAT Master 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 2 of the
-#  License, or (at your option) any later version.
-#
-#  The IgH EtherCAT Master 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 the IgH EtherCAT Master; if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#
-#  The right to use EtherCAT Technology is granted and comes free of
-#  charge under condition of compatibility of product made by
-#  Licensee. People intending to distribute/sell products based on the
-#  code, have to sign an agreement to guarantee that products using
-#  software based on IgH EtherCAT master stay compatible with the actual
-#  EtherCAT specification (which are released themselves as an open
-#  standard) as the (only) precondition to have the right to use EtherCAT
-#  Technology, IP and trade marks.
-#
-#------------------------------------------------------------------------------
-
-CONFIGFILE=/etc/sysconfig/ethercat
-
-#------------------------------------------------------------------------------
-
-# install function
-
-install()
-{
-    echo "    $1"
-    if ! cp $1 $INSTALLDIR; then exit 1; fi
-}
-
-#------------------------------------------------------------------------------
-
-# Fetch parameter
-
-if [ $# -ne 2 ]; then
-    echo "This script is called by \"make\". Run \"make install\" instead."
-    exit 1
-fi
-
-KERNEL=$1
-DEVICEINDEX=$2
-
-INSTALLDIR=/lib/modules/$KERNEL/kernel/drivers/net
-echo "EtherCAT installer - Kernel: $KERNEL"
-
-# Copy files
-
-echo "  installing modules..."
-install master/ec_master.ko
-install devices/ec_8139too.ko
-
-# Update dependencies
-
-echo "  building module dependencies..."
-depmod
-
-# Create configuration file
-
-if [ -f $CONFIGFILE ]; then
-    echo "  notice: using existing configuration file."
-else
-    echo "  creating $CONFIGFILE..."
-    echo "DEVICEINDEX=$DEVICEINDEX" > $CONFIGFILE || exit 1
-fi
-
-# Install rc script
-
-echo "  installing startup script..."
-cp ethercat.sh /etc/init.d/ethercat || exit 1
-chmod +x /etc/init.d/ethercat || exit 1
-if [ ! -L /usr/sbin/rcethercat ]; then
-    ln -s /etc/init.d/ethercat /usr/sbin/rcethercat || exit 1
-fi
-
-# Install tools
-
-echo "  installing tools..."
-cp tools/ec_list.pl /usr/local/bin/ec_list || exit 1
-chmod +x /usr/local/bin/ec_list || exit 1
-
-# Finish
-
-echo "EtherCAT installer done."
-exit 0
-
-#------------------------------------------------------------------------------
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/script/ec_list.pl	Fri May 19 09:56:55 2006 +0000
@@ -0,0 +1,176 @@
+#!/usr/bin/perl
+
+#------------------------------------------------------------------------------
+#
+#  e c _ l i s t . p l
+#
+#  Userspace tool for listing EtherCAT slaves.
+#
+#  $Id: slave.c 340 2006-04-11 10:17:30Z fp $
+#
+#  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
+#
+#  This file is part of the IgH EtherCAT Master.
+#
+#  The IgH EtherCAT Master 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 2 of the
+#  License, or (at your option) any later version.
+#
+#  The IgH EtherCAT Master 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 the IgH EtherCAT Master; if not, write to the Free Software
+#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#
+#  The right to use EtherCAT Technology is granted and comes free of
+#  charge under condition of compatibility of product made by
+#  Licensee. People intending to distribute/sell products based on the
+#  code, have to sign an agreement to guarantee that products using
+#  software based on IgH EtherCAT master stay compatible with the actual
+#  EtherCAT specification (which are released themselves as an open
+#  standard) as the (only) precondition to have the right to use EtherCAT
+#  Technology, IP and trade marks.
+#
+#------------------------------------------------------------------------------
+
+use strict;
+use Getopt::Std;
+
+my $master_index;
+my $master_dir;
+
+#------------------------------------------------------------------------------
+
+&get_options;
+&query_master;
+exit 0;
+
+#------------------------------------------------------------------------------
+
+sub query_master
+{
+    $master_dir = "/sys/ethercat" . $master_index;
+    &query_slaves;
+}
+
+#------------------------------------------------------------------------------
+
+sub query_slaves
+{
+    my $dirhandle;
+    my $slave_dir;
+    my $entry;
+    my $slave_index;
+    my $file_name;
+    my $vendor_name;
+    my @slaves;
+    my $slave;
+    my $abs;
+
+    unless (opendir $dirhandle, $master_dir) {
+	print "Failed to open directory \"$master_dir\".\n";
+	exit 1;
+    }
+
+    while ($entry = readdir $dirhandle) {
+        next unless $entry =~ /^slave(\d+)$/;
+	$slave_dir = $master_dir . "/" . $entry;
+
+	$slave = {};
+	$slave->{'ring_position'} =
+	    &read_integer("$slave_dir/ring_position");
+	$slave->{'coupler_address'} =
+	    &read_string("$slave_dir/coupler_address");
+	$slave->{'vendor_name'} =
+	    &read_string("$slave_dir/vendor_name");
+	$slave->{'product_name'} =
+	    &read_string("$slave_dir/product_name");
+	$slave->{'product_desc'} =
+	    &read_string("$slave_dir/product_desc");
+	$slave->{'type'} =
+	    &read_string("$slave_dir/type");
+
+	push @slaves, $slave;
+    }
+    closedir $dirhandle;
+
+    @slaves = sort { $a->{'ring_position'} <=> $b->{'ring_position'} } @slaves;
+
+    print "EtherCAT bus listing for master $master_index:\n";
+    for $slave (@slaves) {
+	if ($slave->{'type'} eq "coupler") {
+	    print "--------------------------------------------------------\n";
+	}
+
+	$abs = sprintf "%i", $slave->{'ring_position'};
+	printf(" %3s %8s   %-12s %-10s %s\n", $abs,
+	       $slave->{'coupler_address'}, $slave->{'vendor_name'},
+	       $slave->{'product_name'}, $slave->{'product_desc'});
+    }
+}
+
+#------------------------------------------------------------------------------
+
+sub read_string
+{
+    (my $file_name) = @_;
+    my $data;
+
+    $data = `cat $file_name 2>/dev/null`;
+    if ($?) {
+	print "ERROR: Unable to read string $file_name!\n";
+	exit 1;
+    }
+
+    chomp $data;
+    return $data;
+}
+
+#------------------------------------------------------------------------------
+
+sub read_integer
+{
+    (my $file_name) = @_;
+
+    if (`cat $file_name 2>/dev/null` !~ /^(\d+)$/) {
+	print "ERROR: Unable to read integer $file_name!\n";
+	exit 1;
+    }
+
+    return int $1;
+}
+
+#------------------------------------------------------------------------------
+
+sub get_options
+{
+    my %opt;
+    my $optret;
+
+    $optret = getopts "m:h", \%opt;
+
+    &print_usage if defined $opt{'h'} or $#ARGV > -1;
+
+    if (defined $opt{'m'}) {
+	$master_index = $opt{'m'};
+    }
+    else {
+	$master_index = 0;
+    }
+}
+
+#------------------------------------------------------------------------------
+
+sub print_usage
+{
+    print "Usage: ec_list [OPTIONS]\n";
+    print "        -m <IDX>    Query master IDX.\n";
+    print "        -h          Show this help.\n";
+    exit 0;
+}
+
+#------------------------------------------------------------------------------
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/script/ethercat.sh	Fri May 19 09:56:55 2006 +0000
@@ -0,0 +1,132 @@
+#!/bin/sh
+
+#------------------------------------------------------------------------------
+#
+#  Init script for EtherCAT
+#
+#  $Id$
+#
+#  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
+#
+#  This file is part of the IgH EtherCAT Master.
+#
+#  The IgH EtherCAT Master 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 2 of the
+#  License, or (at your option) any later version.
+#
+#  The IgH EtherCAT Master 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 the IgH EtherCAT Master; if not, write to the Free Software
+#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#
+#  The right to use EtherCAT Technology is granted and comes free of
+#  charge under condition of compatibility of product made by
+#  Licensee. People intending to distribute/sell products based on the
+#  code, have to sign an agreement to guarantee that products using
+#  software based on IgH EtherCAT master stay compatible with the actual
+#  EtherCAT specification (which are released themselves as an open
+#  standard) as the (only) precondition to have the right to use EtherCAT
+#  Technology, IP and trade marks.
+#
+#------------------------------------------------------------------------------
+
+### BEGIN INIT INFO
+# Provides:          ethercat
+# Required-Start:    $local_fs $syslog $network
+# Should-Start:      $time
+# Required-Stop:     $local_fs $syslog $network
+# Should-Stop:       $time
+# Default-Start:     3 5
+# Default-Stop:      0 1 2 6
+# Short-Description: IgH EtherCAT master modules
+# Description:
+### END INIT INFO
+
+#------------------------------------------------------------------------------
+
+ETHERCAT_CONFIG=/etc/sysconfig/ethercat
+
+test -r $ETHERCAT_CONFIG || { echo "$ETHERCAT_CONFIG not existing";
+	if [ "$1" = "stop" ]; then exit 0;
+	else exit 6; fi; }
+
+. $ETHERCAT_CONFIG
+
+#------------------------------------------------------------------------------
+
+. /etc/rc.status
+rc_reset
+
+case "$1" in
+    start)
+	echo -n "Starting EtherCAT master "
+
+	if [ ! $DEVICE_INDEX ]; then
+	    echo "ERROR: DEVICE_INDEX not set!"
+	    /bin/false
+	    rc_status -v
+	    rc_exit
+	fi
+
+	for mod in 8139too 8139cp; do
+		if lsmod | grep "^$mod " > /dev/null; then
+			if ! rmmod $mod; then
+				/bin/false
+				rc_status -v
+				rc_exit
+			fi
+		fi
+	done
+
+	modprobe ec_8139too ec_device_index=$DEVICE_INDEX
+
+	rc_status -v
+	;;
+
+    stop)
+	echo -n "Shutting down EtherCAT master "
+
+	for mod in ec_8139too ec_master; do
+		if lsmod | grep "^$mod " > /dev/null; then
+			if ! rmmod $mod; then
+				/bin/false
+				rc_status -v
+				rc_exit
+			fi;
+		fi;
+	done
+
+	if ! modprobe 8139too; then
+	    echo "Warning: Failed to restore 8139too module."
+	fi
+
+	rc_status -v
+	;;
+
+    restart)
+	$0 stop
+	$0 start
+
+	rc_status
+	;;
+
+    status)
+	echo -n "Checking for EtherCAT "
+
+	lsmod | grep "^ec_master " > /dev/null
+	master_running=$?
+	lsmod | grep "^ec_8139too " > /dev/null
+	device_running=$?
+	test $master_running -eq 0 -a $device_running -eq 0
+
+	rc_status -v
+	;;
+esac
+rc_exit
+
+#------------------------------------------------------------------------------
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/script/install.sh	Fri May 19 09:56:55 2006 +0000
@@ -0,0 +1,114 @@
+#!/bin/sh
+
+#------------------------------------------------------------------------------
+#
+#  EtherCAT install script
+#
+#  $Id$
+#
+#  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
+#
+#  This file is part of the IgH EtherCAT Master.
+#
+#  The IgH EtherCAT Master 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 2 of the
+#  License, or (at your option) any later version.
+#
+#  The IgH EtherCAT Master 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 the IgH EtherCAT Master; if not, write to the Free Software
+#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#
+#  The right to use EtherCAT Technology is granted and comes free of
+#  charge under condition of compatibility of product made by
+#  Licensee. People intending to distribute/sell products based on the
+#  code, have to sign an agreement to guarantee that products using
+#  software based on IgH EtherCAT master stay compatible with the actual
+#  EtherCAT specification (which are released themselves as an open
+#  standard) as the (only) precondition to have the right to use EtherCAT
+#  Technology, IP and trade marks.
+#
+#------------------------------------------------------------------------------
+
+# Fetch parameters
+
+if [ $# -ne 1 ]; then
+    echo "This script is called by \"make\". Run \"make install\" instead."
+    exit 1
+fi
+
+KERNEL=$1
+
+if [ ! -d /lib/modules/$KERNEL ]; then
+    echo "Kernel \"$KERNEL\" does not exist in /lib/modules!"
+    exit 1
+fi
+
+#------------------------------------------------------------------------------
+
+# Copy files
+
+INSTALLDIR=/lib/modules/$KERNEL/kernel/drivers/net
+MODULES=(master/ec_master.ko devices/ec_8139too.ko)
+
+echo "EtherCAT installer - Kernel: $KERNEL"
+echo "  Installing modules"
+
+for mod in ${MODULES[*]}; do
+    echo "    $mod"
+    cp $mod $INSTALLDIR || exit 1
+done
+
+#------------------------------------------------------------------------------
+
+# Update dependencies
+
+echo "  Building module dependencies"
+depmod
+
+#------------------------------------------------------------------------------
+
+# Create configuration file
+
+CONFIGFILE=/etc/sysconfig/ethercat
+
+if [ -s $CONFIGFILE ]; then
+    echo "  Note: Using existing configuration file."
+else
+    echo "  Creating $CONFIGFILE"
+    cp script/sysconfig $CONFIGFILE || exit 1
+    echo "  Note: Please edit DEVICE_INDEX in $CONFIGFILE!"
+fi
+
+#------------------------------------------------------------------------------
+
+# Install rc script
+
+echo "  Installing startup script"
+cp script/ethercat.sh /etc/init.d/ethercat || exit 1
+chmod +x /etc/init.d/ethercat || exit 1
+if [ ! -L /usr/sbin/rcethercat ]; then
+    ln -s /etc/init.d/ethercat /usr/sbin/rcethercat || exit 1
+fi
+
+#------------------------------------------------------------------------------
+
+# Install tools
+
+echo "  Installing tools"
+cp script/ec_list.pl /usr/local/bin/ec_list || exit 1
+chmod +x /usr/local/bin/ec_list || exit 1
+
+#------------------------------------------------------------------------------
+
+# Finish
+
+echo "Done"
+exit 0
+
+#------------------------------------------------------------------------------
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/script/sysconfig	Fri May 19 09:56:55 2006 +0000
@@ -0,0 +1,21 @@
+#------------------------------------------------------------------------------
+#
+#  EtherCAT sysconfig file
+#
+#  $Id$
+#
+#------------------------------------------------------------------------------
+
+#
+#  PCI index of the (RTL8139-)EtherCAT device
+#  Setting this is mandatory for the EtherCAT init script!
+#
+#DEVICE_INDEX=99
+
+#
+#  Number of Ethernet-over-EtherCAT devices the master shall create
+#  on startup. Default is 0.
+#
+#EOE_DEVICES=0
+
+#------------------------------------------------------------------------------
--- a/tools/ec_list.pl	Thu May 18 17:49:52 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,176 +0,0 @@
-#!/usr/bin/perl
-
-#------------------------------------------------------------------------------
-#
-#  e c _ l i s t . p l
-#
-#  Userspace tool for listing EtherCAT slaves.
-#
-#  $Id: slave.c 340 2006-04-11 10:17:30Z fp $
-#
-#  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
-#
-#  This file is part of the IgH EtherCAT Master.
-#
-#  The IgH EtherCAT Master 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 2 of the
-#  License, or (at your option) any later version.
-#
-#  The IgH EtherCAT Master 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 the IgH EtherCAT Master; if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#
-#  The right to use EtherCAT Technology is granted and comes free of
-#  charge under condition of compatibility of product made by
-#  Licensee. People intending to distribute/sell products based on the
-#  code, have to sign an agreement to guarantee that products using
-#  software based on IgH EtherCAT master stay compatible with the actual
-#  EtherCAT specification (which are released themselves as an open
-#  standard) as the (only) precondition to have the right to use EtherCAT
-#  Technology, IP and trade marks.
-#
-#------------------------------------------------------------------------------
-
-use strict;
-use Getopt::Std;
-
-my $master_index;
-my $master_dir;
-
-#------------------------------------------------------------------------------
-
-&get_options;
-&query_master;
-exit 0;
-
-#------------------------------------------------------------------------------
-
-sub query_master
-{
-    $master_dir = "/sys/ethercat" . $master_index;
-    &query_slaves;
-}
-
-#------------------------------------------------------------------------------
-
-sub query_slaves
-{
-    my $dirhandle;
-    my $slave_dir;
-    my $entry;
-    my $slave_index;
-    my $file_name;
-    my $vendor_name;
-    my @slaves;
-    my $slave;
-    my $abs;
-
-    unless (opendir $dirhandle, $master_dir) {
-	print "Failed to open directory \"$master_dir\".\n";
-	exit 1;
-    }
-
-    while ($entry = readdir $dirhandle) {
-        next unless $entry =~ /^slave(\d+)$/;
-	$slave_dir = $master_dir . "/" . $entry;
-
-	$slave = {};
-	$slave->{'ring_position'} =
-	    &read_integer("$slave_dir/ring_position");
-	$slave->{'coupler_address'} =
-	    &read_string("$slave_dir/coupler_address");
-	$slave->{'vendor_name'} =
-	    &read_string("$slave_dir/vendor_name");
-	$slave->{'product_name'} =
-	    &read_string("$slave_dir/product_name");
-	$slave->{'product_desc'} =
-	    &read_string("$slave_dir/product_desc");
-	$slave->{'type'} =
-	    &read_string("$slave_dir/type");
-
-	push @slaves, $slave;
-    }
-    closedir $dirhandle;
-
-    @slaves = sort { $a->{'ring_position'} <=> $b->{'ring_position'} } @slaves;
-
-    print "EtherCAT bus listing for master $master_index:\n";
-    for $slave (@slaves) {
-	if ($slave->{'type'} eq "coupler") {
-	    print "--------------------------------------------------------\n";
-	}
-
-	$abs = sprintf "%i", $slave->{'ring_position'};
-	printf(" %3s %8s   %-12s %-10s %s\n", $abs,
-	       $slave->{'coupler_address'}, $slave->{'vendor_name'},
-	       $slave->{'product_name'}, $slave->{'product_desc'});
-    }
-}
-
-#------------------------------------------------------------------------------
-
-sub read_string
-{
-    (my $file_name) = @_;
-    my $data;
-
-    $data = `cat $file_name 2>/dev/null`;
-    if ($?) {
-	print "ERROR: Unable to read string $file_name!\n";
-	exit 1;
-    }
-
-    chomp $data;
-    return $data;
-}
-
-#------------------------------------------------------------------------------
-
-sub read_integer
-{
-    (my $file_name) = @_;
-
-    if (`cat $file_name 2>/dev/null` !~ /^(\d+)$/) {
-	print "ERROR: Unable to read integer $file_name!\n";
-	exit 1;
-    }
-
-    return int $1;
-}
-
-#------------------------------------------------------------------------------
-
-sub get_options
-{
-    my %opt;
-    my $optret;
-
-    $optret = getopts "m:h", \%opt;
-
-    &print_usage if defined $opt{'h'} or $#ARGV > -1;
-
-    if (defined $opt{'m'}) {
-	$master_index = $opt{'m'};
-    }
-    else {
-	$master_index = 0;
-    }
-}
-
-#------------------------------------------------------------------------------
-
-sub print_usage
-{
-    print "Usage: ec_list [OPTIONS]\n";
-    print "        -m <IDX>    Query master IDX.\n";
-    print "        -h          Show this help.\n";
-    exit 0;
-}
-
-#------------------------------------------------------------------------------