blob: d76b716d205cce9689c20b58541f7f9b45c43701 [file] [log] [blame]
Sampa Misra032bd502019-03-06 05:03:22 -06001#pragma once
2
3#include <stdint.h>
4#include <systemd/sd-bus.h>
5
6#include <sdbusplus/server.hpp>
7#include <string>
8
9namespace pldm
10{
11namespace responder
12{
13
14/**
15 * @brief Get the DBUS Service name for the input dbus path
16 * @param[in] bus - DBUS Bus Object
17 * @param[in] path - DBUS object path
18 * @param[in] interface - DBUS Interface
19 * @return std::string - the dbus service name
20 */
21std::string getService(sdbusplus::bus::bus& bus, const std::string& path,
22 const std::string& interface);
23
24/** @brief Convert any Decimal number to BCD
25 *
26 * @tparam[in] decimal - Decimal number
27 * @return Corresponding BCD number
28 */
29template <typename T>
30T decimalToBcd(T decimal)
31{
32 T bcd = 0;
33 T rem = 0;
34 auto cnt = 0;
35
36 while (decimal)
37 {
38 rem = decimal % 10;
39 bcd = bcd + (rem << cnt);
40 decimal = decimal / 10;
41 cnt += 4;
42 }
43
44 return bcd;
45}
46
47} // namespace responder
48} // namespace pldm