xref: /openbmc/openpower-hw-diags/attn/pel/extended_user_header.cpp (revision feeea83b3fc9aabd23a1ec6d29bd293008954acc)
1*feeea83bSBen Tyner #include "extended_user_header.hpp"
2*feeea83bSBen Tyner 
3*feeea83bSBen Tyner namespace attn
4*feeea83bSBen Tyner {
5*feeea83bSBen Tyner namespace pel
6*feeea83bSBen Tyner {
7*feeea83bSBen Tyner 
ExtendedUserHeader(Stream & pel)8*feeea83bSBen Tyner ExtendedUserHeader::ExtendedUserHeader(Stream& pel)
9*feeea83bSBen Tyner {
10*feeea83bSBen Tyner     unflatten(pel);
11*feeea83bSBen Tyner }
12*feeea83bSBen Tyner 
flatten(Stream & pel) const13*feeea83bSBen Tyner void ExtendedUserHeader::flatten(Stream& pel) const
14*feeea83bSBen Tyner {
15*feeea83bSBen Tyner     pel << _header;
16*feeea83bSBen Tyner     pel.write(_mtms, mtmsSize);
17*feeea83bSBen Tyner     pel.write(_serverFWVersion.data(), _serverFWVersion.size());
18*feeea83bSBen Tyner     pel.write(_subsystemFWVersion.data(), _subsystemFWVersion.size());
19*feeea83bSBen Tyner     pel << _reserved4B << _refTime << _reserved1B1 << _reserved1B2
20*feeea83bSBen Tyner         << _reserved1B3 << _symptomIdSize << _symptomId;
21*feeea83bSBen Tyner }
22*feeea83bSBen Tyner 
unflatten(Stream & pel)23*feeea83bSBen Tyner void ExtendedUserHeader::unflatten(Stream& pel)
24*feeea83bSBen Tyner {
25*feeea83bSBen Tyner     pel >> _header;
26*feeea83bSBen Tyner     pel.read(_mtms, mtmsSize);
27*feeea83bSBen Tyner     pel.read(_serverFWVersion.data(), _serverFWVersion.size());
28*feeea83bSBen Tyner     pel.read(_subsystemFWVersion.data(), _subsystemFWVersion.size());
29*feeea83bSBen Tyner     pel >> _reserved4B >> _refTime >> _reserved1B1 >> _reserved1B2 >>
30*feeea83bSBen Tyner         _reserved1B3 >> _symptomIdSize >> _symptomId;
31*feeea83bSBen Tyner 
32*feeea83bSBen Tyner     //_symptomId.resize(_symptomIdSize);
33*feeea83bSBen Tyner     pel >> _symptomId;
34*feeea83bSBen Tyner }
35*feeea83bSBen Tyner 
setSymptomId(const std::string & symptomId)36*feeea83bSBen Tyner void ExtendedUserHeader::setSymptomId(const std::string& symptomId)
37*feeea83bSBen Tyner {
38*feeea83bSBen Tyner     // set symptomId to new symptomId
39*feeea83bSBen Tyner     std::copy(symptomId.begin(), symptomId.end(),
40*feeea83bSBen Tyner               std::back_inserter(_symptomId));
41*feeea83bSBen Tyner 
42*feeea83bSBen Tyner     // new symptom Id cannot be larger than existing symptom Id
43*feeea83bSBen Tyner     if (_symptomId.size() > size_t((_symptomIdSize - 1)))
44*feeea83bSBen Tyner     {
45*feeea83bSBen Tyner         _symptomId.resize(_symptomIdSize - 1);
46*feeea83bSBen Tyner     }
47*feeea83bSBen Tyner 
48*feeea83bSBen Tyner     // null terminate new symptom Id (it may have been smaller)
49*feeea83bSBen Tyner     _symptomId.push_back(0);
50*feeea83bSBen Tyner 
51*feeea83bSBen Tyner     // pad if new symptom ID (it may have been smaller)
52*feeea83bSBen Tyner     while ((_symptomId.size() != _symptomIdSize))
53*feeea83bSBen Tyner     {
54*feeea83bSBen Tyner         _symptomId.push_back(0);
55*feeea83bSBen Tyner     }
56*feeea83bSBen Tyner }
57*feeea83bSBen Tyner 
58*feeea83bSBen Tyner } // namespace pel
59*feeea83bSBen Tyner } // namespace attn
60