PEL: Add string accessors to MTMS class
This class is used by a few other classes, so make it easier to get
data out of it.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I2feb4b83a09e6cb6056c9f1a903ca55e8cacf2ae
diff --git a/extensions/openpower-pels/failing_mtms.cpp b/extensions/openpower-pels/failing_mtms.cpp
index 0b02f2d..1b15c16 100644
--- a/extensions/openpower-pels/failing_mtms.cpp
+++ b/extensions/openpower-pels/failing_mtms.cpp
@@ -58,31 +58,6 @@
_valid = (failed) ? false : true;
}
-std::string FailingMTMS::getMachineTypeModel()
-{
- std::string mtmString;
- const auto& mtm = _mtms.machineTypeAndModel();
-
- for (size_t i = 0; (i < MTMS::mtmSize) && (mtm[i] != 0); i++)
- {
- mtmString.push_back(mtm[i]);
- }
- return mtmString;
-}
-
-std::string FailingMTMS::getMachineSerialNumber()
-{
- std::string snString;
- const auto& sn = _mtms.machineSerialNumber();
-
- // Get everything up to the 0s.
- for (size_t i = 0; (i < MTMS::snSize) && (sn[i] != 0); i++)
- {
- snString.push_back(sn[i]);
- }
- return snString;
-}
-
void FailingMTMS::flatten(Stream& stream)
{
stream << _header << _mtms;
diff --git a/extensions/openpower-pels/failing_mtms.hpp b/extensions/openpower-pels/failing_mtms.hpp
index 209eaa9..bbf0b2a 100644
--- a/extensions/openpower-pels/failing_mtms.hpp
+++ b/extensions/openpower-pels/failing_mtms.hpp
@@ -66,14 +66,20 @@
*
* @return std::string the MTM
*/
- std::string getMachineTypeModel();
+ std::string getMachineTypeModel() const
+ {
+ return _mtms.machineTypeAndModel();
+ }
/**
* @brief Returns the machine serial number as a string
*
* @return std::string the serial number
*/
- std::string getMachineSerialNumber();
+ std::string getMachineSerialNumber() const
+ {
+ return _mtms.machineSerialNumber();
+ }
private:
/**
diff --git a/extensions/openpower-pels/mtms.cpp b/extensions/openpower-pels/mtms.cpp
index 355431f..ec964f2 100644
--- a/extensions/openpower-pels/mtms.cpp
+++ b/extensions/openpower-pels/mtms.cpp
@@ -51,12 +51,12 @@
{
for (size_t i = 0; i < MTMS::mtmSize; i++)
{
- s << mtms.machineTypeAndModel()[i];
+ s << mtms.machineTypeAndModelRaw()[i];
}
for (size_t i = 0; i < MTMS::snSize; i++)
{
- s << mtms.machineSerialNumber()[i];
+ s << mtms.machineSerialNumberRaw()[i];
}
return s;
@@ -66,12 +66,12 @@
{
for (size_t i = 0; i < MTMS::mtmSize; i++)
{
- s >> mtms.machineTypeAndModel()[i];
+ s >> mtms.machineTypeAndModelRaw()[i];
}
for (size_t i = 0; i < MTMS::snSize; i++)
{
- s >> mtms.machineSerialNumber()[i];
+ s >> mtms.machineSerialNumberRaw()[i];
}
return s;
diff --git a/extensions/openpower-pels/mtms.hpp b/extensions/openpower-pels/mtms.hpp
index fe8723d..6b76ec7 100644
--- a/extensions/openpower-pels/mtms.hpp
+++ b/extensions/openpower-pels/mtms.hpp
@@ -59,26 +59,61 @@
explicit MTMS(Stream& stream);
/**
- * @brief Returns the machine type/model value
+ * @brief Returns the raw machine type/model value
*
* @return std::array<uint8_t, mtmSize>& - The TM value
*/
- std::array<uint8_t, mtmSize>& machineTypeAndModel()
+ std::array<uint8_t, mtmSize>& machineTypeAndModelRaw()
{
return _machineTypeAndModel;
}
/**
- * @brief Returns the machine serial number value
+ * @brief Returns the machine type/model value
+ *
+ * @return std::string - The TM value
+ */
+ std::string machineTypeAndModel() const
+ {
+ std::string mtm;
+
+ // Get everything up to the 0s.
+ for (size_t i = 0; (i < mtmSize) && (_machineTypeAndModel[i] != 0); i++)
+ {
+ mtm.push_back(_machineTypeAndModel[i]);
+ }
+
+ return mtm;
+ }
+
+ /**
+ * @brief Returns the raw machine serial number value
*
* @return std::array<uint8_t, snSize>& - The SN value
*/
- std::array<uint8_t, snSize>& machineSerialNumber()
+ std::array<uint8_t, snSize>& machineSerialNumberRaw()
{
return _serialNumber;
}
/**
+ * @brief Returns the machine serial number value
+ *
+ * @return std::string - The SN value
+ */
+ std::string machineSerialNumber() const
+ {
+ std::string sn;
+
+ // Get everything up to the 0s.
+ for (size_t i = 0; (i < snSize) && (_serialNumber[i] != 0); i++)
+ {
+ sn.push_back(_serialNumber[i]);
+ }
+ return sn;
+ }
+
+ /**
* @brief Returns the size of the data when flattened
*
* @return size_t - The size of the data
diff --git a/test/openpower-pels/mtms_test.cpp b/test/openpower-pels/mtms_test.cpp
index 999100f..2290374 100644
--- a/test/openpower-pels/mtms_test.cpp
+++ b/test/openpower-pels/mtms_test.cpp
@@ -18,11 +18,13 @@
MTMS mtms{tm, sn};
std::array<uint8_t, 8> t{'T', 'T', 'T', 'T', '-', 'M', 'M', 'M'};
- EXPECT_EQ(t, mtms.machineTypeAndModel());
+ EXPECT_EQ(t, mtms.machineTypeAndModelRaw());
+ EXPECT_EQ("TTTT-MMM", mtms.machineTypeAndModel());
std::array<uint8_t, 12> s{'1', '2', '3', '4', '5', '6',
'7', '8', '9', 'A', 'B', 'C'};
- EXPECT_EQ(s, mtms.machineSerialNumber());
+ EXPECT_EQ(s, mtms.machineSerialNumberRaw());
+ EXPECT_EQ("123456789ABC", mtms.machineSerialNumber());
}
{
@@ -33,11 +35,11 @@
MTMS mtms{tm, sn};
std::array<uint8_t, 8> t{'T', 'T', 'T', 'T', '-', 'M', 'M', 'M'};
- EXPECT_EQ(t, mtms.machineTypeAndModel());
+ EXPECT_EQ(t, mtms.machineTypeAndModelRaw());
std::array<uint8_t, 12> s{'1', '2', '3', '4', '5', '6',
'7', '8', '9', 'A', 'B', 'C'};
- EXPECT_EQ(s, mtms.machineSerialNumber());
+ EXPECT_EQ(s, mtms.machineSerialNumberRaw());
}
{
@@ -48,10 +50,12 @@
MTMS mtms{tm, sn};
std::array<uint8_t, 8> t{'T', 'T', 'T', 'T', 0, 0, 0, 0};
- EXPECT_EQ(t, mtms.machineTypeAndModel());
+ EXPECT_EQ(t, mtms.machineTypeAndModelRaw());
+ EXPECT_EQ("TTTT", mtms.machineTypeAndModel());
std::array<uint8_t, 12> s{'1', '2', '3', '4', 0, 0, 0, 0, 0, 0, 0, 0};
- EXPECT_EQ(s, mtms.machineSerialNumber());
+ EXPECT_EQ(s, mtms.machineSerialNumberRaw());
+ EXPECT_EQ("1234", mtms.machineSerialNumber());
}
{
@@ -63,12 +67,9 @@
MTMS mtms{stream};
- std::array<uint8_t, 8> t{'T', 'T', 'T', 'T', '-', 'M', 'M', 'M'};
- EXPECT_EQ(t, mtms.machineTypeAndModel());
+ EXPECT_EQ("TTTT-MMM", mtms.machineTypeAndModel());
- std::array<uint8_t, 12> s{'1', '2', '3', '4', '5', '6',
- '7', '8', '9', 'A', 'B', 'C'};
- EXPECT_EQ(s, mtms.machineSerialNumber());
+ EXPECT_EQ("123456789ABC", mtms.machineSerialNumber());
}
}
@@ -100,10 +101,7 @@
MTMS mtms;
stream >> mtms;
- std::array<uint8_t, 8> t{'T', 'T', 'T', 'T', '-', 'M', 'M', 'M'};
- EXPECT_EQ(t, mtms.machineTypeAndModel());
+ EXPECT_EQ("TTTT-MMM", mtms.machineTypeAndModel());
- std::array<uint8_t, 12> s{'1', '2', '3', '4', '5', '6',
- '7', '8', '9', 'A', 'B', 'C'};
- EXPECT_EQ(s, mtms.machineSerialNumber());
+ EXPECT_EQ("123456789ABC", mtms.machineSerialNumber());
}