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