DLE Encoder Improvements #467

Merged
muellerr merged 22 commits from KSat/fsfw:mueller/dle-improvements into development 2021-09-13 15:25:02 +02:00
Showing only changes of commit abacfbf2d5 - Show all commits

View File

@ -154,6 +154,11 @@ ReturnValue_t DleEncoder::decodeStreamEscaped(const uint8_t *sourceStream, size_
size_t encodedIndex = 0;
size_t decodedIndex = 0;
uint8_t nextByte;
//init to 0 so that we can just return in the first checks (which do not consume anything from
//the source stream)
*readLen = 0;
if(maxDestStreamlen < 1) {
return STREAM_TOO_SHORT;
}
@ -166,6 +171,8 @@ ReturnValue_t DleEncoder::decodeStreamEscaped(const uint8_t *sourceStream, size_
and (sourceStream[encodedIndex] != STX_CHAR)) {
if (sourceStream[encodedIndex] == DLE_CHAR) {
if(encodedIndex + 1 >= sourceStreamLen) {
//reached the end of the sourceStream
*readLen = sourceStreamLen;
return DECODING_ERROR;
}
mohr marked this conversation as resolved Outdated
Outdated
Review

Enhancement over the original implementation: readlen should be set here (to sourceStreamLen), so that the user can resume parsing after the incorrect data.

Enhancement over the original implementation: readlen should be set here (to sourceStreamLen), so that the user can resume parsing after the incorrect data.
nextByte = sourceStream[encodedIndex + 1];
@ -200,6 +207,8 @@ ReturnValue_t DleEncoder::decodeStreamEscaped(const uint8_t *sourceStream, size_
}
if (sourceStream[encodedIndex] != ETX_CHAR) {
if(decodedIndex == maxDestStreamlen) {
//so far we did not find anything wrong here, so let user try again
*readLen = 0;
return STREAM_TOO_SHORT;
}
else {
@ -220,6 +229,11 @@ ReturnValue_t DleEncoder::decodeStreamNonEscaped(const uint8_t *sourceStream,
size_t encodedIndex = 0;
size_t decodedIndex = 0;
uint8_t nextByte;
mohr marked this conversation as resolved Outdated
Outdated
Review

I think it would be better to return *readlen = encodedIndex, so that the presumably valid DLE STX combination is preserved.

I think it would be better to return \*readlen = encodedIndex, so that the presumably valid DLE STX combination is preserved.
//init to 0 so that we can just return in the first checks (which do not consume anything from
//the source stream)
*readLen = 0;
if(maxDestStreamlen < 2) {
return STREAM_TOO_SHORT;
}
@ -227,6 +241,7 @@ ReturnValue_t DleEncoder::decodeStreamNonEscaped(const uint8_t *sourceStream,
return DECODING_ERROR;
}
if (sourceStream[encodedIndex++] != STX_CHAR) {
*readLen = 1;
return DECODING_ERROR;
}
while ((encodedIndex < sourceStreamLen) && (decodedIndex < maxDestStreamlen)) {
@ -265,11 +280,13 @@ ReturnValue_t DleEncoder::decodeStreamNonEscaped(const uint8_t *sourceStream,
++encodedIndex;
++decodedIndex;
}
*readLen = encodedIndex;
if(decodedIndex == maxDestStreamlen) {
//so far we did not find anything wrong here, so let user try again
*readLen = 0;
return STREAM_TOO_SHORT;
}
else {
} else {
*readLen = encodedIndex;
return DECODING_ERROR;
}
}