v1.14.0 #304

Merged
muellerr merged 366 commits from develop into main 2022-10-10 17:46:38 +02:00
Showing only changes of commit 859ced185d - Show all commits

View File

@ -6,7 +6,7 @@
#include <fsfw/globalfunctions/CRC.h> #include <fsfw/globalfunctions/CRC.h>
#include <fsfw/serialize/SerializeAdapter.h> #include <fsfw/serialize/SerializeAdapter.h>
#include <fsfw/timemanager/Clock.h> #include <fsfw/timemanager/Clock.h>
#include <fsfw/tmtcpacket/SpacePacket.h> #include <fsfw/tmtcpacket/ccsds/SpacePacketCreator.h>
#include "linux/devices/devicedefinitions/SupvReturnValuesIF.h" #include "linux/devices/devicedefinitions/SupvReturnValuesIF.h"
@ -274,10 +274,47 @@ static const uint32_t ERASE_MEMORY = 60000;
static const uint32_t UPDATE_STATUS_REPORT = 70000; static const uint32_t UPDATE_STATUS_REPORT = 70000;
} // namespace recv_timeout } // namespace recv_timeout
class SpacePacketBase {
public:
SpacePacketBase(SpacePacketCreator& creator, uint8_t* buf, size_t payloadLen, size_t maxSize)
: creator(creator), buf(buf), payloadLen(payloadLen), maxSize(maxSize) {
creator.setDataLen(payloadLen - 1);
creator.setPacketType(ccsds::PacketType::TC);
payloadStart = buf + ccsds::HEADER_LEN;
}
ReturnValue_t checkPayloadLen() {
if(ccsds::HEADER_LEN + payloadLen > maxSize) {
return SerializeIF::BUFFER_TOO_SHORT;
}
return result::OK;
}
ReturnValue_t serialize() {
size_t serLen = 0;
return creator.serializeBe(buf, serLen, maxSize);
}
ReturnValue_t checkSizeAndSerialize() {
ReturnValue_t result = checkPayloadLen();
if(result != result::OK) {
return result;
}
return serialize();
}
protected:
SpacePacketCreator& creator;
uint8_t* buf;
size_t payloadLen;
uint8_t* payloadStart;
size_t maxSize;
};
/** /**
* @brief This class creates a space packet containing only the header data and the CRC. * @brief This class creates a space packet containing only the header data and the CRC.
*/ */
class ApidOnlyPacket : public SpacePacket { class ApidOnlyPacket: public SpacePacketBase {
public: public:
/** /**
* @brief Constructor * @brief Constructor
@ -286,20 +323,33 @@ class ApidOnlyPacket : public SpacePacket {
* *
* @note Sequence count of empty packet is always 1. * @note Sequence count of empty packet is always 1.
*/ */
ApidOnlyPacket(uint16_t apid) : SpacePacket(LENGTH_EMPTY_TC - 1, true, apid, 1) { calcCrc(); } ApidOnlyPacket(uint16_t apid, SpacePacketCreator& creator, uint8_t* buf, size_t maxSize)
: SpacePacketBase(creator, buf, LENGTH_EMPTY_TC, maxSize) {
creator.setApid(apid);
}
ReturnValue_t buildPacket() {
ReturnValue_t result = checkSizeAndSerialize();
if(result != result::OK) {
return result;
}
calcCrc();
return result::OK;
}
private: private:
/** /**
* @brief CRC calculation which involves only the header in an empty packet * @brief CRC calculation which involves only the header in an empty packet
*/ */
void calcCrc() { void calcCrc() {
/* Calculate crc */ /* Calculate crc */
uint16_t crc = CRC::crc16ccitt(this->localData.byteStream, sizeof(CCSDSPrimaryHeader)); uint16_t crc = CRC::crc16ccitt(buf, ccsds::HEADER_LEN);
/* Add crc to packet data field of space packet */ /* Add crc to packet data field of space packet */
size_t serializedSize = 0; size_t serializedSize = 0;
uint8_t* crcPos = this->localData.fields.buffer; SerializeAdapter::serialize<uint16_t>(&crc, &payloadStart, &serializedSize, sizeof(crc),
SerializeAdapter::serialize<uint16_t>(&crc, &crcPos, &serializedSize, sizeof(crc),
SerializeIF::Endianness::BIG); SerializeIF::Endianness::BIG);
} }
}; };
@ -308,7 +358,7 @@ class ApidOnlyPacket : public SpacePacket {
* @brief This class can be used to generate the space packet selecting the boot image of * @brief This class can be used to generate the space packet selecting the boot image of
* of the MPSoC. * of the MPSoC.
*/ */
class MPSoCBootSelect : public SpacePacket { class MPSoCBootSelect : public SpacePacketBase {
public: public:
static const uint8_t NVM0 = 0; static const uint8_t NVM0 = 0;
static const uint8_t NVM1 = 1; static const uint8_t NVM1 = 1;
@ -323,13 +373,23 @@ class MPSoCBootSelect : public SpacePacket {
* *
* @note Selection of partitions is currently not supported. * @note Selection of partitions is currently not supported.
*/ */
MPSoCBootSelect(uint8_t mem = 0, uint8_t bp0 = 0, uint8_t bp1 = 0, uint8_t bp2 = 0) MPSoCBootSelect(SpacePacketCreator& creator, uint8_t* buf, size_t maxSize)
: SpacePacket(DATA_FIELD_LENGTH - 1, true, APID_SEL_MPSOC_BOOT_IMAGE, DEFAULT_SEQUENCE_COUNT), : SpacePacketBase(creator, buf, DATA_FIELD_LENGTH - 1, maxSize) {
mem(mem), creator.setApid(APID_SEL_MPSOC_BOOT_IMAGE);
bp0(bp0), creator.setSeqCount(DEFAULT_SEQUENCE_COUNT);
bp1(bp1), }
bp2(bp2) {
ReturnValue_t buildPacket(uint8_t mem_ = 0, uint8_t bp0_ = 0, uint8_t bp1_ = 0, uint8_t bp2_ = 0) {
mem = mem_;
bp0 = bp0_;
bp1 = bp1_;
bp2 = bp2_;
auto res = checkSizeAndSerialize();
if(res != result::OK) {
return res;
}
initPacket(); initPacket();
return res;
} }
private: private:
@ -348,18 +408,16 @@ class MPSoCBootSelect : public SpacePacket {
uint8_t bp2 = 0; uint8_t bp2 = 0;
void initPacket() { void initPacket() {
uint8_t* data_field_start = this->localData.fields.buffer; std::memcpy(payloadStart + MEM_OFFSET, &mem, sizeof(mem));
std::memcpy(data_field_start + MEM_OFFSET, &mem, sizeof(mem)); std::memcpy(payloadStart + BP0_OFFSET, &bp0, sizeof(bp0));
std::memcpy(data_field_start + BP0_OFFSET, &bp0, sizeof(bp0)); std::memcpy(payloadStart + BP1_OFFSET, &bp1, sizeof(bp1));
std::memcpy(data_field_start + BP1_OFFSET, &bp1, sizeof(bp1)); std::memcpy(payloadStart + BP2_OFFSET, &bp2, sizeof(bp2));
std::memcpy(data_field_start + BP2_OFFSET, &bp2, sizeof(bp2));
/* Calculate crc */ /* Calculate crc */
uint16_t crc = CRC::crc16ccitt(this->localData.byteStream, uint16_t crc = CRC::crc16ccitt(buf, ccsds::HEADER_LEN + DATA_FIELD_LENGTH - 2);
sizeof(CCSDSPrimaryHeader) + DATA_FIELD_LENGTH - 2);
/* Add crc to packet data field of space packet */ /* Add crc to packet data field of space packet */
size_t serializedSize = 0; size_t serializedSize = 0;
uint8_t* crcPos = this->localData.fields.buffer + CRC_OFFSET; uint8_t* crcPos = payloadStart + CRC_OFFSET;
SerializeAdapter::serialize<uint16_t>(&crc, &crcPos, &serializedSize, sizeof(crc), SerializeAdapter::serialize<uint16_t>(&crc, &crcPos, &serializedSize, sizeof(crc),
SerializeIF::Endianness::BIG); SerializeIF::Endianness::BIG);
} }
@ -369,7 +427,7 @@ class MPSoCBootSelect : public SpacePacket {
* @brief This class creates the command to enable or disable the NVMs connected to the * @brief This class creates the command to enable or disable the NVMs connected to the
* supervisor. * supervisor.
*/ */
class EnableNvms : public SpacePacket { class EnableNvms : public SpacePacketCreator {
public: public:
/** /**
* @brief Constructor * @brief Constructor
@ -412,7 +470,7 @@ class EnableNvms : public SpacePacket {
/** /**
* @brief This class generates the space packet to update the time of the PLOC supervisor. * @brief This class generates the space packet to update the time of the PLOC supervisor.
*/ */
class SetTimeRef : public SpacePacket { class SetTimeRef : public SpacePacketCreator {
public: public:
SetTimeRef(Clock::TimeOfDay_t* time) SetTimeRef(Clock::TimeOfDay_t* time)
: SpacePacket(DATA_FIELD_LENGTH - 1, true, APID_SET_TIME_REF, DEFAULT_SEQUENCE_COUNT) { : SpacePacket(DATA_FIELD_LENGTH - 1, true, APID_SET_TIME_REF, DEFAULT_SEQUENCE_COUNT) {
@ -467,7 +525,7 @@ class SetTimeRef : public SpacePacket {
/** /**
* @brief This class can be used to generate the set boot timout command. * @brief This class can be used to generate the set boot timout command.
*/ */
class SetBootTimeout : public SpacePacket { class SetBootTimeout : public SpacePacketCreator {
public: public:
/** /**
* @brief Constructor * @brief Constructor
@ -503,7 +561,7 @@ class SetBootTimeout : public SpacePacket {
/** /**
* @brief This class can be used to generate the space packet to set the maximum boot tries. * @brief This class can be used to generate the space packet to set the maximum boot tries.
*/ */
class SetRestartTries : public SpacePacket { class SetRestartTries : public SpacePacketCreator {
public: public:
/** /**
* @brief Constructor * @brief Constructor