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