script/lsec.pl
author Florian Pose <fp@igh-essen.com>
Thu, 03 Aug 2006 13:05:52 +0000
branchstable-1.0
changeset 1626 d849e3b7b202
parent 1624 9dc190591c0f
permissions -rwxr-xr-x
MERGE trunk -r492:493 -> branches/stable-1.0 (Init script identation.
1624
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
#!/usr/bin/perl
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
#------------------------------------------------------------------------------
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
#
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
#  l s e c  -  List EtherCAT
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
#
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
#  Userspace tool for listing EtherCAT slaves.
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
#
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
#  $Id$
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
#
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
#  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
#
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
#  This file is part of the IgH EtherCAT Master.
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
#
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
#  The IgH EtherCAT Master is free software; you can redistribute it
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
#  and/or modify it under the terms of the GNU General Public License
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
#  as published by the Free Software Foundation; either version 2 of the
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
#  License, or (at your option) any later version.
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
#
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
#  The IgH EtherCAT Master is distributed in the hope that it will be
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
#  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
#  GNU General Public License for more details.
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
#
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
#  You should have received a copy of the GNU General Public License
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
#  along with the IgH EtherCAT Master; if not, write to the Free Software
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
#
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
#  The right to use EtherCAT Technology is granted and comes free of
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
#  charge under condition of compatibility of product made by
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
#  Licensee. People intending to distribute/sell products based on the
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
#  code, have to sign an agreement to guarantee that products using
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
#  software based on IgH EtherCAT master stay compatible with the actual
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
#  EtherCAT specification (which are released themselves as an open
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
#  standard) as the (only) precondition to have the right to use EtherCAT
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
#  Technology, IP and trade marks.
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
#------------------------------------------------------------------------------
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
use strict;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
use Getopt::Std;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
my $master_index;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
my $master_dir;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
my $show_sii_naming;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
#------------------------------------------------------------------------------
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
&get_options;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
&query_master;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
exit 0;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
#------------------------------------------------------------------------------
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
sub query_master
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
{
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
    $master_dir = "/sys/ethercat" . $master_index;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
    &query_slaves;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
}
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
#------------------------------------------------------------------------------
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
sub query_slaves
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
{
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
    my $dirhandle;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
    my $slave_dir;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
    my $entry;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
    my $slave_index;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
    my $file_name;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
    my $vendor_name;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
    my @slaves;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
    my $slave;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
    my $abs;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
    unless (opendir $dirhandle, $master_dir) {
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
	print "Failed to open directory \"$master_dir\".\n";
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
	exit 1;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
    }
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
    while ($entry = readdir $dirhandle) {
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
        next unless $entry =~ /^slave(\d+)$/;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
	$slave_dir = $master_dir . "/" . $entry;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
	$slave = {};
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
	$slave->{'ring_position'} =
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
	    &read_integer("$slave_dir/ring_position");
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
	$slave->{'advanced_position'} =
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
	    &read_string("$slave_dir/advanced_position");
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
	unless ($show_sii_naming) {
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
	    $slave->{'vendor_name'} =
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
		&read_string("$slave_dir/vendor_name");
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
	    $slave->{'product_name'} =
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
		&read_string("$slave_dir/product_name");
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
	    $slave->{'product_desc'} =
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
		&read_string("$slave_dir/product_desc");
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
	}
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
	else {
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
	    $slave->{'name'} =
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
		&read_string("$slave_dir/name");
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
	}
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
	$slave->{'type'} =
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
	    &read_string("$slave_dir/type");
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
	push @slaves, $slave;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
    }
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
    closedir $dirhandle;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
    @slaves = sort { $a->{'ring_position'} <=> $b->{'ring_position'} } @slaves;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
    print "EtherCAT bus listing for master $master_index:\n";
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
    for $slave (@slaves) {
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
	if ($slave->{'type'} eq "coupler") {
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
	    print "--------------------------------------------------------\n";
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
	}
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
	$abs = sprintf "%i", $slave->{'ring_position'};
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
	printf(" %3s %8s   ", $abs, $slave->{'advanced_position'});
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
	unless ($show_sii_naming) {
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
	    printf("%-12s %-10s %s\n", $slave->{'vendor_name'},
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
		   $slave->{'product_name'}, $slave->{'product_desc'});
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
	}
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
	else {
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
	    printf("%s\n", $slave->{'name'});
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
	}
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
    }
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
}
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
#------------------------------------------------------------------------------
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
sub read_string
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
{
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
    (my $file_name) = @_;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
    my $data;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
    $data = `cat $file_name 2>/dev/null`;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
    if ($?) {
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
	print "ERROR: Unable to read string $file_name!\n";
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
	exit 1;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
    }
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
    chomp $data;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
    return $data;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
}
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
#------------------------------------------------------------------------------
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
sub read_integer
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
{
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
    (my $file_name) = @_;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
    if (`cat $file_name 2>/dev/null` !~ /^(\d+)$/) {
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
	print "ERROR: Unable to read integer $file_name!\n";
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
	exit 1;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
    }
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
    return int $1;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
}
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
#------------------------------------------------------------------------------
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
sub get_options
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
{
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
    my %opt;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
    my $optret;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
    $optret = getopts "m:sh", \%opt;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
    &print_usage if defined $opt{'h'} or $#ARGV > -1 or !$optret;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
    if (defined $opt{'m'}) {
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
	$master_index = $opt{'m'};
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
    }
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
    else {
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
	$master_index = 0;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
    }
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
    $show_sii_naming = defined $opt{'s'};
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
}
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
#------------------------------------------------------------------------------
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
sub print_usage
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
{
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
    print "Usage: $0 [OPTIONS]\n";
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
    print "        -m <IDX>    Query master <IDX>.\n";
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
    print "        -s          Show EEPROM name instead of";
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
    print " vendor/product/description.\n";
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
    print "        -h          Show this help.\n";
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
    exit 0;
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
}
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
9dc190591c0f MERGE trunk -r452:489 -> stable-1.0 (datagrams, bugfixes, EEPROM info, idle mode)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
#------------------------------------------------------------------------------