Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.

This commit is contained in:
Florian Pose 2006-12-08 11:52:33 +00:00
parent 4357e80e22
commit b00258a4d8
3 changed files with 38 additions and 7 deletions

View File

@ -145,6 +145,7 @@ int ec_slave_init(ec_slave_t *slave, /**< EtherCAT slave */
slave->sii_image = NULL;
slave->sii_order = NULL;
slave->sii_name = NULL;
slave->sii_current_on_ebus = 0;
INIT_LIST_HEAD(&slave->sii_strings);
INIT_LIST_HEAD(&slave->sii_syncs);
@ -398,6 +399,8 @@ void ec_slave_fetch_general(ec_slave_t *slave, /**< EtherCAT slave */
for (i = 0; i < 4; i++)
slave->sii_physical_layer[i] =
(data[4] & (0x03 << (i * 2))) >> (i * 2);
slave->sii_current_on_ebus = EC_READ_S16(data + 0x0C);
}
/*****************************************************************************/
@ -636,8 +639,10 @@ size_t ec_slave_info(const ec_slave_t *slave, /**< EtherCAT slave */
slave->ring_position);
off += sprintf(buffer + off, "Advanced position: %i:%i\n",
slave->coupler_index, slave->coupler_subindex);
off += sprintf(buffer + off, "Coupler: %s\n\n",
off += sprintf(buffer + off, "Coupler: %s\n",
ec_slave_is_coupler(slave) ? "yes" : "no");
off += sprintf(buffer + off, "Current consumption: %i mA\n\n",
slave->sii_current_on_ebus);
off += sprintf(buffer + off, "Data link status:\n");
for (i = 0; i < 4; i++) {

View File

@ -244,6 +244,7 @@ struct ec_slave
char *sii_image; /**< slave image name acc. to EEPROM */
char *sii_order; /**< slave order number acc. to EEPROM */
char *sii_name; /**< slave name acc. to EEPROM */
int16_t sii_current_on_ebus; /**< power consumption */
ec_fmmu_t fmmus[EC_MAX_FMMUS]; /**< FMMU configurations */
uint8_t fmmu_count; /**< number of FMMUs used */

View File

@ -106,6 +106,9 @@ sub query_slaves
elsif ($line =~ /^Coupler: ([a-z]+)$/) {
$slave->{'coupler'} = $1;
}
elsif ($line =~ /^Current consumption: (-?\d+) mA$/) {
$slave->{'current'} = $1;
}
}
close INFO;
@ -124,12 +127,32 @@ sub query_slaves
$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'});
if (defined $opt{'c'}) { # display power consumtion
$fmt = sprintf " %%%is %%-%is %%6i %%6i %%s\n",
$ring_cols, $adv_cols;
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'});
}
}
else {
$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'});
}
}
}
@ -137,7 +160,7 @@ sub query_slaves
sub get_options
{
my $optret = getopts "m:nh", \%opt;
my $optret = getopts "m:cnh", \%opt;
&print_usage if defined $opt{h} or $#ARGV > -1 or !$optret;
@ -157,6 +180,8 @@ sub print_usage
chomp $cmd;
print "Usage: $cmd [OPTIONS]\n";
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 " -h Show this help.\n";
exit 0;