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
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 
23  BufferLogger(const char *const compName) :
24  BufferLoggerComponentBase(compName),
25  m_state(LogState::LOGGING_ON),
26  m_file(*this)
27  {
28 
29  }
30 
31  // ----------------------------------------------------------------------
32  // Public methods
33  // ----------------------------------------------------------------------
34 
35  //TODO(mereweth) - only allow calling this once?
37  initLog(
38  const char *const logFilePrefix,
39  const char *const logFileSuffix,
40  const U32 maxFileSize,
41  const U8 sizeOfSize
42  )
43  {
44  m_file.init(logFilePrefix, logFileSuffix, maxFileSize, sizeOfSize);
45  }
46 
47  // ----------------------------------------------------------------------
48  // Handler implementations for user-defined typed input ports
49  // ----------------------------------------------------------------------
50 
51  void BufferLogger ::
52  bufferSendIn_handler(
53  const NATIVE_INT_TYPE portNum,
54  Fw::Buffer& fwBuffer
55  )
56  {
57  if (m_state == LogState::LOGGING_ON) {
58  const U8 *const addr = fwBuffer.getData();
59  const U32 size = fwBuffer.getSize();
60  m_file.logBuffer(addr, size);
61  }
62  this->bufferSendOut_out(0, fwBuffer);
63  }
64 
65  void BufferLogger ::
66  comIn_handler(
67  NATIVE_INT_TYPE portNum,
68  Fw::ComBuffer &data,
69  U32 context
70  )
71  {
72  if (m_state == LogState::LOGGING_ON) {
73  const U8 *const addr = data.getBuffAddr();
74  const U32 size = data.getBuffLength();
75  m_file.logBuffer(addr, size);
76  }
77  }
78 
79  void BufferLogger ::
80  pingIn_handler(NATIVE_INT_TYPE portNum, U32 key)
81  {
82  this->pingOut_out(0, key);
83  }
84 
85  void BufferLogger ::
86  schedIn_handler(
87  const NATIVE_INT_TYPE portNum,
88  U32 context
89  )
90  {
91  // TODO
92  }
93 
94  // ----------------------------------------------------------------------
95  // Command handler implementations
96  // ----------------------------------------------------------------------
97 
98  // TODO(mereweth) - should this command only set the base name?
99  void BufferLogger ::
100  BL_OpenFile_cmdHandler(
101  const FwOpcodeType opCode,
102  const U32 cmdSeq,
103  const Fw::CmdStringArg& file
104  )
105  {
106  m_file.setBaseName(file);
107  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
108  }
109 
110  void BufferLogger ::
111  BL_CloseFile_cmdHandler(
112  const FwOpcodeType opCode,
113  const U32 cmdSeq
114  )
115  {
116  m_file.closeAndEmitEvent();
117  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
118  }
119 
120  void BufferLogger ::
121  BL_SetLogging_cmdHandler(
122  const FwOpcodeType opCode,
123  const U32 cmdSeq,
124  LogState state
125  )
126  {
127  m_state = state;
128  if (state == LogState::LOGGING_OFF) {
129  m_file.closeAndEmitEvent();
130  }
131  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
132  }
133 
134  void BufferLogger ::
135  BL_FlushFile_cmdHandler(
136  const FwOpcodeType opCode,
137  const U32 cmdSeq
138  )
139  {
140  const bool status = m_file.flush();
141  if(status)
142  {
143  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
144  }
145  else
146  {
147  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR);
148  }
149  }
150 
151 }
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:55
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:30
U32 FwOpcodeType
Definition: FpConfig.h:91
U8 * getData() const
Definition: Buffer.cpp:68
U32 getSize() const
Definition: Buffer.cpp:72
@ EXECUTION_ERROR
Command had execution error.
@ OK
Command successfully executed.
U8 * getBuffAddr()
gets buffer address for data filling
Definition: ComBuffer.cpp:40
Serializable::SizeType getBuffLength() const
returns current buffer size
Auto-generated base for BufferLogger component.
void pingOut_out(FwIndexType portNum, U32 key)
Invoke output port pingOut.
void bufferSendOut_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port bufferSendOut.
void cmdResponse_out(FwOpcodeType opCode, U32 cmdSeq, Fw::CmdResponse response)
Emit command response.
void initLog(const char *const logFilePrefix, const char *const logFileSuffix, const U32 maxFileSize, const U8 sizeOfSize)
Set up log file parameters.
BufferLogger(const char *const compName)
Create a BufferLogger object.
BufferLogger_LogState LogState