pool raw access modified so vectors are properly serialized now

Endian swapper can swap the entries of a uint16,uint32 buffers now.
Some documentation for functions added. setter function for serial buffer
adapter written but does not appear to compile, commented out
This commit is contained in:
Robin Müller 2019-12-09 12:27:14 +01:00
parent 8168885dd9
commit e765f8c99b
6 changed files with 62 additions and 11 deletions

View File

@ -31,7 +31,10 @@ ReturnValue_t PoolRawAccess::read() {
sizeTillEnd = read_out->getByteSize() - arrayPosition; sizeTillEnd = read_out->getByteSize() - arrayPosition;
uint8_t* ptr = uint8_t* ptr =
&((uint8_t*) read_out->getRawData())[arrayPosition]; &((uint8_t*) read_out->getRawData())[arrayPosition];
memcpy(value, ptr, typeSize); for(uint8_t arrayCount = 0; arrayCount < arraySize; arrayCount++) {
memcpy(value + typeSize * arrayCount, ptr + typeSize * arrayCount, typeSize);
}
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} else { } else {
//Error value type too large. //Error value type too large.
@ -152,17 +155,20 @@ ReturnValue_t PoolRawAccess::serialize(uint8_t** buffer, uint32_t* size,
#ifndef BYTE_ORDER_SYSTEM #ifndef BYTE_ORDER_SYSTEM
#error BYTE_ORDER_SYSTEM not defined #error BYTE_ORDER_SYSTEM not defined
#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN #elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
for (uint8_t count = 0; count < typeSize; count++) { for(uint8_t arrayCount = 0; arrayCount < arraySize; arrayCount++) {
(*buffer)[count] = value[typeSize - count - 1]; for (uint8_t count = 0; count < typeSize; count++) {
(*buffer)[typeSize * (arrayCount + 1) - count - 1] =
value[typeSize * arrayCount + count];
}
} }
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN #elif BYTE_ORDER_SYSTEM == BIG_ENDIAN
memcpy(*buffer, value, typeSize); memcpy(*buffer, value, typeSize * arraySize);
#endif #endif
} else { } else {
memcpy(*buffer, value, typeSize); memcpy(*buffer, value, typeSize * arraySize);
} }
*size += typeSize; *size += typeSize * arraySize;
(*buffer) += typeSize; (*buffer) += typeSize * arraySize;
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} else { } else {
return SerializeIF::BUFFER_TOO_SHORT; return SerializeIF::BUFFER_TOO_SHORT;

View File

@ -48,7 +48,6 @@ private:
ReadWriteMode_t readWriteMode; ReadWriteMode_t readWriteMode;
static const uint8_t RAW_MAX_SIZE = sizeof(double); static const uint8_t RAW_MAX_SIZE = sizeof(double);
protected: protected:
/** /**
* \brief The commit call writes back the variable's value to the data pool. * \brief The commit call writes back the variable's value to the data pool.
* \details It checks type and size, as well as if the variable is writable. If so, * \details It checks type and size, as well as if the variable is writable. If so,
@ -80,6 +79,20 @@ public:
* The operation does NOT provide any mutual exclusive protection by itself. * The operation does NOT provide any mutual exclusive protection by itself.
*/ */
ReturnValue_t read(); ReturnValue_t read();
/**
* @brief Serialize raw pool entry into provided buffer directly
* @details Should be called after read() call. Endianness can be specified too
* @param buffer Provided buffer. Raw pool data will be copied here
* @param size [out] Increment provided size value by serialized size
* @param max_size Maximum allowed serialization size
* @param bigEndian Specify endianess
* @return - @c RETURN_OK if serialization was successfull
* - @c SerializeIF::BUFFER_TOO_SHORT if range check failed
*/
ReturnValue_t serialize(uint8_t** buffer, uint32_t* size,
const uint32_t max_size, bool bigEndian) const;
/** /**
* \brief This operation returns a pointer to the entry fetched. * \brief This operation returns a pointer to the entry fetched.
* \details Return pointer to the buffer containing the raw data * \details Return pointer to the buffer containing the raw data
@ -142,9 +155,6 @@ public:
*/ */
uint16_t getSizeTillEnd() const; uint16_t getSizeTillEnd() const;
ReturnValue_t serialize(uint8_t** buffer, uint32_t* size,
const uint32_t max_size, bool bigEndian) const;
uint32_t getSerializedSize() const; uint32_t getSerializedSize() const;
ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size,

View File

@ -44,6 +44,27 @@ public:
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN #elif BYTE_ORDER_SYSTEM == BIG_ENDIAN
memcpy(out, in, size); memcpy(out, in, size);
return; return;
#endif
}
template<typename T>
static void swap(T * out, const T * in, uint32_t size) {
#ifndef BYTE_ORDER_SYSTEM
#error BYTE_ORDER_SYSTEM not defined
#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
const uint8_t * in_buffer = reinterpret_cast<const uint8_t *>(in);
uint8_t * out_buffer = reinterpret_cast<uint8_t *>(out);
for (uint8_t count = 0; count < size; count++) {
for(uint8_t i = 0; i < sizeof(T);i++) {
out_buffer[sizeof(T)* (count + 1) - i - 1] = in_buffer[count * sizeof(T) + i];
}
}
return;
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN
memcpy(out, in, size*sizeof(T));
return;
#endif #endif
} }
}; };

View File

@ -96,6 +96,11 @@ uint8_t * SerialBufferAdapter<T>::getBuffer() {
return buffer; return buffer;
} }
//template<typename T>
//void SerialBufferAdapter<T>::setBuffer(uint8_t * buffer_) {
// buffer = buffer_;
//}
//forward Template declaration for linker //forward Template declaration for linker
template class SerialBufferAdapter<uint8_t>; template class SerialBufferAdapter<uint8_t>;
template class SerialBufferAdapter<uint16_t>; template class SerialBufferAdapter<uint16_t>;

View File

@ -56,6 +56,7 @@ public:
bool bigEndian); bool bigEndian);
uint8_t * getBuffer(); uint8_t * getBuffer();
//void setBuffer(uint8_t * buffer_);
private: private:
bool serializeLength; bool serializeLength;
const uint8_t *constBuffer; const uint8_t *constBuffer;

View File

@ -76,6 +76,14 @@ public:
} }
} }
/**
* Deserialize buffer into object
* @param object [out] Object to be deserialized with buffer data
* @param buffer buffer containing the data
* @param size int32_t type to allow value to be values smaller than 0, needed for range/size checking
* @param bigEndian Specify endianness
* @return
*/
ReturnValue_t deSerialize(T* object, const uint8_t** buffer, int32_t* size, ReturnValue_t deSerialize(T* object, const uint8_t** buffer, int32_t* size,
bool bigEndian) { bool bigEndian) {
T tmp; T tmp;