blob: 4f14e8c9bbaab2a7908ba926e1925d7114df27fd [file] [log] [blame]
George Liu44073352020-03-12 14:00:13 +08001#include "pldm_host_cmd.hpp"
2
George Liu44073352020-03-12 14:00:13 +08003#include "oem/ibm/libpldm/host.h"
4
George Liu6492f522020-06-16 10:34:05 +08005#include "../../pldm_cmd_helper.hpp"
6
George Liu44073352020-03-12 14:00:13 +08007namespace pldmtool
8{
9
10namespace oem_ibm
11{
12namespace power_host
13{
14using namespace pldmtool::helper;
15
16std::vector<std::unique_ptr<CommandInterface>> commands;
17
18class GetAlertStatus : public CommandInterface
19{
20 public:
21 ~GetAlertStatus() = default;
22 GetAlertStatus() = delete;
23 GetAlertStatus(const GetAlertStatus&) = delete;
24 GetAlertStatus(GetAlertStatus&&) = default;
25 GetAlertStatus& operator=(const GetAlertStatus&) = delete;
26 GetAlertStatus& operator=(GetAlertStatus&&) = default;
27
28 explicit GetAlertStatus(const char* type, const char* name, CLI::App* app) :
29 CommandInterface(type, name, app)
30 {
31 app->add_option(
32 "-i, --id", versionId,
33 "Version of the command/response format. 0x00 for this format")
34 ->required();
35 }
36
37 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
38 {
39 std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) +
40 PLDM_GET_ALERT_STATUS_REQ_BYTES);
41 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
42
43 auto rc = encode_get_alert_status_req(instanceId, versionId, request,
44 PLDM_GET_ALERT_STATUS_REQ_BYTES);
45 return {rc, requestMsg};
46 }
47
48 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
49 {
50 uint8_t completionCode = 0;
51 uint32_t rack_entry = 0;
52 uint32_t pri_cec_node = 0;
53 auto rc = decode_get_alert_status_resp(responsePtr, payloadLength,
54 &completionCode, &rack_entry,
55 &pri_cec_node);
56
57 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
58 {
59 std::cerr << "Response Message Error: "
60 << "rc=" << rc << ",cc=" << (int)completionCode << "\n";
61 return;
62 }
63
64 std::cout << "GetAlertStatus Success: " << std::endl;
65 std::cout << "rack entry: 0x" << std::setfill('0') << std::setw(8)
66 << std::hex << (int)rack_entry << std::endl;
67 std::cout << "pri cec node: 0x" << std::setfill('0') << std::setw(8)
68 << std::hex << (int)pri_cec_node << std::endl;
69 }
70
71 private:
72 uint8_t versionId;
73};
74
75void registerCommand(CLI::App& app)
76{
77 auto oem_ibm = app.add_subcommand("oem-ibm", "oem type command");
78 oem_ibm->require_subcommand(1);
79
80 auto getAlertStatus = oem_ibm->add_subcommand(
81 "GetAlertStatus", "get alert status descriptor");
82 commands.push_back(std::make_unique<GetAlertStatus>(
83 "oem_ibm", "getAlertStatus", getAlertStatus));
84}
85} // namespace power_host
86} // namespace oem_ibm
87} // namespace pldmtool