this should get the job done
This commit is contained in:
parent
b9fbb4fd4c
commit
efd12544df
@ -1,3 +1,4 @@
|
|||||||
target_sources(
|
target_sources(
|
||||||
${LIB_FSFW_NAME} PRIVATE TcPacketPusBase.cpp TcPacketPus.cpp
|
${LIB_FSFW_NAME}
|
||||||
TcPacketStoredBase.cpp TcPacketStoredPus.cpp)
|
PRIVATE TcPacketPusBase.cpp TcPacketPus.cpp TcPacketStoredBase.cpp
|
||||||
|
TcPacketStoredPus.cpp TcPacketPusIntoBuf.cpp)
|
||||||
|
@ -97,15 +97,3 @@ ReturnValue_t TcPacketPus::setData(uint8_t *dataPtr, size_t maxSize, void *args)
|
|||||||
tcData = reinterpret_cast<TcPacketPointer *>(const_cast<uint8_t *>(dataPtr));
|
tcData = reinterpret_cast<TcPacketPointer *>(const_cast<uint8_t *>(dataPtr));
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TcPacketPus::setApplicationData(const uint8_t *data, size_t len, bool updateSpLenField) {
|
|
||||||
if(data == nullptr) {
|
|
||||||
len = 0;
|
|
||||||
}
|
|
||||||
if(data != nullptr) {
|
|
||||||
std::memcpy(&tcData->appData, data, len);
|
|
||||||
}
|
|
||||||
if(updateSpLenField) {
|
|
||||||
setPacketDataLength(calculateFullPacketLength(len) - sizeof(CCSDSPrimaryHeader) - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -49,16 +49,6 @@ class TcPacketPus : public TcPacketPusBase {
|
|||||||
*/
|
*/
|
||||||
TcPacketPus(const uint8_t* setData);
|
TcPacketPus(const uint8_t* setData);
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes the Tc Packet header.
|
|
||||||
* @param apid APID used.
|
|
||||||
* @param sequenceCount Sequence Count in the primary header.
|
|
||||||
* @param ack Which acknowledeges are expected from the receiver.
|
|
||||||
* @param service PUS Service
|
|
||||||
* @param subservice PUS Subservice
|
|
||||||
*/
|
|
||||||
void initializeTcPacket(uint16_t apid, uint16_t sequenceCount, uint8_t ack, uint8_t service,
|
|
||||||
uint8_t subservice, pus::PusVersion pusVersion, uint16_t sourceId = 0);
|
|
||||||
/**
|
/**
|
||||||
* Set the application data field by copying the provided data to the application data field.
|
* Set the application data field by copying the provided data to the application data field.
|
||||||
* This function can also update the space packet length
|
* This function can also update the space packet length
|
||||||
@ -68,7 +58,7 @@ class TcPacketPus : public TcPacketPusBase {
|
|||||||
* @param len
|
* @param len
|
||||||
* @param updateSpLenField
|
* @param updateSpLenField
|
||||||
*/
|
*/
|
||||||
void setApplicationData(const uint8_t* data, size_t len, bool updateSpLenField);
|
void setApplicationData(const uint8_t* data, size_t len, bool updateSpLenField);
|
||||||
|
|
||||||
// Base class overrides
|
// Base class overrides
|
||||||
uint8_t getSecondaryHeaderFlag() const override;
|
uint8_t getSecondaryHeaderFlag() const override;
|
||||||
@ -86,6 +76,17 @@ class TcPacketPus : public TcPacketPusBase {
|
|||||||
protected:
|
protected:
|
||||||
ReturnValue_t setData(uint8_t* dataPtr, size_t maxSize, void* args = nullptr) override;
|
ReturnValue_t setData(uint8_t* dataPtr, size_t maxSize, void* args = nullptr) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the Tc Packet header.
|
||||||
|
* @param apid APID used.
|
||||||
|
* @param sequenceCount Sequence Count in the primary header.
|
||||||
|
* @param ack Which acknowledeges are expected from the receiver.
|
||||||
|
* @param service PUS Service
|
||||||
|
* @param subservice PUS Subservice
|
||||||
|
*/
|
||||||
|
void initializeTcPacket(uint16_t apid, uint16_t sequenceCount, uint8_t ack, uint8_t service,
|
||||||
|
uint8_t subservice, pus::PusVersion pusVersion, uint16_t sourceId = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A pointer to a structure which defines the data structure of
|
* A pointer to a structure which defines the data structure of
|
||||||
* the packet's data.
|
* the packet's data.
|
||||||
|
@ -22,7 +22,7 @@ class TcPacketPusBase : public SpacePacketBase, virtual public RedirectableDataP
|
|||||||
friend class TcPacketStoredBase;
|
friend class TcPacketStoredBase;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum AckField {
|
enum AckField : uint8_t {
|
||||||
//! No acknowledgements are expected.
|
//! No acknowledgements are expected.
|
||||||
ACK_NONE = 0b0000,
|
ACK_NONE = 0b0000,
|
||||||
//! Acknowledgements on acceptance are expected.
|
//! Acknowledgements on acceptance are expected.
|
||||||
|
47
src/fsfw/tmtcpacket/pus/tc/TcPacketPusIntoBuf.cpp
Normal file
47
src/fsfw/tmtcpacket/pus/tc/TcPacketPusIntoBuf.cpp
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#include "TcPacketPusIntoBuf.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
TcPacketPusIntoBuf::TcPacketPusIntoBuf(uint8_t* store, size_t maxSize, PusConfig& cfg)
|
||||||
|
: TcPacketPus(nullptr), store(store), maxSize(maxSize), cfg(cfg) {}
|
||||||
|
|
||||||
|
ReturnValue_t TcPacketPusIntoBuf::serialize(uint8_t** buffer, size_t* size, size_t maxSize,
|
||||||
|
Endianness streamEndianness) const {
|
||||||
|
if (*size + getSerializedSize() > maxSize) {
|
||||||
|
return BUFFER_TOO_SHORT;
|
||||||
|
}
|
||||||
|
std::memcpy(*buffer, store, getSerializedSize());
|
||||||
|
*buffer += getSerializedSize();
|
||||||
|
*size += getSerializedSize();
|
||||||
|
return RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t TcPacketPusIntoBuf::getSerializedSize() const { return TC_PACKET_MIN_SIZE + cfg.appDataLen; }
|
||||||
|
|
||||||
|
ReturnValue_t TcPacketPusIntoBuf::initialize() {
|
||||||
|
if (getSerializedSize() > maxSize) {
|
||||||
|
return SerializeIF::BUFFER_TOO_SHORT;
|
||||||
|
}
|
||||||
|
ReturnValue_t result = setData(store, maxSize);
|
||||||
|
if (result != RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#if FSFW_USE_PUS_C_TELECOMMANDS == 1
|
||||||
|
pus::PusVersion pusVersion = pus::PusVersion::PUS_C_VERSION;
|
||||||
|
#else
|
||||||
|
pus::PusVersion pusVersion = pus::PusVersion::PUS_A_VERSION;
|
||||||
|
#endif
|
||||||
|
initializeTcPacket(cfg.apid, cfg.sequenceCount, cfg.ack, cfg.service, cfg.subservice, pusVersion,
|
||||||
|
cfg.sourceId);
|
||||||
|
if (cfg.appData != nullptr and cfg.appDataLen > 0) {
|
||||||
|
std::memcpy(&tcData->appData, cfg.appData, cfg.appDataLen);
|
||||||
|
}
|
||||||
|
setPacketDataLength(calculateFullPacketLength(cfg.appDataLen) - sizeof(CCSDSPrimaryHeader) - 1);
|
||||||
|
setErrorControl();
|
||||||
|
return RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t TcPacketPusIntoBuf::deSerialize(const uint8_t** buffer, size_t* size,
|
||||||
|
Endianness streamEndianness) {
|
||||||
|
return RETURN_FAILED;
|
||||||
|
}
|
38
src/fsfw/tmtcpacket/pus/tc/TcPacketPusIntoBuf.h
Normal file
38
src/fsfw/tmtcpacket/pus/tc/TcPacketPusIntoBuf.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#ifndef FSFW_SRC_FSFW_TMTCPACKET_PUS_TC_TCPACKETPUSINTOBUF_H_
|
||||||
|
#define FSFW_SRC_FSFW_TMTCPACKET_PUS_TC_TCPACKETPUSINTOBUF_H_
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include "TcPacketPus.h"
|
||||||
|
#include "fsfw/serialize/SerializeIF.h"
|
||||||
|
|
||||||
|
struct PusConfig {
|
||||||
|
uint16_t apid = 0;
|
||||||
|
uint8_t service = 0;
|
||||||
|
uint8_t subservice = 0;
|
||||||
|
uint16_t sequenceCount = 0;
|
||||||
|
uint16_t sourceId = 0;
|
||||||
|
uint8_t* appData = nullptr;
|
||||||
|
size_t appDataLen = 0;
|
||||||
|
uint8_t ack = TcPacketPus::ACK_ALL;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TcPacketPusIntoBuf : public TcPacketPus, public SerializeIF, public HasReturnvaluesIF {
|
||||||
|
public:
|
||||||
|
TcPacketPusIntoBuf(uint8_t* data, size_t size, PusConfig& cfg);
|
||||||
|
|
||||||
|
ReturnValue_t initialize();
|
||||||
|
|
||||||
|
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
|
||||||
|
Endianness streamEndianness) const override;
|
||||||
|
size_t getSerializedSize() const override;
|
||||||
|
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||||
|
Endianness streamEndianness) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t* store;
|
||||||
|
size_t maxSize;
|
||||||
|
PusConfig& cfg;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FSFW_SRC_FSFW_TMTCPACKET_PUS_TC_TCPACKETPUSINTOBUF_H_ */
|
Loading…
Reference in New Issue
Block a user