script/lsec
branchstable-1.3
changeset 1751 b6cfd85db58e
parent 1744 7bc131b92039
child 1760 036f19bde00b
--- a/script/lsec	Thu Oct 04 08:43:47 2007 +0000
+++ b/script/lsec	Fri Oct 05 08:16:43 2007 +0000
@@ -63,7 +63,6 @@
     my $slave_info_file;
     my @slaves;
     my $slave;
-    my $abs;
     my $line;
     my $ring_col_width;
     my $alias_col_width;
@@ -71,6 +70,7 @@
     my $width;
     my $last_alias;
     my $alias_index;
+    my $category;
 
     $master_dir = "/sys/ethercat/master" . $master_index;
 
@@ -87,21 +87,35 @@
         open INFO, $slave_info_file or die
             "ERROR: Failed to open $slave_info_file.";
 
+        $category = "";
         while ($line = <INFO>) {
-            if ($line =~ /^Name: (.*)$/) {
-                $slave->{'name'} = $1;
+            # remember category
+            if ($line =~ /^([^\s][^:]*):$/) {
+                $category = $1;
+            } elsif ($line =~ /^\s*$/) {
+                $category = "";
             }
-            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;
+
+            if ($category eq "") {
+                if ($line =~ /^Ring position: (\d+)$/) {
+                    $slave->{'ring_position'} = $1;
+                } elsif ($line =~ /^State: (.+) /) {
+                    $slave->{'state'} = $1;
+                } elsif ($line =~ /^Configured station alias: .* \((\d+)\)$/) {
+                    $slave->{'alias'} = $1;
+                } elsif ($line =~ /^Current consumption: (-?\d+) mA$/) {
+                    $slave->{'current'} = $1;
+                }
+            } elsif ($category eq "Identity") {
+                if ($line =~ /Vendor ID: .* \((\d+)\)$/) {
+                    $slave->{'vendor'} = $1;
+                } elsif ($line =~ /Product code: .* \((\d+)\)$/) {
+                    $slave->{'product'} = $1;
+                }
+            } elsif ($category eq "General") {
+                if ($line =~ /Name: (.*)$/) {
+                    $slave->{'name'} = $1;
+                }
             }
         }
 
@@ -131,6 +145,14 @@
         $alias_index++;
     }
 
+    # replace empty name with vendor id and product code
+    for $slave (@slaves) {
+        unless (defined $slave->{'name'}) {
+            $slave->{'name'} = sprintf("0x%08X:0x%08X", $slave->{'vendor'},
+                    $slave->{'product'});
+        }
+    }
+
     if (defined $opt{'c'}) { # display power consumtion
         $fmt = sprintf " %%%is  %%%is  %%6i  %%6i  %%s\n",
             $ring_col_width, $alias_col_width;
@@ -182,7 +204,7 @@
     print "        -m <IDX>    Query master <IDX>.\n";
     print "        -c          Display current [mA] ";
     print "(3: consumption, 4: remaining).\n";
-    print "        -n          Display no coupler lines.\n";
+    print "        -n          Do not display lines before aliased slaves.\n";
     print "        -h          Show this help.\n";
     exit 0;
 }