Sridevi Ramesh | d448975 | 2019-12-08 09:03:29 -0600 | [diff] [blame] | 1 | #include "pldm_fru_cmd.hpp" |
| 2 | |
| 3 | #include "pldm_cmd_helper.hpp" |
| 4 | |
| 5 | namespace pldmtool |
| 6 | { |
| 7 | |
| 8 | namespace fru |
| 9 | { |
| 10 | |
| 11 | namespace |
| 12 | { |
| 13 | |
| 14 | using namespace pldmtool::helper; |
| 15 | |
| 16 | std::vector<std::unique_ptr<CommandInterface>> commands; |
| 17 | |
| 18 | } // namespace |
| 19 | |
| 20 | class GetFruRecordTableMetadata : public CommandInterface |
| 21 | { |
| 22 | public: |
| 23 | ~GetFruRecordTableMetadata() = default; |
| 24 | GetFruRecordTableMetadata() = delete; |
| 25 | GetFruRecordTableMetadata(const GetFruRecordTableMetadata&) = delete; |
| 26 | GetFruRecordTableMetadata(GetFruRecordTableMetadata&&) = default; |
| 27 | GetFruRecordTableMetadata& |
| 28 | operator=(const GetFruRecordTableMetadata&) = delete; |
| 29 | GetFruRecordTableMetadata& operator=(GetFruRecordTableMetadata&&) = default; |
| 30 | |
| 31 | using CommandInterface::CommandInterface; |
| 32 | |
| 33 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 34 | { |
| 35 | std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr)); |
| 36 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 37 | |
Pavithra Barithaya | ac3c45a | 2020-03-05 02:28:26 -0600 | [diff] [blame] | 38 | auto rc = encode_get_fru_record_table_metadata_req(instanceId, request); |
Sridevi Ramesh | d448975 | 2019-12-08 09:03:29 -0600 | [diff] [blame] | 39 | return {rc, requestMsg}; |
| 40 | } |
| 41 | |
| 42 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
| 43 | { |
| 44 | uint8_t cc = 0; |
| 45 | uint8_t fru_data_major_version, fru_data_minor_version; |
| 46 | uint32_t fru_table_maximum_size, fru_table_length; |
| 47 | uint16_t total_record_set_identifiers, total_table_records; |
| 48 | uint32_t checksum; |
| 49 | |
| 50 | auto rc = decode_get_fru_record_table_metadata_resp( |
| 51 | responsePtr, payloadLength, &cc, &fru_data_major_version, |
| 52 | &fru_data_minor_version, &fru_table_maximum_size, &fru_table_length, |
| 53 | &total_record_set_identifiers, &total_table_records, &checksum); |
| 54 | if (rc != PLDM_SUCCESS || cc != PLDM_SUCCESS) |
| 55 | { |
| 56 | std::cerr << "Response Message Error: " |
| 57 | << "rc=" << rc << ",cc=" << (int)cc << std::endl; |
| 58 | return; |
| 59 | } |
Sridevi Ramesh | d448975 | 2019-12-08 09:03:29 -0600 | [diff] [blame] | 60 | std::cout << "FRUDATAMajorVersion : " |
| 61 | << static_cast<uint32_t>(fru_data_major_version) << std::endl; |
| 62 | std::cout << "FRUDATAMinorVersion : " |
| 63 | << static_cast<uint32_t>(fru_data_minor_version) << std::endl; |
| 64 | std::cout << "FRUTableMaximumSize : " << fru_table_maximum_size |
| 65 | << std::endl; |
| 66 | std::cout << "FRUTableLength : " << fru_table_length << std::endl; |
| 67 | std::cout << "Total number of Record Set Identifiers in table : " |
| 68 | << total_record_set_identifiers << std::endl; |
| 69 | std::cout << "Total number of records in table : " |
| 70 | << total_table_records << std::endl; |
| 71 | std::cout << "FRU DATAStructureTableIntegrityChecksum : " << checksum |
| 72 | << std::endl; |
| 73 | } |
| 74 | }; |
| 75 | |
| 76 | void registerCommand(CLI::App& app) |
| 77 | { |
| 78 | auto fru = app.add_subcommand("fru", "FRU type command"); |
| 79 | fru->require_subcommand(1); |
| 80 | auto getFruRecordTableMetadata = fru->add_subcommand( |
| 81 | "GetFruRecordTableMetadata", "get FRU record table metadata"); |
| 82 | commands.push_back(std::make_unique<GetFruRecordTableMetadata>( |
| 83 | "fru", "GetFruRecordTableMetadata", getFruRecordTableMetadata)); |
| 84 | } |
| 85 | |
| 86 | } // namespace fru |
| 87 | |
| 88 | } // namespace pldmtool |