summaryrefslogtreecommitdiffstats
path: root/extensions/openpower-pels/ascii_string.cpp
blob: 124bd0c9d33523e6b9f02f5a8bd882e864778b99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
 * Copyright © 2019 IBM Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "ascii_string.hpp"

#include "pel_types.hpp"

#include <phosphor-logging/log.hpp>

namespace openpower
{
namespace pels
{
namespace src
{

using namespace phosphor::logging;

AsciiString::AsciiString(Stream& stream)
{
    unflatten(stream);
}

AsciiString::AsciiString(const message::Entry& entry)
{
    // Power Error:  1100RRRR
    // BMC Error:    BDSSRRRR
    // where:
    //  RRRR = reason code
    //  SS = subsystem ID

    // First is type, like 'BD'
    setByte(0, entry.src.type);

    // Next is '00', or subsystem ID
    if (entry.src.type == static_cast<uint8_t>(SRCType::powerError))
    {
        setByte(2, 0x00);
    }
    else // BMC Error
    {
        setByte(2, entry.subsystem);
    }

    // Then the reason code
    setByte(4, entry.src.reasonCode >> 8);
    setByte(6, entry.src.reasonCode & 0xFF);

    // Padded with spaces
    for (size_t offset = 8; offset < asciiStringSize; offset++)
    {
        _string[offset] = ' ';
    }
}

void AsciiString::flatten(Stream& stream) const
{
    stream.write(_string.data(), _string.size());
}

void AsciiString::unflatten(Stream& stream)
{
    stream.read(_string.data(), _string.size());
}

std::string AsciiString::get() const
{
    std::string string{_string.begin(), _string.begin() + _string.size()};
    return string;
}

void AsciiString::setByte(size_t byteOffset, uint8_t value)
{
    assert(byteOffset < asciiStringSize);

    char characters[3];
    sprintf(characters, "%02X", value);

    auto writeOffset = byteOffset;
    _string[writeOffset++] = characters[0];
    _string[writeOffset] = characters[1];
}

} // namespace src
} // namespace pels
} // namespace openpower
OpenPOWER on IntegriCloud