From a44141c4766f88e15e5220355e5e1cec629265e4 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 4 Oct 2022 21:17:54 +0200 Subject: [PATCH] something is still wrong --- fsfw | 2 +- linux/devices/ScexUartReader.cpp | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/fsfw b/fsfw index 49747fc8..d1630cdc 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 49747fc8a49e85e7b3d442eabe668d34e44bad32 +Subproject commit d1630cdc4c3fc801934f1e394efa80e898f8031b diff --git a/linux/devices/ScexUartReader.cpp b/linux/devices/ScexUartReader.cpp index b717c308..812848e7 100644 --- a/linux/devices/ScexUartReader.cpp +++ b/linux/devices/ScexUartReader.cpp @@ -35,7 +35,7 @@ ReturnValue_t ScexUartReader::performOperation(uint8_t operationCode) { while (true) { semaphore->acquire(); int bytesRead = 0; - // debugMode = true; + debugMode = true; while (true) { bytesRead = read(serialPort, reinterpret_cast(recBuf.data()), static_cast(recBuf.size())); @@ -43,6 +43,9 @@ ReturnValue_t ScexUartReader::performOperation(uint8_t operationCode) { { MutexGuard mg(lock); if (state == States::FINISH) { + dleParser.reset(); + // Flush received and unread data + tcflush(serialPort, TCIOFLUSH); state = States::IDLE; break; } @@ -52,6 +55,7 @@ ReturnValue_t ScexUartReader::performOperation(uint8_t operationCode) { while (result != DleParser::NO_PACKET_FOUND) { result = dleParser.parseRingBuf(bytesRead); if (result == returnvalue::OK) { + sif::info << "FOund dle packet, read " << bytesRead << " bytes" << std::endl; // Packet found, advance read pointer. auto& decodedPacket = dleParser.getContext().decodedPacket; handleFoundDlePacket(decodedPacket.first, decodedPacket.second); @@ -142,14 +146,12 @@ ReturnValue_t ScexUartReader::sendMessage(CookieIF *cookie, const uint8_t *sendD lock->unlockMutex(); return FAILED; } + tcflush(serialPort, TCIOFLUSH); state = States::RUNNING; lock->unlockMutex(); - ReturnValue_t result = semaphore->release(); - if (result != OK) { - std::cout << "ScexUartReader::sendMessage: Releasing semaphore failed" << std::endl; - } + size_t encodedLen = 0; - result = + ReturnValue_t result = dleEncoder.encode(sendData, sendLen, cmdbuf.data(), cmdbuf.size(), &encodedLen, true); if (result != OK) { sif::warning << "ScexUartReader::sendMessage: Encoding failed" << std::endl; @@ -161,6 +163,10 @@ ReturnValue_t ScexUartReader::sendMessage(CookieIF *cookie, const uint8_t *sendD << std::endl; return FAILED; } + result = semaphore->release(); + if (result != OK) { + std::cout << "ScexUartReader::sendMessage: Releasing semaphore failed" << std::endl; + } return OK; }