crc check now works
This commit is contained in:
@ -970,7 +970,7 @@ ReturnValue_t PlocSupvUartManager::handleRunningLongerRequest() {
|
||||
|
||||
ReturnValue_t PlocSupvUartManager::encodeAndSendPacket(const uint8_t* sendData, size_t sendLen) {
|
||||
size_t encodedLen = 0;
|
||||
hdlc_add_framing(sendData, sendLen, encodedSendBuf.data(), &encodedLen);
|
||||
addHdlcFraming(sendData, sendLen, encodedSendBuf.data(), &encodedLen, encodedSendBuf.size());
|
||||
sif::debug << "Sending TC" << std::endl;
|
||||
arrayprinter::print(encodedSendBuf.data(), encodedLen);
|
||||
size_t bytesWritten = write(serialPort, encodedSendBuf.data(), encodedLen);
|
||||
@ -1051,8 +1051,8 @@ ReturnValue_t PlocSupvUartManager::parseRecRingBufForHdlc(size_t& readSize, size
|
||||
if (encodedBuf[idx] == HDLC_END_MARKER) {
|
||||
if (startMarkerFound) {
|
||||
// Probably a packet, so decode it
|
||||
int retval = hdlc_remove_framing_with_crc_check(
|
||||
encodedBuf.data() + startIdx, idx + 1 - startIdx, decodedBuf.data(), &decodedLen);
|
||||
int retval = removeHdlcFramingWithCrcCheck(encodedBuf.data() + startIdx, idx + 1 - startIdx,
|
||||
decodedBuf.data(), &decodedLen);
|
||||
readSize = idx + 1;
|
||||
if (retval == -1 or retval == -2) {
|
||||
triggerEvent(HDLC_FRAME_REMOVAL_ERROR, retval);
|
||||
@ -1097,3 +1097,58 @@ void PlocSupvUartManager::performUartShutdown() {
|
||||
}
|
||||
state = InternalState::GO_TO_SLEEP;
|
||||
}
|
||||
|
||||
void PlocSupvUartManager::addHdlcFraming(const uint8_t* src, size_t slen, uint8_t* dst,
|
||||
size_t* dlen, size_t maxDest) {
|
||||
size_t tlen = 0;
|
||||
uint16_t ii;
|
||||
uint8_t bt;
|
||||
|
||||
// calc crc16
|
||||
uint16_t crc16 = calc_crc16_buff_reflected(src, slen);
|
||||
|
||||
dst[tlen++] = 0x7E;
|
||||
for (ii = 0; ii < slen; ii++) {
|
||||
bt = *src++;
|
||||
hdlc_add_byte(bt, dst, &tlen);
|
||||
}
|
||||
|
||||
size_t dummy = 0;
|
||||
// hdlc crc16 is in little endian format
|
||||
SerializeAdapter::serialize(&crc16, dst + tlen, &dummy, maxDest, SerializeIF::Endianness::LITTLE);
|
||||
tlen += dummy;
|
||||
|
||||
dst[tlen++] = 0x7C;
|
||||
*dlen = tlen;
|
||||
}
|
||||
|
||||
int PlocSupvUartManager::removeHdlcFramingWithCrcCheck(const uint8_t* src, size_t slen,
|
||||
uint8_t* dst, size_t* dlen) {
|
||||
uint16_t tlen = 0;
|
||||
uint16_t ii;
|
||||
uint8_t bt;
|
||||
|
||||
*dlen = 0;
|
||||
if (slen < 4) return -1;
|
||||
if ((src[tlen] != 0x7E) && (src[slen - 1] != 0x7C)) return -2;
|
||||
src++;
|
||||
for (ii = 1; ii < slen - 1; ii++) {
|
||||
bt = *src++;
|
||||
|
||||
if (bt == 0x7D) {
|
||||
bt = *src++ ^ 0x20;
|
||||
ii++;
|
||||
}
|
||||
dst[tlen++] = bt;
|
||||
}
|
||||
// calc crc16
|
||||
uint16_t calcCrc = calc_crc16_buff_reflected(dst, tlen - 2);
|
||||
uint16_t crc;
|
||||
size_t dummy;
|
||||
SerializeAdapter::deSerialize(&crc, dst + tlen - 2, &dummy, SerializeIF::Endianness::LITTLE);
|
||||
if (calcCrc != crc) {
|
||||
return 1;
|
||||
}
|
||||
*dlen = tlen - 2;
|
||||
return 0;
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "fsfw/tasks/ExecutableObjectIF.h"
|
||||
#include "fsfw_hal/linux/serial/SerialComIF.h"
|
||||
#include "linux/devices/devicedefinitions/PlocSupervisorDefinitions.h"
|
||||
#include "tas/crc.h"
|
||||
|
||||
#ifdef XIPHOS_Q7S
|
||||
#include "bsp_q7s/fs/SdCardManager.h"
|
||||
@ -259,6 +260,8 @@ class PlocSupvUartManager : public DeviceCommunicationIF,
|
||||
|
||||
ReturnValue_t handleRunningLongerRequest();
|
||||
bool handleUartReception();
|
||||
void addHdlcFraming(const uint8_t* src, size_t slen, uint8_t* dst, size_t* dlen, size_t maxDest);
|
||||
int removeHdlcFramingWithCrcCheck(const uint8_t* src, size_t slen, uint8_t* dst, size_t* dlen);
|
||||
|
||||
ReturnValue_t encodeAndSendPacket(const uint8_t* sendData, size_t sendLen);
|
||||
void executeFullCheckMemoryCommand();
|
||||
|
Reference in New Issue
Block a user