pldmtool: Fix display format of attribute value
4dd11a7 changed the display format of attribute value
entry unexpectedly. This change change the display format
to the same as before
Tested:
GetBIOSTable:
root@fp5280g2:/tmp# ./pldmtool bios GetBIOSTable -t 2
PLDM AttributeValueTable:
AttributeHandle: 0
AttributeType: BIOSString
CurrentStringLength: 12
CurrentString: powersupply0
AttributeHandle: 1
AttributeType: BIOSStringReadOnly
CurrentStringLength: 2
CurrentString: ef
AttributeHandle: 2
AttributeType: BIOSInteger
CurrentValue: 0
AttributeHandle: 3
AttributeType: BIOSEnumeration
NumberOfCurrentValues: 1
CurrentValueStringHandleIndex[0] = 1, StringHandle = Off
AttributeHandle: 4
AttributeType: BIOSEnumerationReadOnly
NumberOfCurrentValues: 1
CurrentValueStringHandleIndex[0] = 0, StringHandle = Concurrent
GetBIOSAttributeCurrentValueByHandle:
root@fp5280g2:/tmp# ./pldmtool bios getbiosattributeCurrentValueByHandle -a Led
CurrentValue: On
root@fp5280g2:/tmp# ./pldmtool bios getbiosattributeCurrentValueByHandle -a Model
CurrentValue: powersupply0
Signed-off-by: John Wang <wangzqbj@inspur.com>
Change-Id: I1b6cde16e216ff11f02661454bc74de684392021
diff --git a/tool/pldm_bios_cmd.cpp b/tool/pldm_bios_cmd.cpp
index e655ea3..823648b 100644
--- a/tool/pldm_bios_cmd.cpp
+++ b/tool/pldm_bios_cmd.cpp
@@ -249,7 +249,6 @@
stringTable.data(), stringTable.size(), name.c_str());
if (stringEntry == nullptr)
{
- std::cout << "StringTable initialize failed" << std::endl;
return nullptr;
}
@@ -345,13 +344,19 @@
void displayAttributeValueEntry(
const pldm_bios_attr_val_table_entry* tableEntry,
const std::optional<Table>& attrTable,
- const std::optional<Table>& stringTable)
+ const std::optional<Table>& stringTable, bool verbose)
{
auto attrHandle =
pldm_bios_table_attr_value_entry_decode_attribute_handle(
tableEntry);
auto attrType = static_cast<pldm_bios_attribute_type>(
pldm_bios_table_attr_value_entry_decode_attribute_type(tableEntry));
+ if (verbose)
+ {
+ std::cout << "AttributeHandle: " << attrHandle << std::endl;
+ std::cout << "\tAttributeType: " << attrTypeMap.at(attrType)
+ << std::endl;
+ }
switch (attrType)
{
case PLDM_BIOS_ENUMERATION:
@@ -363,12 +368,30 @@
std::vector<uint8_t> handles(count);
pldm_bios_table_attr_value_entry_enum_decode_handles(
tableEntry, handles.data(), handles.size());
+ if (verbose)
+ {
+ std::cout << "\tNumberOfCurrentValues: " << (int)count
+ << std::endl;
+ }
for (size_t i = 0; i < handles.size(); i++)
{
- std::cout << "CurrentValue: "
- << displayEnumValueByIndex(attrHandle, handles[i],
- attrTable, stringTable)
- << std::endl;
+ if (verbose)
+ {
+ std::cout
+ << "\tCurrentValueStringHandleIndex[" << i
+ << "] = " << (int)handles[i] << ", StringHandle = "
+ << displayEnumValueByIndex(attrHandle, handles[i],
+ attrTable, stringTable)
+ << std::endl;
+ }
+ else
+ {
+ std::cout
+ << "CurrentValue: "
+ << displayEnumValueByIndex(attrHandle, handles[i],
+ attrTable, stringTable)
+ << std::endl;
+ }
}
break;
}
@@ -377,7 +400,14 @@
{
auto cv = pldm_bios_table_attr_value_entry_integer_decode_cv(
tableEntry);
- std::cout << "CurrentValue: " << cv << std::endl;
+ if (verbose)
+ {
+ std::cout << "\tCurrentValue: " << cv << std::endl;
+ }
+ else
+ {
+ std::cout << "CurrentValue: " << cv << std::endl;
+ }
break;
}
case PLDM_BIOS_STRING:
@@ -386,11 +416,25 @@
variable_field currentString;
pldm_bios_table_attr_value_entry_string_decode_string(
tableEntry, ¤tString);
- std::cout << "CurrentValue: "
- << std::string(reinterpret_cast<const char*>(
- currentString.ptr),
- currentString.length)
- << std::endl;
+ if (verbose)
+ {
+ std::cout
+ << "\tCurrentStringLength: " << currentString.length
+ << std::endl
+ << "\tCurrentString: "
+ << std::string(
+ reinterpret_cast<const char*>(currentString.ptr),
+ currentString.length)
+ << std::endl;
+ }
+ else
+ {
+ std::cout << "CurrentValue: "
+ << std::string(reinterpret_cast<const char*>(
+ currentString.ptr),
+ currentString.length)
+ << std::endl;
+ }
break;
}
@@ -601,7 +645,8 @@
for (auto tableEntry : BIOSTableIter<PLDM_BIOS_ATTR_VAL_TABLE>(
attrValTable->data(), attrValTable->size()))
{
- displayAttributeValueEntry(tableEntry, attrTable, stringTable);
+ displayAttributeValueEntry(tableEntry, attrTable, stringTable,
+ true);
}
}
};
@@ -683,7 +728,7 @@
reinterpret_cast<const struct pldm_bios_attr_val_table_entry*>(
attributeData.ptr);
- displayAttributeValueEntry(tableEntry, attrTable, stringTable);
+ displayAttributeValueEntry(tableEntry, attrTable, stringTable, false);
}
private: