mirror of
https://gitlab.com/etherlab.org/ethercat.git
synced 2026-09-23 10:33:49 +08:00
Removed X:Y addressing scheme, ec_slave_is_coupler(),
ec_master_calc_addressing(), coupler_index and coupler_subindex variables. Adapted lsec script and examples.
This commit is contained in:
+71
-63
@@ -60,93 +60,99 @@ sub query
|
||||
my $master_dir;
|
||||
my $dirhandle;
|
||||
my $entry;
|
||||
my $slave_info_file;
|
||||
my @slaves;
|
||||
my $slave;
|
||||
my $abs;
|
||||
my $line;
|
||||
my $ring_cols;
|
||||
my $adv_cols;
|
||||
my $ring_col_width;
|
||||
my $alias_col_width;
|
||||
my $fmt;
|
||||
my $cols;
|
||||
my $width;
|
||||
my $last_alias;
|
||||
my $alias_index;
|
||||
|
||||
$master_dir = "/sys/ethercat/master" . $master_index;
|
||||
|
||||
unless (opendir $dirhandle, $master_dir) {
|
||||
print "Failed to open directory \"$master_dir\".\n";
|
||||
exit 1;
|
||||
print "Failed to open directory \"$master_dir\".\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
while ($entry = readdir $dirhandle) {
|
||||
next unless $entry =~ /^slave(\d+)$/;
|
||||
|
||||
$slave = {};
|
||||
$slave = {};
|
||||
$slave_info_file = "$master_dir/$entry/info";
|
||||
open INFO, $slave_info_file or die
|
||||
"ERROR: Failed to open $slave_info_file.";
|
||||
|
||||
open INFO, "$master_dir/$entry/info" or die
|
||||
"ERROR: Failed to open $master_dir/$entry/info";
|
||||
while ($line = <INFO>) {
|
||||
if ($line =~ /^Name: (.*)$/) {
|
||||
$slave->{'name'} = $1;
|
||||
}
|
||||
elsif ($line =~ /^Ring position: (\d+)$/) {
|
||||
$slave->{'ring_position'} = $1;
|
||||
}
|
||||
elsif ($line =~ /Configured station alias: .* \((\d+)\)$/) {
|
||||
$slave->{'alias'} = $1;
|
||||
}
|
||||
elsif ($line =~ /^State: (.+) /) {
|
||||
$slave->{'state'} = $1;
|
||||
}
|
||||
elsif ($line =~ /^Current consumption: (-?\d+) mA$/) {
|
||||
$slave->{'current'} = $1;
|
||||
}
|
||||
}
|
||||
|
||||
while ($line = <INFO>) {
|
||||
if ($line =~ /^Name: (.*)$/) {
|
||||
$slave->{'name'} = $1;
|
||||
}
|
||||
elsif ($line =~ /^Ring position: (\d+)$/) {
|
||||
$slave->{'ring_position'} = $1;
|
||||
}
|
||||
elsif ($line =~ /^Advanced position: (\d+:\d+)$/) {
|
||||
$slave->{'advanced_position'} = $1;
|
||||
}
|
||||
elsif ($line =~ /^State: (.+) /) {
|
||||
$slave->{'state'} = $1;
|
||||
}
|
||||
elsif ($line =~ /^Coupler: ([a-z]+)$/) {
|
||||
$slave->{'coupler'} = $1;
|
||||
}
|
||||
elsif ($line =~ /^Current consumption: (-?\d+) mA$/) {
|
||||
$slave->{'current'} = $1;
|
||||
}
|
||||
}
|
||||
|
||||
close INFO;
|
||||
|
||||
push @slaves, $slave;
|
||||
close INFO;
|
||||
push @slaves, $slave;
|
||||
}
|
||||
closedir $dirhandle;
|
||||
|
||||
@slaves = sort { $a->{'ring_position'} <=> $b->{'ring_position'} } @slaves;
|
||||
|
||||
$ring_cols = 0;
|
||||
$adv_cols = 0;
|
||||
# create field addresses and calculate column widths
|
||||
$ring_col_width = 0;
|
||||
$alias_col_width = 0;
|
||||
$last_alias = "";
|
||||
for $slave (@slaves) {
|
||||
$cols = length $slave->{'ring_position'};
|
||||
$ring_cols = $cols if ($cols > $ring_cols);
|
||||
$cols = length $slave->{'advanced_position'};
|
||||
$adv_cols = $cols if ($cols > $adv_cols);
|
||||
if ($slave->{'alias'}) {
|
||||
$last_alias = $slave->{'alias'};
|
||||
$alias_index = 0;
|
||||
}
|
||||
if ($last_alias) {
|
||||
$slave->{'field_address'} = "#" . $last_alias . ":" . $alias_index;
|
||||
$width = length $slave->{'field_address'};
|
||||
$alias_col_width = $width if ($width > $alias_col_width);
|
||||
}
|
||||
$width = length $slave->{'ring_position'};
|
||||
$ring_col_width = $width if ($width > $ring_col_width);
|
||||
$alias_index++;
|
||||
}
|
||||
|
||||
if (defined $opt{'c'}) { # display power consumtion
|
||||
$fmt = sprintf " %%%is %%-%is %%6i %%6i %%s\n",
|
||||
$ring_cols, $adv_cols;
|
||||
$fmt = sprintf " %%%is %%%is %%6i %%6i %%s\n",
|
||||
$ring_col_width, $alias_col_width;
|
||||
|
||||
my $current_sum = 0;
|
||||
for $slave (@slaves) {
|
||||
if ($slave->{'coupler'} eq "yes") {
|
||||
&print_line if !defined $opt{n};
|
||||
$current_sum = 0; # reset current sum
|
||||
}
|
||||
$current_sum -= $slave->{'current'};
|
||||
printf($fmt, $slave->{'ring_position'},
|
||||
$slave->{'advanced_position'}, $slave->{'current'},
|
||||
$current_sum, $slave->{'name'});
|
||||
}
|
||||
my $current_sum = 0;
|
||||
for $slave (@slaves) {
|
||||
&print_line if $slave->{'alias'} and !defined $opt{n};
|
||||
$current_sum = 0 if $slave->{'current'} < 0;
|
||||
$current_sum -= $slave->{'current'};
|
||||
printf($fmt, $slave->{'ring_position'}, $slave->{'field_address'},
|
||||
$slave->{'current'}, $current_sum, $slave->{'name'});
|
||||
}
|
||||
}
|
||||
else {
|
||||
$fmt = sprintf " %%%is %%-%is %%-6s %%s\n", $ring_cols, $adv_cols;
|
||||
else { # normal display
|
||||
$fmt = sprintf " %%%is %%%is %%-6s %%s\n",
|
||||
$ring_col_width, $alias_col_width;
|
||||
|
||||
for $slave (@slaves) {
|
||||
&print_line if $slave->{'coupler'} eq "yes" and !defined $opt{n};
|
||||
printf($fmt, $slave->{'ring_position'},
|
||||
$slave->{'advanced_position'}, $slave->{'state'},
|
||||
$slave->{'name'});
|
||||
}
|
||||
for $slave (@slaves) {
|
||||
&print_line if $slave->{'alias'} and !defined $opt{n};
|
||||
printf($fmt, $slave->{'ring_position'}, $slave->{'field_address'},
|
||||
$slave->{'state'}, $slave->{'name'});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,10 +165,10 @@ sub get_options
|
||||
&print_usage if defined $opt{h} or $#ARGV > -1 or !$optret;
|
||||
|
||||
if (defined $opt{m}) {
|
||||
$master_index = $opt{m};
|
||||
$master_index = $opt{m};
|
||||
}
|
||||
else {
|
||||
$master_index = 0;
|
||||
$master_index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +195,7 @@ sub get_terminal_width
|
||||
die "no TIOCGWINSZ " unless defined &TIOCGWINSZ;
|
||||
open(TTY, "+</dev/tty") or die "No tty: $!";
|
||||
unless (ioctl(TTY, &TIOCGWINSZ, $winsize='')) {
|
||||
die sprintf "$0: ioctl TIOCGWINSZ (%08x: $!)\n", &TIOCGWINSZ;
|
||||
die sprintf "$0: ioctl TIOCGWINSZ (%08x: $!)\n", &TIOCGWINSZ;
|
||||
}
|
||||
(my $row, my $col, my $xpixel, my $ypixel) = unpack('S4', $winsize);
|
||||
return $col;
|
||||
@@ -198,7 +204,9 @@ sub get_terminal_width
|
||||
|
||||
sub print_line
|
||||
{
|
||||
for (my $i = 0; $i < $term_width; $i++) {print "-";}
|
||||
for (my $i = 0; $i < $term_width; $i++) {
|
||||
print "-";
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user