F´ Flight Software - C/C++ Documentation devel
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.
3
4namespace Fw {
5
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
42 Fw::StringUtils::string_copy(this->m_buf, other, sizeof(this->m_buf));
43 return *this;
44 }
45
48
49 const char* LogStringArg::toChar() const {
50 return this->m_buf;
51 }
52
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}
PlatformIntType NATIVE_INT_TYPE
Definition BasicTypes.h:51
#define FW_MIN(a, b)
MIN macro.
Definition BasicTypes.h:68
uint8_t U8
8-bit unsigned integer
Definition BasicTypes.h:26
char CHAR
Definition BasicTypes.h:28
PlatformUIntType NATIVE_UINT_TYPE
Definition BasicTypes.h:52
#define FW_LOG_STRING_MAX_SIZE
Max size of log string parameter type.
Definition FpConfig.h:259
const char * toChar() const override
Definition LogString.cpp:49
SerializeStatus deserialize(SerializeBufferBase &buffer) override
deserialization function
Definition LogString.cpp:76
LogStringArg & operator=(const LogStringArg &other)
assignment operator
Definition LogString.cpp:23
NATIVE_UINT_TYPE getCapacity() const override
return size of buffer
Definition LogString.cpp:53
SerializeStatus serialize(SerializeBufferBase &buffer) const override
serialization function
Definition LogString.cpp:57
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
SerializeStatus serialize(U8 val)
serialize 8-bit unsigned int
virtual const CHAR * toChar() const =0
NATIVE_UINT_TYPE length() const
Get length of string.
char * string_copy(char *destination, const char *source, U32 num)
copy string with null-termination guaranteed
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.