DLE FRAM packets can be read now
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit

This commit is contained in:
2022-04-09 14:43:06 +02:00
parent 44c8f5f730
commit 808e01dfd3
13 changed files with 176 additions and 93 deletions

View File

@ -4,6 +4,7 @@
#include <fcntl.h> // Contains file controls like O_RDWR
#include <fsfw/tasks/TaskFactory.h>
#include <fsfw_hal/linux/uart/UartCookie.h>
#include <linux/devices/ScexDleParser.h>
#include <linux/devices/ScexUartReader.h>
#include <unistd.h> // write(), read(), close()
@ -20,10 +21,15 @@
#endif
UartTestClass::UartTestClass(object_id_t objectId, ScexUartReader* reader)
: TestTask(objectId), reader(reader) {
: TestTask(objectId), reader(reader), decodeRingBuf(4096, true) {
mode = TestModes::SCEX;
scexMode = ScexModes::SIMPLE;
currCmd = scex::ScexCmds::ONE_CELL;
currCmd = scex::ScexCmds::FRAM;
if (mode == TestModes::SCEX) {
dleParser =
new ScexDleParser(decodeRingBuf, dleEncoder, {encodedBuf.data(), encodedBuf.size()},
{decodedBuf.data(), decodedBuf.size()}, &foundDlePacketHandler, this);
}
}
ReturnValue_t UartTestClass::initialize() {
@ -145,8 +151,7 @@ void UartTestClass::scexInit() {
#else
std::string devname = "/dev/ul-scex";
#endif
uartCookie =
new UartCookie(this->getObjectId(), devname, UartModes::NON_CANONICAL, 57600, 4096);
uartCookie = new UartCookie(this->getObjectId(), devname, UartBaudRate::RATE_57600, 4096);
reader->setDebugMode(true);
ReturnValue_t result = reader->initializeInterface(uartCookie);
if (result != HasReturnvaluesIF::RETURN_OK) {
@ -171,25 +176,6 @@ void UartTestClass::scexPeriodic() {
}
}
int UartTestClass::prepareScexCmd(scex::ScexCmds cmd, bool tempCheck,
uint8_t* cmdBuf, size_t* len) {
using namespace scex;
// Send ping command
cmdBuf[0] = scex::createCmdByte(cmd, false);
// These two fields are the packet counter and the total packet count. Those are 1 and 1 for each
// telecommand so far
cmdBuf[1] = 1;
cmdBuf[2] = 1;
uint16_t userDataLen = 0;
cmdBuf[3] = (userDataLen >> 8) & 0xff;
cmdBuf[4] = userDataLen & 0xff;
uint16_t crc = CRC::crc16ccitt(cmdBuf, 5);
cmdBuf[5] = (crc >> 8) & 0xff;
cmdBuf[6] = crc & 0xff;
*len = 7;
return 0;
}
void UartTestClass::scexSimpleInit() {
#if defined(RASPBERRY_PI)
std::string devname = "/dev/serial0";
@ -216,8 +202,8 @@ void UartTestClass::scexSimpleInit() {
// Non-blocking mode, read until either line is 0.1 second idle or maximum of 255 bytes are
// received in one go
tty.c_cc[VTIME] = 0; // In units of 0.1 seconds
tty.c_cc[VMIN] = 0; // Read up to 255 bytes
tty.c_cc[VTIME] = 10; // In units of 0.1 seconds
tty.c_cc[VMIN] = 255; // Read up to 255 bytes
// Q7S UART Lite has fixed baud rate. For other linux systems, set baud rate here.
#if !defined(XIPHOS_Q7S)
@ -226,53 +212,89 @@ void UartTestClass::scexSimpleInit() {
}
#endif
// Flush received and unread data
tcflush(serialPort, TCIOFLUSH);
if (tcsetattr(serialPort, TCSANOW, &tty) != 0) {
sif::warning << "tcsetattr call failed with error [" << errno << ", " << strerror(errno)
<< std::endl;
}
// Flush received and unread data
tcflush(serialPort, TCIOFLUSH);
}
void UartTestClass::scexSimplePeriodic() {
using namespace scex;
sif::info << "UartTestClass::scexInit: Sending ping command to SCEX" << std::endl;
uint8_t tmpCmdBuf[32] = {};
size_t len = 0;
prepareScexCmd(currCmd, false, tmpCmdBuf, &len);
ReturnValue_t result =
dleEncoder.encode(tmpCmdBuf, len, cmdBuf.data(), cmdBuf.size(), &encodedLen, true);
if (result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "UartTestClass::scexInit: Encoding failed" << std::endl;
return;
}
if (result != 0) {
return;
};
size_t bytesWritten = write(serialPort, cmdBuf.data(), encodedLen);
if (bytesWritten != encodedLen) {
sif::warning << "Sending ping command to solar experiment failed" << std::endl;
}
// Read back reply immediately
int bytesRead = 0;
do {
bytesRead = read(serialPort, reinterpret_cast<void*>(recBuf.data()),
static_cast<unsigned int>(recBuf.size()));
if (bytesRead == 0) {
sif::warning << "Reading SCEX: Timeout or no bytes read" << std::endl;
} else if (bytesRead < 0) {
sif::warning << "UartTestClass::performPeriodicAction: read call failed with error [" << errno
<< ", " << strerror(errno) << "]" << std::endl;
break;
} else if (bytesRead >= static_cast<int>(recBuf.size())) {
sif::debug << "UartTestClass::performPeriodicAction: recv buffer might not be large enough"
<< std::endl;
} else if (bytesRead > 0) {
sif::info << "Received " << bytesRead
<< " bytes from the Solar Cell Experiment:" << std::endl;
arrayprinter::print(recBuf.data(), bytesRead, OutputType::HEX, false);
break;
ReturnValue_t result = RETURN_OK;
if (not cmdSent) {
// Flush received and unread data
tcflush(serialPort, TCIFLUSH);
uint8_t tmpCmdBuf[32] = {};
size_t len = 0;
sif::info << "UartTestClass::scexSimplePeriodic: Sending command to SCEX" << std::endl;
prepareScexCmd(currCmd, false, tmpCmdBuf, &len);
result = dleEncoder.encode(tmpCmdBuf, len, cmdBuf.data(), cmdBuf.size(), &encodedLen, true);
if (result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "UartTestClass::scexInit: Encoding failed" << std::endl;
return;
}
} while (bytesRead > 0);
if (result != 0) {
return;
};
size_t bytesWritten = write(serialPort, cmdBuf.data(), encodedLen);
if (bytesWritten != encodedLen) {
sif::warning << "Sending command to solar experiment failed" << std::endl;
}
cmdSent = true;
cmdDone = false;
}
if (not cmdDone) {
// Read back reply immediately
int bytesRead = 0;
do {
bytesRead = read(serialPort, reinterpret_cast<void*>(recBuf.data()),
static_cast<unsigned int>(recBuf.size()));
if (bytesRead == 0) {
sif::warning << "Reading SCEX: Timeout or no bytes read" << std::endl;
} else if (bytesRead < 0) {
sif::warning << "UartTestClass::performPeriodicAction: read call failed with error ["
<< errno << ", " << strerror(errno) << "]" << std::endl;
break;
} else if (bytesRead >= static_cast<int>(recBuf.size())) {
sif::debug << "UartTestClass::performPeriodicAction: recv buffer might not be large enough"
<< std::endl;
} else if (bytesRead > 0) {
dleParser->passData(recBuf.data(), bytesRead);
if (currCmd == ScexCmds::PING) {
cmdDone = true;
cmdSent = false;
}
}
} while (bytesRead > 0);
}
}
int UartTestClass::prepareScexCmd(scex::ScexCmds cmd, bool tempCheck, uint8_t* cmdBuf,
size_t* len) {
using namespace scex;
// Send ping command
cmdBuf[0] = scex::createCmdByte(cmd, false);
// These two fields are the packet counter and the total packet count. Those are 1 and 1 for each
// telecommand so far
cmdBuf[1] = 1;
cmdBuf[2] = 1;
uint16_t userDataLen = 0;
cmdBuf[3] = (userDataLen >> 8) & 0xff;
cmdBuf[4] = userDataLen & 0xff;
uint16_t crc = CRC::crc16ccitt(cmdBuf, 5);
cmdBuf[5] = (crc >> 8) & 0xff;
cmdBuf[6] = crc & 0xff;
*len = 7;
return 0;
}
void UartTestClass::foundDlePacketHandler(uint8_t* packet, size_t len, void* args) {
UartTestClass* obj = reinterpret_cast<UartTestClass*>(args);
obj->handleFoundDlePacket(packet, len);
}
void UartTestClass::handleFoundDlePacket(uint8_t* packet, size_t len) {
sif::info << "Detected DLE encoded packet with decoded size " << len << std::endl;
}

View File

@ -1,6 +1,7 @@
#ifndef LINUX_BOARDTEST_UARTTESTCLASS_H_
#define LINUX_BOARDTEST_UARTTESTCLASS_H_
#include <fsfw/container/SimpleRingBuffer.h>
#include <fsfw/globalfunctions/DleEncoder.h>
#include <fsfw_hal/linux/uart/UartCookie.h>
#include <termios.h> // Contains POSIX terminal control definitions
@ -8,10 +9,11 @@
#include <array>
#include "lwgps/lwgps.h"
#include "mission/devices/devicedefinitions/SCEXDefinitions.h"
#include "mission/devices/devicedefinitions/ScexDefinitions.h"
#include "test/testtasks/TestTask.h"
class ScexUartReader;
class ScexDleParser;
class UartTestClass : public TestTask {
public:
@ -40,6 +42,11 @@ class UartTestClass : public TestTask {
void scexSimplePeriodic();
void scexSimpleInit();
static void foundDlePacketHandler(uint8_t* packet, size_t len, void* args);
void handleFoundDlePacket(uint8_t* packet, size_t len);
bool cmdSent = false;
bool cmdDone = false;
scex::ScexCmds currCmd = scex::ScexCmds::PING;
TestModes mode = TestModes::GPS;
DleEncoder dleEncoder = DleEncoder();
@ -48,10 +55,15 @@ class UartTestClass : public TestTask {
lwgps_t gpsData = {};
struct termios tty = {};
int serialPort = 0;
std::array<uint8_t, 64> cmdBuf = {};
std::array<uint8_t, 4096> recBuf = {};
uint8_t recvCnt = 0;
bool startFound = false;
ScexUartReader* reader = nullptr;
SimpleRingBuffer decodeRingBuf;
std::array<uint8_t, 64> cmdBuf = {};
std::array<uint8_t, 524> recBuf = {};
std::array<uint8_t, 4096> encodedBuf = {};
std::array<uint8_t, 4096> decodedBuf = {};
ScexDleParser* dleParser;
uint8_t recvCnt = 0;
};
#endif /* LINUX_BOARDTEST_UARTTESTCLASS_H_ */