Merge branch 'mueller/fsfw-pus-c-tc' into mueller/master

This commit is contained in:
2021-06-13 18:00:13 +02:00
31 changed files with 733 additions and 518 deletions

View File

@ -1,7 +1,6 @@
target_sources(${LIB_FSFW_NAME}
PRIVATE
SpacePacket.cpp
SpacePacketBase.cpp
target_sources(${LIB_FSFW_NAME} PRIVATE
SpacePacket.cpp
SpacePacketBase.cpp
)
add_subdirectory(packetmatcher)

View File

@ -1,12 +1,14 @@
target_sources(${LIB_FSFW_NAME}
PRIVATE
TcPacketBase.cpp
TcPacketStored.cpp
TmPacketBase.cpp
TmPacketMinimal.cpp
TmPacketStoredPusA.cpp
TmPacketStoredPusC.cpp
TmPacketPusA.cpp
TmPacketPusC.cpp
TmPacketStoredBase.cpp
target_sources(${LIB_FSFW_NAME} PRIVATE
TcPacketBase.cpp
TcPacketPusA.cpp
TcPacketStoredBase.cpp
TcPacketStoredPusA.cpp
TmPacketBase.cpp
TmPacketMinimal.cpp
TmPacketStoredPusA.cpp
TmPacketStoredPusC.cpp
TmPacketPusA.cpp
TmPacketPusC.cpp
TmPacketStoredBase.cpp
)

View File

@ -2,91 +2,19 @@
#include "../../globalfunctions/CRC.h"
#include "../../globalfunctions/arrayprinter.h"
#include "../../serviceinterface/ServiceInterfaceStream.h"
#include "../../serviceinterface/ServiceInterface.h"
#include <cstring>
TcPacketBase::TcPacketBase(const uint8_t* setData) :
SpacePacketBase(setData) {
tcData = reinterpret_cast<TcPacketPointer*>(const_cast<uint8_t*>(setData));
}
TcPacketBase::TcPacketBase(const uint8_t* setData): SpacePacketBase(setData) {}
TcPacketBase::~TcPacketBase() {
//Nothing to do.
}
uint8_t TcPacketBase::getService() {
return tcData->dataField.service_type;
}
uint8_t TcPacketBase::getSubService() {
return tcData->dataField.service_subtype;
}
uint8_t TcPacketBase::getSourceId() {
return tcData->dataField.source_id;
}
uint8_t TcPacketBase::getAcknowledgeFlags() {
return tcData->dataField.version_type_ack & 0b00001111;
}
const uint8_t* TcPacketBase::getApplicationData() const {
return &tcData->appData;
}
uint16_t TcPacketBase::getApplicationDataSize() {
return getPacketDataLength() - sizeof(tcData->dataField) - CRC_SIZE + 1;
}
uint16_t TcPacketBase::getErrorControl() {
uint16_t size = getApplicationDataSize() + CRC_SIZE;
uint8_t* p_to_buffer = &tcData->appData;
return (p_to_buffer[size - 2] << 8) + p_to_buffer[size - 1];
}
void TcPacketBase::setErrorControl() {
uint32_t full_size = getFullSize();
uint16_t crc = CRC::crc16ccitt(getWholeData(), full_size - CRC_SIZE);
uint32_t size = getApplicationDataSize();
(&tcData->appData)[size] = (crc & 0XFF00) >> 8; // CRCH
(&tcData->appData)[size + 1] = (crc) & 0X00FF; // CRCL
}
void TcPacketBase::setData(const uint8_t* pData) {
SpacePacketBase::setData(pData);
tcData = (TcPacketPointer*) pData;
}
uint8_t TcPacketBase::getSecondaryHeaderFlag() {
return (tcData->dataField.version_type_ack & 0b10000000) >> 7;
}
uint8_t TcPacketBase::getPusVersionNumber() {
return (tcData->dataField.version_type_ack & 0b01110000) >> 4;
}
TcPacketBase::~TcPacketBase() {}
void TcPacketBase::print() {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "TcPacketBase::print: " << std::endl;
sif::info << "TcPacketBase::print:" << std::endl;
#else
sif::printInfo("TcPacketBase::print:\n");
#endif
arrayprinter::print(getWholeData(), getFullSize());
}
void TcPacketBase::initializeTcPacket(uint16_t apid, uint16_t sequenceCount,
uint8_t ack, uint8_t service, uint8_t subservice) {
initSpacePacketHeader(true, true, apid, sequenceCount);
std::memset(&tcData->dataField, 0, sizeof(tcData->dataField));
setPacketDataLength(sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1);
//Data Field Header:
//Set CCSDS_secondary_header_flag to 0 and version number to 001
tcData->dataField.version_type_ack = 0b00010000;
tcData->dataField.version_type_ack |= (ack & 0x0F);
tcData->dataField.service_type = service;
tcData->dataField.service_subtype = subservice;
}
size_t TcPacketBase::calculateFullPacketLength(size_t appDataLen) {
return sizeof(CCSDSPrimaryHeader) + sizeof(PUSTcDataFieldHeader) +
appDataLen + TcPacketBase::CRC_SIZE;
arrayprinter::print(getWholeData(), getFullSize());
}

View File

@ -4,31 +4,6 @@
#include "../../tmtcpacket/SpacePacketBase.h"
#include <cstddef>
/**
* This struct defines a byte-wise structured PUS TC Data Field Header.
* Any optional fields in the header must be added or removed here.
* Currently, the Source Id field is present with one byte.
* @ingroup tmtcpackets
*/
struct PUSTcDataFieldHeader {
uint8_t version_type_ack;
uint8_t service_type;
uint8_t service_subtype;
uint8_t source_id;
};
/**
* This struct defines the data structure of a PUS Telecommand Packet when
* accessed via a pointer.
* @ingroup tmtcpackets
*/
struct TcPacketPointer {
CCSDSPrimaryHeader primary;
PUSTcDataFieldHeader dataField;
uint8_t appData;
};
/**
* This class is the basic data handler for any ECSS PUS Telecommand packet.
*
@ -41,9 +16,8 @@ struct TcPacketPointer {
* @ingroup tmtcpackets
*/
class TcPacketBase : public SpacePacketBase {
friend class TcPacketStoredBase;
public:
static const uint16_t TC_PACKET_MIN_SIZE = (sizeof(CCSDSPrimaryHeader) +
sizeof(PUSTcDataFieldHeader) + 2);
enum AckField {
//! No acknowledgements are expected.
@ -79,7 +53,7 @@ public:
* highest bit of the first byte of the Data Field Header.
* @return the CCSDS Secondary Header Flag
*/
uint8_t getSecondaryHeaderFlag();
virtual uint8_t getSecondaryHeaderFlag() = 0;
/**
* This command returns the TC Packet PUS Version Number.
* The version number of ECSS PUS 2003 is 1.
@ -87,7 +61,7 @@ public:
* first byte.
* @return
*/
uint8_t getPusVersionNumber();
virtual uint8_t getPusVersionNumber() = 0;
/**
* This is a getter for the packet's Ack field, which are the lowest four
* bits of the first byte of the Data Field Header.
@ -95,19 +69,19 @@ public:
* It is packed in a uint8_t variable.
* @return The packet's PUS Ack field.
*/
uint8_t getAcknowledgeFlags();
virtual uint8_t getAcknowledgeFlags() = 0;
/**
* This is a getter for the packet's PUS Service ID, which is the second
* byte of the Data Field Header.
* @return The packet's PUS Service ID.
*/
uint8_t getService();
virtual uint8_t getService() const = 0;
/**
* This is a getter for the packet's PUS Service Subtype, which is the
* third byte of the Data Field Header.
* @return The packet's PUS Service Subtype.
*/
uint8_t getSubService();
virtual uint8_t getSubService() = 0;
/**
* The source ID can be used to have an additional identifier, e.g. for different ground
* station.
@ -122,7 +96,7 @@ public:
* the packet's application data.
* @return A pointer to the PUS Application Data.
*/
const uint8_t* getApplicationData() const;
virtual const uint8_t* getApplicationData() const = 0;
/**
* This method calculates the size of the PUS Application data field.
*
@ -131,7 +105,7 @@ public:
* @return The size of the PUS Application Data (without Error Control
* field)
*/
uint16_t getApplicationDataSize();
virtual uint16_t getApplicationDataSize() = 0;
/**
* This getter returns the Error Control Field of the packet.
*
@ -140,44 +114,26 @@ public:
* supposed to be a 16bit-CRC.
* @return The PUS Error Control
*/
uint16_t getErrorControl();
virtual uint16_t getErrorControl() = 0;
/**
* With this method, the Error Control Field is updated to match the
* current content of the packet.
*/
void setErrorControl();
virtual void setErrorControl() = 0;
/**
* This is a debugging helper method that prints the whole packet content
* to the screen.
*/
void print();
/**
* Calculate full packet length from application data length.
* @param appDataLen
* @return
*/
static size_t calculateFullPacketLength(size_t appDataLen);
virtual size_t calculateFullPacketLength(size_t appDataLen) = 0;
/**
* This is a debugging helper method that prints the whole packet content
* to the screen.
*/
void print();
protected:
/**
* A pointer to a structure which defines the data structure of
* the packet's data.
*
* To be hardware-safe, all elements are of byte size.
*/
TcPacketPointer* tcData;
/**
* 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);
/**
* With this method, the packet data pointer can be redirected to another
@ -187,7 +143,7 @@ protected:
*
* @param p_data A pointer to another PUS Telecommand Packet.
*/
void setData( const uint8_t* pData );
void setData( const uint8_t* pData ) = 0;
};

View File

@ -0,0 +1,75 @@
#include "TcPacketPusA.h"
#include "../../globalfunctions/CRC.h"
#include <cstring>
TcPacketPusA::TcPacketPusA(const uint8_t *setData): TcPacketBase(setData) {
tcData = reinterpret_cast<TcPacketPointer*>(const_cast<uint8_t*>(setData));
}
uint8_t TcPacketPusA::getService() const {
return tcData->dataField.service_type;
}
uint8_t TcPacketPusA::getSubService() {
return tcData->dataField.service_subtype;
}
uint8_t TcPacketPusA::getAcknowledgeFlags() {
return tcData->dataField.version_type_ack & 0b00001111;
}
const uint8_t* TcPacketPusA::getApplicationData() const {
return &tcData->appData;
}
uint16_t TcPacketPusA::getApplicationDataSize() {
return getPacketDataLength() - sizeof(tcData->dataField) - CRC_SIZE + 1;
}
uint16_t TcPacketPusA::getErrorControl() {
uint16_t size = getApplicationDataSize() + CRC_SIZE;
uint8_t* p_to_buffer = &tcData->appData;
return (p_to_buffer[size - 2] << 8) + p_to_buffer[size - 1];
}
void TcPacketPusA::setErrorControl() {
uint32_t full_size = getFullSize();
uint16_t crc = CRC::crc16ccitt(getWholeData(), full_size - CRC_SIZE);
uint32_t size = getApplicationDataSize();
(&tcData->appData)[size] = (crc & 0XFF00) >> 8; // CRCH
(&tcData->appData)[size + 1] = (crc) & 0X00FF; // CRCL
}
void TcPacketPusA::setData(const uint8_t* pData) {
SpacePacketBase::setData(pData);
// This function is const-correct, but it was decided to keep the pointer non-const
// for convenience. Therefore, cast aways constness here and then cast to packet type.
tcData = reinterpret_cast<TcPacketPointer*>(const_cast<uint8_t*>(pData));
}
uint8_t TcPacketPusA::getSecondaryHeaderFlag() {
return (tcData->dataField.version_type_ack & 0b10000000) >> 7;
}
uint8_t TcPacketPusA::getPusVersionNumber() {
return (tcData->dataField.version_type_ack & 0b01110000) >> 4;
}
void TcPacketPusA::initializeTcPacket(uint16_t apid, uint16_t sequenceCount,
uint8_t ack, uint8_t service, uint8_t subservice) {
initSpacePacketHeader(true, true, apid, sequenceCount);
std::memset(&tcData->dataField, 0, sizeof(tcData->dataField));
setPacketDataLength(sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1);
// Data Field Header:
// Set CCSDS_secondary_header_flag to 0 and version number to 001
tcData->dataField.version_type_ack = 0b00010000;
tcData->dataField.version_type_ack |= (ack & 0x0F);
tcData->dataField.service_type = service;
tcData->dataField.service_subtype = subservice;
}
size_t TcPacketPusA::calculateFullPacketLength(size_t appDataLen) {
return sizeof(CCSDSPrimaryHeader) + sizeof(PUSTcDataFieldHeader) +
appDataLen + TcPacketBase::CRC_SIZE;
}

View File

@ -0,0 +1,83 @@
#ifndef FSFW_TMTCPACKET_PUS_TCPACKETPUSA_H_
#define FSFW_TMTCPACKET_PUS_TCPACKETPUSA_H_
#include "../ccsds_header.h"
#include "TcPacketBase.h"
#include <cstdint>
/**
* This struct defines a byte-wise structured PUS TC A Data Field Header.
* Any optional fields in the header must be added or removed here.
* Currently, the Source Id field is present with one byte.
* @ingroup tmtcpackets
*/
struct PUSTcDataFieldHeader {
uint8_t version_type_ack;
uint8_t service_type;
uint8_t service_subtype;
uint8_t source_id;
};
/**
* This struct defines the data structure of a PUS Telecommand A packet when
* accessed via a pointer.
* @ingroup tmtcpackets
*/
struct TcPacketPointer {
CCSDSPrimaryHeader primary;
PUSTcDataFieldHeader dataField;
uint8_t appData;
};
class TcPacketPusA: public TcPacketBase {
public:
static const uint16_t TC_PACKET_MIN_SIZE = (sizeof(CCSDSPrimaryHeader) +
sizeof(PUSTcDataFieldHeader) + 2);
/**
* Initialize a PUS A telecommand packet which already exists. You can also
* create an empty (invalid) object by passing nullptr as the data pointer
* @param setData
*/
TcPacketPusA(const uint8_t* setData);
// Base class overrides
virtual uint8_t getSecondaryHeaderFlag() override;
virtual uint8_t getPusVersionNumber() override;
virtual uint8_t getAcknowledgeFlags() override;
virtual uint8_t getService() const override;
virtual uint8_t getSubService() override;
const uint8_t* getApplicationData() const override;
uint16_t getApplicationDataSize() override;
uint16_t getErrorControl() override;
void setErrorControl() override;
size_t calculateFullPacketLength(size_t appDataLen) override;
protected:
void setData(const uint8_t* pData) 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);
/**
* A pointer to a structure which defines the data structure of
* the packet's data.
*
* To be hardware-safe, all elements are of byte size.
*/
TcPacketPointer* tcData = nullptr;
};
#endif /* FSFW_TMTCPACKET_PUS_TCPACKETPUSA_H_ */

View File

@ -0,0 +1,4 @@
#include "TcPacketPusC.h"

View File

@ -0,0 +1,8 @@
#ifndef FSFW_TMTCPACKET_PUS_TCPACKETPUSC_H_
#define FSFW_TMTCPACKET_PUS_TCPACKETPUSC_H_
#endif /* FSFW_TMTCPACKET_PUS_TCPACKETPUSC_H_ */

View File

@ -1,124 +0,0 @@
#include "TcPacketStored.h"
#include "../../objectmanager/ObjectManager.h"
#include "../../serviceinterface/ServiceInterface.h"
#include <cstring>
StorageManagerIF* TcPacketStored::store = nullptr;
TcPacketStored::TcPacketStored(store_address_t setAddress) :
TcPacketBase(nullptr), storeAddress(setAddress) {
setStoreAddress(storeAddress);
}
TcPacketStored::TcPacketStored(uint16_t apid, uint8_t service,
uint8_t subservice, uint8_t sequenceCount, const uint8_t* data,
size_t size, uint8_t ack) :
TcPacketBase(nullptr) {
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (not this->checkAndSetStore()) {
return;
}
uint8_t* pData = nullptr;
ReturnValue_t returnValue = this->store->getFreeElement(&this->storeAddress,
(TC_PACKET_MIN_SIZE + size), &pData);
if (returnValue != this->store->RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "TcPacketStored: Could not get free element from store!"
<< std::endl;
#endif
return;
}
this->setData(pData);
initializeTcPacket(apid, sequenceCount, ack, service, subservice);
memcpy(&tcData->appData, data, size);
this->setPacketDataLength(
size + sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1);
this->setErrorControl();
}
ReturnValue_t TcPacketStored::getData(const uint8_t ** dataPtr,
size_t* dataSize) {
auto result = this->store->getData(storeAddress, dataPtr, dataSize);
if(result != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "TcPacketStored: Could not get data!" << std::endl;
#endif
}
return result;
}
TcPacketStored::TcPacketStored(): TcPacketBase(nullptr) {
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
this->checkAndSetStore();
}
ReturnValue_t TcPacketStored::deletePacket() {
ReturnValue_t result = this->store->deleteData(this->storeAddress);
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
this->setData(nullptr);
return result;
}
bool TcPacketStored::checkAndSetStore() {
if (this->store == nullptr) {
this->store = ObjectManager::instance()->get<StorageManagerIF>(objects::TC_STORE);
if (this->store == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "TcPacketStored::TcPacketStored: TC Store not found!"
<< std::endl;
#endif
return false;
}
}
return true;
}
void TcPacketStored::setStoreAddress(store_address_t setAddress) {
this->storeAddress = setAddress;
const uint8_t* tempData = nullptr;
size_t temp_size;
ReturnValue_t status = StorageManagerIF::RETURN_FAILED;
if (this->checkAndSetStore()) {
status = this->store->getData(this->storeAddress, &tempData,
&temp_size);
}
if (status == StorageManagerIF::RETURN_OK) {
this->setData(tempData);
} else {
this->setData(nullptr);
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
}
}
store_address_t TcPacketStored::getStoreAddress() {
return this->storeAddress;
}
bool TcPacketStored::isSizeCorrect() {
const uint8_t* temp_data = nullptr;
size_t temp_size;
ReturnValue_t status = this->store->getData(this->storeAddress, &temp_data,
&temp_size);
if (status == StorageManagerIF::RETURN_OK) {
if (this->getFullSize() == temp_size) {
return true;
}
}
return false;
}
TcPacketStored::TcPacketStored(const uint8_t* data, uint32_t size) :
TcPacketBase(data) {
if (getFullSize() != size) {
return;
}
if (this->checkAndSetStore()) {
ReturnValue_t status = store->addData(&storeAddress, data, size);
if (status != HasReturnvaluesIF::RETURN_OK) {
this->setData(nullptr);
}
}
}

View File

@ -1,117 +1,13 @@
#ifndef TMTCPACKET_PUS_TCPACKETSTORED_H_
#define TMTCPACKET_PUS_TCPACKETSTORED_H_
#ifndef FSFW_TMTCPACKET_PUS_TCPACKETSTORED_H_
#define FSFW_TMTCPACKET_PUS_TCPACKETSTORED_H_
#include "TcPacketBase.h"
#include "../../storagemanager/StorageManagerIF.h"
#include <FSFWConfig.h>
/**
* This class generates a ECSS PUS Telecommand packet within a given
* intermediate storage.
* As most packets are passed between tasks with the help of a storage
* anyway, it seems logical to create a Packet-In-Storage access class
* which saves the user almost all storage handling operation.
* Packets can both be newly created with the class and be "linked" to
* packets in a store with the help of a storeAddress.
* @ingroup tmtcpackets
*/
class TcPacketStored : public TcPacketBase {
public:
/**
* This is a default constructor which does not set the data pointer.
* However, it does try to set the packet store.
*/
TcPacketStored();
/**
* With this constructor, the class instance is linked to an existing
* packet in the packet store.
* The packet content is neither checked nor changed with this call. If
* the packet could not be found, the data pointer is set to NULL.
*/
TcPacketStored( store_address_t setAddress );
/**
* With this constructor, new space is allocated in the packet store and
* a new PUS Telecommand Packet is created there.
* Packet Application Data passed in data is copied into the packet.
* @param apid Sets the packet's APID field.
* @param service Sets the packet's Service ID field.
* This specifies the destination service.
* @param subservice Sets the packet's Service Subtype field.
* This specifies the destination sub-service.
* @param sequence_count Sets the packet's Source Sequence Count field.
* @param data The data to be copied to the Application Data Field.
* @param size The amount of data to be copied.
* @param ack Set's the packet's Ack field, which specifies
* number of verification packets returned
* for this command.
*/
TcPacketStored(uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t sequence_count = 0, const uint8_t* data = nullptr,
size_t size = 0, uint8_t ack = TcPacketBase::ACK_ALL);
/**
* Another constructor to create a TcPacket from a raw packet stream.
* Takes the data and adds it unchecked to the TcStore.
* @param data Pointer to the complete TC Space Packet.
* @param Size size of the packet.
*/
TcPacketStored( const uint8_t* data, uint32_t size);
/**
* Getter function for the raw data.
* @param dataPtr [out] Pointer to the data pointer to set
* @param dataSize [out] Address of size to set.
* @return -@c RETURN_OK if data was retrieved successfully.
*/
ReturnValue_t getData(const uint8_t ** dataPtr,
size_t* dataSize);
/**
* This is a getter for the current store address of the packet.
* @return The current store address. The (raw) value is
* @c StorageManagerIF::INVALID_ADDRESS if the packet is not linked.
*/
store_address_t getStoreAddress();
/**
* With this call, the packet is deleted.
* It removes itself from the store and sets its data pointer to NULL.
* @return returncode from deleting the data.
*/
ReturnValue_t deletePacket();
/**
* With this call, a packet can be linked to another store. This is useful
* if the packet is a class member and used for more than one packet.
* @param setAddress The new packet id to link to.
*/
void setStoreAddress( store_address_t setAddress );
/**
* This method performs a size check.
* It reads the stored size and compares it with the size entered in the
* packet header. This class is the optimal place for such a check as it
* has access to both the header data and the store.
* @return true if size is correct, false if packet is not registered in
* store or size is incorrect.
*/
bool isSizeCorrect();
private:
/**
* This is a pointer to the store all instances of the class use.
* If the store is not yet set (i.e. @c store is NULL), every constructor
* call tries to set it and throws an error message in case of failures.
* The default store is objects::TC_STORE.
*/
static StorageManagerIF* store;
/**
* The address where the packet data of the object instance is stored.
*/
store_address_t storeAddress;
/**
* A helper method to check if a store is assigned to the class.
* If not, the method tries to retrieve the store from the global
* ObjectManager.
* @return @li @c true if the store is linked or could be created.
* @li @c false otherwise.
*/
bool checkAndSetStore();
};
#if FSFW_USE_PUS_C_TELECOMMANDS == 1
#include "TcPacketStoredPusC.h"
#else
#include "TcPacketStoredPusA.h"
#endif
#endif /* TMTCPACKET_PUS_TCPACKETSTORED_H_ */
#endif /* FSFW_TMTCPACKET_PUS_TCPACKETSTORED_H_ */

View File

@ -0,0 +1,72 @@
#include "TcPacketStoredBase.h"
#include "../../objectmanager/ObjectManager.h"
#include "../../serviceinterface/ServiceInterface.h"
#include "../../objectmanager/frameworkObjects.h"
#include <cstring>
StorageManagerIF* TcPacketStoredBase::store = nullptr;
TcPacketStoredBase::TcPacketStoredBase() {
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
this->checkAndSetStore();
}
TcPacketStoredBase::~TcPacketStoredBase() {
}
ReturnValue_t TcPacketStoredBase::getData(const uint8_t ** dataPtr,
size_t* dataSize) {
auto result = this->store->getData(storeAddress, dataPtr, dataSize);
if(result != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "TcPacketStoredBase: Could not get data!" << std::endl;
#else
sif::printWarning("TcPacketStoredBase: Could not get data!\n");
#endif
}
return result;
}
bool TcPacketStoredBase::checkAndSetStore() {
if (this->store == nullptr) {
this->store = ObjectManager::instance()->get<StorageManagerIF>(objects::TC_STORE);
if (this->store == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "TcPacketStoredBase::TcPacketStoredBase: TC Store not found!"
<< std::endl;
#endif
return false;
}
}
return true;
}
void TcPacketStoredBase::setStoreAddress(store_address_t setAddress) {
this->storeAddress = setAddress;
const uint8_t* tempData = nullptr;
size_t tempSize;
ReturnValue_t status = StorageManagerIF::RETURN_FAILED;
if (this->checkAndSetStore()) {
status = this->store->getData(this->storeAddress, &tempData, &tempSize);
}
TcPacketBase* tcPacketBase = this->getPacketBase();
if(tcPacketBase == nullptr) {
return;
}
if (status == StorageManagerIF::RETURN_OK) {
tcPacketBase->setData(tempData);
}
else {
tcPacketBase->setData(nullptr);
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
}
}
store_address_t TcPacketStoredBase::getStoreAddress() {
return this->storeAddress;
}

View File

@ -0,0 +1,90 @@
#ifndef TMTCPACKET_PUS_TCPACKETSTORED_H_
#define TMTCPACKET_PUS_TCPACKETSTORED_H_
#include <fsfw/tmtcpacket/pus/TcPacketStoredIF.h>
#include "../../storagemanager/StorageManagerIF.h"
/**
* This class generates a ECSS PUS Telecommand packet within a given
* intermediate storage.
* As most packets are passed between tasks with the help of a storage
* anyway, it seems logical to create a Packet-In-Storage access class
* which saves the user almost all storage handling operation.
* Packets can both be newly created with the class and be "linked" to
* packets in a store with the help of a storeAddress.
* @ingroup tmtcpackets
*/
class TcPacketStoredBase: public TcPacketStoredIF {
public:
/**
* This is a default constructor which does not set the data pointer to initialize
* with an empty cached store address
*/
TcPacketStoredBase();
/**
* Constructor to set to an existing store address.
* @param setAddress
*/
TcPacketStoredBase(store_address_t setAddress);
/**
* Another constructor to create a TcPacket from a raw packet stream.
* Takes the data and adds it unchecked to the TcStore.
* @param data Pointer to the complete TC Space Packet.
* @param Size size of the packet.
*/
TcPacketStoredBase(const uint8_t* data, uint32_t size);
virtual~ TcPacketStoredBase();
/**
* Getter function for the raw data.
* @param dataPtr [out] Pointer to the data pointer to set
* @param dataSize [out] Address of size to set.
* @return -@c RETURN_OK if data was retrieved successfully.
*/
ReturnValue_t getData(const uint8_t ** dataPtr, size_t* dataSize) override;
void setStoreAddress(store_address_t setAddress) override;
store_address_t getStoreAddress() override;
/**
* With this call, the packet is deleted.
* It removes itself from the store and sets its data pointer to NULL.
* @return returncode from deleting the data.
*/
virtual ReturnValue_t deletePacket() = 0;
/**
* This method performs a size check.
* It reads the stored size and compares it with the size entered in the
* packet header. This class is the optimal place for such a check as it
* has access to both the header data and the store.
* @return true if size is correct, false if packet is not registered in
* store or size is incorrect.
*/
virtual bool isSizeCorrect() = 0;
protected:
/**
* This is a pointer to the store all instances of the class use.
* If the store is not yet set (i.e. @c store is NULL), every constructor
* call tries to set it and throws an error message in case of failures.
* The default store is objects::TC_STORE.
*/
static StorageManagerIF* store;
/**
* The address where the packet data of the object instance is stored.
*/
store_address_t storeAddress;
/**
* A helper method to check if a store is assigned to the class.
* If not, the method tries to retrieve the store from the global
* ObjectManager.
* @return @li @c true if the store is linked or could be created.
* @li @c false otherwise.
*/
bool checkAndSetStore();
};
#endif /* TMTCPACKET_PUS_TcPacketStoredBase_H_ */

View File

@ -0,0 +1,38 @@
#ifndef FSFW_TMTCPACKET_PUS_TCPACKETSTOREDIF_H_
#define FSFW_TMTCPACKET_PUS_TCPACKETSTOREDIF_H_
#include "../../tmtcpacket/pus/TcPacketBase.h"
#include "../../storagemanager/storeAddress.h"
#include "../../returnvalues/HasReturnvaluesIF.h"
class TcPacketStoredIF {
public:
virtual~TcPacketStoredIF() {};
/**
* With this call, the stored packet can be set to another packet in a store. This is useful
* if the packet is a class member and used for more than one packet.
* @param setAddress The new packet id to link to.
*/
virtual void setStoreAddress(store_address_t setAddress) = 0;
virtual store_address_t getStoreAddress() = 0;
/**
* Getter function for the raw data.
* @param dataPtr [out] Pointer to the data pointer to set
* @param dataSize [out] Address of size to set.
* @return -@c RETURN_OK if data was retrieved successfully.
*/
virtual ReturnValue_t getData(const uint8_t ** dataPtr, size_t* dataSize) = 0;
/**
* Get packet base pointer which can be used to get access to PUS packet fields
* @return
*/
virtual TcPacketBase* getPacketBase() = 0;
};
#endif /* FSFW_TMTCPACKET_PUS_TCPACKETSTOREDIF_H_ */

View File

@ -0,0 +1,77 @@
#include "TcPacketStoredPusA.h"
#include <cstring>
TcPacketStoredPusA::TcPacketStoredPusA(uint16_t apid, uint8_t service,
uint8_t subservice, uint8_t sequenceCount, const uint8_t* data,
size_t size, uint8_t ack) :
TcPacketPusA(nullptr) {
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (not this->checkAndSetStore()) {
return;
}
uint8_t* pData = nullptr;
ReturnValue_t returnValue = this->store->getFreeElement(&this->storeAddress,
(TC_PACKET_MIN_SIZE + size), &pData);
if (returnValue != this->store->RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "TcPacketStoredBase: Could not get free element from store!"
<< std::endl;
#endif
return;
}
this->setData(pData);
initializeTcPacket(apid, sequenceCount, ack, service, subservice);
std::memcpy(&tcData->appData, data, size);
this->setPacketDataLength(
size + sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1);
this->setErrorControl();
}
TcPacketStoredPusA::TcPacketStoredPusA(): TcPacketStoredBase(), TcPacketPusA(nullptr) {
}
TcPacketStoredPusA::TcPacketStoredPusA(store_address_t setAddress): TcPacketPusA(nullptr) {
TcPacketStoredBase::setStoreAddress(setAddress);
}
TcPacketStoredPusA::TcPacketStoredPusA(const uint8_t* data, size_t size): TcPacketPusA(data) {
if (this->getFullSize() != size) {
return;
}
if (this->checkAndSetStore()) {
ReturnValue_t status = store->addData(&storeAddress, data, size);
if (status != HasReturnvaluesIF::RETURN_OK) {
this->setData(nullptr);
}
const uint8_t* storePtr = nullptr;
// Repoint base data pointer to the data in the store.
store->getData(storeAddress, &storePtr, &size);
this->setData(storePtr);
}
}
ReturnValue_t TcPacketStoredPusA::deletePacket() {
ReturnValue_t result = this->store->deleteData(this->storeAddress);
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
this->setData(nullptr);
return result;
}
TcPacketBase* TcPacketStoredPusA::getPacketBase() {
return this;
}
bool TcPacketStoredPusA::isSizeCorrect() {
const uint8_t* temp_data = nullptr;
size_t temp_size;
ReturnValue_t status = this->store->getData(this->storeAddress, &temp_data,
&temp_size);
if (status == StorageManagerIF::RETURN_OK) {
if (this->getFullSize() == temp_size) {
return true;
}
}
return false;
}

View File

@ -0,0 +1,53 @@
#ifndef FSFW_TMTCPACKET_PUS_TCPACKETSTOREDPUSA_H_
#define FSFW_TMTCPACKET_PUS_TCPACKETSTOREDPUSA_H_
#include "TcPacketStoredBase.h"
#include "TcPacketPusA.h"
class TcPacketStoredPusA:
public TcPacketStoredBase,
public TcPacketPusA {
public:
/**
* With this constructor, new space is allocated in the packet store and
* a new PUS Telecommand Packet is created there.
* Packet Application Data passed in data is copied into the packet.
* @param apid Sets the packet's APID field.
* @param service Sets the packet's Service ID field.
* This specifies the destination service.
* @param subservice Sets the packet's Service Subtype field.
* This specifies the destination sub-service.
* @param sequence_count Sets the packet's Source Sequence Count field.
* @param data The data to be copied to the Application Data Field.
* @param size The amount of data to be copied.
* @param ack Set's the packet's Ack field, which specifies
* number of verification packets returned
* for this command.
*/
TcPacketStoredPusA(uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t sequence_count = 0, const uint8_t* data = nullptr,
size_t size = 0, uint8_t ack = TcPacketBase::ACK_ALL);
/**
* Create stored packet with existing data.
* @param data
* @param size
*/
TcPacketStoredPusA(const uint8_t* data, size_t size);
/**
* Create stored packet from existing packet in store
* @param setAddress
*/
TcPacketStoredPusA(store_address_t setAddress);
TcPacketStoredPusA();
ReturnValue_t deletePacket() override;
TcPacketBase* getPacketBase() override;
private:
bool isSizeCorrect() override;
};
#endif /* FSFW_TMTCPACKET_PUS_TCPACKETSTOREDPUSA_H_ */

View File

@ -0,0 +1,2 @@
#include "TcPacketStoredPusC.h"

View File

@ -0,0 +1,8 @@
#ifndef FSFW_TMTCPACKET_PUS_TCPACKETSTOREDPUSC_H_
#define FSFW_TMTCPACKET_PUS_TCPACKETSTOREDPUSC_H_
#endif /* FSFW_TMTCPACKET_PUS_TCPACKETSTOREDPUSC_H_ */

View File

@ -44,13 +44,6 @@ ReturnValue_t TmPacketBase::getPacketTime(timeval* timestamp) const {
&tempSize, getTimestampSize());
}
void TmPacketBase::print() {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "TmPacketBase::print: " << std::endl;
#endif
arrayprinter::print(getWholeData(), getFullSize());
}
bool TmPacketBase::checkAndSetStamper() {
if (timeStamper == NULL) {
timeStamper = ObjectManager::instance()->get<TimeStamperIF>(timeStamperId);
@ -66,3 +59,11 @@ bool TmPacketBase::checkAndSetStamper() {
return true;
}
void TmPacketBase::print() {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "TmPacketBase::print:" << std::endl;
#else
sif::printInfo("TmPacketBase::print:\n");
#endif
arrayprinter::print(getWholeData(), getFullSize());
}