script/lsec
author Florian Pose <fp@igh-essen.com>
Mon, 05 Mar 2007 15:50:30 +0000
changeset 616 b777e26367c5
parent 576 158c5a3d0a2a
child 643 78929d878b2c
permissions -rwxr-xr-x
Added PDO mapping FSM graph.
563
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
#!/usr/bin/perl
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
#------------------------------------------------------------------------------
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
#
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
#  l s e c  -  List EtherCAT
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
#
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
#  Userspace tool for listing EtherCAT slaves.
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
#
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
#  $Id$
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
#
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
#  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
#
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
#  This file is part of the IgH EtherCAT Master.
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
#
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
#  The IgH EtherCAT Master is free software; you can redistribute it
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
#  and/or modify it under the terms of the GNU General Public License
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
#  as published by the Free Software Foundation; either version 2 of the
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
#  License, or (at your option) any later version.
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
#
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
#  The IgH EtherCAT Master is distributed in the hope that it will be
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
#  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
#  GNU General Public License for more details.
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
#
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
#  You should have received a copy of the GNU General Public License
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
#  along with the IgH EtherCAT Master; if not, write to the Free Software
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
#
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
#  The right to use EtherCAT Technology is granted and comes free of
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
#  charge under condition of compatibility of product made by
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
#  Licensee. People intending to distribute/sell products based on the
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
#  code, have to sign an agreement to guarantee that products using
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
#  software based on IgH EtherCAT master stay compatible with the actual
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
#  EtherCAT specification (which are released themselves as an open
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
#  standard) as the (only) precondition to have the right to use EtherCAT
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
#  Technology, IP and trade marks.
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
#------------------------------------------------------------------------------
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
require 'sys/ioctl.ph';
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
use strict;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
use Getopt::Std;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
my %opt;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
my $master_index;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
my $term_width;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
#------------------------------------------------------------------------------
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
$term_width = &get_terminal_width;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
&get_options;
576
158c5a3d0a2a New module file /sys/ethercat, masters moved to /sys/ethercat/masterX.
Florian Pose <fp@igh-essen.com>
parents: 563
diff changeset
    53
&query;
563
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
exit 0;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
#------------------------------------------------------------------------------
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
576
158c5a3d0a2a New module file /sys/ethercat, masters moved to /sys/ethercat/masterX.
Florian Pose <fp@igh-essen.com>
parents: 563
diff changeset
    58
sub query
158c5a3d0a2a New module file /sys/ethercat, masters moved to /sys/ethercat/masterX.
Florian Pose <fp@igh-essen.com>
parents: 563
diff changeset
    59
{
158c5a3d0a2a New module file /sys/ethercat, masters moved to /sys/ethercat/masterX.
Florian Pose <fp@igh-essen.com>
parents: 563
diff changeset
    60
    my $master_dir;
563
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
    my $dirhandle;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
    my $entry;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
    my @slaves;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
    my $slave;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
    my $abs;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
    my $line;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
    my $ring_cols;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
    my $adv_cols;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
    my $fmt;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
    my $cols;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
576
158c5a3d0a2a New module file /sys/ethercat, masters moved to /sys/ethercat/masterX.
Florian Pose <fp@igh-essen.com>
parents: 563
diff changeset
    72
    $master_dir = "/sys/ethercat/master" . $master_index;
158c5a3d0a2a New module file /sys/ethercat, masters moved to /sys/ethercat/masterX.
Florian Pose <fp@igh-essen.com>
parents: 563
diff changeset
    73
563
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
    unless (opendir $dirhandle, $master_dir) {
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
		print "Failed to open directory \"$master_dir\".\n";
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
		exit 1;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
    }
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
    while ($entry = readdir $dirhandle) {
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
        next unless $entry =~ /^slave(\d+)$/;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
		$slave = {};
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
		open INFO, "$master_dir/$entry/info" or die
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
			"ERROR: Failed to open $master_dir/$entry/info";
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
		while ($line = <INFO>) {
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
			if ($line =~ /^Name: (.*)$/) {
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
				$slave->{'name'} = $1;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
			}
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
			elsif ($line =~ /^Ring position: (\d+)$/) {
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
				$slave->{'ring_position'} = $1;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
			}
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
			elsif ($line =~ /^Advanced position: (\d+:\d+)$/) {
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
				$slave->{'advanced_position'} = $1;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
			}
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
			elsif ($line =~ /^State: (.+) /) {
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
				$slave->{'state'} = $1;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
			}
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
			elsif ($line =~ /^Coupler: ([a-z]+)$/) {
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
				$slave->{'coupler'} = $1;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
			}
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
			elsif ($line =~ /^Current consumption: (-?\d+) mA$/) {
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
				$slave->{'current'} = $1;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
			}
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
		}
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
		close INFO;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
		push @slaves, $slave;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
    }
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
    closedir $dirhandle;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
    @slaves = sort { $a->{'ring_position'} <=> $b->{'ring_position'} } @slaves;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
    $ring_cols = 0;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
    $adv_cols = 0;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
    for $slave (@slaves) {
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
	$cols = length $slave->{'ring_position'};
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
	$ring_cols = $cols if ($cols > $ring_cols);
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
	$cols = length $slave->{'advanced_position'};
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
	$adv_cols = $cols if ($cols > $adv_cols);
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
    }
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
    if (defined $opt{'c'}) { # display power consumtion
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
	$fmt = sprintf " %%%is  %%-%is  %%6i  %%6i  %%s\n",
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
	    $ring_cols, $adv_cols;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
	my $current_sum = 0;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
	for $slave (@slaves) {
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
	    if ($slave->{'coupler'} eq "yes") {
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
		&print_line if !defined $opt{n};
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
		$current_sum = 0; # reset current sum
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
	    }
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
	    $current_sum -= $slave->{'current'};
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
	    printf($fmt, $slave->{'ring_position'},
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
		   $slave->{'advanced_position'}, $slave->{'current'},
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
		   $current_sum, $slave->{'name'});
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
	}
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
    }
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
    else {
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
	$fmt = sprintf " %%%is  %%-%is  %%-6s  %%s\n", $ring_cols, $adv_cols;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
	for $slave (@slaves) {
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
	    &print_line if $slave->{'coupler'} eq "yes" and !defined $opt{n};
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
	    printf($fmt, $slave->{'ring_position'},
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
		   $slave->{'advanced_position'}, $slave->{'state'},
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
		   $slave->{'name'});
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
	}
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
    }
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
}
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
#------------------------------------------------------------------------------
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
sub get_options
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
{
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
    my $optret = getopts "m:cnh", \%opt;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
    &print_usage if defined $opt{h} or $#ARGV > -1 or !$optret;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
    if (defined $opt{m}) {
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
	$master_index = $opt{m};
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
    }
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
    else {
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
	$master_index = 0;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
    }
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
}
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
#------------------------------------------------------------------------------
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
sub print_usage
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
{
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
    my $cmd = `basename $0`;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
    chomp $cmd;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
    print "Usage: $cmd [OPTIONS]\n";
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
    print "        -m <IDX>    Query master <IDX>.\n";
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
    print "        -c          Display current [mA] ";
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
    print "(3: consumption, 4: remaining).\n";
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
    print "        -n          Display no coupler lines.\n";
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
    print "        -h          Show this help.\n";
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
    exit 0;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
}
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
#------------------------------------------------------------------------------
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
sub get_terminal_width
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
{
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
    my $winsize;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
    die "no TIOCGWINSZ " unless defined &TIOCGWINSZ;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
    open(TTY, "+</dev/tty") or die "No tty: $!";
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
    unless (ioctl(TTY, &TIOCGWINSZ, $winsize='')) {
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
	die sprintf "$0: ioctl TIOCGWINSZ (%08x: $!)\n", &TIOCGWINSZ;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
    }
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
    (my $row, my $col, my $xpixel, my $ypixel) = unpack('S4', $winsize);
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
    return $col;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
}
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
#------------------------------------------------------------------------------
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
sub print_line
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
{
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
    for (my $i = 0; $i < $term_width; $i++) {print "-";}
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
    print "\n";
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
}
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
#------------------------------------------------------------------------------