1 #pragma once 2 3 #include "registry.hpp" 4 #include "stream.hpp" 5 6 #include <string> 7 8 namespace openpower 9 { 10 namespace pels 11 { 12 namespace src 13 { 14 15 const size_t asciiStringSize = 32; 16 17 /** 18 * @class AsciiString 19 * 20 * This represents the ASCII string field in the SRC PEL section. 21 * This 32 character string shows up on the panel on a function 11. 22 * 23 * The first 2 characters are the SRC type, like 'BD' or '11'. 24 * Next is the subsystem, like '8D', if a BD SRC, otherwise '00'. 25 * Next is the reason code, like 'AAAA'. 26 * The rest is filled in with spaces. 27 */ 28 class AsciiString 29 { 30 public: 31 AsciiString() = delete; 32 ~AsciiString() = default; 33 AsciiString(const AsciiString&) = default; 34 AsciiString& operator=(const AsciiString&) = default; 35 AsciiString(AsciiString&&) = default; 36 AsciiString& operator=(AsciiString&&) = default; 37 38 /** 39 * @brief Constructor 40 * 41 * Fills in this class's data fields from the stream. 42 * 43 * @param[in] pel - the PEL data stream 44 */ 45 explicit AsciiString(Stream& stream); 46 47 /** 48 * @brief Constructor 49 * 50 * Fills in the class from the registry entry 51 */ 52 explicit AsciiString(const message::Entry& entry); 53 54 /** 55 * @brief Flatten the object into the stream 56 * 57 * @param[in] stream - The stream to write to 58 */ 59 void flatten(Stream& stream) const; 60 61 /** 62 * @brief Fills in the object from the stream data 63 * 64 * @param[in] stream - The stream to read from 65 */ 66 void unflatten(Stream& stream); 67 68 /** 69 * @brief Return the 32 character ASCII string data 70 * 71 * @return std::string - The data 72 */ 73 std::string get() const; 74 75 private: 76 /** 77 * @brief Converts a byte of raw data to 2 characters 78 * and writes it to the offset. 79 * 80 * For example, if string is: "AABBCCDD" 81 * 82 * setByte(0, 0x11); 83 * setByte(1, 0x22); 84 * setByte(2, 0x33); 85 * setByte(3, 0x44); 86 * 87 * results in "11223344" 88 * 89 * @param[in] offset - The offset into the ascii string 90 * @param[in] value - The value to write (0x55 -> "55") 91 */ 92 void setByte(size_t offset, uint8_t value); 93 94 /** 95 * @brief The ASCII string itself 96 */ 97 std::array<char, asciiStringSize> _string; 98 }; 99 100 } // namespace src 101 102 } // namespace pels 103 } // namespace openpower 104