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.
1 #include <Fw/Tlm/TlmString.hpp>
3 
4 namespace 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 }
Fw::TlmString::operator=
TlmString & operator=(const TlmString &other)
assignment operator
Definition: TlmString.cpp:22
Fw::TlmString::TlmString
TlmString()
Definition: TlmString.cpp:18
Fw::TlmString
Definition: TlmString.hpp:11
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::StringBase
Definition: StringType.hpp:23
U8
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.hpp:76
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_MIN
#define FW_MIN(a, b)
MIN macro.
Definition: BasicTypes.hpp:104
Fw::TlmString::toChar
const char * toChar() const override
Definition: TlmString.cpp:48
Fw::StringUtils::string_copy
char * string_copy(char *destination, const char *source, U32 num)
copy string with null-termination guaranteed
Definition: StringUtils.cpp:5
TlmString.hpp
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::TlmString::deserialize
SerializeStatus deserialize(SerializeBufferBase &buffer) override
deserialization function
Definition: TlmString.cpp:75
FW_TLM_STRING_MAX_SIZE
#define FW_TLM_STRING_MAX_SIZE
Max size of channelized telemetry string type.
Definition: FpConfig.hpp:262
Fw::StringBase::toChar
virtual const CHAR * toChar() const =0
Fw::TlmString::serialize
SerializeStatus serialize(SerializeBufferBase &buffer) const override
serialization function
Definition: TlmString.cpp:56
NATIVE_INT_TYPE
int NATIVE_INT_TYPE
native integer type declaration
Definition: BasicTypes.hpp:29
Fw::TlmString::~TlmString
~TlmString()
Definition: TlmString.cpp:45
Fw::TlmString::getCapacity
NATIVE_UINT_TYPE getCapacity() const override
return size of buffer
Definition: TlmString.cpp:52
Fw
Definition: Buffer.cpp:21