PEL: Convert a BCDTime to epoch milliseconds
Add a new function to convert a BCDTime value from a PEL to the number
of milliseconds since the epoch.
This will be used to put the PEL creation timestamp on D-Bus.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Ic470c9324e959b3e6a7eea29db4162a45dd54fc3
diff --git a/extensions/openpower-pels/bcd_time.hpp b/extensions/openpower-pels/bcd_time.hpp
index 5679a5b..c2f6611 100644
--- a/extensions/openpower-pels/bcd_time.hpp
+++ b/extensions/openpower-pels/bcd_time.hpp
@@ -57,6 +57,15 @@
BCDTime getBCDTime(uint64_t milliseconds);
/**
+ * @brief Convert a BCDTime value into the number of
+ * milliseconds since the epoch (1/1/1970).
+ *
+ * @param[in] bcdTime - The BCD time value
+ * @return uint64_t - The milliseconds value
+ */
+uint64_t getMillisecondsSinceEpoch(const BCDTime& bcdTime);
+
+/**
* @brief Converts a number to a BCD.
*
* For example 32 -> 0x32.
@@ -86,6 +95,19 @@
}
/**
+ * @brief Converts a BCD byte to a decimal number.
+ *
+ * For example 0x22 -> 22.
+ *
+ * @param[in] bcd - The value in BCD
+ * @return int - The number in decimal
+ */
+inline int fromBCD(uint8_t bcd)
+{
+ return (((bcd & 0xF0) >> 4) * 10) + (bcd & 0xF);
+}
+
+/**
* @brief Stream extraction operator for BCDTime
*
* @param[in] s - the Stream