Display pldmtool Fru & oem-ibm command output in JSON
./pldmtool fru GetFruRecordTableMetadata
{
"FRU DATAStructureTableIntegrityChecksum": 3870816131,
"FRUDATAMajorVersion": 1,
"FRUDATAMinorVersion": 0,
"FRUTableLength": 2005,
"FRUTableMaximumSize": 4294967295,
"Total number of Record Set Identifiers in table": 13,
"Total number of records in table": 33
}
./pldmtool oem-ibm GetAlertStatus -i 0x00
{
"pri cec node": "0x00008030",
"rack entry": "0xff000030"
}
./pldmtool oem-ibm GetFileTable
[
{
"FileHandle": "0",
"FileName": "PHYP-NVRAM",
"FileNameLength": 10,
"FileSize": 17870848,
"FileTraits": 1
},
{
"FileHandle": "1",
"FileName": "PHYP-NVRAM-CKSUM",
"FileNameLength": 16,
"FileSize": 16,
"FileTraits": 4
}
]
./pldmtool fru GetFruRecordTable
[
[
{
"FRU Record Set Identifier": 1,
"FRU Record Type": "General(1)",
"Number of FRU fields": 2,
"Encoding Type for FRU fields": "ASCII(1)"
},
{
"FRU Field Type": "Model(2)",
"FRU Field Length": 8,
"FRU Field Value": "9105-22A"
},
{
"FRU Field Type": "Serial Number(4)",
"FRU Field Length": 7,
"FRU Field Value": "SIMP10R"
}
],
...
...
...
...
...
[
{
"FRU Record Set Identifier": 13,
"FRU Record Type": "OEM(254)",
"Number of FRU fields": 1,
"Encoding Type for FRU fields": "ASCII(1)"
},
{
"FRU Field Type": "Location Code(254)",
"FRU Field Length": 24,
"FRU Field Value": "U78DA.ND1.1234567-P0-C23"
}
],
[
{
"FRU Record Set Identifier": 13,
"FRU Record Type": "General(1)",
"Number of FRU fields": 3,
"Encoding Type for FRU fields": "ASCII(1)"
},
{
"FRU Field Type": "Part Number(3)",
"FRU Field Length": 7,
"FRU Field Value": "PN12345"
},
{
"FRU Field Type": "Serial Number(4)",
"FRU Field Length": 12,
"FRU Field Value": "YL2E32010000"
},
{
"FRU Field Type": "Name(8)",
"FRU Field Length": 16,
"FRU Field Value": "CPU POWER CARD "
}
]
]
./pldmtool fru GetFRURecordByOption -i 3 -r 1 -f 3
[
[
{
"FRU Record Set Identifier": 3,
"FRU Record Type": "General(1)",
"Number of FRU fields": 1,
"Encoding Type for FRU fields": "ASCII(1)"
},
{
"FRU Field Type": "Part Number(3)",
"FRU Field Length": 7,
"FRU Field Value": "PN12345"
}
]
]
Change-Id: I1c5db56e5f336a0a1340ccd2ff8da5483a562cf8
Signed-off-by: Sridevi Ramesh <sridevra@in.ibm.com>
diff --git a/pldmtool/oem/ibm/pldm_oem_ibm.cpp b/pldmtool/oem/ibm/pldm_oem_ibm.cpp
index 2cea225..4773f8a 100644
--- a/pldmtool/oem/ibm/pldm_oem_ibm.cpp
+++ b/pldmtool/oem/ibm/pldm_oem_ibm.cpp
@@ -76,11 +76,16 @@
return;
}
- std::cout << "GetAlertStatus Success: " << std::endl;
- std::cout << "rack entry: 0x" << std::setfill('0') << std::setw(8)
- << std::hex << (int)rack_entry << std::endl;
- std::cout << "pri cec node: 0x" << std::setfill('0') << std::setw(8)
- << std::hex << (int)pri_cec_node << std::endl;
+ std::stringstream re;
+ std::stringstream pcn;
+ ordered_json data;
+ re << "0x" << std::setfill('0') << std::setw(8) << std::hex
+ << (int)rack_entry;
+ pcn << "0x" << std::setfill('0') << std::setw(8) << std::hex
+ << (int)pri_cec_node;
+ data["rack entry"] = re.str();
+ data["pri cec node"] = pcn.str();
+ pldmtool::helper::DisplayInJson(data);
}
private:
@@ -164,31 +169,35 @@
auto startptr = data;
auto endptr = startptr + length - CHKSUM_PADDING;
+ ordered_json kwVal;
while (startptr < endptr)
{
+ ordered_json fdata;
auto filetableData =
reinterpret_cast<pldm_file_attr_table_entry*>(startptr);
- std::cout << "FileHandle:" << filetableData->file_handle
- << std::endl;
+ fdata["FileHandle"] = std::to_string(filetableData->file_handle);
startptr += sizeof(filetableData->file_handle);
auto nameLength = filetableData->file_name_length;
- std::cout << " FileNameLength:" << nameLength << std::endl;
+ fdata["FileNameLength"] = nameLength;
startptr += sizeof(filetableData->file_name_length);
- std::cout << " FileName:" << startptr << std::endl;
+ fdata["FileName"] = (std::string(
+ reinterpret_cast<char const*>(startptr), nameLength));
startptr += nameLength;
auto fileSize = *(reinterpret_cast<uint32_t*>(startptr));
- std::cout << " FileSize:" << le32toh(fileSize) << std::endl;
+ fdata["FileSize"] = le32toh(fileSize);
startptr += sizeof(fileSize);
auto fileTraits =
(*(reinterpret_cast<bitfield32_t*>(startptr))).value;
- std::cout << " FileTraits:" << le32toh(fileTraits) << std::endl;
+ fdata["FileTraits"] = le32toh(fileTraits);
startptr += sizeof(fileTraits);
+ kwVal.emplace_back(fdata);
}
+ pldmtool::helper::DisplayInJson(kwVal);
}
};
diff --git a/pldmtool/pldm_fru_cmd.cpp b/pldmtool/pldm_fru_cmd.cpp
index 6dda65c..8c466b1 100644
--- a/pldmtool/pldm_fru_cmd.cpp
+++ b/pldmtool/pldm_fru_cmd.cpp
@@ -67,19 +67,18 @@
<< "rc=" << rc << ",cc=" << (int)cc << std::endl;
return;
}
- std::cout << "FRUDATAMajorVersion : "
- << static_cast<uint32_t>(fru_data_major_version) << std::endl;
- std::cout << "FRUDATAMinorVersion : "
- << static_cast<uint32_t>(fru_data_minor_version) << std::endl;
- std::cout << "FRUTableMaximumSize : " << fru_table_maximum_size
- << std::endl;
- std::cout << "FRUTableLength : " << fru_table_length << std::endl;
- std::cout << "Total number of Record Set Identifiers in table : "
- << total_record_set_identifiers << std::endl;
- std::cout << "Total number of records in table : "
- << total_table_records << std::endl;
- std::cout << "FRU DATAStructureTableIntegrityChecksum : " << checksum
- << std::endl;
+ ordered_json output;
+ output["FRUDATAMajorVersion"] =
+ static_cast<uint32_t>(fru_data_major_version);
+ output["FRUDATAMinorVersion"] =
+ static_cast<uint32_t>(fru_data_minor_version);
+ output["FRUTableMaximumSize"] = fru_table_maximum_size;
+ output["FRUTableLength"] = fru_table_length;
+ output["Total number of Record Set Identifiers in table"] =
+ total_record_set_identifiers;
+ output["Total number of records in table"] = total_table_records;
+ output["FRU DATAStructureTableIntegrityChecksum"] = checksum;
+ pldmtool::helper::DisplayInJson(output);
}
};
@@ -93,20 +92,19 @@
void print()
{
auto p = table;
+ ordered_json frutable;
+ ordered_json output;
while (!isTableEnd(p))
{
auto record =
reinterpret_cast<const pldm_fru_record_data_format*>(p);
- std::cout << "FRU Record Set Identifier: "
- << (int)le16toh(record->record_set_id) << std::endl;
- std::cout << "FRU Record Type: "
- << typeToString(fruRecordTypes, record->record_type)
- << std::endl;
- std::cout << "Number of FRU fields: " << (int)record->num_fru_fields
- << std::endl;
- std::cout << "Encoding Type for FRU fields: "
- << typeToString(fruEncodingType, record->encoding_type)
- << std::endl;
+ output["FRU Record Set Identifier"] =
+ (int)le16toh(record->record_set_id);
+ output["FRU Record Type"] =
+ typeToString(fruRecordTypes, record->record_type);
+ output["Number of FRU fields"] = (int)record->num_fru_fields;
+ output["Encoding Type for FRU fields"] =
+ typeToString(fruEncodingType, record->encoding_type);
p += sizeof(pldm_fru_record_data_format) -
sizeof(pldm_fru_record_tlv);
@@ -115,6 +113,9 @@
std::map<uint8_t, std::string> FruFieldTypeMap;
std::string fruFieldValue;
+ ordered_json frudata;
+ ordered_json frufielddata;
+ frufielddata.emplace_back(output);
for (int i = 0; i < record->num_fru_fields; i++)
{
auto tlv = reinterpret_cast<const pldm_fru_record_tlv*>(p);
@@ -174,17 +175,16 @@
fruFieldValuestring(tlv->value, tlv->length);
}
- std::cout << "\tFRU Field Type: "
- << typeToString(FruFieldTypeMap, tlv->type)
- << std::endl;
- std::cout << "\tFRU Field Length: " << (int)(tlv->length)
- << std::endl;
- std::cout << "\tFRU Field Value: " << fruFieldValue
- << std::endl;
-
+ frudata["FRU Field Type"] =
+ typeToString(FruFieldTypeMap, tlv->type);
+ frudata["FRU Field Length"] = (int)(tlv->length);
+ frudata["FRU Field Value"] = fruFieldValue;
+ frufielddata.emplace_back(frudata);
p += sizeof(pldm_fru_record_tlv) - 1 + tlv->length;
}
+ frutable.emplace_back(frufielddata);
}
+ pldmtool::helper::DisplayInJson(frutable);
}
private: