APID getter bugfix

This commit is contained in:
Robin Müller 2022-07-22 16:41:32 +02:00
parent 9275ccb79b
commit f28b9ea61b
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
5 changed files with 78 additions and 3 deletions

View File

@ -31,7 +31,7 @@ class CCSDSDistributor : public TcDistributor,
/**
* The destructor is empty.
*/
virtual ~CCSDSDistributor();
~CCSDSDistributor() override;
MessageQueueId_t getRequestQueue() override;
ReturnValue_t registerApplication(uint16_t apid, MessageQueueId_t id) override;

View File

@ -51,9 +51,8 @@ class SpacePacketIF {
virtual PacketSeqCtrl getPacketSeqCtrl() { return PacketSeqCtrl::fromRaw(getPacketSeqCtrlRaw()); }
[[nodiscard]] virtual uint16_t getApid() const {
uint16_t packetId = getPacketIdRaw();
// Uppermost 11 bits of packet ID
return ((packetId >> 8) & 0b111) | (packetId & 0xFF);
return getPacketIdRaw() & 0x7ff;
}
/**

View File

@ -13,17 +13,27 @@ PusTmCreator::PusTmCreator(SpacePacketParams initSpParams, PusTmParams initPusPa
PusTmCreator::PusTmCreator() { setup(); }
uint16_t PusTmCreator::getPacketIdRaw() const { return spCreator.getPacketIdRaw(); }
uint16_t PusTmCreator::getPacketSeqCtrlRaw() const { return spCreator.getPacketSeqCtrlRaw(); }
uint16_t PusTmCreator::getPacketDataLen() const { return spCreator.getPacketDataLen(); }
uint8_t PusTmCreator::getPusVersion() const { return pusParams.secHeader.pusVersion; }
uint8_t PusTmCreator::getService() const { return pusParams.secHeader.service; }
uint8_t PusTmCreator::getSubService() const { return pusParams.secHeader.subservice; }
PusTmParams& PusTmCreator::getParams() { return pusParams; }
void PusTmCreator::setTimeStamper(TimeStamperIF* timeStamper_) {
pusParams.secHeader.timeStamper = timeStamper_;
}
uint8_t PusTmCreator::getScTimeRefStatus() { return pusParams.secHeader.scTimeRefStatus; }
uint16_t PusTmCreator::getMessageTypeCounter() { return pusParams.secHeader.messageTypeCounter; }
uint16_t PusTmCreator::getDestId() { return pusParams.secHeader.destId; }
ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t maxSize,
@ -83,7 +93,9 @@ ReturnValue_t PusTmCreator::deSerialize(const uint8_t** buffer, size_t* size,
}
ecss::DataWrapper& PusTmCreator::getDataWrapper() { return pusParams.dataWrapper; }
TimeStamperIF* PusTmCreator::getTimestamper() const { return pusParams.secHeader.timeStamper; }
SpacePacketParams& PusTmCreator::getSpParams() { return spCreator.getParams(); }
void PusTmCreator::updateSpLengthField() {
@ -105,3 +117,22 @@ void PusTmCreator::setup() {
updateSpLengthField();
spCreator.setPacketType(ccsds::PacketType::TM);
}
void PusTmCreator::setMessageTypeCounter(uint16_t messageTypeCounter) {
pusParams.secHeader.messageTypeCounter = messageTypeCounter;
};
void PusTmCreator::setDestId(uint16_t destId) { pusParams.secHeader.destId = destId; }
void PusTmCreator::setRawSourceData(ecss::DataWrapper::BufPairT bufPair) {
pusParams.dataWrapper.type = ecss::DataTypes::RAW;
pusParams.dataWrapper.dataUnion.raw.data = bufPair.first;
pusParams.dataWrapper.dataUnion.raw.len = bufPair.second;
updateSpLengthField();
}
void PusTmCreator::setSerializableSourceData(SerializeIF* serializable) {
pusParams.dataWrapper.type = ecss::DataTypes::SERIALIZABLE;
pusParams.dataWrapper.dataUnion.serializable = serializable;
updateSpLengthField();
}

View File

@ -47,7 +47,11 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CreatorDataIF {
void setTimeStamper(TimeStamperIF* timeStamper);
SpacePacketParams& getSpParams();
void setRawSourceData(ecss::DataWrapper::BufPairT bufPair);
void setSerializableSourceData(SerializeIF* serializable);
void setApid(uint16_t apid);
void setDestId(uint16_t destId);
void setMessageTypeCounter(uint16_t messageTypeCounter);
PusTmParams& getParams();
void updateSpLengthField();
[[nodiscard]] uint16_t getPacketIdRaw() const override;

View File

@ -62,4 +62,45 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") {
REQUIRE(buf[20] == 0x03);
REQUIRE(buf[21] == 0x79);
}
SECTION("Custom Fields") {
creator.setApid(0x3ff);
SECTION("Using Params") {
auto& pusParams = creator.getParams();
pusParams.secHeader.destId = 0xfff;
pusParams.secHeader.messageTypeCounter = 0x313;
}
SECTION("Using Setters") {
auto& pusParams = creator.getParams();
creator.setDestId(0xfff);
creator.setMessageTypeCounter(0x313);
}
REQUIRE(creator.getApid() == 0x3ff);
REQUIRE(creator.getDestId() == 0xfff);
REQUIRE(creator.getMessageTypeCounter() == 0x313);
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
// Message Sequence Count
REQUIRE(((buf[9] << 8) | buf[10]) == 0x313);
// Destination ID
REQUIRE(((buf[11] << 8) | buf[12]) == 0xfff);
}
SECTION("Deserialization fails") {
const uint8_t* roDataPtr = nullptr;
REQUIRE(creator.deSerialize(&roDataPtr, &serLen, SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_FAILED);
}
SECTION("Serialize with Raw Data") {
std::array<uint8_t, 3> data{1, 2, 3};
creator.setRawSourceData({data.data(), data.size()});
REQUIRE(creator.getFullPacketLen() == 25);
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(buf[20] == 1);
REQUIRE(buf[21] == 2);
REQUIRE(buf[22] == 3);
}
SECTION("Serialize with Serializable") {
}
}