author | Florian Pose <fp@igh-essen.com> |
Fri, 13 Oct 2006 10:07:10 +0000 | |
branch | stable-1.1 |
changeset 1731 | 60b2aad9d40b |
parent 1722 | 14024a941c2e |
child 1739 | 5fcbd29151d2 |
permissions | -rwxr-xr-x |
1715
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/perl |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2 |
|
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
3 |
#------------------------------------------------------------------------------ |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
4 |
# |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
5 |
# l s e c - List EtherCAT |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
6 |
# |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
7 |
# Userspace tool for listing EtherCAT slaves. |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
8 |
# |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
9 |
# $Id$ |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
10 |
# |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
11 |
# Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
12 |
# |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
13 |
# This file is part of the IgH EtherCAT Master. |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
14 |
# |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
15 |
# The IgH EtherCAT Master is free software; you can redistribute it |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
16 |
# and/or modify it under the terms of the GNU General Public License |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
17 |
# as published by the Free Software Foundation; either version 2 of the |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
18 |
# License, or (at your option) any later version. |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
19 |
# |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
20 |
# The IgH EtherCAT Master is distributed in the hope that it will be |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
21 |
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
22 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
23 |
# GNU General Public License for more details. |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
24 |
# |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
25 |
# You should have received a copy of the GNU General Public License |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
26 |
# along with the IgH EtherCAT Master; if not, write to the Free Software |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
27 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
28 |
# |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
29 |
# The right to use EtherCAT Technology is granted and comes free of |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
30 |
# charge under condition of compatibility of product made by |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
31 |
# Licensee. People intending to distribute/sell products based on the |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
32 |
# code, have to sign an agreement to guarantee that products using |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
33 |
# software based on IgH EtherCAT master stay compatible with the actual |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
34 |
# EtherCAT specification (which are released themselves as an open |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
35 |
# standard) as the (only) precondition to have the right to use EtherCAT |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
36 |
# Technology, IP and trade marks. |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
37 |
# |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
38 |
#------------------------------------------------------------------------------ |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
39 |
|
1722
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
40 |
require 'sys/ioctl.ph'; |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
41 |
|
1715
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
42 |
use strict; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
43 |
use Getopt::Std; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
44 |
|
1722
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
45 |
my %opt; |
1715
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
46 |
my $master_index; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
47 |
my $master_dir; |
1722
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
48 |
my $term_width; |
1715
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
49 |
|
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
50 |
#------------------------------------------------------------------------------ |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
51 |
|
1722
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
52 |
$term_width = &get_terminal_width; |
1715
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
53 |
&get_options; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
54 |
&query_master; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
55 |
exit 0; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
56 |
|
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
57 |
#------------------------------------------------------------------------------ |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
58 |
|
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
59 |
sub query_master |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
60 |
{ |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
61 |
$master_dir = "/sys/ethercat" . $master_index; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
62 |
&query_slaves; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
63 |
} |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
64 |
|
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
65 |
#------------------------------------------------------------------------------ |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
66 |
|
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
67 |
sub query_slaves |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
68 |
{ |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
69 |
my $dirhandle; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
70 |
my $entry; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
71 |
my @slaves; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
72 |
my $slave; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
73 |
my $abs; |
1722
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
74 |
my $line; |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
75 |
my $ring_cols; |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
76 |
my $adv_cols; |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
77 |
my $fmt; |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
78 |
my $cols; |
1715
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
79 |
|
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
80 |
unless (opendir $dirhandle, $master_dir) { |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
81 |
print "Failed to open directory \"$master_dir\".\n"; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
82 |
exit 1; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
83 |
} |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
84 |
|
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
85 |
while ($entry = readdir $dirhandle) { |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
86 |
next unless $entry =~ /^slave(\d+)$/; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
87 |
|
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
88 |
$slave = {}; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
89 |
|
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
90 |
open INFO, "$master_dir/$entry/info" or die |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
91 |
"ERROR: Failed to open $master_dir/$entry/info"; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
92 |
|
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
93 |
while ($line = <INFO>) { |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
94 |
if ($line =~ /^Name: (.*)$/) { |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
95 |
$slave->{'name'} = $1; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
96 |
} |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
97 |
elsif ($line =~ /^Ring position: (\d+)$/) { |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
98 |
$slave->{'ring_position'} = $1; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
99 |
} |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
100 |
elsif ($line =~ /^Advanced position: (\d+:\d+)$/) { |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
101 |
$slave->{'advanced_position'} = $1; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
102 |
} |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
103 |
elsif ($line =~ /^State: (.+)$/) { |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
104 |
$slave->{'state'} = $1; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
105 |
} |
1722
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
106 |
elsif ($line =~ /^Coupler: ([a-z]+)$/) { |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
107 |
$slave->{'coupler'} = $1; |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
108 |
} |
1715
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
109 |
} |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
110 |
|
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
111 |
close INFO; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
112 |
|
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
113 |
push @slaves, $slave; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
114 |
} |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
115 |
closedir $dirhandle; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
116 |
|
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
117 |
@slaves = sort { $a->{'ring_position'} <=> $b->{'ring_position'} } @slaves; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
118 |
|
1722
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
119 |
$ring_cols = 0; |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
120 |
$adv_cols = 0; |
1715
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
121 |
for $slave (@slaves) { |
1722
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
122 |
$cols = length $slave->{'ring_position'}; |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
123 |
$ring_cols = $cols if ($cols > $ring_cols); |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
124 |
$cols = length $slave->{'advanced_position'}; |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
125 |
$adv_cols = $cols if ($cols > $adv_cols); |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
126 |
} |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
127 |
$fmt = sprintf " %%%is %%-%is %%-6s %%s\n", $ring_cols, $adv_cols; |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
128 |
|
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
129 |
for $slave (@slaves) { |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
130 |
&print_line if $slave->{'coupler'} eq "yes" and !defined $opt{n}; |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
131 |
printf($fmt, $slave->{'ring_position'}, $slave->{'advanced_position'}, |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
132 |
$slave->{'state'}, $slave->{'name'}); |
1715
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
133 |
} |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
134 |
} |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
135 |
|
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
136 |
#------------------------------------------------------------------------------ |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
137 |
|
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
138 |
sub get_options |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
139 |
{ |
1722
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
140 |
my $optret = getopts "m:nh", \%opt; |
1715
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
141 |
|
1722
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
142 |
&print_usage if defined $opt{h} or $#ARGV > -1 or !$optret; |
1715
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
143 |
|
1722
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
144 |
if (defined $opt{m}) { |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
145 |
$master_index = $opt{m}; |
1715
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
146 |
} |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
147 |
else { |
1722
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
148 |
$master_index = 0; |
1715
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
149 |
} |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
150 |
} |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
151 |
|
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
152 |
#------------------------------------------------------------------------------ |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
153 |
|
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
154 |
sub print_usage |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
155 |
{ |
1722
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
156 |
my $cmd = `basename $0`; |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
157 |
chomp $cmd; |
1715
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
158 |
print "Usage: $cmd [OPTIONS]\n"; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
159 |
print " -m <IDX> Query master <IDX>.\n"; |
1722
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
160 |
print " -n Display no coupler lines.\n"; |
1715
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
161 |
print " -h Show this help.\n"; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
162 |
exit 0; |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
163 |
} |
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
164 |
|
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
165 |
#------------------------------------------------------------------------------ |
1722
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
166 |
|
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
167 |
sub get_terminal_width |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
168 |
{ |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
169 |
my $winsize; |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
170 |
die "no TIOCGWINSZ " unless defined &TIOCGWINSZ; |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
171 |
open(TTY, "+</dev/tty") or die "No tty: $!"; |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
172 |
unless (ioctl(TTY, &TIOCGWINSZ, $winsize='')) { |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
173 |
die sprintf "$0: ioctl TIOCGWINSZ (%08x: $!)\n", &TIOCGWINSZ; |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
174 |
} |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
175 |
(my $row, my $col, my $xpixel, my $ypixel) = unpack('S4', $winsize); |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
176 |
return $col; |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
177 |
} |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
178 |
#------------------------------------------------------------------------------ |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
179 |
|
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
180 |
sub print_line |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
181 |
{ |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
182 |
for (my $i = 0; $i < $term_width; $i++) {print "-";} |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
183 |
print "\n"; |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
184 |
} |
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
185 |
|
14024a941c2e
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
Florian Pose <fp@igh-essen.com>
parents:
1715
diff
changeset
|
186 |
#------------------------------------------------------------------------------ |