F´ Flight Software - C/C++ Documentation  NASA-v1.5.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
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 
17  // ----------------------------------------------------------------------
18  // Construction, initialization, and destruction
19  // ----------------------------------------------------------------------
20 
22  BufferLogger(const char *const compName) :
23  BufferLoggerComponentBase(compName),
24  m_state(LOGGING_ON),
25  m_file(*this)
26  {
27 
28  }
29 
31  init(
32  const NATIVE_INT_TYPE queueDepth,
33  const NATIVE_INT_TYPE instance
34  )
35  {
36  BufferLoggerComponentBase::init(queueDepth, instance);
37  }
38 
39  // ----------------------------------------------------------------------
40  // Public methods
41  // ----------------------------------------------------------------------
42 
43  //TODO(mereweth) - only allow calling this once?
45  initLog(
46  const char *const logFilePrefix,
47  const char *const logFileSuffix,
48  const U32 maxFileSize,
49  const U8 sizeOfSize
50  )
51  {
52  m_file.init(logFilePrefix, logFileSuffix, maxFileSize, sizeOfSize);
53  }
54 
55  // ----------------------------------------------------------------------
56  // Handler implementations for user-defined typed input ports
57  // ----------------------------------------------------------------------
58 
59  void BufferLogger ::
60  bufferSendIn_handler(
61  const NATIVE_INT_TYPE portNum,
62  Fw::Buffer& fwBuffer
63  )
64  {
65  if (m_state == LOGGING_ON) {
66  const U8 *const addr = reinterpret_cast<U8*>(fwBuffer.getdata());
67  const U32 size = fwBuffer.getsize();
68  m_file.logBuffer(addr, size);
69  }
70  this->bufferSendOut_out(0, fwBuffer);
71  }
72 
75  NATIVE_INT_TYPE portNum,
76  Fw::ComBuffer &data,
77  U32 context
78  )
79  {
80  if (m_state == LOGGING_ON) {
81  const U8 *const addr = data.getBuffAddr();
82  const U32 size = data.getBuffLength();
83  m_file.logBuffer(addr, size);
84  }
85  }
86 
88  pingIn_handler(NATIVE_INT_TYPE portNum, U32 key)
89  {
90  this->pingOut_out(0, key);
91  }
92 
95  const NATIVE_INT_TYPE portNum,
96  NATIVE_UINT_TYPE context
97  )
98  {
99  // TODO
100  }
101 
102  // ----------------------------------------------------------------------
103  // Command handler implementations
104  // ----------------------------------------------------------------------
105 
106  // TODO(mereweth) - should this command only set the base name?
107  void BufferLogger ::
108  BL_OpenFile_cmdHandler(
109  const FwOpcodeType opCode,
110  const U32 cmdSeq,
111  const Fw::CmdStringArg& file
112  )
113  {
114  m_file.setBaseName(file);
115  this->cmdResponse_out(opCode, cmdSeq, Fw::COMMAND_OK);
116  }
117 
120  const FwOpcodeType opCode,
121  const U32 cmdSeq
122  )
123  {
124  m_file.closeAndEmitEvent();
125  this->cmdResponse_out(opCode, cmdSeq, Fw::COMMAND_OK);
126  }
127 
130  const FwOpcodeType opCode,
131  const U32 cmdSeq,
132  LogState state
133  )
134  {
135  m_state = state;
136  if (state == LOGGING_OFF) {
137  m_file.closeAndEmitEvent();
138  }
139  this->cmdResponse_out(opCode, cmdSeq, Fw::COMMAND_OK);
140  }
141 
144  const FwOpcodeType opCode,
145  const U32 cmdSeq
146  )
147  {
148  const bool status = m_file.flush();
149  if(status)
150  {
151  this->cmdResponse_out(opCode, cmdSeq, Fw::COMMAND_OK);
152  }
153  else
154  {
155  this->cmdResponse_out(opCode, cmdSeq, Fw::COMMAND_EXECUTION_ERROR);
156  }
157  }
158 
159 };
Svc::BufferLogger::BufferLogger
BufferLogger(const char *const compName)
Create a BufferLogger object.
Definition: BufferLogger.cpp:22
Fw::Buffer::getsize
U32 getsize(void)
get member size
Definition: BufferSerializableAc.cpp:61
BufferLogger.hpp
Fw::ComBuffer::getBuffAddr
U8 * getBuffAddr(void)
gets buffer address for data filling
Definition: ComBuffer.cpp:36
U8
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.hpp:76
Fw::Buffer
Definition: BufferSerializableAc.hpp:24
Fw::CmdStringArg
Definition: CmdString.hpp:11
Svc::BufferLogger::initLog
void initLog(const char *const logFilePrefix, const char *const logFileSuffix, const U32 maxFileSize, const U8 sizeOfSize)
Set up log file parameters.
Definition: BufferLogger.cpp:45
Svc::BufferLoggerComponentBase::LOGGING_OFF
PROTECTED LOGGING_OFF
Definition: BufferLoggerComponentAc.hpp:608
Fw::Buffer::getdata
U64 getdata(void)
get member data
Definition: BufferSerializableAc.cpp:57
Svc::BufferLogger::comIn_handler
void comIn_handler(const NATIVE_INT_TYPE portNum, Fw::ComBuffer &data, U32 context)
Definition: BufferLogger.cpp:74
Fw::ObjBase::init
void init(void)
Object initializer.
Definition: ObjBase.cpp:26
Svc::BufferLogger::BL_CloseFile_cmdHandler
void BL_CloseFile_cmdHandler(const FwOpcodeType opCode, const U32 cmdSeq)
Definition: BufferLogger.cpp:119
Svc::BufferLoggerComponentBase::pingOut_out
void pingOut_out(NATIVE_INT_TYPE portNum, U32 key)
Definition: BufferLoggerComponentAc.cpp:704
Fw::COMMAND_EXECUTION_ERROR
@ COMMAND_EXECUTION_ERROR
Definition: CmdResponsePortAc.hpp:29
Svc::BufferLogger::cmdSeq
PRIVATE const U32 cmdSeq
Definition: BufferLogger.hpp:227
Svc::BufferLogger::fwBuffer
PRIVATE Fw::Buffer & fwBuffer
Definition: BufferLogger.hpp:193
FwOpcodeType
#define FwOpcodeType
Type representation for a command opcode.
Definition: FpConfig.hpp:62
NATIVE_UINT_TYPE
unsigned int NATIVE_UINT_TYPE
native unsigned integer type declaration
Definition: BasicTypes.hpp:30
Fw::SerializeBufferBase::getBuffLength
NATIVE_UINT_TYPE getBuffLength() const
returns current buffer size
Definition: Serializable.cpp:592
Svc::BufferLogger::file
PRIVATE const U32 const Fw::CmdStringArg & file
Definition: BufferLogger.hpp:229
Svc
Definition: ActiveLoggerComponentAc.cpp:22
Fw::COMMAND_OK
@ COMMAND_OK
Definition: CmdResponsePortAc.hpp:25
Svc::BufferLogger::BL_SetLogging_cmdHandler
void BL_SetLogging_cmdHandler(const FwOpcodeType opCode, const U32 cmdSeq, LogState state)
Definition: BufferLogger.cpp:129
Svc::BufferLogger::schedIn_handler
void schedIn_handler(const NATIVE_INT_TYPE portNum, NATIVE_UINT_TYPE context)
Definition: BufferLogger.cpp:94
Svc::BufferLogger::sizeOfSize
U8 sizeOfSize
The number of bytes to use when storing the size field at the start of each buffer.
Definition: BufferLogger.hpp:137
Svc::BufferLoggerComponentBase
Auto-generated base for BufferLogger component.
Definition: BufferLoggerComponentAc.hpp:51
NATIVE_INT_TYPE
int NATIVE_INT_TYPE
native integer type declaration
Definition: BasicTypes.hpp:29
Svc::BufferLogger::BL_FlushFile_cmdHandler
void BL_FlushFile_cmdHandler(const FwOpcodeType opCode, const U32 cmdSeq)
Definition: BufferLogger.cpp:143
Svc::BufferLogger::m_file
File m_file
The file.
Definition: BufferLogger.hpp:263
Fw::ComBuffer
Definition: ComBuffer.hpp:21
Svc::BufferLogger::pingIn_handler
void pingIn_handler(const NATIVE_INT_TYPE portNum, U32 key)
Definition: BufferLogger.cpp:88