PEL: Print SRC section into JSON

For BMC created errors, look up the reason code in
the message registry for error description and also
meaning of data stored in hexwords 6-9 (if any).

Added registry message field in peltool list output.

"Primary SRC": {
    "Section Version":          "1",
    "Sub-section type":         "1",
    "Created by":               "0x1000",
    "SRC Version":              "0x02",
    "SRC Format":               "0x55",
    "Power Control Net Fault":  "False",
    "Error Details": {
        "Message":              "PS 0x64 had a PGOOD Fault",
        "PS_NUM":               "0x64"
    },
    "Valid Word Count":         "0x09",
    "Reference Code":           "BD8D1001",
    "Hex Word 2":               "00000055",
    "Hex Word 3":               "00000010",
    "Hex Word 4":               "00000000",
    "Hex Word 5":               "00000000",
    "Hex Word 6":               "00000064",
    "Hex Word 7":               "00000000",
    "Hex Word 8":               "00000000",
    "Hex Word 9":               "00000000"
}

"Primary SRC": {
    "Section Version":          "1",
    "Sub-section type":         "0",
    "Created by":               "0x4552",
    "SRC Version":              "0x02",
    "SRC Format":               "0x2008000",
    "Power Control Net Fault":  "False",
    "Valid Word Count":         "0x04",
    "Reference Code":           "B2001020",
    "Hex Word 2":               "02008000",
    "Hex Word 3":               "00000000",
    "Hex Word 4":               "00000012",
    "Callout Section": {
        "Callout Count":        "1",
        "Callouts": [{
            "FRU Type":         "Symbolic FRU",
            "Priority":         "Medium Priority",
            "Part Number":      "NEXTLVL"
        }]
    }
}

Testing: Manually run peltool and verified out. All unit tests passed.
Signed-off-by: Harisuddin Mohamed Isa <harisuddin@gmail.com>
Change-Id: I124627ba785413ebda02305b7d9f95431922e714
diff --git a/extensions/openpower-pels/tools/peltool.cpp b/extensions/openpower-pels/tools/peltool.cpp
index 5c040ca..f1d5f59 100644
--- a/extensions/openpower-pels/tools/peltool.cpp
+++ b/extensions/openpower-pels/tools/peltool.cpp
@@ -16,6 +16,7 @@
 #include "config.h"
 
 #include "../bcd_time.hpp"
+#include "../paths.hpp"
 #include "../pel.hpp"
 #include "../pel_types.hpp"
 #include "../pel_values.hpp"
@@ -197,7 +198,7 @@
 }
 
 template <typename T>
-std::string genPELJSON(T itr, bool hidden)
+std::string genPELJSON(T itr, bool hidden, message::Registry& registry)
 {
     std::size_t found;
     std::string val;
@@ -224,9 +225,24 @@
                 val = std::string(tmpValStr);
                 listStr += "\t\"" + val + "\": {\n";
                 // ASCII
-                val = pel.primarySRC() ? pel.primarySRC().value()->asciiString()
-                                       : "No SRC";
-                listStr += "\t\t\"SRC\": \"" + trim(val) + "\",\n";
+                if (pel.primarySRC())
+                {
+                    val = pel.primarySRC().value()->asciiString();
+                    listStr += "\t\t\"SRC\": \"" +
+                               val.substr(0, val.find(0x20)) + "\",\n";
+                    // Registry message
+                    auto regVal = pel.primarySRC().value()->getErrorDetails(
+                        registry, DetailLevel::message, true);
+                    if (regVal)
+                    {
+                        val = regVal.value();
+                        listStr += "\t\t\"Message\": \"" + val + "\",\n";
+                    }
+                }
+                else
+                {
+                    listStr += "\t\t\"SRC\": \"No SRC\",\n";
+                }
                 // platformid
                 sprintf(tmpValStr, "0x%X", pel.privateHeader().plid());
                 val = std::string(tmpValStr);
@@ -308,8 +324,10 @@
                          fileNameToTimestamp((*it).path().filename()));
         }
     }
-    auto buildJSON = [&listStr, &hidden](const auto& i) {
-        listStr += genPELJSON(i, hidden);
+    message::Registry registry(getMessageRegistryPath() /
+                               message::registryFileName);
+    auto buildJSON = [&listStr, &hidden, &registry](const auto& i) {
+        listStr += genPELJSON(i, hidden, registry);
     };
     if (order)
     {