script/lsec.pl
author Florian Pose <fp@igh-essen.com>
Mon, 30 Oct 2006 15:39:03 +0000
changeset 467 2274de57ca84
parent 358 f557be43b8c7
child 499 fb005e975181
permissions -rwxr-xr-x
Remove estimated sync manager sizes when leaving operation mode.
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
#
316
23f501274ddf renamed ec_list script to lsec.
Florian Pose <fp@igh-essen.com>
parents: 315
diff changeset
     5
#  l s e c  -  List EtherCAT
186
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
#
258
7d46b83e3175 Aligned property values on all files.
Florian Pose <fp@igh-essen.com>
parents: 257
diff changeset
     9
#  $Id$
186
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
357
277de5572f99 Coupler information in slave info file, lines in lsec.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    40
require 'sys/ioctl.ph';
277de5572f99 Coupler information in slave info file, lines in lsec.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    41
186
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
use strict;
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
use Getopt::Std;
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
358
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
    45
my %opt;
186
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
my $master_index;
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
my $master_dir;
357
277de5572f99 Coupler information in slave info file, lines in lsec.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    48
my $term_width;
186
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
#------------------------------------------------------------------------------
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
357
277de5572f99 Coupler information in slave info file, lines in lsec.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    52
$term_width = &get_terminal_width;
186
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
&get_options;
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
&query_master;
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
exit 0;
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
#------------------------------------------------------------------------------
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
sub query_master
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
    $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
    62
    &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
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
#------------------------------------------------------------------------------
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
sub query_slaves
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
{
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
    my $dirhandle;
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
    my $entry;
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
    my @slaves;
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
    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
    73
    my $abs;
358
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
    74
    my $line;
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
    75
    my $ring_cols;
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
    76
    my $adv_cols;
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
    77
    my $fmt;
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
    78
    my $cols;
186
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
    unless (opendir $dirhandle, $master_dir) {
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 316
diff changeset
    81
		print "Failed to open directory \"$master_dir\".\n";
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 316
diff changeset
    82
		exit 1;
186
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
    }
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
    while ($entry = readdir $dirhandle) {
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
        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
    87
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 316
diff changeset
    88
		$slave = {};
186
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 316
diff changeset
    90
		open INFO, "$master_dir/$entry/info" or die
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 316
diff changeset
    91
			"ERROR: Failed to open $master_dir/$entry/info";
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 316
diff changeset
    92
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 316
diff changeset
    93
		while ($line = <INFO>) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 316
diff changeset
    94
			if ($line =~ /^Name: (.*)$/) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 316
diff changeset
    95
				$slave->{'name'} = $1;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 316
diff changeset
    96
			}
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 316
diff changeset
    97
			elsif ($line =~ /^Ring position: (\d+)$/) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 316
diff changeset
    98
				$slave->{'ring_position'} = $1;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 316
diff changeset
    99
			}
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 316
diff changeset
   100
			elsif ($line =~ /^Advanced position: (\d+:\d+)$/) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 316
diff changeset
   101
				$slave->{'advanced_position'} = $1;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 316
diff changeset
   102
			}
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 316
diff changeset
   103
			elsif ($line =~ /^State: (.+)$/) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 316
diff changeset
   104
				$slave->{'state'} = $1;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 316
diff changeset
   105
			}
357
277de5572f99 Coupler information in slave info file, lines in lsec.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   106
			elsif ($line =~ /^Coupler: ([a-z]+)$/) {
277de5572f99 Coupler information in slave info file, lines in lsec.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   107
				$slave->{'coupler'} = $1;
277de5572f99 Coupler information in slave info file, lines in lsec.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   108
			}
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 316
diff changeset
   109
		}
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 316
diff changeset
   110
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 316
diff changeset
   111
		close INFO;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 316
diff changeset
   112
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 316
diff changeset
   113
		push @slaves, $slave;
186
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
    closedir $dirhandle;
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
    @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
   118
358
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   119
    $ring_cols = 0;
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   120
    $adv_cols = 0;
186
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
    for $slave (@slaves) {
358
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   122
	$cols = length $slave->{'ring_position'};
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   123
	$ring_cols = $cols if ($cols > $ring_cols);
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   124
	$cols = length $slave->{'advanced_position'};
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   125
	$adv_cols = $cols if ($cols > $adv_cols);
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   126
    }
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   127
    $fmt = sprintf " %%%is  %%-%is  %%-6s  %%s\n", $ring_cols, $adv_cols;
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   128
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   129
    for $slave (@slaves) {
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   130
	&print_line if $slave->{'coupler'} eq "yes" and !defined $opt{n};
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   131
	printf($fmt, $slave->{'ring_position'}, $slave->{'advanced_position'},
357
277de5572f99 Coupler information in slave info file, lines in lsec.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   132
	       $slave->{'state'}, $slave->{'name'});
186
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
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
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
sub get_options
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
{
358
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   140
    my $optret = getopts "m:nh", \%opt;
186
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
358
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   142
    &print_usage if defined $opt{h} or $#ARGV > -1 or !$optret;
186
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
358
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   144
    if (defined $opt{m}) {
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   145
	$master_index = $opt{m};
186
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
    else {
358
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   148
	$master_index = 0;
186
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
    }
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
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
#------------------------------------------------------------------------------
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
sub print_usage
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
{
358
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   156
    my $cmd = `basename $0`;
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   157
    chomp $cmd;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 316
diff changeset
   158
    print "Usage: $cmd [OPTIONS]\n";
257
291019811648 ec_list shows SII device description on demand.
Florian Pose <fp@igh-essen.com>
parents: 250
diff changeset
   159
    print "        -m <IDX>    Query master <IDX>.\n";
358
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   160
    print "        -n          Display no coupler lines.\n";
186
644a053fe103 ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
    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
   162
    exit 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
#------------------------------------------------------------------------------
358
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   166
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   167
sub get_terminal_width
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   168
{
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   169
    my $winsize;
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   170
    die "no TIOCGWINSZ " unless defined &TIOCGWINSZ;
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   171
    open(TTY, "+</dev/tty") or die "No tty: $!";
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   172
    unless (ioctl(TTY, &TIOCGWINSZ, $winsize='')) {
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   173
	die sprintf "$0: ioctl TIOCGWINSZ (%08x: $!)\n", &TIOCGWINSZ;
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   174
    }
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   175
    (my $row, my $col, my $xpixel, my $ypixel) = unpack('S4', $winsize);
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   176
    return $col;
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   177
}
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   178
#------------------------------------------------------------------------------
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   179
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   180
sub print_line
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   181
{
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   182
    for (my $i = 0; $i < $term_width; $i++) {print "-";}
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   183
    print "\n";
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   184
}
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   185
f557be43b8c7 lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents: 357
diff changeset
   186
#------------------------------------------------------------------------------