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
TlmString.cpp
Go to the documentation of this file.
3
4namespace Fw {
5
6 TlmString::TlmString(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 this->m_buf[0] = 0;
20 }
21
23 if(this == &other) {
24 return *this;
25 }
26
27 Fw::StringUtils::string_copy(this->m_buf, other.toChar(), sizeof(this->m_buf));
28 return *this;
29 }
30
32 if(this == &other) {
33 return *this;
34 }
35
36 Fw::StringUtils::string_copy(this->m_buf, other.toChar(), sizeof(this->m_buf));
37 return *this;
38 }
39
40 TlmString& TlmString::operator=(const char* other) {
41 Fw::StringUtils::string_copy(this->m_buf, other, sizeof(this->m_buf));
42 return *this;
43 }
44
46 }
47
48 const char* TlmString::toChar() const {
49 return this->m_buf;
50 }
51
54 }
55
57 return this->serialize(buffer, this->length());
58 }
59
61 NATIVE_INT_TYPE len = FW_MIN(maxLength,this->length());
62#if FW_AMPCS_COMPATIBLE
63 // serialize 8-bit size with null terminator removed
64 U8 strSize = len - 1;
65 SerializeStatus stat = buffer.serialize(strSize);
66 if (stat != FW_SERIALIZE_OK) {
67 return stat;
68 }
69 return buffer.serialize(reinterpret_cast<const U8*>(this->toChar()),strSize, true);
70#else
71 return buffer.serialize(reinterpret_cast<const U8*>(this->toChar()),len);
72#endif
73 }
74
76 NATIVE_UINT_TYPE maxSize = this->getCapacity() - 1;
77 CHAR* raw = const_cast<CHAR*>(this->toChar());
78
79#if FW_AMPCS_COMPATIBLE
80 // AMPCS encodes 8-bit string size
81 U8 strSize;
82 SerializeStatus stat = buffer.deserialize(strSize);
83 if (stat != FW_SERIALIZE_OK) {
84 return stat;
85 }
86 strSize = FW_MIN(maxSize,strSize);
87 stat = buffer.deserialize(reinterpret_cast<U8*>(raw),strSize,true);
88 // AMPCS Strings not null terminated
89 if(strSize < maxSize) {
90 raw[strSize] = 0;
91 }
92#else
93 SerializeStatus stat = buffer.deserialize(reinterpret_cast<U8*>(raw),maxSize);
94#endif
95
96 // Null terminate deserialized string
97 raw[maxSize] = 0;
98 return stat;
99 }
100}
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_TLM_STRING_MAX_SIZE
Max size of channelized telemetry string type.
Definition FpConfig.h:261
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.
const char * toChar() const override
Definition TlmString.cpp:48
NATIVE_UINT_TYPE getCapacity() const override
return size of buffer
Definition TlmString.cpp:52
SerializeStatus serialize(SerializeBufferBase &buffer) const override
serialization function
Definition TlmString.cpp:56
TlmString & operator=(const TlmString &other)
assignment operator
Definition TlmString.cpp:22
SerializeStatus deserialize(SerializeBufferBase &buffer) override
deserialization function
Definition TlmString.cpp:75
char * string_copy(char *destination, const char *source, U32 num)
copy string with null-termination guaranteed
Definition Buffer.cpp:21
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.