85 $slave = {}; |
85 $slave = {}; |
86 $slave_info_file = "$master_dir/$entry/info"; |
86 $slave_info_file = "$master_dir/$entry/info"; |
87 open INFO, $slave_info_file or die |
87 open INFO, $slave_info_file or die |
88 "ERROR: Failed to open $slave_info_file."; |
88 "ERROR: Failed to open $slave_info_file."; |
89 |
89 |
|
90 $category = ""; |
90 while ($line = <INFO>) { |
91 while ($line = <INFO>) { |
91 if ($line =~ /^Name: (.*)$/) { |
92 # remember category |
92 $slave->{'name'} = $1; |
93 if ($line =~ /^([^\s][^:]*):$/) { |
|
94 $category = $1; |
|
95 } elsif ($line =~ /^\s*$/) { |
|
96 $category = ""; |
93 } |
97 } |
94 elsif ($line =~ /^Ring position: (\d+)$/) { |
98 |
95 $slave->{'ring_position'} = $1; |
99 if ($category eq "") { |
96 } |
100 if ($line =~ /^Ring position: (\d+)$/) { |
97 elsif ($line =~ /Configured station alias: .* \((\d+)\)$/) { |
101 $slave->{'ring_position'} = $1; |
98 $slave->{'alias'} = $1; |
102 } elsif ($line =~ /^State: (.+) /) { |
99 } |
103 $slave->{'state'} = $1; |
100 elsif ($line =~ /^State: (.+) /) { |
104 } elsif ($line =~ /^Configured station alias: .* \((\d+)\)$/) { |
101 $slave->{'state'} = $1; |
105 $slave->{'alias'} = $1; |
102 } |
106 } elsif ($line =~ /^Current consumption: (-?\d+) mA$/) { |
103 elsif ($line =~ /^Current consumption: (-?\d+) mA$/) { |
107 $slave->{'current'} = $1; |
104 $slave->{'current'} = $1; |
108 } |
|
109 } elsif ($category eq "Identity") { |
|
110 if ($line =~ /Vendor ID: .* \((\d+)\)$/) { |
|
111 $slave->{'vendor'} = $1; |
|
112 } elsif ($line =~ /Product code: .* \((\d+)\)$/) { |
|
113 $slave->{'product'} = $1; |
|
114 } |
|
115 } elsif ($category eq "General") { |
|
116 if ($line =~ /Name: (.*)$/) { |
|
117 $slave->{'name'} = $1; |
|
118 } |
105 } |
119 } |
106 } |
120 } |
107 |
121 |
108 close INFO; |
122 close INFO; |
109 push @slaves, $slave; |
123 push @slaves, $slave; |
129 $width = length $slave->{'ring_position'}; |
143 $width = length $slave->{'ring_position'}; |
130 $ring_col_width = $width if ($width > $ring_col_width); |
144 $ring_col_width = $width if ($width > $ring_col_width); |
131 $alias_index++; |
145 $alias_index++; |
132 } |
146 } |
133 |
147 |
|
148 # replace empty name with vendor id and product code |
|
149 for $slave (@slaves) { |
|
150 unless (defined $slave->{'name'}) { |
|
151 $slave->{'name'} = sprintf("0x%08X:0x%08X", $slave->{'vendor'}, |
|
152 $slave->{'product'}); |
|
153 } |
|
154 } |
|
155 |
134 if (defined $opt{'c'}) { # display power consumtion |
156 if (defined $opt{'c'}) { # display power consumtion |
135 $fmt = sprintf " %%%is %%%is %%6i %%6i %%s\n", |
157 $fmt = sprintf " %%%is %%%is %%6i %%6i %%s\n", |
136 $ring_col_width, $alias_col_width; |
158 $ring_col_width, $alias_col_width; |
137 |
159 |
138 my $current_sum = 0; |
160 my $current_sum = 0; |
180 chomp $cmd; |
202 chomp $cmd; |
181 print "Usage: $cmd [OPTIONS]\n"; |
203 print "Usage: $cmd [OPTIONS]\n"; |
182 print " -m <IDX> Query master <IDX>.\n"; |
204 print " -m <IDX> Query master <IDX>.\n"; |
183 print " -c Display current [mA] "; |
205 print " -c Display current [mA] "; |
184 print "(3: consumption, 4: remaining).\n"; |
206 print "(3: consumption, 4: remaining).\n"; |
185 print " -n Display no coupler lines.\n"; |
207 print " -n Do not display lines before aliased slaves.\n"; |
186 print " -h Show this help.\n"; |
208 print " -h Show this help.\n"; |
187 exit 0; |
209 exit 0; |
188 } |
210 } |
189 |
211 |
190 #------------------------------------------------------------------------------ |
212 #------------------------------------------------------------------------------ |