sensor: Add metadata for sensor to handle SDR commands

a) Entity ID is read from the MRW for each sensor populated in yaml.
b) Entity instance is populated for corresponding entity ID.
c) Sensor name pattern is read from the config yaml.

Change-Id: I933650f9c99f79ee60d5513cf7ff9b7f6b14b768
Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
diff --git a/gen_ipmi_sensor.pl b/gen_ipmi_sensor.pl
index 30fc226..84b00c8 100755
--- a/gen_ipmi_sensor.pl
+++ b/gen_ipmi_sensor.pl
@@ -41,6 +41,7 @@
 
 my @interestedTypes = keys %{$sensorTypeConfig};
 my %types;
+my %entityDict;
 
 @types{@interestedTypes} = ();
 
@@ -54,6 +55,8 @@
     my $path = '';
     my $obmcPath = '';
     my $sensorName = '';
+    my $entityID = '';
+    my $entityInstance = '';
 
     if ($targetObj->getTargetType($target) eq "unit-ipmi-sensor") {
 
@@ -61,6 +64,17 @@
         #not interested in this sensortype
         next if (not exists $types{$sensorName});
 
+        $entityID = $targetObj->getAttribute($target, "IPMI_ENTITY_ID");
+        if (exists ($entityDict{$entityID}))
+        {
+            $entityDict{$entityID}++;
+        }
+        else
+        {
+            $entityDict{$entityID} = '1';
+        }
+        $entityInstance = $entityDict{$entityID};
+
         $sensorID = $targetObj->getAttribute($target, "IPMI_SENSOR_ID");
 
         $sensorType = hex($targetObj->getAttribute($target,
@@ -101,11 +115,15 @@
         my $serviceInterface =
             $sensorTypeConfig->{$sensorName}->{"serviceInterface"};
         my $readingType = $sensorTypeConfig->{$sensorName}->{"readingType"};
+        my $sensorNamePattern = $sensorTypeConfig->{$sensorName}->{"sensorNamePattern"};
 
-        printDebug("$sensorID : $sensorName : $sensorType : $sensorReadingType :$obmcPath \n");
+        my $debug = "$sensorID : $sensorName : $sensorType : ";
+        $debug .= "$sensorReadingType : $entityID : $entityInstance : ";
+        $debug .= "$obmcPath \n";
+        printDebug("$debug");
 
         writeToFile($sensorName,$sensorType,$sensorReadingType,$obmcPath,$serviceInterface,
-            $readingType,$sensorTypeConfig,$fh);
+            $readingType,$sensorTypeConfig,$entityID,$entityInstance,$sensorNamePattern,$fh);
 
     }
 
@@ -119,14 +137,18 @@
 sub writeToFile
 {
     my ($sensorName,$sensorType,$sensorReadingType,$path,$serviceInterface,
-        $readingType,$sensorTypeConfig,$fh) = @_;
+        $readingType,$sensorTypeConfig,$entityID,$entityInstance,
+        $sensorNamePattern,$fh) = @_;
 
+    print $fh "  entityID: ".$entityID."\n";
+    print $fh "  entityInstance: ".$entityInstance."\n";
     print $fh "  sensorType: ".$sensorType."\n";
     print $fh "  path: ".$path."\n";
 
     print $fh "  sensorReadingType: ".$sensorReadingType."\n";
     print $fh "  serviceInterface: ".$serviceInterface."\n";
     print $fh "  readingType: ".$readingType."\n";
+    print $fh "  sensorNamePattern: ".$sensorNamePattern."\n";
     print $fh "  interfaces:"."\n";
 
     my $interfaces = $sensorTypeConfig->{$sensorName}->{"interfaces"};