fixed some tiny bugs

This commit is contained in:
2022-04-15 01:39:47 +02:00
parent bbdd3c052e
commit 57cc77e197
4 changed files with 289 additions and 284 deletions

View File

@ -5,6 +5,7 @@
#include <fsfw/ipc/MutexFactory.h>
#include <fsfw/ipc/MutexGuard.h>
#include <fsfw/tasks/SemaphoreFactory.h>
#include <fsfw/tasks/TaskFactory.h>
#include <fsfw_hal/linux/uart/UartCookie.h>
#include <linux/devices/ScexDleParser.h>
#include <unistd.h> // write(), read(), close()
@ -34,16 +35,17 @@ ReturnValue_t ScexUartReader::performOperation(uint8_t operationCode) {
semaphore->acquire();
sif::info << "task was started" << std::endl;
int bytesRead = 0;
while(true) {
while (true) {
bytesRead = read(serialPort, reinterpret_cast<void *>(recBuf.data()),
static_cast<unsigned int>(recBuf.size()));
if (bytesRead == 0) {
MutexGuard mg(lock);
States currentState = state;
if (currentState == States::FINISH) {
if (state == States::FINISH) {
sif::debug << "finish detected" << std::endl;
state = States::IDLE;
break;
}
TaskFactory::delayTask(1000);
} else if (bytesRead < 0) {
sif::warning << "ScexUartReader::performOperation: read call failed with error [" << errno
<< ", " << strerror(errno) << "]" << std::endl;
@ -63,7 +65,7 @@ ReturnValue_t ScexUartReader::performOperation(uint8_t operationCode) {
}
};
// task block comes here
std::cout << "done" << std::endl;
sif::info << "task was stopped" << std::endl;
}
return RETURN_OK;
}
@ -74,7 +76,7 @@ ReturnValue_t ScexUartReader::initializeInterface(CookieIF *cookie) {
return RETURN_FAILED;
}
std::string devname = uartCookie->getDeviceFile();
sif::info << devname << std::endl;
sif::info << devname << std::endl;
/* Get file descriptor */
serialPort = open(devname.c_str(), O_RDWR);
if (serialPort < 0) {
@ -94,8 +96,8 @@ ReturnValue_t ScexUartReader::initializeInterface(CookieIF *cookie) {
tty.c_lflag &= ~(ICANON | ECHO);
// Non-blocking mode, use polling
tty.c_cc[VTIME] = 10; // Read for up to 1 seconds
tty.c_cc[VMIN] = 255; // Read as much as there is available
tty.c_cc[VTIME] = 0;
tty.c_cc[VMIN] = 0;
// Q7S UART Lite has fixed baud rate. For other linux systems, set baud rate here.
#if !defined(XIPHOS_Q7S)
@ -109,7 +111,7 @@ ReturnValue_t ScexUartReader::initializeInterface(CookieIF *cookie) {
<< std::endl;
}
// Flush received and unread data
tcflush(serialPort, TCIFLUSH);
tcflush(serialPort, TCIOFLUSH);
return RETURN_OK;
}
@ -172,13 +174,13 @@ void ScexUartReader::handleFoundDlePacket(uint8_t *packet, size_t len) {
sif::info << "Detected DLE encoded packet with decoded size " << len << std::endl;
MutexGuard mg(lock);
ReturnValue_t result = ipcQueue.insert(len);
if(result != RETURN_OK){
sif::warning<< "IPCQueue error" << std::endl;
if (result != RETURN_OK) {
sif::warning << "IPCQueue error" << std::endl;
}
result = ipcRingBuf.writeData(packet, len);
if(result != RETURN_OK){
sif::warning<< "IPCRingBuf error" << std::endl;
}
if (result != RETURN_OK) {
sif::warning << "IPCRingBuf error" << std::endl;
}
sif::info << "DLE handler done" << std::endl;
}
@ -189,7 +191,8 @@ ReturnValue_t ScexUartReader::readReceivedMessage(CookieIF *cookie, uint8_t **bu
*size = 0;
return RETURN_OK;
}
*size = ipcQueue.pop();
sif::info << "returning data" << std::endl;
ipcQueue.retrieve(size);
*buffer = ipcBuffer.data();
ReturnValue_t result = ipcRingBuf.readData(ipcBuffer.data(), *size, true);
if (result != RETURN_OK) {