F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
BufferLogger.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title BufferLogger.cpp
3 // \author bocchino, dinkel, mereweth
4 // \brief Svc BufferLogger implementation
5 //
6 // \copyright
7 // Copyright (C) 2015-2017 California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12 
14 
15 namespace Svc {
16 
18 // ----------------------------------------------------------------------
19 // Construction, initialization, and destruction
20 // ----------------------------------------------------------------------
21 
22 BufferLogger ::BufferLogger(const char* const compName)
23  : BufferLoggerComponentBase(compName), m_state(LogState::LOGGING_ON), m_file(*this) {}
24 
25 // ----------------------------------------------------------------------
26 // Public methods
27 // ----------------------------------------------------------------------
28 
29 // TODO(mereweth) - only allow calling this once?
30 void BufferLogger ::initLog(const char* const logFilePrefix,
31  const char* const logFileSuffix,
32  const FwSizeType maxFileSize,
33  const U8 sizeOfSize) {
34  m_file.init(logFilePrefix, logFileSuffix, maxFileSize, sizeOfSize);
35 }
36 
37 // ----------------------------------------------------------------------
38 // Handler implementations for user-defined typed input ports
39 // ----------------------------------------------------------------------
40 
41 void BufferLogger ::bufferSendIn_handler(const FwIndexType portNum, Fw::Buffer& fwBuffer) {
42  if (m_state == LogState::LOGGING_ON) {
43  const U8* const addr = fwBuffer.getData();
44  const FwSizeType size = fwBuffer.getSize();
45  m_file.logBuffer(addr, size);
46  }
47  this->bufferSendOut_out(0, fwBuffer);
48 }
49 
50 void BufferLogger ::comIn_handler(FwIndexType portNum, Fw::ComBuffer& data, U32 context) {
51  if (m_state == LogState::LOGGING_ON) {
52  const U8* const addr = data.getBuffAddr();
53  const FwSizeType size = data.getBuffLength();
54  m_file.logBuffer(addr, size);
55  }
56 }
57 
58 void BufferLogger ::pingIn_handler(FwIndexType portNum, U32 key) {
59  this->pingOut_out(0, key);
60 }
61 
62 void BufferLogger ::schedIn_handler(const FwIndexType portNum, U32 context) {
63  // TODO
64 }
65 
66 // ----------------------------------------------------------------------
67 // Command handler implementations
68 // ----------------------------------------------------------------------
69 
70 // TODO(mereweth) - should this command only set the base name?
71 void BufferLogger ::BL_OpenFile_cmdHandler(const FwOpcodeType opCode, const U32 cmdSeq, const Fw::CmdStringArg& file) {
72  m_file.setBaseName(file);
73  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
74 }
75 
76 void BufferLogger ::BL_CloseFile_cmdHandler(const FwOpcodeType opCode, const U32 cmdSeq) {
77  m_file.closeAndEmitEvent();
78  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
79 }
80 
81 void BufferLogger ::BL_SetLogging_cmdHandler(const FwOpcodeType opCode, const U32 cmdSeq, LogState state) {
82  m_state = state;
83  if (state == LogState::LOGGING_OFF) {
84  m_file.closeAndEmitEvent();
85  }
86  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
87 }
88 
89 void BufferLogger ::BL_FlushFile_cmdHandler(const FwOpcodeType opCode, const U32 cmdSeq) {
90  const bool status = m_file.flush();
91  if (status) {
92  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
93  } else {
95  }
96 }
97 
98 } // namespace Svc
FwIdType FwOpcodeType
The type of a command opcode.
PlatformSizeType FwSizeType
BufferLogger_LogState LogState
void initLog(const char *const logFilePrefix, const char *const logFileSuffix, const FwSizeType maxFileSize, const U8 sizeOfSize)
Set up log file parameters.
void pingOut_out(FwIndexType portNum, U32 key)
Invoke output port pingOut.
U8 * getData() const
Definition: Buffer.cpp:56
Serializable::SizeType getBuffLength() const
returns current buffer size
BufferLogger(const char *const compName)
Create a BufferLogger object.
Auto-generated base for BufferLogger component.
U8 * getBuffAddr()
gets buffer address for data filling
Definition: ComBuffer.cpp:38
Command successfully executed.
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:53
void cmdResponse_out(FwOpcodeType opCode, U32 cmdSeq, Fw::CmdResponse response)
Emit command response.
FwSizeType getSize() const
Definition: Buffer.cpp:60
Command had execution error.
void bufferSendOut_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port bufferSendOut.
PlatformIndexType FwIndexType
RateGroupDivider component implementation.