104 $slave->{'state'} = $1; |
104 $slave->{'state'} = $1; |
105 } |
105 } |
106 elsif ($line =~ /^Coupler: ([a-z]+)$/) { |
106 elsif ($line =~ /^Coupler: ([a-z]+)$/) { |
107 $slave->{'coupler'} = $1; |
107 $slave->{'coupler'} = $1; |
108 } |
108 } |
|
109 elsif ($line =~ /^Current consumption: (-?\d+) mA$/) { |
|
110 $slave->{'current'} = $1; |
|
111 } |
109 } |
112 } |
110 |
113 |
111 close INFO; |
114 close INFO; |
112 |
115 |
113 push @slaves, $slave; |
116 push @slaves, $slave; |
122 $cols = length $slave->{'ring_position'}; |
125 $cols = length $slave->{'ring_position'}; |
123 $ring_cols = $cols if ($cols > $ring_cols); |
126 $ring_cols = $cols if ($cols > $ring_cols); |
124 $cols = length $slave->{'advanced_position'}; |
127 $cols = length $slave->{'advanced_position'}; |
125 $adv_cols = $cols if ($cols > $adv_cols); |
128 $adv_cols = $cols if ($cols > $adv_cols); |
126 } |
129 } |
127 $fmt = sprintf " %%%is %%-%is %%-6s %%s\n", $ring_cols, $adv_cols; |
130 |
128 |
131 if (defined $opt{'c'}) { # display power consumtion |
129 for $slave (@slaves) { |
132 $fmt = sprintf " %%%is %%-%is %%6i %%6i %%s\n", |
130 &print_line if $slave->{'coupler'} eq "yes" and !defined $opt{n}; |
133 $ring_cols, $adv_cols; |
131 printf($fmt, $slave->{'ring_position'}, $slave->{'advanced_position'}, |
134 |
132 $slave->{'state'}, $slave->{'name'}); |
135 my $current_sum = 0; |
|
136 for $slave (@slaves) { |
|
137 if ($slave->{'coupler'} eq "yes") { |
|
138 &print_line if !defined $opt{n}; |
|
139 $current_sum = 0; # reset current sum |
|
140 } |
|
141 $current_sum -= $slave->{'current'}; |
|
142 printf($fmt, $slave->{'ring_position'}, |
|
143 $slave->{'advanced_position'}, $slave->{'current'}, |
|
144 $current_sum, $slave->{'name'}); |
|
145 } |
|
146 } |
|
147 else { |
|
148 $fmt = sprintf " %%%is %%-%is %%-6s %%s\n", $ring_cols, $adv_cols; |
|
149 |
|
150 for $slave (@slaves) { |
|
151 &print_line if $slave->{'coupler'} eq "yes" and !defined $opt{n}; |
|
152 printf($fmt, $slave->{'ring_position'}, |
|
153 $slave->{'advanced_position'}, $slave->{'state'}, |
|
154 $slave->{'name'}); |
|
155 } |
133 } |
156 } |
134 } |
157 } |
135 |
158 |
136 #------------------------------------------------------------------------------ |
159 #------------------------------------------------------------------------------ |
137 |
160 |
138 sub get_options |
161 sub get_options |
139 { |
162 { |
140 my $optret = getopts "m:nh", \%opt; |
163 my $optret = getopts "m:cnh", \%opt; |
141 |
164 |
142 &print_usage if defined $opt{h} or $#ARGV > -1 or !$optret; |
165 &print_usage if defined $opt{h} or $#ARGV > -1 or !$optret; |
143 |
166 |
144 if (defined $opt{m}) { |
167 if (defined $opt{m}) { |
145 $master_index = $opt{m}; |
168 $master_index = $opt{m}; |
155 { |
178 { |
156 my $cmd = `basename $0`; |
179 my $cmd = `basename $0`; |
157 chomp $cmd; |
180 chomp $cmd; |
158 print "Usage: $cmd [OPTIONS]\n"; |
181 print "Usage: $cmd [OPTIONS]\n"; |
159 print " -m <IDX> Query master <IDX>.\n"; |
182 print " -m <IDX> Query master <IDX>.\n"; |
|
183 print " -c Display current [mA] "; |
|
184 print "(3: consumption, 4: remaining).\n"; |
160 print " -n Display no coupler lines.\n"; |
185 print " -n Display no coupler lines.\n"; |
161 print " -h Show this help.\n"; |
186 print " -h Show this help.\n"; |
162 exit 0; |
187 exit 0; |
163 } |
188 } |
164 |
189 |