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 
23 namespace Svc {
24 
29 
36 
37 class PrmDbImpl final : public PrmDbComponentBase {
38  friend class PrmDbTester;
39 
40  public:
47  PrmDbImpl(const char* name);
48 
54  void configure(const char* file);
55 
61  void readParamFile(); // NOTE: Assumed to run at initialization time. No guard of data structure.
62 
65  virtual ~PrmDbImpl();
66 
67  // Parameter update status for an individual parameter update or add
73  };
74 
75  // Enum to return status of parameter file load
79  };
80 
81  protected:
82  private:
83  Fw::String m_fileName;
84 
85  PrmDbFileLoadState m_state; // Current file load state of the parameter database
86 
87  // Structure for a single parameter entry
88  struct t_dbStruct {
89  bool used;
90  FwPrmIdType id;
91  Fw::ParamBuffer val;
92 
93  bool operator==(const t_dbStruct& other) const {
94  if (used != other.used)
95  return false;
96  if (id != other.id)
97  return false;
98  // Compare lengths first
99  if (val.getSize() != other.val.getSize())
100  return false;
101  // Compare buffer contents
102  return std::memcmp(val.getBuffAddr(), other.val.getBuffAddr(), val.getSize()) == 0;
103  }
104  };
105 
106  // Pointers to the active and staging databases
107  // These point to the actual storage arrays below
108  // The active database is the ONLY one used for getting parameters
109  // The staging database is used for loading parameters from a file
110  // when commanded. Upon reading the file, the parameters are "staged"
111  // into the staging database, and then committed to the active database
112  // when a commit command is received.
113  t_dbStruct* m_activeDb;
114  t_dbStruct* m_stagingDb;
115 
116  // Actual storage for the active and staging databases
117  t_dbStruct m_dbStore1[PRMDB_NUM_DB_ENTRIES];
118  t_dbStruct m_dbStore2[PRMDB_NUM_DB_ENTRIES];
119 
123 
133  PrmLoadStatus readParamFileImpl(const Fw::StringBase& fileName, PrmDbType dbType);
134 
144  Fw::ParamValid getPrm_handler(FwIndexType portNum, FwPrmIdType id, Fw::ParamBuffer& val);
145 
154  void setPrm_handler(FwIndexType portNum, FwPrmIdType id, Fw::ParamBuffer& val);
155 
163  PrmDbImpl::PrmUpdateType updateAddPrmImpl(FwPrmIdType id, Fw::ParamBuffer& val, PrmDbType prmDbType);
164 
173  void pingIn_handler(FwIndexType portNum, U32 key);
174 
183  void PRM_SAVE_FILE_cmdHandler(FwOpcodeType opCode, U32 cmdSeq);
184 
197  void PRM_LOAD_FILE_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, const Fw::CmdStringArg& fileName, PrmDb_Merge merge);
198 
208  void PRM_COMMIT_STAGED_cmdHandler(FwOpcodeType opCode, U32 cmdSeq);
209 
213 
219  void clearDb(PrmDbType prmDbType);
220 
225  t_dbStruct* getDbPtr(PrmDbType dbType);
226 
231  static Fw::String getDbString(PrmDbType dbType);
232 
236  bool dbEqual();
237 
243  void dbCopy(PrmDbType dest, PrmDbType src);
244 
252  void dbCopySingle(PrmDbType dest, PrmDbType src, FwSizeType index);
253 };
254 } // namespace Svc
255 
256 #endif /* PRMDBIMPL_HPP_ */
Parameter already in database, updated parameter.
Definition: PrmDbImpl.hpp:71
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:25
PlatformSizeType FwSizeType
friend class PrmDbTester
Definition: PrmDbImpl.hpp:38
void readParamFile()
PrmDb file read function.
Definition: PrmDbImpl.cpp:55
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:40
PrmDb_PrmDbType PrmDbType
Definition: PrmDbImpl.hpp:27
Parameter added to database.
Definition: PrmDbImpl.hpp:70
Component class for managing parameters.
Definition: PrmDbImpl.hpp:37
File load error.
Definition: PrmDbImpl.hpp:78
void configure(const char *file)
PrmDb configure method.
Definition: PrmDbImpl.cpp:50
Auto-generated base for PrmDb component.
PrmDb_PrmReadError PrmReadError
Definition: PrmDbImpl.hpp:26
PrmDb_PrmDbFileLoadState PrmDbFileLoadState
Definition: PrmDbImpl.hpp:28
PlatformIndexType FwIndexType
File load successful.
Definition: PrmDbImpl.hpp:77
RateGroupDivider component implementation.
Enum representing parameter validity.
No slots available to add new parameter.
Definition: PrmDbImpl.hpp:69
virtual ~PrmDbImpl()
PrmDb destructor.
Definition: PrmDbImpl.cpp:48