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
2 changed files with 12 additions and 10 deletions
Showing only changes of commit b5063117f6 - Show all commits

View File

@ -10,12 +10,10 @@ ReturnValue_t DleEncoder::encode(const uint8_t* sourceStream,
size_t* encodedLen, bool addStxEtx) {
size_t minAllowedLen = 0;
mohr marked this conversation as resolved Outdated
Outdated
Review

addStxEtx comes into play here, too. If it is false, 1 or even 0 might be valid. I think STREAM_TOO_SHORT should be caught directely when writing to the dest stream

addStxEtx comes into play here, too. If it is false, 1 or even 0 might be valid. I think STREAM_TOO_SHORT should be caught directely when writing to the dest stream
if(escapeStxEtx) {
minAllowedLen = 2;
minAllowedLen = 1;
}
else {
minAllowedLen = 1;
minAllowedLen = 2;
}
if(maxDestLen < minAllowedLen) {
return STREAM_TOO_SHORT;
@ -41,7 +39,7 @@ ReturnValue_t DleEncoder::encode(const uint8_t* sourceStream,
ReturnValue_t DleEncoder::encodeStreamEscaped(const uint8_t *sourceStream, size_t sourceLen,
uint8_t *destStream, size_t maxDestLen, size_t *encodedLen,
bool addStxEtx) {
size_t encodedIndex = 2;
size_t encodedIndex = 1;
size_t sourceIndex = 0;
mohr marked this conversation as resolved Outdated
Outdated
Review

If addStxEtx is false, this must be 0

If addStxEtx is false, this must be 0
uint8_t nextByte = 0;
while (encodedIndex < maxDestLen and sourceIndex < sourceLen) {
@ -99,7 +97,7 @@ ReturnValue_t DleEncoder::encodeStreamEscaped(const uint8_t *sourceStream, size_
ReturnValue_t DleEncoder::encodeStreamNonEscaped(const uint8_t *sourceStream, size_t sourceLen,
uint8_t *destStream, size_t maxDestLen, size_t *encodedLen,
bool addStxEtx) {
size_t encodedIndex = 1;
size_t encodedIndex = 2;
size_t sourceIndex = 0;
uint8_t nextByte = 0;
while (encodedIndex < maxDestLen and sourceIndex < sourceLen) {
@ -166,10 +164,14 @@ ReturnValue_t DleEncoder::decodeStreamEscaped(const uint8_t *sourceStream, size_
size_t encodedIndex = 1;
size_t decodedIndex = 0;
uint8_t nextByte;
while ((encodedIndex < sourceStreamLen) && (decodedIndex < maxDestStreamlen)
&& (sourceStream[encodedIndex] != ETX_CHAR)
&& (sourceStream[encodedIndex] != STX_CHAR)) {
while ((encodedIndex < sourceStreamLen)
and (decodedIndex < maxDestStreamlen)
and (sourceStream[encodedIndex] != ETX_CHAR)
and (sourceStream[encodedIndex] != STX_CHAR)) {
if (sourceStream[encodedIndex] == DLE_CHAR) {
if(encodedIndex + 1 >= sourceStreamLen) {
return DECODING_ERROR;
}
nextByte = sourceStream[encodedIndex + 1];
// The next byte is a DLE character that was escaped by another
// DLE character, so we can write it to the destination stream.
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.

View File

@ -1,7 +1,7 @@
#ifndef FSFW_CATCHFACTORY_H_
#define FSFW_CATCHFACTORY_H_
#include "TestConfig.h"
#include "TestsConfig.h"
#include "fsfw/objectmanager/SystemObjectIF.h"
#include "fsfw/objectmanager/ObjectManager.h"