Get I2C and hwmon attributes for hwmon entries

Find attributes in the MRW needed for the conf files.

Change-Id: I26754faa0ca66f265c054f44d36149041e06e458
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/hwmon.pl b/hwmon.pl
index 1baf104..fa09062 100755
--- a/hwmon.pl
+++ b/hwmon.pl
@@ -55,12 +55,68 @@
         my %entry;
         $entry{type} = I2C_TYPE;
         $entry{name} = lc $g_targetObj->getInstanceName($chip);
+        getHwmonAttributes(\@hwmonUnits, \%entry);
+        getI2CAttributes($i2c, \%entry);
 
         push @$hwmon, { %entry };
     }
 }
 
 
+#Reads the hwmon related attributes from the HWMON_FEATURE
+#complex attribute and adds them to the hash.
+sub getHwmonAttributes
+{
+    my ($units, $entry) = @_;
+    my %hwmonFeatures;
+
+    for my $unit (@$units) {
+
+        #The hwmon name, like 'in1', 'temp1', 'fan1', etc
+        my $hwmon = $g_targetObj->getAttributeField($unit,
+                                                    "HWMON_FEATURE",
+                                                    "HWMON_NAME");
+
+        #The useful name for this feature, like 'ambient'
+        my $name = $g_targetObj->getAttributeField($unit,
+                                                   "HWMON_FEATURE",
+                                                   "DESCRIPTIVE_NAME");
+        $hwmonFeatures{$hwmon}{label} = $name;
+
+        #Thresholds are optional, ignore if NA
+        my $warnHigh = $g_targetObj->getAttributeField($unit,
+                                                       "HWMON_FEATURE",
+                                                       "WARN_HIGH");
+        if (($warnHigh ne "") && ($warnHigh ne "NA")) {
+            $hwmonFeatures{$hwmon}{warnhigh} = $warnHigh;
+        }
+
+        my $warnLow = $g_targetObj->getAttributeField($unit,
+                                                      "HWMON_FEATURE",
+                                                      "WARN_LOW");
+        if (($warnLow ne "") && ($warnLow ne "NA")) {
+            $hwmonFeatures{$hwmon}{warnlow} = $warnLow;
+        }
+
+        my $critHigh = $g_targetObj->getAttributeField($unit,
+                                                       "HWMON_FEATURE",
+                                                       "CRIT_HIGH");
+        if (($critHigh ne "") && ($critHigh ne "NA")) {
+            $hwmonFeatures{$hwmon}{crithigh} = $critHigh;
+        }
+
+        my $critLow = $g_targetObj->getAttributeField($unit,
+                                                      "HWMON_FEATURE",
+                                                      "CRIT_LOW");
+        if (($critLow ne "") && ($critHigh ne "NA")) {
+            $hwmonFeatures{$hwmon}{critlow} = $critLow;
+        }
+    }
+
+    $entry->{hwmon} = { %hwmonFeatures };
+}
+
+
 #Reads the I2C attributes for the chip and adds them to the hash.
 #This includes the i2C address, and register base address and
 #offset for the I2C bus the chip is on.