Skip to content

Commit

Permalink
Update Svc/PolyDb to use configurable FPP enumeration as index (#2587)
Browse files Browse the repository at this point in the history
* Updating PolyDb

* PolyDb rename

* PolyDb Unit tests pass again

* Updated docs

* Fixed entry asserts

* Updates due to PR comments
  • Loading branch information
timcanham authored Mar 26, 2024
1 parent 9f5b364 commit 00eed9f
Show file tree
Hide file tree
Showing 19 changed files with 411 additions and 528 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ coverity.out

**/docs/*.html
/docs/UsersGuide/api/*
*-template
*.template.*

logs

Expand Down
13 changes: 9 additions & 4 deletions Svc/PolyDb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
####
set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/PolyDb.fpp"
"${CMAKE_CURRENT_LIST_DIR}/PolyDbImpl.cpp"
"${CMAKE_CURRENT_LIST_DIR}/PolyDb.cpp"
)

register_fprime_module()
Expand All @@ -18,9 +18,14 @@ register_fprime_module()
#
# This UT does not use auto-generate GTest files. DO NOT emulate.
####

set(UT_AUTO_HELPERS ON)

set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/test/ut/PolyDbComponentTestAc.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/PolyDbTester.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/PolyDbImplTester.cpp"
"${FPRIME_FRAMEWORK_PATH}/Svc/PolyDb/PolyDb.fpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/PolyDbTestMain.cpp"
# "${CMAKE_CURRENT_LIST_DIR}/test/ut/PolyDbTesterHelpers.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/PolyDbTester.cpp"
)

register_fprime_ut()
51 changes: 51 additions & 0 deletions Svc/PolyDb/PolyDb.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* PolyDbImpl.cpp
*
* Created on: May 13, 2014
* Author: Timothy Canham
*/

#include <Svc/PolyDb/PolyDb.hpp>
#include <Fw/Types/Assert.hpp>
#include <FpConfig.hpp>

namespace Svc {
PolyDb::PolyDb(const char* const name) : PolyDbComponentBase(name) {
// initialize all entries to stale
for (FwIndexType entry = 0; entry < Svc::PolyDbCfg::PolyDbEntry::NUM_CONSTANTS; entry++) {
this->m_db[entry].status = MeasurementStatus::STALE;
}
}

void PolyDb ::
getValue_handler(
NATIVE_INT_TYPE portNum,
const Svc::PolyDbCfg::PolyDbEntry& entry,
Svc::MeasurementStatus& status,
Fw::Time& time,
Fw::PolyType& val)
{
FW_ASSERT(entry.isValid(),entry.e);
status = this->m_db[entry.e].status;
time = this->m_db[entry.e].time;
val = this->m_db[entry.e].val;
}

void PolyDb ::
setValue_handler(
NATIVE_INT_TYPE portNum,
const Svc::PolyDbCfg::PolyDbEntry& entry,
Svc::MeasurementStatus& status,
Fw::Time& time,
Fw::PolyType& val)
{
FW_ASSERT(entry.isValid(),entry.e);
this->m_db[entry.e].status = status;
this->m_db[entry.e].time = time;
this->m_db[entry.e].val = val;
}

PolyDb::~PolyDb() {
}

}
108 changes: 98 additions & 10 deletions Svc/PolyDb/PolyDb.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,105 @@
// ======================================================================
// PolyDb.hpp
// Standardization header for PolyDb
// ======================================================================
/**
* \file
* \author T. Canham
* \brief PolyDb is a database for storing telemetry for internal software use
*
* \copyright
* Copyright 2009-2015, by the California Institute of Technology.
* ALL RIGHTS RESERVED. United States Government Sponsorship
* acknowledged.
* <br /><br />
*/
#ifndef POLYDB_HPP_
#define POLYDB_HPP_

#ifndef Svc_PolyDb_HPP
#define Svc_PolyDb_HPP

#include "Svc/PolyDb/PolyDbImpl.hpp"
#include <Svc/PolyDb/PolyDbComponentAc.hpp>
#include <Fw/Types/PolyType.hpp>

namespace Svc {

typedef PolyDbImpl PolyDb;
//! \class PolyDb
//! \brief PolyDb Component Class
//!
//! This component allows the setting and retrieving of PolyType
//! telemetry values. It be used as a central analog database
//! that can decouple measurement sources from measurement users.
//! The intent is that measurement sources would convert DNs (data numbers)
//! to ENs (Engineering Numbers) to decouple the conversion as well.
//!

class PolyDb : public PolyDbComponentBase {
public:
//! \brief PolyDbImpl constructor
//!
//! The constructor initializes the database to "MeasurementStatus::STALE."
//! All values retrieved will have this status until the first
//! update is received.
//!

explicit PolyDb(const char* const name);

//! \brief PolyDbImpl destructor
//!
//! The destructor is empty.
//!

virtual ~PolyDb();
protected:
private:

//! \brief The value getter port handler
//!
//! The getter port handler looks up the indicated entry
//! in the database and copies the contents into the user
//! supplied arguments status, time, and val.
//!
//! \param portNum port number of request (always 0)
//! \param entry entry to retrieve
//! \param status last status of retrieved measurement
//! \param time time tag of latest measurement
//! \param val value of latest measurement

void getValue_handler(
NATIVE_INT_TYPE portNum, //!< The port number
const Svc::PolyDbCfg::PolyDbEntry& entry, //!< The entry to access
Svc::MeasurementStatus& status, //!< The command response argument
Fw::Time& time, //!< The time of the measurement
Fw::PolyType& val //!< The value to be passed
) override;

//! \brief The value setter port handler
//!
//! The setter port handler takes the values passed
//! and updates the entry in the database
//!
//! \param portNum port number of request (always 0)
//! \param entry entry to retrieve
//! \param status status of new measurement
//! \param time time tag of new measurement
//! \param val value of new measurement

void setValue_handler(
NATIVE_INT_TYPE portNum, //!< The port number
const Svc::PolyDbCfg::PolyDbEntry& entry, //!< The entry to access
Svc::MeasurementStatus& status, //!< The command response argument
Fw::Time& time, //!< The time of the measurement
Fw::PolyType& val //!< The value to be passed
) override;

//! \struct t_dbStruct
//! \brief PolyDb database structure
//!
//! This structure stores the latest values of the measurements.
//! The statuses are all initialized to MeasurementStatus::STALE by the constructor.
//!

struct t_dbStruct {
MeasurementStatus status; //!< last status of measurement
Fw::PolyType val; //!< the last value of the measurement
Fw::Time time; //!< the timetag of the last measurement
} m_db[Svc::PolyDbCfg::PolyDbEntry::NUM_CONSTANTS];

};
}

#endif
#endif /* POLYDB_HPP_ */
44 changes: 0 additions & 44 deletions Svc/PolyDb/PolyDbImpl.cpp

This file was deleted.

100 changes: 0 additions & 100 deletions Svc/PolyDb/PolyDbImpl.hpp

This file was deleted.

12 changes: 8 additions & 4 deletions Svc/PolyDb/docs/sdd.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The `Svc::PolyDb` component has the following component diagram:

#### 3.1.2 Ports

The Svc::RateGroupDriver component uses the following port types:
The Svc::PolyDb component uses the following port types:

Port Data Type | Name | Direction | Kind | Usage
-------------- | ---- | --------- | ---- | -----
Expand All @@ -37,15 +37,19 @@ Port Data Type | Name | Direction | Kind | Usage

#### 3.2 Functional Description

`Fw::PolyType` is different from binary telemetry in that it is not in a serialized form, but is stored as the native type.
The component stores a table of `Fw::PolyType' objects which are read and written by table index.
`Fw::PolyType` is different from binary telemetry in that it is not in a serialized form, but is stored as the native type.
The component stores a table of `Fw::PolyType' objects which are read and written by a table index enumeration.
The table is protected by a mutex to prevent simultaneous access.

Users can customize the index name by modifying the `config/PolyDbCfg.fpp` file in their own configuration directory.

Note that users should understand how the `Fw::PolyType` works to avoid asserts when reading a different type than was written. To avoid asserts, user code can verify the expected type matches by calling the correct `isXX()` function before trying to read the value out. The `PolyDb` will not assert on the read or write of a `Fw::PolyType` if there is a type mismatch. This only happens when trying to read out the value stored in the `Fw::PolyType`.

### 3.3 Scenarios

#### 3.3.1 Read and Write Values

As described in the Functional Description section, the RateGroupDriver component accepts calls to the SchedIn and divides them down to the SchedOut ports:
The following diagram shows how components can share a value by having one component write the value, and the other read it:

![Read and Write Values](img/PolyDbReadWriteScenario.jpg)

Expand Down
Loading

0 comments on commit 00eed9f

Please sign in to comment.