F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
ApidManagerComponentAc.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title ApidManagerComponentAc.cpp
3 // \author Generated by fpp-to-cpp
4 // \brief cpp file for ApidManager component base class
5 // ======================================================================
6 
7 #include "Fw/Types/Assert.hpp"
9 #if FW_ENABLE_TEXT_LOGGING
10 #include "Fw/Types/String.hpp"
11 #endif
13 
14 namespace Svc {
15 
16  namespace Ccsds {
17 
18  // ----------------------------------------------------------------------
19  // Component initialization
20  // ----------------------------------------------------------------------
21 
24  {
25  // Initialize base class
27 
28 #if !FW_DIRECT_PORT_CALLS
29  // Connect input port getApidSeqCountIn
30  for (
31  FwIndexType port = 0;
32  port < static_cast<FwIndexType>(this->getNum_getApidSeqCountIn_InputPorts());
33  port++
34  ) {
35  this->m_getApidSeqCountIn_InputPort[port].init();
36  this->m_getApidSeqCountIn_InputPort[port].addCallComp(
37  this,
38  m_p_getApidSeqCountIn_in
39  );
40  this->m_getApidSeqCountIn_InputPort[port].setPortNum(port);
41 
42 #if FW_OBJECT_NAMES == 1
43  Fw::ObjectName portName;
44  portName.format(
45  "%s_getApidSeqCountIn_InputPort[%" PRI_FwIndexType "]",
46  this->m_objName.toChar(),
47  port
48  );
49  this->m_getApidSeqCountIn_InputPort[port].setObjName(portName.toChar());
50 #endif
51  }
52 #endif
53 
54 #if !FW_DIRECT_PORT_CALLS
55  // Connect input port validateApidSeqCountIn
56  for (
57  FwIndexType port = 0;
58  port < static_cast<FwIndexType>(this->getNum_validateApidSeqCountIn_InputPorts());
59  port++
60  ) {
61  this->m_validateApidSeqCountIn_InputPort[port].init();
62  this->m_validateApidSeqCountIn_InputPort[port].addCallComp(
63  this,
64  m_p_validateApidSeqCountIn_in
65  );
66  this->m_validateApidSeqCountIn_InputPort[port].setPortNum(port);
67 
68 #if FW_OBJECT_NAMES == 1
69  Fw::ObjectName portName;
70  portName.format(
71  "%s_validateApidSeqCountIn_InputPort[%" PRI_FwIndexType "]",
72  this->m_objName.toChar(),
73  port
74  );
75  this->m_validateApidSeqCountIn_InputPort[port].setObjName(portName.toChar());
76 #endif
77  }
78 #endif
79 
80 #if !FW_DIRECT_PORT_CALLS
81  // Connect output port logOut
82  for (
83  FwIndexType port = 0;
84  port < static_cast<FwIndexType>(this->getNum_logOut_OutputPorts());
85  port++
86  ) {
87  this->m_logOut_OutputPort[port].init();
88 
89 #if FW_OBJECT_NAMES == 1
90  Fw::ObjectName portName;
91  portName.format(
92  "%s_logOut_OutputPort[%" PRI_FwIndexType "]",
93  this->m_objName.toChar(),
94  port
95  );
96  this->m_logOut_OutputPort[port].setObjName(portName.toChar());
97 #endif
98  }
99 #endif
100 
101 #if !FW_DIRECT_PORT_CALLS && FW_ENABLE_TEXT_LOGGING
102  // Connect output port logTextOut
103  for (
104  FwIndexType port = 0;
105  port < static_cast<FwIndexType>(this->getNum_logTextOut_OutputPorts());
106  port++
107  ) {
108  this->m_logTextOut_OutputPort[port].init();
109 
110 #if FW_OBJECT_NAMES == 1
111  Fw::ObjectName portName;
112  portName.format(
113  "%s_logTextOut_OutputPort[%" PRI_FwIndexType "]",
114  this->m_objName.toChar(),
115  port
116  );
117  this->m_logTextOut_OutputPort[port].setObjName(portName.toChar());
118 #endif
119  }
120 #endif
121 
122 #if !FW_DIRECT_PORT_CALLS
123  // Connect output port timeCaller
124  for (
125  FwIndexType port = 0;
126  port < static_cast<FwIndexType>(this->getNum_timeCaller_OutputPorts());
127  port++
128  ) {
129  this->m_timeCaller_OutputPort[port].init();
130 
131 #if FW_OBJECT_NAMES == 1
132  Fw::ObjectName portName;
133  portName.format(
134  "%s_timeCaller_OutputPort[%" PRI_FwIndexType "]",
135  this->m_objName.toChar(),
136  port
137  );
138  this->m_timeCaller_OutputPort[port].setObjName(portName.toChar());
139 #endif
140  }
141 #endif
142  }
143 
144 #if !FW_DIRECT_PORT_CALLS
145 
146  // ----------------------------------------------------------------------
147  // Getters for typed input ports
148  // ----------------------------------------------------------------------
149 
152  {
153  FW_ASSERT(
154  (0 <= portNum) && (portNum < this->getNum_getApidSeqCountIn_InputPorts()),
155  static_cast<FwAssertArgType>(portNum)
156  );
157 
158  return &this->m_getApidSeqCountIn_InputPort[portNum];
159  }
160 
163  {
164  FW_ASSERT(
165  (0 <= portNum) && (portNum < this->getNum_validateApidSeqCountIn_InputPorts()),
166  static_cast<FwAssertArgType>(portNum)
167  );
168 
169  return &this->m_validateApidSeqCountIn_InputPort[portNum];
170  }
171 
172 #endif
173 
174 #if !FW_DIRECT_PORT_CALLS
175 
176  // ----------------------------------------------------------------------
177  // Connect input ports to special output ports
178  // ----------------------------------------------------------------------
179 
182  FwIndexType portNum,
183  Fw::InputLogPort* port
184  )
185  {
186  FW_ASSERT(
187  (0 <= portNum) && (portNum < this->getNum_logOut_OutputPorts()),
188  static_cast<FwAssertArgType>(portNum)
189  );
190 
191  this->m_logOut_OutputPort[portNum].addCallPort(port);
192  }
193 
194 #if FW_ENABLE_TEXT_LOGGING == 1
195 
196  void ApidManagerComponentBase ::
197  set_logTextOut_OutputPort(
198  FwIndexType portNum,
200  )
201  {
202  FW_ASSERT(
203  (0 <= portNum) && (portNum < this->getNum_logTextOut_OutputPorts()),
204  static_cast<FwAssertArgType>(portNum)
205  );
206 
207  this->m_logTextOut_OutputPort[portNum].addCallPort(port);
208  }
209 
210 #endif
211 
214  FwIndexType portNum,
215  Fw::InputTimePort* port
216  )
217  {
218  FW_ASSERT(
219  (0 <= portNum) && (portNum < this->getNum_timeCaller_OutputPorts()),
220  static_cast<FwAssertArgType>(portNum)
221  );
222 
223  this->m_timeCaller_OutputPort[portNum].addCallPort(port);
224  }
225 
226 #endif
227 
228 #if !FW_DIRECT_PORT_CALLS && FW_PORT_SERIALIZATION
229 
230  // ----------------------------------------------------------------------
231  // Connect serial input ports to special output ports
232  // ----------------------------------------------------------------------
233 
236  FwIndexType portNum,
237  Fw::InputSerializePort* port
238  )
239  {
240  FW_ASSERT(
241  (0 <= portNum) && (portNum < this->getNum_logOut_OutputPorts()),
242  static_cast<FwAssertArgType>(portNum)
243  );
244 
245  this->m_logOut_OutputPort[portNum].registerSerialPort(port);
246  }
247 
248 #if FW_ENABLE_TEXT_LOGGING == 1
249 
250  void ApidManagerComponentBase ::
251  set_logTextOut_OutputPort(
252  FwIndexType portNum,
253  Fw::InputSerializePort* port
254  )
255  {
256  FW_ASSERT(
257  (0 <= portNum) && (portNum < this->getNum_logTextOut_OutputPorts()),
258  static_cast<FwAssertArgType>(portNum)
259  );
260 
261  this->m_logTextOut_OutputPort[portNum].registerSerialPort(port);
262  }
263 
264 #endif
265 
268  FwIndexType portNum,
269  Fw::InputSerializePort* port
270  )
271  {
272  FW_ASSERT(
273  (0 <= portNum) && (portNum < this->getNum_timeCaller_OutputPorts()),
274  static_cast<FwAssertArgType>(portNum)
275  );
276 
277  this->m_timeCaller_OutputPort[portNum].registerSerialPort(port);
278  }
279 
280 #endif
281 
282  // ----------------------------------------------------------------------
283  // Component construction and destruction
284  // ----------------------------------------------------------------------
285 
287  ApidManagerComponentBase(const char* compName) :
288  Fw::PassiveComponentBase(compName)
289  {
290 
291  }
292 
295  {
296 
297  }
298 
299 #if !FW_DIRECT_PORT_CALLS
300 
301  // ----------------------------------------------------------------------
302  // Connection status queries for special output ports
303  // ----------------------------------------------------------------------
304 
307  {
308  FW_ASSERT(
309  (0 <= portNum) && (portNum < this->getNum_logOut_OutputPorts()),
310  static_cast<FwAssertArgType>(portNum)
311  );
312 
313  return this->m_logOut_OutputPort[portNum].isConnected();
314  }
315 
316 #if FW_ENABLE_TEXT_LOGGING == 1
317 
318  bool ApidManagerComponentBase ::
319  isConnected_logTextOut_OutputPort(FwIndexType portNum) const
320  {
321  FW_ASSERT(
322  (0 <= portNum) && (portNum < this->getNum_logTextOut_OutputPorts()),
323  static_cast<FwAssertArgType>(portNum)
324  );
325 
326  return this->m_logTextOut_OutputPort[portNum].isConnected();
327  }
328 
329 #endif
330 
333  {
334  FW_ASSERT(
335  (0 <= portNum) && (portNum < this->getNum_timeCaller_OutputPorts()),
336  static_cast<FwAssertArgType>(portNum)
337  );
338 
339  return this->m_timeCaller_OutputPort[portNum].isConnected();
340  }
341 
342 #endif
343 
344  // ----------------------------------------------------------------------
345  // Port handler base-class functions for typed input ports
346  //
347  // Call these functions directly to bypass the corresponding ports
348  // ----------------------------------------------------------------------
349 
352  FwIndexType portNum,
353  const ComCfg::Apid& apid,
354  U16 sequenceCount
355  )
356  {
357  // Make sure port number is valid
358  FW_ASSERT(
359  (0 <= portNum) && (portNum < this->getNum_getApidSeqCountIn_InputPorts()),
360  static_cast<FwAssertArgType>(portNum)
361  );
362 
363  U16 retVal;
364 
365  // Lock guard mutex before calling
366  this->lock();
367 
368  // Call handler function
369  retVal = this->getApidSeqCountIn_handler(
370  portNum,
371  apid,
372  sequenceCount
373  );
374 
375  // Unlock guard mutex
376  this->unLock();
377 
378  return retVal;
379  }
380 
383  FwIndexType portNum,
384  const ComCfg::Apid& apid,
385  U16 sequenceCount
386  )
387  {
388  // Make sure port number is valid
389  FW_ASSERT(
390  (0 <= portNum) && (portNum < this->getNum_validateApidSeqCountIn_InputPorts()),
391  static_cast<FwAssertArgType>(portNum)
392  );
393 
394  U16 retVal;
395 
396  // Lock guard mutex before calling
397  this->lock();
398 
399  // Call handler function
400  retVal = this->validateApidSeqCountIn_handler(
401  portNum,
402  apid,
403  sequenceCount
404  );
405 
406  // Unlock guard mutex
407  this->unLock();
408 
409  return retVal;
410  }
411 
412  // ----------------------------------------------------------------------
413  // Event logging functions
414  // ----------------------------------------------------------------------
415 
418  U16 transmitted,
419  U16 expected
420  ) const
421  {
422  // Get the time
423  Fw::Time _logTime;
424  if (this->isConnected_timeCaller_OutputPort(0)) {
425  this->timeCaller_out(0, _logTime);
426  }
427 
429 
430  // Emit the event on the log port
431  if (this->isConnected_logOut_OutputPort(0)) {
432  Fw::LogBuffer _logBuff;
434 
435 #if FW_AMPCS_COMPATIBLE
436  // Serialize the number of arguments
437  _status = _logBuff.serializeFrom(static_cast<U8>(2));
438  FW_ASSERT(
439  _status == Fw::FW_SERIALIZE_OK,
440  static_cast<FwAssertArgType>(_status)
441  );
442 #endif
443 
444 #if FW_AMPCS_COMPATIBLE
445  // Serialize the argument size
446  _status = _logBuff.serializeFrom(
447  static_cast<U8>(sizeof(U16))
448  );
449  FW_ASSERT(
450  _status == Fw::FW_SERIALIZE_OK,
451  static_cast<FwAssertArgType>(_status)
452  );
453 #endif
454  _status = _logBuff.serializeFrom(transmitted);
455  FW_ASSERT(
456  _status == Fw::FW_SERIALIZE_OK,
457  static_cast<FwAssertArgType>(_status)
458  );
459 
460 #if FW_AMPCS_COMPATIBLE
461  // Serialize the argument size
462  _status = _logBuff.serializeFrom(
463  static_cast<U8>(sizeof(U16))
464  );
465  FW_ASSERT(
466  _status == Fw::FW_SERIALIZE_OK,
467  static_cast<FwAssertArgType>(_status)
468  );
469 #endif
470  _status = _logBuff.serializeFrom(expected);
471  FW_ASSERT(
472  _status == Fw::FW_SERIALIZE_OK,
473  static_cast<FwAssertArgType>(_status)
474  );
475 
476  this->logOut_out(
477  0,
478  _id,
479  _logTime,
481  _logBuff
482  );
483  }
484 
485  // Emit the event on the text log port
486 #if FW_ENABLE_TEXT_LOGGING
487  if (this->isConnected_logTextOut_OutputPort(0)) {
488 #if FW_OBJECT_NAMES == 1
489  const char* _formatString =
490  "(%s) %s: Unexpected sequence count received. Packets may have been dropped. Transmitted: %" PRIu16 " | Expected on board: %" PRIu16 "";
491 #else
492  const char* _formatString =
493  "%s: Unexpected sequence count received. Packets may have been dropped. Transmitted: %" PRIu16 " | Expected on board: %" PRIu16 "";
494 #endif
495 
496  Fw::TextLogString _logString;
497  (void) _logString.format(
498  _formatString,
499 #if FW_OBJECT_NAMES == 1
500  this->m_objName.toChar(),
501 #endif
502  "UnexpectedSequenceCount ",
503  transmitted,
504  expected
505  );
506 
507  this->logTextOut_out(
508  0,
509  _id,
510  _logTime,
512  _logString
513  );
514  }
515 #endif
516  }
517 
518  // ----------------------------------------------------------------------
519  // Time
520  // ----------------------------------------------------------------------
521 
523  getTime() const
524  {
525  if (this->isConnected_timeCaller_OutputPort(0)) {
526  Fw::Time _time;
527  this->timeCaller_out(0, _time);
528  return _time;
529  }
530  else {
531  return Fw::Time(TimeBase::TB_NONE, 0, 0);
532  }
533  }
534 
535  // ----------------------------------------------------------------------
536  // Mutex operations for guarded ports
537  //
538  // You can override these operations to provide more sophisticated
539  // synchronization
540  // ----------------------------------------------------------------------
541 
544  {
545  this->m_guardedPortMutex.lock();
546  }
547 
550  {
551  this->m_guardedPortMutex.unLock();
552  }
553 
554  // ----------------------------------------------------------------------
555  // Calls for messages received on typed input ports
556  // ----------------------------------------------------------------------
557 
558  U16 ApidManagerComponentBase ::
559  m_p_getApidSeqCountIn_in(
560  Fw::PassiveComponentBase* callComp,
561  FwIndexType portNum,
562  const ComCfg::Apid& apid,
563  U16 sequenceCount
564  )
565  {
566  FW_ASSERT(callComp != nullptr);
567  ApidManagerComponentBase* compPtr = static_cast<ApidManagerComponentBase*>(callComp);
568  return compPtr->getApidSeqCountIn_handlerBase(
569  portNum,
570  apid,
571  sequenceCount
572  );
573  }
574 
575  U16 ApidManagerComponentBase ::
576  m_p_validateApidSeqCountIn_in(
577  Fw::PassiveComponentBase* callComp,
578  FwIndexType portNum,
579  const ComCfg::Apid& apid,
580  U16 sequenceCount
581  )
582  {
583  FW_ASSERT(callComp != nullptr);
584  ApidManagerComponentBase* compPtr = static_cast<ApidManagerComponentBase*>(callComp);
585  return compPtr->validateApidSeqCountIn_handlerBase(
586  portNum,
587  apid,
588  sequenceCount
589  );
590  }
591 
592 #if !FW_DIRECT_PORT_CALLS
593 
594  // ----------------------------------------------------------------------
595  // Invocation functions for special output ports
596  // ----------------------------------------------------------------------
597 
598  void ApidManagerComponentBase ::
599  logOut_out(
600  FwIndexType portNum,
601  FwEventIdType id,
602  Fw::Time& timeTag,
603  const Fw::LogSeverity& severity,
604  Fw::LogBuffer& args
605  ) const
606  {
607  FW_ASSERT(
608  (0 <= portNum) && (portNum < this->getNum_logOut_OutputPorts()),
609  static_cast<FwAssertArgType>(portNum)
610  );
611 
612  FW_ASSERT(
613  this->m_logOut_OutputPort[portNum].isConnected(),
614  static_cast<FwAssertArgType>(portNum)
615  );
616  this->m_logOut_OutputPort[portNum].invoke(
617  id,
618  timeTag,
619  severity,
620  args
621  );
622  }
623 
624 #if FW_ENABLE_TEXT_LOGGING
625 
626  void ApidManagerComponentBase ::
627  logTextOut_out(
628  FwIndexType portNum,
629  FwEventIdType id,
630  Fw::Time& timeTag,
631  const Fw::LogSeverity& severity,
632  Fw::TextLogString& text
633  ) const
634  {
635  FW_ASSERT(
636  (0 <= portNum) && (portNum < this->getNum_logTextOut_OutputPorts()),
637  static_cast<FwAssertArgType>(portNum)
638  );
639 
640  FW_ASSERT(
641  this->m_logTextOut_OutputPort[portNum].isConnected(),
642  static_cast<FwAssertArgType>(portNum)
643  );
644  this->m_logTextOut_OutputPort[portNum].invoke(
645  id,
646  timeTag,
647  severity,
648  text
649  );
650  }
651 
652 #endif
653 
654  void ApidManagerComponentBase ::
655  timeCaller_out(
656  FwIndexType portNum,
657  Fw::Time& time
658  ) const
659  {
660  FW_ASSERT(
661  (0 <= portNum) && (portNum < this->getNum_timeCaller_OutputPorts()),
662  static_cast<FwAssertArgType>(portNum)
663  );
664 
665  FW_ASSERT(
666  this->m_timeCaller_OutputPort[portNum].isConnected(),
667  static_cast<FwAssertArgType>(portNum)
668  );
669  this->m_timeCaller_OutputPort[portNum].invoke(
670  time
671  );
672  }
673 
674 #endif
675 
676  }
677 
678 }
Serialization/Deserialization operation was successful.
void set_timeCaller_OutputPort(FwIndexType portNum, Fw::InputTimePort *port)
Connect port to timeCaller[portNum].
void addCallPort(InputTimePort *callPort)
Register an input port.
Definition: TimePortAc.cpp:157
SerializeStatus serializeFrom(U8 val, Endianness mode=Endianness::BIG) override
Serialize an 8-bit unsigned integer value.
virtual void unLock()
Unlock the guarded mutex.
I32 FwEnumStoreType
void unLock()
unlock the mutex and assert success
Definition: Mutex.cpp:41
virtual ~ApidManagerComponentBase()
Destroy ApidManagerComponentBase object.
No time base has been established (Required)
static constexpr FwIndexType getNum_getApidSeqCountIn_InputPorts()
void init()
Object initializer.
Definition: ObjBase.cpp:24
static constexpr FwIndexType getNum_timeCaller_OutputPorts()
Svc::Ccsds::InputApidSequenceCountPort * get_validateApidSeqCountIn_InputPort(FwIndexType portNum)
SerializeStatus
forward declaration for string
FwIdType FwEventIdType
The type of an event identifier.
#define FW_OBJECT_NAMES
Indicates whether or not object names are stored (more memory, can be used for tracking objects) ...
Definition: FpConfig.h:40
void init()
Initialization function.
Definition: TimePortAc.cpp:151
A less serious but recoverable event.
void invoke(Fw::Time &time) const
Invoke a port connection.
Definition: TimePortAc.cpp:170
ApidManagerComponentBase(const char *compName="")
Construct ApidManagerComponentBase object.
virtual U16 validateApidSeqCountIn_handler(FwIndexType portNum, const ComCfg::Apid &apid, U16 sequenceCount)=0
Handler for input port validateApidSeqCountIn.
const char * toChar() const
Convert to a C-style char*.
bool isConnected() const
Definition: PortBase.cpp:38
Enum representing event severity.
#define PRI_FwIndexType
FormatStatus format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:58
void init()
Initialization function.
Definition: LogPortAc.cpp:180
void setPortNum(FwIndexType portNum)
void log_WARNING_LO_UnexpectedSequenceCount(U16 transmitted, U16 expected) const
void invoke(FwEventIdType id, Fw::Time &timeTag, const Fw::LogSeverity &severity, Fw::LogBuffer &args) const
Invoke a port connection.
Definition: LogPortAc.cpp:199
virtual void lock()
Lock the guarded mutex.
static constexpr FwIndexType getNum_logOut_OutputPorts()
U16 getApidSeqCountIn_handlerBase(FwIndexType portNum, const ComCfg::Apid &apid, U16 sequenceCount)
Handler base-class function for input port getApidSeqCountIn.
PlatformIndexType FwIndexType
U16 validateApidSeqCountIn_handlerBase(FwIndexType portNum, const ComCfg::Apid &apid, U16 sequenceCount)
Handler base-class function for input port validateApidSeqCountIn.
bool isConnected_logOut_OutputPort(FwIndexType portNum) const
void addCallPort(InputLogPort *callPort)
Register an input port.
Definition: LogPortAc.cpp:186
void set_logOut_OutputPort(FwIndexType portNum, Fw::InputLogPort *port)
Connect port to logOut[portNum].
RateGroupDivider component implementation.
Auto-generated base for ApidManager component.
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
Implementation of malloc based allocator.
static constexpr FwIndexType getNum_validateApidSeqCountIn_InputPorts()
Svc::Ccsds::InputApidSequenceCountPort * get_getApidSeqCountIn_InputPort(FwIndexType portNum)
#define FW_ASSERT(...)
Definition: Assert.hpp:14
APIDs are 11 bits in the Space Packet protocol, so we use U16. Max value 7FF.
Definition: ApidEnumAc.hpp:18
bool isConnected_timeCaller_OutputPort(FwIndexType portNum) const
virtual U16 getApidSeqCountIn_handler(FwIndexType portNum, const ComCfg::Apid &apid, U16 sequenceCount)=0
Handler for input port getApidSeqCountIn.
void lock()
lock the mutex and assert success
Definition: Mutex.cpp:34