Pool Raw Access Helper tested, appesrs to work. SerializeAdapter doc

changes, tm packet stored debug output if not enough
storage available
This commit is contained in:
Robin Müller 2019-12-26 16:44:50 +01:00
parent 1f1831c4a1
commit e24f9b89e4
5 changed files with 55 additions and 40 deletions

View File

@ -6,10 +6,11 @@
*/
#include <framework/datapool/PoolRawAccessHelper.h>
#include <framework/datapool/DataSet.h>
PoolRawAccessHelper::PoolRawAccessHelper(DataSet *dataSet_,
const uint8_t * poolIdBuffer_, uint8_t numberOfParameters_):
dataSet(dataSet_), poolIdBuffer(poolIdBuffer_),
PoolRawAccessHelper::PoolRawAccessHelper(uint8_t * poolIdBuffer_,
uint8_t numberOfParameters_):
poolIdBuffer(poolIdBuffer_),
numberOfParameters(numberOfParameters_), validBufferIndex(0), validBufferIndexBit(1){
}
@ -19,52 +20,61 @@ PoolRawAccessHelper::~PoolRawAccessHelper() {
ReturnValue_t PoolRawAccessHelper::serialize(uint8_t **buffer, uint32_t *size,
const uint32_t max_size, bool bigEndian) {
ReturnValue_t result;
const uint8_t ** pPoolIdBuffer = &poolIdBuffer;
int32_t remainingParametersSize = numberOfParameters * 4;
for(uint8_t count=0; count < numberOfParameters; count++) {
result = serializeCurrentPoolEntryIntoBuffer(pPoolIdBuffer,buffer,
result = serializeCurrentPoolEntryIntoBuffer(buffer,
&remainingParametersSize,size,max_size, bigEndian, false);
if(result != RETURN_OK) {
return result;
}
}
return RETURN_OK;
if(remainingParametersSize != 0) {
debug << "Pool Raw Access: Remaining parameters size not 0 !" << std::endl;
result = RETURN_FAILED;
}
return result;
}
ReturnValue_t PoolRawAccessHelper::serializeWithValidityMask(uint8_t **buffer,
uint32_t *size, const uint32_t max_size, bool bigEndian) {
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,
for(uint8_t count = 0; count < numberOfParameters; count++) {
result = serializeCurrentPoolEntryIntoBuffer(buffer,
&remainingParametersSize,size,max_size, bigEndian,true,validityMask);
if (result != RETURN_OK) {
return result;
}
}
if(remainingParametersSize != 0) {
debug << "Pool Raw Access: Remaining parameters size not 0 !" << std::endl;
result = RETURN_FAILED;
}
memcpy(*buffer + *size, validityMask, validityMaskSize);
*size += validityMaskSize;
validBufferIndex = 1;
validBufferIndexBit = 0;
return RETURN_OK;
return result;
}
ReturnValue_t PoolRawAccessHelper::serializeCurrentPoolEntryIntoBuffer(const uint8_t ** pPoolIdBuffer,
uint8_t ** buffer, int32_t * remainingParameters, uint32_t * hkDataSize,
ReturnValue_t PoolRawAccessHelper::serializeCurrentPoolEntryIntoBuffer(uint8_t ** buffer,
int32_t * remainingParameters, uint32_t * hkDataSize,
const uint32_t max_size, bool bigEndian, bool withValidMask, uint8_t * validityMask) {
uint32_t currentPoolId;
DataSet currentDataSet = DataSet();
// Deserialize current pool ID from pool ID buffer
ReturnValue_t result = AutoSerializeAdapter::deSerialize(&currentPoolId,
pPoolIdBuffer,remainingParameters,true);
&poolIdBuffer,remainingParameters,true);
if(result != RETURN_OK) {
debug << std::hex << "Pool Raw Access Helper: Error deSeralizing pool IDs" << std::dec << std::endl;
return result;
}
PoolRawAccess currentPoolRawAccess(currentPoolId,0,dataSet,PoolVariableIF::VAR_READ);
// info << "Pool Raw Access Helper: Handling Pool ID: " << std::hex << currentPoolId << std::endl;
PoolRawAccess currentPoolRawAccess(currentPoolId,0,&currentDataSet,PoolVariableIF::VAR_READ);
// set valid mask bit if necessary
if(withValidMask) {
@ -79,12 +89,12 @@ ReturnValue_t PoolRawAccessHelper::serializeCurrentPoolEntryIntoBuffer(const uin
}
}
result = dataSet->read();
result = currentDataSet.read();
if (result != RETURN_OK) {
debug << std::hex << "Pool Raw Access Helper: Error read raw dataset" << std::dec << std::endl;
return result;
}
result = dataSet->serialize(buffer, hkDataSize,
result = currentDataSet.serialize(buffer, hkDataSize,
max_size, bigEndian);
if (result != RETURN_OK) {
debug << "Pool Raw Access Helper: Error serializing pool data into send buffer" << std::endl;

View File

@ -28,8 +28,7 @@ public:
* @param poolIdBuffer_ A buffer of uint32_t pool IDs
* @param numberOfParameters_ The number of parameters / pool IDs
*/
PoolRawAccessHelper(DataSet * dataSet_, const uint8_t * poolIdBuffer_,
uint8_t numberOfParameters_);
PoolRawAccessHelper(uint8_t * poolIdBuffer_, uint8_t numberOfParameters_);
virtual ~PoolRawAccessHelper();
/**
@ -60,7 +59,7 @@ public:
private:
DataSet * dataSet;
// DataSet * dataSet;
const uint8_t * poolIdBuffer;
uint8_t numberOfParameters;
@ -79,7 +78,7 @@ private:
* @param validityMask Can be supplied and will be set if @c withValidMask is set to true
* @return
*/
ReturnValue_t serializeCurrentPoolEntryIntoBuffer(const uint8_t ** pPoolIdBuffer,uint8_t ** buffer,
ReturnValue_t serializeCurrentPoolEntryIntoBuffer(uint8_t ** buffer,
int32_t * remainingParameters, uint32_t * hkDataSize,const uint32_t max_size,
bool bigEndian, bool withValidMask = false, uint8_t * validityMask = NULL);

View File

@ -89,23 +89,24 @@ MessageQueueId_t MessageQueue::getDefaultDestination() const {
bool MessageQueue::isDefaultDestinationSet() const {
return 0;
}
ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
MessageQueueMessage *message, MessageQueueId_t sentFrom,
bool ignoreFault) {
message->setSender(sentFrom);
BaseType_t result = xQueueSendToBack(reinterpret_cast<void*>(sendTo),reinterpret_cast<const void*>(message->getBuffer()), 0);
if (result != pdPASS) {
if (!ignoreFault) {
InternalErrorReporterIF* internalErrorReporter = objectManager->get<InternalErrorReporterIF>(
objects::INTERNAL_ERROR_REPORTER);
if (internalErrorReporter != NULL) {
internalErrorReporter->queueMessageNotSent();
}
BaseType_t result = xQueueSendToBack(reinterpret_cast<void*>(sendTo),reinterpret_cast<const void*>(message->getBuffer()), 0);
if (result != pdPASS) {
if (!ignoreFault) {
InternalErrorReporterIF* internalErrorReporter = objectManager->get<InternalErrorReporterIF>(
objects::INTERNAL_ERROR_REPORTER);
if (internalErrorReporter != NULL) {
internalErrorReporter->queueMessageNotSent();
}
return MessageQueueIF::FULL;
}
return HasReturnvaluesIF::RETURN_OK;
return MessageQueueIF::FULL;
}
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -10,7 +10,7 @@
/**
* @brief This adapter provides an interface to use the SerializeIF functions
* with arbitrary template objects to facilitate and simplify the serialization of classes
* with different multiple different data types into buffers vice-versa.
* with different multiple different data types into buffers and vice-versa.
* @details
* Examples:
* A report class is converted into a TM buffer. The report class implements a serialize functions and calls
@ -20,27 +20,31 @@
*
* The AutoSerializeAdapter functions can also be used as an alternative to memcpy
* to retrieve data out of a buffer directly into a class variable with data type T while being able to specify endianness.
* The boolean bigEndian specifies the endiness of the data to serialize or deSerialize.
* The boolean bigEndian specifies whether an endian swap is performed on the data before
* serialization or deserialization.
*
* If the target architecture is little endian (ARM), any data types created might
* have the wrong endiness if they are to be used for the FSFW.
* there are three ways to retrieve data out of a buffer to be used in the FSFW to use regular aligned (big endian) data.
* There are three ways to retrieve data out of a buffer to be used in the FSFW
* to use regular aligned (big endian) data.
* This can also be applied to uint32_t and uint64_t:
*
* 1. Use the AutoSerializeAdapter::deSerialize function with bool bigEndian = true:
* The pointer *buffer will be incremented automatically by the typeSize of data,
* so this function can be called on &buffer without adjusting pointer position
* 1. Use the AutoSerializeAdapter::deSerialize function
* The pointer *buffer will be incremented automatically by the typeSize of the object,
* so this function can be called on &buffer repeatedly without adjusting pointer position.
* Set bigEndian parameter to true to perform endian swapping.
*
* uint16_t data;
* int32_t dataLen = sizeof(data);
* ReturnValue_t result = AutoSerializeAdapter::deSerialize(&data,&buffer,&dataLen,true);
*
* 2. Perform a bitshift operation:
* 2. Perform a bitshift operation. Perform endian swapping if necessary:
*
* uint16_t data;
* data = buffer[targetByte1] >> 8 | buffer[targetByte2];
* data = buffer[targetByte1] << 8 | buffer[targetByte2];
* data = EndianSwapper::swap(data);
*
* 3. Memcpy can be used when data is little-endian. Otherwise, endian-swapper has to be used.
* 3. Memcpy can be used when data is little-endian. Perform endian-swapping if necessary.
*
* uint16_t data;
* memcpy(&data,buffer + positionOfTargetByte1,sizeof(data));
@ -79,7 +83,7 @@ public:
/**
* Deserialize buffer into object
* @param object [out] Object to be deserialized with buffer data
* @param buffer buffer containing the data
* @param buffer buffer containing the data. Non-Const pointer to non-const pointer to const buffer.
* @param size int32_t type to allow value to be values smaller than 0, needed for range/size checking
* @param bigEndian Specify endianness
* @return

View File

@ -22,6 +22,7 @@ TmPacketStored::TmPacketStored(uint16_t apid, uint8_t service,
(TmPacketBase::TM_PACKET_MIN_SIZE + size + headerSize), &pData);
if (returnValue != store->RETURN_OK) {
debug << "TM Packet Stored: Issue getting free storage" << std::endl;
checkAndReportLostTm();
return;
}