2020-06-07 02:22:18 +02:00
|
|
|
#include <framework/datapoollocal/LocalDataPoolManager.h>
|
2020-05-17 01:17:11 +02:00
|
|
|
#include <framework/datapoollocal/LocalDataSet.h>
|
2020-06-19 14:25:03 +02:00
|
|
|
#include <framework/serialize/SerializeAdapter.h>
|
2020-05-17 01:17:11 +02:00
|
|
|
|
2020-06-19 03:03:17 +02:00
|
|
|
#include <cmath>
|
|
|
|
#include <cstring>
|
|
|
|
|
2020-07-02 16:54:53 +02:00
|
|
|
LocalDataSet::LocalDataSet(OwnsLocalDataPoolIF *hkOwner,
|
|
|
|
const size_t maxNumberOfVariables):
|
|
|
|
DataSetBase(poolVarList.data(), maxNumberOfVariables) {
|
|
|
|
poolVarList.reserve(maxNumberOfVariables);
|
|
|
|
poolVarList.resize(maxNumberOfVariables);
|
2020-06-19 03:03:17 +02:00
|
|
|
if(hkOwner == nullptr) {
|
|
|
|
sif::error << "LocalDataSet::LocalDataSet: Owner can't be nullptr!"
|
|
|
|
<< std::endl;
|
2020-07-02 16:54:53 +02:00
|
|
|
return;
|
2020-06-19 03:03:17 +02:00
|
|
|
}
|
|
|
|
hkManager = hkOwner->getHkManagerHandle();
|
2020-05-17 01:17:11 +02:00
|
|
|
}
|
|
|
|
|
2020-07-02 16:54:53 +02:00
|
|
|
LocalDataSet::LocalDataSet(object_id_t ownerId,
|
|
|
|
const size_t maxNumberOfVariables):
|
|
|
|
DataSetBase(poolVarList.data(), maxNumberOfVariables) {
|
|
|
|
poolVarList.reserve(maxNumberOfVariables);
|
|
|
|
poolVarList.resize(maxNumberOfVariables);
|
2020-06-19 03:03:17 +02:00
|
|
|
OwnsLocalDataPoolIF* hkOwner = objectManager->get<OwnsLocalDataPoolIF>(
|
|
|
|
ownerId);
|
|
|
|
if(hkOwner == nullptr) {
|
|
|
|
sif::error << "LocalDataSet::LocalDataSet: Owner can't be nullptr!"
|
|
|
|
<< std::endl;
|
2020-07-02 16:54:53 +02:00
|
|
|
return;
|
2020-06-19 03:03:17 +02:00
|
|
|
}
|
|
|
|
hkManager = hkOwner->getHkManagerHandle();
|
2020-05-17 01:17:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LocalDataSet::~LocalDataSet() {
|
|
|
|
}
|
|
|
|
|
2020-06-05 20:34:34 +02:00
|
|
|
ReturnValue_t LocalDataSet::lockDataPool(uint32_t timeoutMs) {
|
|
|
|
MutexIF* mutex = hkManager->getMutexHandle();
|
|
|
|
return mutex->lockMutex(timeoutMs);
|
2020-05-17 01:17:11 +02:00
|
|
|
}
|
|
|
|
|
2020-06-19 03:03:17 +02:00
|
|
|
ReturnValue_t LocalDataSet::serializeWithValidityBuffer(uint8_t **buffer,
|
|
|
|
size_t *size, const size_t maxSize, bool bigEndian) const {
|
|
|
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
uint8_t validityMaskSize = std::ceil(static_cast<float>(fillCount)/8.0);
|
|
|
|
uint8_t validityMask[validityMaskSize];
|
|
|
|
uint8_t validBufferIndex = 0;
|
|
|
|
uint8_t validBufferIndexBit = 0;
|
|
|
|
for (uint16_t count = 0; count < fillCount; count++) {
|
|
|
|
if(registeredVariables[count]->isValid()) {
|
|
|
|
// set validity buffer here.
|
|
|
|
this->bitSetter(validityMask + validBufferIndex,
|
2020-06-30 00:48:48 +02:00
|
|
|
validBufferIndexBit);
|
2020-06-19 03:03:17 +02:00
|
|
|
if(validBufferIndexBit == 7) {
|
|
|
|
validBufferIndex ++;
|
|
|
|
validBufferIndexBit = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
validBufferIndexBit ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = registeredVariables[count]->serialize(buffer, size, maxSize,
|
|
|
|
bigEndian);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// copy validity buffer to end
|
|
|
|
std::memcpy(*buffer, validityMask, validityMaskSize);
|
|
|
|
*size += validityMaskSize;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-05-17 01:17:11 +02:00
|
|
|
ReturnValue_t LocalDataSet::unlockDataPool() {
|
2020-06-05 20:34:34 +02:00
|
|
|
MutexIF* mutex = hkManager->getMutexHandle();
|
|
|
|
return mutex->unlockMutex();
|
2020-05-17 01:17:11 +02:00
|
|
|
}
|
|
|
|
|
2020-06-19 14:25:03 +02:00
|
|
|
ReturnValue_t LocalDataSet::serializeLocalPoolIds(uint8_t** buffer,
|
|
|
|
size_t* size, const size_t maxSize, bool bigEndian) const {
|
|
|
|
for (uint16_t count = 0; count < fillCount; count++) {
|
|
|
|
lp_id_t currentPoolId = registeredVariables[count]->getDataPoolId();
|
|
|
|
auto result = AutoSerializeAdapter::serialize(¤tPoolId, buffer,
|
|
|
|
size, maxSize, bigEndian);
|
|
|
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
sif::warning << "LocalDataSet::serializeLocalPoolIds: Serialization"
|
|
|
|
" error!" << std::endl;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2020-06-30 00:48:48 +02:00
|
|
|
void LocalDataSet::bitSetter(uint8_t* byte, uint8_t position) const {
|
2020-06-19 03:03:17 +02:00
|
|
|
if(position > 7) {
|
|
|
|
sif::debug << "Pool Raw Access: Bit setting invalid position" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint8_t shiftNumber = position + (7 - 2 * position);
|
2020-06-30 00:48:48 +02:00
|
|
|
*byte |= 1 << shiftNumber;
|
2020-06-19 03:03:17 +02:00
|
|
|
}
|
2020-05-17 01:17:11 +02:00
|
|
|
|