Merge branch 'mueller/dle-improvements' into mueller/master
This commit is contained in:
commit
ae3c56a27e
@ -1,6 +1,7 @@
|
||||
#include "fsfw/globalfunctions/DleEncoder.h"
|
||||
|
||||
DleEncoder::DleEncoder() {}
|
||||
DleEncoder::DleEncoder(bool escapeStxEtx, bool escapeCr): escapeStxEtx(escapeStxEtx),
|
||||
escapeCr(escapeCr) {}
|
||||
|
||||
DleEncoder::~DleEncoder() {}
|
||||
|
||||
@ -21,8 +22,8 @@ ReturnValue_t DleEncoder::encode(const uint8_t* sourceStream,
|
||||
nextByte = sourceStream[sourceIndex];
|
||||
// STX, ETX and CR characters in the stream need to be escaped with DLE
|
||||
if ((nextByte == STX_CHAR or nextByte == ETX_CHAR) or
|
||||
(escapeCr and nextByte == CARRIAGE_RETURN)) {
|
||||
if(escapeStxEtx) {
|
||||
(this->escapeCr and nextByte == CARRIAGE_RETURN)) {
|
||||
if(this->escapeStxEtx) {
|
||||
if (encodedIndex + 1 >= maxDestLen) {
|
||||
return STREAM_TOO_SHORT;
|
||||
}
|
||||
@ -73,7 +74,7 @@ ReturnValue_t DleEncoder::encode(const uint8_t* sourceStream,
|
||||
|
||||
ReturnValue_t DleEncoder::decode(const uint8_t *sourceStream,
|
||||
size_t sourceStreamLen, size_t *readLen, uint8_t *destStream,
|
||||
size_t maxDestStreamlen, size_t *decodedLen, bool escapeStxEtx, bool escapeCr) {
|
||||
size_t maxDestStreamlen, size_t *decodedLen) {
|
||||
size_t encodedIndex = 0, decodedIndex = 0;
|
||||
uint8_t nextByte;
|
||||
if (*sourceStream != STX_CHAR) {
|
||||
@ -92,13 +93,13 @@ ReturnValue_t DleEncoder::decode(const uint8_t *sourceStream,
|
||||
destStream[decodedIndex] = nextByte;
|
||||
}
|
||||
else {
|
||||
if(escapeStxEtx) {
|
||||
if(this->escapeStxEtx) {
|
||||
/* The next byte is a STX, DTX or 0x0D character which
|
||||
* was escaped by a DLE character. The actual byte was
|
||||
* also encoded by adding + 0x40 to prevent having control chars,
|
||||
* in the stream at all, so we convert it back. */
|
||||
if ((nextByte == STX_CHAR + 0x40 or nextByte == ETX_CHAR + 0x40) or
|
||||
(escapeCr and nextByte == CARRIAGE_RETURN + 0x40)) {
|
||||
(this->escapeCr and nextByte == CARRIAGE_RETURN + 0x40)) {
|
||||
destStream[decodedIndex] = nextByte - 0x40;
|
||||
}
|
||||
else {
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef FRAMEWORK_GLOBALFUNCTIONS_DLEENCODER_H_
|
||||
#define FRAMEWORK_GLOBALFUNCTIONS_DLEENCODER_H_
|
||||
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||
#include <cstddef>
|
||||
|
||||
/**
|
||||
@ -26,7 +26,7 @@
|
||||
*/
|
||||
class DleEncoder: public HasReturnvaluesIF {
|
||||
private:
|
||||
DleEncoder();
|
||||
DleEncoder(bool escapeStxEtx = true, bool escapeCr = false);
|
||||
virtual ~DleEncoder();
|
||||
|
||||
public:
|
||||
@ -64,7 +64,7 @@ public:
|
||||
* by adding 0x40
|
||||
* @return
|
||||
*/
|
||||
static ReturnValue_t encode(const uint8_t *sourceStream, size_t sourceLen,
|
||||
ReturnValue_t encode(const uint8_t *sourceStream, size_t sourceLen,
|
||||
uint8_t *destStream, size_t maxDestLen, size_t *encodedLen,
|
||||
bool addStxEtx = true, bool escapeStxEtx = true, bool escapeCr = false);
|
||||
|
||||
@ -82,10 +82,14 @@ public:
|
||||
* be decoded back as well by subtracting 0x40
|
||||
* @return
|
||||
*/
|
||||
static ReturnValue_t decode(const uint8_t *sourceStream,
|
||||
ReturnValue_t decode(const uint8_t *sourceStream,
|
||||
size_t sourceStreamLen, size_t *readLen, uint8_t *destStream,
|
||||
size_t maxDestStreamlen, size_t *decodedLen, bool escapeStxEtx = true,
|
||||
bool escapeCr = false);
|
||||
size_t maxDestStreamlen, size_t *decodedLen);
|
||||
|
||||
private:
|
||||
|
||||
bool escapeStxEtx;
|
||||
bool escapeCr;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_GLOBALFUNCTIONS_DLEENCODER_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user