F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
PortBase.cpp
Go to the documentation of this file.
2 #include <Fw/Logger/Logger.hpp>
3 #include <Fw/Port/PortBase.hpp>
4 #include <cstdio>
5 #include "Fw/Types/Assert.hpp"
7 
8 #if FW_PORT_TRACING
9 void setConnTrace(bool trace) {
10  Fw::PortBase::setTrace(trace);
11 }
12 
13 namespace Fw {
14 bool PortBase::s_trace = false;
15 }
16 
17 #endif // FW_PORT_TRACING
18 
19 namespace Fw {
20 
22  : Fw::ObjBase(nullptr),
23  m_connObj(nullptr)
24 #if FW_PORT_TRACING == 1
25  ,
26  m_trace(false),
27  m_ovr_trace(false)
28 #endif
29 {
30 }
31 
33 
35  ObjBase::init();
36 }
37 
38 bool PortBase::isConnected() const {
39  return m_connObj == nullptr ? false : true;
40 }
41 
42 #if FW_PORT_TRACING == 1
43 
44 void PortBase::trace() const {
45  bool do_trace = false;
46 
47  if (this->m_ovr_trace) {
48  if (this->m_trace) {
49  do_trace = true;
50  }
51  } else if (PortBase::s_trace) {
52  do_trace = true;
53  }
54 
55  if (do_trace) {
56 #if FW_OBJECT_NAMES == 1
57  Fw::Logger::log("Trace: %s\n", this->m_objName.toChar());
58 #else
59  Fw::Logger::log("Trace: %p\n", this);
60 #endif
61  }
62 }
63 
64 void PortBase::setTrace(bool trace) {
65  PortBase::s_trace = trace;
66 }
67 
68 void PortBase::ovrTrace(bool ovr, bool trace) {
69  this->m_ovr_trace = ovr;
70  this->m_trace = trace;
71 }
72 
73 #endif // FW_PORT_TRACING
74 
75 #if FW_OBJECT_TO_STRING == 1
76 const char* PortBase::getToStringFormatString() {
77  return "Port: %s %s->(%s)";
78 }
79 
80 void PortBase::toString(char* buffer, FwSizeType size) {
81  FW_ASSERT(size > 0);
82  // Get the port-custom format string
83  const char* formatString = this->getToStringFormatString();
84  // Determine this port object name (or use "UNKNOWN")
85  const char* object_name =
86 #if FW_OBJECT_NAMES == 1
87  this->m_objName.toChar();
88 #else
89  "UNKNOWN";
90 #endif
91  // Get the C/NC for connected or not
92  const char* this_is_connected = this->isConnected() ? "C" : "NC";
93 
94  // Get the name of the connection object, "UNKNOWN" or "NONE"
95  const char* connected_to = this->isConnected() ?
96 #if FW_OBJECT_NAMES == 1
97  this->m_connObj->getObjName()
98 #else
99  "UNKNOWN"
100 #endif
101  : "None";
102  // Format the external string or use "" on error
103  if (Fw::ExternalString(buffer, static_cast<Fw::ExternalString::SizeType>(size))
104  .format(formatString, object_name, this_is_connected, connected_to) != Fw::FormatStatus::SUCCESS) {
105  buffer[0] = 0;
106  }
107 }
108 #endif // FW_OBJECT_TO_STRING
109 
110 } // namespace Fw
PlatformSizeType FwSizeType
static void log(const char *format,...)
log a formated string with supplied arguments
Definition: Logger.cpp:21
virtual void init()
Definition: PortBase.cpp:34
void init()
Object initializer.
Definition: ObjBase.cpp:24
Brief class description.
Definition: ObjBase.hpp:35
A string backed by an external buffer.
bool isConnected() const
Definition: PortBase.cpp:38
#define FW_PORT_TRACING
Indicates whether port calls are traced (more code, more visibility into execution) ...
Definition: FpConfig.h:86
virtual ~PortBase()
Definition: PortBase.cpp:32
Fw::ObjBase * m_connObj
Definition: PortBase.hpp:34
#define FW_ASSERT(...)
Definition: Assert.hpp:14