Revert "renormalize CHB"

This reverts commit a4d9c761a7.
This commit is contained in:
Robin Müller 2020-09-01 11:51:43 +02:00
parent d644a40e14
commit 4abdc436fb
8 changed files with 2569 additions and 2569 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,117 +1,117 @@
#ifndef _sgp4unit_ #ifndef _sgp4unit_
#define _sgp4unit_ #define _sgp4unit_
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
* *
* sgp4unit.h * sgp4unit.h
* *
* this file contains the sgp4 procedures for analytical propagation * this file contains the sgp4 procedures for analytical propagation
* of a satellite. the code was originally released in the 1980 and 1986 * of a satellite. the code was originally released in the 1980 and 1986
* spacetrack papers. a detailed discussion of the theory and history * spacetrack papers. a detailed discussion of the theory and history
* may be found in the 2006 aiaa paper by vallado, crawford, hujsak, * may be found in the 2006 aiaa paper by vallado, crawford, hujsak,
* and kelso. * and kelso.
* *
* companion code for * companion code for
* fundamentals of astrodynamics and applications * fundamentals of astrodynamics and applications
* 2007 * 2007
* by david vallado * by david vallado
* *
* (w) 719-573-2600, email dvallado@agi.com * (w) 719-573-2600, email dvallado@agi.com
* *
* current : * current :
* 20 apr 07 david vallado * 20 apr 07 david vallado
* misc fixes for constants * misc fixes for constants
* changes : * changes :
* 11 aug 06 david vallado * 11 aug 06 david vallado
* chg lyddane choice back to strn3, constants, misc doc * chg lyddane choice back to strn3, constants, misc doc
* 15 dec 05 david vallado * 15 dec 05 david vallado
* misc fixes * misc fixes
* 26 jul 05 david vallado * 26 jul 05 david vallado
* fixes for paper * fixes for paper
* note that each fix is preceded by a * note that each fix is preceded by a
* comment with "sgp4fix" and an explanation of * comment with "sgp4fix" and an explanation of
* what was changed * what was changed
* 10 aug 04 david vallado * 10 aug 04 david vallado
* 2nd printing baseline working * 2nd printing baseline working
* 14 may 01 david vallado * 14 may 01 david vallado
* 2nd edition baseline * 2nd edition baseline
* 80 norad * 80 norad
* original baseline * original baseline
* ---------------------------------------------------------------- */ * ---------------------------------------------------------------- */
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
// -------------------------- structure declarations ---------------------------- // -------------------------- structure declarations ----------------------------
typedef enum typedef enum
{ {
wgs72old, wgs72old,
wgs72, wgs72,
wgs84 wgs84
} gravconsttype; } gravconsttype;
typedef struct elsetrec typedef struct elsetrec
{ {
long int satnum; long int satnum;
int epochyr, epochtynumrev; int epochyr, epochtynumrev;
int error; int error;
char init, method; char init, method;
/* Near Earth */ /* Near Earth */
int isimp; int isimp;
double aycof , con41 , cc1 , cc4 , cc5 , d2 , d3 , d4 , double aycof , con41 , cc1 , cc4 , cc5 , d2 , d3 , d4 ,
delmo , eta , argpdot, omgcof , sinmao , t , t2cof, t3cof , delmo , eta , argpdot, omgcof , sinmao , t , t2cof, t3cof ,
t4cof , t5cof , x1mth2 , x7thm1 , mdot , nodedot, xlcof , xmcof , t4cof , t5cof , x1mth2 , x7thm1 , mdot , nodedot, xlcof , xmcof ,
nodecf; nodecf;
/* Deep Space */ /* Deep Space */
int irez; int irez;
double d2201 , d2211 , d3210 , d3222 , d4410 , d4422 , d5220 , d5232 , double d2201 , d2211 , d3210 , d3222 , d4410 , d4422 , d5220 , d5232 ,
d5421 , d5433 , dedt , del1 , del2 , del3 , didt , dmdt , d5421 , d5433 , dedt , del1 , del2 , del3 , didt , dmdt ,
dnodt , domdt , e3 , ee2 , peo , pgho , pho , pinco , dnodt , domdt , e3 , ee2 , peo , pgho , pho , pinco ,
plo , se2 , se3 , sgh2 , sgh3 , sgh4 , sh2 , sh3 , plo , se2 , se3 , sgh2 , sgh3 , sgh4 , sh2 , sh3 ,
si2 , si3 , sl2 , sl3 , sl4 , gsto , xfact , xgh2 , si2 , si3 , sl2 , sl3 , sl4 , gsto , xfact , xgh2 ,
xgh3 , xgh4 , xh2 , xh3 , xi2 , xi3 , xl2 , xl3 , xgh3 , xgh4 , xh2 , xh3 , xi2 , xi3 , xl2 , xl3 ,
xl4 , xlamo , zmol , zmos , atime , xli , xni; xl4 , xlamo , zmol , zmos , atime , xli , xni;
double a , altp , alta , epochdays, jdsatepoch , nddot , ndot , double a , altp , alta , epochdays, jdsatepoch , nddot , ndot ,
bstar , rcse , inclo , nodeo , ecco , argpo , mo , bstar , rcse , inclo , nodeo , ecco , argpo , mo ,
no; no;
} elsetrec; } elsetrec;
// --------------------------- function declarations ---------------------------- // --------------------------- function declarations ----------------------------
int sgp4init int sgp4init
( (
gravconsttype whichconst, const int satn, const double epoch, gravconsttype whichconst, const int satn, const double epoch,
const double xbstar, const double xecco, const double xargpo, const double xbstar, const double xecco, const double xargpo,
const double xinclo, const double xmo, const double xno, const double xinclo, const double xmo, const double xno,
const double xnodeo, const double xnodeo,
elsetrec& satrec elsetrec& satrec
); );
int sgp4 int sgp4
( (
gravconsttype whichconst, gravconsttype whichconst,
elsetrec& satrec, double tsince, elsetrec& satrec, double tsince,
double r[], double v[] double r[], double v[]
); );
double gstime double gstime
( (
double double
); );
void getgravconst void getgravconst
( (
gravconsttype, gravconsttype,
double&, double&,
double&, double&,
double&, double&,
double&, double&,
double&, double&,
double&, double&,
double&, double&,
double& double&
); );
#endif #endif

View File

@ -1,45 +1,45 @@
#include "../subsystem/SubsystemBase.h" #include "../subsystem/SubsystemBase.h"
#include "../devicehandlers/ChildHandlerBase.h" #include "../devicehandlers/ChildHandlerBase.h"
#include "../subsystem/SubsystemBase.h" #include "../subsystem/SubsystemBase.h"
ChildHandlerBase::ChildHandlerBase(object_id_t setObjectId, ChildHandlerBase::ChildHandlerBase(object_id_t setObjectId,
object_id_t deviceCommunication, CookieIF * cookie, object_id_t deviceCommunication, CookieIF * cookie,
uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId, uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId,
object_id_t parent, FailureIsolationBase* customFdir, object_id_t parent, FailureIsolationBase* customFdir,
size_t cmdQueueSize) : size_t cmdQueueSize) :
DeviceHandlerBase(setObjectId, deviceCommunication, cookie, DeviceHandlerBase(setObjectId, deviceCommunication, cookie,
(customFdir == nullptr? &childHandlerFdir : customFdir), (customFdir == nullptr? &childHandlerFdir : customFdir),
cmdQueueSize), cmdQueueSize),
parentId(parent), childHandlerFdir(setObjectId) { parentId(parent), childHandlerFdir(setObjectId) {
this->setThermalStateRequestPoolIds(thermalStatePoolId, this->setThermalStateRequestPoolIds(thermalStatePoolId,
thermalRequestPoolId); thermalRequestPoolId);
} }
ChildHandlerBase::~ChildHandlerBase() { ChildHandlerBase::~ChildHandlerBase() {
} }
ReturnValue_t ChildHandlerBase::initialize() { ReturnValue_t ChildHandlerBase::initialize() {
ReturnValue_t result = DeviceHandlerBase::initialize(); ReturnValue_t result = DeviceHandlerBase::initialize();
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
return result; return result;
} }
MessageQueueId_t parentQueue = 0; MessageQueueId_t parentQueue = 0;
if (parentId != objects::NO_OBJECT) { if (parentId != objects::NO_OBJECT) {
SubsystemBase *parent = objectManager->get<SubsystemBase>(parentId); SubsystemBase *parent = objectManager->get<SubsystemBase>(parentId);
if (parent == NULL) { if (parent == NULL) {
return RETURN_FAILED; return RETURN_FAILED;
} }
parentQueue = parent->getCommandQueue(); parentQueue = parent->getCommandQueue();
parent->registerChild(getObjectId()); parent->registerChild(getObjectId());
} }
healthHelper.setParentQueue(parentQueue); healthHelper.setParentQueue(parentQueue);
modeHelper.setParentQueue(parentQueue); modeHelper.setParentQueue(parentQueue);
return RETURN_OK; return RETURN_OK;
} }

View File

@ -1,26 +1,26 @@
#ifndef FSFW_DEVICES_CHILDHANDLERBASE_H_ #ifndef FSFW_DEVICES_CHILDHANDLERBASE_H_
#define FSFW_DEVICES_CHILDHANDLERBASE_H_ #define FSFW_DEVICES_CHILDHANDLERBASE_H_
#include "ChildHandlerFDIR.h" #include "ChildHandlerFDIR.h"
#include "DeviceHandlerBase.h" #include "DeviceHandlerBase.h"
class ChildHandlerBase: public DeviceHandlerBase { class ChildHandlerBase: public DeviceHandlerBase {
public: public:
ChildHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication, ChildHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication,
CookieIF * cookie, uint32_t thermalStatePoolId, CookieIF * cookie, uint32_t thermalStatePoolId,
uint32_t thermalRequestPoolId, uint32_t thermalRequestPoolId,
object_id_t parent = objects::NO_OBJECT, object_id_t parent = objects::NO_OBJECT,
FailureIsolationBase* customFdir = nullptr, FailureIsolationBase* customFdir = nullptr,
size_t cmdQueueSize = 20); size_t cmdQueueSize = 20);
virtual ~ChildHandlerBase(); virtual ~ChildHandlerBase();
virtual ReturnValue_t initialize(); virtual ReturnValue_t initialize();
protected: protected:
const uint32_t parentId; const uint32_t parentId;
ChildHandlerFDIR childHandlerFdir; ChildHandlerFDIR childHandlerFdir;
}; };
#endif /* FSFW_DEVICES_CHILDHANDLERBASE_H_ */ #endif /* FSFW_DEVICES_CHILDHANDLERBASE_H_ */

View File

@ -1,24 +1,24 @@
#include "../../osal/FreeRTOS/TaskManagement.h" #include "../../osal/FreeRTOS/TaskManagement.h"
void TaskManagement::vRequestContextSwitchFromTask() { void TaskManagement::vRequestContextSwitchFromTask() {
vTaskDelay(0); vTaskDelay(0);
} }
void TaskManagement::requestContextSwitch( void TaskManagement::requestContextSwitch(
CallContext callContext = CallContext::TASK) { CallContext callContext = CallContext::TASK) {
if(callContext == CallContext::ISR) { if(callContext == CallContext::ISR) {
// This function depends on the partmacro.h definition for the specific device // This function depends on the partmacro.h definition for the specific device
vRequestContextSwitchFromISR(); vRequestContextSwitchFromISR();
} else { } else {
vRequestContextSwitchFromTask(); vRequestContextSwitchFromTask();
} }
} }
TaskHandle_t TaskManagement::getCurrentTaskHandle() { TaskHandle_t TaskManagement::getCurrentTaskHandle() {
return xTaskGetCurrentTaskHandle(); return xTaskGetCurrentTaskHandle();
} }
size_t TaskManagement::getTaskStackHighWatermark( size_t TaskManagement::getTaskStackHighWatermark(
TaskHandle_t task) { TaskHandle_t task) {
return uxTaskGetStackHighWaterMark(task) * sizeof(StackType_t); return uxTaskGetStackHighWaterMark(task) * sizeof(StackType_t);
} }

View File

@ -1,64 +1,64 @@
#ifndef FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_ #ifndef FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_
#define FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_ #define FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_
#include "../../returnvalues/HasReturnvaluesIF.h" #include "../../returnvalues/HasReturnvaluesIF.h"
extern "C" { extern "C" {
#include <freertos/FreeRTOS.h> #include <freertos/FreeRTOS.h>
#include <freertos/task.h> #include <freertos/task.h>
} }
#include <cstdint> #include <cstdint>
/** /**
* Architecture dependant portmacro.h function call. * Architecture dependant portmacro.h function call.
* Should be implemented in bsp. * Should be implemented in bsp.
*/ */
extern void vRequestContextSwitchFromISR(); extern void vRequestContextSwitchFromISR();
/*! /*!
* Used by functions to tell if they are being called from * Used by functions to tell if they are being called from
* within an ISR or from a regular task. This is required because FreeRTOS * within an ISR or from a regular task. This is required because FreeRTOS
* has different functions for handling semaphores and messages from within * has different functions for handling semaphores and messages from within
* an ISR and task. * an ISR and task.
*/ */
enum class CallContext { enum class CallContext {
TASK = 0x00,//!< task_context TASK = 0x00,//!< task_context
ISR = 0xFF //!< isr_context ISR = 0xFF //!< isr_context
}; };
class TaskManagement { class TaskManagement {
public: public:
/** /**
* @brief In this function, a function dependant on the portmacro.h header * @brief In this function, a function dependant on the portmacro.h header
* function calls to request a context switch can be specified. * function calls to request a context switch can be specified.
* This can be used if sending to the queue from an ISR caused a task * This can be used if sending to the queue from an ISR caused a task
* to unblock and a context switch is required. * to unblock and a context switch is required.
*/ */
static void requestContextSwitch(CallContext callContext); static void requestContextSwitch(CallContext callContext);
/** /**
* If task preemption in FreeRTOS is disabled, a context switch * If task preemption in FreeRTOS is disabled, a context switch
* can be requested manually by calling this function. * can be requested manually by calling this function.
*/ */
static void vRequestContextSwitchFromTask(void); static void vRequestContextSwitchFromTask(void);
/** /**
* @return The current task handle * @return The current task handle
*/ */
static TaskHandle_t getCurrentTaskHandle(); static TaskHandle_t getCurrentTaskHandle();
/** /**
* Get returns the minimum amount of remaining stack space in words * Get returns the minimum amount of remaining stack space in words
* that was a available to the task since the task started executing. * that was a available to the task since the task started executing.
* Please note that the actual value in bytes depends * Please note that the actual value in bytes depends
* on the stack depth type. * on the stack depth type.
* E.g. on a 32 bit machine, a value of 200 means 800 bytes. * E.g. on a 32 bit machine, a value of 200 means 800 bytes.
* @return Smallest value of stack remaining since the task was started in * @return Smallest value of stack remaining since the task was started in
* words. * words.
*/ */
static size_t getTaskStackHighWatermark( static size_t getTaskStackHighWatermark(
TaskHandle_t task = nullptr); TaskHandle_t task = nullptr);
}; };
#endif /* FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_ */ #endif /* FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_ */

View File

@ -1,129 +1,129 @@
#include "../serialize/SerialBufferAdapter.h" #include "../serialize/SerialBufferAdapter.h"
#include "../serviceinterface/ServiceInterfaceStream.h" #include "../serviceinterface/ServiceInterfaceStream.h"
#include <cstring> #include <cstring>
template<typename count_t> template<typename count_t>
SerialBufferAdapter<count_t>::SerialBufferAdapter(const uint8_t* buffer, SerialBufferAdapter<count_t>::SerialBufferAdapter(const uint8_t* buffer,
count_t bufferLength, bool serializeLength) : count_t bufferLength, bool serializeLength) :
serializeLength(serializeLength), serializeLength(serializeLength),
constBuffer(buffer), buffer(nullptr), constBuffer(buffer), buffer(nullptr),
bufferLength(bufferLength) {} bufferLength(bufferLength) {}
template<typename count_t> template<typename count_t>
SerialBufferAdapter<count_t>::SerialBufferAdapter(uint8_t* buffer, SerialBufferAdapter<count_t>::SerialBufferAdapter(uint8_t* buffer,
count_t bufferLength, bool serializeLength) : count_t bufferLength, bool serializeLength) :
serializeLength(serializeLength), constBuffer(buffer), buffer(buffer), serializeLength(serializeLength), constBuffer(buffer), buffer(buffer),
bufferLength(bufferLength) {} bufferLength(bufferLength) {}
template<typename count_t> template<typename count_t>
SerialBufferAdapter<count_t>::~SerialBufferAdapter() { SerialBufferAdapter<count_t>::~SerialBufferAdapter() {
} }
template<typename count_t> template<typename count_t>
ReturnValue_t SerialBufferAdapter<count_t>::serialize(uint8_t** buffer, ReturnValue_t SerialBufferAdapter<count_t>::serialize(uint8_t** buffer,
size_t* size, size_t maxSize, Endianness streamEndianness) const { size_t* size, size_t maxSize, Endianness streamEndianness) const {
if (serializeLength) { if (serializeLength) {
ReturnValue_t result = SerializeAdapter::serialize(&bufferLength, ReturnValue_t result = SerializeAdapter::serialize(&bufferLength,
buffer, size, maxSize, streamEndianness); buffer, size, maxSize, streamEndianness);
if(result != HasReturnvaluesIF::RETURN_OK) { if(result != HasReturnvaluesIF::RETURN_OK) {
return result; return result;
} }
} }
if (*size + bufferLength > maxSize) { if (*size + bufferLength > maxSize) {
return BUFFER_TOO_SHORT; return BUFFER_TOO_SHORT;
} }
if (this->constBuffer != nullptr) { if (this->constBuffer != nullptr) {
std::memcpy(*buffer, this->constBuffer, bufferLength); std::memcpy(*buffer, this->constBuffer, bufferLength);
} }
else if (this->buffer != nullptr) { else if (this->buffer != nullptr) {
// This will propably be never reached, constBuffer should always be // This will propably be never reached, constBuffer should always be
// set if non-const buffer is set. // set if non-const buffer is set.
std::memcpy(*buffer, this->buffer, bufferLength); std::memcpy(*buffer, this->buffer, bufferLength);
} }
else { else {
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
*size += bufferLength; *size += bufferLength;
(*buffer) += bufferLength; (*buffer) += bufferLength;
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
template<typename count_t> template<typename count_t>
size_t SerialBufferAdapter<count_t>::getSerializedSize() const { size_t SerialBufferAdapter<count_t>::getSerializedSize() const {
if (serializeLength) { if (serializeLength) {
return bufferLength + SerializeAdapter::getSerializedSize(&bufferLength); return bufferLength + SerializeAdapter::getSerializedSize(&bufferLength);
} else { } else {
return bufferLength; return bufferLength;
} }
} }
template<typename count_t> template<typename count_t>
ReturnValue_t SerialBufferAdapter<count_t>::deSerialize(const uint8_t** buffer, ReturnValue_t SerialBufferAdapter<count_t>::deSerialize(const uint8_t** buffer,
size_t* size, Endianness streamEndianness) { size_t* size, Endianness streamEndianness) {
if (this->buffer == nullptr) { if (this->buffer == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
if(serializeLength){ if(serializeLength){
count_t lengthField = 0; count_t lengthField = 0;
ReturnValue_t result = SerializeAdapter::deSerialize(&lengthField, ReturnValue_t result = SerializeAdapter::deSerialize(&lengthField,
buffer, size, streamEndianness); buffer, size, streamEndianness);
if(result != HasReturnvaluesIF::RETURN_OK) { if(result != HasReturnvaluesIF::RETURN_OK) {
return result; return result;
} }
if(lengthField > bufferLength) { if(lengthField > bufferLength) {
return TOO_MANY_ELEMENTS; return TOO_MANY_ELEMENTS;
} }
bufferLength = lengthField; bufferLength = lengthField;
} }
if (bufferLength <= *size) { if (bufferLength <= *size) {
*size -= bufferLength; *size -= bufferLength;
std::memcpy(this->buffer, *buffer, bufferLength); std::memcpy(this->buffer, *buffer, bufferLength);
(*buffer) += bufferLength; (*buffer) += bufferLength;
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
else { else {
return STREAM_TOO_SHORT; return STREAM_TOO_SHORT;
} }
} }
template<typename count_t> template<typename count_t>
uint8_t * SerialBufferAdapter<count_t>::getBuffer() { uint8_t * SerialBufferAdapter<count_t>::getBuffer() {
if(buffer == nullptr) { if(buffer == nullptr) {
sif::error << "Wrong access function for stored type !" sif::error << "Wrong access function for stored type !"
" Use getConstBuffer()." << std::endl; " Use getConstBuffer()." << std::endl;
return nullptr; return nullptr;
} }
return buffer; return buffer;
} }
template<typename count_t> template<typename count_t>
const uint8_t * SerialBufferAdapter<count_t>::getConstBuffer() { const uint8_t * SerialBufferAdapter<count_t>::getConstBuffer() {
if(constBuffer == nullptr) { if(constBuffer == nullptr) {
sif::error << "SerialBufferAdapter::getConstBuffer:" sif::error << "SerialBufferAdapter::getConstBuffer:"
" Buffers are unitialized!" << std::endl; " Buffers are unitialized!" << std::endl;
return nullptr; return nullptr;
} }
return constBuffer; return constBuffer;
} }
template<typename count_t> template<typename count_t>
void SerialBufferAdapter<count_t>::setBuffer(uint8_t* buffer, void SerialBufferAdapter<count_t>::setBuffer(uint8_t* buffer,
count_t bufferLength) { count_t bufferLength) {
this->buffer = buffer; this->buffer = buffer;
this->constBuffer = buffer; this->constBuffer = buffer;
this->bufferLength = bufferLength; this->bufferLength = bufferLength;
} }
//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>;
template class SerialBufferAdapter<uint32_t>; template class SerialBufferAdapter<uint32_t>;
template class SerialBufferAdapter<uint64_t>; template class SerialBufferAdapter<uint64_t>;

View File

@ -1,78 +1,78 @@
#ifndef SERIALBUFFERADAPTER_H_ #ifndef SERIALBUFFERADAPTER_H_
#define SERIALBUFFERADAPTER_H_ #define SERIALBUFFERADAPTER_H_
#include "../serialize/SerializeIF.h" #include "../serialize/SerializeIF.h"
#include "../serialize/SerializeAdapter.h" #include "../serialize/SerializeAdapter.h"
/** /**
* This adapter provides an interface for SerializeIF to serialize or deserialize * This adapter provides an interface for SerializeIF to serialize or deserialize
* buffers with no length header but a known size. * buffers with no length header but a known size.
* *
* Additionally, the buffer length can be serialized too and will be put in * Additionally, the buffer length can be serialized too and will be put in
* front of the serialized buffer. * front of the serialized buffer.
* *
* Can be used with SerialLinkedListAdapter by declaring a SerializeElement with * Can be used with SerialLinkedListAdapter by declaring a SerializeElement with
* SerialElement<SerialBufferAdapter<bufferLengthType(will be uint8_t mostly)>>. * SerialElement<SerialBufferAdapter<bufferLengthType(will be uint8_t mostly)>>.
* Right now, the SerialBufferAdapter must always * Right now, the SerialBufferAdapter must always
* be initialized with the buffer and size ! * be initialized with the buffer and size !
* *
* \ingroup serialize * \ingroup serialize
*/ */
template<typename count_t> template<typename count_t>
class SerialBufferAdapter: public SerializeIF { class SerialBufferAdapter: public SerializeIF {
public: public:
/** /**
* Constructor for constant uint8_t buffer. Length field can be serialized optionally. * Constructor for constant uint8_t buffer. Length field can be serialized optionally.
* Type of length can be supplied as template type. * Type of length can be supplied as template type.
* @param buffer * @param buffer
* @param bufferLength * @param bufferLength
* @param serializeLength * @param serializeLength
*/ */
SerialBufferAdapter(const uint8_t* buffer, count_t bufferLength, SerialBufferAdapter(const uint8_t* buffer, count_t bufferLength,
bool serializeLength = false); bool serializeLength = false);
/** /**
* Constructor for non-constant uint8_t buffer. * Constructor for non-constant uint8_t buffer.
* Length field can be serialized optionally. * Length field can be serialized optionally.
* Type of length can be supplied as template type. * Type of length can be supplied as template type.
* @param buffer * @param buffer
* @param bufferLength * @param bufferLength
* @param serializeLength Length field will be serialized with size count_t * @param serializeLength Length field will be serialized with size count_t
*/ */
SerialBufferAdapter(uint8_t* buffer, count_t bufferLength, SerialBufferAdapter(uint8_t* buffer, count_t bufferLength,
bool serializeLength = false); bool serializeLength = false);
virtual ~SerialBufferAdapter(); virtual ~SerialBufferAdapter();
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
size_t maxSize, Endianness streamEndianness) const override; size_t maxSize, Endianness streamEndianness) const override;
virtual size_t getSerializedSize() const override; virtual size_t getSerializedSize() const override;
/** /**
* @brief This function deserializes a buffer into the member buffer. * @brief This function deserializes a buffer into the member buffer.
* @details * @details
* If a length field is present, it is ignored, as the size should have * If a length field is present, it is ignored, as the size should have
* been set in the constructor. If the size is not known beforehand, * been set in the constructor. If the size is not known beforehand,
* consider using SerialFixedArrayListAdapter instead. * consider using SerialFixedArrayListAdapter instead.
* @param buffer [out] Resulting buffer * @param buffer [out] Resulting buffer
* @param size remaining size to deserialize, should be larger than buffer * @param size remaining size to deserialize, should be larger than buffer
* + size field size * + size field size
* @param bigEndian * @param bigEndian
* @return * @return
*/ */
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) override; Endianness streamEndianness) override;
uint8_t * getBuffer(); uint8_t * getBuffer();
const uint8_t * getConstBuffer(); const uint8_t * getConstBuffer();
void setBuffer(uint8_t* buffer, count_t bufferLength); void setBuffer(uint8_t* buffer, count_t bufferLength);
private: private:
bool serializeLength = false; bool serializeLength = false;
const uint8_t *constBuffer = nullptr; const uint8_t *constBuffer = nullptr;
uint8_t *buffer = nullptr; uint8_t *buffer = nullptr;
count_t bufferLength = 0; count_t bufferLength = 0;
}; };
#endif /* SERIALBUFFERADAPTER_H_ */ #endif /* SERIALBUFFERADAPTER_H_ */