fsfw/datapool/PoolRawAccessHelper.cpp

104 lines
3.6 KiB
C++
Raw Normal View History

2019-12-24 01:41:04 +01:00
/**
* @file PoolRawAccessHelper.cpp
*
* @date 22.12.2019
2019-12-24 22:15:39 +01:00
* @author R. Mueller
2019-12-24 01:41:04 +01:00
*/
#include <framework/datapool/PoolRawAccessHelper.h>
PoolRawAccessHelper::PoolRawAccessHelper(DataSet *dataSet_,
const uint8_t * poolIdBuffer_, uint8_t numberOfParameters_):
dataSet(dataSet_), poolIdBuffer(poolIdBuffer_),
2019-12-24 22:15:39 +01:00
numberOfParameters(numberOfParameters_), validBufferIndex(0), validBufferIndexBit(1){
2019-12-24 01:41:04 +01:00
}
PoolRawAccessHelper::~PoolRawAccessHelper() {
}
ReturnValue_t PoolRawAccessHelper::serialize(uint8_t **buffer, uint32_t *size,
const uint32_t max_size, bool bigEndian) {
2019-12-24 22:15:39 +01:00
ReturnValue_t result;
2019-12-24 01:41:04 +01:00
const uint8_t ** pPoolIdBuffer = &poolIdBuffer;
int32_t remainingParametersSize = numberOfParameters * 4;
for(uint8_t count=0; count < numberOfParameters; count++) {
2019-12-24 22:15:39 +01:00
result = serializeCurrentPoolEntryIntoBuffer(pPoolIdBuffer,buffer,
2019-12-24 01:41:04 +01:00
&remainingParametersSize,size,max_size, bigEndian, false);
2019-12-24 22:15:39 +01:00
if(result != RETURN_OK) {
return result;
}
2019-12-24 01:41:04 +01:00
}
return RETURN_OK;
}
ReturnValue_t PoolRawAccessHelper::serializeWithValidityMask(uint8_t **buffer,
uint32_t *size, const uint32_t max_size, bool bigEndian) {
2019-12-24 22:15:39 +01:00
ReturnValue_t result;
const uint8_t ** pPoolIdBuffer = &poolIdBuffer;
int32_t remainingParametersSize = numberOfParameters * 4;
uint8_t validityMaskSize = numberOfParameters/8;
uint8_t validityMask[validityMaskSize];
memset(validityMask,0, validityMaskSize);
for(uint8_t count=0; count < numberOfParameters; count++) {
result = serializeCurrentPoolEntryIntoBuffer(pPoolIdBuffer,buffer,
&remainingParametersSize,size,max_size, bigEndian,true,validityMask);
if (result != RETURN_OK) {
return result;
}
}
memcpy(*buffer + *size, validityMask, validityMaskSize);
*size += validityMaskSize;
validBufferIndex = 1;
validBufferIndexBit = 0;
2019-12-24 01:41:04 +01:00
return RETURN_OK;
}
2019-12-24 22:15:39 +01:00
ReturnValue_t PoolRawAccessHelper::serializeCurrentPoolEntryIntoBuffer(const uint8_t ** pPoolIdBuffer,
2019-12-24 01:41:04 +01:00
uint8_t ** buffer, int32_t * remainingParameters, uint32_t * hkDataSize,
2019-12-24 22:15:39 +01:00
const uint32_t max_size, bool bigEndian, bool withValidMask, uint8_t * validityMask) {
2019-12-24 01:41:04 +01:00
uint32_t currentPoolId;
// Deserialize current pool ID from pool ID buffer
ReturnValue_t result = AutoSerializeAdapter::deSerialize(&currentPoolId,
pPoolIdBuffer,remainingParameters,true);
if(result != RETURN_OK) {
debug << std::hex << "Pool Raw Access Helper: Error deSeralizing pool IDs" << std::dec << std::endl;
2019-12-24 22:15:39 +01:00
return result;
2019-12-24 01:41:04 +01:00
}
PoolRawAccess currentPoolRawAccess(currentPoolId,0,dataSet,PoolVariableIF::VAR_READ);
2019-12-24 22:15:39 +01:00
// set valid mask bit if necessary
if(withValidMask) {
if(currentPoolRawAccess.isValid()) {
validityMask[validBufferIndex] =
bitSetter(validityMask[validBufferIndex], validBufferIndexBit, true);
validBufferIndexBit ++;
if(validBufferIndexBit == 8) {
validBufferIndex ++;
validBufferIndexBit = 1;
}
}
}
result = dataSet->read();
2019-12-24 01:41:04 +01:00
if (result != RETURN_OK) {
debug << std::hex << "Pool Raw Access Helper: Error read raw dataset" << std::dec << std::endl;
2019-12-24 22:15:39 +01:00
return result;
2019-12-24 01:41:04 +01:00
}
result = dataSet->serialize(buffer, hkDataSize,
max_size, bigEndian);
if (result != RETURN_OK) {
2019-12-24 22:15:39 +01:00
debug << "Pool Raw Access Helper: Error serializing pool data into send buffer" << std::endl;
2019-12-24 01:41:04 +01:00
}
2019-12-24 22:15:39 +01:00
return result;
2019-12-24 01:41:04 +01:00
}
uint8_t PoolRawAccessHelper::bitSetter(uint8_t byte, uint8_t position, bool value) {
if(position < 1 or position > 8) {
debug << "Pool Raw Access: Bit setting invalid position" << std::endl;
return byte;
}
uint8_t shiftNumber = position + (6 - 2 * (position - 1));
byte = (byte | value) << shiftNumber;
return byte;
}