Merge branch 'mueller/expand-serialize-if' into mueller/refactor-tmtc-stack
All checks were successful
fsfw/fsfw/pipeline/pr-development This commit looks good

This commit is contained in:
Robin Müller 2022-07-25 11:35:32 +02:00
commit ca1e921b94
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
4 changed files with 25 additions and 27 deletions

View File

@ -62,9 +62,9 @@ class SerializeIF {
virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const = 0;
/**
* Forwards to regular @serialize call with network endianness
* Forwards to regular @serialize call with big (network) endianness
*/
virtual ReturnValue_t serializeNe(uint8_t **buffer, size_t *size, size_t maxSize) {
virtual ReturnValue_t serializeBe(uint8_t** buffer, size_t* size, size_t maxSize) {
return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK);
}
/**
@ -103,9 +103,9 @@ class SerializeIF {
virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
Endianness streamEndianness) = 0;
/**
* Forwards to regular @deSerialize call with network endianness
* Forwards to regular @deSerialize call with big (network) endianness
*/
virtual ReturnValue_t deSerializeNe(const uint8_t **buffer, size_t *size) {
virtual ReturnValue_t deSerializeBe(const uint8_t** buffer, size_t* size) {
return deSerialize(buffer, size, SerializeIF::Endianness::NETWORK);
}
/**
@ -129,9 +129,9 @@ class SerializeIF {
return serialize(&buffer, &tmpSize, maxSize, streamEndianness);
}
/**
* Forwards to regular @serialize call with network endianness
* Forwards to regular @serialize call with big (network) endianness
*/
virtual ReturnValue_t serializeNe(uint8_t *buffer, size_t maxSize) const {
virtual ReturnValue_t serializeBe(uint8_t *buffer, size_t maxSize) const {
return serialize(buffer, maxSize, SerializeIF::Endianness::NETWORK);
}
/**
@ -154,9 +154,9 @@ class SerializeIF {
return deSerialize(&buffer, &maxSize, streamEndianness);
}
/**
* Forwards to regular @serialize call with network endianness
* Forwards to regular @serialize call with big (network) endianness
*/
virtual ReturnValue_t deSerializeNe(const uint8_t *buffer, size_t maxSize) {
virtual ReturnValue_t deSerializeBe(const uint8_t *buffer, size_t maxSize) {
return deSerialize(buffer, maxSize, SerializeIF::Endianness::NETWORK);
}
/**

View File

@ -42,7 +42,7 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") {
HasReturnvaluesIF::RETURN_OK);
}
SECTION("Network 1") {
REQUIRE(simpleSer.serializeNe(&ptr, &len, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(simpleSer.serializeBe(&ptr, &len, buf.size()) == HasReturnvaluesIF::RETURN_OK);
}
CHECK(buf[0] == 1);
@ -65,8 +65,7 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") {
HasReturnvaluesIF::RETURN_OK);
}
SECTION("Network 1") {
REQUIRE(simpleSer.SerializeIF::serializeNe(buf.data(), buf.size()) ==
HasReturnvaluesIF::RETURN_OK);
REQUIRE(simpleSer.SerializeIF::serializeBe(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK);
}
CHECK(buf[0] == 1);
CHECK(buf[1] == 2);
@ -135,7 +134,7 @@ TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") {
HasReturnvaluesIF::RETURN_OK);
}
SECTION("Network 1") {
REQUIRE(simpleSer.SerializeIF::deSerializeNe(&ptr, &len) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(simpleSer.SerializeIF::deSerializeBe(&ptr, &len) == HasReturnvaluesIF::RETURN_OK);
}
CHECK(simpleSer.getU8() == 5);
CHECK(simpleSer.getU16() == 1);
@ -155,8 +154,7 @@ TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") {
HasReturnvaluesIF::RETURN_OK);
}
SECTION("Network 1") {
REQUIRE(simpleSer.SerializeIF::deSerializeNe(buf.data(), buf.size()) ==
HasReturnvaluesIF::RETURN_OK);
REQUIRE(simpleSer.SerializeIF::deSerializeBe(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK);
}
CHECK(simpleSer.getU8() == 5);
CHECK(simpleSer.getU16() == 1);

View File

@ -43,15 +43,15 @@ TEST_CASE("CCSDS Packet ID", "[ccsds-packet-id]") {
packetId.secHeaderFlag = false;
packetId.packetType = ccsds::PacketType::TM;
REQUIRE(packetId.raw() == 0x1ff);
REQUIRE(packetId.SerializeIF::serializeNe(buf.data(), buf.size()) ==
REQUIRE(packetId.SerializeIF::serializeBe(buf.data(), buf.size()) ==
HasReturnvaluesIF::RETURN_OK);
CHECK(buf[0] == 0x1);
CHECK(buf[1] == 0xff);
}
SECTION("Invalid Ser") {
REQUIRE(packetId.SerializeIF::serializeNe(buf.data(), 0) == SerializeIF::BUFFER_TOO_SHORT);
REQUIRE(packetId.SerializeIF::serializeNe(buf.data(), 1) == SerializeIF::BUFFER_TOO_SHORT);
REQUIRE(packetId.SerializeIF::serializeBe(buf.data(), 0) == SerializeIF::BUFFER_TOO_SHORT);
REQUIRE(packetId.SerializeIF::serializeBe(buf.data(), 1) == SerializeIF::BUFFER_TOO_SHORT);
}
SECTION("Invalid Deser") {
@ -84,7 +84,7 @@ TEST_CASE("CCSDS Packet Seq Ctrl", "[ccsds-packet-seq-ctrl]") {
psc.seqFlags = ccsds::SequenceFlags::FIRST_SEGMENT;
psc.seqCount = static_cast<uint16_t>(std::round(std::pow(2, 14) - 1));
REQUIRE(psc.raw() == 0x7fff);
REQUIRE(psc.SerializeIF::serializeNe(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(psc.SerializeIF::serializeBe(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK);
CHECK(buf[0] == 0x7f);
CHECK(buf[1] == 0xff);
}
@ -106,8 +106,8 @@ TEST_CASE("CCSDS Packet Seq Ctrl", "[ccsds-packet-seq-ctrl]") {
}
SECTION("Invalid Ser") {
REQUIRE(psc.SerializeIF::serializeNe(buf.data(), 0) == SerializeIF::BUFFER_TOO_SHORT);
REQUIRE(psc.SerializeIF::serializeNe(buf.data(), 1) == SerializeIF::BUFFER_TOO_SHORT);
REQUIRE(psc.SerializeIF::serializeBe(buf.data(), 0) == SerializeIF::BUFFER_TOO_SHORT);
REQUIRE(psc.SerializeIF::serializeBe(buf.data(), 1) == SerializeIF::BUFFER_TOO_SHORT);
}
SECTION("Invalid Deser") {

View File

@ -44,7 +44,7 @@ TEST_CASE("CCSDS Creator", "[ccsds-creator]") {
}
SECTION("Raw Output") {
REQUIRE(base.serializeNe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(base.serializeBe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
// TC, and secondary header flag is set -> 0b0001100 -> 0x18
CHECK(buf[0] == 0x18);
// APID 0x02
@ -66,7 +66,7 @@ TEST_CASE("CCSDS Creator", "[ccsds-creator]") {
base.setSeqFlags(ccsds::SequenceFlags::UNSEGMENTED);
base.setDataLen(static_cast<int>(std::pow(2, 16)) - 1);
REQUIRE(base.isValid());
REQUIRE(base.serializeNe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(base.serializeBe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
CHECK(buf[0] == 0x1F);
CHECK(buf[1] == 0xFF);
CHECK(buf[2] == 0xFF);
@ -80,28 +80,28 @@ TEST_CASE("CCSDS Creator", "[ccsds-creator]") {
ccsds::PacketType::TC, true, 0xFFFF, ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16);
REQUIRE(not creator.isValid());
REQUIRE(not creator);
REQUIRE(creator.serializeNe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED);
REQUIRE(creator.serializeBe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED);
}
SECTION("Invalid Seq Count") {
SpacePacketCreator invalid = SpacePacketCreator(
ccsds::PacketType::TC, true, 0x02, ccsds::SequenceFlags::FIRST_SEGMENT, 0xFFFF, 0x16);
REQUIRE(not invalid.isValid());
REQUIRE(invalid.serializeNe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED);
REQUIRE(invalid.serializeBe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED);
}
SECTION("Invalid Buf Size 1") {
serLen = 2;
REQUIRE(base.serializeNe(&bufPtr, &serLen, buf.size()) == SerializeIF::BUFFER_TOO_SHORT);
REQUIRE(base.serializeBe(&bufPtr, &serLen, buf.size()) == SerializeIF::BUFFER_TOO_SHORT);
}
SECTION("Invalid Buf Size 2") {
serLen = 4;
REQUIRE(base.serializeNe(&bufPtr, &serLen, buf.size()) == SerializeIF::BUFFER_TOO_SHORT);
REQUIRE(base.serializeBe(&bufPtr, &serLen, buf.size()) == SerializeIF::BUFFER_TOO_SHORT);
}
SECTION("Invalid Buf Size 3") {
serLen = 6;
REQUIRE(base.serializeNe(&bufPtr, &serLen, buf.size()) == SerializeIF::BUFFER_TOO_SHORT);
REQUIRE(base.serializeBe(&bufPtr, &serLen, buf.size()) == SerializeIF::BUFFER_TOO_SHORT);
}
}