2022-08-15 17:25:16 +02:00
|
|
|
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_SPBASE_H_
|
|
|
|
#define MISSION_DEVICES_DEVICEDEFINITIONS_SPBASE_H_
|
|
|
|
|
|
|
|
#include <fsfw/tmtcpacket/ccsds/SpacePacketCreator.h>
|
2022-08-15 18:34:26 +02:00
|
|
|
#include <fsfw/tmtcpacket/ccsds/SpacePacketReader.h>
|
2022-08-15 17:25:16 +02:00
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
2022-08-15 18:34:26 +02:00
|
|
|
namespace ploc {
|
2022-08-15 17:25:16 +02:00
|
|
|
|
2022-08-15 18:34:26 +02:00
|
|
|
struct SpTcParams {
|
|
|
|
SpTcParams(SpacePacketCreator& creator) : creator(creator) {}
|
|
|
|
|
|
|
|
SpTcParams(SpacePacketCreator& creator, uint8_t* buf, size_t maxSize)
|
2022-08-15 17:25:16 +02:00
|
|
|
: creator(creator), buf(buf), maxSize(maxSize) {}
|
|
|
|
|
2022-11-07 10:30:09 +01:00
|
|
|
void setFullPayloadLen(size_t fullPayloadLen_) { fullPayloadLen = fullPayloadLen_; }
|
2022-08-15 17:25:16 +02:00
|
|
|
|
|
|
|
SpacePacketCreator& creator;
|
|
|
|
uint8_t* buf = nullptr;
|
|
|
|
size_t maxSize = 0;
|
2022-11-07 10:30:09 +01:00
|
|
|
size_t fullPayloadLen = 0;
|
2022-08-15 17:25:16 +02:00
|
|
|
};
|
|
|
|
|
2022-08-15 18:34:26 +02:00
|
|
|
class SpTcBase {
|
2022-08-15 17:25:16 +02:00
|
|
|
public:
|
2022-11-07 13:37:51 +01:00
|
|
|
SpTcBase(SpTcParams params) : SpTcBase(params, 0x00, 1, 0) {}
|
|
|
|
|
|
|
|
SpTcBase(SpTcParams params, uint16_t apid, size_t payloadLen)
|
|
|
|
: SpTcBase(params, apid, payloadLen, 0) {}
|
2022-08-15 17:25:16 +02:00
|
|
|
|
2022-11-07 13:37:51 +01:00
|
|
|
SpTcBase(SpTcParams params, uint16_t apid, size_t payloadLen, uint16_t seqCount)
|
|
|
|
: spParams(params) {
|
2022-08-15 17:25:16 +02:00
|
|
|
spParams.creator.setApid(apid);
|
|
|
|
spParams.creator.setSeqCount(seqCount);
|
2022-08-15 18:58:56 +02:00
|
|
|
payloadStart = spParams.buf + ccsds::HEADER_LEN;
|
2022-11-07 13:37:51 +01:00
|
|
|
spParams.fullPayloadLen = payloadLen;
|
2022-08-15 18:58:56 +02:00
|
|
|
updateSpFields();
|
2022-08-15 17:25:16 +02:00
|
|
|
}
|
|
|
|
|
2022-08-15 18:58:56 +02:00
|
|
|
void updateSpFields() {
|
2022-11-07 13:37:51 +01:00
|
|
|
updateLenFromParams();
|
2022-08-15 17:25:16 +02:00
|
|
|
spParams.creator.setPacketType(ccsds::PacketType::TC);
|
|
|
|
}
|
|
|
|
|
2022-11-07 13:37:51 +01:00
|
|
|
void updateLenFromParams() { spParams.creator.setDataLenField(spParams.fullPayloadLen - 1); }
|
2022-08-15 17:25:16 +02:00
|
|
|
const uint8_t* getFullPacket() const { return spParams.buf; }
|
|
|
|
|
|
|
|
size_t getFullPacketLen() const { return spParams.creator.getFullPacketLen(); }
|
|
|
|
|
|
|
|
uint16_t getApid() const { return spParams.creator.getApid(); }
|
|
|
|
|
2022-11-08 16:26:30 +01:00
|
|
|
uint16_t getSeqCount() const { return spParams.creator.getSequenceCount(); }
|
|
|
|
|
2022-08-15 17:25:16 +02:00
|
|
|
ReturnValue_t checkPayloadLen() {
|
2022-11-07 10:30:09 +01:00
|
|
|
if (ccsds::HEADER_LEN + spParams.fullPayloadLen > spParams.maxSize) {
|
2022-08-15 17:25:16 +02:00
|
|
|
return SerializeIF::BUFFER_TOO_SHORT;
|
|
|
|
}
|
|
|
|
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2022-08-15 17:25:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t serializeHeader() {
|
2022-08-15 18:58:56 +02:00
|
|
|
updateSpFields();
|
2022-08-15 17:25:16 +02:00
|
|
|
size_t serLen = 0;
|
|
|
|
return spParams.creator.serializeBe(spParams.buf, serLen, spParams.maxSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t checkSizeAndSerializeHeader() {
|
|
|
|
ReturnValue_t result = checkPayloadLen();
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-08-15 17:25:16 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return serializeHeader();
|
|
|
|
}
|
|
|
|
|
2022-11-07 10:30:09 +01:00
|
|
|
ReturnValue_t calcAndSetCrc() {
|
2022-08-15 17:25:16 +02:00
|
|
|
/* Calculate crc */
|
2022-08-18 15:32:24 +02:00
|
|
|
uint16_t crc = CRC::crc16ccitt(spParams.buf, getFullPacketLen() - 2);
|
2022-08-15 17:25:16 +02:00
|
|
|
|
|
|
|
/* Add crc to packet data field of space packet */
|
|
|
|
size_t serializedSize = 0;
|
2022-08-18 15:32:24 +02:00
|
|
|
return SerializeAdapter::serialize(&crc, spParams.buf + getFullPacketLen() - 2, &serializedSize,
|
|
|
|
spParams.maxSize, SerializeIF::Endianness::BIG);
|
2022-08-15 17:25:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2022-08-15 18:34:26 +02:00
|
|
|
ploc::SpTcParams spParams;
|
2022-08-15 17:25:16 +02:00
|
|
|
uint8_t* payloadStart;
|
|
|
|
};
|
|
|
|
|
2022-08-15 18:34:26 +02:00
|
|
|
/**
|
|
|
|
* @brief Class for handling tm replies of the supervisor.
|
|
|
|
*/
|
|
|
|
class SpTmReader : public SpacePacketReader {
|
|
|
|
public:
|
|
|
|
SpTmReader() = default;
|
|
|
|
/**
|
|
|
|
* @brief Constructor creates idle packet and sets length field to maximum allowed size.
|
|
|
|
*/
|
|
|
|
SpTmReader(const uint8_t* buf, size_t maxSize) : SpacePacketReader(buf, maxSize) {}
|
|
|
|
|
|
|
|
ReturnValue_t setData(const uint8_t* buf, size_t maxSize) {
|
|
|
|
return setReadOnlyData(buf, maxSize);
|
|
|
|
}
|
|
|
|
|
2022-11-08 11:08:21 +01:00
|
|
|
ReturnValue_t checkCrc() const {
|
2022-08-21 01:38:45 +02:00
|
|
|
if (CRC::crc16ccitt(getFullData(), getFullPacketLen()) != 0) {
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::FAILED;
|
2022-08-15 18:34:26 +02:00
|
|
|
}
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2022-08-15 18:34:26 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ploc
|
|
|
|
|
2022-08-15 17:25:16 +02:00
|
|
|
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_SPBASE_H_ */
|