script/lsec.pl
changeset 357 277de5572f99
parent 325 7833cf70c4f2
child 358 f557be43b8c7
equal deleted inserted replaced
356:4bdc4f2e1a93 357:277de5572f99
    35 #  standard) as the (only) precondition to have the right to use EtherCAT
    35 #  standard) as the (only) precondition to have the right to use EtherCAT
    36 #  Technology, IP and trade marks.
    36 #  Technology, IP and trade marks.
    37 #
    37 #
    38 #------------------------------------------------------------------------------
    38 #------------------------------------------------------------------------------
    39 
    39 
       
    40 require 'sys/ioctl.ph';
       
    41 
    40 use strict;
    42 use strict;
    41 use Getopt::Std;
    43 use Getopt::Std;
    42 
    44 
    43 my $master_index;
    45 my $master_index;
    44 my $master_dir;
    46 my $master_dir;
       
    47 my $term_width;
    45 
    48 
    46 #------------------------------------------------------------------------------
    49 #------------------------------------------------------------------------------
    47 
    50 
       
    51 $term_width = &get_terminal_width;
    48 &get_options;
    52 &get_options;
    49 &query_master;
    53 &query_master;
    50 exit 0;
    54 exit 0;
       
    55 
       
    56 #------------------------------------------------------------------------------
       
    57 
       
    58 sub get_terminal_width
       
    59 {
       
    60     my $winsize;
       
    61     die "no TIOCGWINSZ " unless defined &TIOCGWINSZ;
       
    62     open(TTY, "+</dev/tty") or die "No tty: $!";
       
    63     unless (ioctl(TTY, &TIOCGWINSZ, $winsize='')) {
       
    64 	die sprintf "$0: ioctl TIOCGWINSZ (%08x: $!)\n", &TIOCGWINSZ;
       
    65     }
       
    66     (my $row, my $col, my $xpixel, my $ypixel) = unpack('S4', $winsize);
       
    67     return $col;
       
    68 }
       
    69 #------------------------------------------------------------------------------
       
    70 
       
    71 sub print_line
       
    72 {
       
    73     for (my $i = 0; $i < $term_width; $i++) {print "-";}
       
    74     print "\n";
       
    75 }
    51 
    76 
    52 #------------------------------------------------------------------------------
    77 #------------------------------------------------------------------------------
    53 
    78 
    54 sub query_master
    79 sub query_master
    55 {
    80 {
    92 				$slave->{'advanced_position'} = $1;
   117 				$slave->{'advanced_position'} = $1;
    93 			}
   118 			}
    94 			elsif ($line =~ /^State: (.+)$/) {
   119 			elsif ($line =~ /^State: (.+)$/) {
    95 				$slave->{'state'} = $1;
   120 				$slave->{'state'} = $1;
    96 			}
   121 			}
       
   122 			elsif ($line =~ /^Coupler: ([a-z]+)$/) {
       
   123 				$slave->{'coupler'} = $1;
       
   124 			}
    97 		}
   125 		}
    98 
   126 
    99 		close INFO;
   127 		close INFO;
   100 
   128 
   101 		push @slaves, $slave;
   129 		push @slaves, $slave;
   104 
   132 
   105     @slaves = sort { $a->{'ring_position'} <=> $b->{'ring_position'} } @slaves;
   133     @slaves = sort { $a->{'ring_position'} <=> $b->{'ring_position'} } @slaves;
   106 
   134 
   107     print "EtherCAT bus listing for master $master_index:\n";
   135     print "EtherCAT bus listing for master $master_index:\n";
   108     for $slave (@slaves) {
   136     for $slave (@slaves) {
   109 		$abs = sprintf "%i", $slave->{'ring_position'};
   137 	print_line if $slave->{'coupler'} eq "yes";
   110 		printf(" %3s %8s  %-6s  %s\n",
   138 	$abs = sprintf "%i", $slave->{'ring_position'};
   111 			   $abs, $slave->{'advanced_position'},
   139 	printf(" %3s %8s  %-6s  %s\n",
   112 			   $slave->{'state'}, $slave->{'name'});
   140 	       $abs, $slave->{'advanced_position'},
       
   141 	       $slave->{'state'}, $slave->{'name'});
   113     }
   142     }
   114 }
   143 }
   115 
   144 
   116 #------------------------------------------------------------------------------
   145 #------------------------------------------------------------------------------
   117 
   146