PEL: private header in JSON

The PELTool application is able to convert sections to JSON. This commit
takes care of converting the private header section to JSON.

private header section in JSON sample:

"Private Header":[
 {"Section Version": "1"},
 {"Sub-section type": "0"},
 {"Log Committed by": "0x1000"},
 {"Entry Creation": "10/24/2019  15:50:08"},
 {"Entry Commit": "10/24/2019  15:50:08"},
 {"Creator ID": "BMC"},
 {"Creator Implementation": ""},
 {"Platform Log ID": "0x50000004"},
 {"Log Entry ID": "0x50000004"}
]

Signed-off-by: Aatir <aatrapps@gmail.com>
Change-Id: I8b0d7dc7b70cd2a03f67f7c9a48755803634005d
diff --git a/extensions/openpower-pels/private_header.cpp b/extensions/openpower-pels/private_header.cpp
index 7ec87f3..2c1a860 100644
--- a/extensions/openpower-pels/private_header.cpp
+++ b/extensions/openpower-pels/private_header.cpp
@@ -17,6 +17,7 @@
 
 #include "log_id.hpp"
 #include "pel_types.hpp"
+#include "pel_values.hpp"
 
 #include <phosphor-logging/log.hpp>
 
@@ -25,6 +26,7 @@
 namespace pels
 {
 
+namespace pv = openpower::pels::pel_values;
 using namespace phosphor::logging;
 
 PrivateHeader::PrivateHeader(uint16_t componentID, uint32_t obmcLogID,
@@ -79,7 +81,52 @@
         _valid = false;
     }
 }
+std::optional<std::string> PrivateHeader::getJSON() const
+{
+    char tmpPhVal[50];
+    sprintf(tmpPhVal, "%02X/%02X/%02X%02X  %02X:%02X:%02X",
+            _createTimestamp.month, _createTimestamp.day,
+            _createTimestamp.yearMSB, _createTimestamp.yearLSB,
+            _createTimestamp.hour, _createTimestamp.minutes,
+            _createTimestamp.seconds);
+    std::string phCreateTStr(tmpPhVal);
+    sprintf(tmpPhVal, "%02X/%02X/%02X%02X  %02X:%02X:%02X",
+            _commitTimestamp.month, _commitTimestamp.day,
+            _createTimestamp.yearMSB, _commitTimestamp.yearLSB,
+            _commitTimestamp.hour, _commitTimestamp.minutes,
+            _commitTimestamp.seconds);
+    std::string phCommitTStr(tmpPhVal);
+    sprintf(tmpPhVal, "%c", _creatorID);
+    std::string creator(tmpPhVal);
+    creator = pv::creatorIDs.count(creator) ? pv::creatorIDs.at(creator)
+                                            : "Unknown CreatorID";
+    std::string phCreatorVersionStr =
+        std::string(reinterpret_cast<const char*>(_creatorVersion.version));
 
+    sprintf(tmpPhVal, "0x%X", _header.componentID);
+    std::string phCbStr(tmpPhVal);
+    sprintf(tmpPhVal, "%d", _header.subType);
+    std::string phStStr(tmpPhVal);
+    sprintf(tmpPhVal, "%d", privateHeaderVersion);
+    std::string phVerStr(tmpPhVal);
+    sprintf(tmpPhVal, "0x%X", _plid);
+    std::string phPlatformIDStr(tmpPhVal);
+    sprintf(tmpPhVal, "0x%X", _id);
+    std::string phLogEntryIDStr(tmpPhVal);
+    std::string ph = "{\"Section Version\": \"" + phVerStr +
+                     "\"}, \n {\"Sub-section type\": \"" + phStStr +
+                     "\"}, \n "
+                     "{\"Log Committed by\": \"" +
+                     phCbStr + "\"}, \n {\"Entry Creation\": \"" +
+                     phCreateTStr + "\"}, \n {\"Entry Commit\": \"" +
+                     phCommitTStr + "\"}, \n {\"Creator ID\": \"" + creator +
+                     "\"}, \n {\"Creator Implementation\": \"" +
+                     phCreatorVersionStr + "\"},\n {\"Platform Log ID\": \"" +
+                     phPlatformIDStr + "\"},\n {\"Log Entry ID\": \"" +
+                     phLogEntryIDStr + "\"}";
+
+    return ph;
+}
 void PrivateHeader::validate()
 {
     bool failed = false;