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.
1 #include <Fw/Port/PortBase.hpp>
2 #include <FpConfig.hpp>
3 #include <Fw/Logger/Logger.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  :
23  Fw::ObjBase(nullptr),
24  m_connObj(nullptr)
25 #if FW_PORT_TRACING == 1
26  ,m_trace(false),
27  m_ovr_trace(false)
28 #endif
29  {
30 
31  }
32 
34 
35  }
36 
37  void PortBase::init() {
38  ObjBase::init();
39 
40  }
41 
42  bool PortBase::isConnected() const {
43  return m_connObj == nullptr?false:true;
44  }
45 
46 #if FW_PORT_TRACING == 1
47 
48  void PortBase::trace() const {
49  bool do_trace = false;
50 
51  if (this->m_ovr_trace) {
52  if (this->m_trace) {
53  do_trace = true;
54  }
55  } else if (PortBase::s_trace) {
56  do_trace = true;
57  }
58 
59  if (do_trace) {
60 #if FW_OBJECT_NAMES == 1
61  Fw::Logger::log("Trace: %s\n", this->m_objName.toChar());
62 #else
63  Fw::Logger::log("Trace: %p\n", this);
64 #endif
65  }
66  }
67 
68  void PortBase::setTrace(bool trace) {
69  PortBase::s_trace = trace;
70  }
71 
72  void PortBase::ovrTrace(bool ovr, bool trace) {
73  this->m_ovr_trace = ovr;
74  this->m_trace = trace;
75  }
76 
77 #endif // FW_PORT_TRACING
78 
79 #if FW_OBJECT_TO_STRING == 1
80  const char* PortBase::getToStringFormatString() {
81  return "Port: %s %s->(%s)";
82  }
83 
84  void PortBase::toString(char* buffer, NATIVE_INT_TYPE size) {
85  FW_ASSERT(size > 0);
86  // Get the port-custom format string
87  const char* formatString = this->getToStringFormatString();
88  // Determine this port object name (or use "UNKNOWN")
89  const char* object_name =
90 #if FW_OBJECT_NAMES == 1
91  this->m_objName.toChar();
92 #else
93  "UNKNOWN";
94 #endif
95  // Get the C/NC for connected or not
96  const char* this_is_connected = this->isConnected() ? "C" : "NC";
97 
98  // Get the name of the connection object, "UNKNOWN" or "NONE"
99  const char* connected_to = this->isConnected() ?
100 #if FW_OBJECT_NAMES == 1
101  this->m_connObj->getObjName()
102 #else
103  "UNKNOWN"
104 #endif
105  : "None";
106  // Format the external string or use "" on error
107  if (Fw::ExternalString(buffer, static_cast<Fw::ExternalString::SizeType>(size)).format(
108  formatString,
109  object_name,
110  this_is_connected,
111  connected_to) != Fw::FormatStatus::SUCCESS) {
112  buffer[0] = 0;
113  }
114  }
115 #endif // FW_OBJECT_TO_STRING
116 
117 
118 }
119 
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:55
static void log(const char *format,...)
log a formated string with supplied arguments
Definition: Logger.cpp:21
virtual void init()
Definition: PortBase.cpp:37
void init()
Object initializer.
Definition: ObjBase.cpp:26
#define FW_PORT_TRACING
Indicates whether port calls are traced (more code, more visibility into execution) ...
Definition: FpConfig.h:199
Brief class description.
Definition: ObjBase.hpp:35
A string backed by an external buffer.
bool isConnected() const
Definition: PortBase.cpp:42
C++-compatible configuration header for fprime configuration.
virtual ~PortBase()
Definition: PortBase.cpp:33
Fw::ObjBase * m_connObj
Definition: PortBase.hpp:33
#define FW_ASSERT(...)
Definition: Assert.hpp:14