Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
authorFlorian Pose <fp@igh-essen.com>
Fri, 08 Dec 2006 11:52:33 +0000
changeset 499 fb005e975181
parent 498 fbf44b0d6b54
child 500 f9e6d119463f
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
master/slave.c
master/slave.h
script/lsec.pl
--- a/master/slave.c	Fri Dec 08 11:49:47 2006 +0000
+++ b/master/slave.c	Fri Dec 08 11:52:33 2006 +0000
@@ -145,6 +145,7 @@
     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 @@
     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 @@
                    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++) {
--- a/master/slave.h	Fri Dec 08 11:49:47 2006 +0000
+++ b/master/slave.h	Fri Dec 08 11:52:33 2006 +0000
@@ -244,6 +244,7 @@
     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 */
--- a/script/lsec.pl	Fri Dec 08 11:49:47 2006 +0000
+++ b/script/lsec.pl	Fri Dec 08 11:52:33 2006 +0000
@@ -106,6 +106,9 @@
 			elsif ($line =~ /^Coupler: ([a-z]+)$/) {
 				$slave->{'coupler'} = $1;
 			}
+			elsif ($line =~ /^Current consumption: (-?\d+) mA$/) {
+				$slave->{'current'} = $1;
+			}
 		}
 
 		close INFO;
@@ -124,12 +127,32 @@
 	$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 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 @@
     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;