F´ Flight Software - C/C++ Documentation  NASA-v1.5.0
A framework for building embedded system applications to NASA flight quality standards.
CmdString.cpp
Go to the documentation of this file.
3 #include <Fw/Cmd/CmdString.hpp>
4 #include <Fw/Types/Assert.hpp>
5 #include <string.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 
9 namespace Fw {
10 
11  CmdStringArg::CmdStringArg(const char* src) : StringBase() {
12  this->copyBuff(src,this->getCapacity());
13  }
14 
16  this->copyBuff(src.toChar(),this->getCapacity());
17  }
18 
20  this->copyBuff(src.m_buf,this->getCapacity());
21  }
22 
24  this->m_buf[0] = 0;
25  }
26 
28  }
29 
31  return strnlen(this->m_buf,sizeof(this->m_buf));
32  }
33 
34  const char* CmdStringArg::toChar(void) const {
35  return this->m_buf;
36  }
37 
38  void CmdStringArg::copyBuff(const char* buff, NATIVE_UINT_TYPE size) {
39  FW_ASSERT(buff);
40  // check for self copy
41  if (buff != this->m_buf) {
42  (void)strncpy(this->m_buf,buff,size);
43  // NULL terminate
44  this->terminate(sizeof(this->m_buf));
45  }
46  }
47 
49  this->copyBuff(other.m_buf,this->getCapacity());
50  return *this;
51  }
52 
54  NATIVE_UINT_TYPE strSize = strnlen(this->m_buf,sizeof(this->m_buf));
55  // serialize string
56  return buffer.serialize((U8*)this->m_buf,strSize);
57  }
58 
60  NATIVE_UINT_TYPE maxSize = sizeof(this->m_buf);
61  // deserialize string
62  SerializeStatus stat = buffer.deserialize((U8*)this->m_buf,maxSize);
63  // make sure it is null-terminated
64  this->terminate(maxSize);
65 
66  return stat;
67  }
68 
69  NATIVE_UINT_TYPE CmdStringArg::getCapacity(void) const {
71  }
72 
73  void CmdStringArg::terminate(NATIVE_UINT_TYPE size) {
74  // null terminate the string
75  this->m_buf[size < sizeof(this->m_buf)?size:sizeof(this->m_buf)-1] = 0;
76  }
77 
78 }
StringType.hpp
Declares ISF string base class.
Fw::CmdStringArg::deserialize
SerializeStatus deserialize(SerializeBufferBase &buffer)
deserialize to contents
Definition: CmdString.cpp:59
Fw::SerializeBufferBase
Definition: Serializable.hpp:43
Fw::SerializeStatus
SerializeStatus
forward declaration for string
Definition: Serializable.hpp:14
Fw::CmdStringArg::toChar
const char * toChar(void) const
Definition: CmdString.cpp:34
FW_CMD_STRING_MAX_SIZE
#define FW_CMD_STRING_MAX_SIZE
Max character size of command string arguments.
Definition: FpConfig.hpp:231
Fw::SerializeBufferBase::serialize
SerializeStatus serialize(U8 val)
serialize 8-bit unsigned int
Definition: Serializable.cpp:67
Fw::CmdStringArg::serialize
SerializeStatus serialize(SerializeBufferBase &buffer) const
serialize contents
Definition: CmdString.cpp:53
Fw::StringBase
Definition: StringType.hpp:23
U8
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.hpp:76
Fw::CmdStringArg::operator=
const CmdStringArg & operator=(const CmdStringArg &other)
equal operator for other strings
Definition: CmdString.cpp:48
Fw::CmdStringArg
Definition: CmdString.hpp:11
Assert.hpp
Fw::StringBase::toChar
virtual const char * toChar(void) const =0
NATIVE_UINT_TYPE
unsigned int NATIVE_UINT_TYPE
native unsigned integer type declaration
Definition: BasicTypes.hpp:30
CmdString.hpp
FW_ASSERT
#define FW_ASSERT(...)
Definition: Assert.hpp:9
Fw::CmdStringArg::CmdStringArg
CmdStringArg(void)
Definition: CmdString.cpp:23
Fw::SerializeBufferBase::deserialize
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
Definition: Serializable.cpp:292
BasicTypes.hpp
Declares ISF basic types.
Fw::CmdStringArg::~CmdStringArg
~CmdStringArg(void)
Definition: CmdString.cpp:27
Fw::CmdStringArg::length
NATIVE_UINT_TYPE length(void) const
Get length of string.
Definition: CmdString.cpp:30
Fw
Definition: BufferGetPortAc.cpp:6