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
BufferLoggerComponentAc.cpp
Go to the documentation of this file.
1// ======================================================================
2// \title BufferLoggerComponentAc.cpp
3// \author Generated by fpp-to-cpp
4// \brief cpp file for BufferLogger 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 BUFFERLOGGER_COMPONENT_EXIT = Fw::ActiveComponentBase::ACTIVE_COMPONENT_EXIT,
20 BUFFERSENDIN_BUFFERSEND,
21 COMIN_COM,
22 PINGIN_PING,
23 SCHEDIN_SCHED,
24 CMD_BL_OPENFILE,
25 CMD_BL_CLOSEFILE,
26 CMD_BL_SETLOGGING,
27 CMD_BL_FLUSHFILE,
28 };
29
30 // Get the max size by constructing a union of the async input, command, and
31 // internal port serialization sizes
32 union BuffUnion {
38 };
39
40 // Define a message buffer class large enough to handle all the
41 // asynchronous inputs to the component
42 class ComponentIpcSerializableBuffer :
44 {
45
46 public:
47
48 enum {
49 // Max. message size = size of data + message id + port
50 SERIALIZATION_SIZE =
51 sizeof(BuffUnion) +
52 sizeof(NATIVE_INT_TYPE) +
53 sizeof(NATIVE_INT_TYPE)
54 };
55
56 NATIVE_UINT_TYPE getBuffCapacity() const {
57 return sizeof(m_buff);
58 }
59
60 U8* getBuffAddr() {
61 return m_buff;
62 }
63
64 const U8* getBuffAddr() const {
65 return m_buff;
66 }
67
68 private:
69 // Should be the max of all the input ports serialized sizes...
70 U8 m_buff[SERIALIZATION_SIZE];
71
72 };
73 }
74
75 // ----------------------------------------------------------------------
76 // Component initialization
77 // ----------------------------------------------------------------------
78
79 void BufferLoggerComponentBase ::
80 init(
81 NATIVE_INT_TYPE queueDepth,
82 NATIVE_INT_TYPE instance
83 )
84 {
85 // Initialize base class
87
88 // Connect input port cmdIn
89 for (
90 PlatformIntType port = 0;
91 port < static_cast<PlatformIntType>(this->getNum_cmdIn_InputPorts());
92 port++
93 ) {
94 this->m_cmdIn_InputPort[port].init();
95 this->m_cmdIn_InputPort[port].addCallComp(
96 this,
97 m_p_cmdIn_in
98 );
99 this->m_cmdIn_InputPort[port].setPortNum(port);
100
101#if FW_OBJECT_NAMES == 1
102 // The port name consists of this->m_objName and some extra info.
103 // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
104 // However, the compiler may assume that this->m_objName fills
105 // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
106 // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
107 // bytes to cover the extra info.
108 char portName[2*FW_OBJ_NAME_MAX_SIZE];
109 (void) snprintf(
110 portName,
111 sizeof(portName),
112 "%s_cmdIn_InputPort[%" PRI_PlatformIntType "]",
113 this->m_objName,
114 port
115 );
116 this->m_cmdIn_InputPort[port].setObjName(portName);
117#endif
118 }
119
120 // Connect input port bufferSendIn
121 for (
122 PlatformIntType port = 0;
123 port < static_cast<PlatformIntType>(this->getNum_bufferSendIn_InputPorts());
124 port++
125 ) {
126 this->m_bufferSendIn_InputPort[port].init();
127 this->m_bufferSendIn_InputPort[port].addCallComp(
128 this,
129 m_p_bufferSendIn_in
130 );
131 this->m_bufferSendIn_InputPort[port].setPortNum(port);
132
133#if FW_OBJECT_NAMES == 1
134 // The port name consists of this->m_objName and some extra info.
135 // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
136 // However, the compiler may assume that this->m_objName fills
137 // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
138 // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
139 // bytes to cover the extra info.
140 char portName[2*FW_OBJ_NAME_MAX_SIZE];
141 (void) snprintf(
142 portName,
143 sizeof(portName),
144 "%s_bufferSendIn_InputPort[%" PRI_PlatformIntType "]",
145 this->m_objName,
146 port
147 );
148 this->m_bufferSendIn_InputPort[port].setObjName(portName);
149#endif
150 }
151
152 // Connect input port comIn
153 for (
154 PlatformIntType port = 0;
155 port < static_cast<PlatformIntType>(this->getNum_comIn_InputPorts());
156 port++
157 ) {
158 this->m_comIn_InputPort[port].init();
159 this->m_comIn_InputPort[port].addCallComp(
160 this,
161 m_p_comIn_in
162 );
163 this->m_comIn_InputPort[port].setPortNum(port);
164
165#if FW_OBJECT_NAMES == 1
166 // The port name consists of this->m_objName and some extra info.
167 // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
168 // However, the compiler may assume that this->m_objName fills
169 // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
170 // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
171 // bytes to cover the extra info.
172 char portName[2*FW_OBJ_NAME_MAX_SIZE];
173 (void) snprintf(
174 portName,
175 sizeof(portName),
176 "%s_comIn_InputPort[%" PRI_PlatformIntType "]",
177 this->m_objName,
178 port
179 );
180 this->m_comIn_InputPort[port].setObjName(portName);
181#endif
182 }
183
184 // Connect input port pingIn
185 for (
186 PlatformIntType port = 0;
187 port < static_cast<PlatformIntType>(this->getNum_pingIn_InputPorts());
188 port++
189 ) {
190 this->m_pingIn_InputPort[port].init();
191 this->m_pingIn_InputPort[port].addCallComp(
192 this,
193 m_p_pingIn_in
194 );
195 this->m_pingIn_InputPort[port].setPortNum(port);
196
197#if FW_OBJECT_NAMES == 1
198 // The port name consists of this->m_objName and some extra info.
199 // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
200 // However, the compiler may assume that this->m_objName fills
201 // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
202 // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
203 // bytes to cover the extra info.
204 char portName[2*FW_OBJ_NAME_MAX_SIZE];
205 (void) snprintf(
206 portName,
207 sizeof(portName),
208 "%s_pingIn_InputPort[%" PRI_PlatformIntType "]",
209 this->m_objName,
210 port
211 );
212 this->m_pingIn_InputPort[port].setObjName(portName);
213#endif
214 }
215
216 // Connect input port schedIn
217 for (
218 PlatformIntType port = 0;
219 port < static_cast<PlatformIntType>(this->getNum_schedIn_InputPorts());
220 port++
221 ) {
222 this->m_schedIn_InputPort[port].init();
223 this->m_schedIn_InputPort[port].addCallComp(
224 this,
225 m_p_schedIn_in
226 );
227 this->m_schedIn_InputPort[port].setPortNum(port);
228
229#if FW_OBJECT_NAMES == 1
230 // The port name consists of this->m_objName and some extra info.
231 // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
232 // However, the compiler may assume that this->m_objName fills
233 // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
234 // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
235 // bytes to cover the extra info.
236 char portName[2*FW_OBJ_NAME_MAX_SIZE];
237 (void) snprintf(
238 portName,
239 sizeof(portName),
240 "%s_schedIn_InputPort[%" PRI_PlatformIntType "]",
241 this->m_objName,
242 port
243 );
244 this->m_schedIn_InputPort[port].setObjName(portName);
245#endif
246 }
247
248 // Connect output port cmdRegOut
249 for (
250 PlatformIntType port = 0;
251 port < static_cast<PlatformIntType>(this->getNum_cmdRegOut_OutputPorts());
252 port++
253 ) {
254 this->m_cmdRegOut_OutputPort[port].init();
255
256#if FW_OBJECT_NAMES == 1
257 // The port name consists of this->m_objName and some extra info.
258 // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
259 // However, the compiler may assume that this->m_objName fills
260 // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
261 // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
262 // bytes to cover the extra info.
263 char portName[2*FW_OBJ_NAME_MAX_SIZE];
264 (void) snprintf(
265 portName,
266 sizeof(portName),
267 "%s_cmdRegOut_OutputPort[%" PRI_PlatformIntType "]",
268 this->m_objName,
269 port
270 );
271 this->m_cmdRegOut_OutputPort[port].setObjName(portName);
272#endif
273 }
274
275 // Connect output port cmdResponseOut
276 for (
277 PlatformIntType port = 0;
278 port < static_cast<PlatformIntType>(this->getNum_cmdResponseOut_OutputPorts());
279 port++
280 ) {
281 this->m_cmdResponseOut_OutputPort[port].init();
282
283#if FW_OBJECT_NAMES == 1
284 // The port name consists of this->m_objName and some extra info.
285 // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
286 // However, the compiler may assume that this->m_objName fills
287 // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
288 // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
289 // bytes to cover the extra info.
290 char portName[2*FW_OBJ_NAME_MAX_SIZE];
291 (void) snprintf(
292 portName,
293 sizeof(portName),
294 "%s_cmdResponseOut_OutputPort[%" PRI_PlatformIntType "]",
295 this->m_objName,
296 port
297 );
298 this->m_cmdResponseOut_OutputPort[port].setObjName(portName);
299#endif
300 }
301
302 // Connect output port eventOut
303 for (
304 PlatformIntType port = 0;
305 port < static_cast<PlatformIntType>(this->getNum_eventOut_OutputPorts());
306 port++
307 ) {
308 this->m_eventOut_OutputPort[port].init();
309
310#if FW_OBJECT_NAMES == 1
311 // The port name consists of this->m_objName and some extra info.
312 // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
313 // However, the compiler may assume that this->m_objName fills
314 // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
315 // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
316 // bytes to cover the extra info.
317 char portName[2*FW_OBJ_NAME_MAX_SIZE];
318 (void) snprintf(
319 portName,
320 sizeof(portName),
321 "%s_eventOut_OutputPort[%" PRI_PlatformIntType "]",
322 this->m_objName,
323 port
324 );
325 this->m_eventOut_OutputPort[port].setObjName(portName);
326#endif
327 }
328
329#if FW_ENABLE_TEXT_LOGGING == 1
330 // Connect output port eventOutText
331 for (
332 PlatformIntType port = 0;
333 port < static_cast<PlatformIntType>(this->getNum_eventOutText_OutputPorts());
334 port++
335 ) {
336 this->m_eventOutText_OutputPort[port].init();
337
338#if FW_OBJECT_NAMES == 1
339 // The port name consists of this->m_objName and some extra info.
340 // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
341 // However, the compiler may assume that this->m_objName fills
342 // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
343 // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
344 // bytes to cover the extra info.
345 char portName[2*FW_OBJ_NAME_MAX_SIZE];
346 (void) snprintf(
347 portName,
348 sizeof(portName),
349 "%s_eventOutText_OutputPort[%" PRI_PlatformIntType "]",
350 this->m_objName,
351 port
352 );
353 this->m_eventOutText_OutputPort[port].setObjName(portName);
354#endif
355 }
356#endif
357
358 // Connect output port timeCaller
359 for (
360 PlatformIntType port = 0;
361 port < static_cast<PlatformIntType>(this->getNum_timeCaller_OutputPorts());
362 port++
363 ) {
364 this->m_timeCaller_OutputPort[port].init();
365
366#if FW_OBJECT_NAMES == 1
367 // The port name consists of this->m_objName and some extra info.
368 // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
369 // However, the compiler may assume that this->m_objName fills
370 // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
371 // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
372 // bytes to cover the extra info.
373 char portName[2*FW_OBJ_NAME_MAX_SIZE];
374 (void) snprintf(
375 portName,
376 sizeof(portName),
377 "%s_timeCaller_OutputPort[%" PRI_PlatformIntType "]",
378 this->m_objName,
379 port
380 );
381 this->m_timeCaller_OutputPort[port].setObjName(portName);
382#endif
383 }
384
385 // Connect output port tlmOut
386 for (
387 PlatformIntType port = 0;
388 port < static_cast<PlatformIntType>(this->getNum_tlmOut_OutputPorts());
389 port++
390 ) {
391 this->m_tlmOut_OutputPort[port].init();
392
393#if FW_OBJECT_NAMES == 1
394 // The port name consists of this->m_objName and some extra info.
395 // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
396 // However, the compiler may assume that this->m_objName fills
397 // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
398 // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
399 // bytes to cover the extra info.
400 char portName[2*FW_OBJ_NAME_MAX_SIZE];
401 (void) snprintf(
402 portName,
403 sizeof(portName),
404 "%s_tlmOut_OutputPort[%" PRI_PlatformIntType "]",
405 this->m_objName,
406 port
407 );
408 this->m_tlmOut_OutputPort[port].setObjName(portName);
409#endif
410 }
411
412 // Connect output port bufferSendOut
413 for (
414 PlatformIntType port = 0;
415 port < static_cast<PlatformIntType>(this->getNum_bufferSendOut_OutputPorts());
416 port++
417 ) {
418 this->m_bufferSendOut_OutputPort[port].init();
419
420#if FW_OBJECT_NAMES == 1
421 // The port name consists of this->m_objName and some extra info.
422 // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
423 // However, the compiler may assume that this->m_objName fills
424 // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
425 // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
426 // bytes to cover the extra info.
427 char portName[2*FW_OBJ_NAME_MAX_SIZE];
428 (void) snprintf(
429 portName,
430 sizeof(portName),
431 "%s_bufferSendOut_OutputPort[%" PRI_PlatformIntType "]",
432 this->m_objName,
433 port
434 );
435 this->m_bufferSendOut_OutputPort[port].setObjName(portName);
436#endif
437 }
438
439 // Connect output port pingOut
440 for (
441 PlatformIntType port = 0;
442 port < static_cast<PlatformIntType>(this->getNum_pingOut_OutputPorts());
443 port++
444 ) {
445 this->m_pingOut_OutputPort[port].init();
446
447#if FW_OBJECT_NAMES == 1
448 // The port name consists of this->m_objName and some extra info.
449 // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
450 // However, the compiler may assume that this->m_objName fills
451 // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
452 // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
453 // bytes to cover the extra info.
454 char portName[2*FW_OBJ_NAME_MAX_SIZE];
455 (void) snprintf(
456 portName,
457 sizeof(portName),
458 "%s_pingOut_OutputPort[%" PRI_PlatformIntType "]",
459 this->m_objName,
460 port
461 );
462 this->m_pingOut_OutputPort[port].setObjName(portName);
463#endif
464 }
465
466 Os::Queue::QueueStatus qStat = this->createQueue(
467 queueDepth,
468 ComponentIpcSerializableBuffer::SERIALIZATION_SIZE
469 );
470 FW_ASSERT(
471 Os::Queue::QUEUE_OK == qStat,
472 static_cast<FwAssertArgType>(qStat)
473 );
474 }
475
476 // ----------------------------------------------------------------------
477 // Getters for special input ports
478 // ----------------------------------------------------------------------
479
480 Fw::InputCmdPort* BufferLoggerComponentBase ::
481 get_cmdIn_InputPort(NATIVE_INT_TYPE portNum)
482 {
483 FW_ASSERT(
484 portNum < this->getNum_cmdIn_InputPorts(),
485 static_cast<FwAssertArgType>(portNum)
486 );
487
488 return &this->m_cmdIn_InputPort[portNum];
489 }
490
491 // ----------------------------------------------------------------------
492 // Getters for typed input ports
493 // ----------------------------------------------------------------------
494
495 Fw::InputBufferSendPort* BufferLoggerComponentBase ::
496 get_bufferSendIn_InputPort(NATIVE_INT_TYPE portNum)
497 {
498 FW_ASSERT(
499 portNum < this->getNum_bufferSendIn_InputPorts(),
500 static_cast<FwAssertArgType>(portNum)
501 );
502
503 return &this->m_bufferSendIn_InputPort[portNum];
504 }
505
506 Fw::InputComPort* BufferLoggerComponentBase ::
507 get_comIn_InputPort(NATIVE_INT_TYPE portNum)
508 {
509 FW_ASSERT(
510 portNum < this->getNum_comIn_InputPorts(),
511 static_cast<FwAssertArgType>(portNum)
512 );
513
514 return &this->m_comIn_InputPort[portNum];
515 }
516
517 Svc::InputPingPort* BufferLoggerComponentBase ::
518 get_pingIn_InputPort(NATIVE_INT_TYPE portNum)
519 {
520 FW_ASSERT(
521 portNum < this->getNum_pingIn_InputPorts(),
522 static_cast<FwAssertArgType>(portNum)
523 );
524
525 return &this->m_pingIn_InputPort[portNum];
526 }
527
528 Svc::InputSchedPort* BufferLoggerComponentBase ::
529 get_schedIn_InputPort(NATIVE_INT_TYPE portNum)
530 {
531 FW_ASSERT(
532 portNum < this->getNum_schedIn_InputPorts(),
533 static_cast<FwAssertArgType>(portNum)
534 );
535
536 return &this->m_schedIn_InputPort[portNum];
537 }
538
539 // ----------------------------------------------------------------------
540 // Connect input ports to special output ports
541 // ----------------------------------------------------------------------
542
543 void BufferLoggerComponentBase ::
544 set_cmdRegOut_OutputPort(
545 NATIVE_INT_TYPE portNum,
547 )
548 {
549 FW_ASSERT(
550 portNum < this->getNum_cmdRegOut_OutputPorts(),
551 static_cast<FwAssertArgType>(portNum)
552 );
553
554 this->m_cmdRegOut_OutputPort[portNum].addCallPort(port);
555 }
556
557 void BufferLoggerComponentBase ::
558 set_cmdResponseOut_OutputPort(
559 NATIVE_INT_TYPE portNum,
561 )
562 {
563 FW_ASSERT(
564 portNum < this->getNum_cmdResponseOut_OutputPorts(),
565 static_cast<FwAssertArgType>(portNum)
566 );
567
568 this->m_cmdResponseOut_OutputPort[portNum].addCallPort(port);
569 }
570
571 void BufferLoggerComponentBase ::
572 set_eventOut_OutputPort(
573 NATIVE_INT_TYPE portNum,
574 Fw::InputLogPort* port
575 )
576 {
577 FW_ASSERT(
578 portNum < this->getNum_eventOut_OutputPorts(),
579 static_cast<FwAssertArgType>(portNum)
580 );
581
582 this->m_eventOut_OutputPort[portNum].addCallPort(port);
583 }
584
585#if FW_ENABLE_TEXT_LOGGING == 1
586
587 void BufferLoggerComponentBase ::
588 set_eventOutText_OutputPort(
589 NATIVE_INT_TYPE portNum,
591 )
592 {
593 FW_ASSERT(
594 portNum < this->getNum_eventOutText_OutputPorts(),
595 static_cast<FwAssertArgType>(portNum)
596 );
597
598 this->m_eventOutText_OutputPort[portNum].addCallPort(port);
599 }
600
601#endif
602
603 void BufferLoggerComponentBase ::
604 set_timeCaller_OutputPort(
605 NATIVE_INT_TYPE portNum,
607 )
608 {
609 FW_ASSERT(
610 portNum < this->getNum_timeCaller_OutputPorts(),
611 static_cast<FwAssertArgType>(portNum)
612 );
613
614 this->m_timeCaller_OutputPort[portNum].addCallPort(port);
615 }
616
617 void BufferLoggerComponentBase ::
618 set_tlmOut_OutputPort(
619 NATIVE_INT_TYPE portNum,
620 Fw::InputTlmPort* port
621 )
622 {
623 FW_ASSERT(
624 portNum < this->getNum_tlmOut_OutputPorts(),
625 static_cast<FwAssertArgType>(portNum)
626 );
627
628 this->m_tlmOut_OutputPort[portNum].addCallPort(port);
629 }
630
631 // ----------------------------------------------------------------------
632 // Connect typed input ports to typed output ports
633 // ----------------------------------------------------------------------
634
635 void BufferLoggerComponentBase ::
636 set_bufferSendOut_OutputPort(
637 NATIVE_INT_TYPE portNum,
639 )
640 {
641 FW_ASSERT(
642 portNum < this->getNum_bufferSendOut_OutputPorts(),
643 static_cast<FwAssertArgType>(portNum)
644 );
645
646 this->m_bufferSendOut_OutputPort[portNum].addCallPort(port);
647 }
648
649 void BufferLoggerComponentBase ::
650 set_pingOut_OutputPort(
651 NATIVE_INT_TYPE portNum,
653 )
654 {
655 FW_ASSERT(
656 portNum < this->getNum_pingOut_OutputPorts(),
657 static_cast<FwAssertArgType>(portNum)
658 );
659
660 this->m_pingOut_OutputPort[portNum].addCallPort(port);
661 }
662
663#if FW_PORT_SERIALIZATION
664
665 // ----------------------------------------------------------------------
666 // Connect serial input ports to special output ports
667 // ----------------------------------------------------------------------
668
669 void BufferLoggerComponentBase ::
670 set_cmdRegOut_OutputPort(
671 NATIVE_INT_TYPE portNum,
672 Fw::InputSerializePort* port
673 )
674 {
675 FW_ASSERT(
676 portNum < this->getNum_cmdRegOut_OutputPorts(),
677 static_cast<FwAssertArgType>(portNum)
678 );
679
680 this->m_cmdRegOut_OutputPort[portNum].registerSerialPort(port);
681 }
682
683 void BufferLoggerComponentBase ::
684 set_cmdResponseOut_OutputPort(
685 NATIVE_INT_TYPE portNum,
686 Fw::InputSerializePort* port
687 )
688 {
689 FW_ASSERT(
690 portNum < this->getNum_cmdResponseOut_OutputPorts(),
691 static_cast<FwAssertArgType>(portNum)
692 );
693
694 this->m_cmdResponseOut_OutputPort[portNum].registerSerialPort(port);
695 }
696
697 void BufferLoggerComponentBase ::
698 set_eventOut_OutputPort(
699 NATIVE_INT_TYPE portNum,
700 Fw::InputSerializePort* port
701 )
702 {
703 FW_ASSERT(
704 portNum < this->getNum_eventOut_OutputPorts(),
705 static_cast<FwAssertArgType>(portNum)
706 );
707
708 this->m_eventOut_OutputPort[portNum].registerSerialPort(port);
709 }
710
711#if FW_ENABLE_TEXT_LOGGING == 1
712
713 void BufferLoggerComponentBase ::
714 set_eventOutText_OutputPort(
715 NATIVE_INT_TYPE portNum,
716 Fw::InputSerializePort* port
717 )
718 {
719 FW_ASSERT(
720 portNum < this->getNum_eventOutText_OutputPorts(),
721 static_cast<FwAssertArgType>(portNum)
722 );
723
724 this->m_eventOutText_OutputPort[portNum].registerSerialPort(port);
725 }
726
727#endif
728
729 void BufferLoggerComponentBase ::
730 set_timeCaller_OutputPort(
731 NATIVE_INT_TYPE portNum,
732 Fw::InputSerializePort* port
733 )
734 {
735 FW_ASSERT(
736 portNum < this->getNum_timeCaller_OutputPorts(),
737 static_cast<FwAssertArgType>(portNum)
738 );
739
740 this->m_timeCaller_OutputPort[portNum].registerSerialPort(port);
741 }
742
743 void BufferLoggerComponentBase ::
744 set_tlmOut_OutputPort(
745 NATIVE_INT_TYPE portNum,
746 Fw::InputSerializePort* port
747 )
748 {
749 FW_ASSERT(
750 portNum < this->getNum_tlmOut_OutputPorts(),
751 static_cast<FwAssertArgType>(portNum)
752 );
753
754 this->m_tlmOut_OutputPort[portNum].registerSerialPort(port);
755 }
756
757#endif
758
759#if FW_PORT_SERIALIZATION
760
761 // ----------------------------------------------------------------------
762 // Connect serial input ports to typed output ports
763 // ----------------------------------------------------------------------
764
765 void BufferLoggerComponentBase ::
766 set_bufferSendOut_OutputPort(
767 NATIVE_INT_TYPE portNum,
768 Fw::InputSerializePort* port
769 )
770 {
771 FW_ASSERT(
772 portNum < this->getNum_bufferSendOut_OutputPorts(),
773 static_cast<FwAssertArgType>(portNum)
774 );
775
776 this->m_bufferSendOut_OutputPort[portNum].registerSerialPort(port);
777 }
778
779 void BufferLoggerComponentBase ::
780 set_pingOut_OutputPort(
781 NATIVE_INT_TYPE portNum,
782 Fw::InputSerializePort* port
783 )
784 {
785 FW_ASSERT(
786 portNum < this->getNum_pingOut_OutputPorts(),
787 static_cast<FwAssertArgType>(portNum)
788 );
789
790 this->m_pingOut_OutputPort[portNum].registerSerialPort(port);
791 }
792
793#endif
794
795 // ----------------------------------------------------------------------
796 // Command registration
797 // ----------------------------------------------------------------------
798
799 void BufferLoggerComponentBase ::
800 regCommands()
801 {
802 FW_ASSERT(this->m_cmdRegOut_OutputPort[0].isConnected());
803
804 this->m_cmdRegOut_OutputPort[0].invoke(
805 this->getIdBase() + OPCODE_BL_OPENFILE
806 );
807
808 this->m_cmdRegOut_OutputPort[0].invoke(
809 this->getIdBase() + OPCODE_BL_CLOSEFILE
810 );
811
812 this->m_cmdRegOut_OutputPort[0].invoke(
813 this->getIdBase() + OPCODE_BL_SETLOGGING
814 );
815
816 this->m_cmdRegOut_OutputPort[0].invoke(
817 this->getIdBase() + OPCODE_BL_FLUSHFILE
818 );
819 }
820
821 // ----------------------------------------------------------------------
822 // Component construction and destruction
823 // ----------------------------------------------------------------------
824
825 BufferLoggerComponentBase ::
826 BufferLoggerComponentBase(const char* compName) :
827 Fw::ActiveComponentBase(compName)
828 {
829
830 }
831
832 BufferLoggerComponentBase ::
833 ~BufferLoggerComponentBase()
834 {
835
836 }
837
838 // ----------------------------------------------------------------------
839 // Getters for numbers of special input ports
840 // ----------------------------------------------------------------------
841
842 NATIVE_INT_TYPE BufferLoggerComponentBase ::
843 getNum_cmdIn_InputPorts() const
844 {
845 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_cmdIn_InputPort));
846 }
847
848 // ----------------------------------------------------------------------
849 // Getters for numbers of typed input ports
850 // ----------------------------------------------------------------------
851
852 NATIVE_INT_TYPE BufferLoggerComponentBase ::
853 getNum_bufferSendIn_InputPorts() const
854 {
855 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_bufferSendIn_InputPort));
856 }
857
858 NATIVE_INT_TYPE BufferLoggerComponentBase ::
859 getNum_comIn_InputPorts() const
860 {
861 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_comIn_InputPort));
862 }
863
864 NATIVE_INT_TYPE BufferLoggerComponentBase ::
865 getNum_pingIn_InputPorts() const
866 {
867 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_pingIn_InputPort));
868 }
869
870 NATIVE_INT_TYPE BufferLoggerComponentBase ::
871 getNum_schedIn_InputPorts() const
872 {
873 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_schedIn_InputPort));
874 }
875
876 // ----------------------------------------------------------------------
877 // Getters for numbers of special output ports
878 // ----------------------------------------------------------------------
879
880 NATIVE_INT_TYPE BufferLoggerComponentBase ::
881 getNum_cmdRegOut_OutputPorts() const
882 {
883 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_cmdRegOut_OutputPort));
884 }
885
886 NATIVE_INT_TYPE BufferLoggerComponentBase ::
887 getNum_cmdResponseOut_OutputPorts() const
888 {
889 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_cmdResponseOut_OutputPort));
890 }
891
892 NATIVE_INT_TYPE BufferLoggerComponentBase ::
893 getNum_eventOut_OutputPorts() const
894 {
895 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_eventOut_OutputPort));
896 }
897
898#if FW_ENABLE_TEXT_LOGGING == 1
899
900 NATIVE_INT_TYPE BufferLoggerComponentBase ::
901 getNum_eventOutText_OutputPorts() const
902 {
903 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_eventOutText_OutputPort));
904 }
905
906#endif
907
908 NATIVE_INT_TYPE BufferLoggerComponentBase ::
909 getNum_timeCaller_OutputPorts() const
910 {
911 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_timeCaller_OutputPort));
912 }
913
914 NATIVE_INT_TYPE BufferLoggerComponentBase ::
915 getNum_tlmOut_OutputPorts() const
916 {
917 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_tlmOut_OutputPort));
918 }
919
920 // ----------------------------------------------------------------------
921 // Getters for numbers of typed output ports
922 // ----------------------------------------------------------------------
923
924 NATIVE_INT_TYPE BufferLoggerComponentBase ::
925 getNum_bufferSendOut_OutputPorts() const
926 {
927 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_bufferSendOut_OutputPort));
928 }
929
930 NATIVE_INT_TYPE BufferLoggerComponentBase ::
931 getNum_pingOut_OutputPorts() const
932 {
933 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_pingOut_OutputPort));
934 }
935
936 // ----------------------------------------------------------------------
937 // Connection status queries for special output ports
938 // ----------------------------------------------------------------------
939
940 bool BufferLoggerComponentBase ::
941 isConnected_cmdRegOut_OutputPort(NATIVE_INT_TYPE portNum)
942 {
943 FW_ASSERT(
944 portNum < this->getNum_cmdRegOut_OutputPorts(),
945 static_cast<FwAssertArgType>(portNum)
946 );
947
948 return this->m_cmdRegOut_OutputPort[portNum].isConnected();
949 }
950
951 bool BufferLoggerComponentBase ::
952 isConnected_cmdResponseOut_OutputPort(NATIVE_INT_TYPE portNum)
953 {
954 FW_ASSERT(
955 portNum < this->getNum_cmdResponseOut_OutputPorts(),
956 static_cast<FwAssertArgType>(portNum)
957 );
958
959 return this->m_cmdResponseOut_OutputPort[portNum].isConnected();
960 }
961
962 bool BufferLoggerComponentBase ::
963 isConnected_eventOut_OutputPort(NATIVE_INT_TYPE portNum)
964 {
965 FW_ASSERT(
966 portNum < this->getNum_eventOut_OutputPorts(),
967 static_cast<FwAssertArgType>(portNum)
968 );
969
970 return this->m_eventOut_OutputPort[portNum].isConnected();
971 }
972
973#if FW_ENABLE_TEXT_LOGGING == 1
974
975 bool BufferLoggerComponentBase ::
976 isConnected_eventOutText_OutputPort(NATIVE_INT_TYPE portNum)
977 {
978 FW_ASSERT(
979 portNum < this->getNum_eventOutText_OutputPorts(),
980 static_cast<FwAssertArgType>(portNum)
981 );
982
983 return this->m_eventOutText_OutputPort[portNum].isConnected();
984 }
985
986#endif
987
988 bool BufferLoggerComponentBase ::
989 isConnected_timeCaller_OutputPort(NATIVE_INT_TYPE portNum)
990 {
991 FW_ASSERT(
992 portNum < this->getNum_timeCaller_OutputPorts(),
993 static_cast<FwAssertArgType>(portNum)
994 );
995
996 return this->m_timeCaller_OutputPort[portNum].isConnected();
997 }
998
999 bool BufferLoggerComponentBase ::
1000 isConnected_tlmOut_OutputPort(NATIVE_INT_TYPE portNum)
1001 {
1002 FW_ASSERT(
1003 portNum < this->getNum_tlmOut_OutputPorts(),
1004 static_cast<FwAssertArgType>(portNum)
1005 );
1006
1007 return this->m_tlmOut_OutputPort[portNum].isConnected();
1008 }
1009
1010 // ----------------------------------------------------------------------
1011 // Connection status queries for typed output ports
1012 // ----------------------------------------------------------------------
1013
1014 bool BufferLoggerComponentBase ::
1015 isConnected_bufferSendOut_OutputPort(NATIVE_INT_TYPE portNum)
1016 {
1017 FW_ASSERT(
1018 portNum < this->getNum_bufferSendOut_OutputPorts(),
1019 static_cast<FwAssertArgType>(portNum)
1020 );
1021
1022 return this->m_bufferSendOut_OutputPort[portNum].isConnected();
1023 }
1024
1025 bool BufferLoggerComponentBase ::
1026 isConnected_pingOut_OutputPort(NATIVE_INT_TYPE portNum)
1027 {
1028 FW_ASSERT(
1029 portNum < this->getNum_pingOut_OutputPorts(),
1030 static_cast<FwAssertArgType>(portNum)
1031 );
1032
1033 return this->m_pingOut_OutputPort[portNum].isConnected();
1034 }
1035
1036 // ----------------------------------------------------------------------
1037 // Port handler base-class functions for typed input ports
1038 //
1039 // Call these functions directly to bypass the corresponding ports
1040 // ----------------------------------------------------------------------
1041
1042 void BufferLoggerComponentBase ::
1043 bufferSendIn_handlerBase(
1044 NATIVE_INT_TYPE portNum,
1045 Fw::Buffer& fwBuffer
1046 )
1047 {
1048 // Make sure port number is valid
1049 FW_ASSERT(
1050 portNum < this->getNum_bufferSendIn_InputPorts(),
1051 static_cast<FwAssertArgType>(portNum)
1052 );
1053
1054 // Call pre-message hook
1055 bufferSendIn_preMsgHook(
1056 portNum,
1057 fwBuffer
1058 );
1059 ComponentIpcSerializableBuffer msg;
1061
1062 // Serialize message ID
1063 _status = msg.serialize(
1064 static_cast<NATIVE_INT_TYPE>(BUFFERSENDIN_BUFFERSEND)
1065 );
1066 FW_ASSERT(
1067 _status == Fw::FW_SERIALIZE_OK,
1068 static_cast<FwAssertArgType>(_status)
1069 );
1070
1071 // Serialize port number
1072 _status = msg.serialize(portNum);
1073 FW_ASSERT(
1074 _status == Fw::FW_SERIALIZE_OK,
1075 static_cast<FwAssertArgType>(_status)
1076 );
1077
1078 // Serialize argument fwBuffer
1079 _status = msg.serialize(fwBuffer);
1080 FW_ASSERT(
1081 _status == Fw::FW_SERIALIZE_OK,
1082 static_cast<FwAssertArgType>(_status)
1083 );
1084
1085 // Send message
1087 Os::Queue::QueueStatus qStatus = this->m_queue.send(msg, 0, _block);
1088
1089 FW_ASSERT(
1090 qStatus == Os::Queue::QUEUE_OK,
1091 static_cast<FwAssertArgType>(qStatus)
1092 );
1093 }
1094
1095 void BufferLoggerComponentBase ::
1096 comIn_handlerBase(
1097 NATIVE_INT_TYPE portNum,
1098 Fw::ComBuffer& data,
1099 U32 context
1100 )
1101 {
1102 // Make sure port number is valid
1103 FW_ASSERT(
1104 portNum < this->getNum_comIn_InputPorts(),
1105 static_cast<FwAssertArgType>(portNum)
1106 );
1107
1108 // Call pre-message hook
1109 comIn_preMsgHook(
1110 portNum,
1111 data,
1112 context
1113 );
1114 ComponentIpcSerializableBuffer msg;
1116
1117 // Serialize message ID
1118 _status = msg.serialize(
1119 static_cast<NATIVE_INT_TYPE>(COMIN_COM)
1120 );
1121 FW_ASSERT(
1122 _status == Fw::FW_SERIALIZE_OK,
1123 static_cast<FwAssertArgType>(_status)
1124 );
1125
1126 // Serialize port number
1127 _status = msg.serialize(portNum);
1128 FW_ASSERT(
1129 _status == Fw::FW_SERIALIZE_OK,
1130 static_cast<FwAssertArgType>(_status)
1131 );
1132
1133 // Serialize argument data
1134 _status = msg.serialize(data);
1135 FW_ASSERT(
1136 _status == Fw::FW_SERIALIZE_OK,
1137 static_cast<FwAssertArgType>(_status)
1138 );
1139
1140 // Serialize argument context
1141 _status = msg.serialize(context);
1142 FW_ASSERT(
1143 _status == Fw::FW_SERIALIZE_OK,
1144 static_cast<FwAssertArgType>(_status)
1145 );
1146
1147 // Send message
1149 Os::Queue::QueueStatus qStatus = this->m_queue.send(msg, 0, _block);
1150
1151 FW_ASSERT(
1152 qStatus == Os::Queue::QUEUE_OK,
1153 static_cast<FwAssertArgType>(qStatus)
1154 );
1155 }
1156
1157 void BufferLoggerComponentBase ::
1158 pingIn_handlerBase(
1159 NATIVE_INT_TYPE portNum,
1160 U32 key
1161 )
1162 {
1163 // Make sure port number is valid
1164 FW_ASSERT(
1165 portNum < this->getNum_pingIn_InputPorts(),
1166 static_cast<FwAssertArgType>(portNum)
1167 );
1168
1169 // Call pre-message hook
1170 pingIn_preMsgHook(
1171 portNum,
1172 key
1173 );
1174 ComponentIpcSerializableBuffer msg;
1176
1177 // Serialize message ID
1178 _status = msg.serialize(
1179 static_cast<NATIVE_INT_TYPE>(PINGIN_PING)
1180 );
1181 FW_ASSERT(
1182 _status == Fw::FW_SERIALIZE_OK,
1183 static_cast<FwAssertArgType>(_status)
1184 );
1185
1186 // Serialize port number
1187 _status = msg.serialize(portNum);
1188 FW_ASSERT(
1189 _status == Fw::FW_SERIALIZE_OK,
1190 static_cast<FwAssertArgType>(_status)
1191 );
1192
1193 // Serialize argument key
1194 _status = msg.serialize(key);
1195 FW_ASSERT(
1196 _status == Fw::FW_SERIALIZE_OK,
1197 static_cast<FwAssertArgType>(_status)
1198 );
1199
1200 // Send message
1202 Os::Queue::QueueStatus qStatus = this->m_queue.send(msg, 0, _block);
1203
1204 FW_ASSERT(
1205 qStatus == Os::Queue::QUEUE_OK,
1206 static_cast<FwAssertArgType>(qStatus)
1207 );
1208 }
1209
1210 void BufferLoggerComponentBase ::
1211 schedIn_handlerBase(
1212 NATIVE_INT_TYPE portNum,
1213 NATIVE_UINT_TYPE context
1214 )
1215 {
1216 // Make sure port number is valid
1217 FW_ASSERT(
1218 portNum < this->getNum_schedIn_InputPorts(),
1219 static_cast<FwAssertArgType>(portNum)
1220 );
1221
1222 // Call pre-message hook
1223 schedIn_preMsgHook(
1224 portNum,
1225 context
1226 );
1227 ComponentIpcSerializableBuffer msg;
1229
1230 // Serialize message ID
1231 _status = msg.serialize(
1232 static_cast<NATIVE_INT_TYPE>(SCHEDIN_SCHED)
1233 );
1234 FW_ASSERT(
1235 _status == Fw::FW_SERIALIZE_OK,
1236 static_cast<FwAssertArgType>(_status)
1237 );
1238
1239 // Serialize port number
1240 _status = msg.serialize(portNum);
1241 FW_ASSERT(
1242 _status == Fw::FW_SERIALIZE_OK,
1243 static_cast<FwAssertArgType>(_status)
1244 );
1245
1246 // Serialize argument context
1247 _status = msg.serialize(context);
1248 FW_ASSERT(
1249 _status == Fw::FW_SERIALIZE_OK,
1250 static_cast<FwAssertArgType>(_status)
1251 );
1252
1253 // Send message
1255 Os::Queue::QueueStatus qStatus = this->m_queue.send(msg, 0, _block);
1256
1257 FW_ASSERT(
1258 qStatus == Os::Queue::QUEUE_OK,
1259 static_cast<FwAssertArgType>(qStatus)
1260 );
1261 }
1262
1263 // ----------------------------------------------------------------------
1264 // Pre-message hooks for typed async input ports
1265 //
1266 // Each of these functions is invoked just before processing a message
1267 // on the corresponding port. By default, they do nothing. You can
1268 // override them to provide specific pre-message behavior.
1269 // ----------------------------------------------------------------------
1270
1271 void BufferLoggerComponentBase ::
1272 bufferSendIn_preMsgHook(
1273 NATIVE_INT_TYPE portNum,
1274 Fw::Buffer& fwBuffer
1275 )
1276 {
1277 // Default: no-op
1278 }
1279
1280 void BufferLoggerComponentBase ::
1281 comIn_preMsgHook(
1282 NATIVE_INT_TYPE portNum,
1283 Fw::ComBuffer& data,
1284 U32 context
1285 )
1286 {
1287 // Default: no-op
1288 }
1289
1290 void BufferLoggerComponentBase ::
1291 pingIn_preMsgHook(
1292 NATIVE_INT_TYPE portNum,
1293 U32 key
1294 )
1295 {
1296 // Default: no-op
1297 }
1298
1299 void BufferLoggerComponentBase ::
1300 schedIn_preMsgHook(
1301 NATIVE_INT_TYPE portNum,
1302 NATIVE_UINT_TYPE context
1303 )
1304 {
1305 // Default: no-op
1306 }
1307
1308 // ----------------------------------------------------------------------
1309 // Invocation functions for typed output ports
1310 // ----------------------------------------------------------------------
1311
1312 void BufferLoggerComponentBase ::
1313 bufferSendOut_out(
1314 NATIVE_INT_TYPE portNum,
1315 Fw::Buffer& fwBuffer
1316 )
1317 {
1318 FW_ASSERT(
1319 portNum < this->getNum_bufferSendOut_OutputPorts(),
1320 static_cast<FwAssertArgType>(portNum)
1321 );
1322 this->m_bufferSendOut_OutputPort[portNum].invoke(
1323 fwBuffer
1324 );
1325 }
1326
1327 void BufferLoggerComponentBase ::
1328 pingOut_out(
1329 NATIVE_INT_TYPE portNum,
1330 U32 key
1331 )
1332 {
1333 FW_ASSERT(
1334 portNum < this->getNum_pingOut_OutputPorts(),
1335 static_cast<FwAssertArgType>(portNum)
1336 );
1337 this->m_pingOut_OutputPort[portNum].invoke(
1338 key
1339 );
1340 }
1341
1342 // ----------------------------------------------------------------------
1343 // Command response
1344 // ----------------------------------------------------------------------
1345
1346 void BufferLoggerComponentBase ::
1347 cmdResponse_out(
1348 FwOpcodeType opCode,
1349 U32 cmdSeq,
1350 Fw::CmdResponse response
1351 )
1352 {
1353 FW_ASSERT(this->m_cmdResponseOut_OutputPort[0].isConnected());
1354 this->m_cmdResponseOut_OutputPort[0].invoke(opCode, cmdSeq, response);
1355 }
1356
1357 // ----------------------------------------------------------------------
1358 // Command handler base-class functions
1359 //
1360 // Call these functions directly to bypass the command input port
1361 // ----------------------------------------------------------------------
1362
1363 void BufferLoggerComponentBase ::
1364 BL_OpenFile_cmdHandlerBase(
1365 FwOpcodeType opCode,
1366 U32 cmdSeq,
1367 Fw::CmdArgBuffer& args
1368 )
1369 {
1370 // Call pre-message hook
1371 this->BL_OpenFile_preMsgHook(opCode,cmdSeq);
1372
1373 // Defer deserializing arguments to the message dispatcher
1374 // to avoid deserializing and reserializing just for IPC
1375 ComponentIpcSerializableBuffer msg;
1377
1378 // Serialize for IPC
1379 _status = msg.serialize(static_cast<NATIVE_INT_TYPE>(CMD_BL_OPENFILE));
1380 FW_ASSERT (
1381 _status == Fw::FW_SERIALIZE_OK,
1382 static_cast<FwAssertArgType>(_status)
1383 );
1384
1385 // Fake port number to make message dequeue work
1386 NATIVE_INT_TYPE port = 0;
1387
1388 _status = msg.serialize(port);
1389 FW_ASSERT (
1390 _status == Fw::FW_SERIALIZE_OK,
1391 static_cast<FwAssertArgType>(_status)
1392 );
1393
1394 _status = msg.serialize(opCode);
1395 FW_ASSERT (
1396 _status == Fw::FW_SERIALIZE_OK,
1397 static_cast<FwAssertArgType>(_status)
1398 );
1399
1400 _status = msg.serialize(cmdSeq);
1401 FW_ASSERT (
1402 _status == Fw::FW_SERIALIZE_OK,
1403 static_cast<FwAssertArgType>(_status)
1404 );
1405
1406 _status = msg.serialize(args);
1407 FW_ASSERT (
1408 _status == Fw::FW_SERIALIZE_OK,
1409 static_cast<FwAssertArgType>(_status)
1410 );
1411
1412 // Send message
1414 Os::Queue::QueueStatus qStatus = this->m_queue.send(msg, 0, _block);
1415
1416 FW_ASSERT(
1417 qStatus == Os::Queue::QUEUE_OK,
1418 static_cast<FwAssertArgType>(qStatus)
1419 );
1420 }
1421
1422 void BufferLoggerComponentBase ::
1423 BL_CloseFile_cmdHandlerBase(
1424 FwOpcodeType opCode,
1425 U32 cmdSeq,
1426 Fw::CmdArgBuffer& args
1427 )
1428 {
1429 // Call pre-message hook
1430 this->BL_CloseFile_preMsgHook(opCode,cmdSeq);
1431
1432 // Defer deserializing arguments to the message dispatcher
1433 // to avoid deserializing and reserializing just for IPC
1434 ComponentIpcSerializableBuffer msg;
1436
1437 // Serialize for IPC
1438 _status = msg.serialize(static_cast<NATIVE_INT_TYPE>(CMD_BL_CLOSEFILE));
1439 FW_ASSERT (
1440 _status == Fw::FW_SERIALIZE_OK,
1441 static_cast<FwAssertArgType>(_status)
1442 );
1443
1444 // Fake port number to make message dequeue work
1445 NATIVE_INT_TYPE port = 0;
1446
1447 _status = msg.serialize(port);
1448 FW_ASSERT (
1449 _status == Fw::FW_SERIALIZE_OK,
1450 static_cast<FwAssertArgType>(_status)
1451 );
1452
1453 _status = msg.serialize(opCode);
1454 FW_ASSERT (
1455 _status == Fw::FW_SERIALIZE_OK,
1456 static_cast<FwAssertArgType>(_status)
1457 );
1458
1459 _status = msg.serialize(cmdSeq);
1460 FW_ASSERT (
1461 _status == Fw::FW_SERIALIZE_OK,
1462 static_cast<FwAssertArgType>(_status)
1463 );
1464
1465 _status = msg.serialize(args);
1466 FW_ASSERT (
1467 _status == Fw::FW_SERIALIZE_OK,
1468 static_cast<FwAssertArgType>(_status)
1469 );
1470
1471 // Send message
1473 Os::Queue::QueueStatus qStatus = this->m_queue.send(msg, 0, _block);
1474
1475 FW_ASSERT(
1476 qStatus == Os::Queue::QUEUE_OK,
1477 static_cast<FwAssertArgType>(qStatus)
1478 );
1479 }
1480
1481 void BufferLoggerComponentBase ::
1482 BL_SetLogging_cmdHandlerBase(
1483 FwOpcodeType opCode,
1484 U32 cmdSeq,
1485 Fw::CmdArgBuffer& args
1486 )
1487 {
1488 // Call pre-message hook
1489 this->BL_SetLogging_preMsgHook(opCode,cmdSeq);
1490
1491 // Defer deserializing arguments to the message dispatcher
1492 // to avoid deserializing and reserializing just for IPC
1493 ComponentIpcSerializableBuffer msg;
1495
1496 // Serialize for IPC
1497 _status = msg.serialize(static_cast<NATIVE_INT_TYPE>(CMD_BL_SETLOGGING));
1498 FW_ASSERT (
1499 _status == Fw::FW_SERIALIZE_OK,
1500 static_cast<FwAssertArgType>(_status)
1501 );
1502
1503 // Fake port number to make message dequeue work
1504 NATIVE_INT_TYPE port = 0;
1505
1506 _status = msg.serialize(port);
1507 FW_ASSERT (
1508 _status == Fw::FW_SERIALIZE_OK,
1509 static_cast<FwAssertArgType>(_status)
1510 );
1511
1512 _status = msg.serialize(opCode);
1513 FW_ASSERT (
1514 _status == Fw::FW_SERIALIZE_OK,
1515 static_cast<FwAssertArgType>(_status)
1516 );
1517
1518 _status = msg.serialize(cmdSeq);
1519 FW_ASSERT (
1520 _status == Fw::FW_SERIALIZE_OK,
1521 static_cast<FwAssertArgType>(_status)
1522 );
1523
1524 _status = msg.serialize(args);
1525 FW_ASSERT (
1526 _status == Fw::FW_SERIALIZE_OK,
1527 static_cast<FwAssertArgType>(_status)
1528 );
1529
1530 // Send message
1532 Os::Queue::QueueStatus qStatus = this->m_queue.send(msg, 0, _block);
1533
1534 FW_ASSERT(
1535 qStatus == Os::Queue::QUEUE_OK,
1536 static_cast<FwAssertArgType>(qStatus)
1537 );
1538 }
1539
1540 void BufferLoggerComponentBase ::
1541 BL_FlushFile_cmdHandlerBase(
1542 FwOpcodeType opCode,
1543 U32 cmdSeq,
1544 Fw::CmdArgBuffer& args
1545 )
1546 {
1547 // Call pre-message hook
1548 this->BL_FlushFile_preMsgHook(opCode,cmdSeq);
1549
1550 // Defer deserializing arguments to the message dispatcher
1551 // to avoid deserializing and reserializing just for IPC
1552 ComponentIpcSerializableBuffer msg;
1554
1555 // Serialize for IPC
1556 _status = msg.serialize(static_cast<NATIVE_INT_TYPE>(CMD_BL_FLUSHFILE));
1557 FW_ASSERT (
1558 _status == Fw::FW_SERIALIZE_OK,
1559 static_cast<FwAssertArgType>(_status)
1560 );
1561
1562 // Fake port number to make message dequeue work
1563 NATIVE_INT_TYPE port = 0;
1564
1565 _status = msg.serialize(port);
1566 FW_ASSERT (
1567 _status == Fw::FW_SERIALIZE_OK,
1568 static_cast<FwAssertArgType>(_status)
1569 );
1570
1571 _status = msg.serialize(opCode);
1572 FW_ASSERT (
1573 _status == Fw::FW_SERIALIZE_OK,
1574 static_cast<FwAssertArgType>(_status)
1575 );
1576
1577 _status = msg.serialize(cmdSeq);
1578 FW_ASSERT (
1579 _status == Fw::FW_SERIALIZE_OK,
1580 static_cast<FwAssertArgType>(_status)
1581 );
1582
1583 _status = msg.serialize(args);
1584 FW_ASSERT (
1585 _status == Fw::FW_SERIALIZE_OK,
1586 static_cast<FwAssertArgType>(_status)
1587 );
1588
1589 // Send message
1591 Os::Queue::QueueStatus qStatus = this->m_queue.send(msg, 0, _block);
1592
1593 FW_ASSERT(
1594 qStatus == Os::Queue::QUEUE_OK,
1595 static_cast<FwAssertArgType>(qStatus)
1596 );
1597 }
1598
1599 // ----------------------------------------------------------------------
1600 // Pre-message hooks for async commands
1601 //
1602 // Each of these functions is invoked just before processing the
1603 // corresponding command. By default they do nothing. You can
1604 // override them to provide specific pre-command behavior.
1605 // ----------------------------------------------------------------------
1606
1607 void BufferLoggerComponentBase ::
1608 BL_OpenFile_preMsgHook(
1609 FwOpcodeType opCode,
1610 U32 cmdSeq
1611 )
1612 {
1613 // Defaults to no-op; can be overridden
1614 (void) opCode;
1615 (void) cmdSeq;
1616 }
1617
1618 void BufferLoggerComponentBase ::
1619 BL_CloseFile_preMsgHook(
1620 FwOpcodeType opCode,
1621 U32 cmdSeq
1622 )
1623 {
1624 // Defaults to no-op; can be overridden
1625 (void) opCode;
1626 (void) cmdSeq;
1627 }
1628
1629 void BufferLoggerComponentBase ::
1630 BL_SetLogging_preMsgHook(
1631 FwOpcodeType opCode,
1632 U32 cmdSeq
1633 )
1634 {
1635 // Defaults to no-op; can be overridden
1636 (void) opCode;
1637 (void) cmdSeq;
1638 }
1639
1640 void BufferLoggerComponentBase ::
1641 BL_FlushFile_preMsgHook(
1642 FwOpcodeType opCode,
1643 U32 cmdSeq
1644 )
1645 {
1646 // Defaults to no-op; can be overridden
1647 (void) opCode;
1648 (void) cmdSeq;
1649 }
1650
1651 // ----------------------------------------------------------------------
1652 // Event logging functions
1653 // ----------------------------------------------------------------------
1654
1655 void BufferLoggerComponentBase ::
1656 log_DIAGNOSTIC_BL_LogFileClosed(const Fw::LogStringArg& file)
1657 {
1658 // Get the time
1659 Fw::Time _logTime;
1660 if (this->m_timeCaller_OutputPort[0].isConnected()) {
1661 this->m_timeCaller_OutputPort[0].invoke(_logTime);
1662 }
1663
1664 FwEventIdType _id = static_cast<FwEventIdType>(0);
1665
1666 _id = this->getIdBase() + EVENTID_BL_LOGFILECLOSED;
1667
1668 // Emit the event on the log port
1669 if (this->m_eventOut_OutputPort[0].isConnected()) {
1670 Fw::LogBuffer _logBuff;
1672
1673#if FW_AMPCS_COMPATIBLE
1674 // Serialize the number of arguments
1675 _status = _logBuff.serialize(static_cast<U8>(1));
1676 FW_ASSERT(
1677 _status == Fw::FW_SERIALIZE_OK,
1678 static_cast<FwAssertArgType>(_status)
1679 );
1680#endif
1681
1682 _status = file.serialize(_logBuff, 256);
1683 FW_ASSERT(
1684 _status == Fw::FW_SERIALIZE_OK,
1685 static_cast<FwAssertArgType>(_status)
1686 );
1687
1688 this->m_eventOut_OutputPort[0].invoke(
1689 _id,
1690 _logTime,
1692 _logBuff
1693 );
1694 }
1695
1696 // Emit the event on the text log port
1697#if FW_ENABLE_TEXT_LOGGING
1698 if (this->m_eventOutText_OutputPort[0].isConnected()) {
1699#if FW_OBJECT_NAMES == 1
1700 const char* _formatString =
1701 "(%s) %s: File %s closed";
1702#else
1703 const char* _formatString =
1704 "%s: File %s closed";
1705#endif
1706
1707 char _textBuffer[FW_LOG_TEXT_BUFFER_SIZE];
1708
1709 (void) snprintf(
1710 _textBuffer,
1712 _formatString,
1713#if FW_OBJECT_NAMES == 1
1714 this->m_objName,
1715#endif
1716 "BL_LogFileClosed ",
1717 file.toChar()
1718 );
1719
1720 // Null terminate
1721 _textBuffer[FW_LOG_TEXT_BUFFER_SIZE-1] = 0;
1722 Fw::TextLogString _logString = _textBuffer;
1723 this->m_eventOutText_OutputPort[0].invoke(
1724 _id,
1725 _logTime,
1727 _logString
1728 );
1729 }
1730#endif
1731 }
1732
1733 void BufferLoggerComponentBase ::
1734 log_WARNING_HI_BL_LogFileOpenError(
1735 U32 errornum,
1736 const Fw::LogStringArg& file
1737 )
1738 {
1739 // Get the time
1740 Fw::Time _logTime;
1741 if (this->m_timeCaller_OutputPort[0].isConnected()) {
1742 this->m_timeCaller_OutputPort[0].invoke(_logTime);
1743 }
1744
1745 FwEventIdType _id = static_cast<FwEventIdType>(0);
1746
1747 _id = this->getIdBase() + EVENTID_BL_LOGFILEOPENERROR;
1748
1749 // Emit the event on the log port
1750 if (this->m_eventOut_OutputPort[0].isConnected()) {
1751 Fw::LogBuffer _logBuff;
1753
1754#if FW_AMPCS_COMPATIBLE
1755 // Serialize the number of arguments
1756 _status = _logBuff.serialize(static_cast<U8>(2));
1757 FW_ASSERT(
1758 _status == Fw::FW_SERIALIZE_OK,
1759 static_cast<FwAssertArgType>(_status)
1760 );
1761#endif
1762
1763#if FW_AMPCS_COMPATIBLE
1764 // Serialize the argument size
1765 _status = _logBuff.serialize(
1766 static_cast<U8>(sizeof(U32))
1767 );
1768 FW_ASSERT(
1769 _status == Fw::FW_SERIALIZE_OK,
1770 static_cast<FwAssertArgType>(_status)
1771 );
1772#endif
1773 _status = _logBuff.serialize(errornum);
1774 FW_ASSERT(
1775 _status == Fw::FW_SERIALIZE_OK,
1776 static_cast<FwAssertArgType>(_status)
1777 );
1778
1779 _status = file.serialize(_logBuff, 256);
1780 FW_ASSERT(
1781 _status == Fw::FW_SERIALIZE_OK,
1782 static_cast<FwAssertArgType>(_status)
1783 );
1784
1785 this->m_eventOut_OutputPort[0].invoke(
1786 _id,
1787 _logTime,
1789 _logBuff
1790 );
1791 }
1792
1793 // Emit the event on the text log port
1794#if FW_ENABLE_TEXT_LOGGING
1795 if (this->m_eventOutText_OutputPort[0].isConnected()) {
1796#if FW_OBJECT_NAMES == 1
1797 const char* _formatString =
1798 "(%s) %s: Error %" PRIu32 " opening file %s";
1799#else
1800 const char* _formatString =
1801 "%s: Error %" PRIu32 " opening file %s";
1802#endif
1803
1804 char _textBuffer[FW_LOG_TEXT_BUFFER_SIZE];
1805
1806 (void) snprintf(
1807 _textBuffer,
1809 _formatString,
1810#if FW_OBJECT_NAMES == 1
1811 this->m_objName,
1812#endif
1813 "BL_LogFileOpenError ",
1814 errornum,
1815 file.toChar()
1816 );
1817
1818 // Null terminate
1819 _textBuffer[FW_LOG_TEXT_BUFFER_SIZE-1] = 0;
1820 Fw::TextLogString _logString = _textBuffer;
1821 this->m_eventOutText_OutputPort[0].invoke(
1822 _id,
1823 _logTime,
1825 _logString
1826 );
1827 }
1828#endif
1829 }
1830
1831 void BufferLoggerComponentBase ::
1832 log_WARNING_HI_BL_LogFileValidationError(
1833 const Fw::LogStringArg& validationFile,
1834 U32 status
1835 )
1836 {
1837 // Get the time
1838 Fw::Time _logTime;
1839 if (this->m_timeCaller_OutputPort[0].isConnected()) {
1840 this->m_timeCaller_OutputPort[0].invoke(_logTime);
1841 }
1842
1843 FwEventIdType _id = static_cast<FwEventIdType>(0);
1844
1845 _id = this->getIdBase() + EVENTID_BL_LOGFILEVALIDATIONERROR;
1846
1847 // Emit the event on the log port
1848 if (this->m_eventOut_OutputPort[0].isConnected()) {
1849 Fw::LogBuffer _logBuff;
1851
1852#if FW_AMPCS_COMPATIBLE
1853 // Serialize the number of arguments
1854 _status = _logBuff.serialize(static_cast<U8>(2));
1855 FW_ASSERT(
1856 _status == Fw::FW_SERIALIZE_OK,
1857 static_cast<FwAssertArgType>(_status)
1858 );
1859#endif
1860
1861 _status = validationFile.serialize(_logBuff, 256);
1862 FW_ASSERT(
1863 _status == Fw::FW_SERIALIZE_OK,
1864 static_cast<FwAssertArgType>(_status)
1865 );
1866
1867#if FW_AMPCS_COMPATIBLE
1868 // Serialize the argument size
1869 _status = _logBuff.serialize(
1870 static_cast<U8>(sizeof(U32))
1871 );
1872 FW_ASSERT(
1873 _status == Fw::FW_SERIALIZE_OK,
1874 static_cast<FwAssertArgType>(_status)
1875 );
1876#endif
1877 _status = _logBuff.serialize(status);
1878 FW_ASSERT(
1879 _status == Fw::FW_SERIALIZE_OK,
1880 static_cast<FwAssertArgType>(_status)
1881 );
1882
1883 this->m_eventOut_OutputPort[0].invoke(
1884 _id,
1885 _logTime,
1887 _logBuff
1888 );
1889 }
1890
1891 // Emit the event on the text log port
1892#if FW_ENABLE_TEXT_LOGGING
1893 if (this->m_eventOutText_OutputPort[0].isConnected()) {
1894#if FW_OBJECT_NAMES == 1
1895 const char* _formatString =
1896 "(%s) %s: Failed creating validation file %s with status %" PRIu32 "";
1897#else
1898 const char* _formatString =
1899 "%s: Failed creating validation file %s with status %" PRIu32 "";
1900#endif
1901
1902 char _textBuffer[FW_LOG_TEXT_BUFFER_SIZE];
1903
1904 (void) snprintf(
1905 _textBuffer,
1907 _formatString,
1908#if FW_OBJECT_NAMES == 1
1909 this->m_objName,
1910#endif
1911 "BL_LogFileValidationError ",
1912 validationFile.toChar(),
1913 status
1914 );
1915
1916 // Null terminate
1917 _textBuffer[FW_LOG_TEXT_BUFFER_SIZE-1] = 0;
1918 Fw::TextLogString _logString = _textBuffer;
1919 this->m_eventOutText_OutputPort[0].invoke(
1920 _id,
1921 _logTime,
1923 _logString
1924 );
1925 }
1926#endif
1927 }
1928
1929 void BufferLoggerComponentBase ::
1930 log_WARNING_HI_BL_LogFileWriteError(
1931 U32 errornum,
1932 U32 bytesWritten,
1933 U32 bytesToWrite,
1934 const Fw::LogStringArg& file
1935 )
1936 {
1937 // Get the time
1938 Fw::Time _logTime;
1939 if (this->m_timeCaller_OutputPort[0].isConnected()) {
1940 this->m_timeCaller_OutputPort[0].invoke(_logTime);
1941 }
1942
1943 FwEventIdType _id = static_cast<FwEventIdType>(0);
1944
1945 _id = this->getIdBase() + EVENTID_BL_LOGFILEWRITEERROR;
1946
1947 // Emit the event on the log port
1948 if (this->m_eventOut_OutputPort[0].isConnected()) {
1949 Fw::LogBuffer _logBuff;
1951
1952#if FW_AMPCS_COMPATIBLE
1953 // Serialize the number of arguments
1954 _status = _logBuff.serialize(static_cast<U8>(4));
1955 FW_ASSERT(
1956 _status == Fw::FW_SERIALIZE_OK,
1957 static_cast<FwAssertArgType>(_status)
1958 );
1959#endif
1960
1961#if FW_AMPCS_COMPATIBLE
1962 // Serialize the argument size
1963 _status = _logBuff.serialize(
1964 static_cast<U8>(sizeof(U32))
1965 );
1966 FW_ASSERT(
1967 _status == Fw::FW_SERIALIZE_OK,
1968 static_cast<FwAssertArgType>(_status)
1969 );
1970#endif
1971 _status = _logBuff.serialize(errornum);
1972 FW_ASSERT(
1973 _status == Fw::FW_SERIALIZE_OK,
1974 static_cast<FwAssertArgType>(_status)
1975 );
1976
1977#if FW_AMPCS_COMPATIBLE
1978 // Serialize the argument size
1979 _status = _logBuff.serialize(
1980 static_cast<U8>(sizeof(U32))
1981 );
1982 FW_ASSERT(
1983 _status == Fw::FW_SERIALIZE_OK,
1984 static_cast<FwAssertArgType>(_status)
1985 );
1986#endif
1987 _status = _logBuff.serialize(bytesWritten);
1988 FW_ASSERT(
1989 _status == Fw::FW_SERIALIZE_OK,
1990 static_cast<FwAssertArgType>(_status)
1991 );
1992
1993#if FW_AMPCS_COMPATIBLE
1994 // Serialize the argument size
1995 _status = _logBuff.serialize(
1996 static_cast<U8>(sizeof(U32))
1997 );
1998 FW_ASSERT(
1999 _status == Fw::FW_SERIALIZE_OK,
2000 static_cast<FwAssertArgType>(_status)
2001 );
2002#endif
2003 _status = _logBuff.serialize(bytesToWrite);
2004 FW_ASSERT(
2005 _status == Fw::FW_SERIALIZE_OK,
2006 static_cast<FwAssertArgType>(_status)
2007 );
2008
2009 _status = file.serialize(_logBuff, 256);
2010 FW_ASSERT(
2011 _status == Fw::FW_SERIALIZE_OK,
2012 static_cast<FwAssertArgType>(_status)
2013 );
2014
2015 this->m_eventOut_OutputPort[0].invoke(
2016 _id,
2017 _logTime,
2019 _logBuff
2020 );
2021 }
2022
2023 // Emit the event on the text log port
2024#if FW_ENABLE_TEXT_LOGGING
2025 if (this->m_eventOutText_OutputPort[0].isConnected()) {
2026#if FW_OBJECT_NAMES == 1
2027 const char* _formatString =
2028 "(%s) %s: Error %" PRIu32 " while writing %" PRIu32 " of %" PRIu32 " bytes to %s";
2029#else
2030 const char* _formatString =
2031 "%s: Error %" PRIu32 " while writing %" PRIu32 " of %" PRIu32 " bytes to %s";
2032#endif
2033
2034 char _textBuffer[FW_LOG_TEXT_BUFFER_SIZE];
2035
2036 (void) snprintf(
2037 _textBuffer,
2039 _formatString,
2040#if FW_OBJECT_NAMES == 1
2041 this->m_objName,
2042#endif
2043 "BL_LogFileWriteError ",
2044 errornum,
2045 bytesWritten,
2046 bytesToWrite,
2047 file.toChar()
2048 );
2049
2050 // Null terminate
2051 _textBuffer[FW_LOG_TEXT_BUFFER_SIZE-1] = 0;
2052 Fw::TextLogString _logString = _textBuffer;
2053 this->m_eventOutText_OutputPort[0].invoke(
2054 _id,
2055 _logTime,
2057 _logString
2058 );
2059 }
2060#endif
2061 }
2062
2063 void BufferLoggerComponentBase ::
2064 log_ACTIVITY_LO_BL_Activated()
2065 {
2066 // Get the time
2067 Fw::Time _logTime;
2068 if (this->m_timeCaller_OutputPort[0].isConnected()) {
2069 this->m_timeCaller_OutputPort[0].invoke(_logTime);
2070 }
2071
2072 FwEventIdType _id = static_cast<FwEventIdType>(0);
2073
2074 _id = this->getIdBase() + EVENTID_BL_ACTIVATED;
2075
2076 // Emit the event on the log port
2077 if (this->m_eventOut_OutputPort[0].isConnected()) {
2078 Fw::LogBuffer _logBuff;
2079
2080#if FW_AMPCS_COMPATIBLE
2082 // Serialize the number of arguments
2083 _status = _logBuff.serialize(static_cast<U8>(0));
2084 FW_ASSERT(
2085 _status == Fw::FW_SERIALIZE_OK,
2086 static_cast<FwAssertArgType>(_status)
2087 );
2088#endif
2089
2090 this->m_eventOut_OutputPort[0].invoke(
2091 _id,
2092 _logTime,
2094 _logBuff
2095 );
2096 }
2097
2098 // Emit the event on the text log port
2099#if FW_ENABLE_TEXT_LOGGING
2100 if (this->m_eventOutText_OutputPort[0].isConnected()) {
2101#if FW_OBJECT_NAMES == 1
2102 const char* _formatString =
2103 "(%s) %s: Buffer logger was activated";
2104#else
2105 const char* _formatString =
2106 "%s: Buffer logger was activated";
2107#endif
2108
2109 char _textBuffer[FW_LOG_TEXT_BUFFER_SIZE];
2110
2111 (void) snprintf(
2112 _textBuffer,
2114 _formatString,
2115#if FW_OBJECT_NAMES == 1
2116 this->m_objName,
2117#endif
2118 "BL_Activated "
2119 );
2120
2121 // Null terminate
2122 _textBuffer[FW_LOG_TEXT_BUFFER_SIZE-1] = 0;
2123 Fw::TextLogString _logString = _textBuffer;
2124 this->m_eventOutText_OutputPort[0].invoke(
2125 _id,
2126 _logTime,
2128 _logString
2129 );
2130 }
2131#endif
2132 }
2133
2134 void BufferLoggerComponentBase ::
2135 log_ACTIVITY_LO_BL_Deactivated()
2136 {
2137 // Get the time
2138 Fw::Time _logTime;
2139 if (this->m_timeCaller_OutputPort[0].isConnected()) {
2140 this->m_timeCaller_OutputPort[0].invoke(_logTime);
2141 }
2142
2143 FwEventIdType _id = static_cast<FwEventIdType>(0);
2144
2145 _id = this->getIdBase() + EVENTID_BL_DEACTIVATED;
2146
2147 // Emit the event on the log port
2148 if (this->m_eventOut_OutputPort[0].isConnected()) {
2149 Fw::LogBuffer _logBuff;
2150
2151#if FW_AMPCS_COMPATIBLE
2153 // Serialize the number of arguments
2154 _status = _logBuff.serialize(static_cast<U8>(0));
2155 FW_ASSERT(
2156 _status == Fw::FW_SERIALIZE_OK,
2157 static_cast<FwAssertArgType>(_status)
2158 );
2159#endif
2160
2161 this->m_eventOut_OutputPort[0].invoke(
2162 _id,
2163 _logTime,
2165 _logBuff
2166 );
2167 }
2168
2169 // Emit the event on the text log port
2170#if FW_ENABLE_TEXT_LOGGING
2171 if (this->m_eventOutText_OutputPort[0].isConnected()) {
2172#if FW_OBJECT_NAMES == 1
2173 const char* _formatString =
2174 "(%s) %s: Buffer logger was deactivated";
2175#else
2176 const char* _formatString =
2177 "%s: Buffer logger was deactivated";
2178#endif
2179
2180 char _textBuffer[FW_LOG_TEXT_BUFFER_SIZE];
2181
2182 (void) snprintf(
2183 _textBuffer,
2185 _formatString,
2186#if FW_OBJECT_NAMES == 1
2187 this->m_objName,
2188#endif
2189 "BL_Deactivated "
2190 );
2191
2192 // Null terminate
2193 _textBuffer[FW_LOG_TEXT_BUFFER_SIZE-1] = 0;
2194 Fw::TextLogString _logString = _textBuffer;
2195 this->m_eventOutText_OutputPort[0].invoke(
2196 _id,
2197 _logTime,
2199 _logString
2200 );
2201 }
2202#endif
2203 }
2204
2205 void BufferLoggerComponentBase ::
2206 log_WARNING_HI_BL_NoLogFileOpenInitError()
2207 {
2208 // Get the time
2209 Fw::Time _logTime;
2210 if (this->m_timeCaller_OutputPort[0].isConnected()) {
2211 this->m_timeCaller_OutputPort[0].invoke(_logTime);
2212 }
2213
2214 FwEventIdType _id = static_cast<FwEventIdType>(0);
2215
2216 _id = this->getIdBase() + EVENTID_BL_NOLOGFILEOPENINITERROR;
2217
2218 // Emit the event on the log port
2219 if (this->m_eventOut_OutputPort[0].isConnected()) {
2220 Fw::LogBuffer _logBuff;
2221
2222#if FW_AMPCS_COMPATIBLE
2224 // Serialize the number of arguments
2225 _status = _logBuff.serialize(static_cast<U8>(0));
2226 FW_ASSERT(
2227 _status == Fw::FW_SERIALIZE_OK,
2228 static_cast<FwAssertArgType>(_status)
2229 );
2230#endif
2231
2232 this->m_eventOut_OutputPort[0].invoke(
2233 _id,
2234 _logTime,
2236 _logBuff
2237 );
2238 }
2239
2240 // Emit the event on the text log port
2241#if FW_ENABLE_TEXT_LOGGING
2242 if (this->m_eventOutText_OutputPort[0].isConnected()) {
2243#if FW_OBJECT_NAMES == 1
2244 const char* _formatString =
2245 "(%s) %s: No log file open command";
2246#else
2247 const char* _formatString =
2248 "%s: No log file open command";
2249#endif
2250
2251 char _textBuffer[FW_LOG_TEXT_BUFFER_SIZE];
2252
2253 (void) snprintf(
2254 _textBuffer,
2256 _formatString,
2257#if FW_OBJECT_NAMES == 1
2258 this->m_objName,
2259#endif
2260 "BL_NoLogFileOpenInitError "
2261 );
2262
2263 // Null terminate
2264 _textBuffer[FW_LOG_TEXT_BUFFER_SIZE-1] = 0;
2265 Fw::TextLogString _logString = _textBuffer;
2266 this->m_eventOutText_OutputPort[0].invoke(
2267 _id,
2268 _logTime,
2270 _logString
2271 );
2272 }
2273#endif
2274 }
2275
2276 // ----------------------------------------------------------------------
2277 // Telemetry write functions
2278 // ----------------------------------------------------------------------
2279
2280 void BufferLoggerComponentBase ::
2281 tlmWrite_BufferLogger_NumLoggedBuffers(
2282 U32 arg,
2283 Fw::Time _tlmTime
2284 )
2285 {
2286 if (this->m_tlmOut_OutputPort[0].isConnected()) {
2287 if (
2288 this->m_timeCaller_OutputPort[0].isConnected() &&
2289 (_tlmTime == Fw::ZERO_TIME)
2290 ) {
2291 this->m_timeCaller_OutputPort[0].invoke(_tlmTime);
2292 }
2293
2294 Fw::TlmBuffer _tlmBuff;
2295 Fw::SerializeStatus _stat = _tlmBuff.serialize(arg);
2296 FW_ASSERT(
2297 _stat == Fw::FW_SERIALIZE_OK,
2298 static_cast<FwAssertArgType>(_stat)
2299 );
2300
2301 FwChanIdType _id;
2302
2303 _id = this->getIdBase() + CHANNELID_BUFFERLOGGER_NUMLOGGEDBUFFERS;
2304
2305 this->m_tlmOut_OutputPort[0].invoke(
2306 _id,
2307 _tlmTime,
2308 _tlmBuff
2309 );
2310 }
2311 }
2312
2313 // ----------------------------------------------------------------------
2314 // Time
2315 // ----------------------------------------------------------------------
2316
2317 Fw::Time BufferLoggerComponentBase ::
2318 getTime()
2319 {
2320 if (this->m_timeCaller_OutputPort[0].isConnected()) {
2321 Fw::Time _time;
2322 this->m_timeCaller_OutputPort[0].invoke(_time);
2323 return _time;
2324 }
2325 else {
2326 return Fw::Time(TB_NONE, 0, 0);
2327 }
2328 }
2329
2330 // ----------------------------------------------------------------------
2331 // Message dispatch functions
2332 // ----------------------------------------------------------------------
2333
2334 Fw::QueuedComponentBase::MsgDispatchStatus BufferLoggerComponentBase ::
2335 doDispatch()
2336 {
2337 ComponentIpcSerializableBuffer msg;
2338 NATIVE_INT_TYPE priority = 0;
2339
2340 Os::Queue::QueueStatus msgStatus = this->m_queue.receive(
2341 msg,
2342 priority,
2344 );
2345 FW_ASSERT(
2346 msgStatus == Os::Queue::QUEUE_OK,
2347 static_cast<FwAssertArgType>(msgStatus)
2348 );
2349
2350 // Reset to beginning of buffer
2351 msg.resetDeser();
2352
2353 NATIVE_INT_TYPE desMsg = 0;
2354 Fw::SerializeStatus deserStatus = msg.deserialize(desMsg);
2355 FW_ASSERT(
2356 deserStatus == Fw::FW_SERIALIZE_OK,
2357 static_cast<FwAssertArgType>(deserStatus)
2358 );
2359
2360 MsgTypeEnum msgType = static_cast<MsgTypeEnum>(desMsg);
2361
2362 if (msgType == BUFFERLOGGER_COMPONENT_EXIT) {
2363 return MSG_DISPATCH_EXIT;
2364 }
2365
2366 NATIVE_INT_TYPE portNum = 0;
2367 deserStatus = msg.deserialize(portNum);
2368 FW_ASSERT(
2369 deserStatus == Fw::FW_SERIALIZE_OK,
2370 static_cast<FwAssertArgType>(deserStatus)
2371 );
2372
2373 switch (msgType) {
2374 // Handle async input port bufferSendIn
2375 case BUFFERSENDIN_BUFFERSEND: {
2376 // Deserialize argument fwBuffer
2377 Fw::Buffer fwBuffer;
2378 deserStatus = msg.deserialize(fwBuffer);
2379 FW_ASSERT(
2380 deserStatus == Fw::FW_SERIALIZE_OK,
2381 static_cast<FwAssertArgType>(deserStatus)
2382 );
2383 // Call handler function
2384 this->bufferSendIn_handler(
2385 portNum,
2386 fwBuffer
2387 );
2388
2389 break;
2390 }
2391
2392 // Handle async input port comIn
2393 case COMIN_COM: {
2394 // Deserialize argument data
2395 Fw::ComBuffer data;
2396 deserStatus = msg.deserialize(data);
2397 FW_ASSERT(
2398 deserStatus == Fw::FW_SERIALIZE_OK,
2399 static_cast<FwAssertArgType>(deserStatus)
2400 );
2401
2402 // Deserialize argument context
2403 U32 context;
2404 deserStatus = msg.deserialize(context);
2405 FW_ASSERT(
2406 deserStatus == Fw::FW_SERIALIZE_OK,
2407 static_cast<FwAssertArgType>(deserStatus)
2408 );
2409 // Call handler function
2410 this->comIn_handler(
2411 portNum,
2412 data,
2413 context
2414 );
2415
2416 break;
2417 }
2418
2419 // Handle async input port pingIn
2420 case PINGIN_PING: {
2421 // Deserialize argument key
2422 U32 key;
2423 deserStatus = msg.deserialize(key);
2424 FW_ASSERT(
2425 deserStatus == Fw::FW_SERIALIZE_OK,
2426 static_cast<FwAssertArgType>(deserStatus)
2427 );
2428 // Call handler function
2429 this->pingIn_handler(
2430 portNum,
2431 key
2432 );
2433
2434 break;
2435 }
2436
2437 // Handle async input port schedIn
2438 case SCHEDIN_SCHED: {
2439 // Deserialize argument context
2440 NATIVE_UINT_TYPE context;
2441 deserStatus = msg.deserialize(context);
2442 FW_ASSERT(
2443 deserStatus == Fw::FW_SERIALIZE_OK,
2444 static_cast<FwAssertArgType>(deserStatus)
2445 );
2446 // Call handler function
2447 this->schedIn_handler(
2448 portNum,
2449 context
2450 );
2451
2452 break;
2453 }
2454
2455 // Handle command BL_OpenFile
2456 case CMD_BL_OPENFILE: {
2457 // Deserialize opcode
2458 FwOpcodeType opCode = 0;
2459 deserStatus = msg.deserialize(opCode);
2460 FW_ASSERT (
2461 deserStatus == Fw::FW_SERIALIZE_OK,
2462 static_cast<FwAssertArgType>(deserStatus)
2463 );
2464
2465 // Deserialize command sequence
2466 U32 cmdSeq = 0;
2467 deserStatus = msg.deserialize(cmdSeq);
2468 FW_ASSERT (
2469 deserStatus == Fw::FW_SERIALIZE_OK,
2470 static_cast<FwAssertArgType>(deserStatus)
2471 );
2472
2473 // Deserialize command argument buffer
2474 Fw::CmdArgBuffer args;
2475 deserStatus = msg.deserialize(args);
2476 FW_ASSERT (
2477 deserStatus == Fw::FW_SERIALIZE_OK,
2478 static_cast<FwAssertArgType>(deserStatus)
2479 );
2480
2481 // Reset buffer
2482 args.resetDeser();
2483
2484 // Deserialize argument file
2485 Fw::CmdStringArg file;
2486 deserStatus = args.deserialize(file);
2487 if (deserStatus != Fw::FW_SERIALIZE_OK) {
2488 if (this->m_cmdResponseOut_OutputPort[0].isConnected()) {
2489 this->cmdResponse_out(
2490 opCode,
2491 cmdSeq,
2493 );
2494 }
2495 // Don't crash the task if bad arguments were passed from the ground
2496 break;
2497 }
2498
2499 // Make sure there was no data left over.
2500 // That means the argument buffer size was incorrect.
2501#if FW_CMD_CHECK_RESIDUAL
2502 if (args.getBuffLeft() != 0) {
2503 if (this->m_cmdResponseOut_OutputPort[0].isConnected()) {
2504 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::FORMAT_ERROR);
2505 }
2506 // Don't crash the task if bad arguments were passed from the ground
2507 break;
2508 }
2509#endif
2510
2511 // Call handler function
2512 this->BL_OpenFile_cmdHandler(
2513 opCode, cmdSeq,
2514 file
2515 );
2516
2517 break;
2518 }
2519
2520 // Handle command BL_CloseFile
2521 case CMD_BL_CLOSEFILE: {
2522 // Deserialize opcode
2523 FwOpcodeType opCode = 0;
2524 deserStatus = msg.deserialize(opCode);
2525 FW_ASSERT (
2526 deserStatus == Fw::FW_SERIALIZE_OK,
2527 static_cast<FwAssertArgType>(deserStatus)
2528 );
2529
2530 // Deserialize command sequence
2531 U32 cmdSeq = 0;
2532 deserStatus = msg.deserialize(cmdSeq);
2533 FW_ASSERT (
2534 deserStatus == Fw::FW_SERIALIZE_OK,
2535 static_cast<FwAssertArgType>(deserStatus)
2536 );
2537
2538 // Deserialize command argument buffer
2539 Fw::CmdArgBuffer args;
2540 deserStatus = msg.deserialize(args);
2541 FW_ASSERT (
2542 deserStatus == Fw::FW_SERIALIZE_OK,
2543 static_cast<FwAssertArgType>(deserStatus)
2544 );
2545
2546 // Reset buffer
2547 args.resetDeser();
2548
2549 // Make sure there was no data left over.
2550 // That means the argument buffer size was incorrect.
2551#if FW_CMD_CHECK_RESIDUAL
2552 if (args.getBuffLeft() != 0) {
2553 if (this->m_cmdResponseOut_OutputPort[0].isConnected()) {
2554 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::FORMAT_ERROR);
2555 }
2556 // Don't crash the task if bad arguments were passed from the ground
2557 break;
2558 }
2559#endif
2560
2561 // Call handler function
2562 this->BL_CloseFile_cmdHandler(opCode, cmdSeq);
2563
2564 break;
2565 }
2566
2567 // Handle command BL_SetLogging
2568 case CMD_BL_SETLOGGING: {
2569 // Deserialize opcode
2570 FwOpcodeType opCode = 0;
2571 deserStatus = msg.deserialize(opCode);
2572 FW_ASSERT (
2573 deserStatus == Fw::FW_SERIALIZE_OK,
2574 static_cast<FwAssertArgType>(deserStatus)
2575 );
2576
2577 // Deserialize command sequence
2578 U32 cmdSeq = 0;
2579 deserStatus = msg.deserialize(cmdSeq);
2580 FW_ASSERT (
2581 deserStatus == Fw::FW_SERIALIZE_OK,
2582 static_cast<FwAssertArgType>(deserStatus)
2583 );
2584
2585 // Deserialize command argument buffer
2586 Fw::CmdArgBuffer args;
2587 deserStatus = msg.deserialize(args);
2588 FW_ASSERT (
2589 deserStatus == Fw::FW_SERIALIZE_OK,
2590 static_cast<FwAssertArgType>(deserStatus)
2591 );
2592
2593 // Reset buffer
2594 args.resetDeser();
2595
2596 // Deserialize argument state
2598 deserStatus = args.deserialize(state);
2599 if (deserStatus != Fw::FW_SERIALIZE_OK) {
2600 if (this->m_cmdResponseOut_OutputPort[0].isConnected()) {
2601 this->cmdResponse_out(
2602 opCode,
2603 cmdSeq,
2605 );
2606 }
2607 // Don't crash the task if bad arguments were passed from the ground
2608 break;
2609 }
2610
2611 // Make sure there was no data left over.
2612 // That means the argument buffer size was incorrect.
2613#if FW_CMD_CHECK_RESIDUAL
2614 if (args.getBuffLeft() != 0) {
2615 if (this->m_cmdResponseOut_OutputPort[0].isConnected()) {
2616 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::FORMAT_ERROR);
2617 }
2618 // Don't crash the task if bad arguments were passed from the ground
2619 break;
2620 }
2621#endif
2622
2623 // Call handler function
2624 this->BL_SetLogging_cmdHandler(
2625 opCode, cmdSeq,
2626 state
2627 );
2628
2629 break;
2630 }
2631
2632 // Handle command BL_FlushFile
2633 case CMD_BL_FLUSHFILE: {
2634 // Deserialize opcode
2635 FwOpcodeType opCode = 0;
2636 deserStatus = msg.deserialize(opCode);
2637 FW_ASSERT (
2638 deserStatus == Fw::FW_SERIALIZE_OK,
2639 static_cast<FwAssertArgType>(deserStatus)
2640 );
2641
2642 // Deserialize command sequence
2643 U32 cmdSeq = 0;
2644 deserStatus = msg.deserialize(cmdSeq);
2645 FW_ASSERT (
2646 deserStatus == Fw::FW_SERIALIZE_OK,
2647 static_cast<FwAssertArgType>(deserStatus)
2648 );
2649
2650 // Deserialize command argument buffer
2651 Fw::CmdArgBuffer args;
2652 deserStatus = msg.deserialize(args);
2653 FW_ASSERT (
2654 deserStatus == Fw::FW_SERIALIZE_OK,
2655 static_cast<FwAssertArgType>(deserStatus)
2656 );
2657
2658 // Reset buffer
2659 args.resetDeser();
2660
2661 // Make sure there was no data left over.
2662 // That means the argument buffer size was incorrect.
2663#if FW_CMD_CHECK_RESIDUAL
2664 if (args.getBuffLeft() != 0) {
2665 if (this->m_cmdResponseOut_OutputPort[0].isConnected()) {
2666 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::FORMAT_ERROR);
2667 }
2668 // Don't crash the task if bad arguments were passed from the ground
2669 break;
2670 }
2671#endif
2672
2673 // Call handler function
2674 this->BL_FlushFile_cmdHandler(opCode, cmdSeq);
2675
2676 break;
2677 }
2678
2679 default:
2680 return MSG_DISPATCH_ERROR;
2681 }
2682
2683 return MSG_DISPATCH_OK;
2684 }
2685
2686 // ----------------------------------------------------------------------
2687 // Calls for messages received on special input ports
2688 // ----------------------------------------------------------------------
2689
2690 void BufferLoggerComponentBase ::
2691 m_p_cmdIn_in(
2692 Fw::PassiveComponentBase* callComp,
2693 NATIVE_INT_TYPE portNum,
2694 FwOpcodeType opCode,
2695 U32 cmdSeq,
2696 Fw::CmdArgBuffer& args
2697 )
2698 {
2699 FW_ASSERT(callComp);
2700 BufferLoggerComponentBase* compPtr = static_cast<BufferLoggerComponentBase*>(callComp);
2701
2702 const U32 idBase = callComp->getIdBase();
2703 FW_ASSERT(opCode >= idBase, opCode, idBase);
2704
2705 // Select base class function based on opcode
2706 switch (opCode - idBase) {
2707 case OPCODE_BL_OPENFILE: {
2708 compPtr->BL_OpenFile_cmdHandlerBase(
2709 opCode,
2710 cmdSeq,
2711 args
2712 );
2713 break;
2714 }
2715
2716 case OPCODE_BL_CLOSEFILE: {
2717 compPtr->BL_CloseFile_cmdHandlerBase(
2718 opCode,
2719 cmdSeq,
2720 args
2721 );
2722 break;
2723 }
2724
2725 case OPCODE_BL_SETLOGGING: {
2726 compPtr->BL_SetLogging_cmdHandlerBase(
2727 opCode,
2728 cmdSeq,
2729 args
2730 );
2731 break;
2732 }
2733
2734 case OPCODE_BL_FLUSHFILE: {
2735 compPtr->BL_FlushFile_cmdHandlerBase(
2736 opCode,
2737 cmdSeq,
2738 args
2739 );
2740 break;
2741 }
2742 }
2743 }
2744
2745 // ----------------------------------------------------------------------
2746 // Calls for messages received on typed input ports
2747 // ----------------------------------------------------------------------
2748
2749 void BufferLoggerComponentBase ::
2750 m_p_bufferSendIn_in(
2751 Fw::PassiveComponentBase* callComp,
2752 NATIVE_INT_TYPE portNum,
2753 Fw::Buffer& fwBuffer
2754 )
2755 {
2756 FW_ASSERT(callComp);
2757 BufferLoggerComponentBase* compPtr = static_cast<BufferLoggerComponentBase*>(callComp);
2758 compPtr->bufferSendIn_handlerBase(
2759 portNum,
2760 fwBuffer
2761 );
2762 }
2763
2764 void BufferLoggerComponentBase ::
2765 m_p_comIn_in(
2766 Fw::PassiveComponentBase* callComp,
2767 NATIVE_INT_TYPE portNum,
2768 Fw::ComBuffer& data,
2769 U32 context
2770 )
2771 {
2772 FW_ASSERT(callComp);
2773 BufferLoggerComponentBase* compPtr = static_cast<BufferLoggerComponentBase*>(callComp);
2774 compPtr->comIn_handlerBase(
2775 portNum,
2776 data,
2777 context
2778 );
2779 }
2780
2781 void BufferLoggerComponentBase ::
2782 m_p_pingIn_in(
2783 Fw::PassiveComponentBase* callComp,
2784 NATIVE_INT_TYPE portNum,
2785 U32 key
2786 )
2787 {
2788 FW_ASSERT(callComp);
2789 BufferLoggerComponentBase* compPtr = static_cast<BufferLoggerComponentBase*>(callComp);
2790 compPtr->pingIn_handlerBase(
2791 portNum,
2792 key
2793 );
2794 }
2795
2796 void BufferLoggerComponentBase ::
2797 m_p_schedIn_in(
2798 Fw::PassiveComponentBase* callComp,
2799 NATIVE_INT_TYPE portNum,
2800 NATIVE_UINT_TYPE context
2801 )
2802 {
2803 FW_ASSERT(callComp);
2804 BufferLoggerComponentBase* compPtr = static_cast<BufferLoggerComponentBase*>(callComp);
2805 compPtr->schedIn_handlerBase(
2806 portNum,
2807 context
2808 );
2809 }
2810
2811}
#define FW_ASSERT(...)
Definition Assert.hpp:14
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
U32 FwOpcodeType
Definition FpConfig.h:56
#define FW_LOG_TEXT_BUFFER_SIZE
Max size of string for text log message.
Definition FpConfig.h:299
#define FW_OBJECT_NAMES
Indicates whether or not object names are stored (more memory, can be used for tracking objects)
Definition FpConfig.h:88
@ ACTIVE_COMPONENT_EXIT
message to exit active component task
Enum representing a command response.
@ FORMAT_ERROR
Command failed to deserialize.
@ 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 CmdPortAc.hpp:37
@ SERIALIZED_SIZE
The size of the serial representations of the port arguments.
Definition ComPortAc.hpp:37
@ WARNING_HI
A serious but recoverable event.
@ DIAGNOSTIC
Software diagnostic events.
@ ACTIVITY_LO
Less important informational events.
const char * toChar() const override
Definition LogString.cpp:49
SerializeStatus serialize(SerializeBufferBase &buffer) const override
serialization function
Definition LogString.cpp:57
void init()
Object initializer.
Definition ObjBase.cpp:27
NATIVE_UINT_TYPE getBuffLeft() const
returns how much deserialization buffer is left
void resetDeser()
reset deserialization to beginning
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
SerializeStatus serialize(U8 val)
serialize 8-bit unsigned int
@ QUEUE_OK
message sent/received okay
Definition Queue.hpp:28
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
@ SERIALIZED_SIZE
The size of the serial representations of the port arguments.
@ SERIALIZED_SIZE
The size of the serial representations of the port arguments.
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.
const Time ZERO_TIME
Definition Time.cpp:5