More changes to support JEDEC format VPD

Change-Id: I7d8e4b0508bc1f92c3f6fd1a924a153ebe23f17e
Signed-off-by: jinuthomas <jinu.joy.thomas@in.ibm.com>
diff --git a/ibm_vpd_app.cpp b/ibm_vpd_app.cpp
index 57109b6..94b7f55 100644
--- a/ibm_vpd_app.cpp
+++ b/ibm_vpd_app.cpp
@@ -240,31 +240,34 @@
         }
         if constexpr (is_same<T, KeywordVpdMap>::value)
         {
-            if (get_if<Binary>(&kwVal.second))
+            if (auto keywordValue = get_if<Binary>(&kwVal.second))
             {
-                Binary vec(get_if<Binary>(&kwVal.second)->begin(),
-                           get_if<Binary>(&kwVal.second)->end());
+                Binary vec((*keywordValue).begin(), (*keywordValue).end());
                 prop.emplace(move(kw), move(vec));
             }
-            else
+            else if (auto keywordValue = get_if<std::string>(&kwVal.second))
+            {
+                Binary vec((*keywordValue).begin(), (*keywordValue).end());
+                prop.emplace(move(kw), move(vec));
+            }
+            else if (auto keywordValue = get_if<size_t>(&kwVal.second))
             {
                 if (kw == "MemorySizeInKB")
                 {
                     inventory::PropertyMap memProp;
-                    auto memVal = get_if<size_t>(&kwVal.second);
-                    if (memVal)
-                    {
-                        memProp.emplace(move(kw),
-                                        ((*memVal) * CONVERT_MB_TO_KB));
-                        interfaces.emplace(
-                            "xyz.openbmc_project.Inventory.Item.Dimm",
-                            move(memProp));
-                    }
-                    else
-                    {
-                        cerr << "MemorySizeInKB value not found in vpd map\n";
-                    }
+                    memProp.emplace(move(kw), ((*keywordValue)));
+                    interfaces.emplace(
+                        "xyz.openbmc_project.Inventory.Item.Dimm",
+                        move(memProp));
                 }
+                else
+                {
+                    cerr << "Unknown Keyword[" << kw << "] found ";
+                }
+            }
+            else
+            {
+                cerr << "Unknown Variant found ";
             }
         }
         else
@@ -362,10 +365,7 @@
                 {
                     if (!kw.empty() && vpdMap.count(kw))
                     {
-                        auto kwValue = get_if<Binary>(&vpdMap.at(kw));
-                        auto uintValue = get_if<size_t>(&vpdMap.at(kw));
-
-                        if (kwValue)
+                        if (auto kwValue = get_if<Binary>(&vpdMap.at(kw)))
                         {
                             auto prop =
                                 string((*kwValue).begin(), (*kwValue).end());
@@ -374,10 +374,26 @@
 
                             props.emplace(busProp, encoded);
                         }
-                        else if (uintValue)
+                        else if (auto kwValue =
+                                     get_if<std::string>(&vpdMap.at(kw)))
+                        {
+                            auto prop =
+                                string((*kwValue).begin(), (*kwValue).end());
+
+                            auto encoded = encodeKeyword(prop, encoding);
+
+                            props.emplace(busProp, encoded);
+                        }
+                        else if (auto uintValue =
+                                     get_if<size_t>(&vpdMap.at(kw)))
                         {
                             props.emplace(busProp, *uintValue);
                         }
+                        else
+                        {
+                            std::cerr << " Unknown Keyword [" << kw
+                                      << "] Encountered";
+                        }
                     }
                 }
             }
@@ -492,17 +508,17 @@
             {
                 // Now bind the device
                 string bind = json["frus"][file].at(0).value("devAddress", "");
-                cout << "Binding device " << bind << endl;
+                cout << "Binding device " << bind << std::endl;
                 string bindCmd = string("echo \"") + bind +
                                  string("\" > /sys/bus/i2c/drivers/at24/bind");
-                cout << bindCmd << endl;
+                cout << bindCmd << std::endl;
                 executeCmd(bindCmd);
 
                 // Check if device showed up (test for file)
                 if (!fs::exists(file))
                 {
                     cerr << "EEPROM " << file
-                         << " does not exist. Take failure action" << endl;
+                         << " does not exist. Take failure action" << std::endl;
                     // If not, then take failure postAction
                     executePostFailAction(json, file);
                 }
@@ -513,7 +529,8 @@
                 cerr << "VPD inventory JSON missing basic informations of "
                         "preAction "
                         "for this FRU : ["
-                     << file << "]. Executing executePostFailAction." << endl;
+                     << file << "]. Executing executePostFailAction."
+                     << std::endl;
 
                 // Take failure postAction
                 executePostFailAction(json, file);
@@ -1422,7 +1439,8 @@
         if (!fs::exists(file))
         {
             cout << "Device path: " << file
-                 << " does not exist. Spurious udev event? Exiting." << endl;
+                 << " does not exist. Spurious udev event? Exiting."
+                 << std::endl;
             return 0;
         }
 
@@ -1446,7 +1464,7 @@
             if ("xyz.openbmc_project.State.Chassis.PowerState.On" ==
                 getPowerState())
             {
-                cout << "This VPD cannot be read when power is ON" << endl;
+                cout << "This VPD cannot be read when power is ON" << std::endl;
                 return 0;
             }
         }
@@ -1454,7 +1472,7 @@
         // Check if this VPD should be recollected at all
         if (!needsRecollection(js, file))
         {
-            cout << "Skip VPD recollection for: " << file << endl;
+            cout << "Skip VPD recollection for: " << file << std::endl;
             return 0;
         }