2020-09-05 21:51:17 +02:00
|
|
|
#ifndef FSFW_DATAPOOLGLOB_GLOBALPOOLVECTOR_TPP_
|
|
|
|
#define FSFW_DATAPOOLGLOB_GLOBALPOOLVECTOR_TPP_
|
2020-05-17 22:16:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
template<typename T, uint16_t vectorSize>
|
|
|
|
inline GlobPoolVector<T, vectorSize>::GlobPoolVector(uint32_t set_id,
|
|
|
|
DataSetIF* set, ReadWriteMode_t setReadWriteMode) :
|
|
|
|
dataPoolId(set_id), valid(false), readWriteMode(setReadWriteMode) {
|
|
|
|
memset(this->value, 0, vectorSize * sizeof(T));
|
|
|
|
if (set != nullptr) {
|
|
|
|
set->registerVariable(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-05 20:33:57 +02:00
|
|
|
|
|
|
|
template<typename T, uint16_t vectorSize>
|
|
|
|
inline ReturnValue_t GlobPoolVector<T, vectorSize>::read(uint32_t lockTimeout) {
|
|
|
|
ReturnValue_t result = glob::dataPool.lockDataPool(lockTimeout);
|
|
|
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = readWithoutLock();
|
|
|
|
ReturnValue_t unlockResult = glob::dataPool.unlockDataPool();
|
|
|
|
if(unlockResult != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
sif::error << "GlobPoolVar::read: Could not unlock global data pool"
|
|
|
|
<< std::endl;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, uint16_t vectorSize>
|
|
|
|
inline ReturnValue_t GlobPoolVector<T, vectorSize>::commit(
|
|
|
|
uint32_t lockTimeout) {
|
|
|
|
ReturnValue_t result = glob::dataPool.lockDataPool(lockTimeout);
|
|
|
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = commitWithoutLock();
|
|
|
|
ReturnValue_t unlockResult = glob::dataPool.unlockDataPool();
|
|
|
|
if(unlockResult != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
sif::error << "GlobPoolVar::read: Could not unlock global data pool"
|
|
|
|
<< std::endl;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-05-17 22:16:25 +02:00
|
|
|
template<typename T, uint16_t vectorSize>
|
2020-06-05 20:33:57 +02:00
|
|
|
inline ReturnValue_t GlobPoolVector<T, vectorSize>::readWithoutLock() {
|
2020-05-17 22:16:25 +02:00
|
|
|
PoolEntry<T>* read_out = glob::dataPool.getData<T>(this->dataPoolId,
|
|
|
|
vectorSize);
|
|
|
|
if (read_out != nullptr) {
|
|
|
|
this->valid = read_out->valid;
|
|
|
|
memcpy(this->value, read_out->address, read_out->getByteSize());
|
|
|
|
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
memset(this->value, 0, vectorSize * sizeof(T));
|
|
|
|
sif::error << "PoolVector: Read of DP Variable 0x" << std::hex
|
|
|
|
<< std::setw(8) << std::setfill('0') << dataPoolId <<
|
|
|
|
std::dec << " failed." << std::endl;
|
|
|
|
this->valid = INVALID;
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, uint16_t vectorSize>
|
2020-06-05 20:33:57 +02:00
|
|
|
inline ReturnValue_t GlobPoolVector<T, vectorSize>::commitWithoutLock() {
|
2020-05-17 22:16:25 +02:00
|
|
|
PoolEntry<T>* writeBack = glob::dataPool.getData<T>(this->dataPoolId,
|
|
|
|
vectorSize);
|
|
|
|
if ((writeBack != nullptr) && (this->readWriteMode != VAR_READ)) {
|
|
|
|
writeBack->valid = valid;
|
|
|
|
memcpy(writeBack->address, this->value, writeBack->getByteSize());
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
} else {
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, uint16_t vectorSize>
|
|
|
|
inline ReturnValue_t GlobPoolVector<T, vectorSize>::serialize(uint8_t** buffer,
|
2020-07-01 14:17:55 +02:00
|
|
|
size_t* size, size_t max_size,
|
|
|
|
SerializeIF::Endianness streamEndianness) const {
|
2020-05-17 22:16:25 +02:00
|
|
|
uint16_t i;
|
|
|
|
ReturnValue_t result;
|
|
|
|
for (i = 0; i < vectorSize; i++) {
|
2020-07-01 14:17:55 +02:00
|
|
|
result = SerializeAdapter::serialize(&(value[i]), buffer, size,
|
|
|
|
max_size, streamEndianness);
|
2020-05-17 22:16:25 +02:00
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, uint16_t vectorSize>
|
|
|
|
inline size_t GlobPoolVector<T, vectorSize>::getSerializedSize() const {
|
2020-07-01 14:17:55 +02:00
|
|
|
return vectorSize * SerializeAdapter::getSerializedSize(value);
|
2020-05-17 22:16:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, uint16_t vectorSize>
|
|
|
|
inline ReturnValue_t GlobPoolVector<T, vectorSize>::deSerialize(
|
2020-07-01 14:17:55 +02:00
|
|
|
const uint8_t** buffer, size_t* size,
|
|
|
|
SerializeIF::Endianness streamEndianness) {
|
2020-05-17 22:16:25 +02:00
|
|
|
uint16_t i;
|
|
|
|
ReturnValue_t result;
|
|
|
|
for (i = 0; i < vectorSize; i++) {
|
2020-07-01 14:17:55 +02:00
|
|
|
result = SerializeAdapter::deSerialize(&(value[i]), buffer, size,
|
|
|
|
streamEndianness);
|
2020-05-17 22:16:25 +02:00
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|