|
|
|
@ -7,7 +7,6 @@
|
|
|
|
|
#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()
|
|
|
|
|
|
|
|
|
|
#include <cerrno> // Error integer and strerror() function
|
|
|
|
@ -21,7 +20,7 @@ ScexUartReader::ScexUartReader(object_id_t objectId)
|
|
|
|
|
ipcRingBuf(200 * 2048, true),
|
|
|
|
|
ipcQueue(200),
|
|
|
|
|
dleParser(decodeRingBuf, dleEncoder, {encodedBuf.data(), encodedBuf.size()},
|
|
|
|
|
{decodedBuf.data(), decodedBuf.size()}, &foundDlePacketHandler, this) {
|
|
|
|
|
{decodedBuf.data(), decodedBuf.size()}, &foundDlePacketHandler, (void *)this) {
|
|
|
|
|
semaphore = SemaphoreFactory::instance()->createBinarySemaphore();
|
|
|
|
|
semaphore->acquire();
|
|
|
|
|
lock = MutexFactory::instance()->createMutex();
|
|
|
|
@ -80,8 +79,8 @@ ReturnValue_t ScexUartReader::initializeInterface(CookieIF *cookie) {
|
|
|
|
|
/* Get file descriptor */
|
|
|
|
|
serialPort = open(devname.c_str(), O_RDWR);
|
|
|
|
|
if (serialPort < 0) {
|
|
|
|
|
sif::warning << "open call failed with error [" << errno << ", " << strerror(errno)
|
|
|
|
|
<< std::endl;
|
|
|
|
|
sif::warning << "ScexUartReader::initializeInterface: open call failed with error [" << errno
|
|
|
|
|
<< ", " << strerror(errno) << std::endl;
|
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
|
}
|
|
|
|
|
// Setting up UART parameters
|
|
|
|
@ -107,8 +106,8 @@ ReturnValue_t ScexUartReader::initializeInterface(CookieIF *cookie) {
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (tcsetattr(serialPort, TCSANOW, &tty) != 0) {
|
|
|
|
|
sif::warning << "tcsetattr call failed with error [" << errno << ", " << strerror(errno)
|
|
|
|
|
<< std::endl;
|
|
|
|
|
sif::warning << "ScexUartReader::initializeInterface: tcsetattr call failed with error ["
|
|
|
|
|
<< errno << ", " << strerror(errno) << std::endl;
|
|
|
|
|
}
|
|
|
|
|
// Flush received and unread data
|
|
|
|
|
tcflush(serialPort, TCIOFLUSH);
|
|
|
|
@ -117,6 +116,9 @@ ReturnValue_t ScexUartReader::initializeInterface(CookieIF *cookie) {
|
|
|
|
|
|
|
|
|
|
ReturnValue_t ScexUartReader::sendMessage(CookieIF *cookie, const uint8_t *sendData,
|
|
|
|
|
size_t sendLen) {
|
|
|
|
|
if (sendData == nullptr or sendLen == 0) {
|
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
|
}
|
|
|
|
|
lock->lockMutex();
|
|
|
|
|
if (state == States::NOT_READY or state == States::RUNNING) {
|
|
|
|
|
lock->unlockMutex();
|
|
|
|
@ -128,17 +130,18 @@ ReturnValue_t ScexUartReader::sendMessage(CookieIF *cookie, const uint8_t *sendD
|
|
|
|
|
ReturnValue_t result =
|
|
|
|
|
dleEncoder.encode(sendData, sendLen, cmdbuf.data(), cmdbuf.size(), &encodedLen, true);
|
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
|
sif::warning << "UartTestClass::scexInit: Encoding failed" << std::endl;
|
|
|
|
|
sif::warning << "ScexUartReader::sendMessage: Encoding failed" << std::endl;
|
|
|
|
|
return RETURN_FAILED;
|
|
|
|
|
}
|
|
|
|
|
size_t bytesWritten = write(serialPort, cmdbuf.data(), encodedLen);
|
|
|
|
|
if (bytesWritten != encodedLen) {
|
|
|
|
|
sif::warning << "Sending ping command to solar experiment failed" << std::endl;
|
|
|
|
|
sif::warning << "ScexUartReader::sendMessage: Sending ping command to solar experiment failed"
|
|
|
|
|
<< std::endl;
|
|
|
|
|
return RETURN_FAILED;
|
|
|
|
|
}
|
|
|
|
|
result = semaphore->release();
|
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
|
std::cout << "ScexUartReader::sendMessag: Releasing semaphore failed" << std::endl;
|
|
|
|
|
std::cout << "ScexUartReader::sendMessage: Releasing semaphore failed" << std::endl;
|
|
|
|
|
}
|
|
|
|
|
return RETURN_OK;
|
|
|
|
|
}
|
|
|
|
@ -160,12 +163,12 @@ ReturnValue_t ScexUartReader::finish() {
|
|
|
|
|
return RETURN_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScexUartReader::foundDlePacketHandler(const DleParser::Context &ctx) {
|
|
|
|
|
void ScexUartReader::foundDlePacketHandler(const ScexDleParser::Context &ctx) {
|
|
|
|
|
ScexUartReader *obj = reinterpret_cast<ScexUartReader *>(ctx.userArgs);
|
|
|
|
|
if (ctx.getType() == DleParser::ContextType::PACKET_FOUND) {
|
|
|
|
|
if (ctx.getType() == ScexDleParser::ContextType::PACKET_FOUND) {
|
|
|
|
|
obj->handleFoundDlePacket(ctx.decodedPacket.first, ctx.decodedPacket.second);
|
|
|
|
|
} else {
|
|
|
|
|
DleParser::defaultErrorHandler(ctx.error.first, ctx.error.second);
|
|
|
|
|
ScexDleParser::defaultErrorHandler(ctx.error.first, ctx.error.second);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -175,11 +178,11 @@ void ScexUartReader::handleFoundDlePacket(uint8_t *packet, size_t len) {
|
|
|
|
|
MutexGuard mg(lock);
|
|
|
|
|
ReturnValue_t result = ipcQueue.insert(len);
|
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
|
sif::warning << "IPCQueue error" << std::endl;
|
|
|
|
|
sif::warning << "ScexUartReader::handleFoundDlePacket: IPCQueue error" << std::endl;
|
|
|
|
|
}
|
|
|
|
|
result = ipcRingBuf.writeData(packet, len);
|
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
|
sif::warning << "IPCRingBuf error" << std::endl;
|
|
|
|
|
sif::warning << "ScexUartReader::handleFoundDlePacket: IPCRingBuf error" << std::endl;
|
|
|
|
|
}
|
|
|
|
|
// sif::info << "DLE handler done" << std::endl;
|
|
|
|
|
}
|
|
|
|
|