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  // Getters for numbers of typed input ports
285  // ----------------------------------------------------------------------
286 
289  {
290  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_getApidSeqCountIn_InputPort));
291  }
292 
295  {
296  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_validateApidSeqCountIn_InputPort));
297  }
298 
299  // ----------------------------------------------------------------------
300  // Getters for numbers of special output ports
301  // ----------------------------------------------------------------------
302 
305  {
306  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_logOut_OutputPort));
307  }
308 
309 #if FW_ENABLE_TEXT_LOGGING == 1
310 
311  FwIndexType ApidManagerComponentBase ::
312  getNum_logTextOut_OutputPorts() const
313  {
314  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_logTextOut_OutputPort));
315  }
316 
317 #endif
318 
321  {
322  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_timeCaller_OutputPort));
323  }
324 
325  // ----------------------------------------------------------------------
326  // Connection status queries for special output ports
327  // ----------------------------------------------------------------------
328 
331  {
332  FW_ASSERT(
333  (0 <= portNum) && (portNum < this->getNum_logOut_OutputPorts()),
334  static_cast<FwAssertArgType>(portNum)
335  );
336 
337  return this->m_logOut_OutputPort[portNum].isConnected();
338  }
339 
340 #if FW_ENABLE_TEXT_LOGGING == 1
341 
342  bool ApidManagerComponentBase ::
343  isConnected_logTextOut_OutputPort(FwIndexType portNum)
344  {
345  FW_ASSERT(
346  (0 <= portNum) && (portNum < this->getNum_logTextOut_OutputPorts()),
347  static_cast<FwAssertArgType>(portNum)
348  );
349 
350  return this->m_logTextOut_OutputPort[portNum].isConnected();
351  }
352 
353 #endif
354 
357  {
358  FW_ASSERT(
359  (0 <= portNum) && (portNum < this->getNum_timeCaller_OutputPorts()),
360  static_cast<FwAssertArgType>(portNum)
361  );
362 
363  return this->m_timeCaller_OutputPort[portNum].isConnected();
364  }
365 
366  // ----------------------------------------------------------------------
367  // Port handler base-class functions for typed input ports
368  //
369  // Call these functions directly to bypass the corresponding ports
370  // ----------------------------------------------------------------------
371 
374  FwIndexType portNum,
375  const ComCfg::APID& apid,
376  U16 sequenceCount
377  )
378  {
379  // Make sure port number is valid
380  FW_ASSERT(
381  (0 <= portNum) && (portNum < this->getNum_getApidSeqCountIn_InputPorts()),
382  static_cast<FwAssertArgType>(portNum)
383  );
384 
385  U16 retVal;
386 
387  // Lock guard mutex before calling
388  this->lock();
389 
390  // Call handler function
391  retVal = this->getApidSeqCountIn_handler(
392  portNum,
393  apid,
394  sequenceCount
395  );
396 
397  // Unlock guard mutex
398  this->unLock();
399 
400  return retVal;
401  }
402 
405  FwIndexType portNum,
406  const ComCfg::APID& apid,
407  U16 sequenceCount
408  )
409  {
410  // Make sure port number is valid
411  FW_ASSERT(
412  (0 <= portNum) && (portNum < this->getNum_validateApidSeqCountIn_InputPorts()),
413  static_cast<FwAssertArgType>(portNum)
414  );
415 
416  U16 retVal;
417 
418  // Lock guard mutex before calling
419  this->lock();
420 
421  // Call handler function
422  retVal = this->validateApidSeqCountIn_handler(
423  portNum,
424  apid,
425  sequenceCount
426  );
427 
428  // Unlock guard mutex
429  this->unLock();
430 
431  return retVal;
432  }
433 
434  // ----------------------------------------------------------------------
435  // Event logging functions
436  // ----------------------------------------------------------------------
437 
440  U16 transmitted,
441  U16 expected
442  ) const
443  {
444  // Get the time
445  Fw::Time _logTime;
446  if (this->m_timeCaller_OutputPort[0].isConnected()) {
447  this->m_timeCaller_OutputPort[0].invoke(_logTime);
448  }
449 
450  FwEventIdType _id = static_cast<FwEventIdType>(0);
451 
453 
454  // Emit the event on the log port
455  if (this->m_logOut_OutputPort[0].isConnected()) {
456  Fw::LogBuffer _logBuff;
458 
459 #if FW_AMPCS_COMPATIBLE
460  // Serialize the number of arguments
461  _status = _logBuff.serialize(static_cast<U8>(2));
462  FW_ASSERT(
463  _status == Fw::FW_SERIALIZE_OK,
464  static_cast<FwAssertArgType>(_status)
465  );
466 #endif
467 
468 #if FW_AMPCS_COMPATIBLE
469  // Serialize the argument size
470  _status = _logBuff.serialize(
471  static_cast<U8>(sizeof(U16))
472  );
473  FW_ASSERT(
474  _status == Fw::FW_SERIALIZE_OK,
475  static_cast<FwAssertArgType>(_status)
476  );
477 #endif
478  _status = _logBuff.serialize(transmitted);
479  FW_ASSERT(
480  _status == Fw::FW_SERIALIZE_OK,
481  static_cast<FwAssertArgType>(_status)
482  );
483 
484 #if FW_AMPCS_COMPATIBLE
485  // Serialize the argument size
486  _status = _logBuff.serialize(
487  static_cast<U8>(sizeof(U16))
488  );
489  FW_ASSERT(
490  _status == Fw::FW_SERIALIZE_OK,
491  static_cast<FwAssertArgType>(_status)
492  );
493 #endif
494  _status = _logBuff.serialize(expected);
495  FW_ASSERT(
496  _status == Fw::FW_SERIALIZE_OK,
497  static_cast<FwAssertArgType>(_status)
498  );
499 
500  this->m_logOut_OutputPort[0].invoke(
501  _id,
502  _logTime,
504  _logBuff
505  );
506  }
507 
508  // Emit the event on the text log port
509 #if FW_ENABLE_TEXT_LOGGING
510  if (this->m_logTextOut_OutputPort[0].isConnected()) {
511 #if FW_OBJECT_NAMES == 1
512  const char* _formatString =
513  "(%s) %s: Unexpected sequence count received. Packets may have been dropped. Transmitted: %" PRIu16 " | Expected on board: %" PRIu16 "";
514 #else
515  const char* _formatString =
516  "%s: Unexpected sequence count received. Packets may have been dropped. Transmitted: %" PRIu16 " | Expected on board: %" PRIu16 "";
517 #endif
518 
519  Fw::TextLogString _logString;
520  _logString.format(
521  _formatString,
522 #if FW_OBJECT_NAMES == 1
523  this->m_objName.toChar(),
524 #endif
525  "UnexpectedSequenceCount ",
526  transmitted,
527  expected
528  );
529 
530  this->m_logTextOut_OutputPort[0].invoke(
531  _id,
532  _logTime,
534  _logString
535  );
536  }
537 #endif
538  }
539 
541  log_WARNING_HI_ApidTableFull(U16 invalidApidValue) const
542  {
543  // Get the time
544  Fw::Time _logTime;
545  if (this->m_timeCaller_OutputPort[0].isConnected()) {
546  this->m_timeCaller_OutputPort[0].invoke(_logTime);
547  }
548 
549  FwEventIdType _id = static_cast<FwEventIdType>(0);
550 
551  _id = this->getIdBase() + EVENTID_APIDTABLEFULL;
552 
553  // Emit the event on the log port
554  if (this->m_logOut_OutputPort[0].isConnected()) {
555  Fw::LogBuffer _logBuff;
557 
558 #if FW_AMPCS_COMPATIBLE
559  // Serialize the number of arguments
560  _status = _logBuff.serialize(static_cast<U8>(1));
561  FW_ASSERT(
562  _status == Fw::FW_SERIALIZE_OK,
563  static_cast<FwAssertArgType>(_status)
564  );
565 #endif
566 
567 #if FW_AMPCS_COMPATIBLE
568  // Serialize the argument size
569  _status = _logBuff.serialize(
570  static_cast<U8>(sizeof(U16))
571  );
572  FW_ASSERT(
573  _status == Fw::FW_SERIALIZE_OK,
574  static_cast<FwAssertArgType>(_status)
575  );
576 #endif
577  _status = _logBuff.serialize(invalidApidValue);
578  FW_ASSERT(
579  _status == Fw::FW_SERIALIZE_OK,
580  static_cast<FwAssertArgType>(_status)
581  );
582 
583  this->m_logOut_OutputPort[0].invoke(
584  _id,
585  _logTime,
587  _logBuff
588  );
589  }
590 
591  // Emit the event on the text log port
592 #if FW_ENABLE_TEXT_LOGGING
593  if (this->m_logTextOut_OutputPort[0].isConnected()) {
594 #if FW_OBJECT_NAMES == 1
595  const char* _formatString =
596  "(%s) %s: APID Table is full, cannot generate or check sequence counts for APID: %" PRIu16 "";
597 #else
598  const char* _formatString =
599  "%s: APID Table is full, cannot generate or check sequence counts for APID: %" PRIu16 "";
600 #endif
601 
602  Fw::TextLogString _logString;
603  _logString.format(
604  _formatString,
605 #if FW_OBJECT_NAMES == 1
606  this->m_objName.toChar(),
607 #endif
608  "ApidTableFull ",
609  invalidApidValue
610  );
611 
612  this->m_logTextOut_OutputPort[0].invoke(
613  _id,
614  _logTime,
616  _logString
617  );
618  }
619 #endif
620  }
621 
622  // ----------------------------------------------------------------------
623  // Time
624  // ----------------------------------------------------------------------
625 
627  getTime() const
628  {
629  if (this->m_timeCaller_OutputPort[0].isConnected()) {
630  Fw::Time _time;
631  this->m_timeCaller_OutputPort[0].invoke(_time);
632  return _time;
633  }
634  else {
635  return Fw::Time(TB_NONE, 0, 0);
636  }
637  }
638 
639  // ----------------------------------------------------------------------
640  // Mutex operations for guarded ports
641  //
642  // You can override these operations to provide more sophisticated
643  // synchronization
644  // ----------------------------------------------------------------------
645 
648  {
649  this->m_guardedPortMutex.lock();
650  }
651 
654  {
655  this->m_guardedPortMutex.unLock();
656  }
657 
658  // ----------------------------------------------------------------------
659  // Calls for messages received on typed input ports
660  // ----------------------------------------------------------------------
661 
662  U16 ApidManagerComponentBase ::
663  m_p_getApidSeqCountIn_in(
664  Fw::PassiveComponentBase* callComp,
665  FwIndexType portNum,
666  const ComCfg::APID& apid,
667  U16 sequenceCount
668  )
669  {
670  FW_ASSERT(callComp);
671  ApidManagerComponentBase* compPtr = static_cast<ApidManagerComponentBase*>(callComp);
672  return compPtr->getApidSeqCountIn_handlerBase(
673  portNum,
674  apid,
675  sequenceCount
676  );
677  }
678 
679  U16 ApidManagerComponentBase ::
680  m_p_validateApidSeqCountIn_in(
681  Fw::PassiveComponentBase* callComp,
682  FwIndexType portNum,
683  const ComCfg::APID& apid,
684  U16 sequenceCount
685  )
686  {
687  FW_ASSERT(callComp);
688  ApidManagerComponentBase* compPtr = static_cast<ApidManagerComponentBase*>(callComp);
689  return compPtr->validateApidSeqCountIn_handlerBase(
690  portNum,
691  apid,
692  sequenceCount
693  );
694  }
695 
696  }
697 
698 }
Serialization/Deserialization operation was successful.
void addCallPort(InputTimePort *callPort)
Register an input port.
Definition: TimePortAc.cpp:134
Definition: Time.hpp:9
I32 FwEnumStoreType
void log_WARNING_LO_UnexpectedSequenceCount(U16 transmitted, U16 expected) const
void log_WARNING_HI_ApidTableFull(U16 invalidApidValue) const
SerializeStatus serialize(U8 val)
serialize 8-bit unsigned int
Svc::CCSDS::InputApidSequenceCountPort * get_validateApidSeqCountIn_InputPort(FwIndexType portNum)
void unLock()
unlock the mutex and assert success
Definition: Mutex.cpp:40
virtual U16 validateApidSeqCountIn_handler(FwIndexType portNum, const ComCfg::APID &apid, U16 sequenceCount)=0
Handler for input port validateApidSeqCountIn.
virtual void unLock()
Unlock the guarded mutex.
Svc::CCSDS::InputApidSequenceCountPort * get_getApidSeqCountIn_InputPort(FwIndexType portNum)
void init()
Object initializer.
Definition: ObjBase.cpp:26
FwIndexType getNum_validateApidSeqCountIn_InputPorts() const
void set_timeCaller_OutputPort(FwIndexType portNum, Fw::InputTimePort *port)
Connect port to timeCaller[portNum].
SerializeStatus
forward declaration for string
void set_logOut_OutputPort(FwIndexType portNum, Fw::InputLogPort *port)
Connect port to logOut[portNum].
virtual U16 getApidSeqCountIn_handler(FwIndexType portNum, const ComCfg::APID &apid, U16 sequenceCount)=0
Handler for input port getApidSeqCountIn.
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:53
virtual void lock()
Lock the guarded mutex.
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
Definition: ObjectName.hpp:50
U16 validateApidSeqCountIn_handlerBase(FwIndexType portNum, const ComCfg::APID &apid, U16 sequenceCount)
Handler base-class function for input port validateApidSeqCountIn.
A serious but recoverable event.
Auto-generated base for ApidManager component.
bool isConnected() const
Definition: PortBase.cpp:42
#define PRI_FwIndexType
FormatStatus format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:55
void init()
Initialization function.
Definition: LogPortAc.cpp:151
void setPortNum(FwIndexType portNum)
void invoke(FwEventIdType id, Fw::Time &timeTag, const Fw::LogSeverity &severity, Fw::LogBuffer &args) const
Invoke a port interface.
Definition: LogPortAc.cpp:170
virtual ~ApidManagerComponentBase()
Destroy ApidManagerComponentBase object.
No time base has been established.
Definition: FpConfig.h:30
PlatformIndexType FwIndexType
APIDs are 11 bits in the Space Packet protocol, so we use U16. Max value 7FF.
Definition: APIDEnumAc.hpp:17
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition: BasicTypes.h:93
void addCallPort(InputLogPort *callPort)
Register an input port.
Definition: LogPortAc.cpp:157
ApidManagerComponentBase(const char *compName="")
Construct ApidManagerComponentBase object.
U16 getApidSeqCountIn_handlerBase(FwIndexType portNum, const ComCfg::APID &apid, U16 sequenceCount)
Handler base-class function for input port getApidSeqCountIn.
RateGroupDivider component implementation.
bool isConnected_logOut_OutputPort(FwIndexType portNum)
bool isConnected_timeCaller_OutputPort(FwIndexType portNum)
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
#define FW_ASSERT(...)
Definition: Assert.hpp:14
void lock()
lock the mutex and assert success
Definition: Mutex.cpp:34