Update FSFW #24
@ -19,10 +19,11 @@ ReturnValue_t DleEncoder::encode(const uint8_t* sourceStream,
|
|||||||
return STREAM_TOO_SHORT;
|
return STREAM_TOO_SHORT;
|
||||||
}
|
}
|
||||||
if (addStxEtx) {
|
if (addStxEtx) {
|
||||||
|
size_t currentIdx = 0;
|
||||||
if(not escapeStxEtx) {
|
if(not escapeStxEtx) {
|
||||||
destStream[0] = DLE_CHAR;
|
destStream[currentIdx++] = DLE_CHAR;
|
||||||
}
|
}
|
||||||
destStream[1] = STX_CHAR;
|
destStream[currentIdx] = STX_CHAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(escapeStxEtx) {
|
if(escapeStxEtx) {
|
||||||
@ -122,8 +123,8 @@ ReturnValue_t DleEncoder::encodeStreamNonEscaped(const uint8_t *sourceStream, si
|
|||||||
|
|
||||||
if (sourceIndex == sourceLen and encodedIndex < maxDestLen) {
|
if (sourceIndex == sourceLen and encodedIndex < maxDestLen) {
|
||||||
if (addStxEtx) {
|
if (addStxEtx) {
|
||||||
destStream[encodedIndex] = ETX_CHAR;
|
destStream[encodedIndex++] = DLE_CHAR;
|
||||||
++encodedIndex;
|
destStream[encodedIndex++] = ETX_CHAR;
|
||||||
}
|
}
|
||||||
*encodedLen = encodedIndex;
|
*encodedLen = encodedIndex;
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
|
@ -22,19 +22,39 @@ const std::vector<uint8_t> TEST_ARRAY_0_ENCODED_NON_ESCAPED = {
|
|||||||
const std::vector<uint8_t> TEST_ARRAY_1_ENCODED_ESCAPED = {
|
const std::vector<uint8_t> TEST_ARRAY_1_ENCODED_ESCAPED = {
|
||||||
DleEncoder::STX_CHAR, 0, DleEncoder::DLE_CHAR, DleEncoder::DLE_CHAR, 5, DleEncoder::ETX_CHAR
|
DleEncoder::STX_CHAR, 0, DleEncoder::DLE_CHAR, DleEncoder::DLE_CHAR, 5, DleEncoder::ETX_CHAR
|
||||||
};
|
};
|
||||||
|
const std::vector<uint8_t> TEST_ARRAY_1_ENCODED_NON_ESCAPED = {
|
||||||
|
DleEncoder::DLE_CHAR, DleEncoder::STX_CHAR, 0, DleEncoder::DLE_CHAR, DleEncoder::DLE_CHAR,
|
||||||
|
5, DleEncoder::DLE_CHAR, DleEncoder::ETX_CHAR
|
||||||
|
};
|
||||||
|
|
||||||
const std::vector<uint8_t> TEST_ARRAY_2_ENCODED_ESCAPED = {
|
const std::vector<uint8_t> TEST_ARRAY_2_ENCODED_ESCAPED = {
|
||||||
DleEncoder::STX_CHAR, 0, DleEncoder::DLE_CHAR, DleEncoder::STX_CHAR + 0x40,
|
DleEncoder::STX_CHAR, 0, DleEncoder::DLE_CHAR, DleEncoder::STX_CHAR + 0x40,
|
||||||
5, DleEncoder::ETX_CHAR
|
5, DleEncoder::ETX_CHAR
|
||||||
};
|
};
|
||||||
|
const std::vector<uint8_t> TEST_ARRAY_2_ENCODED_NON_ESCAPED = {
|
||||||
|
DleEncoder::DLE_CHAR, DleEncoder::STX_CHAR, 0,
|
||||||
|
DleEncoder::STX_CHAR, 5, DleEncoder::DLE_CHAR, DleEncoder::ETX_CHAR
|
||||||
|
};
|
||||||
|
|
||||||
const std::vector<uint8_t> TEST_ARRAY_3_ENCODED_ESCAPED = {
|
const std::vector<uint8_t> TEST_ARRAY_3_ENCODED_ESCAPED = {
|
||||||
DleEncoder::STX_CHAR, 0, DleEncoder::CARRIAGE_RETURN,
|
DleEncoder::STX_CHAR, 0, DleEncoder::CARRIAGE_RETURN,
|
||||||
DleEncoder::DLE_CHAR, DleEncoder::ETX_CHAR + 0x40, DleEncoder::ETX_CHAR
|
DleEncoder::DLE_CHAR, DleEncoder::ETX_CHAR + 0x40, DleEncoder::ETX_CHAR
|
||||||
};
|
};
|
||||||
|
const std::vector<uint8_t> TEST_ARRAY_3_ENCODED_NON_ESCAPED = {
|
||||||
|
DleEncoder::DLE_CHAR, DleEncoder::STX_CHAR, 0,
|
||||||
|
DleEncoder::CARRIAGE_RETURN, DleEncoder::ETX_CHAR, DleEncoder::DLE_CHAR,
|
||||||
|
DleEncoder::ETX_CHAR
|
||||||
|
};
|
||||||
|
|
||||||
const std::vector<uint8_t> TEST_ARRAY_4_ENCODED_ESCAPED = {
|
const std::vector<uint8_t> TEST_ARRAY_4_ENCODED_ESCAPED = {
|
||||||
DleEncoder::STX_CHAR, DleEncoder::DLE_CHAR, DleEncoder::DLE_CHAR,
|
DleEncoder::STX_CHAR, DleEncoder::DLE_CHAR, DleEncoder::DLE_CHAR,
|
||||||
DleEncoder::DLE_CHAR, DleEncoder::ETX_CHAR + 0x40, DleEncoder::DLE_CHAR,
|
DleEncoder::DLE_CHAR, DleEncoder::ETX_CHAR + 0x40, DleEncoder::DLE_CHAR,
|
||||||
DleEncoder::STX_CHAR + 0x40, DleEncoder::ETX_CHAR
|
DleEncoder::STX_CHAR + 0x40, DleEncoder::ETX_CHAR
|
||||||
};
|
};
|
||||||
|
const std::vector<uint8_t> TEST_ARRAY_4_ENCODED_NON_ESCAPED = {
|
||||||
|
DleEncoder::DLE_CHAR, DleEncoder::STX_CHAR, DleEncoder::DLE_CHAR, DleEncoder::DLE_CHAR,
|
||||||
|
DleEncoder::ETX_CHAR, DleEncoder::STX_CHAR, DleEncoder::DLE_CHAR, DleEncoder::ETX_CHAR
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE("DleEncoder" , "[DleEncoder]") {
|
TEST_CASE("DleEncoder" , "[DleEncoder]") {
|
||||||
@ -75,16 +95,20 @@ TEST_CASE("DleEncoder" , "[DleEncoder]") {
|
|||||||
testLambdaEncode(dleEncoder, TEST_ARRAY_2, TEST_ARRAY_2_ENCODED_ESCAPED);
|
testLambdaEncode(dleEncoder, TEST_ARRAY_2, TEST_ARRAY_2_ENCODED_ESCAPED);
|
||||||
testLambdaEncode(dleEncoder, TEST_ARRAY_3, TEST_ARRAY_3_ENCODED_ESCAPED);
|
testLambdaEncode(dleEncoder, TEST_ARRAY_3, TEST_ARRAY_3_ENCODED_ESCAPED);
|
||||||
testLambdaEncode(dleEncoder, TEST_ARRAY_4, TEST_ARRAY_4_ENCODED_ESCAPED);
|
testLambdaEncode(dleEncoder, TEST_ARRAY_4, TEST_ARRAY_4_ENCODED_ESCAPED);
|
||||||
|
|
||||||
dleEncoder.setEscapeMode(false);
|
|
||||||
testLambdaEncode(dleEncoder, TEST_ARRAY_0, TEST_ARRAY_0_ENCODED_NON_ESCAPED);
|
|
||||||
|
|
||||||
ReturnValue_t result = dleEncoder.encode(TEST_ARRAY_3.data(), TEST_ARRAY_3.size(),
|
ReturnValue_t result = dleEncoder.encode(TEST_ARRAY_3.data(), TEST_ARRAY_3.size(),
|
||||||
buffer.data(), 0, &encodedLen);
|
buffer.data(), 0, &encodedLen);
|
||||||
REQUIRE(result == DleEncoder::STREAM_TOO_SHORT);
|
REQUIRE(result == DleEncoder::STREAM_TOO_SHORT);
|
||||||
result = dleEncoder.encode(TEST_ARRAY_1.data(), TEST_ARRAY_1.size(),
|
result = dleEncoder.encode(TEST_ARRAY_1.data(), TEST_ARRAY_1.size(),
|
||||||
buffer.data(), 4, &encodedLen);
|
buffer.data(), 4, &encodedLen);
|
||||||
REQUIRE(result == DleEncoder::STREAM_TOO_SHORT);
|
REQUIRE(result == DleEncoder::STREAM_TOO_SHORT);
|
||||||
|
|
||||||
|
dleEncoder.setEscapeMode(false);
|
||||||
|
testLambdaEncode(dleEncoder, TEST_ARRAY_0, TEST_ARRAY_0_ENCODED_NON_ESCAPED);
|
||||||
|
testLambdaEncode(dleEncoder, TEST_ARRAY_1, TEST_ARRAY_1_ENCODED_NON_ESCAPED);
|
||||||
|
testLambdaEncode(dleEncoder, TEST_ARRAY_2, TEST_ARRAY_2_ENCODED_NON_ESCAPED);
|
||||||
|
testLambdaEncode(dleEncoder, TEST_ARRAY_3, TEST_ARRAY_3_ENCODED_NON_ESCAPED);
|
||||||
|
testLambdaEncode(dleEncoder, TEST_ARRAY_4, TEST_ARRAY_4_ENCODED_NON_ESCAPED);
|
||||||
|
dleEncoder.setEscapeMode(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Decoding") {
|
SECTION("Decoding") {
|
||||||
|
Loading…
Reference in New Issue
Block a user