Util: add getEnclosingFru
getEnclosingFru determines the nearest FRU enclosing a given Target.
Change-Id: I56533519c053171a98897a67368d1c1ba0d132b6
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
diff --git a/Util.pm b/Util.pm
index b9b2aef..050fee6 100644
--- a/Util.pm
+++ b/Util.pm
@@ -97,6 +97,31 @@
return $addr;
}
+#Return nearest FRU enclosing the input target
+# $targets = the Targets object
+# $targetName = the target name
+sub getEnclosingFru
+{
+ my ($targets, $targetName) = @_;
+
+ if (($targetName eq "") || (!defined $targetName))
+ {
+ return "";
+ }
+
+ if (!$targets->isBadAttribute($targetName, "RU_TYPE"))
+ {
+ my $ruType = $targets->getAttribute($targetName, "RU_TYPE");
+ if (($ruType eq "FRU") || ($ruType eq "CRU"))
+ {
+ return $targetName;
+ }
+ }
+
+ my $parent = $targets->getTargetParent($targetName);
+ return getEnclosingFru($targets, $parent);
+}
+
1;
=head1 NAME
@@ -134,6 +159,10 @@
Returns C<I2CAddress> converted from MRW format (8-bit) to the standard 7-bit
format.
+=item getEnclosingFru(C<TargetsObj>, C<Target>)
+
+Finds the nearest FRU enclosing the input Target.
+
=back
=cut