author | Florian Pose <fp@igh-essen.com> |
Tue, 13 Feb 2007 12:44:11 +0000 | |
changeset 559 | 63c5791a02a5 |
parent 519 | 54787e1b57d4 |
permissions | -rwxr-xr-x |
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 |
} |
519
54787e1b57d4
Display requested state in slave info.
Florian Pose <fp@igh-essen.com>
parents:
499
diff
changeset
|
103 |
elsif ($line =~ /^State: (.+) /) { |
325
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 |
} |
499
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
109 |
elsif ($line =~ /^Current consumption: (-?\d+) mA$/) { |
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
110 |
$slave->{'current'} = $1; |
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
111 |
} |
325
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 |
|
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
316
diff
changeset
|
114 |
close INFO; |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
316
diff
changeset
|
115 |
|
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
316
diff
changeset
|
116 |
push @slaves, $slave; |
186
644a053fe103
ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
117 |
} |
644a053fe103
ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
118 |
closedir $dirhandle; |
644a053fe103
ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
119 |
|
644a053fe103
ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
120 |
@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
|
121 |
|
358
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
122 |
$ring_cols = 0; |
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
123 |
$adv_cols = 0; |
186
644a053fe103
ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
124 |
for $slave (@slaves) { |
358
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
125 |
$cols = length $slave->{'ring_position'}; |
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
126 |
$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
|
127 |
$cols = length $slave->{'advanced_position'}; |
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
128 |
$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
|
129 |
} |
499
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
130 |
|
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
131 |
if (defined $opt{'c'}) { # display power consumtion |
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
132 |
$fmt = sprintf " %%%is %%-%is %%6i %%6i %%s\n", |
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
133 |
$ring_cols, $adv_cols; |
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
134 |
|
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
135 |
my $current_sum = 0; |
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
136 |
for $slave (@slaves) { |
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
137 |
if ($slave->{'coupler'} eq "yes") { |
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
138 |
&print_line if !defined $opt{n}; |
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
139 |
$current_sum = 0; # reset current sum |
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
140 |
} |
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
141 |
$current_sum -= $slave->{'current'}; |
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
142 |
printf($fmt, $slave->{'ring_position'}, |
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
143 |
$slave->{'advanced_position'}, $slave->{'current'}, |
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
144 |
$current_sum, $slave->{'name'}); |
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
145 |
} |
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
146 |
} |
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
147 |
else { |
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
148 |
$fmt = sprintf " %%%is %%-%is %%-6s %%s\n", $ring_cols, $adv_cols; |
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
149 |
|
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
150 |
for $slave (@slaves) { |
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
151 |
&print_line if $slave->{'coupler'} eq "yes" and !defined $opt{n}; |
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
152 |
printf($fmt, $slave->{'ring_position'}, |
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
153 |
$slave->{'advanced_position'}, $slave->{'state'}, |
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
154 |
$slave->{'name'}); |
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
155 |
} |
186
644a053fe103
ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
156 |
} |
644a053fe103
ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
157 |
} |
644a053fe103
ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
158 |
|
644a053fe103
ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
159 |
#------------------------------------------------------------------------------ |
644a053fe103
ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
160 |
|
644a053fe103
ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
161 |
sub get_options |
644a053fe103
ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
162 |
{ |
499
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
163 |
my $optret = getopts "m:cnh", \%opt; |
186
644a053fe103
ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
164 |
|
358
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
165 |
&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
|
166 |
|
358
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
167 |
if (defined $opt{m}) { |
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
168 |
$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
|
169 |
} |
644a053fe103
ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
170 |
else { |
358
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
171 |
$master_index = 0; |
186
644a053fe103
ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
172 |
} |
644a053fe103
ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
173 |
} |
644a053fe103
ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
174 |
|
644a053fe103
ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
175 |
#------------------------------------------------------------------------------ |
644a053fe103
ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
176 |
|
644a053fe103
ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
177 |
sub print_usage |
644a053fe103
ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
178 |
{ |
358
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
179 |
my $cmd = `basename $0`; |
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
180 |
chomp $cmd; |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
316
diff
changeset
|
181 |
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
|
182 |
print " -m <IDX> Query master <IDX>.\n"; |
499
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
183 |
print " -c Display current [mA] "; |
fb005e975181
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents:
358
diff
changeset
|
184 |
print "(3: consumption, 4: remaining).\n"; |
358
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
185 |
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
|
186 |
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
|
187 |
exit 0; |
644a053fe103
ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
188 |
} |
644a053fe103
ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
189 |
|
644a053fe103
ec_list tool for listing the bus in user space
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
190 |
#------------------------------------------------------------------------------ |
358
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
191 |
|
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
192 |
sub get_terminal_width |
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
193 |
{ |
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
194 |
my $winsize; |
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
195 |
die "no TIOCGWINSZ " unless defined &TIOCGWINSZ; |
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
196 |
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
|
197 |
unless (ioctl(TTY, &TIOCGWINSZ, $winsize='')) { |
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
198 |
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
|
199 |
} |
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
200 |
(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
|
201 |
return $col; |
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
202 |
} |
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
203 |
#------------------------------------------------------------------------------ |
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
204 |
|
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
205 |
sub print_line |
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
206 |
{ |
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
207 |
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
|
208 |
print "\n"; |
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
209 |
} |
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
210 |
|
f557be43b8c7
lsec: advanced number formatting; no-lines option.
Florian Pose <fp@igh-essen.com>
parents:
357
diff
changeset
|
211 |
#------------------------------------------------------------------------------ |