F´ Flight Software - C/C++ Documentation  NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LogString.cpp
Go to the documentation of this file.
1 #include <Fw/Log/LogString.hpp>
3 
4 namespace Fw {
5 
6  LogStringArg::LogStringArg(const char* src) : StringBase() {
7  Fw::StringUtils::string_copy(this->m_buf, src, sizeof(this->m_buf));
8  }
9 
11  Fw::StringUtils::string_copy(this->m_buf, src.toChar(), sizeof(this->m_buf));
12  }
13 
15  Fw::StringUtils::string_copy(this->m_buf, src.toChar(), sizeof(this->m_buf));
16  }
17 
19  : StringBase() {
20  this->m_buf[0] = 0;
21  }
22 
24  if(this == &other) {
25  return *this;
26  }
27 
28  Fw::StringUtils::string_copy(this->m_buf, other.toChar(), sizeof(this->m_buf));
29  return *this;
30  }
31 
33  if(this == &other) {
34  return *this;
35  }
36 
37  Fw::StringUtils::string_copy(this->m_buf, other.toChar(), sizeof(this->m_buf));
38  return *this;
39  }
40 
41  LogStringArg& LogStringArg::operator=(const char* other) {
42  Fw::StringUtils::string_copy(this->m_buf, other, sizeof(this->m_buf));
43  return *this;
44  }
45 
47  }
48 
49  const char* LogStringArg::toChar() const {
50  return this->m_buf;
51  }
52 
55  }
56 
58  return this->serialize(buffer, this->length());
59  }
60 
62  NATIVE_INT_TYPE len = FW_MIN(maxLength,this->length());
63 #if FW_AMPCS_COMPATIBLE
64  // serialize 8-bit size with null terminator removed
65  U8 strSize = len - 1;
66  SerializeStatus stat = buffer.serialize(strSize);
67  if (stat != FW_SERIALIZE_OK) {
68  return stat;
69  }
70  return buffer.serialize(reinterpret_cast<const U8*>(this->toChar()),strSize, true);
71 #else
72  return buffer.serialize(reinterpret_cast<const U8*>(this->toChar()),len);
73 #endif
74  }
75 
77  NATIVE_UINT_TYPE maxSize = this->getCapacity() - 1;
78  CHAR* raw = const_cast<CHAR*>(this->toChar());
79 
80 #if FW_AMPCS_COMPATIBLE
81  // AMPCS encodes 8-bit string size
82  U8 strSize;
83  SerializeStatus stat = buffer.deserialize(strSize);
84  if (stat != FW_SERIALIZE_OK) {
85  return stat;
86  }
87  strSize = FW_MIN(maxSize,strSize);
88  stat = buffer.deserialize(reinterpret_cast<U8*>(raw),strSize,true);
89  // AMPCS Strings not null terminated
90  if(strSize < maxSize) {
91  raw[strSize] = 0;
92  }
93 #else
94  SerializeStatus stat = buffer.deserialize(reinterpret_cast<U8*>(raw),maxSize);
95 #endif
96 
97  // Null terminate deserialized string
98  raw[maxSize] = 0;
99  return stat;
100  }
101 }
Fw::LogStringArg::toChar
const char * toChar() const override
Definition: LogString.cpp:49
Fw::LogStringArg::deserialize
SerializeStatus deserialize(SerializeBufferBase &buffer) override
deserialization function
Definition: LogString.cpp:76
Fw::LogStringArg::operator=
LogStringArg & operator=(const LogStringArg &other)
assignment operator
Definition: LogString.cpp:23
Fw::SerializeBufferBase
Definition: Serializable.hpp:43
Fw::SerializeStatus
SerializeStatus
forward declaration for string
Definition: Serializable.hpp:14
Fw::StringBase::length
NATIVE_UINT_TYPE length() const
Get length of string.
Definition: StringType.cpp:123
Fw::SerializeBufferBase::serialize
SerializeStatus serialize(U8 val)
serialize 8-bit unsigned int
Definition: Serializable.cpp:67
Fw::LogStringArg
Definition: LogString.hpp:11
Fw::StringBase
Definition: StringType.hpp:23
U8
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.hpp:76
Fw::LogStringArg::getCapacity
NATIVE_UINT_TYPE getCapacity() const override
return size of buffer
Definition: LogString.cpp:53
CHAR
char CHAR
Definition: BasicTypes.hpp:99
StringUtils.hpp
Fw::FW_SERIALIZE_OK
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.
Definition: Serializable.hpp:15
Fw::LogStringArg::~LogStringArg
~LogStringArg()
Definition: LogString.cpp:46
LogString.hpp
FW_MIN
#define FW_MIN(a, b)
MIN macro.
Definition: BasicTypes.hpp:104
Fw::StringUtils::string_copy
char * string_copy(char *destination, const char *source, U32 num)
copy string with null-termination guaranteed
Definition: StringUtils.cpp:5
NATIVE_UINT_TYPE
unsigned int NATIVE_UINT_TYPE
native unsigned integer type declaration
Definition: BasicTypes.hpp:30
Fw::SerializeBufferBase::deserialize
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
Definition: Serializable.cpp:290
FW_LOG_STRING_MAX_SIZE
#define FW_LOG_STRING_MAX_SIZE
Max size of log string parameter type.
Definition: FpConfig.hpp:252
Fw::LogStringArg::serialize
SerializeStatus serialize(SerializeBufferBase &buffer) const override
serialization function
Definition: LogString.cpp:57
Fw::LogStringArg::LogStringArg
LogStringArg()
Definition: LogString.cpp:18
Fw::StringBase::toChar
virtual const CHAR * toChar() const =0
NATIVE_INT_TYPE
int NATIVE_INT_TYPE
native integer type declaration
Definition: BasicTypes.hpp:29
Fw
Definition: Buffer.cpp:21