BuildDate encoding support for FRUs
This commit and vpd-json commit together enables the encoding for
BuildDate and set Present state true for all the FRUs.
Test:
[[0;1;39mxyz.openbmc_project.Inventory.Decorator.Asset[[0m interface - -
.BuildDate property s "2019-08-26 11:00"
[[0;1;39mxyz.openbmc_project.Inventory.Item [[0m interface -
.Present property b true
Change-Id: I6d2f07477b0079c1df370908558b2ab0f17a4212
Signed-off-by: Alpana Kumari <alpankum@in.ibm.com>
diff --git a/ibm_vpd_app.cpp b/ibm_vpd_app.cpp
index 44977e0..827a370 100644
--- a/ibm_vpd_app.cpp
+++ b/ibm_vpd_app.cpp
@@ -37,6 +37,24 @@
}
return res;
}
+ else if (encoding == "DATE")
+ {
+ // Date, represent as
+ // <year>-<month>-<day> <hour>:<min>
+ string res{};
+ static constexpr uint8_t skipPrefix = 3;
+
+ auto strItr = kw.begin();
+ advance(strItr, skipPrefix);
+ for_each(strItr, kw.end(), [&res](size_t c) { res += c; });
+
+ res.insert(BD_YEAR_END, 1, '-');
+ res.insert(BD_MONTH_END, 1, '-');
+ res.insert(BD_DAY_END, 1, ' ');
+ res.insert(BD_HOUR_END, 1, ':');
+
+ return res;
+ }
else // default to string encoding
{
return string(kw.begin(), kw.end());
@@ -96,28 +114,36 @@
for (const auto& itr : ifs.value().items())
{
- const string& rec = itr.value().value("recordName", "");
- const string& kw = itr.value().value("keywordName", "");
- const string& encoding = itr.value().value("encoding", "");
-
- if constexpr (std::is_same<T, Parsed>::value)
+ // check if the Value is boolean or object
+ if (itr.value().is_boolean())
{
- if (!rec.empty() && !kw.empty() && vpdMap.at(rec).count(kw) &&
- vpdMap.count(rec))
- {
- auto encoded =
- encodeKeyword(vpdMap.at(rec).at(kw), encoding);
- props.emplace(itr.key(), encoded);
- }
+ props.emplace(itr.key(), itr.value().get<bool>());
}
- else if constexpr (std::is_same<T, KeywordVpdMap>::value)
+ else if (itr.value().is_object())
{
- if (!kw.empty() && vpdMap.count(kw))
+ const string& rec = itr.value().value("recordName", "");
+ const string& kw = itr.value().value("keywordName", "");
+ const string& encoding = itr.value().value("encoding", "");
+
+ if constexpr (std::is_same<T, Parsed>::value)
{
- auto prop =
- string(vpdMap.at(kw).begin(), vpdMap.at(kw).end());
- auto encoded = encodeKeyword(prop, encoding);
- props.emplace(itr.key(), encoded);
+ if (!rec.empty() && !kw.empty() &&
+ vpdMap.at(rec).count(kw) && vpdMap.count(rec))
+ {
+ auto encoded =
+ encodeKeyword(vpdMap.at(rec).at(kw), encoding);
+ props.emplace(itr.key(), encoded);
+ }
+ }
+ else if constexpr (std::is_same<T, KeywordVpdMap>::value)
+ {
+ if (!kw.empty() && vpdMap.count(kw))
+ {
+ auto prop =
+ string(vpdMap.at(kw).begin(), vpdMap.at(kw).end());
+ auto encoded = encodeKeyword(prop, encoding);
+ props.emplace(itr.key(), encoded);
+ }
}
}
}