F´ Flight Software - C/C++ Documentation NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ComQueueComponentAc.cpp
Go to the documentation of this file.
1// ======================================================================
2// \title ComQueueComponentAc.cpp
3// \author Generated by fpp-to-cpp
4// \brief cpp file for ComQueue component base class
5// ======================================================================
6
7#include <cstdio>
8
10#include "Fw/Types/Assert.hpp"
11#if FW_ENABLE_TEXT_LOGGING
12#include "Fw/Types/String.hpp"
13#endif
14
15namespace Svc {
16
17 namespace {
18 enum MsgTypeEnum {
19 COMQUEUE_COMPONENT_EXIT = Fw::ActiveComponentBase::ACTIVE_COMPONENT_EXIT,
20 BUFFQUEUEIN_BUFFERSEND,
21 COMQUEUEIN_COM,
22 COMSTATUSIN_SUCCESSCONDITION,
23 RUN_SCHED,
24 };
25
26 // Get the max size by doing a union of the input and internal port serialization sizes
27 union BuffUnion {
29 BYTE comQueueInPortSize[Fw::InputComPort::SERIALIZED_SIZE];
32 };
33
34 // Define a message buffer class large enough to handle all the
35 // asynchronous inputs to the component
36 class ComponentIpcSerializableBuffer :
38 {
39
40 public:
41
42 enum {
43 // Max. message size = size of data + message id + port
44 SERIALIZATION_SIZE =
45 sizeof(BuffUnion) +
46 sizeof(NATIVE_INT_TYPE) +
47 sizeof(NATIVE_INT_TYPE)
48 };
49
50 NATIVE_UINT_TYPE getBuffCapacity() const {
51 return sizeof(m_buff);
52 }
53
54 U8* getBuffAddr() {
55 return m_buff;
56 }
57
58 const U8* getBuffAddr() const {
59 return m_buff;
60 }
61
62 private:
63 // Should be the max of all the input ports serialized sizes...
64 U8 m_buff[SERIALIZATION_SIZE];
65
66 };
67 }
68
69 // ----------------------------------------------------------------------
70 // Component initialization
71 // ----------------------------------------------------------------------
72
73 void ComQueueComponentBase ::
74 init(
75 NATIVE_INT_TYPE queueDepth,
76 NATIVE_INT_TYPE instance
77 )
78 {
79 // Initialize base class
81
82 // Connect input port buffQueueIn
83 for (
84 PlatformIntType port = 0;
85 port < static_cast<PlatformIntType>(this->getNum_buffQueueIn_InputPorts());
86 port++
87 ) {
88 this->m_buffQueueIn_InputPort[port].init();
89 this->m_buffQueueIn_InputPort[port].addCallComp(
90 this,
91 m_p_buffQueueIn_in
92 );
93 this->m_buffQueueIn_InputPort[port].setPortNum(port);
94
95#if FW_OBJECT_NAMES == 1
96 char portName[120];
97 (void) snprintf(
98 portName,
99 sizeof(portName),
100 "%s_buffQueueIn_InputPort[%" PRI_PlatformIntType "]",
101 this->m_objName,
102 port
103 );
104 this->m_buffQueueIn_InputPort[port].setObjName(portName);
105#endif
106 }
107
108 // Connect input port comQueueIn
109 for (
110 PlatformIntType port = 0;
111 port < static_cast<PlatformIntType>(this->getNum_comQueueIn_InputPorts());
112 port++
113 ) {
114 this->m_comQueueIn_InputPort[port].init();
115 this->m_comQueueIn_InputPort[port].addCallComp(
116 this,
117 m_p_comQueueIn_in
118 );
119 this->m_comQueueIn_InputPort[port].setPortNum(port);
120
121#if FW_OBJECT_NAMES == 1
122 char portName[120];
123 (void) snprintf(
124 portName,
125 sizeof(portName),
126 "%s_comQueueIn_InputPort[%" PRI_PlatformIntType "]",
127 this->m_objName,
128 port
129 );
130 this->m_comQueueIn_InputPort[port].setObjName(portName);
131#endif
132 }
133
134 // Connect input port comStatusIn
135 for (
136 PlatformIntType port = 0;
137 port < static_cast<PlatformIntType>(this->getNum_comStatusIn_InputPorts());
138 port++
139 ) {
140 this->m_comStatusIn_InputPort[port].init();
141 this->m_comStatusIn_InputPort[port].addCallComp(
142 this,
143 m_p_comStatusIn_in
144 );
145 this->m_comStatusIn_InputPort[port].setPortNum(port);
146
147#if FW_OBJECT_NAMES == 1
148 char portName[120];
149 (void) snprintf(
150 portName,
151 sizeof(portName),
152 "%s_comStatusIn_InputPort[%" PRI_PlatformIntType "]",
153 this->m_objName,
154 port
155 );
156 this->m_comStatusIn_InputPort[port].setObjName(portName);
157#endif
158 }
159
160 // Connect input port run
161 for (
162 PlatformIntType port = 0;
163 port < static_cast<PlatformIntType>(this->getNum_run_InputPorts());
164 port++
165 ) {
166 this->m_run_InputPort[port].init();
167 this->m_run_InputPort[port].addCallComp(
168 this,
169 m_p_run_in
170 );
171 this->m_run_InputPort[port].setPortNum(port);
172
173#if FW_OBJECT_NAMES == 1
174 char portName[120];
175 (void) snprintf(
176 portName,
177 sizeof(portName),
178 "%s_run_InputPort[%" PRI_PlatformIntType "]",
179 this->m_objName,
180 port
181 );
182 this->m_run_InputPort[port].setObjName(portName);
183#endif
184 }
185
186 // Connect output port Log
187 for (
188 PlatformIntType port = 0;
189 port < static_cast<PlatformIntType>(this->getNum_Log_OutputPorts());
190 port++
191 ) {
192 this->m_Log_OutputPort[port].init();
193
194#if FW_OBJECT_NAMES == 1
195 char portName[120];
196 (void) snprintf(
197 portName,
198 sizeof(portName),
199 "%s_Log_OutputPort[%" PRI_PlatformIntType "]",
200 this->m_objName,
201 port
202 );
203 this->m_Log_OutputPort[port].setObjName(portName);
204#endif
205 }
206
207#if FW_ENABLE_TEXT_LOGGING == 1
208 // Connect output port LogText
209 for (
210 PlatformIntType port = 0;
211 port < static_cast<PlatformIntType>(this->getNum_LogText_OutputPorts());
212 port++
213 ) {
214 this->m_LogText_OutputPort[port].init();
215
216#if FW_OBJECT_NAMES == 1
217 char portName[120];
218 (void) snprintf(
219 portName,
220 sizeof(portName),
221 "%s_LogText_OutputPort[%" PRI_PlatformIntType "]",
222 this->m_objName,
223 port
224 );
225 this->m_LogText_OutputPort[port].setObjName(portName);
226#endif
227 }
228#endif
229
230 // Connect output port Time
231 for (
232 PlatformIntType port = 0;
233 port < static_cast<PlatformIntType>(this->getNum_Time_OutputPorts());
234 port++
235 ) {
236 this->m_Time_OutputPort[port].init();
237
238#if FW_OBJECT_NAMES == 1
239 char portName[120];
240 (void) snprintf(
241 portName,
242 sizeof(portName),
243 "%s_Time_OutputPort[%" PRI_PlatformIntType "]",
244 this->m_objName,
245 port
246 );
247 this->m_Time_OutputPort[port].setObjName(portName);
248#endif
249 }
250
251 // Connect output port Tlm
252 for (
253 PlatformIntType port = 0;
254 port < static_cast<PlatformIntType>(this->getNum_Tlm_OutputPorts());
255 port++
256 ) {
257 this->m_Tlm_OutputPort[port].init();
258
259#if FW_OBJECT_NAMES == 1
260 char portName[120];
261 (void) snprintf(
262 portName,
263 sizeof(portName),
264 "%s_Tlm_OutputPort[%" PRI_PlatformIntType "]",
265 this->m_objName,
266 port
267 );
268 this->m_Tlm_OutputPort[port].setObjName(portName);
269#endif
270 }
271
272 // Connect output port buffQueueSend
273 for (
274 PlatformIntType port = 0;
275 port < static_cast<PlatformIntType>(this->getNum_buffQueueSend_OutputPorts());
276 port++
277 ) {
278 this->m_buffQueueSend_OutputPort[port].init();
279
280#if FW_OBJECT_NAMES == 1
281 char portName[120];
282 (void) snprintf(
283 portName,
284 sizeof(portName),
285 "%s_buffQueueSend_OutputPort[%" PRI_PlatformIntType "]",
286 this->m_objName,
287 port
288 );
289 this->m_buffQueueSend_OutputPort[port].setObjName(portName);
290#endif
291 }
292
293 // Connect output port comQueueSend
294 for (
295 PlatformIntType port = 0;
296 port < static_cast<PlatformIntType>(this->getNum_comQueueSend_OutputPorts());
297 port++
298 ) {
299 this->m_comQueueSend_OutputPort[port].init();
300
301#if FW_OBJECT_NAMES == 1
302 char portName[120];
303 (void) snprintf(
304 portName,
305 sizeof(portName),
306 "%s_comQueueSend_OutputPort[%" PRI_PlatformIntType "]",
307 this->m_objName,
308 port
309 );
310 this->m_comQueueSend_OutputPort[port].setObjName(portName);
311#endif
312 }
313
314 Os::Queue::QueueStatus qStat = this->createQueue(
315 queueDepth,
316 ComponentIpcSerializableBuffer::SERIALIZATION_SIZE
317 );
318 FW_ASSERT(
319 Os::Queue::QUEUE_OK == qStat,
320 static_cast<FwAssertArgType>(qStat)
321 );
322 }
323
324 // ----------------------------------------------------------------------
325 // Getters for typed input ports
326 // ----------------------------------------------------------------------
327
328 Fw::InputBufferSendPort* ComQueueComponentBase ::
329 get_buffQueueIn_InputPort(NATIVE_INT_TYPE portNum)
330 {
331 FW_ASSERT(
332 portNum < this->getNum_buffQueueIn_InputPorts(),
333 static_cast<FwAssertArgType>(portNum)
334 );
335
336 return &this->m_buffQueueIn_InputPort[portNum];
337 }
338
339 Fw::InputComPort* ComQueueComponentBase ::
340 get_comQueueIn_InputPort(NATIVE_INT_TYPE portNum)
341 {
342 FW_ASSERT(
343 portNum < this->getNum_comQueueIn_InputPorts(),
344 static_cast<FwAssertArgType>(portNum)
345 );
346
347 return &this->m_comQueueIn_InputPort[portNum];
348 }
349
350 Fw::InputSuccessConditionPort* ComQueueComponentBase ::
351 get_comStatusIn_InputPort(NATIVE_INT_TYPE portNum)
352 {
353 FW_ASSERT(
354 portNum < this->getNum_comStatusIn_InputPorts(),
355 static_cast<FwAssertArgType>(portNum)
356 );
357
358 return &this->m_comStatusIn_InputPort[portNum];
359 }
360
361 Svc::InputSchedPort* ComQueueComponentBase ::
362 get_run_InputPort(NATIVE_INT_TYPE portNum)
363 {
364 FW_ASSERT(
365 portNum < this->getNum_run_InputPorts(),
366 static_cast<FwAssertArgType>(portNum)
367 );
368
369 return &this->m_run_InputPort[portNum];
370 }
371
372 // ----------------------------------------------------------------------
373 // Connect special input ports to special output ports
374 // ----------------------------------------------------------------------
375
376 void ComQueueComponentBase ::
377 set_Log_OutputPort(
378 NATIVE_INT_TYPE portNum,
379 Fw::InputLogPort* port
380 )
381 {
382 FW_ASSERT(
383 portNum < this->getNum_Log_OutputPorts(),
384 static_cast<FwAssertArgType>(portNum)
385 );
386
387 this->m_Log_OutputPort[portNum].addCallPort(port);
388 }
389
390#if FW_ENABLE_TEXT_LOGGING == 1
391
392 void ComQueueComponentBase ::
393 set_LogText_OutputPort(
394 NATIVE_INT_TYPE portNum,
396 )
397 {
398 FW_ASSERT(
399 portNum < this->getNum_LogText_OutputPorts(),
400 static_cast<FwAssertArgType>(portNum)
401 );
402
403 this->m_LogText_OutputPort[portNum].addCallPort(port);
404 }
405
406#endif
407
408 void ComQueueComponentBase ::
409 set_Time_OutputPort(
410 NATIVE_INT_TYPE portNum,
412 )
413 {
414 FW_ASSERT(
415 portNum < this->getNum_Time_OutputPorts(),
416 static_cast<FwAssertArgType>(portNum)
417 );
418
419 this->m_Time_OutputPort[portNum].addCallPort(port);
420 }
421
422 void ComQueueComponentBase ::
423 set_Tlm_OutputPort(
424 NATIVE_INT_TYPE portNum,
425 Fw::InputTlmPort* port
426 )
427 {
428 FW_ASSERT(
429 portNum < this->getNum_Tlm_OutputPorts(),
430 static_cast<FwAssertArgType>(portNum)
431 );
432
433 this->m_Tlm_OutputPort[portNum].addCallPort(port);
434 }
435
436 // ----------------------------------------------------------------------
437 // Connect typed input ports to typed output ports
438 // ----------------------------------------------------------------------
439
440 void ComQueueComponentBase ::
441 set_buffQueueSend_OutputPort(
442 NATIVE_INT_TYPE portNum,
444 )
445 {
446 FW_ASSERT(
447 portNum < this->getNum_buffQueueSend_OutputPorts(),
448 static_cast<FwAssertArgType>(portNum)
449 );
450
451 this->m_buffQueueSend_OutputPort[portNum].addCallPort(port);
452 }
453
454 void ComQueueComponentBase ::
455 set_comQueueSend_OutputPort(
456 NATIVE_INT_TYPE portNum,
457 Fw::InputComPort* port
458 )
459 {
460 FW_ASSERT(
461 portNum < this->getNum_comQueueSend_OutputPorts(),
462 static_cast<FwAssertArgType>(portNum)
463 );
464
465 this->m_comQueueSend_OutputPort[portNum].addCallPort(port);
466 }
467
468#if FW_PORT_SERIALIZATION
469
470 // ----------------------------------------------------------------------
471 // Connect serial input ports to special output ports
472 // ----------------------------------------------------------------------
473
474 void ComQueueComponentBase ::
475 set_Log_OutputPort(
476 NATIVE_INT_TYPE portNum,
477 Fw::InputSerializePort* port
478 )
479 {
480 FW_ASSERT(
481 portNum < this->getNum_Log_OutputPorts(),
482 static_cast<FwAssertArgType>(portNum)
483 );
484
485 this->m_Log_OutputPort[portNum].registerSerialPort(port);
486 }
487
488#if FW_ENABLE_TEXT_LOGGING == 1
489
490 void ComQueueComponentBase ::
491 set_LogText_OutputPort(
492 NATIVE_INT_TYPE portNum,
493 Fw::InputSerializePort* port
494 )
495 {
496 FW_ASSERT(
497 portNum < this->getNum_LogText_OutputPorts(),
498 static_cast<FwAssertArgType>(portNum)
499 );
500
501 this->m_LogText_OutputPort[portNum].registerSerialPort(port);
502 }
503
504#endif
505
506 void ComQueueComponentBase ::
507 set_Time_OutputPort(
508 NATIVE_INT_TYPE portNum,
509 Fw::InputSerializePort* port
510 )
511 {
512 FW_ASSERT(
513 portNum < this->getNum_Time_OutputPorts(),
514 static_cast<FwAssertArgType>(portNum)
515 );
516
517 this->m_Time_OutputPort[portNum].registerSerialPort(port);
518 }
519
520 void ComQueueComponentBase ::
521 set_Tlm_OutputPort(
522 NATIVE_INT_TYPE portNum,
523 Fw::InputSerializePort* port
524 )
525 {
526 FW_ASSERT(
527 portNum < this->getNum_Tlm_OutputPorts(),
528 static_cast<FwAssertArgType>(portNum)
529 );
530
531 this->m_Tlm_OutputPort[portNum].registerSerialPort(port);
532 }
533
534#endif
535
536#if FW_PORT_SERIALIZATION
537
538 // ----------------------------------------------------------------------
539 // Connect serial input ports to typed output ports
540 // ----------------------------------------------------------------------
541
542 void ComQueueComponentBase ::
543 set_buffQueueSend_OutputPort(
544 NATIVE_INT_TYPE portNum,
545 Fw::InputSerializePort* port
546 )
547 {
548 FW_ASSERT(
549 portNum < this->getNum_buffQueueSend_OutputPorts(),
550 static_cast<FwAssertArgType>(portNum)
551 );
552
553 this->m_buffQueueSend_OutputPort[portNum].registerSerialPort(port);
554 }
555
556 void ComQueueComponentBase ::
557 set_comQueueSend_OutputPort(
558 NATIVE_INT_TYPE portNum,
559 Fw::InputSerializePort* port
560 )
561 {
562 FW_ASSERT(
563 portNum < this->getNum_comQueueSend_OutputPorts(),
564 static_cast<FwAssertArgType>(portNum)
565 );
566
567 this->m_comQueueSend_OutputPort[portNum].registerSerialPort(port);
568 }
569
570#endif
571
572 // ----------------------------------------------------------------------
573 // Component construction and destruction
574 // ----------------------------------------------------------------------
575
576 ComQueueComponentBase ::
577 ComQueueComponentBase(const char* compName) :
578 Fw::ActiveComponentBase(compName)
579 {
580
581 }
582
583 ComQueueComponentBase ::
584 ~ComQueueComponentBase()
585 {
586
587 }
588
589 // ----------------------------------------------------------------------
590 // Getters for numbers of typed input ports
591 // ----------------------------------------------------------------------
592
593 NATIVE_INT_TYPE ComQueueComponentBase ::
594 getNum_buffQueueIn_InputPorts()
595 {
596 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_buffQueueIn_InputPort));
597 }
598
599 NATIVE_INT_TYPE ComQueueComponentBase ::
600 getNum_comQueueIn_InputPorts()
601 {
602 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_comQueueIn_InputPort));
603 }
604
605 NATIVE_INT_TYPE ComQueueComponentBase ::
606 getNum_comStatusIn_InputPorts()
607 {
608 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_comStatusIn_InputPort));
609 }
610
611 NATIVE_INT_TYPE ComQueueComponentBase ::
612 getNum_run_InputPorts()
613 {
614 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_run_InputPort));
615 }
616
617 // ----------------------------------------------------------------------
618 // Getters for numbers of special output ports
619 // ----------------------------------------------------------------------
620
621 NATIVE_INT_TYPE ComQueueComponentBase ::
622 getNum_Log_OutputPorts()
623 {
624 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_Log_OutputPort));
625 }
626
627#if FW_ENABLE_TEXT_LOGGING == 1
628
629 NATIVE_INT_TYPE ComQueueComponentBase ::
630 getNum_LogText_OutputPorts()
631 {
632 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_LogText_OutputPort));
633 }
634
635#endif
636
637 NATIVE_INT_TYPE ComQueueComponentBase ::
638 getNum_Time_OutputPorts()
639 {
640 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_Time_OutputPort));
641 }
642
643 NATIVE_INT_TYPE ComQueueComponentBase ::
644 getNum_Tlm_OutputPorts()
645 {
646 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_Tlm_OutputPort));
647 }
648
649 // ----------------------------------------------------------------------
650 // Getters for numbers of typed output ports
651 // ----------------------------------------------------------------------
652
653 NATIVE_INT_TYPE ComQueueComponentBase ::
654 getNum_buffQueueSend_OutputPorts()
655 {
656 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_buffQueueSend_OutputPort));
657 }
658
659 NATIVE_INT_TYPE ComQueueComponentBase ::
660 getNum_comQueueSend_OutputPorts()
661 {
662 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_comQueueSend_OutputPort));
663 }
664
665 // ----------------------------------------------------------------------
666 // Connection status queries for special output ports
667 // ----------------------------------------------------------------------
668
669 bool ComQueueComponentBase ::
670 isConnected_Log_OutputPort(NATIVE_INT_TYPE portNum)
671 {
672 FW_ASSERT(
673 portNum < this->getNum_Log_OutputPorts(),
674 static_cast<FwAssertArgType>(portNum)
675 );
676
677 return this->m_Log_OutputPort[portNum].isConnected();
678 }
679
680#if FW_ENABLE_TEXT_LOGGING == 1
681
682 bool ComQueueComponentBase ::
683 isConnected_LogText_OutputPort(NATIVE_INT_TYPE portNum)
684 {
685 FW_ASSERT(
686 portNum < this->getNum_LogText_OutputPorts(),
687 static_cast<FwAssertArgType>(portNum)
688 );
689
690 return this->m_LogText_OutputPort[portNum].isConnected();
691 }
692
693#endif
694
695 bool ComQueueComponentBase ::
696 isConnected_Time_OutputPort(NATIVE_INT_TYPE portNum)
697 {
698 FW_ASSERT(
699 portNum < this->getNum_Time_OutputPorts(),
700 static_cast<FwAssertArgType>(portNum)
701 );
702
703 return this->m_Time_OutputPort[portNum].isConnected();
704 }
705
706 bool ComQueueComponentBase ::
707 isConnected_Tlm_OutputPort(NATIVE_INT_TYPE portNum)
708 {
709 FW_ASSERT(
710 portNum < this->getNum_Tlm_OutputPorts(),
711 static_cast<FwAssertArgType>(portNum)
712 );
713
714 return this->m_Tlm_OutputPort[portNum].isConnected();
715 }
716
717 // ----------------------------------------------------------------------
718 // Connection status queries for typed output ports
719 // ----------------------------------------------------------------------
720
721 bool ComQueueComponentBase ::
722 isConnected_buffQueueSend_OutputPort(NATIVE_INT_TYPE portNum)
723 {
724 FW_ASSERT(
725 portNum < this->getNum_buffQueueSend_OutputPorts(),
726 static_cast<FwAssertArgType>(portNum)
727 );
728
729 return this->m_buffQueueSend_OutputPort[portNum].isConnected();
730 }
731
732 bool ComQueueComponentBase ::
733 isConnected_comQueueSend_OutputPort(NATIVE_INT_TYPE portNum)
734 {
735 FW_ASSERT(
736 portNum < this->getNum_comQueueSend_OutputPorts(),
737 static_cast<FwAssertArgType>(portNum)
738 );
739
740 return this->m_comQueueSend_OutputPort[portNum].isConnected();
741 }
742
743 // ----------------------------------------------------------------------
744 // Port handler base-class functions for typed input ports
745 //
746 // Call these functions directly to bypass the corresponding ports
747 // ----------------------------------------------------------------------
748
749 void ComQueueComponentBase ::
750 buffQueueIn_handlerBase(
751 NATIVE_INT_TYPE portNum,
752 Fw::Buffer& fwBuffer
753 )
754 {
755 // Make sure port number is valid
756 FW_ASSERT(
757 portNum < this->getNum_buffQueueIn_InputPorts(),
758 static_cast<FwAssertArgType>(portNum)
759 );
760
761 // Call pre-message hook
762 buffQueueIn_preMsgHook(
763 portNum,
764 fwBuffer
765 );
766 ComponentIpcSerializableBuffer msg;
768
769 // Serialize message ID
770 _status = msg.serialize(
771 static_cast<NATIVE_INT_TYPE>(BUFFQUEUEIN_BUFFERSEND)
772 );
773 FW_ASSERT(
774 _status == Fw::FW_SERIALIZE_OK,
775 static_cast<FwAssertArgType>(_status)
776 );
777
778 // Serialize port number
779 _status = msg.serialize(portNum);
780 FW_ASSERT(
781 _status == Fw::FW_SERIALIZE_OK,
782 static_cast<FwAssertArgType>(_status)
783 );
784
785 // Serialize argument fwBuffer
786 _status = msg.serialize(fwBuffer);
787 FW_ASSERT(
788 _status == Fw::FW_SERIALIZE_OK,
789 static_cast<FwAssertArgType>(_status)
790 );
791
792 // Send message
794 Os::Queue::QueueStatus qStatus = this->m_queue.send(msg, 0, _block);
795
796 if (qStatus == Os::Queue::QUEUE_FULL) {
797 this->incNumMsgDropped();
798 return;
799 }
800
801 FW_ASSERT(
802 qStatus == Os::Queue::QUEUE_OK,
803 static_cast<FwAssertArgType>(qStatus)
804 );
805 }
806
807 void ComQueueComponentBase ::
808 comQueueIn_handlerBase(
809 NATIVE_INT_TYPE portNum,
810 Fw::ComBuffer& data,
811 U32 context
812 )
813 {
814 // Make sure port number is valid
815 FW_ASSERT(
816 portNum < this->getNum_comQueueIn_InputPorts(),
817 static_cast<FwAssertArgType>(portNum)
818 );
819
820 // Call pre-message hook
821 comQueueIn_preMsgHook(
822 portNum,
823 data,
824 context
825 );
826 ComponentIpcSerializableBuffer msg;
828
829 // Serialize message ID
830 _status = msg.serialize(
831 static_cast<NATIVE_INT_TYPE>(COMQUEUEIN_COM)
832 );
833 FW_ASSERT(
834 _status == Fw::FW_SERIALIZE_OK,
835 static_cast<FwAssertArgType>(_status)
836 );
837
838 // Serialize port number
839 _status = msg.serialize(portNum);
840 FW_ASSERT(
841 _status == Fw::FW_SERIALIZE_OK,
842 static_cast<FwAssertArgType>(_status)
843 );
844
845 // Serialize argument data
846 _status = msg.serialize(data);
847 FW_ASSERT(
848 _status == Fw::FW_SERIALIZE_OK,
849 static_cast<FwAssertArgType>(_status)
850 );
851
852 // Serialize argument context
853 _status = msg.serialize(context);
854 FW_ASSERT(
855 _status == Fw::FW_SERIALIZE_OK,
856 static_cast<FwAssertArgType>(_status)
857 );
858
859 // Send message
861 Os::Queue::QueueStatus qStatus = this->m_queue.send(msg, 0, _block);
862
863 if (qStatus == Os::Queue::QUEUE_FULL) {
864 this->incNumMsgDropped();
865 return;
866 }
867
868 FW_ASSERT(
869 qStatus == Os::Queue::QUEUE_OK,
870 static_cast<FwAssertArgType>(qStatus)
871 );
872 }
873
874 void ComQueueComponentBase ::
875 comStatusIn_handlerBase(
876 NATIVE_INT_TYPE portNum,
877 Fw::Success& condition
878 )
879 {
880 // Make sure port number is valid
881 FW_ASSERT(
882 portNum < this->getNum_comStatusIn_InputPorts(),
883 static_cast<FwAssertArgType>(portNum)
884 );
885
886 // Call pre-message hook
887 comStatusIn_preMsgHook(
888 portNum,
889 condition
890 );
891 ComponentIpcSerializableBuffer msg;
893
894 // Serialize message ID
895 _status = msg.serialize(
896 static_cast<NATIVE_INT_TYPE>(COMSTATUSIN_SUCCESSCONDITION)
897 );
898 FW_ASSERT(
899 _status == Fw::FW_SERIALIZE_OK,
900 static_cast<FwAssertArgType>(_status)
901 );
902
903 // Serialize port number
904 _status = msg.serialize(portNum);
905 FW_ASSERT(
906 _status == Fw::FW_SERIALIZE_OK,
907 static_cast<FwAssertArgType>(_status)
908 );
909
910 // Serialize argument condition
911 _status = msg.serialize(condition);
912 FW_ASSERT(
913 _status == Fw::FW_SERIALIZE_OK,
914 static_cast<FwAssertArgType>(_status)
915 );
916
917 // Send message
919 Os::Queue::QueueStatus qStatus = this->m_queue.send(msg, 0, _block);
920
921 FW_ASSERT(
922 qStatus == Os::Queue::QUEUE_OK,
923 static_cast<FwAssertArgType>(qStatus)
924 );
925 }
926
927 void ComQueueComponentBase ::
928 run_handlerBase(
929 NATIVE_INT_TYPE portNum,
930 NATIVE_UINT_TYPE context
931 )
932 {
933 // Make sure port number is valid
934 FW_ASSERT(
935 portNum < this->getNum_run_InputPorts(),
936 static_cast<FwAssertArgType>(portNum)
937 );
938
939 // Call pre-message hook
940 run_preMsgHook(
941 portNum,
942 context
943 );
944 ComponentIpcSerializableBuffer msg;
946
947 // Serialize message ID
948 _status = msg.serialize(
949 static_cast<NATIVE_INT_TYPE>(RUN_SCHED)
950 );
951 FW_ASSERT(
952 _status == Fw::FW_SERIALIZE_OK,
953 static_cast<FwAssertArgType>(_status)
954 );
955
956 // Serialize port number
957 _status = msg.serialize(portNum);
958 FW_ASSERT(
959 _status == Fw::FW_SERIALIZE_OK,
960 static_cast<FwAssertArgType>(_status)
961 );
962
963 // Serialize argument context
964 _status = msg.serialize(context);
965 FW_ASSERT(
966 _status == Fw::FW_SERIALIZE_OK,
967 static_cast<FwAssertArgType>(_status)
968 );
969
970 // Send message
972 Os::Queue::QueueStatus qStatus = this->m_queue.send(msg, 0, _block);
973
974 if (qStatus == Os::Queue::QUEUE_FULL) {
975 this->incNumMsgDropped();
976 return;
977 }
978
979 FW_ASSERT(
980 qStatus == Os::Queue::QUEUE_OK,
981 static_cast<FwAssertArgType>(qStatus)
982 );
983 }
984
985 // ----------------------------------------------------------------------
986 // Pre-message hooks for typed async input ports
987 //
988 // Each of these functions is invoked just before processing a message
989 // on the corresponding port. By default, they do nothing. You can
990 // override them to provide specific pre-message behavior.
991 // ----------------------------------------------------------------------
992
993 void ComQueueComponentBase ::
994 buffQueueIn_preMsgHook(
995 NATIVE_INT_TYPE portNum,
996 Fw::Buffer& fwBuffer
997 )
998 {
999 // Default: no-op
1000 }
1001
1002 void ComQueueComponentBase ::
1003 comQueueIn_preMsgHook(
1004 NATIVE_INT_TYPE portNum,
1005 Fw::ComBuffer& data,
1006 U32 context
1007 )
1008 {
1009 // Default: no-op
1010 }
1011
1012 void ComQueueComponentBase ::
1013 comStatusIn_preMsgHook(
1014 NATIVE_INT_TYPE portNum,
1015 Fw::Success& condition
1016 )
1017 {
1018 // Default: no-op
1019 }
1020
1021 void ComQueueComponentBase ::
1022 run_preMsgHook(
1023 NATIVE_INT_TYPE portNum,
1024 NATIVE_UINT_TYPE context
1025 )
1026 {
1027 // Default: no-op
1028 }
1029
1030 // ----------------------------------------------------------------------
1031 // Invocation functions for typed output ports
1032 // ----------------------------------------------------------------------
1033
1034 void ComQueueComponentBase ::
1035 buffQueueSend_out(
1036 NATIVE_INT_TYPE portNum,
1037 Fw::Buffer& fwBuffer
1038 )
1039 {
1040 FW_ASSERT(
1041 portNum < this->getNum_buffQueueSend_OutputPorts(),
1042 static_cast<FwAssertArgType>(portNum)
1043 );
1044 this->m_buffQueueSend_OutputPort[portNum].invoke(
1045 fwBuffer
1046 );
1047 }
1048
1049 void ComQueueComponentBase ::
1050 comQueueSend_out(
1051 NATIVE_INT_TYPE portNum,
1052 Fw::ComBuffer& data,
1053 U32 context
1054 )
1055 {
1056 FW_ASSERT(
1057 portNum < this->getNum_comQueueSend_OutputPorts(),
1058 static_cast<FwAssertArgType>(portNum)
1059 );
1060 this->m_comQueueSend_OutputPort[portNum].invoke(
1061 data,
1062 context
1063 );
1064 }
1065
1066 // ----------------------------------------------------------------------
1067 // Event logging functions
1068 // ----------------------------------------------------------------------
1069
1070 void ComQueueComponentBase ::
1071 log_WARNING_HI_QueueOverflow(
1072 Svc::QueueType queueType,
1073 U32 index
1074 )
1075 {
1076 // Get the time
1077 Fw::Time _logTime;
1078 if (this->m_Time_OutputPort[0].isConnected()) {
1079 this->m_Time_OutputPort[0].invoke(_logTime);
1080 }
1081
1082 FwEventIdType _id = static_cast<FwEventIdType>(0);
1083
1084 _id = this->getIdBase() + EVENTID_QUEUEOVERFLOW;
1085
1086 // Emit the event on the log port
1087 if (this->m_Log_OutputPort[0].isConnected()) {
1088 Fw::LogBuffer _logBuff;
1090
1091#if FW_AMPCS_COMPATIBLE
1092 // Serialize the number of arguments
1093 _status = _logBuff.serialize(static_cast<U8>(2));
1094 FW_ASSERT(
1095 _status == Fw::FW_SERIALIZE_OK,
1096 static_cast<FwAssertArgType>(_status)
1097 );
1098#endif
1099
1100#if FW_AMPCS_COMPATIBLE
1101 // Serialize the argument size
1102 _status = _logBuff.serialize(
1104 );
1105 FW_ASSERT(
1106 _status == Fw::FW_SERIALIZE_OK,
1107 static_cast<FwAssertArgType>(_status)
1108 );
1109#endif
1110 _status = _logBuff.serialize(queueType);
1111 FW_ASSERT(
1112 _status == Fw::FW_SERIALIZE_OK,
1113 static_cast<FwAssertArgType>(_status)
1114 );
1115
1116#if FW_AMPCS_COMPATIBLE
1117 // Serialize the argument size
1118 _status = _logBuff.serialize(
1119 static_cast<U8>(sizeof(U32))
1120 );
1121 FW_ASSERT(
1122 _status == Fw::FW_SERIALIZE_OK,
1123 static_cast<FwAssertArgType>(_status)
1124 );
1125#endif
1126 _status = _logBuff.serialize(index);
1127 FW_ASSERT(
1128 _status == Fw::FW_SERIALIZE_OK,
1129 static_cast<FwAssertArgType>(_status)
1130 );
1131
1132 this->m_Log_OutputPort[0].invoke(
1133 _id,
1134 _logTime,
1136 _logBuff
1137 );
1138 }
1139
1140 // Emit the event on the text log port
1141#if FW_ENABLE_TEXT_LOGGING
1142 if (this->m_LogText_OutputPort[0].isConnected()) {
1143#if FW_OBJECT_NAMES == 1
1144 const char* _formatString =
1145 "(%s) %s: The %s queue at index %" PRIu32 " overflowed";
1146#else
1147 const char* _formatString =
1148 "%s: The %s queue at index %" PRIu32 " overflowed";
1149#endif
1150
1151 char _textBuffer[FW_LOG_TEXT_BUFFER_SIZE];
1152
1153 Fw::String queueTypeStr;
1154 queueType.toString(queueTypeStr);
1155
1156 (void) snprintf(
1157 _textBuffer,
1159 _formatString,
1160#if FW_OBJECT_NAMES == 1
1161 this->m_objName,
1162#endif
1163 "QueueOverflow ",
1164 queueTypeStr.toChar(),
1165 index
1166 );
1167
1168 // Null terminate
1169 _textBuffer[FW_LOG_TEXT_BUFFER_SIZE-1] = 0;
1170 Fw::TextLogString _logString = _textBuffer;
1171 this->m_LogText_OutputPort[0].invoke(
1172 _id,
1173 _logTime,
1175 _logString
1176 );
1177 }
1178#endif
1179 }
1180
1181 // ----------------------------------------------------------------------
1182 // Telemetry write functions
1183 // ----------------------------------------------------------------------
1184
1185 void ComQueueComponentBase ::
1186 tlmWrite_comQueueDepth(
1187 const Svc::ComQueueDepth& arg,
1188 Fw::Time _tlmTime
1189 )
1190 {
1191 if (this->m_Tlm_OutputPort[0].isConnected()) {
1192 if (
1193 this->m_Time_OutputPort[0].isConnected() &&
1194 (_tlmTime == Fw::ZERO_TIME)
1195 ) {
1196 this->m_Time_OutputPort[0].invoke(_tlmTime);
1197 }
1198
1199 Fw::TlmBuffer _tlmBuff;
1200 Fw::SerializeStatus _stat = _tlmBuff.serialize(arg);
1201 FW_ASSERT(
1202 _stat == Fw::FW_SERIALIZE_OK,
1203 static_cast<FwAssertArgType>(_stat)
1204 );
1205
1206 FwChanIdType _id;
1207
1208 _id = this->getIdBase() + CHANNELID_COMQUEUEDEPTH;
1209
1210 this->m_Tlm_OutputPort[0].invoke(
1211 _id,
1212 _tlmTime,
1213 _tlmBuff
1214 );
1215 }
1216 }
1217
1218 void ComQueueComponentBase ::
1219 tlmWrite_buffQueueDepth(
1220 const Svc::BuffQueueDepth& arg,
1221 Fw::Time _tlmTime
1222 )
1223 {
1224 if (this->m_Tlm_OutputPort[0].isConnected()) {
1225 if (
1226 this->m_Time_OutputPort[0].isConnected() &&
1227 (_tlmTime == Fw::ZERO_TIME)
1228 ) {
1229 this->m_Time_OutputPort[0].invoke(_tlmTime);
1230 }
1231
1232 Fw::TlmBuffer _tlmBuff;
1233 Fw::SerializeStatus _stat = _tlmBuff.serialize(arg);
1234 FW_ASSERT(
1235 _stat == Fw::FW_SERIALIZE_OK,
1236 static_cast<FwAssertArgType>(_stat)
1237 );
1238
1239 FwChanIdType _id;
1240
1241 _id = this->getIdBase() + CHANNELID_BUFFQUEUEDEPTH;
1242
1243 this->m_Tlm_OutputPort[0].invoke(
1244 _id,
1245 _tlmTime,
1246 _tlmBuff
1247 );
1248 }
1249 }
1250
1251 // ----------------------------------------------------------------------
1252 // Time
1253 // ----------------------------------------------------------------------
1254
1255 Fw::Time ComQueueComponentBase ::
1256 getTime()
1257 {
1258 if (this->m_Time_OutputPort[0].isConnected()) {
1259 Fw::Time _time;
1260 this->m_Time_OutputPort[0].invoke(_time);
1261 return _time;
1262 }
1263 else {
1264 return Fw::Time(TB_NONE, 0, 0);
1265 }
1266 }
1267
1268 // ----------------------------------------------------------------------
1269 // Message dispatch functions
1270 // ----------------------------------------------------------------------
1271
1272 Fw::QueuedComponentBase::MsgDispatchStatus ComQueueComponentBase ::
1273 doDispatch()
1274 {
1275 ComponentIpcSerializableBuffer msg;
1276 NATIVE_INT_TYPE priority = 0;
1277
1278 Os::Queue::QueueStatus msgStatus = this->m_queue.receive(
1279 msg,
1280 priority,
1282 );
1283 FW_ASSERT(
1284 msgStatus == Os::Queue::QUEUE_OK,
1285 static_cast<FwAssertArgType>(msgStatus)
1286 );
1287
1288 // Reset to beginning of buffer
1289 msg.resetDeser();
1290
1291 NATIVE_INT_TYPE desMsg = 0;
1292 Fw::SerializeStatus deserStatus = msg.deserialize(desMsg);
1293 FW_ASSERT(
1294 deserStatus == Fw::FW_SERIALIZE_OK,
1295 static_cast<FwAssertArgType>(deserStatus)
1296 );
1297
1298 MsgTypeEnum msgType = static_cast<MsgTypeEnum>(desMsg);
1299
1300 if (msgType == COMQUEUE_COMPONENT_EXIT) {
1301 return MSG_DISPATCH_EXIT;
1302 }
1303
1304 NATIVE_INT_TYPE portNum = 0;
1305 deserStatus = msg.deserialize(portNum);
1306 FW_ASSERT(
1307 deserStatus == Fw::FW_SERIALIZE_OK,
1308 static_cast<FwAssertArgType>(deserStatus)
1309 );
1310
1311 switch (msgType) {
1312 // Handle async input port buffQueueIn
1313 case BUFFQUEUEIN_BUFFERSEND: {
1314 // Deserialize argument fwBuffer
1315 Fw::Buffer fwBuffer;
1316 deserStatus = msg.deserialize(fwBuffer);
1317 FW_ASSERT(
1318 deserStatus == Fw::FW_SERIALIZE_OK,
1319 static_cast<FwAssertArgType>(deserStatus)
1320 );
1321 // Call handler function
1322 this->buffQueueIn_handler(
1323 portNum,
1324 fwBuffer
1325 );
1326
1327 break;
1328 }
1329
1330 // Handle async input port comQueueIn
1331 case COMQUEUEIN_COM: {
1332 // Deserialize argument data
1333 Fw::ComBuffer data;
1334 deserStatus = msg.deserialize(data);
1335 FW_ASSERT(
1336 deserStatus == Fw::FW_SERIALIZE_OK,
1337 static_cast<FwAssertArgType>(deserStatus)
1338 );
1339
1340 // Deserialize argument context
1341 U32 context;
1342 deserStatus = msg.deserialize(context);
1343 FW_ASSERT(
1344 deserStatus == Fw::FW_SERIALIZE_OK,
1345 static_cast<FwAssertArgType>(deserStatus)
1346 );
1347 // Call handler function
1348 this->comQueueIn_handler(
1349 portNum,
1350 data,
1351 context
1352 );
1353
1354 break;
1355 }
1356
1357 // Handle async input port comStatusIn
1358 case COMSTATUSIN_SUCCESSCONDITION: {
1359 // Deserialize argument condition
1360 Fw::Success condition;
1361 deserStatus = msg.deserialize(condition);
1362 FW_ASSERT(
1363 deserStatus == Fw::FW_SERIALIZE_OK,
1364 static_cast<FwAssertArgType>(deserStatus)
1365 );
1366 // Call handler function
1367 this->comStatusIn_handler(
1368 portNum,
1369 condition
1370 );
1371
1372 break;
1373 }
1374
1375 // Handle async input port run
1376 case RUN_SCHED: {
1377 // Deserialize argument context
1378 NATIVE_UINT_TYPE context;
1379 deserStatus = msg.deserialize(context);
1380 FW_ASSERT(
1381 deserStatus == Fw::FW_SERIALIZE_OK,
1382 static_cast<FwAssertArgType>(deserStatus)
1383 );
1384 // Call handler function
1385 this->run_handler(
1386 portNum,
1387 context
1388 );
1389
1390 break;
1391 }
1392
1393 default:
1394 return MSG_DISPATCH_ERROR;
1395 }
1396
1397 return MSG_DISPATCH_OK;
1398 }
1399
1400 // ----------------------------------------------------------------------
1401 // Calls for messages received on typed input ports
1402 // ----------------------------------------------------------------------
1403
1404 void ComQueueComponentBase ::
1405 m_p_buffQueueIn_in(
1406 Fw::PassiveComponentBase* callComp,
1407 NATIVE_INT_TYPE portNum,
1408 Fw::Buffer& fwBuffer
1409 )
1410 {
1411 FW_ASSERT(callComp);
1412 ComQueueComponentBase* compPtr = static_cast<ComQueueComponentBase*>(callComp);
1413 compPtr->buffQueueIn_handlerBase(
1414 portNum,
1415 fwBuffer
1416 );
1417 }
1418
1419 void ComQueueComponentBase ::
1420 m_p_comQueueIn_in(
1421 Fw::PassiveComponentBase* callComp,
1422 NATIVE_INT_TYPE portNum,
1423 Fw::ComBuffer& data,
1424 U32 context
1425 )
1426 {
1427 FW_ASSERT(callComp);
1428 ComQueueComponentBase* compPtr = static_cast<ComQueueComponentBase*>(callComp);
1429 compPtr->comQueueIn_handlerBase(
1430 portNum,
1431 data,
1432 context
1433 );
1434 }
1435
1436 void ComQueueComponentBase ::
1437 m_p_comStatusIn_in(
1438 Fw::PassiveComponentBase* callComp,
1439 NATIVE_INT_TYPE portNum,
1440 Fw::Success& condition
1441 )
1442 {
1443 FW_ASSERT(callComp);
1444 ComQueueComponentBase* compPtr = static_cast<ComQueueComponentBase*>(callComp);
1445 compPtr->comStatusIn_handlerBase(
1446 portNum,
1447 condition
1448 );
1449 }
1450
1451 void ComQueueComponentBase ::
1452 m_p_run_in(
1453 Fw::PassiveComponentBase* callComp,
1454 NATIVE_INT_TYPE portNum,
1455 NATIVE_UINT_TYPE context
1456 )
1457 {
1458 FW_ASSERT(callComp);
1459 ComQueueComponentBase* compPtr = static_cast<ComQueueComponentBase*>(callComp);
1460 compPtr->run_handlerBase(
1461 portNum,
1462 context
1463 );
1464 }
1465
1466}
#define FW_ASSERT(...)
Definition Assert.hpp:7
PlatformIntType NATIVE_INT_TYPE
Definition BasicTypes.h:51
U8 BYTE
byte type
Definition BasicTypes.h:27
uint8_t U8
8-bit unsigned integer
Definition BasicTypes.h:26
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition BasicTypes.h:66
PlatformUIntType NATIVE_UINT_TYPE
Definition BasicTypes.h:52
int PlatformIntType
DefaultTypes.hpp provides fallback defaults for the platform types.
#define PRI_PlatformIntType
@ TB_NONE
No time base has been established.
Definition FpConfig.h:39
PlatformAssertArgType FwAssertArgType
Definition FpConfig.h:21
U32 FwChanIdType
Definition FpConfig.h:59
U32 FwEventIdType
Definition FpConfig.h:62
#define FW_LOG_TEXT_BUFFER_SIZE
Max size of string for text log message.
Definition FpConfig.h:291
#define FW_OBJECT_NAMES
Indicates whether or not object names are stored (more memory, can be used for tracking objects)
Definition FpConfig.h:82
@ ACTIVE_COMPONENT_EXIT
message to exit active component task
Input BufferSend port.
@ SERIALIZED_SIZE
The size of the serial representations of the port arguments.
@ SERIALIZED_SIZE
The size of the serial representations of the port arguments.
Definition ComPortAc.hpp:37
@ SERIALIZED_SIZE
The size of the serial representations of the port arguments.
@ WARNING_HI
A serious but recoverable event.
void init()
Object initializer.
Definition ObjBase.cpp:27
SerializeStatus serialize(U8 val)
serialize 8-bit unsigned int
const char * toChar() const
gets char buffer
Definition String.cpp:48
Success/Failure.
@ QUEUE_OK
message sent/received okay
Definition Queue.hpp:28
@ QUEUE_FULL
queue was full when attempting to send a message
Definition Queue.hpp:36
QueueBlocking
Definition Queue.hpp:40
@ QUEUE_BLOCKING
Queue receive blocks until a message arrives.
Definition Queue.hpp:41
@ QUEUE_NONBLOCKING
Queue receive always returns even if there is no message.
Definition Queue.hpp:42
Array of queue depths for Fw::Buffer types.
Array of queue depths for Fw::Com types.
@ SERIALIZED_SIZE
The size of the serial representations of the port arguments.
An enumeration of queue data types.
@ SERIALIZED_SIZE
The size of the serial representation.
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.
const Time ZERO_TIME
Definition Time.cpp:5