WIP: SCEX Init #272

Closed
muellerr wants to merge 62 commits from irini into develop
13 changed files with 176 additions and 93 deletions
Showing only changes of commit 808e01dfd3 - Show all commits

2
fsfw

@ -1 +1 @@
Subproject commit 85a6e4b12977f24247ed3ca3011c6f8b611a144e Subproject commit bdddee4f81fbdff7f207fd03b3c592522e04c5aa

View File

@ -4,6 +4,7 @@
#include <fcntl.h> // Contains file controls like O_RDWR #include <fcntl.h> // Contains file controls like O_RDWR
#include <fsfw/tasks/TaskFactory.h> #include <fsfw/tasks/TaskFactory.h>
#include <fsfw_hal/linux/uart/UartCookie.h> #include <fsfw_hal/linux/uart/UartCookie.h>
#include <linux/devices/ScexDleParser.h>
#include <linux/devices/ScexUartReader.h> #include <linux/devices/ScexUartReader.h>
#include <unistd.h> // write(), read(), close() #include <unistd.h> // write(), read(), close()
@ -20,10 +21,15 @@
#endif #endif
UartTestClass::UartTestClass(object_id_t objectId, ScexUartReader* reader) UartTestClass::UartTestClass(object_id_t objectId, ScexUartReader* reader)
: TestTask(objectId), reader(reader) { : TestTask(objectId), reader(reader), decodeRingBuf(4096, true) {
mode = TestModes::SCEX; mode = TestModes::SCEX;
scexMode = ScexModes::SIMPLE; 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() { ReturnValue_t UartTestClass::initialize() {
@ -145,8 +151,7 @@ void UartTestClass::scexInit() {
#else #else
std::string devname = "/dev/ul-scex"; std::string devname = "/dev/ul-scex";
#endif #endif
uartCookie = uartCookie = new UartCookie(this->getObjectId(), devname, UartBaudRate::RATE_57600, 4096);
new UartCookie(this->getObjectId(), devname, UartModes::NON_CANONICAL, 57600, 4096);
reader->setDebugMode(true); reader->setDebugMode(true);
ReturnValue_t result = reader->initializeInterface(uartCookie); ReturnValue_t result = reader->initializeInterface(uartCookie);
if (result != HasReturnvaluesIF::RETURN_OK) { 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() { void UartTestClass::scexSimpleInit() {
#if defined(RASPBERRY_PI) #if defined(RASPBERRY_PI)
std::string devname = "/dev/serial0"; 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 // Non-blocking mode, read until either line is 0.1 second idle or maximum of 255 bytes are
// received in one go // received in one go
tty.c_cc[VTIME] = 0; // In units of 0.1 seconds tty.c_cc[VTIME] = 10; // In units of 0.1 seconds
tty.c_cc[VMIN] = 0; // Read up to 255 bytes 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. // Q7S UART Lite has fixed baud rate. For other linux systems, set baud rate here.
#if !defined(XIPHOS_Q7S) #if !defined(XIPHOS_Q7S)
@ -226,53 +212,89 @@ void UartTestClass::scexSimpleInit() {
} }
#endif #endif
// Flush received and unread data
tcflush(serialPort, TCIOFLUSH);
if (tcsetattr(serialPort, TCSANOW, &tty) != 0) { if (tcsetattr(serialPort, TCSANOW, &tty) != 0) {
sif::warning << "tcsetattr call failed with error [" << errno << ", " << strerror(errno) sif::warning << "tcsetattr call failed with error [" << errno << ", " << strerror(errno)
<< std::endl; << std::endl;
} }
// Flush received and unread data
tcflush(serialPort, TCIOFLUSH);
} }
void UartTestClass::scexSimplePeriodic() { void UartTestClass::scexSimplePeriodic() {
using namespace scex; using namespace scex;
sif::info << "UartTestClass::scexInit: Sending ping command to SCEX" << std::endl; ReturnValue_t result = RETURN_OK;
uint8_t tmpCmdBuf[32] = {}; if (not cmdSent) {
size_t len = 0; // Flush received and unread data
prepareScexCmd(currCmd, false, tmpCmdBuf, &len); tcflush(serialPort, TCIFLUSH);
ReturnValue_t result = uint8_t tmpCmdBuf[32] = {};
dleEncoder.encode(tmpCmdBuf, len, cmdBuf.data(), cmdBuf.size(), &encodedLen, true); size_t len = 0;
if (result != HasReturnvaluesIF::RETURN_OK) { sif::info << "UartTestClass::scexSimplePeriodic: Sending command to SCEX" << std::endl;
sif::warning << "UartTestClass::scexInit: Encoding failed" << std::endl; prepareScexCmd(currCmd, false, tmpCmdBuf, &len);
return; result = dleEncoder.encode(tmpCmdBuf, len, cmdBuf.data(), cmdBuf.size(), &encodedLen, true);
} if (result != HasReturnvaluesIF::RETURN_OK) {
if (result != 0) { sif::warning << "UartTestClass::scexInit: Encoding failed" << std::endl;
return; 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;
} }
} 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_ #ifndef LINUX_BOARDTEST_UARTTESTCLASS_H_
#define LINUX_BOARDTEST_UARTTESTCLASS_H_ #define LINUX_BOARDTEST_UARTTESTCLASS_H_
#include <fsfw/container/SimpleRingBuffer.h>
#include <fsfw/globalfunctions/DleEncoder.h> #include <fsfw/globalfunctions/DleEncoder.h>
#include <fsfw_hal/linux/uart/UartCookie.h> #include <fsfw_hal/linux/uart/UartCookie.h>
#include <termios.h> // Contains POSIX terminal control definitions #include <termios.h> // Contains POSIX terminal control definitions
@ -8,10 +9,11 @@
#include <array> #include <array>
#include "lwgps/lwgps.h" #include "lwgps/lwgps.h"
#include "mission/devices/devicedefinitions/SCEXDefinitions.h" #include "mission/devices/devicedefinitions/ScexDefinitions.h"
#include "test/testtasks/TestTask.h" #include "test/testtasks/TestTask.h"
class ScexUartReader; class ScexUartReader;
class ScexDleParser;
class UartTestClass : public TestTask { class UartTestClass : public TestTask {
public: public:
@ -40,6 +42,11 @@ class UartTestClass : public TestTask {
void scexSimplePeriodic(); void scexSimplePeriodic();
void scexSimpleInit(); 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; scex::ScexCmds currCmd = scex::ScexCmds::PING;
TestModes mode = TestModes::GPS; TestModes mode = TestModes::GPS;
DleEncoder dleEncoder = DleEncoder(); DleEncoder dleEncoder = DleEncoder();
@ -48,10 +55,15 @@ class UartTestClass : public TestTask {
lwgps_t gpsData = {}; lwgps_t gpsData = {};
struct termios tty = {}; struct termios tty = {};
int serialPort = 0; int serialPort = 0;
std::array<uint8_t, 64> cmdBuf = {}; bool startFound = false;
std::array<uint8_t, 4096> recBuf = {};
uint8_t recvCnt = 0;
ScexUartReader* reader = nullptr; 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_ */ #endif /* LINUX_BOARDTEST_UARTTESTCLASS_H_ */

View File

@ -6,6 +6,7 @@ endif()
target_sources(${OBSW_NAME} PRIVATE target_sources(${OBSW_NAME} PRIVATE
ScexUartReader.cpp ScexUartReader.cpp
ScexDleParser.cpp
) )
add_subdirectory(ploc) add_subdirectory(ploc)
add_subdirectory(startracker) add_subdirectory(startracker)

View File

@ -0,0 +1,6 @@
#include "ScexDleParser.h"
ScexDleParser::ScexDleParser(SimpleRingBuffer &decodeRingBuf, DleEncoder &decoder,
BufPair encodedBuf, BufPair decodedBuf, FoundPacketHandler handler,
void *args)
: DleParser(decodeRingBuf, decoder, encodedBuf, decodedBuf, handler, args) {}

View File

@ -0,0 +1,12 @@
#ifndef LINUX_DEVICES_SCEXDLEPARSER_H_
#define LINUX_DEVICES_SCEXDLEPARSER_H_
#include <fsfw/globalfunctions/DleParser.h>
class ScexDleParser : public DleParser {
public:
ScexDleParser(SimpleRingBuffer& decodeRingBuf, DleEncoder& decoder, BufPair encodedBuf,
BufPair decodedBuf, FoundPacketHandler handler, void* args);
};
#endif /* LINUX_DEVICES_SCEXDLEPARSER_H_ */

View File

@ -6,6 +6,7 @@
#include <fsfw/ipc/MutexGuard.h> #include <fsfw/ipc/MutexGuard.h>
#include <fsfw/tasks/SemaphoreFactory.h> #include <fsfw/tasks/SemaphoreFactory.h>
#include <fsfw_hal/linux/uart/UartCookie.h> #include <fsfw_hal/linux/uart/UartCookie.h>
#include <linux/devices/ScexDleParser.h>
#include <unistd.h> // write(), read(), close() #include <unistd.h> // write(), read(), close()
#include <cerrno> // Error integer and strerror() function #include <cerrno> // Error integer and strerror() function
@ -14,7 +15,12 @@
#include "OBSWConfig.h" #include "OBSWConfig.h"
ScexUartReader::ScexUartReader(object_id_t objectId) ScexUartReader::ScexUartReader(object_id_t objectId)
: SystemObject(objectId), ringBuffer(200 * 2048, true), sizesQueue(200) { : SystemObject(objectId),
decodeRingBuf(4096, true),
ipcRingBuf(200 * 2048, true),
ipcQueue(200),
dleParser(decodeRingBuf, dleEncoder, {encodedBuf.data(), encodedBuf.size()},
{decodedBuf.data(), decodedBuf.size()}, &foundDlePacketHandler, this) {
semaphore = SemaphoreFactory::instance()->createBinarySemaphore(); semaphore = SemaphoreFactory::instance()->createBinarySemaphore();
semaphore->acquire(); semaphore->acquire();
lock = MutexFactory::instance()->createMutex(); lock = MutexFactory::instance()->createMutex();
@ -47,10 +53,10 @@ ReturnValue_t ScexUartReader::performOperation(uint8_t operationCode) {
sif::error << "ScexUartReader::performOperation: Receive buffer too small" << std::endl; sif::error << "ScexUartReader::performOperation: Receive buffer too small" << std::endl;
} else if (bytesRead > 0) { } else if (bytesRead > 0) {
MutexGuard mg(lock); MutexGuard mg(lock);
sizesQueue.insert(bytesRead); ipcQueue.insert(bytesRead);
ReturnValue_t result = ringBuffer.writeData(recBuf.data(), bytesRead); ReturnValue_t result = dleParser.passData(recBuf.data(), bytesRead);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "ScexUartReader::performOperation: Writing into ring buffer failed" sif::warning << "ScexUartReader::performOperation: Passing data to DLE parser failed"
<< std::endl; << std::endl;
} }
if (debugMode) { if (debugMode) {
@ -91,10 +97,9 @@ ReturnValue_t ScexUartReader::initializeInterface(CookieIF *cookie) {
// Use non-canonical mode and clear echo flag // Use non-canonical mode and clear echo flag
tty.c_lflag &= ~(ICANON | ECHO); tty.c_lflag &= ~(ICANON | ECHO);
// Non-blocking mode, read until either line is 0.1 second idle or maximum of 255 bytes are // Non-blocking mode, use polling
// received in one go tty.c_cc[VTIME] = 0; // Read for up to 2 seconds
tty.c_cc[VTIME] = 20; // Read for up to 2 seconds tty.c_cc[VMIN] = 0; // Read as much as there is available
tty.c_cc[VMIN] = 0; // Read as much as there is available
// Q7S UART Lite has fixed baud rate. For other linux systems, set baud rate here. // Q7S UART Lite has fixed baud rate. For other linux systems, set baud rate here.
#if !defined(XIPHOS_Q7S) #if !defined(XIPHOS_Q7S)
@ -157,16 +162,26 @@ ReturnValue_t ScexUartReader::finish() {
return RETURN_OK; return RETURN_OK;
} }
void ScexUartReader::foundDlePacketHandler(uint8_t *packet, size_t len, void *args) {
ScexUartReader *obj = reinterpret_cast<ScexUartReader *>(args);
obj->handleFoundDlePacket(packet, len);
}
void ScexUartReader::handleFoundDlePacket(uint8_t *packet, size_t len) {
// TODO: insert data into IPC ring buffer here
sif::info << "Detected DLE encoded packet with decoded size " << len << std::endl;
}
ReturnValue_t ScexUartReader::readReceivedMessage(CookieIF *cookie, uint8_t **buffer, ReturnValue_t ScexUartReader::readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
size_t *size) { size_t *size) {
MutexGuard mg(lock); MutexGuard mg(lock);
if (sizesQueue.empty()) { if (ipcQueue.empty()) {
*size = 0; *size = 0;
return RETURN_OK; return RETURN_OK;
} }
*size = sizesQueue.pop(); *size = ipcQueue.pop();
*buffer = ipcBuffer.data(); *buffer = ipcBuffer.data();
ReturnValue_t result = ringBuffer.readData(ipcBuffer.data(), *size, true); ReturnValue_t result = ipcRingBuf.readData(ipcBuffer.data(), *size, true);
if (result != RETURN_OK) { if (result != RETURN_OK) {
sif::warning << "ScexUartReader::readReceivedMessage: Reading RingBuffer failed" << std::endl; sif::warning << "ScexUartReader::readReceivedMessage: Reading RingBuffer failed" << std::endl;
} }

View File

@ -8,6 +8,7 @@
#include <fsfw/objectmanager/SystemObject.h> #include <fsfw/objectmanager/SystemObject.h>
#include <fsfw/tasks/ExecutableObjectIF.h> #include <fsfw/tasks/ExecutableObjectIF.h>
#include <fsfw/timemanager/Countdown.h> #include <fsfw/timemanager/Countdown.h>
#include <linux/devices/ScexDleParser.h>
#include <termios.h> // Contains POSIX terminal control definitions #include <termios.h> // Contains POSIX terminal control definitions
class SemaphoreIF; class SemaphoreIF;
@ -34,13 +35,20 @@ class ScexUartReader : public SystemObject, // strg+shift+n
struct termios tty = {}; struct termios tty = {};
bool doFinish = false; bool doFinish = false;
DleEncoder dleEncoder = DleEncoder(); DleEncoder dleEncoder = DleEncoder();
SimpleRingBuffer ringBuffer; SimpleRingBuffer decodeRingBuf;
DynamicFIFO<size_t> sizesQueue;
Countdown finishCoutdown = Countdown(180 * 1000); Countdown finishCoutdown = Countdown(180 * 1000);
std::array<uint8_t, 256> cmdbuf = {}; std::array<uint8_t, 256> cmdbuf = {};
std::array<uint8_t, 4096> recBuf = {}; std::array<uint8_t, 524> recBuf = {};
std::array<uint8_t, 4096> encodedBuf = {};
std::array<uint8_t, 4096> decodedBuf = {};
std::array<uint8_t, 4096> ipcBuffer = {}; std::array<uint8_t, 4096> ipcBuffer = {};
SimpleRingBuffer ipcRingBuf;
DynamicFIFO<size_t> ipcQueue;
ScexDleParser dleParser;
static void foundDlePacketHandler(uint8_t *packet, size_t len, void *args);
void handleFoundDlePacket(uint8_t *packet, size_t len);
ReturnValue_t performOperation(uint8_t operationCode = 0) override; ReturnValue_t performOperation(uint8_t operationCode = 0) override;

View File

@ -163,6 +163,8 @@ debugging. */
#ifdef RASPBERRY_PI #ifdef RASPBERRY_PI
#define OBSW_TC_FROM_PDEC 0
#define OBSW_ENABLE_TIMERS 1 #define OBSW_ENABLE_TIMERS 1
#define OBSW_ADD_STAR_TRACKER 0 #define OBSW_ADD_STAR_TRACKER 0
#define OBSW_ADD_PLOC_SUPERVISOR 0 #define OBSW_ADD_PLOC_SUPERVISOR 0

View File

@ -19,3 +19,5 @@ target_sources(${LIB_EIVE_MISSION} PRIVATE
PayloadPcduHandler.cpp PayloadPcduHandler.cpp
SolarArrayDeploymentHandler.cpp SolarArrayDeploymentHandler.cpp
) )
add_subdirectory(devicedefinitions)

View File

@ -0,0 +1,3 @@
target_sources(${LIB_EIVE_MISSION} PRIVATE
ScexDefinitions.cpp
)

View File

@ -0,0 +1,5 @@
#include "ScexDefinitions.h"
uint8_t scex::createCmdByte(ScexCmds cmd, bool tempCheck) {
return (IDLE_BIT_0_DEF_STATE << 7) | (IDLE_BIT_1_DEF_STATE << 6) | (cmd << 1) | tempCheck;
}

View File

@ -6,18 +6,13 @@
// Definitions for the Solar Cell Experiment // Definitions for the Solar Cell Experiment
namespace scex { namespace scex {
enum ScexCmds: uint8_t { enum ScexCmds : uint8_t { PING = 0b00111, ONE_CELL = 0b00110, FRAM = 0b00001 };
PING = 0b00111,
ONE_CELL = 0b00110
};
static constexpr uint8_t IDLE_BIT_0_DEF_STATE = 0; static constexpr uint8_t IDLE_BIT_0_DEF_STATE = 0;
static constexpr uint8_t IDLE_BIT_1_DEF_STATE = 1; static constexpr uint8_t IDLE_BIT_1_DEF_STATE = 1;
uint8_t createCmdByte(ScexCmds cmd, bool tempCheck) { uint8_t createCmdByte(ScexCmds cmd, bool tempCheck);
return (IDLE_BIT_0_DEF_STATE << 7) | (IDLE_BIT_1_DEF_STATE << 6) | (cmd << 1) | tempCheck;
}
} } // namespace scex
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_SCEXDEFINITIONS_H_ */ #endif /* MISSION_DEVICES_DEVICEDEFINITIONS_SCEXDEFINITIONS_H_ */