27 return sizeof(m_buff);
34 const U8* getBuffAddr()
const {
50 this->m_fileName = file;
54 PrmDbComponentBase::init(queueDepth,instance);
57 void PrmDbImpl::clearDb() {
58 for (I32 entry = 0; entry < PRMDB_NUM_DB_ENTRIES; entry++) {
59 this->m_db[entry].used =
false;
60 this->m_db[entry].id = 0;
69 Fw::ParamValid stat = Fw::ParamValid::INVALID;
71 for (I32 entry = 0; entry < PRMDB_NUM_DB_ENTRIES; entry++) {
72 if (this->m_db[entry].used) {
73 if (this->m_db[entry].
id ==
id) {
74 val = this->m_db[entry].val;
75 stat = Fw::ParamValid::VALID;
82 if (Fw::ParamValid::INVALID == stat.e) {
83 this->log_WARNING_LO_PrmIdNotFound(
id);
95 bool existingEntry =
false;
98 for (
NATIVE_INT_TYPE entry = 0; entry < PRMDB_NUM_DB_ENTRIES; entry++) {
99 if ((this->m_db[entry].used) && (
id == this->m_db[entry].
id)) {
100 this->m_db[entry].val = val;
101 existingEntry =
true;
107 if (!existingEntry) {
108 for (I32 entry = 0; entry < PRMDB_NUM_DB_ENTRIES; entry++) {
109 if (!(this->m_db[entry].used)) {
110 this->m_db[entry].val = val;
111 this->m_db[entry].id = id;
112 this->m_db[entry].used =
true;
122 this->log_ACTIVITY_HI_PrmIdUpdated(
id);
123 }
else if (noSlots) {
124 this->log_FATAL_PrmDbFull(
id);
126 this->log_ACTIVITY_HI_PrmIdAdded(
id);
131 void PrmDbImpl::PRM_SAVE_FILE_cmdHandler(
FwOpcodeType opCode, U32 cmdSeq) {
138 this->log_WARNING_HI_PrmFileWriteError(PrmWriteError::OPEN,0,stat);
139 this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::EXECUTION_ERROR);
150 if (this->m_db[entry].used) {
152 static const U8 delim = PRMDB_ENTRY_DELIMITER;
154 stat = paramFile.
write(&delim,writeSize,
true);
157 this->log_WARNING_HI_PrmFileWriteError(PrmWriteError::DELIMITER,numRecords,stat);
158 this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::EXECUTION_ERROR);
161 if (writeSize !=
sizeof(delim)) {
163 this->log_WARNING_HI_PrmFileWriteError(PrmWriteError::DELIMITER_SIZE,numRecords,writeSize);
164 this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::EXECUTION_ERROR);
177 writeSize = buff.getBuffLength();
178 stat = paramFile.
write(buff.getBuffAddr(),writeSize,
true);
181 this->log_WARNING_HI_PrmFileWriteError(PrmWriteError::RECORD_SIZE,numRecords,stat);
182 this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::EXECUTION_ERROR);
185 if (writeSize !=
sizeof(writeSize)) {
187 this->log_WARNING_HI_PrmFileWriteError(PrmWriteError::RECORD_SIZE_SIZE,numRecords,writeSize);
188 this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::EXECUTION_ERROR);
197 serStat = buff.serialize(this->m_db[entry].
id);
202 writeSize = buff.getBuffLength();
203 stat = paramFile.
write(buff.getBuffAddr(),writeSize,
true);
206 this->log_WARNING_HI_PrmFileWriteError(PrmWriteError::PARAMETER_ID,numRecords,stat);
207 this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::EXECUTION_ERROR);
212 this->log_WARNING_HI_PrmFileWriteError(PrmWriteError::PARAMETER_ID_SIZE,numRecords,writeSize);
213 this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::EXECUTION_ERROR);
219 writeSize = this->m_db[entry].val.getBuffLength();
223 this->log_WARNING_HI_PrmFileWriteError(PrmWriteError::PARAMETER_VALUE,numRecords,stat);
224 this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::EXECUTION_ERROR);
229 this->log_WARNING_HI_PrmFileWriteError(PrmWriteError::PARAMETER_VALUE_SIZE,numRecords,writeSize);
230 this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::EXECUTION_ERROR);
238 this->log_ACTIVITY_HI_PrmFileSaveComplete(numRecords);
239 this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::OK);
253 this->log_WARNING_HI_PrmFileReadError(PrmReadError::OPEN,0,stat);
263 for (
NATIVE_INT_TYPE entry = 0; entry < PRMDB_NUM_DB_ENTRIES; entry++) {
277 this->log_WARNING_HI_PrmFileReadError(PrmReadError::DELIMITER,recordNum,fStat);
281 if (
sizeof(delimiter) != readSize) {
282 this->log_WARNING_HI_PrmFileReadError(PrmReadError::DELIMITER_SIZE,recordNum,readSize);
286 if (PRMDB_ENTRY_DELIMITER != delimiter) {
287 this->log_WARNING_HI_PrmFileReadError(PrmReadError::DELIMITER_VALUE,recordNum,delimiter);
293 readSize =
sizeof(recordSize);
295 fStat = paramFile.
read(buff.getBuffAddr(),readSize,
true);
297 this->log_WARNING_HI_PrmFileReadError(PrmReadError::RECORD_SIZE,recordNum,fStat);
300 if (
sizeof(recordSize) != readSize) {
301 this->log_WARNING_HI_PrmFileReadError(PrmReadError::RECORD_SIZE_SIZE,recordNum,readSize);
316 this->log_WARNING_HI_PrmFileReadError(PrmReadError::RECORD_SIZE_VALUE,recordNum,recordSize);
324 fStat = paramFile.
read(buff.getBuffAddr(),readSize,
true);
326 this->log_WARNING_HI_PrmFileReadError(PrmReadError::PARAMETER_ID,recordNum,fStat);
330 this->log_WARNING_HI_PrmFileReadError(PrmReadError::PARAMETER_ID_SIZE,recordNum,readSize);
335 desStat = buff.setBuffLen(readSize);
344 this->m_db[entry].used =
true;
345 this->m_db[entry].id = parameterId;
346 readSize = recordSize-
sizeof(parameterId);
351 this->log_WARNING_HI_PrmFileReadError(PrmReadError::PARAMETER_VALUE,recordNum,fStat);
354 if (
static_cast<U32
>(readSize) != recordSize-
sizeof(parameterId)) {
355 this->log_WARNING_HI_PrmFileReadError(PrmReadError::PARAMETER_VALUE_SIZE,recordNum,readSize);
360 desStat = this->m_db[entry].val.setBuffLen(readSize);
367 this->log_ACTIVITY_HI_PrmFileLoadComplete(recordNum);
372 this->pingOut_out(0,key);
PlatformIntType NATIVE_INT_TYPE
uint8_t U8
8-bit unsigned integer
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
PlatformUIntType NATIVE_UINT_TYPE
#define FW_PARAM_BUFFER_MAX_SIZE
Component for managing parameters.
U8 * getBuffAddr()
gets buffer address for data filling
NATIVE_UINT_TYPE getBuffLength() const
returns current buffer size
NATIVE_UINT_TYPE length() const
Get length of string.
const char * toChar() const
gets char buffer
@ OP_OK
Operation was successful.
Status write(const void *buffer, NATIVE_INT_TYPE &size, bool waitForDone=true)
write size; will return amount written or errno
@ OPEN_WRITE
Open file for writing.
@ OPEN_READ
Open file for reading.
Status open(const char *fileName, Mode mode)
open file. Writing creates file if it doesn't exist
Status read(void *buffer, NATIVE_INT_TYPE &size, bool waitForFull=true)
waitForFull = true to wait for all bytes to be read
void readParamFile()
PrmDb file read function.
virtual ~PrmDbImpl()
PrmDb destructor.
PrmDbImpl(const char *name)
PrmDb constructor.
void configure(const char *file)
PrmDb configure method.
void init(NATIVE_INT_TYPE queueDepth, NATIVE_INT_TYPE instance)
PrmDb initialization function.
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.
PrmDb_PrmReadError PrmReadError
PrmDb_PrmWriteError PrmWriteError