bugfixes and auto indentation

This commit is contained in:
Robin Müller 2021-01-13 12:12:08 +01:00
parent 27e5254ecd
commit c3bca518e7

View File

@ -11,47 +11,50 @@
#include <cstring> #include <cstring>
LocalPoolDataSetBase::LocalPoolDataSetBase(HasLocalDataPoolIF *hkOwner, LocalPoolDataSetBase::LocalPoolDataSetBase(HasLocalDataPoolIF *hkOwner,
uint32_t setId, PoolVariableIF** registeredVariablesArray, uint32_t setId, PoolVariableIF** registeredVariablesArray,
const size_t maxNumberOfVariables, bool periodicHandling): const size_t maxNumberOfVariables, bool periodicHandling):
PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) { PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) {
if(hkOwner == nullptr) { if(hkOwner == nullptr) {
// Configuration error. // Configuration error.
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "LocalPoolDataSetBase::LocalPoolDataSetBase: Owner " sif::error << "LocalPoolDataSetBase::LocalPoolDataSetBase: Owner "
<< "invalid!" << std::endl; << "invalid!" << std::endl;
#else #else
sif::printError("LocalPoolDataSetBase::LocalPoolDataSetBase: Owner " sif::printError("LocalPoolDataSetBase::LocalPoolDataSetBase: Owner "
"invalid!\n\r"); "invalid!\n\r");
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
return; return;
} }
AccessPoolManagerIF* accessor = HasLocalDpIFUserAttorney::getAccessorHandle(hkOwner); AccessPoolManagerIF* accessor = HasLocalDpIFUserAttorney::getAccessorHandle(hkOwner);
if(poolManager != nullptr) { if(accessor != nullptr) {
poolManager = accessor->getHkManagerHandle(); poolManager = accessor->getHkManagerHandle();
mutexIfSingleDataCreator = accessor->getLocalPoolMutex(); mutexIfSingleDataCreator = accessor->getLocalPoolMutex();
} }
this->sid.objectId = hkOwner->getObjectId(); this->sid.objectId = hkOwner->getObjectId();
this->sid.ownerSetId = setId; this->sid.ownerSetId = setId;
// Data creators get a periodic helper for periodic HK data generation. // Data creators get a periodic helper for periodic HK data generation.
if(periodicHandling) { if(periodicHandling) {
periodicHelper = new PeriodicHousekeepingHelper(this); periodicHelper = new PeriodicHousekeepingHelper(this);
} }
} }
LocalPoolDataSetBase::LocalPoolDataSetBase(sid_t sid, LocalPoolDataSetBase::LocalPoolDataSetBase(sid_t sid,
PoolVariableIF** registeredVariablesArray, PoolVariableIF** registeredVariablesArray,
const size_t maxNumberOfVariables): const size_t maxNumberOfVariables):
PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) { PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) {
AccessPoolManagerIF* hkOwner = objectManager->get<AccessPoolManagerIF>( HasLocalDataPoolIF* hkOwner = objectManager->get<HasLocalDataPoolIF>(
sid.objectId); sid.objectId);
if(hkOwner != nullptr) { if(hkOwner != nullptr) {
mutexIfSingleDataCreator = hkOwner->getLocalPoolMutex(); AccessPoolManagerIF* accessor = HasLocalDpIFUserAttorney::getAccessorHandle(hkOwner);
} if(accessor != nullptr) {
mutexIfSingleDataCreator = accessor->getLocalPoolMutex();
}
}
this->sid = sid; this->sid = sid;
} }
LocalPoolDataSetBase::LocalPoolDataSetBase( LocalPoolDataSetBase::LocalPoolDataSetBase(
@ -72,240 +75,240 @@ ReturnValue_t LocalPoolDataSetBase::lockDataPool(
MutexIF::TimeoutType timeoutType, MutexIF::TimeoutType timeoutType,
uint32_t timeoutMs) { uint32_t timeoutMs) {
if(mutexIfSingleDataCreator != nullptr) { if(mutexIfSingleDataCreator != nullptr) {
return mutexIfSingleDataCreator->lockMutex(timeoutType, timeoutMs); return mutexIfSingleDataCreator->lockMutex(timeoutType, timeoutMs);
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
ReturnValue_t LocalPoolDataSetBase::serializeWithValidityBuffer(uint8_t **buffer, ReturnValue_t LocalPoolDataSetBase::serializeWithValidityBuffer(uint8_t **buffer,
size_t *size, size_t maxSize, size_t *size, size_t maxSize,
SerializeIF::Endianness streamEndianness) const { SerializeIF::Endianness streamEndianness) const {
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED; ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
uint8_t validityMaskSize = std::ceil(static_cast<float>(fillCount)/8.0); uint8_t validityMaskSize = std::ceil(static_cast<float>(fillCount)/8.0);
uint8_t validityMask[validityMaskSize]; uint8_t validityMask[validityMaskSize];
uint8_t validBufferIndex = 0; uint8_t validBufferIndex = 0;
uint8_t validBufferIndexBit = 0; uint8_t validBufferIndexBit = 0;
for (uint16_t count = 0; count < fillCount; count++) { for (uint16_t count = 0; count < fillCount; count++) {
if(registeredVariables[count]->isValid()) { if(registeredVariables[count]->isValid()) {
// set validity buffer here. // set validity buffer here.
this->bitSetter(validityMask + validBufferIndex, this->bitSetter(validityMask + validBufferIndex,
validBufferIndexBit); validBufferIndexBit);
if(validBufferIndexBit == 7) { if(validBufferIndexBit == 7) {
validBufferIndex ++; validBufferIndex ++;
validBufferIndexBit = 0; validBufferIndexBit = 0;
} }
else { else {
validBufferIndexBit ++; validBufferIndexBit ++;
} }
} }
result = registeredVariables[count]->serialize(buffer, size, maxSize, result = registeredVariables[count]->serialize(buffer, size, maxSize,
streamEndianness); streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
return result; return result;
} }
} }
if(*size + validityMaskSize > maxSize) { if(*size + validityMaskSize > maxSize) {
return SerializeIF::BUFFER_TOO_SHORT; return SerializeIF::BUFFER_TOO_SHORT;
} }
// copy validity buffer to end // copy validity buffer to end
std::memcpy(*buffer, validityMask, validityMaskSize); std::memcpy(*buffer, validityMask, validityMaskSize);
*size += validityMaskSize; *size += validityMaskSize;
return result; return result;
} }
ReturnValue_t LocalPoolDataSetBase::deSerializeWithValidityBuffer( ReturnValue_t LocalPoolDataSetBase::deSerializeWithValidityBuffer(
const uint8_t **buffer, size_t *size, const uint8_t **buffer, size_t *size,
SerializeIF::Endianness streamEndianness) { SerializeIF::Endianness streamEndianness) {
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED; ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
for (uint16_t count = 0; count < fillCount; count++) { for (uint16_t count = 0; count < fillCount; count++) {
result = registeredVariables[count]->deSerialize(buffer, size, result = registeredVariables[count]->deSerialize(buffer, size,
streamEndianness); streamEndianness);
if(result != HasReturnvaluesIF::RETURN_OK) { if(result != HasReturnvaluesIF::RETURN_OK) {
return result; return result;
} }
} }
if(*size < std::ceil(static_cast<float>(fillCount) / 8.0)) { if(*size < std::ceil(static_cast<float>(fillCount) / 8.0)) {
return SerializeIF::STREAM_TOO_SHORT; return SerializeIF::STREAM_TOO_SHORT;
} }
uint8_t validBufferIndex = 0; uint8_t validBufferIndex = 0;
uint8_t validBufferIndexBit = 0; uint8_t validBufferIndexBit = 0;
for (uint16_t count = 0; count < fillCount; count++) { for (uint16_t count = 0; count < fillCount; count++) {
// set validity buffer here. // set validity buffer here.
bool nextVarValid = this->bitGetter(*buffer + bool nextVarValid = this->bitGetter(*buffer +
validBufferIndex, validBufferIndexBit); validBufferIndex, validBufferIndexBit);
registeredVariables[count]->setValid(nextVarValid); registeredVariables[count]->setValid(nextVarValid);
if(validBufferIndexBit == 7) { if(validBufferIndexBit == 7) {
validBufferIndex ++; validBufferIndex ++;
validBufferIndexBit = 0; validBufferIndexBit = 0;
} }
else { else {
validBufferIndexBit ++; validBufferIndexBit ++;
} }
} }
return result; return result;
} }
ReturnValue_t LocalPoolDataSetBase::unlockDataPool() { ReturnValue_t LocalPoolDataSetBase::unlockDataPool() {
if(mutexIfSingleDataCreator != nullptr) { if(mutexIfSingleDataCreator != nullptr) {
return mutexIfSingleDataCreator->unlockMutex(); return mutexIfSingleDataCreator->unlockMutex();
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
ReturnValue_t LocalPoolDataSetBase::serializeLocalPoolIds(uint8_t** buffer, ReturnValue_t LocalPoolDataSetBase::serializeLocalPoolIds(uint8_t** buffer,
size_t* size, size_t maxSize,SerializeIF::Endianness streamEndianness, size_t* size, size_t maxSize,SerializeIF::Endianness streamEndianness,
bool serializeFillCount) const { bool serializeFillCount) const {
// Serialize as uint8_t // Serialize as uint8_t
uint8_t fillCount = this->fillCount; uint8_t fillCount = this->fillCount;
if(serializeFillCount) { if(serializeFillCount) {
SerializeAdapter::serialize(&fillCount, buffer, size, maxSize, SerializeAdapter::serialize(&fillCount, buffer, size, maxSize,
streamEndianness); streamEndianness);
} }
for (uint16_t count = 0; count < fillCount; count++) { for (uint16_t count = 0; count < fillCount; count++) {
lp_id_t currentPoolId = registeredVariables[count]->getDataPoolId(); lp_id_t currentPoolId = registeredVariables[count]->getDataPoolId();
auto result = SerializeAdapter::serialize(&currentPoolId, buffer, auto result = SerializeAdapter::serialize(&currentPoolId, buffer,
size, maxSize, streamEndianness); size, maxSize, streamEndianness);
if(result != HasReturnvaluesIF::RETURN_OK) { if(result != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "LocalPoolDataSetBase::serializeLocalPoolIds: " sif::warning << "LocalPoolDataSetBase::serializeLocalPoolIds: "
<< "Serialization error!" << std::endl; << "Serialization error!" << std::endl;
#else #else
sif::printWarning("LocalPoolDataSetBase::serializeLocalPoolIds: " sif::printWarning("LocalPoolDataSetBase::serializeLocalPoolIds: "
"Serialization error!\n\r"); "Serialization error!\n\r");
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
return result; return result;
} }
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
uint8_t LocalPoolDataSetBase::getLocalPoolIdsSerializedSize( uint8_t LocalPoolDataSetBase::getLocalPoolIdsSerializedSize(
bool serializeFillCount) const { bool serializeFillCount) const {
if(serializeFillCount) { if(serializeFillCount) {
return fillCount * sizeof(lp_id_t) + sizeof(uint8_t); return fillCount * sizeof(lp_id_t) + sizeof(uint8_t);
} }
else { else {
return fillCount * sizeof(lp_id_t); return fillCount * sizeof(lp_id_t);
} }
} }
size_t LocalPoolDataSetBase::getSerializedSize() const { size_t LocalPoolDataSetBase::getSerializedSize() const {
if(withValidityBuffer) { if(withValidityBuffer) {
uint8_t validityMaskSize = std::ceil(static_cast<float>(fillCount)/8.0); uint8_t validityMaskSize = std::ceil(static_cast<float>(fillCount)/8.0);
return validityMaskSize + PoolDataSetBase::getSerializedSize(); return validityMaskSize + PoolDataSetBase::getSerializedSize();
} }
else { else {
return PoolDataSetBase::getSerializedSize(); return PoolDataSetBase::getSerializedSize();
} }
} }
void LocalPoolDataSetBase::setValidityBufferGeneration( void LocalPoolDataSetBase::setValidityBufferGeneration(
bool withValidityBuffer) { bool withValidityBuffer) {
this->withValidityBuffer = withValidityBuffer; this->withValidityBuffer = withValidityBuffer;
} }
ReturnValue_t LocalPoolDataSetBase::deSerialize(const uint8_t **buffer, ReturnValue_t LocalPoolDataSetBase::deSerialize(const uint8_t **buffer,
size_t *size, SerializeIF::Endianness streamEndianness) { size_t *size, SerializeIF::Endianness streamEndianness) {
if(withValidityBuffer) { if(withValidityBuffer) {
return this->deSerializeWithValidityBuffer(buffer, size, return this->deSerializeWithValidityBuffer(buffer, size,
streamEndianness); streamEndianness);
} }
else { else {
return PoolDataSetBase::deSerialize(buffer, size, streamEndianness); return PoolDataSetBase::deSerialize(buffer, size, streamEndianness);
} }
} }
ReturnValue_t LocalPoolDataSetBase::serialize(uint8_t **buffer, size_t *size, ReturnValue_t LocalPoolDataSetBase::serialize(uint8_t **buffer, size_t *size,
size_t maxSize, SerializeIF::Endianness streamEndianness) const { size_t maxSize, SerializeIF::Endianness streamEndianness) const {
if(withValidityBuffer) { if(withValidityBuffer) {
return this->serializeWithValidityBuffer(buffer, size, return this->serializeWithValidityBuffer(buffer, size,
maxSize, streamEndianness); maxSize, streamEndianness);
} }
else { else {
return PoolDataSetBase::serialize(buffer, size, maxSize, return PoolDataSetBase::serialize(buffer, size, maxSize,
streamEndianness); streamEndianness);
} }
} }
void LocalPoolDataSetBase::bitSetter(uint8_t* byte, uint8_t position) const { void LocalPoolDataSetBase::bitSetter(uint8_t* byte, uint8_t position) const {
if(position > 7) { if(position > 7) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "LocalPoolDataSetBase::bitSetter: Invalid position!" sif::warning << "LocalPoolDataSetBase::bitSetter: Invalid position!"
<< std::endl; << std::endl;
#else #else
sif::printWarning("LocalPoolDataSetBase::bitSetter: " sif::printWarning("LocalPoolDataSetBase::bitSetter: "
"Invalid position!\n\r"); "Invalid position!\n\r");
#endif #endif
return; return;
} }
uint8_t shiftNumber = position + (7 - 2 * position); uint8_t shiftNumber = position + (7 - 2 * position);
*byte |= 1 << shiftNumber; *byte |= 1 << shiftNumber;
} }
void LocalPoolDataSetBase::setDiagnostic(bool isDiagnostics) { void LocalPoolDataSetBase::setDiagnostic(bool isDiagnostics) {
this->diagnostic = isDiagnostics; this->diagnostic = isDiagnostics;
} }
bool LocalPoolDataSetBase::isDiagnostics() const { bool LocalPoolDataSetBase::isDiagnostics() const {
return diagnostic; return diagnostic;
} }
void LocalPoolDataSetBase::setReportingEnabled(bool reportingEnabled) { void LocalPoolDataSetBase::setReportingEnabled(bool reportingEnabled) {
this->reportingEnabled = reportingEnabled; this->reportingEnabled = reportingEnabled;
} }
bool LocalPoolDataSetBase::getReportingEnabled() const { bool LocalPoolDataSetBase::getReportingEnabled() const {
return reportingEnabled; return reportingEnabled;
} }
void LocalPoolDataSetBase::initializePeriodicHelper( void LocalPoolDataSetBase::initializePeriodicHelper(
float collectionInterval, dur_millis_t minimumPeriodicInterval, float collectionInterval, dur_millis_t minimumPeriodicInterval,
bool isDiagnostics, uint8_t nonDiagIntervalFactor) { bool isDiagnostics, uint8_t nonDiagIntervalFactor) {
periodicHelper->initialize(collectionInterval, minimumPeriodicInterval, periodicHelper->initialize(collectionInterval, minimumPeriodicInterval,
isDiagnostics, nonDiagIntervalFactor); isDiagnostics, nonDiagIntervalFactor);
} }
void LocalPoolDataSetBase::setChanged(bool changed) { void LocalPoolDataSetBase::setChanged(bool changed) {
this->changed = changed; this->changed = changed;
} }
bool LocalPoolDataSetBase::hasChanged() const { bool LocalPoolDataSetBase::hasChanged() const {
return changed; return changed;
} }
sid_t LocalPoolDataSetBase::getSid() const { sid_t LocalPoolDataSetBase::getSid() const {
return sid; return sid;
} }
bool LocalPoolDataSetBase::bitGetter(const uint8_t* byte, bool LocalPoolDataSetBase::bitGetter(const uint8_t* byte,
uint8_t position) const { uint8_t position) const {
if(position > 7) { if(position > 7) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "Pool Raw Access: Bit setting invalid position" sif::debug << "Pool Raw Access: Bit setting invalid position"
<< std::endl; << std::endl;
#endif #endif
return false; return false;
} }
uint8_t shiftNumber = position + (7 - 2 * position); uint8_t shiftNumber = position + (7 - 2 * position);
return *byte & (1 << shiftNumber); return *byte & (1 << shiftNumber);
} }
bool LocalPoolDataSetBase::isValid() const { bool LocalPoolDataSetBase::isValid() const {
return this->valid; return this->valid;
} }
void LocalPoolDataSetBase::setValidity(bool valid, bool setEntriesRecursively) { void LocalPoolDataSetBase::setValidity(bool valid, bool setEntriesRecursively) {
if(setEntriesRecursively) { if(setEntriesRecursively) {
for(size_t idx = 0; idx < this->getFillCount(); idx++) { for(size_t idx = 0; idx < this->getFillCount(); idx++) {
registeredVariables[idx] -> setValid(valid); registeredVariables[idx] -> setValid(valid);
} }
} }
this->valid = valid; this->valid = valid;
} }
object_id_t LocalPoolDataSetBase::getCreatorObjectId() { object_id_t LocalPoolDataSetBase::getCreatorObjectId() {