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