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  // Connect input port getApidSeqCountIn
29  for (
30  FwIndexType port = 0;
31  port < static_cast<FwIndexType>(this->getNum_getApidSeqCountIn_InputPorts());
32  port++
33  ) {
34  this->m_getApidSeqCountIn_InputPort[port].init();
35  this->m_getApidSeqCountIn_InputPort[port].addCallComp(
36  this,
37  m_p_getApidSeqCountIn_in
38  );
39  this->m_getApidSeqCountIn_InputPort[port].setPortNum(port);
40 
41 #if FW_OBJECT_NAMES == 1
42  Fw::ObjectName portName;
43  portName.format(
44  "%s_getApidSeqCountIn_InputPort[%" PRI_FwIndexType "]",
45  this->m_objName.toChar(),
46  port
47  );
48  this->m_getApidSeqCountIn_InputPort[port].setObjName(portName.toChar());
49 #endif
50  }
51 
52  // Connect input port validateApidSeqCountIn
53  for (
54  FwIndexType port = 0;
55  port < static_cast<FwIndexType>(this->getNum_validateApidSeqCountIn_InputPorts());
56  port++
57  ) {
58  this->m_validateApidSeqCountIn_InputPort[port].init();
59  this->m_validateApidSeqCountIn_InputPort[port].addCallComp(
60  this,
61  m_p_validateApidSeqCountIn_in
62  );
63  this->m_validateApidSeqCountIn_InputPort[port].setPortNum(port);
64 
65 #if FW_OBJECT_NAMES == 1
66  Fw::ObjectName portName;
67  portName.format(
68  "%s_validateApidSeqCountIn_InputPort[%" PRI_FwIndexType "]",
69  this->m_objName.toChar(),
70  port
71  );
72  this->m_validateApidSeqCountIn_InputPort[port].setObjName(portName.toChar());
73 #endif
74  }
75 
76  // Connect output port logOut
77  for (
78  FwIndexType port = 0;
79  port < static_cast<FwIndexType>(this->getNum_logOut_OutputPorts());
80  port++
81  ) {
82  this->m_logOut_OutputPort[port].init();
83 
84 #if FW_OBJECT_NAMES == 1
85  Fw::ObjectName portName;
86  portName.format(
87  "%s_logOut_OutputPort[%" PRI_FwIndexType "]",
88  this->m_objName.toChar(),
89  port
90  );
91  this->m_logOut_OutputPort[port].setObjName(portName.toChar());
92 #endif
93  }
94 
95 #if FW_ENABLE_TEXT_LOGGING == 1
96  // Connect output port logTextOut
97  for (
98  FwIndexType port = 0;
99  port < static_cast<FwIndexType>(this->getNum_logTextOut_OutputPorts());
100  port++
101  ) {
102  this->m_logTextOut_OutputPort[port].init();
103 
104 #if FW_OBJECT_NAMES == 1
105  Fw::ObjectName portName;
106  portName.format(
107  "%s_logTextOut_OutputPort[%" PRI_FwIndexType "]",
108  this->m_objName.toChar(),
109  port
110  );
111  this->m_logTextOut_OutputPort[port].setObjName(portName.toChar());
112 #endif
113  }
114 #endif
115 
116  // Connect output port timeCaller
117  for (
118  FwIndexType port = 0;
119  port < static_cast<FwIndexType>(this->getNum_timeCaller_OutputPorts());
120  port++
121  ) {
122  this->m_timeCaller_OutputPort[port].init();
123 
124 #if FW_OBJECT_NAMES == 1
125  Fw::ObjectName portName;
126  portName.format(
127  "%s_timeCaller_OutputPort[%" PRI_FwIndexType "]",
128  this->m_objName.toChar(),
129  port
130  );
131  this->m_timeCaller_OutputPort[port].setObjName(portName.toChar());
132 #endif
133  }
134  }
135 
136  // ----------------------------------------------------------------------
137  // Getters for typed input ports
138  // ----------------------------------------------------------------------
139 
142  {
143  FW_ASSERT(
144  (0 <= portNum) && (portNum < this->getNum_getApidSeqCountIn_InputPorts()),
145  static_cast<FwAssertArgType>(portNum)
146  );
147 
148  return &this->m_getApidSeqCountIn_InputPort[portNum];
149  }
150 
153  {
154  FW_ASSERT(
155  (0 <= portNum) && (portNum < this->getNum_validateApidSeqCountIn_InputPorts()),
156  static_cast<FwAssertArgType>(portNum)
157  );
158 
159  return &this->m_validateApidSeqCountIn_InputPort[portNum];
160  }
161 
162  // ----------------------------------------------------------------------
163  // Connect input ports to special output ports
164  // ----------------------------------------------------------------------
165 
168  FwIndexType portNum,
169  Fw::InputLogPort* port
170  )
171  {
172  FW_ASSERT(
173  (0 <= portNum) && (portNum < this->getNum_logOut_OutputPorts()),
174  static_cast<FwAssertArgType>(portNum)
175  );
176 
177  this->m_logOut_OutputPort[portNum].addCallPort(port);
178  }
179 
180 #if FW_ENABLE_TEXT_LOGGING == 1
181 
182  void ApidManagerComponentBase ::
183  set_logTextOut_OutputPort(
184  FwIndexType portNum,
186  )
187  {
188  FW_ASSERT(
189  (0 <= portNum) && (portNum < this->getNum_logTextOut_OutputPorts()),
190  static_cast<FwAssertArgType>(portNum)
191  );
192 
193  this->m_logTextOut_OutputPort[portNum].addCallPort(port);
194  }
195 
196 #endif
197 
200  FwIndexType portNum,
201  Fw::InputTimePort* port
202  )
203  {
204  FW_ASSERT(
205  (0 <= portNum) && (portNum < this->getNum_timeCaller_OutputPorts()),
206  static_cast<FwAssertArgType>(portNum)
207  );
208 
209  this->m_timeCaller_OutputPort[portNum].addCallPort(port);
210  }
211 
212 #if FW_PORT_SERIALIZATION
213 
214  // ----------------------------------------------------------------------
215  // Connect serial input ports to special output ports
216  // ----------------------------------------------------------------------
217 
220  FwIndexType portNum,
221  Fw::InputSerializePort* port
222  )
223  {
224  FW_ASSERT(
225  (0 <= portNum) && (portNum < this->getNum_logOut_OutputPorts()),
226  static_cast<FwAssertArgType>(portNum)
227  );
228 
229  this->m_logOut_OutputPort[portNum].registerSerialPort(port);
230  }
231 
232 #if FW_ENABLE_TEXT_LOGGING == 1
233 
234  void ApidManagerComponentBase ::
235  set_logTextOut_OutputPort(
236  FwIndexType portNum,
237  Fw::InputSerializePort* port
238  )
239  {
240  FW_ASSERT(
241  (0 <= portNum) && (portNum < this->getNum_logTextOut_OutputPorts()),
242  static_cast<FwAssertArgType>(portNum)
243  );
244 
245  this->m_logTextOut_OutputPort[portNum].registerSerialPort(port);
246  }
247 
248 #endif
249 
252  FwIndexType portNum,
253  Fw::InputSerializePort* port
254  )
255  {
256  FW_ASSERT(
257  (0 <= portNum) && (portNum < this->getNum_timeCaller_OutputPorts()),
258  static_cast<FwAssertArgType>(portNum)
259  );
260 
261  this->m_timeCaller_OutputPort[portNum].registerSerialPort(port);
262  }
263 
264 #endif
265 
266  // ----------------------------------------------------------------------
267  // Component construction and destruction
268  // ----------------------------------------------------------------------
269 
271  ApidManagerComponentBase(const char* compName) :
272  Fw::PassiveComponentBase(compName)
273  {
274 
275  }
276 
279  {
280 
281  }
282 
283  // ----------------------------------------------------------------------
284  // Connection status queries for special output ports
285  // ----------------------------------------------------------------------
286 
289  {
290  FW_ASSERT(
291  (0 <= portNum) && (portNum < this->getNum_logOut_OutputPorts()),
292  static_cast<FwAssertArgType>(portNum)
293  );
294 
295  return this->m_logOut_OutputPort[portNum].isConnected();
296  }
297 
298 #if FW_ENABLE_TEXT_LOGGING == 1
299 
300  bool ApidManagerComponentBase ::
301  isConnected_logTextOut_OutputPort(FwIndexType portNum)
302  {
303  FW_ASSERT(
304  (0 <= portNum) && (portNum < this->getNum_logTextOut_OutputPorts()),
305  static_cast<FwAssertArgType>(portNum)
306  );
307 
308  return this->m_logTextOut_OutputPort[portNum].isConnected();
309  }
310 
311 #endif
312 
315  {
316  FW_ASSERT(
317  (0 <= portNum) && (portNum < this->getNum_timeCaller_OutputPorts()),
318  static_cast<FwAssertArgType>(portNum)
319  );
320 
321  return this->m_timeCaller_OutputPort[portNum].isConnected();
322  }
323 
324  // ----------------------------------------------------------------------
325  // Port handler base-class functions for typed input ports
326  //
327  // Call these functions directly to bypass the corresponding ports
328  // ----------------------------------------------------------------------
329 
332  FwIndexType portNum,
333  const ComCfg::Apid& apid,
334  U16 sequenceCount
335  )
336  {
337  // Make sure port number is valid
338  FW_ASSERT(
339  (0 <= portNum) && (portNum < this->getNum_getApidSeqCountIn_InputPorts()),
340  static_cast<FwAssertArgType>(portNum)
341  );
342 
343  U16 retVal;
344 
345  // Lock guard mutex before calling
346  this->lock();
347 
348  // Call handler function
349  retVal = this->getApidSeqCountIn_handler(
350  portNum,
351  apid,
352  sequenceCount
353  );
354 
355  // Unlock guard mutex
356  this->unLock();
357 
358  return retVal;
359  }
360 
363  FwIndexType portNum,
364  const ComCfg::Apid& apid,
365  U16 sequenceCount
366  )
367  {
368  // Make sure port number is valid
369  FW_ASSERT(
370  (0 <= portNum) && (portNum < this->getNum_validateApidSeqCountIn_InputPorts()),
371  static_cast<FwAssertArgType>(portNum)
372  );
373 
374  U16 retVal;
375 
376  // Lock guard mutex before calling
377  this->lock();
378 
379  // Call handler function
380  retVal = this->validateApidSeqCountIn_handler(
381  portNum,
382  apid,
383  sequenceCount
384  );
385 
386  // Unlock guard mutex
387  this->unLock();
388 
389  return retVal;
390  }
391 
392  // ----------------------------------------------------------------------
393  // Event logging functions
394  // ----------------------------------------------------------------------
395 
398  U16 transmitted,
399  U16 expected
400  ) const
401  {
402  // Get the time
403  Fw::Time _logTime;
404  if (this->m_timeCaller_OutputPort[0].isConnected()) {
405  this->m_timeCaller_OutputPort[0].invoke(_logTime);
406  }
407 
408  FwEventIdType _id = static_cast<FwEventIdType>(0);
409 
411 
412  // Emit the event on the log port
413  if (this->m_logOut_OutputPort[0].isConnected()) {
414  Fw::LogBuffer _logBuff;
416 
417 #if FW_AMPCS_COMPATIBLE
418  // Serialize the number of arguments
419  _status = _logBuff.serializeFrom(static_cast<U8>(2));
420  FW_ASSERT(
421  _status == Fw::FW_SERIALIZE_OK,
422  static_cast<FwAssertArgType>(_status)
423  );
424 #endif
425 
426 #if FW_AMPCS_COMPATIBLE
427  // Serialize the argument size
428  _status = _logBuff.serializeFrom(
429  static_cast<U8>(sizeof(U16))
430  );
431  FW_ASSERT(
432  _status == Fw::FW_SERIALIZE_OK,
433  static_cast<FwAssertArgType>(_status)
434  );
435 #endif
436  _status = _logBuff.serializeFrom(transmitted);
437  FW_ASSERT(
438  _status == Fw::FW_SERIALIZE_OK,
439  static_cast<FwAssertArgType>(_status)
440  );
441 
442 #if FW_AMPCS_COMPATIBLE
443  // Serialize the argument size
444  _status = _logBuff.serializeFrom(
445  static_cast<U8>(sizeof(U16))
446  );
447  FW_ASSERT(
448  _status == Fw::FW_SERIALIZE_OK,
449  static_cast<FwAssertArgType>(_status)
450  );
451 #endif
452  _status = _logBuff.serializeFrom(expected);
453  FW_ASSERT(
454  _status == Fw::FW_SERIALIZE_OK,
455  static_cast<FwAssertArgType>(_status)
456  );
457 
458  this->m_logOut_OutputPort[0].invoke(
459  _id,
460  _logTime,
462  _logBuff
463  );
464  }
465 
466  // Emit the event on the text log port
467 #if FW_ENABLE_TEXT_LOGGING
468  if (this->m_logTextOut_OutputPort[0].isConnected()) {
469 #if FW_OBJECT_NAMES == 1
470  const char* _formatString =
471  "(%s) %s: Unexpected sequence count received. Packets may have been dropped. Transmitted: %" PRIu16 " | Expected on board: %" PRIu16 "";
472 #else
473  const char* _formatString =
474  "%s: Unexpected sequence count received. Packets may have been dropped. Transmitted: %" PRIu16 " | Expected on board: %" PRIu16 "";
475 #endif
476 
477  Fw::TextLogString _logString;
478  _logString.format(
479  _formatString,
480 #if FW_OBJECT_NAMES == 1
481  this->m_objName.toChar(),
482 #endif
483  "UnexpectedSequenceCount ",
484  transmitted,
485  expected
486  );
487 
488  this->m_logTextOut_OutputPort[0].invoke(
489  _id,
490  _logTime,
492  _logString
493  );
494  }
495 #endif
496  }
497 
499  log_WARNING_HI_ApidTableFull(U16 invalidApidValue) const
500  {
501  // Get the time
502  Fw::Time _logTime;
503  if (this->m_timeCaller_OutputPort[0].isConnected()) {
504  this->m_timeCaller_OutputPort[0].invoke(_logTime);
505  }
506 
507  FwEventIdType _id = static_cast<FwEventIdType>(0);
508 
509  _id = this->getIdBase() + EVENTID_APIDTABLEFULL;
510 
511  // Emit the event on the log port
512  if (this->m_logOut_OutputPort[0].isConnected()) {
513  Fw::LogBuffer _logBuff;
515 
516 #if FW_AMPCS_COMPATIBLE
517  // Serialize the number of arguments
518  _status = _logBuff.serializeFrom(static_cast<U8>(1));
519  FW_ASSERT(
520  _status == Fw::FW_SERIALIZE_OK,
521  static_cast<FwAssertArgType>(_status)
522  );
523 #endif
524 
525 #if FW_AMPCS_COMPATIBLE
526  // Serialize the argument size
527  _status = _logBuff.serializeFrom(
528  static_cast<U8>(sizeof(U16))
529  );
530  FW_ASSERT(
531  _status == Fw::FW_SERIALIZE_OK,
532  static_cast<FwAssertArgType>(_status)
533  );
534 #endif
535  _status = _logBuff.serializeFrom(invalidApidValue);
536  FW_ASSERT(
537  _status == Fw::FW_SERIALIZE_OK,
538  static_cast<FwAssertArgType>(_status)
539  );
540 
541  this->m_logOut_OutputPort[0].invoke(
542  _id,
543  _logTime,
545  _logBuff
546  );
547  }
548 
549  // Emit the event on the text log port
550 #if FW_ENABLE_TEXT_LOGGING
551  if (this->m_logTextOut_OutputPort[0].isConnected()) {
552 #if FW_OBJECT_NAMES == 1
553  const char* _formatString =
554  "(%s) %s: APID Table is full, cannot generate or check sequence counts for APID: %" PRIu16 "";
555 #else
556  const char* _formatString =
557  "%s: APID Table is full, cannot generate or check sequence counts for APID: %" PRIu16 "";
558 #endif
559 
560  Fw::TextLogString _logString;
561  _logString.format(
562  _formatString,
563 #if FW_OBJECT_NAMES == 1
564  this->m_objName.toChar(),
565 #endif
566  "ApidTableFull ",
567  invalidApidValue
568  );
569 
570  this->m_logTextOut_OutputPort[0].invoke(
571  _id,
572  _logTime,
574  _logString
575  );
576  }
577 #endif
578  }
579 
580  // ----------------------------------------------------------------------
581  // Time
582  // ----------------------------------------------------------------------
583 
585  getTime() const
586  {
587  if (this->m_timeCaller_OutputPort[0].isConnected()) {
588  Fw::Time _time;
589  this->m_timeCaller_OutputPort[0].invoke(_time);
590  return _time;
591  }
592  else {
593  return Fw::Time(TimeBase::TB_NONE, 0, 0);
594  }
595  }
596 
597  // ----------------------------------------------------------------------
598  // Mutex operations for guarded ports
599  //
600  // You can override these operations to provide more sophisticated
601  // synchronization
602  // ----------------------------------------------------------------------
603 
606  {
607  this->m_guardedPortMutex.lock();
608  }
609 
612  {
613  this->m_guardedPortMutex.unLock();
614  }
615 
616  // ----------------------------------------------------------------------
617  // Calls for messages received on typed input ports
618  // ----------------------------------------------------------------------
619 
620  U16 ApidManagerComponentBase ::
621  m_p_getApidSeqCountIn_in(
622  Fw::PassiveComponentBase* callComp,
623  FwIndexType portNum,
624  const ComCfg::Apid& apid,
625  U16 sequenceCount
626  )
627  {
628  FW_ASSERT(callComp);
629  ApidManagerComponentBase* compPtr = static_cast<ApidManagerComponentBase*>(callComp);
630  return compPtr->getApidSeqCountIn_handlerBase(
631  portNum,
632  apid,
633  sequenceCount
634  );
635  }
636 
637  U16 ApidManagerComponentBase ::
638  m_p_validateApidSeqCountIn_in(
639  Fw::PassiveComponentBase* callComp,
640  FwIndexType portNum,
641  const ComCfg::Apid& apid,
642  U16 sequenceCount
643  )
644  {
645  FW_ASSERT(callComp);
646  ApidManagerComponentBase* compPtr = static_cast<ApidManagerComponentBase*>(callComp);
647  return compPtr->validateApidSeqCountIn_handlerBase(
648  portNum,
649  apid,
650  sequenceCount
651  );
652  }
653 
654  }
655 
656 }
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:134
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
bool isConnected_logOut_OutputPort(FwIndexType portNum)
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:26
void init()
Initialization function.
Definition: TimePortAc.cpp:128
A less serious but recoverable event.
void invoke(Fw::Time &time) const
Invoke a port interface.
Definition: TimePortAc.cpp:147
const char * toChar() const
Convert to a C-style char*.
Definition: ObjectName.hpp:50
ApidManagerComponentBase(const char *compName="")
Construct ApidManagerComponentBase object.
A serious but recoverable event.
virtual U16 validateApidSeqCountIn_handler(FwIndexType portNum, const ComCfg::Apid &apid, U16 sequenceCount)=0
Handler for input port validateApidSeqCountIn.
bool isConnected() const
Definition: PortBase.cpp:38
#define PRI_FwIndexType
FormatStatus format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:39
void init()
Initialization function.
Definition: LogPortAc.cpp:151
void log_WARNING_HI_ApidTableFull(U16 invalidApidValue) const
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 interface.
Definition: LogPortAc.cpp:170
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.
void addCallPort(InputLogPort *callPort)
Register an input port.
Definition: LogPortAc.cpp:157
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:17
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
bool isConnected_timeCaller_OutputPort(FwIndexType portNum)