MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec) stable-1.1
authorFlorian Pose <fp@igh-essen.com>
Mon, 11 Sep 2006 09:28:26 +0000
branchstable-1.1
changeset 1722 14024a941c2e
parent 1721 8d1fcfe68ced
child 1723 492767ba685a
MERGE trunk -r537:540 -> branches/stable-1.1 (coupler info in sysfs, lines in lsec)
master/slave.c
script/lsec.pl
--- a/master/slave.c	Fri Sep 08 13:06:09 2006 +0000
+++ b/master/slave.c	Mon Sep 11 09:28:26 2006 +0000
@@ -530,8 +530,10 @@
     off += ec_state_string(slave->current_state, buffer + off);
     off += sprintf(buffer + off, "\nRing position: %i\n",
                    slave->ring_position);
-    off += sprintf(buffer + off, "Advanced position: %i:%i\n\n",
+    off += sprintf(buffer + off, "Advanced position: %i:%i\n",
                    slave->coupler_index, slave->coupler_subindex);
+    off += sprintf(buffer + off, "Coupler: %s\n\n",
+                   ec_slave_is_coupler(slave) ? "yes" : "no");
 
     off += sprintf(buffer + off, "Data link status:\n");
     for (i = 0; i < 4; i++) {
--- a/script/lsec.pl	Fri Sep 08 13:06:09 2006 +0000
+++ b/script/lsec.pl	Mon Sep 11 09:28:26 2006 +0000
@@ -37,14 +37,19 @@
 #
 #------------------------------------------------------------------------------
 
+require 'sys/ioctl.ph';
+
 use strict;
 use Getopt::Std;
 
+my %opt;
 my $master_index;
 my $master_dir;
+my $term_width;
 
 #------------------------------------------------------------------------------
 
+$term_width = &get_terminal_width;
 &get_options;
 &query_master;
 exit 0;
@@ -66,7 +71,11 @@
     my @slaves;
     my $slave;
     my $abs;
-	my $line;
+    my $line;
+    my $ring_cols;
+    my $adv_cols;
+    my $fmt;
+    my $cols;
 
     unless (opendir $dirhandle, $master_dir) {
 		print "Failed to open directory \"$master_dir\".\n";
@@ -94,6 +103,9 @@
 			elsif ($line =~ /^State: (.+)$/) {
 				$slave->{'state'} = $1;
 			}
+			elsif ($line =~ /^Coupler: ([a-z]+)$/) {
+				$slave->{'coupler'} = $1;
+			}
 		}
 
 		close INFO;
@@ -104,12 +116,20 @@
 
     @slaves = sort { $a->{'ring_position'} <=> $b->{'ring_position'} } @slaves;
 
-    print "EtherCAT bus listing for master $master_index:\n";
+    $ring_cols = 0;
+    $adv_cols = 0;
     for $slave (@slaves) {
-		$abs = sprintf "%i", $slave->{'ring_position'};
-		printf(" %3s %8s  %-6s  %s\n",
-			   $abs, $slave->{'advanced_position'},
-			   $slave->{'state'}, $slave->{'name'});
+	$cols = length $slave->{'ring_position'};
+	$ring_cols = $cols if ($cols > $ring_cols);
+	$cols = length $slave->{'advanced_position'};
+	$adv_cols = $cols if ($cols > $adv_cols);
+    }
+    $fmt = sprintf " %%%is  %%-%is  %%-6s  %%s\n", $ring_cols, $adv_cols;
+
+    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'});
     }
 }
 
@@ -117,18 +137,15 @@
 
 sub get_options
 {
-    my %opt;
-    my $optret;
+    my $optret = getopts "m:nh", \%opt;
 
-    $optret = getopts "m:h", \%opt;
+    &print_usage if defined $opt{h} or $#ARGV > -1 or !$optret;
 
-    &print_usage if defined $opt{'h'} or $#ARGV > -1 or !$optret;
-
-    if (defined $opt{'m'}) {
-		$master_index = $opt{'m'};
+    if (defined $opt{m}) {
+	$master_index = $opt{m};
     }
     else {
-		$master_index = 0;
+	$master_index = 0;
     }
 }
 
@@ -136,12 +153,34 @@
 
 sub print_usage
 {
-	my $cmd = `basename $0`;
-	chomp $cmd;
+    my $cmd = `basename $0`;
+    chomp $cmd;
     print "Usage: $cmd [OPTIONS]\n";
     print "        -m <IDX>    Query master <IDX>.\n";
+    print "        -n          Display no coupler lines.\n";
     print "        -h          Show this help.\n";
     exit 0;
 }
 
 #------------------------------------------------------------------------------
+
+sub get_terminal_width
+{
+    my $winsize;
+    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;
+    }
+    (my $row, my $col, my $xpixel, my $ypixel) = unpack('S4', $winsize);
+    return $col;
+}
+#------------------------------------------------------------------------------
+
+sub print_line
+{
+    for (my $i = 0; $i < $term_width; $i++) {print "-";}
+    print "\n";
+}
+
+#------------------------------------------------------------------------------