2023-02-15 17:02:22 +01:00
|
|
|
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_RWHELPERS_CPP_
|
|
|
|
#define MISSION_DEVICES_DEVICEDEFINITIONS_RWHELPERS_CPP_
|
|
|
|
|
|
|
|
#include "rwHelpers.h"
|
|
|
|
|
2023-02-15 19:58:32 +01:00
|
|
|
void rws::encodeHdlc(const uint8_t* sourceBuf, size_t sourceLen, uint8_t* encodedBuffer,
|
|
|
|
size_t& encodedLen) {
|
|
|
|
encodedBuffer[0] = rws::FRAME_DELIMITER;
|
|
|
|
encodedLen = 1;
|
|
|
|
for (size_t sourceIdx = 0; sourceIdx < sourceLen; sourceIdx++) {
|
|
|
|
if (sourceBuf[sourceIdx] == 0x7E) {
|
|
|
|
encodedBuffer[encodedLen++] = 0x7D;
|
|
|
|
encodedBuffer[encodedLen++] = 0x5E;
|
|
|
|
} else if (sourceBuf[sourceIdx] == 0x7D) {
|
|
|
|
encodedBuffer[encodedLen++] = 0x7D;
|
|
|
|
encodedBuffer[encodedLen++] = 0x5D;
|
|
|
|
} else {
|
|
|
|
encodedBuffer[encodedLen++] = sourceBuf[sourceIdx];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
encodedBuffer[encodedLen++] = rws::FRAME_DELIMITER;
|
|
|
|
}
|
|
|
|
|
2023-02-15 17:02:22 +01:00
|
|
|
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_RWHELPERS_CPP_ */
|