fsfw/datapoollocal/LocalPoolDataSetBase.h

199 lines
6.6 KiB
C
Raw Normal View History

2020-09-05 21:59:17 +02:00
#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLDATASETBASE_H_
#define FSFW_DATAPOOLLOCAL_LOCALPOOLDATASETBASE_H_
#include "HasLocalDataPoolIF.h"
2020-10-14 12:42:30 +02:00
#include "MarkChangedIF.h"
#include "../datapool/DataSetIF.h"
#include "../datapool/PoolDataSetBase.h"
#include "../serialize/SerializeIF.h"
2020-07-14 15:45:03 +02:00
#include <vector>
class LocalDataPoolManager;
2020-09-19 15:58:34 +02:00
class PeriodicHousekeepingHelper;
2020-07-14 15:45:03 +02:00
/**
* @brief The LocalDataSet class manages a set of locally checked out
* variables for local data pools
* @details
2020-09-28 21:28:03 +02:00
* Extends the PoolDataSetBase class for local data pools by introducing
* a validity state, a flag to mark the set as changed, and various other
* functions to make it usable by the LocalDataPoolManager class.
*
2020-07-14 15:45:03 +02:00
* This class manages a list, where a set of local variables (or pool variables)
* are registered. They are checked-out (i.e. their values are looked
* up and copied) with the read call. After the user finishes working with the
* pool variables, he can write back all variable values to the pool with
2020-09-28 21:28:03 +02:00
* the commit call. The data set manages locking and freeing the local data
* pools, to ensure thread-safety.
*
* Pool variables can be added to the dataset by using the constructor
* argument of the pool variable or using the #registerVariable member function.
2020-07-14 15:45:03 +02:00
*
* An internal state manages usage of this class. Variables may only be
2020-09-28 21:28:03 +02:00
* registered before any read call is made, and the commit call can only happen
2020-07-14 15:45:03 +02:00
* after the read call.
*
* If pool variables are writable and not committed until destruction
* of the set, the DataSet class automatically sets the valid flag in the
* data pool to invalid (without) changing the variable's value.
*
* @ingroup data_pool
*/
2020-10-14 12:42:30 +02:00
class LocalPoolDataSetBase: public PoolDataSetBase,
public MarkChangedIF {
2020-09-19 01:17:43 +02:00
friend class LocalDataPoolManager;
2020-09-19 02:46:29 +02:00
friend class PeriodicHousekeepingHelper;
2020-07-14 15:45:03 +02:00
public:
/**
* @brief Constructor for the creator of local pool data.
2020-09-19 15:58:34 +02:00
* @details
* This constructor also initializes the components required for
* periodic handling.
2020-07-14 15:45:03 +02:00
*/
2020-08-08 12:51:31 +02:00
LocalPoolDataSetBase(HasLocalDataPoolIF *hkOwner,
2020-08-23 22:33:22 +02:00
uint32_t setId, PoolVariableIF** registeredVariablesArray,
const size_t maxNumberOfVariables, bool noPeriodicHandling = false);
2020-07-14 15:45:03 +02:00
/**
2020-09-19 15:58:34 +02:00
* @brief Constructor for users of local pool data.
2020-07-16 11:45:23 +02:00
* @details
2020-08-23 22:33:22 +02:00
* @param sid Unique identifier of dataset consisting of object ID and
* set ID.
* @param registeredVariablesArray
* @param maxNumberOfVariables
2020-07-14 15:45:03 +02:00
*/
2020-08-23 22:33:22 +02:00
LocalPoolDataSetBase(sid_t sid, PoolVariableIF** registeredVariablesArray,
2020-07-14 15:45:03 +02:00
const size_t maxNumberOfVariables);
/**
* @brief The destructor automatically manages writing the valid
* information of variables.
* @details
* In case the data set was read out, but not committed(indicated by state),
* the destructor parses all variables that are still registered to the set.
* For each, the valid flag in the data pool is set to "invalid".
*/
2020-08-08 12:51:31 +02:00
~LocalPoolDataSetBase();
2020-07-14 15:45:03 +02:00
2020-08-08 21:32:15 +02:00
void setValidityBufferGeneration(bool withValidityBuffer);
2020-09-19 15:58:34 +02:00
sid_t getSid() const;
2020-09-28 21:28:03 +02:00
/** SerializeIF overrides */
2020-08-08 21:32:15 +02:00
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
SerializeIF::Endianness streamEndianness) const override;
ReturnValue_t deSerialize(const uint8_t** buffer, size_t *size,
SerializeIF::Endianness streamEndianness) override;
size_t getSerializedSize() const override;
2020-07-14 15:45:03 +02:00
/**
* Special version of the serilization function which appends a
* validity buffer at the end. Each bit of this validity buffer
* denotes whether the container data set entries are valid from left
2020-09-28 21:28:03 +02:00
* to right, MSB first. (length = ceil(N/8), N = number of pool variables)
2020-07-14 15:45:03 +02:00
* @param buffer
* @param size
* @param maxSize
* @param bigEndian
* @param withValidityBuffer
* @return
*/
ReturnValue_t serializeWithValidityBuffer(uint8_t** buffer,
size_t* size, size_t maxSize,
SerializeIF::Endianness streamEndianness) const;
2020-08-08 21:32:15 +02:00
ReturnValue_t deSerializeWithValidityBuffer(const uint8_t** buffer,
size_t *size, SerializeIF::Endianness streamEndianness);
2020-07-14 15:45:03 +02:00
ReturnValue_t serializeLocalPoolIds(uint8_t** buffer,
size_t* size, size_t maxSize,
2020-09-28 21:09:56 +02:00
SerializeIF::Endianness streamEndianness,
bool serializeFillCount = true) const;
uint8_t getLocalPoolIdsSerializedSize(bool serializeFillCount = true) const;
2020-07-14 15:45:03 +02:00
2020-09-10 21:05:50 +02:00
/**
2020-10-14 12:42:30 +02:00
* Set the dataset valid or invalid. These calls are mutex protected.
2020-09-10 21:05:50 +02:00
* @param setEntriesRecursively
* If this is true, all contained datasets will also be set recursively.
*/
void setValidity(bool valid, bool setEntriesRecursively);
2020-07-14 15:45:03 +02:00
bool isValid() const override;
2020-10-14 12:42:30 +02:00
/**
* These calls are mutex protected.
* @param changed
*/
void setChanged(bool changed) override;
bool hasChanged() const override;
2020-09-19 15:58:34 +02:00
2020-07-14 15:45:03 +02:00
protected:
2020-08-23 22:33:22 +02:00
sid_t sid;
2020-10-14 12:42:30 +02:00
MutexIF* mutex = nullptr;
2020-09-19 01:17:43 +02:00
2020-09-19 15:58:34 +02:00
bool diagnostic = false;
void setDiagnostic(bool diagnostics);
bool isDiagnostics() const;
2020-09-19 01:17:43 +02:00
/**
* Used for periodic generation.
*/
2020-09-19 02:46:29 +02:00
bool reportingEnabled = false;
void setReportingEnabled(bool enabled);
bool getReportingEnabled() const;
2020-09-19 01:17:43 +02:00
2020-09-19 15:58:34 +02:00
void initializePeriodicHelper(float collectionInterval,
dur_millis_t minimumPeriodicInterval,
bool isDiagnostics, uint8_t nonDiagIntervalFactor = 5);
2020-07-14 15:45:03 +02:00
/**
* If the valid state of a dataset is always relevant to the whole
* data set we can use this flag.
*/
bool valid = false;
2020-09-19 15:58:34 +02:00
/**
* Can be used to mark the dataset as changed, which is used
* by the LocalDataPoolManager to send out update messages.
*/
bool changed = false;
2020-09-28 21:28:03 +02:00
/**
* Specify whether the validity buffer is serialized too when serializing
* or deserializing the packet. Each bit of the validity buffer will
* contain the validity state of the pool variables from left to right.
* The size of validity buffer thus will be ceil(N / 8) with N = number of
* pool variables.
*/
2020-08-08 21:32:15 +02:00
bool withValidityBuffer = true;
2020-07-14 15:45:03 +02:00
/**
* @brief This is a small helper function to facilitate locking
* the global data pool.
* @details
* It makes use of the lockDataPool method offered by the DataPool class.
*/
ReturnValue_t lockDataPool(uint32_t timeoutMs) override;
/**
* @brief This is a small helper function to facilitate
* unlocking the global data pool
* @details
* It makes use of the freeDataPoolLock method offered by the DataPool class.
*/
ReturnValue_t unlockDataPool() override;
LocalDataPoolManager* hkManager;
/**
* Set n-th bit of a byte, with n being the position from 0
* (most significant bit) to 7 (least significant bit)
*/
void bitSetter(uint8_t* byte, uint8_t position) const;
2020-08-08 21:32:15 +02:00
bool bitGetter(const uint8_t* byte, uint8_t position) const;
2020-09-19 15:58:34 +02:00
2020-09-19 02:46:29 +02:00
PeriodicHousekeepingHelper* periodicHelper = nullptr;
2020-07-14 15:45:03 +02:00
};
2020-09-10 21:05:50 +02:00
2020-09-05 21:59:17 +02:00
#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLDATASETBASE_H_ */