blob: 547955e2e9c733bbcfc2aaea9c3b74c5e3f0cde7 [file] [log] [blame]
Sridevi Ramesh98576432019-11-27 10:10:28 -06001#include "pldm_bios_cmd.hpp"
2
3#include "pldm_cmd_helper.hpp"
4
5#include <map>
6#include <memory>
7#include <string>
8#include <typeinfo>
9#include <vector>
10
11#include "libpldm/utils.h"
12
13namespace pldmtool
14{
15
16namespace bios
17{
18
19namespace
20{
21
22using namespace pldmtool::helper;
23
24std::vector<std::unique_ptr<CommandInterface>> commands;
25
26} // namespace
27
28class GetDateTime : public CommandInterface
29{
30 public:
31 ~GetDateTime() = default;
32 GetDateTime() = delete;
33 GetDateTime(const GetDateTime&) = delete;
34 GetDateTime(GetDateTime&&) = default;
35 GetDateTime& operator=(const GetDateTime&) = delete;
36 GetDateTime& operator=(GetDateTime&&) = default;
37
38 using CommandInterface::CommandInterface;
39
40 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
41 {
42 std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr));
43 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
44
45 auto rc = encode_get_date_time_req(PLDM_LOCAL_INSTANCE_ID, request);
46 return {rc, requestMsg};
47 }
48
49 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
50 {
51 uint8_t cc = 0;
52
53 uint8_t seconds, minutes, hours, day, month;
54 uint16_t year;
55 auto rc =
56 decode_get_date_time_resp(responsePtr, payloadLength, &cc, &seconds,
57 &minutes, &hours, &day, &month, &year);
58 if (rc != PLDM_SUCCESS || cc != PLDM_SUCCESS)
59 {
60 std::cerr << "Response Message Error: "
61 << "rc=" << rc << ",cc=" << (int)cc << std::endl;
62 return;
63 }
64 std::cout << "Date & Time : " << std::endl;
65 std::cout << "DD-MM-YYYY HH:MM:SS - ";
66 setWidth(day);
67 std::cout << "-";
68 setWidth(month);
69 std::cout << "-" << bcd2dec16(year) << " ";
70 setWidth(hours);
71 std::cout << ":";
72 setWidth(minutes);
73 std::cout << ":";
74 setWidth(seconds);
75 std::cout << std::endl;
76 }
77
78 private:
79 void setWidth(uint8_t data)
80 {
81 std::cout << std::setfill('0') << std::setw(2)
82 << static_cast<uint32_t>(bcd2dec8(data));
83 }
84};
85
86void registerCommand(CLI::App& app)
87{
88 auto bios = app.add_subcommand("bios", "bios type command");
89 bios->require_subcommand(1);
90 auto getDateTime = bios->add_subcommand("GetDateTime", "get date time");
91 commands.push_back(
92 std::make_unique<GetDateTime>("bios", "GetDateTime", getDateTime));
93}
94
95} // namespace bios
96
97} // namespace pldmtool