found the bug
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good

This commit is contained in:
2022-10-04 23:04:50 +02:00
parent a44141c476
commit 1a192cd8fb
8 changed files with 60 additions and 44 deletions

View File

@ -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<void *>(recBuf.data()),
static_cast<unsigned int>(recBuf.size()));
@ -50,24 +50,11 @@ ReturnValue_t ScexUartReader::performOperation(uint8_t operationCode) {
break;
}
}
size_t bytesRead = 0;
ReturnValue_t result = returnvalue::OK;
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);
dleParser.confirmBytesRead(bytesRead);
} else if (result != DleParser::NO_PACKET_FOUND) {
sif::warning << "ScexUartReader::performOperation: Possible packet loss" << std::endl;
// Markers found at wrong place
// which might be a hint for a possibly lost packet.
dleParser.defaultErrorHandler();
dleParser.confirmBytesRead(bytesRead);
}
result = tryDleParsing();
}
TaskFactory::delayTask(400);
} else if (bytesRead < 0) {
sif::warning << "ScexUartReader::performOperation: read call failed with error [" << errno
@ -77,15 +64,16 @@ ReturnValue_t ScexUartReader::performOperation(uint8_t operationCode) {
sif::error << "ScexUartReader::performOperation: Receive buffer too small for " << bytesRead
<< " bytes" << std::endl;
} else if (bytesRead > 0) {
ReturnValue_t result = dleParser.passData(recBuf.data(), bytesRead);
if (debugMode) {
sif::info << "Received " << bytesRead
<< " bytes from the Solar Cell Experiment:" << std::endl;
}
ReturnValue_t result = dleParser.passData(recBuf.data(), bytesRead);
if (result != OK) {
sif::warning << "ScexUartReader::performOperation: Passing data to DLE parser failed"
<< std::endl;
}
result = tryDleParsing();
}
};
}
@ -138,6 +126,7 @@ ReturnValue_t ScexUartReader::initializeInterface(CookieIF *cookie) {
ReturnValue_t ScexUartReader::sendMessage(CookieIF *cookie, const uint8_t *sendData,
size_t sendLen) {
ReturnValue_t result;
if (sendData == nullptr or sendLen == 0) {
return FAILED;
}
@ -146,13 +135,16 @@ ReturnValue_t ScexUartReader::sendMessage(CookieIF *cookie, const uint8_t *sendD
lock->unlockMutex();
return FAILED;
}
tcflush(serialPort, TCIOFLUSH);
tcflush(serialPort, TCIFLUSH);
state = States::RUNNING;
lock->unlockMutex();
result = semaphore->release();
if (result != OK) {
std::cout << "ScexUartReader::sendMessage: Releasing semaphore failed" << std::endl;
}
size_t encodedLen = 0;
ReturnValue_t result =
dleEncoder.encode(sendData, sendLen, cmdbuf.data(), cmdbuf.size(), &encodedLen, true);
result = dleEncoder.encode(sendData, sendLen, cmdbuf.data(), cmdbuf.size(), &encodedLen, true);
if (result != OK) {
sif::warning << "ScexUartReader::sendMessage: Encoding failed" << std::endl;
return FAILED;
@ -163,10 +155,7 @@ 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;
}
@ -199,6 +188,30 @@ void ScexUartReader::handleFoundDlePacket(uint8_t *packet, size_t len) {
}
}
ReturnValue_t ScexUartReader::tryDleParsing() {
size_t bytesRead = 0;
ReturnValue_t result = dleParser.parseRingBuf(bytesRead);
if (result == returnvalue::OK) {
// Packet found, advance read pointer.
auto &decodedPacket = dleParser.getContext().decodedPacket;
handleFoundDlePacket(decodedPacket.first, decodedPacket.second);
dleParser.confirmBytesRead(bytesRead);
} else if (result != DleParser::NO_PACKET_FOUND) {
sif::warning << "ScexUartReader::performOperation: Possible packet loss" << std::endl;
// Markers found at wrong place
// which might be a hint for a possibly lost packet.
dleParser.defaultErrorHandler();
dleParser.confirmBytesRead(bytesRead);
}
return result;
}
void ScexUartReader::reset() {
lock->lockMutex();
state = States::FINISH;
lock->unlockMutex();
}
ReturnValue_t ScexUartReader::readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
size_t *size) {
MutexGuard mg(lock);

View File

@ -22,6 +22,7 @@ class ScexUartReader : public SystemObject, // strg+shift+n
enum class States { NOT_READY, IDLE, RUNNING, FINISH };
ScexUartReader(object_id_t objectId);
void reset();
ReturnValue_t finish();
void setDebugMode(bool enable);
@ -47,6 +48,7 @@ class ScexUartReader : public SystemObject, // strg+shift+n
static void foundDlePacketHandler(const DleParser::Context &ctx);
void handleFoundDlePacket(uint8_t *packet, size_t len);
ReturnValue_t tryDleParsing();
ReturnValue_t performOperation(uint8_t operationCode = 0) override;