no payload packet impl

This commit is contained in:
Robin Müller 2022-11-07 10:30:09 +01:00
parent 32865d1834
commit 23025eec7a
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
4 changed files with 137 additions and 111 deletions

View File

@ -153,7 +153,7 @@ class TcBase : public ploc::SpTcBase, public MPSoCReturnValuesIF {
*/ */
TcBase(ploc::SpTcParams params, uint16_t apid, uint16_t sequenceCount) TcBase(ploc::SpTcParams params, uint16_t apid, uint16_t sequenceCount)
: ploc::SpTcBase(params, apid, sequenceCount) { : ploc::SpTcBase(params, apid, sequenceCount) {
spParams.setFullPacketLen(INIT_LENGTH); spParams.setFullPayloadLen(INIT_LENGTH);
} }
ReturnValue_t buildPacket() { return buildPacket(nullptr, 0); } ReturnValue_t buildPacket() { return buildPacket(nullptr, 0); }
@ -181,7 +181,7 @@ class TcBase : public ploc::SpTcBase, public MPSoCReturnValuesIF {
if (res != returnvalue::OK) { if (res != returnvalue::OK) {
return res; return res;
} }
return calcCrc(); return calcAndSetCrc();
} }
protected: protected:
@ -206,7 +206,7 @@ class TcMemRead : public TcBase {
*/ */
TcMemRead(ploc::SpTcParams params, uint16_t sequenceCount) TcMemRead(ploc::SpTcParams params, uint16_t sequenceCount)
: TcBase(params, apid::TC_MEM_READ, sequenceCount) { : TcBase(params, apid::TC_MEM_READ, sequenceCount) {
spParams.setFullPacketLen(COMMAND_LENGTH + CRC_SIZE); spParams.setFullPayloadLen(COMMAND_LENGTH + CRC_SIZE);
} }
uint16_t getMemLen() const { return memLen; } uint16_t getMemLen() const { return memLen; }
@ -267,7 +267,7 @@ class TcMemWrite : public TcBase {
} }
uint16_t memLen = uint16_t memLen =
*(commandData + MEM_ADDRESS_SIZE) << 8 | *(commandData + MEM_ADDRESS_SIZE + 1); *(commandData + MEM_ADDRESS_SIZE) << 8 | *(commandData + MEM_ADDRESS_SIZE + 1);
spParams.setFullPacketLen(MIN_FIXED_PAYLOAD_LENGTH + memLen * 4 + CRC_SIZE); spParams.setFullPayloadLen(MIN_FIXED_PAYLOAD_LENGTH + memLen * 4 + CRC_SIZE);
result = checkPayloadLen(); result = checkPayloadLen();
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
@ -313,7 +313,7 @@ class FlashFopen : public ploc::SpTcBase {
ReturnValue_t createPacket(std::string filename, char accessMode_) { ReturnValue_t createPacket(std::string filename, char accessMode_) {
accessMode = accessMode_; accessMode = accessMode_;
size_t nameSize = filename.size(); size_t nameSize = filename.size();
spParams.setFullPacketLen(nameSize + sizeof(NULL_TERMINATOR) + sizeof(accessMode) + CRC_SIZE); spParams.setFullPayloadLen(nameSize + sizeof(NULL_TERMINATOR) + sizeof(accessMode) + CRC_SIZE);
ReturnValue_t result = checkPayloadLen(); ReturnValue_t result = checkPayloadLen();
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
@ -322,7 +322,7 @@ class FlashFopen : public ploc::SpTcBase {
*(spParams.buf + nameSize) = NULL_TERMINATOR; *(spParams.buf + nameSize) = NULL_TERMINATOR;
std::memcpy(payloadStart + nameSize + sizeof(NULL_TERMINATOR), &accessMode, sizeof(accessMode)); std::memcpy(payloadStart + nameSize + sizeof(NULL_TERMINATOR), &accessMode, sizeof(accessMode));
updateSpFields(); updateSpFields();
return calcCrc(); return calcAndSetCrc();
} }
private: private:
@ -339,14 +339,14 @@ class FlashFclose : public ploc::SpTcBase {
ReturnValue_t createPacket(std::string filename) { ReturnValue_t createPacket(std::string filename) {
size_t nameSize = filename.size(); size_t nameSize = filename.size();
spParams.setFullPacketLen(nameSize + sizeof(NULL_TERMINATOR) + CRC_SIZE); spParams.setFullPayloadLen(nameSize + sizeof(NULL_TERMINATOR) + CRC_SIZE);
ReturnValue_t result = checkPayloadLen(); ReturnValue_t result = checkPayloadLen();
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
std::memcpy(payloadStart, filename.c_str(), nameSize); std::memcpy(payloadStart, filename.c_str(), nameSize);
*(payloadStart + nameSize) = NULL_TERMINATOR; *(payloadStart + nameSize) = NULL_TERMINATOR;
return calcCrc(); return calcAndSetCrc();
} }
}; };
@ -365,7 +365,7 @@ class TcFlashWrite : public ploc::SpTcBase {
sif::debug << "FlashWrite::createPacket: Command data too big" << std::endl; sif::debug << "FlashWrite::createPacket: Command data too big" << std::endl;
return returnvalue::FAILED; return returnvalue::FAILED;
} }
spParams.setFullPacketLen(static_cast<uint16_t>(writeLen) + 4 + CRC_SIZE); spParams.setFullPayloadLen(static_cast<uint16_t>(writeLen) + 4 + CRC_SIZE);
result = checkPayloadLen(); result = checkPayloadLen();
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
@ -382,7 +382,7 @@ class TcFlashWrite : public ploc::SpTcBase {
if (res != returnvalue::OK) { if (res != returnvalue::OK) {
return res; return res;
} }
return calcCrc(); return calcAndSetCrc();
} }
private: private:
@ -399,7 +399,7 @@ class TcFlashDelete : public ploc::SpTcBase {
ReturnValue_t buildPacket(std::string filename) { ReturnValue_t buildPacket(std::string filename) {
size_t nameSize = filename.size(); size_t nameSize = filename.size();
spParams.setFullPacketLen(nameSize + sizeof(NULL_TERMINATOR) + CRC_SIZE); spParams.setFullPayloadLen(nameSize + sizeof(NULL_TERMINATOR) + CRC_SIZE);
auto res = checkPayloadLen(); auto res = checkPayloadLen();
if (res != returnvalue::OK) { if (res != returnvalue::OK) {
return res; return res;
@ -412,7 +412,7 @@ class TcFlashDelete : public ploc::SpTcBase {
if (res != returnvalue::OK) { if (res != returnvalue::OK) {
return res; return res;
} }
return calcCrc(); return calcAndSetCrc();
} }
}; };
@ -439,7 +439,7 @@ class TcReplayStart : public TcBase {
protected: protected:
ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) override { ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) override {
ReturnValue_t result = returnvalue::OK; ReturnValue_t result = returnvalue::OK;
spParams.setFullPacketLen(commandDataLen + CRC_SIZE); spParams.setFullPayloadLen(commandDataLen + CRC_SIZE);
result = lengthCheck(commandDataLen); result = lengthCheck(commandDataLen);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
@ -500,7 +500,7 @@ class TcDownlinkPwrOn : public TcBase {
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
spParams.setFullPacketLen(commandDataLen + sizeof(MAX_AMPLITUDE) + CRC_SIZE); spParams.setFullPayloadLen(commandDataLen + sizeof(MAX_AMPLITUDE) + CRC_SIZE);
result = checkPayloadLen(); result = checkPayloadLen();
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
@ -571,7 +571,7 @@ class TcReplayWriteSeq : public TcBase {
protected: protected:
ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) override { ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) override {
ReturnValue_t result = returnvalue::OK; ReturnValue_t result = returnvalue::OK;
spParams.setFullPacketLen(commandDataLen + sizeof(NULL_TERMINATOR) + CRC_SIZE); spParams.setFullPayloadLen(commandDataLen + sizeof(NULL_TERMINATOR) + CRC_SIZE);
result = lengthCheck(commandDataLen); result = lengthCheck(commandDataLen);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
@ -657,8 +657,8 @@ class TcCamcmdSend : public TcBase {
return INVALID_LENGTH; return INVALID_LENGTH;
} }
uint16_t dataLen = static_cast<uint16_t>(commandDataLen + sizeof(CARRIAGE_RETURN)); uint16_t dataLen = static_cast<uint16_t>(commandDataLen + sizeof(CARRIAGE_RETURN));
spParams.setFullPacketLen(sizeof(dataLen) + commandDataLen + sizeof(CARRIAGE_RETURN) + spParams.setFullPayloadLen(sizeof(dataLen) + commandDataLen + sizeof(CARRIAGE_RETURN) +
CRC_SIZE); CRC_SIZE);
auto res = checkPayloadLen(); auto res = checkPayloadLen();
if (res != returnvalue::OK) { if (res != returnvalue::OK) {
return res; return res;

View File

@ -13,6 +13,8 @@
#include "linux/devices/devicedefinitions/SupvReturnValuesIF.h" #include "linux/devices/devicedefinitions/SupvReturnValuesIF.h"
#include "mission/devices/devicedefinitions/SpBase.h" #include "mission/devices/devicedefinitions/SpBase.h"
using namespace returnvalue;
namespace supv { namespace supv {
typedef struct { typedef struct {
@ -218,14 +220,28 @@ static const uint16_t APID_GET_HK_REPORT = 0xC6;
static const uint16_t APID_MASK = 0x3FF; static const uint16_t APID_MASK = 0x3FF;
static const uint16_t SEQUENCE_COUNT_MASK = 0xFFF; static const uint16_t SEQUENCE_COUNT_MASK = 0xFFF;
/** Offset from first byte in Space packet to first byte of data field */ static constexpr uint16_t DEFAULT_SEQUENCE_COUNT = 1;
static const uint8_t DATA_FIELD_OFFSET = 6; static const uint8_t HK_SET_ENTRIES = 13;
static const uint8_t BOOT_REPORT_SET_ENTRIES = 10;
static const uint8_t LATCHUP_RPT_SET_ENTRIES = 16;
static const uint8_t LOGGING_RPT_SET_ENTRIES = 16;
static const uint8_t ADC_RPT_SET_ENTRIES = 32;
/** static const uint32_t HK_SET_ID = HK_REPORT;
* Space packet length for fixed size packets. This is the size of the whole packet data static const uint32_t BOOT_REPORT_SET_ID = BOOT_STATUS_REPORT;
* field. For the length field in the space packet this size will be substracted by one. static const uint32_t LATCHUP_RPT_ID = LATCHUP_REPORT;
*/ static const uint32_t LOGGING_RPT_ID = LOGGING_REPORT;
static const uint16_t LENGTH_EMPTY_TC = 2; // Only CRC will be transported with the data field static const uint32_t ADC_REPORT_SET_ID = ADC_REPORT;
namespace recv_timeout {
// Erase memory can require up to 60 seconds for execution
static const uint32_t ERASE_MEMORY = 60000;
static const uint32_t UPDATE_STATUS_REPORT = 70000;
} // namespace recv_timeout
static constexpr size_t TIMESTAMP_LEN = 7;
static constexpr size_t SECONDARY_HEADER_LEN = TIMESTAMP_LEN + 1;
static constexpr size_t CRC_LEN = 2;
/** This is the maximum length of a space packet as defined by the TAS ICD */ /** This is the maximum length of a space packet as defined by the TAS ICD */
static const size_t MAX_COMMAND_SIZE = 1024; static const size_t MAX_COMMAND_SIZE = 1024;
@ -233,6 +249,10 @@ static const size_t MAX_DATA_CAPACITY = 1016;
/** This is the maximum size of a space packet for the supervisor */ /** This is the maximum size of a space packet for the supervisor */
static const size_t MAX_PACKET_SIZE = 1024; static const size_t MAX_PACKET_SIZE = 1024;
static constexpr size_t MIN_PAYLOAD_LEN = SECONDARY_HEADER_LEN + CRC_LEN;
static constexpr size_t MIN_TC_LEN = ccsds::HEADER_LEN + MIN_PAYLOAD_LEN;
static constexpr size_t PAYLOAD_OFFSET = ccsds::HEADER_LEN + SECONDARY_HEADER_LEN;
struct UpdateParams { struct UpdateParams {
std::string file; std::string file;
uint8_t memId; uint8_t memId;
@ -335,29 +355,6 @@ enum PoolIds : lp_id_t {
ADC_ENG_15 ADC_ENG_15
}; };
static constexpr uint16_t DEFAULT_SEQUENCE_COUNT = 1;
static const uint8_t HK_SET_ENTRIES = 13;
static const uint8_t BOOT_REPORT_SET_ENTRIES = 10;
static const uint8_t LATCHUP_RPT_SET_ENTRIES = 16;
static const uint8_t LOGGING_RPT_SET_ENTRIES = 16;
static const uint8_t ADC_RPT_SET_ENTRIES = 32;
static const uint32_t HK_SET_ID = HK_REPORT;
static const uint32_t BOOT_REPORT_SET_ID = BOOT_STATUS_REPORT;
static const uint32_t LATCHUP_RPT_ID = LATCHUP_REPORT;
static const uint32_t LOGGING_RPT_ID = LOGGING_REPORT;
static const uint32_t ADC_REPORT_SET_ID = ADC_REPORT;
namespace recv_timeout {
// Erase memory can require up to 60 seconds for execution
static const uint32_t ERASE_MEMORY = 60000;
static const uint32_t UPDATE_STATUS_REPORT = 70000;
} // namespace recv_timeout
static constexpr size_t TIMESTAMP_LEN = 7;
static constexpr size_t SECONDARY_HEADER_LEN = TIMESTAMP_LEN + 1;
static constexpr size_t CRC_LEN = 2;
struct SupvTcParams : public ploc::SpTcParams { struct SupvTcParams : public ploc::SpTcParams {
public: public:
SupvTcParams(SpacePacketCreator& creator) : ploc::SpTcParams(creator) {} SupvTcParams(SpacePacketCreator& creator) : ploc::SpTcParams(creator) {}
@ -366,20 +363,49 @@ struct SupvTcParams : public ploc::SpTcParams {
: ploc::SpTcParams(creator, buf, maxSize) {} : ploc::SpTcParams(creator, buf, maxSize) {}
void setLenFromPayloadLen(size_t payloadLen) { void setLenFromPayloadLen(size_t payloadLen) {
setFullPacketLen(ccsds::HEADER_LEN + SECONDARY_HEADER_LEN + payloadLen + CRC_LEN); setFullPayloadLen(ccsds::HEADER_LEN + SECONDARY_HEADER_LEN + payloadLen + CRC_LEN);
} }
}; };
class SupvTcBase : public ploc::SpTcBase { class SupvTcBase : public ploc::SpTcBase {
public: public:
SupvTcBase(SupvTcParams params) : ploc::SpTcBase(params) {} SupvTcBase(SupvTcParams params) : ploc::SpTcBase(params) { setup(); }
SupvTcBase(SupvTcParams params, uint16_t apid, uint16_t seqCount) SupvTcBase(SupvTcParams params, uint16_t apid, uint8_t serviceId, uint16_t seqCount)
: ploc::SpTcBase(params, apid, seqCount) {} : ploc::SpTcBase(params, apid, seqCount), serviceId(serviceId) {
if (setup() == OK) {
params.buf + supv::PAYLOAD_OFFSET = serviceId;
}
}
private:
uint8_t serviceId = 0;
ReturnValue_t setup() {
if (spParams.maxSize < MIN_PAYLOAD_LEN) {
sif::error << "SupvTcBase::SupvTcBase: Passed buffer is too small" << std::endl;
return returnvalue::FAILED;
}
std::memset(spParams.buf + ccsds::HEADER_LEN, 0, TIMESTAMP_LEN);
return returnvalue::OK;
}
};
class NoPayloadPacket : public SupvTcBase {
public:
NoPayloadPacket(SupvTcParams params, uint16_t apid, uint8_t serviceId, uint16_t seqCount)
: SupvTcBase(params, apid, serviceId, seqCount) {}
ReturnValue_t buildPacket() {
ReturnValue_t result = checkSizeAndSerializeHeader();
if (result != OK) {
return result;
}
return calcAndSetCrc();
}
private: private:
}; };
/** /**
* @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.
*/ */
@ -393,7 +419,7 @@ class ApidOnlyPacket : public ploc::SpTcBase {
* @note Sequence count of empty packet is always 1. * @note Sequence count of empty packet is always 1.
*/ */
ApidOnlyPacket(ploc::SpTcParams params, uint16_t apid) : ploc::SpTcBase(params) { ApidOnlyPacket(ploc::SpTcParams params, uint16_t apid) : ploc::SpTcBase(params) {
spParams.setFullPacketLen(LENGTH_EMPTY_TC); spParams.setFullPayloadLen(MIN_TC_LEN);
spParams.creator.setApid(apid); spParams.creator.setApid(apid);
} }
@ -402,7 +428,7 @@ class ApidOnlyPacket : public ploc::SpTcBase {
if (res != returnvalue::OK) { if (res != returnvalue::OK) {
return res; return res;
} }
return calcCrc(); return calcAndSetCrc();
} }
private: private:
@ -428,7 +454,7 @@ class MPSoCBootSelect : public ploc::SpTcBase {
* @note Selection of partitions is currently not supported. * @note Selection of partitions is currently not supported.
*/ */
MPSoCBootSelect(ploc::SpTcParams params) : ploc::SpTcBase(params) { MPSoCBootSelect(ploc::SpTcParams params) : ploc::SpTcBase(params) {
spParams.setFullPacketLen(DATA_FIELD_LENGTH); spParams.setFullPayloadLen(DATA_FIELD_LENGTH);
spParams.creator.setApid(APID_SEL_MPSOC_BOOT_IMAGE); spParams.creator.setApid(APID_SEL_MPSOC_BOOT_IMAGE);
spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT); spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT);
} }
@ -439,7 +465,7 @@ class MPSoCBootSelect : public ploc::SpTcBase {
return res; return res;
} }
initPacket(mem, bp0, bp1, bp2); initPacket(mem, bp0, bp1, bp2);
return calcCrc(); return calcAndSetCrc();
} }
private: private:
@ -474,7 +500,7 @@ class EnableNvms : public ploc::SpTcBase {
* @param bp2 Partition pin 2 * @param bp2 Partition pin 2
*/ */
EnableNvms(ploc::SpTcParams params) : ploc::SpTcBase(params) { EnableNvms(ploc::SpTcParams params) : ploc::SpTcBase(params) {
spParams.setFullPacketLen(DATA_FIELD_LENGTH); spParams.setFullPayloadLen(DATA_FIELD_LENGTH);
spParams.creator.setApid(APID_ENABLE_NVMS); spParams.creator.setApid(APID_ENABLE_NVMS);
spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT); spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT);
} }
@ -485,7 +511,7 @@ class EnableNvms : public ploc::SpTcBase {
return res; return res;
} }
initPacket(nvm01, nvm3); initPacket(nvm01, nvm3);
return calcCrc(); return calcAndSetCrc();
} }
private: private:
@ -504,7 +530,7 @@ class EnableNvms : public ploc::SpTcBase {
class SetTimeRef : public ploc::SpTcBase { class SetTimeRef : public ploc::SpTcBase {
public: public:
SetTimeRef(ploc::SpTcParams params) : ploc::SpTcBase(params) { SetTimeRef(ploc::SpTcParams params) : ploc::SpTcBase(params) {
spParams.setFullPacketLen(DATA_FIELD_LENGTH); spParams.setFullPayloadLen(DATA_FIELD_LENGTH);
spParams.creator.setApid(APID_SET_TIME_REF); spParams.creator.setApid(APID_SET_TIME_REF);
spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT); spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT);
} }
@ -518,7 +544,7 @@ class SetTimeRef : public ploc::SpTcBase {
if (res != returnvalue::OK) { if (res != returnvalue::OK) {
return res; return res;
} }
return calcCrc(); return calcAndSetCrc();
} }
private: private:
@ -583,7 +609,7 @@ class SetBootTimeout : public ploc::SpTcBase {
* @param timeout The boot timeout in milliseconds. * @param timeout The boot timeout in milliseconds.
*/ */
SetBootTimeout(ploc::SpTcParams params) : ploc::SpTcBase(params) { SetBootTimeout(ploc::SpTcParams params) : ploc::SpTcBase(params) {
spParams.setFullPacketLen(DATA_FIELD_LENGTH); spParams.setFullPayloadLen(DATA_FIELD_LENGTH);
spParams.creator.setApid(APID_SET_BOOT_TIMEOUT); spParams.creator.setApid(APID_SET_BOOT_TIMEOUT);
spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT); spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT);
} }
@ -594,7 +620,7 @@ class SetBootTimeout : public ploc::SpTcBase {
return res; return res;
} }
initPacket(timeout); initPacket(timeout);
return calcCrc(); return calcAndSetCrc();
} }
private: private:
@ -620,7 +646,7 @@ class SetRestartTries : public ploc::SpTcBase {
* @param restartTries Maximum restart tries to set. * @param restartTries Maximum restart tries to set.
*/ */
SetRestartTries(ploc::SpTcParams params) : ploc::SpTcBase(params) { SetRestartTries(ploc::SpTcParams params) : ploc::SpTcBase(params) {
spParams.setFullPacketLen(DATA_FIELD_LENGTH); spParams.setFullPayloadLen(DATA_FIELD_LENGTH);
spParams.creator.setApid(APID_SET_MAX_RESTART_TRIES); spParams.creator.setApid(APID_SET_MAX_RESTART_TRIES);
spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT); spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT);
} }
@ -631,7 +657,7 @@ class SetRestartTries : public ploc::SpTcBase {
return res; return res;
} }
initPacket(restartTries); initPacket(restartTries);
return calcCrc(); return calcAndSetCrc();
} }
private: private:
@ -654,7 +680,7 @@ class DisablePeriodicHkTransmission : public ploc::SpTcBase {
* @brief Constructor * @brief Constructor
*/ */
DisablePeriodicHkTransmission(ploc::SpTcParams params) : ploc::SpTcBase(params) { DisablePeriodicHkTransmission(ploc::SpTcParams params) : ploc::SpTcBase(params) {
spParams.setFullPacketLen(DATA_FIELD_LENGTH); spParams.setFullPayloadLen(DATA_FIELD_LENGTH);
spParams.creator.setApid(APID_DISABLE_HK); spParams.creator.setApid(APID_DISABLE_HK);
spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT); spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT);
} }
@ -665,7 +691,7 @@ class DisablePeriodicHkTransmission : public ploc::SpTcBase {
return res; return res;
} }
initPacket(); initPacket();
return calcCrc(); return calcAndSetCrc();
} }
private: private:
@ -690,7 +716,7 @@ class LatchupAlert : public ploc::SpTcBase {
* 3 - 3.3V, 4 - NVM_4XO, 5 - MISSION, 6 - SAFECOTS) * 3 - 3.3V, 4 - NVM_4XO, 5 - MISSION, 6 - SAFECOTS)
*/ */
LatchupAlert(ploc::SpTcParams params) : ploc::SpTcBase(params) { LatchupAlert(ploc::SpTcParams params) : ploc::SpTcBase(params) {
spParams.setFullPacketLen(DATA_FIELD_LENGTH); spParams.setFullPayloadLen(DATA_FIELD_LENGTH);
spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT); spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT);
} }
@ -705,7 +731,7 @@ class LatchupAlert : public ploc::SpTcBase {
return res; return res;
} }
initPacket(latchupId); initPacket(latchupId);
return calcCrc(); return calcAndSetCrc();
} }
private: private:
@ -728,7 +754,7 @@ class SetAlertlimit : public ploc::SpTcBase {
* @param dutycycle * @param dutycycle
*/ */
SetAlertlimit(ploc::SpTcParams params) : ploc::SpTcBase(params) { SetAlertlimit(ploc::SpTcParams params) : ploc::SpTcBase(params) {
spParams.setFullPacketLen(DATA_FIELD_LENGTH); spParams.setFullPayloadLen(DATA_FIELD_LENGTH);
spParams.creator.setApid(APID_SET_ALERT_LIMIT); spParams.creator.setApid(APID_SET_ALERT_LIMIT);
spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT); spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT);
} }
@ -742,7 +768,7 @@ class SetAlertlimit : public ploc::SpTcBase {
if (res != returnvalue::OK) { if (res != returnvalue::OK) {
return res; return res;
} }
return calcCrc(); return calcAndSetCrc();
} }
private: private:
@ -771,7 +797,7 @@ class SetAdcEnabledChannels : public ploc::SpTcBase {
* @param ch Defines channels to be enabled or disabled. * @param ch Defines channels to be enabled or disabled.
*/ */
SetAdcEnabledChannels(ploc::SpTcParams params) : ploc::SpTcBase(params) { SetAdcEnabledChannels(ploc::SpTcParams params) : ploc::SpTcBase(params) {
spParams.setFullPacketLen(DATA_FIELD_LENGTH); spParams.setFullPayloadLen(DATA_FIELD_LENGTH);
spParams.creator.setApid(APID_SET_ADC_ENABLED_CHANNELS); spParams.creator.setApid(APID_SET_ADC_ENABLED_CHANNELS);
spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT); spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT);
} }
@ -782,7 +808,7 @@ class SetAdcEnabledChannels : public ploc::SpTcBase {
return res; return res;
} }
initPacket(ch); initPacket(ch);
return calcCrc(); return calcAndSetCrc();
} }
private: private:
@ -810,7 +836,7 @@ class SetAdcWindowAndStride : public ploc::SpTcBase {
* @param stridingStepSize * @param stridingStepSize
*/ */
SetAdcWindowAndStride(ploc::SpTcParams params) : ploc::SpTcBase(params) { SetAdcWindowAndStride(ploc::SpTcParams params) : ploc::SpTcBase(params) {
spParams.setFullPacketLen(DATA_FIELD_LENGTH); spParams.setFullPayloadLen(DATA_FIELD_LENGTH);
spParams.creator.setApid(APID_SET_ADC_WINDOW_AND_STRIDE); spParams.creator.setApid(APID_SET_ADC_WINDOW_AND_STRIDE);
spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT); spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT);
} }
@ -821,7 +847,7 @@ class SetAdcWindowAndStride : public ploc::SpTcBase {
return res; return res;
} }
initPacket(windowSize, stridingStepSize); initPacket(windowSize, stridingStepSize);
return calcCrc(); return calcAndSetCrc();
} }
private: private:
@ -850,7 +876,7 @@ class SetAdcThreshold : public ploc::SpTcBase {
* @param threshold * @param threshold
*/ */
SetAdcThreshold(ploc::SpTcParams params) : ploc::SpTcBase(params) { SetAdcThreshold(ploc::SpTcParams params) : ploc::SpTcBase(params) {
spParams.setFullPacketLen(DATA_FIELD_LENGTH); spParams.setFullPayloadLen(DATA_FIELD_LENGTH);
spParams.creator.setApid(APID_SET_ADC_THRESHOLD); spParams.creator.setApid(APID_SET_ADC_THRESHOLD);
spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT); spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT);
} }
@ -861,7 +887,7 @@ class SetAdcThreshold : public ploc::SpTcBase {
return res; return res;
} }
initPacket(threshold); initPacket(threshold);
return calcCrc(); return calcAndSetCrc();
} }
private: private:
@ -888,7 +914,7 @@ class RunAutoEmTests : public ploc::SpTcBase {
* @param test 1 - complete EM test, 2 - Short test (only memory readback NVM0,1,3) * @param test 1 - complete EM test, 2 - Short test (only memory readback NVM0,1,3)
*/ */
RunAutoEmTests(ploc::SpTcParams params) : ploc::SpTcBase(params) { RunAutoEmTests(ploc::SpTcParams params) : ploc::SpTcBase(params) {
spParams.setFullPacketLen(DATA_FIELD_LENGTH); spParams.setFullPayloadLen(DATA_FIELD_LENGTH);
spParams.creator.setApid(APID_RUN_AUTO_EM_TESTS); spParams.creator.setApid(APID_RUN_AUTO_EM_TESTS);
spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT); spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT);
} }
@ -899,7 +925,7 @@ class RunAutoEmTests : public ploc::SpTcBase {
return res; return res;
} }
initPacket(test); initPacket(test);
return calcCrc(); return calcAndSetCrc();
} }
private: private:
@ -930,7 +956,7 @@ class MramCmd : public ploc::SpTcBase {
* @note The content at the stop address is excluded from the dump or wipe operation. * @note The content at the stop address is excluded from the dump or wipe operation.
*/ */
MramCmd(ploc::SpTcParams params) : ploc::SpTcBase(params) { MramCmd(ploc::SpTcParams params) : ploc::SpTcBase(params) {
spParams.setFullPacketLen(DATA_FIELD_LENGTH); spParams.setFullPayloadLen(DATA_FIELD_LENGTH);
spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT); spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT);
} }
@ -947,7 +973,7 @@ class MramCmd : public ploc::SpTcBase {
return res; return res;
} }
initPacket(start, stop); initPacket(start, stop);
return calcCrc(); return calcAndSetCrc();
} }
private: private:
@ -984,7 +1010,7 @@ class SetGpio : public ploc::SpTcBase {
* @param val * @param val
*/ */
SetGpio(ploc::SpTcParams params) : ploc::SpTcBase(params) { SetGpio(ploc::SpTcParams params) : ploc::SpTcBase(params) {
spParams.setFullPacketLen(DATA_FIELD_LENGTH); spParams.setFullPayloadLen(DATA_FIELD_LENGTH);
spParams.creator.setApid(APID_SET_GPIO); spParams.creator.setApid(APID_SET_GPIO);
spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT); spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT);
} }
@ -995,7 +1021,7 @@ class SetGpio : public ploc::SpTcBase {
return res; return res;
} }
initPacket(port, pin, val); initPacket(port, pin, val);
return calcCrc(); return calcAndSetCrc();
} }
private: private:
@ -1028,7 +1054,7 @@ class ReadGpio : public ploc::SpTcBase {
* @param pin * @param pin
*/ */
ReadGpio(ploc::SpTcParams params) : ploc::SpTcBase(params) { ReadGpio(ploc::SpTcParams params) : ploc::SpTcBase(params) {
spParams.setFullPacketLen(DATA_FIELD_LENGTH); spParams.setFullPayloadLen(DATA_FIELD_LENGTH);
spParams.creator.setApid(APID_READ_GPIO); spParams.creator.setApid(APID_READ_GPIO);
spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT); spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT);
} }
@ -1039,7 +1065,7 @@ class ReadGpio : public ploc::SpTcBase {
return res; return res;
} }
initPacket(port, pin); initPacket(port, pin);
return calcCrc(); return calcAndSetCrc();
} }
private: private:
@ -1085,7 +1111,7 @@ class FactoryReset : public ploc::SpTcBase {
return res; return res;
} }
initPacket(op); initPacket(op);
return calcCrc(); return calcAndSetCrc();
} }
private: private:
@ -1105,14 +1131,14 @@ class FactoryReset : public ploc::SpTcBase {
default: default:
break; break;
} }
spParams.setFullPacketLen(packetDataLen); spParams.setFullPayloadLen(packetDataLen);
} }
}; };
class SetShutdownTimeout : public ploc::SpTcBase { class SetShutdownTimeout : public ploc::SpTcBase {
public: public:
SetShutdownTimeout(ploc::SpTcParams params) : ploc::SpTcBase(params) { SetShutdownTimeout(ploc::SpTcParams params) : ploc::SpTcBase(params) {
spParams.setFullPacketLen(PAYLOAD_LEN + 2); spParams.setFullPayloadLen(PAYLOAD_LEN + 2);
spParams.creator.setApid(APID_SET_SHUTDOWN_TIMEOUT); spParams.creator.setApid(APID_SET_SHUTDOWN_TIMEOUT);
spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT); spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT);
} }
@ -1123,7 +1149,7 @@ class SetShutdownTimeout : public ploc::SpTcBase {
return res; return res;
} }
initPacket(timeout); initPacket(timeout);
return calcCrc(); return calcAndSetCrc();
} }
private: private:
@ -1151,7 +1177,7 @@ class CheckMemory : public ploc::SpTcBase {
* @param length Length in bytes of memory region * @param length Length in bytes of memory region
*/ */
CheckMemory(ploc::SpTcParams params) : ploc::SpTcBase(params) { CheckMemory(ploc::SpTcParams params) : ploc::SpTcBase(params) {
spParams.setFullPacketLen(PAYLOAD_LENGTH + 2); spParams.setFullPayloadLen(PAYLOAD_LENGTH + 2);
spParams.creator.setApid(APID_CHECK_MEMORY); spParams.creator.setApid(APID_CHECK_MEMORY);
spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT); spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT);
} }
@ -1162,7 +1188,7 @@ class CheckMemory : public ploc::SpTcBase {
return res; return res;
} }
initPacket(memoryId, startAddress, length); initPacket(memoryId, startAddress, length);
return calcCrc(); return calcAndSetCrc();
} }
private: private:
@ -1216,7 +1242,7 @@ class WriteMemory : public ploc::SpTcBase {
if (res != returnvalue::OK) { if (res != returnvalue::OK) {
return res; return res;
} }
return calcCrc(); return calcAndSetCrc();
} }
// Although the space packet has space left for 1010 bytes of data to supervisor can only process // Although the space packet has space left for 1010 bytes of data to supervisor can only process
// update packets with a maximum of 512 bytes. // update packets with a maximum of 512 bytes.
@ -1230,9 +1256,9 @@ class WriteMemory : public ploc::SpTcBase {
uint8_t* updateData) { uint8_t* updateData) {
uint8_t* data = payloadStart; uint8_t* data = payloadStart;
if (updateDataLen % 2 != 0) { if (updateDataLen % 2 != 0) {
spParams.setFullPacketLen(META_DATA_LENGTH + updateDataLen + 1 + 2); spParams.setFullPayloadLen(META_DATA_LENGTH + updateDataLen + 1 + 2);
} else { } else {
spParams.setFullPacketLen(META_DATA_LENGTH + updateDataLen + 2); spParams.setFullPayloadLen(META_DATA_LENGTH + updateDataLen + 2);
} }
// To avoid crashes in this unexpected case // To avoid crashes in this unexpected case
ReturnValue_t result = checkPayloadLen(); ReturnValue_t result = checkPayloadLen();
@ -1264,7 +1290,7 @@ class WriteMemory : public ploc::SpTcBase {
class EraseMemory : public ploc::SpTcBase { class EraseMemory : public ploc::SpTcBase {
public: public:
EraseMemory(ploc::SpTcParams params) : ploc::SpTcBase(params) { EraseMemory(ploc::SpTcParams params) : ploc::SpTcBase(params) {
spParams.setFullPacketLen(PAYLOAD_LENGTH + 2); spParams.setFullPayloadLen(PAYLOAD_LENGTH + 2);
spParams.creator.setApid(APID_ERASE_MEMORY); spParams.creator.setApid(APID_ERASE_MEMORY);
spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT); spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT);
} }
@ -1275,7 +1301,7 @@ class EraseMemory : public ploc::SpTcBase {
return res; return res;
} }
initPacket(memoryId, startAddress, length); initPacket(memoryId, startAddress, length);
return calcCrc(); return calcAndSetCrc();
} }
private: private:
@ -1306,7 +1332,7 @@ class EraseMemory : public ploc::SpTcBase {
class EnableAutoTm : public ploc::SpTcBase { class EnableAutoTm : public ploc::SpTcBase {
public: public:
EnableAutoTm(ploc::SpTcParams params) : ploc::SpTcBase(params) { EnableAutoTm(ploc::SpTcParams params) : ploc::SpTcBase(params) {
spParams.setFullPacketLen(PAYLOAD_LENGTH + 2); spParams.setFullPayloadLen(PAYLOAD_LENGTH + 2);
spParams.creator.setApid(APID_AUTO_TM); spParams.creator.setApid(APID_AUTO_TM);
spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT); spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT);
} }
@ -1317,7 +1343,7 @@ class EnableAutoTm : public ploc::SpTcBase {
return res; return res;
} }
payloadStart[0] = ENABLE; payloadStart[0] = ENABLE;
return calcCrc(); return calcAndSetCrc();
} }
private: private:
@ -1331,7 +1357,7 @@ class EnableAutoTm : public ploc::SpTcBase {
class DisableAutoTm : public ploc::SpTcBase { class DisableAutoTm : public ploc::SpTcBase {
public: public:
DisableAutoTm(ploc::SpTcParams params) : ploc::SpTcBase(params) { DisableAutoTm(ploc::SpTcParams params) : ploc::SpTcBase(params) {
spParams.setFullPacketLen(PAYLOAD_LENGTH + 2); spParams.setFullPayloadLen(PAYLOAD_LENGTH + 2);
spParams.creator.setApid(APID_AUTO_TM); spParams.creator.setApid(APID_AUTO_TM);
spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT); spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT);
} }
@ -1342,7 +1368,7 @@ class DisableAutoTm : public ploc::SpTcBase {
return res; return res;
} }
payloadStart[0] = DISABLE; payloadStart[0] = DISABLE;
return calcCrc(); return calcAndSetCrc();
} }
private: private:
@ -1366,7 +1392,7 @@ class RequestLoggingData : public ploc::SpTcBase {
}; };
RequestLoggingData(ploc::SpTcParams params) : ploc::SpTcBase(params) { RequestLoggingData(ploc::SpTcParams params) : ploc::SpTcBase(params) {
spParams.setFullPacketLen(PAYLOAD_LENGTH + 2); spParams.setFullPayloadLen(PAYLOAD_LENGTH + 2);
spParams.creator.setApid(APID_REQUEST_LOGGING_DATA); spParams.creator.setApid(APID_REQUEST_LOGGING_DATA);
spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT); spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT);
} }
@ -1383,7 +1409,7 @@ class RequestLoggingData : public ploc::SpTcBase {
} }
payloadStart[0] = static_cast<uint8_t>(sa); payloadStart[0] = static_cast<uint8_t>(sa);
payloadStart[1] = tpc; payloadStart[1] = tpc;
return calcCrc(); return calcAndSetCrc();
} }
private: private:

View File

@ -1028,7 +1028,7 @@ ReturnValue_t PlocSupervisorHandler::handleHkReport(const uint8_t* data) {
return result; return result;
} }
uint16_t offset = supv::DATA_FIELD_OFFSET; uint16_t offset = supv::PAYLOAD_OFFSET;
hkset.tempPs = *(data + offset) << 24 | *(data + offset + 1) << 16 | *(data + offset + 2) << 8 | hkset.tempPs = *(data + offset) << 24 | *(data + offset + 1) << 16 | *(data + offset + 2) << 8 |
*(data + offset + 3); *(data + offset + 3);
offset += 4; offset += 4;
@ -1106,7 +1106,7 @@ ReturnValue_t PlocSupervisorHandler::handleBootStatusReport(const uint8_t* data)
return result; return result;
} }
uint16_t offset = supv::DATA_FIELD_OFFSET; uint16_t offset = supv::PAYLOAD_OFFSET;
bootStatusReport.socState = *(data + offset); bootStatusReport.socState = *(data + offset);
offset += 1; offset += 1;
bootStatusReport.powerCycles = *(data + offset); bootStatusReport.powerCycles = *(data + offset);
@ -1171,7 +1171,7 @@ ReturnValue_t PlocSupervisorHandler::handleLatchupStatusReport(const uint8_t* da
return result; return result;
} }
uint16_t offset = supv::DATA_FIELD_OFFSET; uint16_t offset = supv::PAYLOAD_OFFSET;
latchupStatusReport.id = *(data + offset); latchupStatusReport.id = *(data + offset);
offset += 1; offset += 1;
latchupStatusReport.cnt0 = *(data + offset) << 8 | *(data + offset + 1); latchupStatusReport.cnt0 = *(data + offset) << 8 | *(data + offset + 1);
@ -1255,7 +1255,7 @@ ReturnValue_t PlocSupervisorHandler::handleLoggingReport(const uint8_t* data) {
return result; return result;
} }
const uint8_t* dataField = data + supv::DATA_FIELD_OFFSET + sizeof(supv::RequestLoggingData::Sa); const uint8_t* dataField = data + supv::PAYLOAD_OFFSET + sizeof(supv::RequestLoggingData::Sa);
result = loggingReport.read(); result = loggingReport.read();
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
@ -1291,7 +1291,7 @@ ReturnValue_t PlocSupervisorHandler::handleAdcReport(const uint8_t* data) {
return result; return result;
} }
const uint8_t* dataField = data + supv::DATA_FIELD_OFFSET; const uint8_t* dataField = data + supv::PAYLOAD_OFFSET;
result = adcReport.read(); result = adcReport.read();
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;

View File

@ -14,12 +14,12 @@ struct SpTcParams {
SpTcParams(SpacePacketCreator& creator, uint8_t* buf, size_t maxSize) SpTcParams(SpacePacketCreator& creator, uint8_t* buf, size_t maxSize)
: creator(creator), buf(buf), maxSize(maxSize) {} : creator(creator), buf(buf), maxSize(maxSize) {}
void setFullPacketLen(size_t fullPacketLen_) { fullPacketLen = fullPacketLen_; } void setFullPayloadLen(size_t fullPayloadLen_) { fullPayloadLen = fullPayloadLen_; }
SpacePacketCreator& creator; SpacePacketCreator& creator;
uint8_t* buf = nullptr; uint8_t* buf = nullptr;
size_t maxSize = 0; size_t maxSize = 0;
size_t fullPacketLen = 0; size_t fullPayloadLen = 0;
}; };
class SpTcBase { class SpTcBase {
@ -37,7 +37,7 @@ class SpTcBase {
} }
void updateSpFields() { void updateSpFields() {
spParams.creator.setDataLenField(spParams.fullPacketLen - 1); spParams.creator.setDataLenField(spParams.fullPayloadLen - 1);
spParams.creator.setPacketType(ccsds::PacketType::TC); spParams.creator.setPacketType(ccsds::PacketType::TC);
} }
@ -48,7 +48,7 @@ class SpTcBase {
uint16_t getApid() const { return spParams.creator.getApid(); } uint16_t getApid() const { return spParams.creator.getApid(); }
ReturnValue_t checkPayloadLen() { ReturnValue_t checkPayloadLen() {
if (ccsds::HEADER_LEN + spParams.fullPacketLen > spParams.maxSize) { if (ccsds::HEADER_LEN + spParams.fullPayloadLen > spParams.maxSize) {
return SerializeIF::BUFFER_TOO_SHORT; return SerializeIF::BUFFER_TOO_SHORT;
} }
@ -69,7 +69,7 @@ class SpTcBase {
return serializeHeader(); return serializeHeader();
} }
ReturnValue_t calcCrc() { ReturnValue_t calcAndSetCrc() {
/* Calculate crc */ /* Calculate crc */
uint16_t crc = CRC::crc16ccitt(spParams.buf, getFullPacketLen() - 2); uint16_t crc = CRC::crc16ccitt(spParams.buf, getFullPacketLen() - 2);