From: Michael Gernoth Date: Sun, 8 Feb 2009 13:15:16 +0000 (+0100) Subject: show sensor values when boardstatus is requested X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/rsbs2/commitdiff_plain/661b5a0eabc3b2e85e20475cdfe60c702a83aa82 show sensor values when boardstatus is requested --- diff --git a/rsbs2.pl b/rsbs2.pl index 4d09c1b..43f4986 100755 --- a/rsbs2.pl +++ b/rsbs2.pl @@ -282,8 +282,8 @@ sub show_boarddesc { my @board = split(//, $boarddesc); foreach my $byte (@board) { printf ("0x%02x ", ord($byte)); -} -print "\n"; + } + print "\n"; } sub show_all_vars { @@ -378,16 +378,51 @@ sub syslog_debug { print "Debug messages will be sent to ${destination_ip} (broadcast: ${bcast})\n"; } -sub sensors { +sub get_sensors { my $slist= _cmd("sensorlist"); - my %sens = (); + my @sensors; if ($slist->{RC} ne '0x0') { print "Error getting sensorlist: ".$slist->{RC}."\n"; return; } + my $req = '0x1'; foreach my $s (@{$slist->{SENSORLIST}->{SENSOR}}) { + $req .= ''; + } + $req .= ''; + + my $sprop = _req($req); + foreach my $s (@{$sprop->{RESP}->{SENSORLIST}->{SENSOR}}) { + my $sensor = {}; + foreach my $sp (@{$s->{PROP}}) { + $sensor->{$sp->{NAME}} = $sp->{VAL}; + } + + next if (!defined($sensor->{NAME})); + $sensor->{VAL} = '0' if ($sensor->{VAL} eq ''); + push @sensors, $sensor; + } + @sensors; +} + +sub show_sensors { + my @sensors = get_sensors(); + + foreach my $sensor (@sensors) { + print $sensor->{NAME}.": ".$sensor->{VAL}.$sensor->{UNITS}." "; + + my @info = (); + foreach my $field qw(MIN MAX LOW_NON_CRITICAL UPPER_NON_CRITICAL LOW_CRITICAL UPPER_CRITICAL) { + if ($sensor->{$field} ne '') { + push @info, "${field}: ".$sensor->{$field}.$sensor->{UNITS}; + } + } + + print " (".join(", ",@info).")" if (@info); + + print "\n"; } } @@ -439,7 +474,7 @@ sub status { print "FW upgrade progress:\t${boardfwprogress}\n"; } print "\nSensors:\n"; - sensors(); + show_sensors(); } sub login {