Merge remote-tracking branch 'upstream/development' into mueller/hosted-osal-fixes
This commit is contained in:
commit
0585ef9051
@ -8,7 +8,9 @@
|
||||
*/
|
||||
template<typename T, size_t MAX_SIZE, typename count_t = uint8_t>
|
||||
class FixedArrayList: public ArrayList<T, count_t> {
|
||||
static_assert(MAX_SIZE <= (pow(2,sizeof(count_t)*8)-1), "count_t is not large enough to hold MAX_SIZE");
|
||||
#if !defined(_MSC_VER)
|
||||
static_assert(MAX_SIZE <= (std::pow(2,sizeof(count_t)*8)-1), "count_t is not large enough to hold MAX_SIZE");
|
||||
#endif
|
||||
private:
|
||||
T data[MAX_SIZE];
|
||||
public:
|
||||
|
@ -17,14 +17,6 @@ ReturnValue_t ExtendedControllerBase::executeAction(ActionId_t actionId,
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ReturnValue_t ExtendedControllerBase::initializeLocalDataPool(
|
||||
localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) {
|
||||
/* Needs to be overriden and implemented by child class. */
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
object_id_t ExtendedControllerBase::getObjectId() const {
|
||||
return SystemObject::getObjectId();
|
||||
}
|
||||
@ -107,14 +99,6 @@ MessageQueueId_t ExtendedControllerBase::getCommandQueue() const {
|
||||
return commandQueue->getId();
|
||||
}
|
||||
|
||||
LocalPoolDataSetBase* ExtendedControllerBase::getDataSetHandle(sid_t sid) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "ExtendedControllerBase::getDataSetHandle: No child "
|
||||
<< " implementation provided, returning nullptr!" << std::endl;
|
||||
#endif
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
LocalDataPoolManager* ExtendedControllerBase::getHkManagerHandle() {
|
||||
return &poolManager;
|
||||
}
|
||||
|
@ -61,11 +61,11 @@ protected:
|
||||
/* HasLocalDatapoolIF overrides */
|
||||
virtual LocalDataPoolManager* getHkManagerHandle() override;
|
||||
virtual object_id_t getObjectId() const override;
|
||||
virtual ReturnValue_t initializeLocalDataPool(
|
||||
localpool::DataPool& localDataPoolMap,
|
||||
LocalDataPoolManager& poolManager) override;
|
||||
virtual uint32_t getPeriodicOperationFrequency() const override;
|
||||
virtual LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override;
|
||||
|
||||
virtual ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
LocalDataPoolManager& poolManager) override = 0;
|
||||
virtual LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override = 0;
|
||||
};
|
||||
|
||||
|
||||
|
@ -8,13 +8,16 @@
|
||||
PoolDataSetBase::PoolDataSetBase(PoolVariableIF** registeredVariablesArray,
|
||||
const size_t maxFillCount):
|
||||
registeredVariables(registeredVariablesArray),
|
||||
maxFillCount(maxFillCount) {
|
||||
}
|
||||
maxFillCount(maxFillCount) {}
|
||||
|
||||
PoolDataSetBase::~PoolDataSetBase() {}
|
||||
|
||||
|
||||
ReturnValue_t PoolDataSetBase::registerVariable(PoolVariableIF *variable) {
|
||||
if(registeredVariables == nullptr) {
|
||||
/* Underlying container invalid */
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
if (state != States::STATE_SET_UNINITIALISED) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "DataSet::registerVariable: Call made in wrong position." << std::endl;
|
||||
|
@ -9,8 +9,8 @@
|
||||
* and unlock a data pool and read/commit semantics.
|
||||
*/
|
||||
class PoolDataSetIF:
|
||||
public DataSetIF,
|
||||
public ReadCommitIF {
|
||||
virtual public DataSetIF,
|
||||
virtual public ReadCommitIF {
|
||||
public:
|
||||
virtual~ PoolDataSetIF() {};
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
template <typename T>
|
||||
PoolEntry<T>::PoolEntry(std::initializer_list<T> initValue, bool setValid ):
|
||||
length(initValue.size()), valid(setValid) {
|
||||
length(static_cast<uint8_t>(initValue.size())), valid(setValid) {
|
||||
this->address = new T[this->length];
|
||||
if(initValue.size() == 0) {
|
||||
std::memset(this->address, 0, this->getByteSize());
|
||||
|
@ -1,13 +1,15 @@
|
||||
#ifndef FRAMEWORK_DATAPOOL_SHAREDDATASETIF_H_
|
||||
#define FRAMEWORK_DATAPOOL_SHAREDDATASETIF_H_
|
||||
|
||||
#include "PoolDataSetIF.h"
|
||||
|
||||
class SharedDataSetIF: public PoolDataSetIF {
|
||||
class SharedDataSetIF {
|
||||
public:
|
||||
virtual ~SharedDataSetIF() {};
|
||||
|
||||
private:
|
||||
virtual ReturnValue_t lockDataset(dur_millis_t mutexTimeout) = 0;
|
||||
virtual ReturnValue_t lockDataset(MutexIF::TimeoutType timeoutType,
|
||||
dur_millis_t mutexTimeout) = 0;
|
||||
virtual ReturnValue_t unlockDataset() = 0;
|
||||
};
|
||||
|
||||
|
@ -65,34 +65,45 @@ public:
|
||||
* usually be the period the pool owner performs its periodic operation.
|
||||
* @return
|
||||
*/
|
||||
virtual uint32_t getPeriodicOperationFrequency() const = 0;
|
||||
virtual dur_millis_t getPeriodicOperationFrequency() const = 0;
|
||||
|
||||
/**
|
||||
* @brief This function will be called by the manager if an update
|
||||
* notification is received.
|
||||
* @details HasLocalDataPoolIF
|
||||
* Can be overriden by the child class to handle changed datasets.
|
||||
* @param sid
|
||||
* @param storeId If a snapshot was requested, data will be located inside
|
||||
* @param sid SID of the updated set
|
||||
* @param storeId If a snapshot was requested, data will be located inside
|
||||
* the IPC store with this store ID.
|
||||
* @param clearMessage If this is set to true, the pool manager will take care of
|
||||
* clearing the store automatically
|
||||
*/
|
||||
virtual void handleChangedDataset(sid_t sid,
|
||||
store_address_t storeId = storeId::INVALID_STORE_ADDRESS) {
|
||||
return;
|
||||
store_address_t storeId = storeId::INVALID_STORE_ADDRESS,
|
||||
bool* clearMessage = nullptr) {
|
||||
if(clearMessage != nullptr) {
|
||||
*clearMessage = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function will be called by the manager if an update
|
||||
* notification is received.
|
||||
* @details
|
||||
* Can be overriden by the child class to handle changed pool IDs.
|
||||
* @param sid
|
||||
* @param storeId If a snapshot was requested, data will be located inside
|
||||
* Can be overriden by the child class to handle changed pool variables.
|
||||
* @param gpid GPID of the updated variable.
|
||||
* @param storeId If a snapshot was requested, data will be located inside
|
||||
* the IPC store with this store ID.
|
||||
* @param clearMessage Relevant for snapshots. If the boolean this points to is set to true,
|
||||
* the pool manager will take care of clearing the store automatically
|
||||
* after the callback.
|
||||
*/
|
||||
virtual void handleChangedPoolVariable(gp_id_t globPoolId,
|
||||
store_address_t storeId = storeId::INVALID_STORE_ADDRESS) {
|
||||
return;
|
||||
virtual void handleChangedPoolVariable(gp_id_t gpid,
|
||||
store_address_t storeId = storeId::INVALID_STORE_ADDRESS,
|
||||
bool* clearMessage = nullptr) {
|
||||
if(clearMessage != nullptr) {
|
||||
*clearMessage = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,7 +38,11 @@ LocalDataPoolManager::LocalDataPoolManager(HasLocalDataPoolIF* owner, MessageQue
|
||||
hkQueue = queueToUse;
|
||||
}
|
||||
|
||||
LocalDataPoolManager::~LocalDataPoolManager() {}
|
||||
LocalDataPoolManager::~LocalDataPoolManager() {
|
||||
if(mutex != nullptr) {
|
||||
MutexFactory::instance()->deleteMutex(mutex);
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::initialize(MessageQueueIF* queueToUse) {
|
||||
if(queueToUse == nullptr) {
|
||||
@ -132,13 +136,16 @@ ReturnValue_t LocalDataPoolManager::performHkOperation() {
|
||||
ReturnValue_t LocalDataPoolManager::handleHkUpdate(HkReceiver& receiver,
|
||||
ReturnValue_t& status) {
|
||||
if(receiver.dataType == DataType::LOCAL_POOL_VARIABLE) {
|
||||
// Update packets shall only be generated from datasets.
|
||||
/* Update packets shall only be generated from datasets. */
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner,
|
||||
receiver.dataId.sid);
|
||||
if(dataSet == nullptr) {
|
||||
return DATASET_NOT_FOUND;
|
||||
}
|
||||
if(dataSet->hasChanged()) {
|
||||
// prepare and send update notification
|
||||
/* Prepare and send update notification */
|
||||
ReturnValue_t result = generateHousekeepingPacket(
|
||||
receiver.dataId.sid, dataSet, true);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
@ -328,7 +335,7 @@ void LocalDataPoolManager::handleChangeResetLogic(
|
||||
toReset->setChanged(false);
|
||||
}
|
||||
/* All recipients have been notified, reset the changed flag */
|
||||
if(changeInfo.currentUpdateCounter <= 1) {
|
||||
else if(changeInfo.currentUpdateCounter <= 1) {
|
||||
toReset->setChanged(false);
|
||||
changeInfo.currentUpdateCounter = 0;
|
||||
}
|
||||
@ -372,7 +379,7 @@ ReturnValue_t LocalDataPoolManager::subscribeForPeriodicPacket(sid_t sid,
|
||||
LocalPoolDataSetAttorney::setReportingEnabled(*dataSet, enableReporting);
|
||||
LocalPoolDataSetAttorney::setDiagnostic(*dataSet, isDiagnostics);
|
||||
LocalPoolDataSetAttorney::initializePeriodicHelper(*dataSet, collectionInterval,
|
||||
owner->getPeriodicOperationFrequency(), isDiagnostics);
|
||||
owner->getPeriodicOperationFrequency());
|
||||
}
|
||||
|
||||
hkReceivers.push_back(hkReceiver);
|
||||
@ -398,7 +405,6 @@ ReturnValue_t LocalDataPoolManager::subscribeForUpdatePacket(sid_t sid,
|
||||
hkReceiver.destinationQueue = hkReceiverObject->getHkQueue();
|
||||
|
||||
LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, sid);
|
||||
//LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid);
|
||||
if(dataSet != nullptr) {
|
||||
LocalPoolDataSetAttorney::setReportingEnabled(*dataSet, true);
|
||||
LocalPoolDataSetAttorney::setDiagnostic(*dataSet, isDiagnostics);
|
||||
@ -516,11 +522,19 @@ ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage(
|
||||
}
|
||||
|
||||
case(HousekeepingMessage::REPORT_DIAGNOSTICS_REPORT_STRUCTURES): {
|
||||
return generateSetStructurePacket(sid, true);
|
||||
result = generateSetStructurePacket(sid, true);
|
||||
if(result == HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case(HousekeepingMessage::REPORT_HK_REPORT_STRUCTURES): {
|
||||
return generateSetStructurePacket(sid, false);
|
||||
result = generateSetStructurePacket(sid, false);
|
||||
if(result == HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case(HousekeepingMessage::MODIFY_DIAGNOSTICS_REPORT_COLLECTION_INTERVAL):
|
||||
case(HousekeepingMessage::MODIFY_PARAMETER_REPORT_COLLECTION_INTERVAL): {
|
||||
@ -540,14 +554,15 @@ ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage(
|
||||
case(HousekeepingMessage::GENERATE_ONE_PARAMETER_REPORT):
|
||||
case(HousekeepingMessage::GENERATE_ONE_DIAGNOSTICS_REPORT): {
|
||||
LocalPoolDataSetBase* dataSet =HasLocalDpIFManagerAttorney::getDataSetHandle(owner, sid);
|
||||
//LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid);
|
||||
if(command == HousekeepingMessage::GENERATE_ONE_PARAMETER_REPORT
|
||||
and LocalPoolDataSetAttorney::isDiagnostics(*dataSet)) {
|
||||
return WRONG_HK_PACKET_TYPE;
|
||||
result = WRONG_HK_PACKET_TYPE;
|
||||
break;
|
||||
}
|
||||
else if(command == HousekeepingMessage::GENERATE_ONE_DIAGNOSTICS_REPORT
|
||||
and not LocalPoolDataSetAttorney::isDiagnostics(*dataSet)) {
|
||||
return WRONG_HK_PACKET_TYPE;
|
||||
result = WRONG_HK_PACKET_TYPE;
|
||||
break;
|
||||
}
|
||||
return generateHousekeepingPacket(HousekeepingMessage::getSid(message),
|
||||
dataSet, true);
|
||||
@ -566,14 +581,22 @@ ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage(
|
||||
case(HousekeepingMessage::UPDATE_SNAPSHOT_SET): {
|
||||
store_address_t storeId;
|
||||
HousekeepingMessage::getUpdateSnapshotSetCommand(message, &storeId);
|
||||
owner->handleChangedDataset(sid, storeId);
|
||||
bool clearMessage = true;
|
||||
owner->handleChangedDataset(sid, storeId, &clearMessage);
|
||||
if(clearMessage) {
|
||||
message->clear();
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
case(HousekeepingMessage::UPDATE_SNAPSHOT_VARIABLE): {
|
||||
store_address_t storeId;
|
||||
gp_id_t globPoolId = HousekeepingMessage::getUpdateSnapshotVariableCommand(message,
|
||||
&storeId);
|
||||
owner->handleChangedPoolVariable(globPoolId, storeId);
|
||||
bool clearMessage = true;
|
||||
owner->handleChangedPoolVariable(globPoolId, storeId, &clearMessage);
|
||||
if(clearMessage) {
|
||||
message->clear();
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
@ -616,7 +639,7 @@ ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid,
|
||||
LocalPoolDataSetBase* dataSet, bool forDownlink,
|
||||
MessageQueueId_t destination) {
|
||||
if(dataSet == nullptr) {
|
||||
// Configuration error.
|
||||
/* Configuration error. */
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING,
|
||||
"generateHousekeepingPacket",
|
||||
DATASET_NOT_FOUND);
|
||||
@ -632,7 +655,7 @@ ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid,
|
||||
return result;
|
||||
}
|
||||
|
||||
// and now we set a HK message and send it the HK packet destination.
|
||||
/* Now we set a HK message and send it the HK packet destination. */
|
||||
CommandMessage hkMessage;
|
||||
if(LocalPoolDataSetAttorney::isDiagnostics(*dataSet)) {
|
||||
HousekeepingMessage::setHkDiagnosticsReply(&hkMessage, sid, storeId);
|
||||
@ -642,7 +665,7 @@ ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid,
|
||||
}
|
||||
|
||||
if(hkQueue == nullptr) {
|
||||
// error, no queue available to send packet with.
|
||||
/* Error, no queue available to send packet with. */
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING,
|
||||
"generateHousekeepingPacket",
|
||||
QUEUE_OR_DESTINATION_INVALID);
|
||||
@ -650,7 +673,7 @@ ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid,
|
||||
}
|
||||
if(destination == MessageQueueIF::NO_QUEUE) {
|
||||
if(hkDestinationId == MessageQueueIF::NO_QUEUE) {
|
||||
// error, all destinations invalid
|
||||
/* Error, all destinations invalid */
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING,
|
||||
"generateHousekeepingPacket",
|
||||
QUEUE_OR_DESTINATION_INVALID);
|
||||
@ -729,6 +752,12 @@ void LocalDataPoolManager::performPeriodicHkGeneration(HkReceiver& receiver) {
|
||||
ReturnValue_t LocalDataPoolManager::togglePeriodicGeneration(sid_t sid,
|
||||
bool enable, bool isDiagnostics) {
|
||||
LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, sid);
|
||||
if(dataSet == nullptr) {
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING, "togglePeriodicGeneration",
|
||||
DATASET_NOT_FOUND);
|
||||
return DATASET_NOT_FOUND;
|
||||
}
|
||||
|
||||
if((LocalPoolDataSetAttorney::isDiagnostics(*dataSet) and not isDiagnostics) or
|
||||
(not LocalPoolDataSetAttorney::isDiagnostics(*dataSet) and isDiagnostics)) {
|
||||
return WRONG_HK_PACKET_TYPE;
|
||||
@ -746,6 +775,12 @@ ReturnValue_t LocalDataPoolManager::togglePeriodicGeneration(sid_t sid,
|
||||
ReturnValue_t LocalDataPoolManager::changeCollectionInterval(sid_t sid,
|
||||
float newCollectionInterval, bool isDiagnostics) {
|
||||
LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, sid);
|
||||
if(dataSet == nullptr) {
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING, "changeCollectionInterval",
|
||||
DATASET_NOT_FOUND);
|
||||
return DATASET_NOT_FOUND;
|
||||
}
|
||||
|
||||
bool targetIsDiagnostics = LocalPoolDataSetAttorney::isDiagnostics(*dataSet);
|
||||
if((targetIsDiagnostics and not isDiagnostics) or
|
||||
(not targetIsDiagnostics and isDiagnostics)) {
|
||||
@ -756,7 +791,7 @@ ReturnValue_t LocalDataPoolManager::changeCollectionInterval(sid_t sid,
|
||||
LocalPoolDataSetAttorney::getPeriodicHelper(*dataSet);
|
||||
|
||||
if(periodicHelper == nullptr) {
|
||||
// config error
|
||||
/* Configuration error, set might not have a corresponding pool manager */
|
||||
return PERIODIC_HELPER_INVALID;
|
||||
}
|
||||
|
||||
@ -766,13 +801,11 @@ ReturnValue_t LocalDataPoolManager::changeCollectionInterval(sid_t sid,
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::generateSetStructurePacket(sid_t sid,
|
||||
bool isDiagnostics) {
|
||||
// Get and check dataset first.
|
||||
//LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid);
|
||||
/* Get and check dataset first. */
|
||||
LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, sid);
|
||||
if(dataSet == nullptr) {
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING,
|
||||
"performPeriodicHkGeneration",
|
||||
DATASET_NOT_FOUND);
|
||||
"performPeriodicHkGeneration", DATASET_NOT_FOUND);
|
||||
return DATASET_NOT_FOUND;
|
||||
}
|
||||
|
||||
@ -831,6 +864,10 @@ ReturnValue_t LocalDataPoolManager::generateSetStructurePacket(sid_t sid,
|
||||
void LocalDataPoolManager::clearReceiversList() {
|
||||
/* Clear the vector completely and releases allocated memory. */
|
||||
HkReceivers().swap(hkReceivers);
|
||||
/* Also clear the reset helper if it exists */
|
||||
if(hkUpdateResetList != nullptr) {
|
||||
HkUpdateResetList().swap(*hkUpdateResetList);
|
||||
}
|
||||
}
|
||||
|
||||
MutexIF* LocalDataPoolManager::getLocalPoolMutex() {
|
||||
@ -843,6 +880,7 @@ object_id_t LocalDataPoolManager::getCreatorObjectId() const {
|
||||
|
||||
void LocalDataPoolManager::printWarningOrError(sif::OutputTypes outputType,
|
||||
const char* functionName, ReturnValue_t error, const char* errorPrint) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
if(errorPrint == nullptr) {
|
||||
if(error == DATASET_NOT_FOUND) {
|
||||
errorPrint = "Dataset not found";
|
||||
@ -873,7 +911,6 @@ void LocalDataPoolManager::printWarningOrError(sif::OutputTypes outputType,
|
||||
}
|
||||
|
||||
if(outputType == sif::OutputTypes::OUT_WARNING) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "LocalDataPoolManager::" << functionName
|
||||
<< ": Object ID 0x" << std::setw(8) << std::setfill('0')
|
||||
@ -883,10 +920,8 @@ void LocalDataPoolManager::printWarningOrError(sif::OutputTypes outputType,
|
||||
sif::printWarning("LocalDataPoolManager::%s: Object ID 0x%08x | %s\n",
|
||||
functionName, owner->getObjectId(), errorPrint);
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||
}
|
||||
else if(outputType == sif::OutputTypes::OUT_ERROR) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "LocalDataPoolManager::" << functionName
|
||||
<< ": Object ID 0x" << std::setw(8) << std::setfill('0')
|
||||
@ -896,8 +931,8 @@ void LocalDataPoolManager::printWarningOrError(sif::OutputTypes outputType,
|
||||
sif::printError("LocalDataPoolManager::%s: Object ID 0x%08x | %s\n",
|
||||
functionName, owner->getObjectId(), errorPrint);
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||
}
|
||||
#endif /* #if FSFW_VERBOSE_LEVEL >= 1 */
|
||||
}
|
||||
|
||||
LocalDataPoolManager* LocalDataPoolManager::getPoolManagerHandle() {
|
||||
|
@ -391,6 +391,10 @@ protected:
|
||||
|
||||
template<class T> inline
|
||||
ReturnValue_t LocalDataPoolManager::fetchPoolEntry(lp_id_t localPoolId, PoolEntry<T> **poolEntry) {
|
||||
if(poolEntry == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
auto poolIter = localPoolMap.find(localPoolId);
|
||||
if (poolIter == localPoolMap.end()) {
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING, "fetchPoolEntry",
|
||||
|
@ -44,7 +44,7 @@ LocalPoolDataSetBase::LocalPoolDataSetBase(HasLocalDataPoolIF *hkOwner,
|
||||
|
||||
LocalPoolDataSetBase::LocalPoolDataSetBase(sid_t sid, PoolVariableIF** registeredVariablesArray,
|
||||
const size_t maxNumberOfVariables):
|
||||
PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) {
|
||||
PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) {
|
||||
HasLocalDataPoolIF* hkOwner = objectManager->get<HasLocalDataPoolIF>(
|
||||
sid.objectId);
|
||||
if(hkOwner != nullptr) {
|
||||
@ -95,14 +95,23 @@ ReturnValue_t LocalPoolDataSetBase::serializeWithValidityBuffer(uint8_t **buffer
|
||||
size_t *size, size_t maxSize,
|
||||
SerializeIF::Endianness streamEndianness) const {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
uint8_t validityMaskSize = std::ceil(static_cast<float>(fillCount)/8.0);
|
||||
uint8_t validityMask[validityMaskSize] = {};
|
||||
const uint8_t validityMaskSize = std::ceil(static_cast<float>(fillCount)/8.0);
|
||||
uint8_t* validityPtr = nullptr;
|
||||
#ifdef _MSC_VER
|
||||
/* Use a std::vector here because MSVC will (rightly) not create a fixed size array
|
||||
with a non constant size specifier */
|
||||
std::vector<uint8_t> validityMask(validityMaskSize);
|
||||
validityPtr = validityMask.data();
|
||||
#else
|
||||
uint8_t validityMask[validityMaskSize];
|
||||
validityPtr = validityMask;
|
||||
#endif
|
||||
uint8_t validBufferIndex = 0;
|
||||
uint8_t validBufferIndexBit = 0;
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
if(registeredVariables[count]->isValid()) {
|
||||
/* Set bit at correct position */
|
||||
bitutil::bitSet(validityMask + validBufferIndex, validBufferIndexBit);
|
||||
bitutil::bitSet(validityPtr + validBufferIndex, validBufferIndexBit);
|
||||
}
|
||||
if(validBufferIndexBit == 7) {
|
||||
validBufferIndex ++;
|
||||
@ -123,7 +132,7 @@ ReturnValue_t LocalPoolDataSetBase::serializeWithValidityBuffer(uint8_t **buffer
|
||||
return SerializeIF::BUFFER_TOO_SHORT;
|
||||
}
|
||||
// copy validity buffer to end
|
||||
std::memcpy(*buffer, validityMask, validityMaskSize);
|
||||
std::memcpy(*buffer, validityPtr, validityMaskSize);
|
||||
*size += validityMaskSize;
|
||||
return result;
|
||||
}
|
||||
@ -262,11 +271,9 @@ bool LocalPoolDataSetBase::getReportingEnabled() const {
|
||||
return reportingEnabled;
|
||||
}
|
||||
|
||||
void LocalPoolDataSetBase::initializePeriodicHelper(
|
||||
float collectionInterval, dur_millis_t minimumPeriodicInterval,
|
||||
bool isDiagnostics, uint8_t nonDiagIntervalFactor) {
|
||||
periodicHelper->initialize(collectionInterval, minimumPeriodicInterval,
|
||||
isDiagnostics, nonDiagIntervalFactor);
|
||||
void LocalPoolDataSetBase::initializePeriodicHelper(float collectionInterval,
|
||||
dur_millis_t minimumPeriodicInterval, uint8_t nonDiagIntervalFactor) {
|
||||
periodicHelper->initialize(collectionInterval, minimumPeriodicInterval, nonDiagIntervalFactor);
|
||||
}
|
||||
|
||||
void LocalPoolDataSetBase::setChanged(bool changed) {
|
||||
@ -306,3 +313,12 @@ void LocalPoolDataSetBase::setAllVariablesReadOnly() {
|
||||
registeredVariables[idx]->setReadWriteMode(pool_rwm_t::VAR_READ);
|
||||
}
|
||||
}
|
||||
|
||||
float LocalPoolDataSetBase::getCollectionInterval() const {
|
||||
if(periodicHelper != nullptr) {
|
||||
return periodicHelper->getCollectionIntervalInSeconds();
|
||||
}
|
||||
else {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
@ -166,6 +166,16 @@ public:
|
||||
|
||||
object_id_t getCreatorObjectId();
|
||||
|
||||
bool getReportingEnabled() const;
|
||||
|
||||
/**
|
||||
* Returns the current periodic HK generation interval this set
|
||||
* belongs to a HK manager and the interval is not 0. Otherwise,
|
||||
* returns 0.0
|
||||
* @return
|
||||
*/
|
||||
float getCollectionInterval() const;
|
||||
|
||||
protected:
|
||||
sid_t sid;
|
||||
//! This mutex is used if the data is created by one object only.
|
||||
@ -180,11 +190,9 @@ protected:
|
||||
*/
|
||||
bool reportingEnabled = false;
|
||||
void setReportingEnabled(bool enabled);
|
||||
bool getReportingEnabled() const;
|
||||
|
||||
void initializePeriodicHelper(float collectionInterval,
|
||||
dur_millis_t minimumPeriodicInterval,
|
||||
bool isDiagnostics, uint8_t nonDiagIntervalFactor = 5);
|
||||
void initializePeriodicHelper(float collectionInterval, dur_millis_t minimumPeriodicInterval,
|
||||
uint8_t nonDiagIntervalFactor = 5);
|
||||
|
||||
/**
|
||||
* If the valid state of a dataset is always relevant to the whole
|
||||
|
@ -1,16 +1,37 @@
|
||||
#include "SharedLocalDataSet.h"
|
||||
|
||||
|
||||
SharedLocalDataSet::SharedLocalDataSet(object_id_t objectId, sid_t sid,
|
||||
const size_t maxSize): SystemObject(objectId),
|
||||
LocalPoolDataSetBase(sid, nullptr, maxSize) {
|
||||
LocalPoolDataSetBase(sid, nullptr, maxSize), poolVarVector(maxSize) {
|
||||
this->setContainer(poolVarVector.data());
|
||||
datasetLock = MutexFactory::instance()->createMutex();
|
||||
}
|
||||
|
||||
ReturnValue_t SharedLocalDataSet::lockDataset(dur_millis_t mutexTimeout) {
|
||||
return datasetLock->lockMutex(MutexIF::TimeoutType::WAITING, mutexTimeout);
|
||||
SharedLocalDataSet::SharedLocalDataSet(object_id_t objectId,
|
||||
HasLocalDataPoolIF *owner, uint32_t setId,
|
||||
const size_t maxSize): SystemObject(objectId),
|
||||
LocalPoolDataSetBase(owner, setId, nullptr, maxSize), poolVarVector(maxSize) {
|
||||
this->setContainer(poolVarVector.data());
|
||||
datasetLock = MutexFactory::instance()->createMutex();
|
||||
}
|
||||
|
||||
ReturnValue_t SharedLocalDataSet::lockDataset(MutexIF::TimeoutType timeoutType,
|
||||
dur_millis_t mutexTimeout) {
|
||||
if(datasetLock != nullptr) {
|
||||
return datasetLock->lockMutex(timeoutType, mutexTimeout);
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
|
||||
SharedLocalDataSet::~SharedLocalDataSet() {
|
||||
MutexFactory::instance()->deleteMutex(datasetLock);
|
||||
}
|
||||
|
||||
ReturnValue_t SharedLocalDataSet::unlockDataset() {
|
||||
return datasetLock->unlockMutex();
|
||||
if(datasetLock != nullptr) {
|
||||
return datasetLock->unlockMutex();
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
@ -11,16 +11,22 @@
|
||||
* multiple threads. It provides a lock in addition to all other functionalities provided
|
||||
* by the LocalPoolDataSetBase class.
|
||||
*
|
||||
* TODO: override and protect read, commit and some other calls used by pool manager.
|
||||
* The user is completely responsible for lockingand unlocking the dataset when using the
|
||||
* shared dataset.
|
||||
*/
|
||||
class SharedLocalDataSet:
|
||||
public SystemObject,
|
||||
public LocalPoolDataSetBase,
|
||||
public SharedDataSetIF {
|
||||
public:
|
||||
SharedLocalDataSet(object_id_t objectId, sid_t sid,
|
||||
SharedLocalDataSet(object_id_t objectId, HasLocalDataPoolIF* owner, uint32_t setId,
|
||||
const size_t maxSize);
|
||||
ReturnValue_t lockDataset(dur_millis_t mutexTimeout) override;
|
||||
SharedLocalDataSet(object_id_t objectId, sid_t sid, const size_t maxSize);
|
||||
|
||||
virtual~ SharedLocalDataSet();
|
||||
|
||||
ReturnValue_t lockDataset(MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING,
|
||||
dur_millis_t mutexTimeout = 20) override;
|
||||
ReturnValue_t unlockDataset() override;
|
||||
private:
|
||||
|
||||
|
12
datapoollocal/datapoollocal.h
Normal file
12
datapoollocal/datapoollocal.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef FSFW_DATAPOOLLOCAL_DATAPOOLLOCAL_H_
|
||||
#define FSFW_DATAPOOLLOCAL_DATAPOOLLOCAL_H_
|
||||
|
||||
/* Collected related headers */
|
||||
#include "LocalPoolVariable.h"
|
||||
#include "LocalPoolVector.h"
|
||||
#include "StaticLocalDataSet.h"
|
||||
#include "LocalDataSet.h"
|
||||
#include "SharedLocalDataSet.h"
|
||||
|
||||
|
||||
#endif /* FSFW_DATAPOOLLOCAL_DATAPOOLLOCAL_H_ */
|
@ -14,9 +14,8 @@ private:
|
||||
}
|
||||
|
||||
static void initializePeriodicHelper(LocalPoolDataSetBase& set, float collectionInterval,
|
||||
uint32_t minimumPeriodicIntervalMs,
|
||||
bool isDiagnostics, uint8_t nonDiagIntervalFactor = 5) {
|
||||
set.initializePeriodicHelper(collectionInterval, minimumPeriodicIntervalMs, isDiagnostics,
|
||||
uint32_t minimumPeriodicIntervalMs, uint8_t nonDiagIntervalFactor = 5) {
|
||||
set.initializePeriodicHelper(collectionInterval, minimumPeriodicIntervalMs,
|
||||
nonDiagIntervalFactor);
|
||||
}
|
||||
|
||||
|
@ -96,11 +96,11 @@ union gp_id_t {
|
||||
return raw == INVALID_GPID;
|
||||
}
|
||||
|
||||
bool operator==(const sid_t& other) const {
|
||||
bool operator==(const gp_id_t& other) const {
|
||||
return raw == other.raw;
|
||||
}
|
||||
|
||||
bool operator!=(const sid_t& other) const {
|
||||
bool operator!=(const gp_id_t& other) const {
|
||||
return not (raw == other.raw);
|
||||
}
|
||||
};
|
||||
|
@ -67,7 +67,9 @@ void arrayprinter::printHex(const uint8_t *data, size_t size,
|
||||
}
|
||||
}
|
||||
}
|
||||
#if FSFW_DISABLE_PRINTOUT == 0
|
||||
printf("[%s]\n", printBuffer);
|
||||
#endif /* FSFW_DISABLE_PRINTOUT == 0 */
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -108,7 +110,9 @@ void arrayprinter::printDec(const uint8_t *data, size_t size,
|
||||
}
|
||||
}
|
||||
}
|
||||
#if FSFW_DISABLE_PRINTOUT == 0
|
||||
printf("[%s]\n", printBuffer);
|
||||
#endif /* FSFW_DISABLE_PRINTOUT == 0 */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -84,15 +84,21 @@ void HousekeepingMessage::setCollectionIntervalModificationCommand(
|
||||
else {
|
||||
command->setCommand(MODIFY_PARAMETER_REPORT_COLLECTION_INTERVAL);
|
||||
}
|
||||
command->setParameter3(collectionInterval);
|
||||
|
||||
/* Raw storage of the float in the message. Do not use setParameter3, does
|
||||
implicit conversion to integer type! */
|
||||
std::memcpy(command->getData() + 2 * sizeof(uint32_t), &collectionInterval,
|
||||
sizeof(collectionInterval));
|
||||
|
||||
setSid(command, sid);
|
||||
}
|
||||
|
||||
sid_t HousekeepingMessage::getCollectionIntervalModificationCommand(
|
||||
const CommandMessage* command, float* newCollectionInterval) {
|
||||
|
||||
if(newCollectionInterval != nullptr) {
|
||||
*newCollectionInterval = command->getParameter3();
|
||||
std::memcpy(newCollectionInterval, command->getData() + 2 * sizeof(uint32_t),
|
||||
sizeof(*newCollectionInterval));
|
||||
}
|
||||
|
||||
return getSid(command);
|
||||
@ -151,7 +157,8 @@ void HousekeepingMessage::clear(CommandMessage* message) {
|
||||
case(DIAGNOSTICS_REPORT):
|
||||
case(HK_DEFINITIONS_REPORT):
|
||||
case(DIAGNOSTICS_DEFINITION_REPORT):
|
||||
case(UPDATE_SNAPSHOT_SET): {
|
||||
case(UPDATE_SNAPSHOT_SET):
|
||||
case(UPDATE_SNAPSHOT_VARIABLE): {
|
||||
store_address_t storeId;
|
||||
getHkDataReply(message, &storeId);
|
||||
StorageManagerIF *ipcStore = objectManager->get<StorageManagerIF>(
|
||||
|
@ -11,7 +11,8 @@
|
||||
* @brief This helper class will be used to serialize and deserialize update housekeeping packets
|
||||
* into the store.
|
||||
*/
|
||||
class HousekeepingSnapshot: public SerializeIF {
|
||||
class HousekeepingSnapshot:
|
||||
public SerializeIF {
|
||||
public:
|
||||
|
||||
/**
|
||||
@ -36,6 +37,17 @@ public:
|
||||
timeStamp(timeStamp), timeStampSize(timeStampSize),
|
||||
updateData(dataSetPtr) {};
|
||||
|
||||
/**
|
||||
* Update packet constructor for pool variables.
|
||||
* @param timeStamp
|
||||
* @param timeStampSize
|
||||
* @param dataSetPtr
|
||||
*/
|
||||
HousekeepingSnapshot(CCSDSTime::CDS_short* cdsShort, LocalPoolObjectBase* dataSetPtr):
|
||||
timeStamp(reinterpret_cast<uint8_t*>(cdsShort)),
|
||||
timeStampSize(sizeof(CCSDSTime::CDS_short)), updateData(dataSetPtr) {};
|
||||
|
||||
|
||||
/**
|
||||
* Update packet constructor for pool variables.
|
||||
* @param timeStamp
|
||||
@ -47,8 +59,8 @@ public:
|
||||
timeStamp(timeStamp), timeStampSize(timeStampSize),
|
||||
updateData(dataSetPtr) {};
|
||||
|
||||
virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size,
|
||||
size_t maxSize, Endianness streamEndianness) const {
|
||||
virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
|
||||
Endianness streamEndianness) const {
|
||||
if(timeStamp != nullptr) {
|
||||
/* Endianness will always be MACHINE, so we can simply use memcpy
|
||||
here. */
|
||||
|
@ -4,46 +4,87 @@
|
||||
#include <cmath>
|
||||
|
||||
PeriodicHousekeepingHelper::PeriodicHousekeepingHelper(
|
||||
LocalPoolDataSetBase* owner): owner(owner) {}
|
||||
|
||||
LocalPoolDataSetBase* owner): owner(owner) {}
|
||||
|
||||
void PeriodicHousekeepingHelper::initialize(float collectionInterval,
|
||||
dur_millis_t minimumPeriodicInterval, bool isDiagnostics,
|
||||
uint8_t nonDiagIntervalFactor) {
|
||||
this->minimumPeriodicInterval = minimumPeriodicInterval;
|
||||
if(not isDiagnostics) {
|
||||
this->minimumPeriodicInterval = this->minimumPeriodicInterval *
|
||||
nonDiagIntervalFactor;
|
||||
}
|
||||
collectionIntervalTicks = intervalSecondsToInterval(collectionInterval);
|
||||
dur_millis_t minimumPeriodicInterval, uint8_t nonDiagIntervalFactor) {
|
||||
this->minimumPeriodicInterval = minimumPeriodicInterval;
|
||||
this->nonDiagIntervalFactor = nonDiagIntervalFactor;
|
||||
collectionIntervalTicks = intervalSecondsToIntervalTicks(collectionInterval);
|
||||
/* This will cause a checkOpNecessary call to be true immediately. I think it's okay
|
||||
if a HK packet is generated immediately instead of waiting one generation cycle. */
|
||||
internalTickCounter = collectionIntervalTicks;
|
||||
}
|
||||
|
||||
float PeriodicHousekeepingHelper::getCollectionIntervalInSeconds() {
|
||||
return intervalToIntervalSeconds(collectionIntervalTicks);
|
||||
float PeriodicHousekeepingHelper::getCollectionIntervalInSeconds() const {
|
||||
return intervalTicksToSeconds(collectionIntervalTicks);
|
||||
}
|
||||
|
||||
bool PeriodicHousekeepingHelper::checkOpNecessary() {
|
||||
if(internalTickCounter >= collectionIntervalTicks) {
|
||||
internalTickCounter = 1;
|
||||
return true;
|
||||
}
|
||||
internalTickCounter++;
|
||||
return false;
|
||||
if(internalTickCounter >= collectionIntervalTicks) {
|
||||
internalTickCounter = 1;
|
||||
return true;
|
||||
}
|
||||
internalTickCounter++;
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t PeriodicHousekeepingHelper::intervalSecondsToInterval(
|
||||
float collectionIntervalSeconds) {
|
||||
return std::ceil(collectionIntervalSeconds * 1000
|
||||
/ minimumPeriodicInterval);
|
||||
uint32_t PeriodicHousekeepingHelper::intervalSecondsToIntervalTicks(
|
||||
float collectionIntervalSeconds) {
|
||||
if(owner == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
bool isDiagnostics = owner->isDiagnostics();
|
||||
|
||||
/* Avoid division by zero */
|
||||
if(minimumPeriodicInterval == 0) {
|
||||
if(isDiagnostics) {
|
||||
/* Perform operation each cycle */
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return nonDiagIntervalFactor;
|
||||
}
|
||||
}
|
||||
else {
|
||||
dur_millis_t intervalInMs = collectionIntervalSeconds * 1000;
|
||||
uint32_t divisor = minimumPeriodicInterval;
|
||||
if(not isDiagnostics) {
|
||||
/* We need to multiply the divisor because non-diagnostics only
|
||||
allow a multiple of the minimum periodic interval */
|
||||
divisor *= nonDiagIntervalFactor;
|
||||
}
|
||||
uint32_t ticks = std::ceil(static_cast<float>(intervalInMs) / divisor);
|
||||
if(not isDiagnostics) {
|
||||
/* Now we need to multiply the calculated ticks with the factor as as well
|
||||
because the minimum tick count to generate a non-diagnostic is the factor itself.
|
||||
|
||||
Example calculation for non-diagnostic with
|
||||
0.4 second interval and 0.2 second task interval.
|
||||
Resultant tick count of 5 is equal to operation each second.
|
||||
|
||||
Examle calculation for non-diagnostic with 2.0 second interval and 0.2 second
|
||||
task interval.
|
||||
Resultant tick count of 10 is equal to operatin every 2 seconds.
|
||||
|
||||
Example calculation for diagnostic with 0.4 second interval and 0.3
|
||||
second task interval. Resulting tick count of 2 is equal to operation
|
||||
every 0.6 seconds. */
|
||||
ticks *= nonDiagIntervalFactor;
|
||||
}
|
||||
return ticks;
|
||||
}
|
||||
}
|
||||
|
||||
float PeriodicHousekeepingHelper::intervalToIntervalSeconds(
|
||||
uint32_t collectionInterval) {
|
||||
return static_cast<float>(collectionInterval *
|
||||
minimumPeriodicInterval);
|
||||
float PeriodicHousekeepingHelper::intervalTicksToSeconds(
|
||||
uint32_t collectionInterval) const {
|
||||
/* Number of ticks times the minimum interval is in milliseconds, so we divide by 1000 to get
|
||||
the value in seconds */
|
||||
return static_cast<float>(collectionInterval * minimumPeriodicInterval / 1000.0);
|
||||
}
|
||||
|
||||
void PeriodicHousekeepingHelper::changeCollectionInterval(
|
||||
float newIntervalSeconds) {
|
||||
collectionIntervalTicks = intervalSecondsToInterval(newIntervalSeconds);
|
||||
float newIntervalSeconds) {
|
||||
collectionIntervalTicks = intervalSecondsToIntervalTicks(newIntervalSeconds);
|
||||
}
|
||||
|
||||
|
@ -10,18 +10,19 @@ class PeriodicHousekeepingHelper {
|
||||
public:
|
||||
PeriodicHousekeepingHelper(LocalPoolDataSetBase* owner);
|
||||
|
||||
void initialize(float collectionInterval,
|
||||
dur_millis_t minimumPeriodicInterval, bool isDiagnostics,
|
||||
uint8_t nonDiagIntervalFactor);
|
||||
void initialize(float collectionInterval, dur_millis_t minimumPeriodicInterval,
|
||||
uint8_t nonDiagIntervalFactor);
|
||||
|
||||
void changeCollectionInterval(float newInterval);
|
||||
float getCollectionIntervalInSeconds();
|
||||
float getCollectionIntervalInSeconds() const;
|
||||
bool checkOpNecessary();
|
||||
|
||||
private:
|
||||
LocalPoolDataSetBase* owner = nullptr;
|
||||
uint8_t nonDiagIntervalFactor = 0;
|
||||
|
||||
uint32_t intervalSecondsToInterval(float collectionIntervalSeconds);
|
||||
float intervalToIntervalSeconds(uint32_t collectionInterval);
|
||||
uint32_t intervalSecondsToIntervalTicks(float collectionIntervalSeconds);
|
||||
float intervalTicksToSeconds(uint32_t collectionInterval) const;
|
||||
|
||||
dur_millis_t minimumPeriodicInterval = 0;
|
||||
uint32_t internalTickCounter = 1;
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef FRAMEWORK_IPC_MUTEXHELPER_H_
|
||||
#define FRAMEWORK_IPC_MUTEXHELPER_H_
|
||||
#ifndef FRAMEWORK_IPC_MUTEXGUARD_H_
|
||||
#define FRAMEWORK_IPC_MUTEXGUARD_H_
|
||||
|
||||
#include "MutexFactory.h"
|
||||
#include "../serviceinterface/ServiceInterface.h"
|
||||
@ -12,9 +12,9 @@ public:
|
||||
if(mutex == nullptr) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "MutexHelper: Passed mutex is invalid!" << std::endl;
|
||||
sif::error << "MutexGuard: Passed mutex is invalid!" << std::endl;
|
||||
#else
|
||||
sif::printError("MutexHelper: Passed mutex is invalid!\n");
|
||||
sif::printError("MutexGuard: Passed mutex is invalid!\n");
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||
return;
|
||||
@ -24,24 +24,22 @@ public:
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
if(result == MutexIF::MUTEX_TIMEOUT) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "MutexHelper: Lock of mutex failed with timeout of "
|
||||
sif::error << "MutexGuard: Lock of mutex failed with timeout of "
|
||||
<< timeoutMs << " milliseconds!" << std::endl;
|
||||
#else
|
||||
sif::printError("MutexHelper: Lock of mutex failed with timeout of %lu milliseconds\n",
|
||||
sif::printError("MutexGuard: Lock of mutex failed with timeout of %lu milliseconds\n",
|
||||
timeoutMs);
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
|
||||
}
|
||||
else if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "MutexHelper: Lock of Mutex failed with code " << result << std::endl;
|
||||
sif::error << "MutexGuard: Lock of Mutex failed with code " << result << std::endl;
|
||||
#else
|
||||
sif::printError("MutexHelper: Lock of Mutex failed with code %d\n", result);
|
||||
sif::printError("MutexGuard: Lock of Mutex failed with code %d\n", result);
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
}
|
||||
#else
|
||||
/* To avoid unused variable warning */
|
||||
static_cast<void>(status);
|
||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||
}
|
||||
|
||||
@ -59,4 +57,4 @@ private:
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_IPC_MUTEXHELPER_H_ */
|
||||
#endif /* FRAMEWORK_IPC_MUTEXGUARD_H_ */
|
||||
|
@ -31,4 +31,6 @@ else()
|
||||
message(FATAL_ERROR "The host OS could not be determined! Aborting.")
|
||||
endif()
|
||||
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_subdirectory(common)
|
3
osal/common/CMakeLists.txt
Normal file
3
osal/common/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||
tcpipCommon.cpp
|
||||
)
|
36
osal/common/tcpipCommon.cpp
Normal file
36
osal/common/tcpipCommon.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include "tcpipCommon.h"
|
||||
|
||||
void tcpip::determineErrorStrings(Protocol protocol, ErrorSources errorSrc, std::string &protStr,
|
||||
std::string &srcString) {
|
||||
if(protocol == Protocol::TCP) {
|
||||
protStr = "TCP";
|
||||
}
|
||||
else if(protocol == Protocol::UDP) {
|
||||
protStr = "UDP";
|
||||
}
|
||||
else {
|
||||
protStr = "Unknown protocol";
|
||||
}
|
||||
|
||||
if(errorSrc == ErrorSources::SETSOCKOPT_CALL) {
|
||||
srcString = "setsockopt call";
|
||||
}
|
||||
else if(errorSrc == ErrorSources::SOCKET_CALL) {
|
||||
srcString = "socket call";
|
||||
}
|
||||
else if(errorSrc == ErrorSources::LISTEN_CALL) {
|
||||
srcString = "listen call";
|
||||
}
|
||||
else if(errorSrc == ErrorSources::ACCEPT_CALL) {
|
||||
srcString = "accept call";
|
||||
}
|
||||
else if(errorSrc == ErrorSources::RECVFROM_CALL) {
|
||||
srcString = "recvfrom call";
|
||||
}
|
||||
else if(errorSrc == ErrorSources::GETADDRINFO_CALL) {
|
||||
srcString = "getaddrinfo call";
|
||||
}
|
||||
else {
|
||||
srcString = "unknown call";
|
||||
}
|
||||
}
|
36
osal/common/tcpipCommon.h
Normal file
36
osal/common/tcpipCommon.h
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef FSFW_OSAL_COMMON_TCPIPCOMMON_H_
|
||||
#define FSFW_OSAL_COMMON_TCPIPCOMMON_H_
|
||||
|
||||
#include "../../timemanager/clockDefinitions.h"
|
||||
#include <string>
|
||||
|
||||
namespace tcpip {
|
||||
|
||||
const char* const DEFAULT_UDP_SERVER_PORT = "7301";
|
||||
const char* const DEFAULT_TCP_SERVER_PORT = "7303";
|
||||
|
||||
enum class Protocol {
|
||||
UDP,
|
||||
TCP
|
||||
};
|
||||
|
||||
enum class ErrorSources {
|
||||
GETADDRINFO_CALL,
|
||||
SOCKET_CALL,
|
||||
SETSOCKOPT_CALL,
|
||||
BIND_CALL,
|
||||
RECV_CALL,
|
||||
RECVFROM_CALL,
|
||||
LISTEN_CALL,
|
||||
ACCEPT_CALL,
|
||||
SENDTO_CALL
|
||||
};
|
||||
|
||||
void determineErrorStrings(Protocol protocol, ErrorSources errorSrc, std::string& protStr,
|
||||
std::string& srcString);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* FSFW_OSAL_COMMON_TCPIPCOMMON_H_ */
|
@ -24,5 +24,7 @@ MutexIF* MutexFactory::createMutex() {
|
||||
}
|
||||
|
||||
void MutexFactory::deleteMutex(MutexIF* mutex) {
|
||||
delete mutex;
|
||||
if(mutex != nullptr) {
|
||||
delete mutex;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
#include "../../tasks/SemaphoreFactory.h"
|
||||
#include "../../osal/linux/BinarySemaphore.h"
|
||||
#include "../../osal/linux/CountingSemaphore.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../../serviceinterface/ServiceInterface.h"
|
||||
|
||||
SemaphoreFactory* SemaphoreFactory::factoryInstance = nullptr;
|
||||
|
||||
|
@ -16,6 +16,7 @@ target_sources(${LIB_FSFW_NAME}
|
||||
TcUnixUdpPollingTask.cpp
|
||||
TmTcUnixUdpBridge.cpp
|
||||
Timer.cpp
|
||||
tcpipHelpers.cpp
|
||||
)
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "PeriodicPosixTask.h"
|
||||
|
||||
#include "../../tasks/TaskFactory.h"
|
||||
#include "../../serviceinterface/ServiceInterface.h"
|
||||
#include "../../returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
//TODO: Different variant than the lazy loading in QueueFactory. What's better and why?
|
||||
|
@ -1,7 +1,9 @@
|
||||
#include "TcUnixUdpPollingTask.h"
|
||||
#include "tcpipHelpers.h"
|
||||
|
||||
#include "../../globalfunctions/arrayprinter.h"
|
||||
|
||||
#include <errno.h>
|
||||
#define FSFW_UDP_RCV_WIRETAPPING_ENABLED 0
|
||||
|
||||
TcUnixUdpPollingTask::TcUnixUdpPollingTask(object_id_t objectId,
|
||||
object_id_t tmtcUnixUdpBridge, size_t frameSize,
|
||||
@ -15,8 +17,8 @@ TcUnixUdpPollingTask::TcUnixUdpPollingTask(object_id_t objectId,
|
||||
this->frameSize = DEFAULT_MAX_FRAME_SIZE;
|
||||
}
|
||||
|
||||
// Set up reception buffer with specified frame size.
|
||||
// For now, it is assumed that only one frame is held in the buffer!
|
||||
/* Set up reception buffer with specified frame size.
|
||||
For now, it is assumed that only one frame is held in the buffer! */
|
||||
receptionBuffer.reserve(this->frameSize);
|
||||
receptionBuffer.resize(this->frameSize);
|
||||
|
||||
@ -31,34 +33,37 @@ TcUnixUdpPollingTask::TcUnixUdpPollingTask(object_id_t objectId,
|
||||
TcUnixUdpPollingTask::~TcUnixUdpPollingTask() {}
|
||||
|
||||
ReturnValue_t TcUnixUdpPollingTask::performOperation(uint8_t opCode) {
|
||||
// Poll for new UDP datagrams in permanent loop.
|
||||
while(1) {
|
||||
//! Sender Address is cached here.
|
||||
struct sockaddr_in senderAddress;
|
||||
socklen_t senderSockLen = sizeof(senderAddress);
|
||||
ssize_t bytesReceived = recvfrom(serverUdpSocket,
|
||||
receptionBuffer.data(), frameSize, receptionFlags,
|
||||
reinterpret_cast<sockaddr*>(&senderAddress), &senderSockLen);
|
||||
if(bytesReceived < 0) {
|
||||
// handle error
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "TcSocketPollingTask::performOperation: Reception"
|
||||
"error." << std::endl;
|
||||
#endif
|
||||
handleReadError();
|
||||
/* Sender Address is cached here. */
|
||||
struct sockaddr_in senderAddress;
|
||||
socklen_t senderAddressSize = sizeof(senderAddress);
|
||||
|
||||
/* Poll for new UDP datagrams in permanent loop. */
|
||||
while(true) {
|
||||
ssize_t bytesReceived = recvfrom(
|
||||
serverUdpSocket,
|
||||
receptionBuffer.data(),
|
||||
frameSize,
|
||||
receptionFlags,
|
||||
reinterpret_cast<sockaddr*>(&senderAddress),
|
||||
&senderAddressSize
|
||||
);
|
||||
if(bytesReceived < 0) {
|
||||
/* Handle error */
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "TcSocketPollingTask::performOperation: Reception error." << std::endl;
|
||||
#endif
|
||||
tcpip::handleError(tcpip::Protocol::UDP, tcpip::ErrorSources::RECVFROM_CALL, 500);
|
||||
continue;
|
||||
}
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
// sif::debug << "TcSocketPollingTask::performOperation: " << bytesReceived
|
||||
// << " bytes received" << std::endl;
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_RCV_WIRETAPPING_ENABLED == 1
|
||||
sif::debug << "TcSocketPollingTask::performOperation: " << bytesReceived
|
||||
<< " bytes received" << std::endl;
|
||||
#endif
|
||||
|
||||
ReturnValue_t result = handleSuccessfullTcRead(bytesReceived);
|
||||
if(result != HasReturnvaluesIF::RETURN_FAILED) {
|
||||
|
||||
}
|
||||
tmtcBridge->registerCommConnect();
|
||||
tmtcBridge->checkAndSetClientAddress(senderAddress);
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
@ -67,15 +72,21 @@ ReturnValue_t TcUnixUdpPollingTask::performOperation(uint8_t opCode) {
|
||||
|
||||
ReturnValue_t TcUnixUdpPollingTask::handleSuccessfullTcRead(size_t bytesRead) {
|
||||
store_address_t storeId;
|
||||
ReturnValue_t result = tcStore->addData(&storeId,
|
||||
receptionBuffer.data(), bytesRead);
|
||||
// arrayprinter::print(receptionBuffer.data(), bytesRead);
|
||||
|
||||
#if FSFW_UDP_RCV_WIRETAPPING_ENABLED == 1
|
||||
arrayprinter::print(receptionBuffer.data(), bytesRead);
|