F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
PrmDbImpl.hpp
Go to the documentation of this file.
1 
13 #ifndef PRMDBIMPL_HPP_
14 #define PRMDBIMPL_HPP_
15 
16 #include <Fw/Types/String.hpp>
17 #include <Os/Mutex.hpp>
21 #include <config/PrmDbImplCfg.hpp>
22 #include <cstring>
23 
24 namespace Svc {
25 
30 
37 
38 class PrmDbImpl final : public PrmDbComponentBase {
39  friend class PrmDbTester;
40 
41  public:
48  PrmDbImpl(const char* name);
49 
55  void configure(const char* file);
56 
62  void readParamFile(); // NOTE: Assumed to run at initialization time. No guard of data structure.
63 
66  virtual ~PrmDbImpl();
67 
68  // Parameter update status for an individual parameter update or add
74  };
75 
76  // Enum to return status of parameter file load
80  };
81 
82  protected:
83  private:
84  Fw::String m_fileName;
85 
86  PrmDbFileLoadState m_state; // Current file load state of the parameter database
87 
88  // Structure for a single parameter entry
89  struct t_dbStruct {
90  bool used;
91  FwPrmIdType id;
92  Fw::ParamBuffer val;
93 
94  bool operator==(const t_dbStruct& other) const {
95  if (used != other.used)
96  return false;
97  if (id != other.id)
98  return false;
99  // Compare lengths first
100  if (val.getSize() != other.val.getSize())
101  return false;
102  // Compare buffer contents
103  return std::memcmp(val.getBuffAddr(), other.val.getBuffAddr(), val.getSize()) == 0;
104  }
105  };
106 
107  // helper to compute CRC over a buffer
108  U32 computeCrc(U32 crc, const BYTE* buff, FwSizeType size);
109 
110  // Pointers to the active and staging databases
111  // These point to the actual storage arrays below
112  // The active database is the ONLY one used for getting parameters
113  // The staging database is used for loading parameters from a file
114  // when commanded. Upon reading the file, the parameters are "staged"
115  // into the staging database, and then committed to the active database
116  // when a commit command is received.
117  t_dbStruct* m_activeDb;
118  t_dbStruct* m_stagingDb;
119 
120  // Actual storage for the active and staging databases
121  t_dbStruct m_dbStore1[PRMDB_NUM_DB_ENTRIES];
122  t_dbStruct m_dbStore2[PRMDB_NUM_DB_ENTRIES];
123 
127 
137  PrmLoadStatus readParamFileImpl(const Fw::StringBase& fileName, PrmDbType dbType);
138 
148  Fw::ParamValid getPrm_handler(FwIndexType portNum, FwPrmIdType id, Fw::ParamBuffer& val);
149 
158  void setPrm_handler(FwIndexType portNum, FwPrmIdType id, Fw::ParamBuffer& val);
159 
167  PrmDbImpl::PrmUpdateType updateAddPrmImpl(FwPrmIdType id, Fw::ParamBuffer& val, PrmDbType prmDbType);
168 
177  void pingIn_handler(FwIndexType portNum, U32 key);
178 
187  void PRM_SAVE_FILE_cmdHandler(FwOpcodeType opCode, U32 cmdSeq);
188 
201  void PRM_LOAD_FILE_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, const Fw::CmdStringArg& fileName, PrmDb_Merge merge);
202 
212  void PRM_COMMIT_STAGED_cmdHandler(FwOpcodeType opCode, U32 cmdSeq);
213 
217 
223  void clearDb(PrmDbType prmDbType);
224 
229  t_dbStruct* getDbPtr(PrmDbType dbType);
230 
235  static Fw::String getDbString(PrmDbType dbType);
236 
240  bool dbEqual();
241 
247  void dbCopy(PrmDbType dest, PrmDbType src);
248 
256  void dbCopySingle(PrmDbType dest, PrmDbType src, FwSizeType index);
257 };
258 } // namespace Svc
259 
260 #endif /* PRMDBIMPL_HPP_ */
Parameter already in database, updated parameter.
Definition: PrmDbImpl.hpp:72
State of parameter DB file load operations.
U8 * getBuffAddr()
Get buffer address for data filling (non-const version)
Definition: PrmBuffer.cpp:42
FwIdType FwOpcodeType
The type of a command opcode.
PrmDb_PrmWriteError PrmWriteError
Definition: PrmDbImpl.hpp:26
PlatformSizeType FwSizeType
friend class PrmDbTester
Definition: PrmDbImpl.hpp:39
void readParamFile()
PrmDb file read function.
Definition: PrmDbImpl.cpp:58
Serializable::SizeType getSize() const override
Get current buffer size.
FwIdType FwPrmIdType
The type of a parameter identifier.
PrmDbImpl(const char *name)
PrmDb constructor.
Definition: PrmDbImpl.cpp:43
PrmDb_PrmDbType PrmDbType
Definition: PrmDbImpl.hpp:28
Parameter added to database.
Definition: PrmDbImpl.hpp:71
Component class for managing parameters.
Definition: PrmDbImpl.hpp:38
File load error.
Definition: PrmDbImpl.hpp:79
void configure(const char *file)
PrmDb configure method.
Definition: PrmDbImpl.cpp:53
Auto-generated base for PrmDb component.
PrmDb_PrmReadError PrmReadError
Definition: PrmDbImpl.hpp:27
PrmDb_PrmDbFileLoadState PrmDbFileLoadState
Definition: PrmDbImpl.hpp:29
PlatformIndexType FwIndexType
File load successful.
Definition: PrmDbImpl.hpp:78
RateGroupDivider component implementation.
Enum representing parameter validity.
U8 BYTE
byte type
Definition: BasicTypes.h:56
No slots available to add new parameter.
Definition: PrmDbImpl.hpp:70
virtual ~PrmDbImpl()
PrmDb destructor.
Definition: PrmDbImpl.cpp:51