fsfw/src/fsfw/datapool/Dataset.h

183 lines
4.6 KiB
C++

#pragma once
#include <fsfw/housekeeping/HousekeepingSet.h>
#include <fsfw/introspection/Enum.h>
#include <fsfw/ipc/MutexIF.h>
#include <fsfw/returnvalues/returnvalue.h>
#include <fsfw/storagemanager/storeAddress.h>
#include <stdint.h>
#include <vector>
#include "DatasetEntryIF.h"
// TODO ring inclusion
// #include "HasDatapoolIF.h"
class HasDatapoolIF;
// TODO allow user commit and reporting TM
/**
* This class has a dual use
*
* 1) It is used as an IPC method:
* It implements a shared memory which can be written and read by different parties
*
* 2) It is used to define data that is to be downlinked, either periodically or
* triggered by an (abstract, not in the sense of fsfw/events) event occuring, ie
* data was received from an external source and should be shared with ground.
*
* Generating a downlinked report is coupled to commiting, as without a commit there is no
* change in information to be reported.
*
* Nominally, the decision to report is done by the set itself, depending on its settings.
* If a report is to be forced regardless of these settings, the commitAndReport() functions
* are provided which will always generate a report.
*
* Periodic reports are not tied to a specific tc and are reported as "unrequested". When forcing
* a report, optionally a tc can be provided which (logically) triggered the report.
*
* And, as life is complicated, there is a third set of commits: commitAndReportIfRequested(). Same
* as before, but this time, a report is only generated, if the store_address_t is valid. These are
* used if at the place where the commit is called, it is not known if there is a request (cf DHB
* interpretDeviceReply)
*/
class Dataset : public HousekeepingSet {
protected:
#ifdef FSFW_INTROSPECTION
Dataset(HasDatapoolIF* owner, const EnumIF &id, bool allowUserCommit);
Dataset(uint32_t owner_id, const EnumIF &id);
#else
Dataset(HasDatapoolIF* owner, HousekeepingSetId_t id, bool allowUserCommit);
Dataset(uint32_t owner_id, HousekeepingSetId_t id);
#endif
public:
~Dataset() override;
/**
* Copy content of local copies into actual variable
*
*/
void commit();
/**
* Copy content of local copies into actual variable
*
* calls setValid(valid) before committing
*
*/
void commit(bool valid);
/**
* Copy content of local copies into actual variable
* Force sending of TM packet
*
*/
void commitAndReport();
/**
* Copy content of local copies into actual variable
* Force sending of TM packet
*
* calls setValid(valid) before committing
*
*/
void commitAndReport(bool valid);
/**
* Copy content of local copies into actual variable
* Force sending of TM packet, in reference to tc
*
*/
void commitAndReport(store_address_t tc, size_t tc_offset);
/**
* Copy content of local copies into actual variable
* Force sending of TM packet, in reference to tc
*
* calls setValid(valid) before committing
*
*/
void commitAndReport(bool valid, store_address_t tc, size_t tc_offset);
/**
* Copy content of local copies into actual variable
* Force sending of TM packet, in reference to tc, if tc is valid
*
*/
void commitAndReportIfRequested(store_address_t tc, size_t tc_offset);
/**
* Copy content of local copies into actual variable
* Force sending of TM packet, in reference to tc, if tc is valid
*
* calls setValid(valid) before committing
*
*/
void commitAndReportIfRequested(bool valid, store_address_t tc, size_t tc_offset);
/**
* set all contained variables to #valid
*
*/
void setAllValid(bool valid);
/**
* Copy content of actual variables into local copies
*
*
*/
void read();
/**
* returns true if local copies and actual variables differ
*
* implicitely calls read()
*/
bool hasChanged();
/**
* returns true if local copies and actual variables differ
* or time since last time true has been returned is greater than
* supplied time
*
* implicitely calls read()
*
*/
bool hasChangedOrOlderThan(uint32_t seconds);
/**
* get List of contained Valiables
*/
virtual const std::vector<DatasetEntryIF*>* getVariables() const;
ReturnValue_t initialize();
// operator[]
bool registerEntry(DatasetEntryIF*);
protected:
bool allocated;
bool allowUserCommit;
union {
object_id_t id;
HasDatapoolIF* pointer;
} owner;
MutexIF* mutex;
std::vector<DatasetEntryIF*> variables;
/**
* lock the mutex of the set
*/
void lock();
/**
* unlock the mutex of the set
*/
void unlock();
bool hasChangedNoRead();
};