Reworked PoolRawAccess to use EndianConverter instead of converting by itself
This commit is contained in:
parent
89accf8940
commit
45430e8586
@ -2,12 +2,13 @@
|
||||
#include <framework/datapool/PoolEntryIF.h>
|
||||
#include <framework/datapool/PoolRawAccess.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
#include <framework/osal/Endiness.h>
|
||||
#include <framework/serialize/EndianConverter.h>
|
||||
|
||||
PoolRawAccess::PoolRawAccess(uint32_t set_id, uint8_t setArrayEntry,
|
||||
DataSetIF *data_set, ReadWriteMode_t setReadWriteMode) :
|
||||
dataPoolId(set_id), arrayEntry(setArrayEntry), valid(false), type(Type::UNKNOWN_TYPE), typeSize(
|
||||
0), arraySize(0), sizeTillEnd(0), readWriteMode(setReadWriteMode) {
|
||||
dataPoolId(set_id), arrayEntry(setArrayEntry), valid(false), type(
|
||||
Type::UNKNOWN_TYPE), typeSize(0), arraySize(0), sizeTillEnd(0), readWriteMode(
|
||||
setReadWriteMode) {
|
||||
memset(value, 0, sizeof(value));
|
||||
if (data_set != NULL) {
|
||||
data_set->registerVariable(this);
|
||||
@ -42,8 +43,8 @@ ReturnValue_t PoolRawAccess::read() {
|
||||
} else {
|
||||
//Error entry does not exist.
|
||||
}
|
||||
sif::error << "PoolRawAccess: read of DP Variable 0x" << std::hex << dataPoolId
|
||||
<< std::dec << " failed." << std::endl;
|
||||
sif::error << "PoolRawAccess: read of DP Variable 0x" << std::hex
|
||||
<< dataPoolId << std::dec << " failed." << std::endl;
|
||||
valid = INVALID;
|
||||
typeSize = 0;
|
||||
sizeTillEnd = 0;
|
||||
@ -69,22 +70,16 @@ uint8_t* PoolRawAccess::getEntry() {
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::getEntryEndianSafe(uint8_t *buffer,
|
||||
uint32_t* writtenBytes, uint32_t maxSize) {
|
||||
size_t *writtenBytes, size_t maxSize) {
|
||||
uint8_t *data_ptr = getEntry();
|
||||
// debug << "PoolRawAccess::getEntry: Array position: " << index * size_of_type << " Size of T: " << (int)size_of_type << " ByteSize: " << byte_size << " Position: " << *size << std::endl;
|
||||
if (typeSize == 0)
|
||||
if (typeSize == 0) {
|
||||
return DATA_POOL_ACCESS_FAILED;
|
||||
if (typeSize > maxSize)
|
||||
return INCORRECT_SIZE;
|
||||
#ifndef BYTE_ORDER_SYSTEM
|
||||
#error BYTE_ORDER_SYSTEM not defined
|
||||
#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
|
||||
for (uint8_t count = 0; count < typeSize; count++) {
|
||||
buffer[count] = data_ptr[typeSize - count - 1];
|
||||
}
|
||||
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN
|
||||
memcpy(buffer, data_ptr, typeSize);
|
||||
#endif
|
||||
if (typeSize > maxSize) {
|
||||
return INCORRECT_SIZE;
|
||||
}
|
||||
EndianConverter::convertBigEndian(buffer, data_ptr, typeSize);
|
||||
*writtenBytes = typeSize;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
@ -93,11 +88,11 @@ Type PoolRawAccess::getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
uint8_t PoolRawAccess::getSizeOfType() {
|
||||
size_t PoolRawAccess::getSizeOfType() {
|
||||
return typeSize;
|
||||
}
|
||||
|
||||
uint8_t PoolRawAccess::getArraySize(){
|
||||
size_t PoolRawAccess::getArraySize() {
|
||||
return arraySize;
|
||||
}
|
||||
|
||||
@ -110,20 +105,13 @@ PoolVariableIF::ReadWriteMode_t PoolRawAccess::getReadWriteMode() const {
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::setEntryFromBigEndian(const uint8_t *buffer,
|
||||
uint32_t setSize) {
|
||||
size_t setSize) {
|
||||
if (typeSize == setSize) {
|
||||
#ifndef BYTE_ORDER_SYSTEM
|
||||
#error BYTE_ORDER_SYSTEM not defined
|
||||
#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
|
||||
for (uint8_t count = 0; count < typeSize; count++) {
|
||||
value[count] = buffer[typeSize - count - 1];
|
||||
}
|
||||
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN
|
||||
memcpy(value, buffer, typeSize);
|
||||
#endif
|
||||
EndianConverter::convertBigEndian(value, buffer, typeSize);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
sif::error << "PoolRawAccess::setEntryFromBigEndian: Illegal sizes: Internal"
|
||||
sif::error
|
||||
<< "PoolRawAccess::setEntryFromBigEndian: Illegal sizes: Internal"
|
||||
<< (uint32_t) typeSize << ", Requested: " << setSize
|
||||
<< std::endl;
|
||||
return INCORRECT_SIZE;
|
||||
@ -141,27 +129,24 @@ void PoolRawAccess::setValid(uint8_t valid) {
|
||||
this->valid = valid;
|
||||
}
|
||||
|
||||
uint16_t PoolRawAccess::getSizeTillEnd() const {
|
||||
size_t PoolRawAccess::getSizeTillEnd() const {
|
||||
return sizeTillEnd;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::serialize(uint8_t **buffer, size_t *size,
|
||||
size_t maxSize, Endianness streamEndianness) const {
|
||||
//TODO integer overflow
|
||||
if (typeSize + *size <= maxSize) {
|
||||
#warning use endian swapper
|
||||
if (1) {
|
||||
#ifndef BYTE_ORDER_SYSTEM
|
||||
#error BYTE_ORDER_SYSTEM not defined
|
||||
#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
|
||||
for (uint8_t count = 0; count < typeSize; count++) {
|
||||
(*buffer)[count] = value[typeSize - count - 1];
|
||||
}
|
||||
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN
|
||||
memcpy(*buffer, value, typeSize);
|
||||
#endif
|
||||
} else {
|
||||
switch (streamEndianness) {
|
||||
case (Endianness::BIG):
|
||||
EndianConverter::convertBigEndian(*buffer, value, typeSize);
|
||||
break;
|
||||
case (Endianness::LITTLE):
|
||||
EndianConverter::convertLittleEndian(*buffer, value, typeSize);
|
||||
break;
|
||||
default:
|
||||
case (Endianness::MACHINE):
|
||||
memcpy(*buffer, value, typeSize);
|
||||
break;
|
||||
}
|
||||
*size += typeSize;
|
||||
(*buffer) += typeSize;
|
||||
@ -179,20 +164,19 @@ ReturnValue_t PoolRawAccess::deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) {
|
||||
|
||||
if (*size >= typeSize) {
|
||||
switch (streamEndianness) {
|
||||
case (Endianness::BIG):
|
||||
EndianConverter::convertBigEndian(value, *buffer, typeSize);
|
||||
break;
|
||||
case (Endianness::LITTLE):
|
||||
EndianConverter::convertLittleEndian(value, *buffer, typeSize);
|
||||
break;
|
||||
default:
|
||||
case (Endianness::MACHINE):
|
||||
memcpy(value, *buffer, typeSize);
|
||||
break;
|
||||
}
|
||||
*size -= typeSize;
|
||||
if (1) {
|
||||
#ifndef BYTE_ORDER_SYSTEM
|
||||
#error BYTE_ORDER_SYSTEM not defined
|
||||
#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
|
||||
for (uint8_t count = 0; count < typeSize; count++) {
|
||||
value[count] = (*buffer)[typeSize - count - 1];
|
||||
}
|
||||
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN
|
||||
memcpy(value, *buffer, typeSize);
|
||||
#endif
|
||||
} else {
|
||||
memcpy(value, *buffer, typeSize);
|
||||
}
|
||||
*buffer += typeSize;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
|
@ -32,15 +32,15 @@ private:
|
||||
/**
|
||||
* \brief This value contains the size of the data pool entry in bytes.
|
||||
*/
|
||||
uint8_t typeSize;
|
||||
size_t typeSize;
|
||||
/**
|
||||
* The size of the DP array (single values return 1)
|
||||
*/
|
||||
uint8_t arraySize;
|
||||
size_t arraySize;
|
||||
/**
|
||||
* The size (in bytes) from the selected entry till the end of this DataPool variable.
|
||||
*/
|
||||
uint16_t sizeTillEnd;
|
||||
size_t sizeTillEnd;
|
||||
/**
|
||||
* \brief The information whether the class is read-write or read-only is stored here.
|
||||
*/
|
||||
@ -97,8 +97,8 @@ public:
|
||||
* \return - \c RETURN_OK if entry could be acquired
|
||||
* - \c RETURN_FAILED else.
|
||||
*/
|
||||
ReturnValue_t getEntryEndianSafe(uint8_t *buffer, uint32_t *size,
|
||||
uint32_t maxSize);
|
||||
ReturnValue_t getEntryEndianSafe(uint8_t *buffer, size_t *size,
|
||||
size_t maxSize);
|
||||
/**
|
||||
* With this method, the content can be set from a big endian buffer safely.
|
||||
* @param buffer Pointer to the data to set
|
||||
@ -107,7 +107,7 @@ public:
|
||||
* - \c RETURN_FAILED on failure
|
||||
*/
|
||||
ReturnValue_t setEntryFromBigEndian(const uint8_t *buffer,
|
||||
uint32_t setSize);
|
||||
size_t setSize);
|
||||
/**
|
||||
* \brief This operation returns the type of the entry currently stored.
|
||||
*/
|
||||
@ -115,12 +115,12 @@ public:
|
||||
/**
|
||||
* \brief This operation returns the size of the entry currently stored.
|
||||
*/
|
||||
uint8_t getSizeOfType();
|
||||
size_t getSizeOfType();
|
||||
/**
|
||||
*
|
||||
* @return the size of the datapool array
|
||||
*/
|
||||
uint8_t getArraySize();
|
||||
size_t getArraySize();
|
||||
/**
|
||||
* \brief This operation returns the data pool id of the variable.
|
||||
*/
|
||||
@ -138,7 +138,7 @@ public:
|
||||
/**
|
||||
* Getter for the remaining size.
|
||||
*/
|
||||
uint16_t getSizeTillEnd() const;
|
||||
size_t getSizeTillEnd() const;
|
||||
|
||||
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
|
||||
Endianness streamEndianness) const override;
|
||||
|
Loading…
Reference in New Issue
Block a user