diff options
author | Ratan Gupta <ratagupt@in.ibm.com> | 2017-02-22 18:16:23 +0530 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2017-03-09 19:19:15 +0000 |
commit | 39747a03af01f5a9aedc54accbbb319747f6dfcb (patch) | |
tree | fc22af946ba7ceee9c9fca1455dbe8527085d3dd | |
parent | c736670674c931860d1c2fa1ca940c9d4557ebbf (diff) | |
download | phosphor-mrw-tools-39747a03af01f5a9aedc54accbbb319747f6dfcb.tar.gz phosphor-mrw-tools-39747a03af01f5a9aedc54accbbb319747f6dfcb.zip |
gen_ipmi_sensor.pl: construct sensor metadata
Generates a file to depict which dbus properties are implemented for a
sensor, and how IPMI sensor data map to those dbus properties.
This commit defines a YAML file which helps figure out the supported
dbus interface/properties for a sensor and how to get the sensor value.
Change-Id: I62ddd3b8546cd036663708c5aa6041523e399e4f
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
-rwxr-xr-x | gen_ipmi_sensor.pl | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/gen_ipmi_sensor.pl b/gen_ipmi_sensor.pl index fd91e6b..742da9b 100755 --- a/gen_ipmi_sensor.pl +++ b/gen_ipmi_sensor.pl @@ -11,17 +11,19 @@ use YAML::Tiny qw(LoadFile); # Globals my $serverwizFile = ""; my $debug = 0; +my $outputFile = ""; my $metaDataFile = ""; # Command line argument parsing GetOptions( "i=s" => \$serverwizFile, # string "m=s" => \$metaDataFile, # string +"o=s" => \$outputFile, # string "d" => \$debug, ) or printUsage(); -if (($serverwizFile eq "") or ($metaDataFile eq "")) +if (($serverwizFile eq "") or ($outputFile eq "") or ($metaDataFile eq "")) { printUsage(); } @@ -31,7 +33,10 @@ $targetObj->loadXML($serverwizFile); #open the mrw xml and the metaData file for the sensor. #Fetch the sensorid,sensortype,class,object path from the mrw. +#Get the metadata for that sensor from the metadata file. +#Merge the data into the outputfile +open(my $fh, '>', $outputFile) or die "Could not open file '$outputFile' $!"; my $sensorTypeConfig = LoadFile($metaDataFile); my @interestedTypes = keys %{$sensorTypeConfig}; @@ -61,12 +66,13 @@ foreach my $target (sort keys %{$targetObj->getAllTargets()}) $path = $targetObj->getAttribute($target, "INSTANCE_PATH"); #not interested in this sensortype - next if (not exists $types{$sensorType} ); + next if (not exists $types{$sensorType}); #if there is ipmi sensor without sensorid or sensorReadingType or #Instance path then die if ($sensorID eq '' or $sensorReadingType eq '' or $path eq '') { + close $fh; die("sensor without info for target=$target"); } @@ -77,20 +83,57 @@ foreach my $target (sort keys %{$targetObj->getAllTargets()}) #if unable to get the obmc path then die if (not defined $obmcPath) { + close $fh; die("Unable to get the obmc path for path=$path"); } + print $fh $sensorID.":\n"; + printDebug("$sensorID : $sensorType : $sensorReadingType :$obmcPath \n"); + writeToFile($sensorType,$sensorReadingType,$obmcPath,$sensorTypeConfig,$fh); + } } +close $fh; + + +#Get the metadata for the incoming sensortype from the loaded config file. +#Write the sensor data into the output file + +sub writeToFile +{ + my ($sensorType,$sensorReadingType,$path,$sensorTypeConfig,$fh) = @_; + print $fh " sensorType: ".$sensorType."\n"; + print $fh " path: ".$path."\n"; + print $fh " sensorReadingType: ".$sensorReadingType."\n"; + print $fh " interfaces:"."\n"; + + my $interfaces = $sensorTypeConfig->{$sensorType}; + #Walk over all the interfces as it needs to be written + while (my ($interface,$properties) = each %{$interfaces}) { + print $fh " ".$interface.":\n"; + #walk over all the properties as it needs to be written + while (my ($dbusProperty,$dbusPropertyValue) = each %{$properties}) { + #will write property named "Property" first then + #other properties. + print $fh " ".$dbusProperty.":\n"; + while (my ( $offset,$values) = each %{$dbusPropertyValue}) { + print $fh " $offset:\n"; + while (my ( $key,$value) = each %{$values}) { + print $fh " $key: ". $value."\n"; + } + } + } + } +} # Usage sub printUsage { print " - $0 -i [MRW filename] -m [SensorMetaData filename] [OPTIONS] + $0 -i [MRW filename] -m [SensorMetaData filename] -o [Output filename] [OPTIONS] Options: -d = debug mode \n"; @@ -103,4 +146,3 @@ sub printDebug my $str = shift; print "DEBUG: ", $str, "\n" if $debug; } - |