F´ Flight Software - C/C++ Documentation  NASA-v2.0.1
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 
30  void BufferLogger ::
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?
44  void BufferLogger ::
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 = fwBuffer.getData();
67  const U32 size = fwBuffer.getSize();
68  m_file.logBuffer(addr, size);
69  }
70  this->bufferSendOut_out(0, fwBuffer);
71  }
72 
73  void BufferLogger ::
74  comIn_handler(
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 
87  void BufferLogger ::
88  pingIn_handler(NATIVE_INT_TYPE portNum, U32 key)
89  {
90  this->pingOut_out(0, key);
91  }
92 
93  void BufferLogger ::
94  schedIn_handler(
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 
118  void BufferLogger ::
119  BL_CloseFile_cmdHandler(
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 
128  void BufferLogger ::
129  BL_SetLogging_cmdHandler(
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 
142  void BufferLogger ::
143  BL_FlushFile_cmdHandler(
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
BufferLogger.hpp
Fw::Buffer::getData
U8 * getData() const
Definition: Buffer.cpp:56
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: Buffer.hpp:43
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
Fw::Buffer::getSize
U32 getSize() const
Definition: Buffer.cpp:60
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
Svc::BufferLogger::init
void init(const NATIVE_INT_TYPE queueDepth, const NATIVE_INT_TYPE instance)
Initialize a BufferLogger object.
Definition: BufferLogger.cpp:31
Fw::SerializeBufferBase::getBuffLength
NATIVE_UINT_TYPE getBuffLength() const
returns current buffer size
Definition: Serializable.cpp:587
Svc
Definition: ActiveRateGroupImplCfg.hpp:18
NATIVE_INT_TYPE
int NATIVE_INT_TYPE
native integer type declaration
Definition: BasicTypes.hpp:29
Fw::ComBuffer
Definition: ComBuffer.hpp:21