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
StreamCrossoverComponentAc.cpp
Go to the documentation of this file.
1// ======================================================================
2// \title StreamCrossoverComponentAc.cpp
3// \author Generated by fpp-to-cpp
4// \brief cpp file for StreamCrossover 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 Drv {
16
17 namespace {
18 // Get the max size by doing a union of the input and internal port serialization sizes
19 union BuffUnion {
21 };
22
23 // Define a message buffer class large enough to handle all the
24 // asynchronous inputs to the component
25 class ComponentIpcSerializableBuffer :
27 {
28
29 public:
30
31 enum {
32 // Max. message size = size of data + message id + port
33 SERIALIZATION_SIZE =
34 sizeof(BuffUnion) +
35 sizeof(NATIVE_INT_TYPE) +
36 sizeof(NATIVE_INT_TYPE)
37 };
38
39 NATIVE_UINT_TYPE getBuffCapacity() const {
40 return sizeof(m_buff);
41 }
42
43 U8* getBuffAddr() {
44 return m_buff;
45 }
46
47 const U8* getBuffAddr() const {
48 return m_buff;
49 }
50
51 private:
52 // Should be the max of all the input ports serialized sizes...
53 U8 m_buff[SERIALIZATION_SIZE];
54
55 };
56 }
57
58 // ----------------------------------------------------------------------
59 // Component initialization
60 // ----------------------------------------------------------------------
61
62 void StreamCrossoverComponentBase ::
63 init(NATIVE_INT_TYPE instance)
64 {
65 // Initialize base class
67
68 // Connect input port streamIn
69 for (
70 PlatformIntType port = 0;
71 port < static_cast<PlatformIntType>(this->getNum_streamIn_InputPorts());
72 port++
73 ) {
74 this->m_streamIn_InputPort[port].init();
75 this->m_streamIn_InputPort[port].addCallComp(
76 this,
77 m_p_streamIn_in
78 );
79 this->m_streamIn_InputPort[port].setPortNum(port);
80
81#if FW_OBJECT_NAMES == 1
82 char portName[120];
83 (void) snprintf(
84 portName,
85 sizeof(portName),
86 "%s_streamIn_InputPort[%" PRI_PlatformIntType "]",
87 this->m_objName,
88 port
89 );
90 this->m_streamIn_InputPort[port].setObjName(portName);
91#endif
92 }
93
94 // Connect output port logOut
95 for (
96 PlatformIntType port = 0;
97 port < static_cast<PlatformIntType>(this->getNum_logOut_OutputPorts());
98 port++
99 ) {
100 this->m_logOut_OutputPort[port].init();
101
102#if FW_OBJECT_NAMES == 1
103 char portName[120];
104 (void) snprintf(
105 portName,
106 sizeof(portName),
107 "%s_logOut_OutputPort[%" PRI_PlatformIntType "]",
108 this->m_objName,
109 port
110 );
111 this->m_logOut_OutputPort[port].setObjName(portName);
112#endif
113 }
114
115#if FW_ENABLE_TEXT_LOGGING == 1
116 // Connect output port logTextOut
117 for (
118 PlatformIntType port = 0;
119 port < static_cast<PlatformIntType>(this->getNum_logTextOut_OutputPorts());
120 port++
121 ) {
122 this->m_logTextOut_OutputPort[port].init();
123
124#if FW_OBJECT_NAMES == 1
125 char portName[120];
126 (void) snprintf(
127 portName,
128 sizeof(portName),
129 "%s_logTextOut_OutputPort[%" PRI_PlatformIntType "]",
130 this->m_objName,
131 port
132 );
133 this->m_logTextOut_OutputPort[port].setObjName(portName);
134#endif
135 }
136#endif
137
138 // Connect output port timeCaller
139 for (
140 PlatformIntType port = 0;
141 port < static_cast<PlatformIntType>(this->getNum_timeCaller_OutputPorts());
142 port++
143 ) {
144 this->m_timeCaller_OutputPort[port].init();
145
146#if FW_OBJECT_NAMES == 1
147 char portName[120];
148 (void) snprintf(
149 portName,
150 sizeof(portName),
151 "%s_timeCaller_OutputPort[%" PRI_PlatformIntType "]",
152 this->m_objName,
153 port
154 );
155 this->m_timeCaller_OutputPort[port].setObjName(portName);
156#endif
157 }
158
159 // Connect output port errorDeallocate
160 for (
161 PlatformIntType port = 0;
162 port < static_cast<PlatformIntType>(this->getNum_errorDeallocate_OutputPorts());
163 port++
164 ) {
165 this->m_errorDeallocate_OutputPort[port].init();
166
167#if FW_OBJECT_NAMES == 1
168 char portName[120];
169 (void) snprintf(
170 portName,
171 sizeof(portName),
172 "%s_errorDeallocate_OutputPort[%" PRI_PlatformIntType "]",
173 this->m_objName,
174 port
175 );
176 this->m_errorDeallocate_OutputPort[port].setObjName(portName);
177#endif
178 }
179
180 // Connect output port streamOut
181 for (
182 PlatformIntType port = 0;
183 port < static_cast<PlatformIntType>(this->getNum_streamOut_OutputPorts());
184 port++
185 ) {
186 this->m_streamOut_OutputPort[port].init();
187
188#if FW_OBJECT_NAMES == 1
189 char portName[120];
190 (void) snprintf(
191 portName,
192 sizeof(portName),
193 "%s_streamOut_OutputPort[%" PRI_PlatformIntType "]",
194 this->m_objName,
195 port
196 );
197 this->m_streamOut_OutputPort[port].setObjName(portName);
198#endif
199 }
200 }
201
202 // ----------------------------------------------------------------------
203 // Getters for typed input ports
204 // ----------------------------------------------------------------------
205
206 Drv::InputByteStreamRecvPort* StreamCrossoverComponentBase ::
207 get_streamIn_InputPort(NATIVE_INT_TYPE portNum)
208 {
209 FW_ASSERT(
210 portNum < this->getNum_streamIn_InputPorts(),
211 static_cast<FwAssertArgType>(portNum)
212 );
213
214 return &this->m_streamIn_InputPort[portNum];
215 }
216
217 // ----------------------------------------------------------------------
218 // Connect special input ports to special output ports
219 // ----------------------------------------------------------------------
220
221 void StreamCrossoverComponentBase ::
222 set_logOut_OutputPort(
223 NATIVE_INT_TYPE portNum,
224 Fw::InputLogPort* port
225 )
226 {
227 FW_ASSERT(
228 portNum < this->getNum_logOut_OutputPorts(),
229 static_cast<FwAssertArgType>(portNum)
230 );
231
232 this->m_logOut_OutputPort[portNum].addCallPort(port);
233 }
234
235#if FW_ENABLE_TEXT_LOGGING == 1
236
237 void StreamCrossoverComponentBase ::
238 set_logTextOut_OutputPort(
239 NATIVE_INT_TYPE portNum,
241 )
242 {
243 FW_ASSERT(
244 portNum < this->getNum_logTextOut_OutputPorts(),
245 static_cast<FwAssertArgType>(portNum)
246 );
247
248 this->m_logTextOut_OutputPort[portNum].addCallPort(port);
249 }
250
251#endif
252
253 void StreamCrossoverComponentBase ::
254 set_timeCaller_OutputPort(
255 NATIVE_INT_TYPE portNum,
257 )
258 {
259 FW_ASSERT(
260 portNum < this->getNum_timeCaller_OutputPorts(),
261 static_cast<FwAssertArgType>(portNum)
262 );
263
264 this->m_timeCaller_OutputPort[portNum].addCallPort(port);
265 }
266
267 // ----------------------------------------------------------------------
268 // Connect typed input ports to typed output ports
269 // ----------------------------------------------------------------------
270
271 void StreamCrossoverComponentBase ::
272 set_errorDeallocate_OutputPort(
273 NATIVE_INT_TYPE portNum,
275 )
276 {
277 FW_ASSERT(
278 portNum < this->getNum_errorDeallocate_OutputPorts(),
279 static_cast<FwAssertArgType>(portNum)
280 );
281
282 this->m_errorDeallocate_OutputPort[portNum].addCallPort(port);
283 }
284
285 void StreamCrossoverComponentBase ::
286 set_streamOut_OutputPort(
287 NATIVE_INT_TYPE portNum,
289 )
290 {
291 FW_ASSERT(
292 portNum < this->getNum_streamOut_OutputPorts(),
293 static_cast<FwAssertArgType>(portNum)
294 );
295
296 this->m_streamOut_OutputPort[portNum].addCallPort(port);
297 }
298
299#if FW_PORT_SERIALIZATION
300
301 // ----------------------------------------------------------------------
302 // Connect serial input ports to special output ports
303 // ----------------------------------------------------------------------
304
305 void StreamCrossoverComponentBase ::
306 set_logOut_OutputPort(
307 NATIVE_INT_TYPE portNum,
308 Fw::InputSerializePort* port
309 )
310 {
311 FW_ASSERT(
312 portNum < this->getNum_logOut_OutputPorts(),
313 static_cast<FwAssertArgType>(portNum)
314 );
315
316 this->m_logOut_OutputPort[portNum].registerSerialPort(port);
317 }
318
319#if FW_ENABLE_TEXT_LOGGING == 1
320
321 void StreamCrossoverComponentBase ::
322 set_logTextOut_OutputPort(
323 NATIVE_INT_TYPE portNum,
324 Fw::InputSerializePort* port
325 )
326 {
327 FW_ASSERT(
328 portNum < this->getNum_logTextOut_OutputPorts(),
329 static_cast<FwAssertArgType>(portNum)
330 );
331
332 this->m_logTextOut_OutputPort[portNum].registerSerialPort(port);
333 }
334
335#endif
336
337 void StreamCrossoverComponentBase ::
338 set_timeCaller_OutputPort(
339 NATIVE_INT_TYPE portNum,
340 Fw::InputSerializePort* port
341 )
342 {
343 FW_ASSERT(
344 portNum < this->getNum_timeCaller_OutputPorts(),
345 static_cast<FwAssertArgType>(portNum)
346 );
347
348 this->m_timeCaller_OutputPort[portNum].registerSerialPort(port);
349 }
350
351#endif
352
353#if FW_PORT_SERIALIZATION
354
355 // ----------------------------------------------------------------------
356 // Connect serial input ports to typed output ports
357 // ----------------------------------------------------------------------
358
359 void StreamCrossoverComponentBase ::
360 set_errorDeallocate_OutputPort(
361 NATIVE_INT_TYPE portNum,
362 Fw::InputSerializePort* port
363 )
364 {
365 FW_ASSERT(
366 portNum < this->getNum_errorDeallocate_OutputPorts(),
367 static_cast<FwAssertArgType>(portNum)
368 );
369
370 this->m_errorDeallocate_OutputPort[portNum].registerSerialPort(port);
371 }
372
373#endif
374
375 // ----------------------------------------------------------------------
376 // Component construction and destruction
377 // ----------------------------------------------------------------------
378
379 StreamCrossoverComponentBase ::
380 StreamCrossoverComponentBase(const char* compName) :
381 Fw::PassiveComponentBase(compName)
382 {
383
384 }
385
386 StreamCrossoverComponentBase ::
387 ~StreamCrossoverComponentBase()
388 {
389
390 }
391
392 // ----------------------------------------------------------------------
393 // Getters for numbers of typed input ports
394 // ----------------------------------------------------------------------
395
396 NATIVE_INT_TYPE StreamCrossoverComponentBase ::
397 getNum_streamIn_InputPorts()
398 {
399 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_streamIn_InputPort));
400 }
401
402 // ----------------------------------------------------------------------
403 // Getters for numbers of special output ports
404 // ----------------------------------------------------------------------
405
406 NATIVE_INT_TYPE StreamCrossoverComponentBase ::
407 getNum_logOut_OutputPorts()
408 {
409 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_logOut_OutputPort));
410 }
411
412#if FW_ENABLE_TEXT_LOGGING == 1
413
414 NATIVE_INT_TYPE StreamCrossoverComponentBase ::
415 getNum_logTextOut_OutputPorts()
416 {
417 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_logTextOut_OutputPort));
418 }
419
420#endif
421
422 NATIVE_INT_TYPE StreamCrossoverComponentBase ::
423 getNum_timeCaller_OutputPorts()
424 {
425 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_timeCaller_OutputPort));
426 }
427
428 // ----------------------------------------------------------------------
429 // Getters for numbers of typed output ports
430 // ----------------------------------------------------------------------
431
432 NATIVE_INT_TYPE StreamCrossoverComponentBase ::
433 getNum_errorDeallocate_OutputPorts()
434 {
435 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_errorDeallocate_OutputPort));
436 }
437
438 NATIVE_INT_TYPE StreamCrossoverComponentBase ::
439 getNum_streamOut_OutputPorts()
440 {
441 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_streamOut_OutputPort));
442 }
443
444 // ----------------------------------------------------------------------
445 // Connection status queries for special output ports
446 // ----------------------------------------------------------------------
447
448 bool StreamCrossoverComponentBase ::
449 isConnected_logOut_OutputPort(NATIVE_INT_TYPE portNum)
450 {
451 FW_ASSERT(
452 portNum < this->getNum_logOut_OutputPorts(),
453 static_cast<FwAssertArgType>(portNum)
454 );
455
456 return this->m_logOut_OutputPort[portNum].isConnected();
457 }
458
459#if FW_ENABLE_TEXT_LOGGING == 1
460
461 bool StreamCrossoverComponentBase ::
462 isConnected_logTextOut_OutputPort(NATIVE_INT_TYPE portNum)
463 {
464 FW_ASSERT(
465 portNum < this->getNum_logTextOut_OutputPorts(),
466 static_cast<FwAssertArgType>(portNum)
467 );
468
469 return this->m_logTextOut_OutputPort[portNum].isConnected();
470 }
471
472#endif
473
474 bool StreamCrossoverComponentBase ::
475 isConnected_timeCaller_OutputPort(NATIVE_INT_TYPE portNum)
476 {
477 FW_ASSERT(
478 portNum < this->getNum_timeCaller_OutputPorts(),
479 static_cast<FwAssertArgType>(portNum)
480 );
481
482 return this->m_timeCaller_OutputPort[portNum].isConnected();
483 }
484
485 // ----------------------------------------------------------------------
486 // Connection status queries for typed output ports
487 // ----------------------------------------------------------------------
488
489 bool StreamCrossoverComponentBase ::
490 isConnected_errorDeallocate_OutputPort(NATIVE_INT_TYPE portNum)
491 {
492 FW_ASSERT(
493 portNum < this->getNum_errorDeallocate_OutputPorts(),
494 static_cast<FwAssertArgType>(portNum)
495 );
496
497 return this->m_errorDeallocate_OutputPort[portNum].isConnected();
498 }
499
500 bool StreamCrossoverComponentBase ::
501 isConnected_streamOut_OutputPort(NATIVE_INT_TYPE portNum)
502 {
503 FW_ASSERT(
504 portNum < this->getNum_streamOut_OutputPorts(),
505 static_cast<FwAssertArgType>(portNum)
506 );
507
508 return this->m_streamOut_OutputPort[portNum].isConnected();
509 }
510
511 // ----------------------------------------------------------------------
512 // Port handler base-class functions for typed input ports
513 //
514 // Call these functions directly to bypass the corresponding ports
515 // ----------------------------------------------------------------------
516
517 void StreamCrossoverComponentBase ::
518 streamIn_handlerBase(
519 NATIVE_INT_TYPE portNum,
520 Fw::Buffer& recvBuffer,
521 const Drv::RecvStatus& recvStatus
522 )
523 {
524 // Make sure port number is valid
525 FW_ASSERT(
526 portNum < this->getNum_streamIn_InputPorts(),
527 static_cast<FwAssertArgType>(portNum)
528 );
529
530 // Down call to pure virtual handler method implemented in Impl class
531 this->streamIn_handler(
532 portNum,
533 recvBuffer,
534 recvStatus
535 );
536 }
537
538 // ----------------------------------------------------------------------
539 // Invocation functions for typed output ports
540 // ----------------------------------------------------------------------
541
542 void StreamCrossoverComponentBase ::
543 errorDeallocate_out(
544 NATIVE_INT_TYPE portNum,
545 Fw::Buffer& fwBuffer
546 )
547 {
548 FW_ASSERT(
549 portNum < this->getNum_errorDeallocate_OutputPorts(),
550 static_cast<FwAssertArgType>(portNum)
551 );
552 this->m_errorDeallocate_OutputPort[portNum].invoke(
553 fwBuffer
554 );
555 }
556
557 Drv::SendStatus StreamCrossoverComponentBase ::
558 streamOut_out(
559 NATIVE_INT_TYPE portNum,
560 Fw::Buffer& sendBuffer
561 )
562 {
563 FW_ASSERT(
564 portNum < this->getNum_streamOut_OutputPorts(),
565 static_cast<FwAssertArgType>(portNum)
566 );
567 return this->m_streamOut_OutputPort[portNum].invoke(
568 sendBuffer
569 );
570 }
571
572 // ----------------------------------------------------------------------
573 // Event logging functions
574 // ----------------------------------------------------------------------
575
576 void StreamCrossoverComponentBase ::
577 log_WARNING_HI_StreamOutError(Drv::SendStatus sendStatus)
578 {
579 // Get the time
580 Fw::Time _logTime;
581 if (this->m_timeCaller_OutputPort[0].isConnected()) {
582 this->m_timeCaller_OutputPort[0].invoke(_logTime);
583 }
584
585 FwEventIdType _id = static_cast<FwEventIdType>(0);
586
587 _id = this->getIdBase() + EVENTID_STREAMOUTERROR;
588
589 // Emit the event on the log port
590 if (this->m_logOut_OutputPort[0].isConnected()) {
591 Fw::LogBuffer _logBuff;
593
594#if FW_AMPCS_COMPATIBLE
595 // Serialize the number of arguments
596 _status = _logBuff.serialize(static_cast<U8>(1));
597 FW_ASSERT(
598 _status == Fw::FW_SERIALIZE_OK,
599 static_cast<FwAssertArgType>(_status)
600 );
601#endif
602
603#if FW_AMPCS_COMPATIBLE
604 // Serialize the argument size
605 _status = _logBuff.serialize(
607 );
608 FW_ASSERT(
609 _status == Fw::FW_SERIALIZE_OK,
610 static_cast<FwAssertArgType>(_status)
611 );
612#endif
613 _status = _logBuff.serialize(sendStatus);
614 FW_ASSERT(
615 _status == Fw::FW_SERIALIZE_OK,
616 static_cast<FwAssertArgType>(_status)
617 );
618
619 this->m_logOut_OutputPort[0].invoke(
620 _id,
621 _logTime,
623 _logBuff
624 );
625 }
626
627 // Emit the event on the text log port
628#if FW_ENABLE_TEXT_LOGGING
629 if (this->m_logTextOut_OutputPort[0].isConnected()) {
630#if FW_OBJECT_NAMES == 1
631 const char* _formatString =
632 "(%s) %s: StreamCrossover StreamOut Error: %s";
633#else
634 const char* _formatString =
635 "%s: StreamCrossover StreamOut Error: %s";
636#endif
637
638 char _textBuffer[FW_LOG_TEXT_BUFFER_SIZE];
639
640 Fw::String sendStatusStr;
641 sendStatus.toString(sendStatusStr);
642
643 (void) snprintf(
644 _textBuffer,
646 _formatString,
647#if FW_OBJECT_NAMES == 1
648 this->m_objName,
649#endif
650 "StreamOutError ",
651 sendStatusStr.toChar()
652 );
653
654 // Null terminate
655 _textBuffer[FW_LOG_TEXT_BUFFER_SIZE-1] = 0;
656 Fw::TextLogString _logString = _textBuffer;
657 this->m_logTextOut_OutputPort[0].invoke(
658 _id,
659 _logTime,
661 _logString
662 );
663 }
664#endif
665 }
666
667 // ----------------------------------------------------------------------
668 // Time
669 // ----------------------------------------------------------------------
670
671 Fw::Time StreamCrossoverComponentBase ::
672 getTime()
673 {
674 if (this->m_timeCaller_OutputPort[0].isConnected()) {
675 Fw::Time _time;
676 this->m_timeCaller_OutputPort[0].invoke(_time);
677 return _time;
678 }
679 else {
680 return Fw::Time(TB_NONE, 0, 0);
681 }
682 }
683
684 // ----------------------------------------------------------------------
685 // Calls for messages received on typed input ports
686 // ----------------------------------------------------------------------
687
688 void StreamCrossoverComponentBase ::
689 m_p_streamIn_in(
690 Fw::PassiveComponentBase* callComp,
691 NATIVE_INT_TYPE portNum,
692 Fw::Buffer& recvBuffer,
693 const Drv::RecvStatus& recvStatus
694 )
695 {
696 FW_ASSERT(callComp);
697 StreamCrossoverComponentBase* compPtr = static_cast<StreamCrossoverComponentBase*>(callComp);
698 compPtr->streamIn_handlerBase(
699 portNum,
700 recvBuffer,
701 recvStatus
702 );
703 }
704
705}
#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 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
BYTE streamInPortSize[Drv::InputByteStreamRecvPort::SERIALIZED_SIZE]
Input ByteStreamRecv port.
@ SERIALIZED_SIZE
The size of the serial representations of the port arguments.
Input ByteStreamSend port.
@ SERIALIZED_SIZE
The size of the serial representation.
Auto-generated base for StreamCrossover component.
void streamIn_handlerBase(NATIVE_INT_TYPE portNum, Fw::Buffer &recvBuffer, const Drv::RecvStatus &recvStatus)
Handler base-class function for input port streamIn.
Input BufferSend port.
@ 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
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.