WIP: SCEX Init #272

Closed
muellerr wants to merge 62 commits from irini into develop
5 changed files with 100 additions and 83 deletions
Showing only changes of commit 6071e34771 - Show all commits

View File

@ -23,7 +23,7 @@
UartTestClass::UartTestClass(object_id_t objectId, ScexUartReader* reader) UartTestClass::UartTestClass(object_id_t objectId, ScexUartReader* reader)
: TestTask(objectId), reader(reader) { : TestTask(objectId), reader(reader) {
mode = TestModes::SCEX; mode = TestModes::SCEX;
scexMode = ScexModes::READER_TASK; scexMode = ScexModes::SIMPLE;
} }
ReturnValue_t UartTestClass::initialize() { ReturnValue_t UartTestClass::initialize() {
@ -138,6 +138,99 @@ void UartTestClass::scexInit() {
return; return;
} }
if (scexMode == ScexModes::SIMPLE) { if (scexMode == ScexModes::SIMPLE) {
scexSimpleInit();
} else {
#if defined(RASPBERRY_PI)
std::string devname = "/dev/serial0";
#else
std::string devname = "/dev/ul-scex";
#endif
uartCookie =
new UartCookie(this->getObjectId(), devname, UartModes::NON_CANONICAL, 57600, 4096);
reader->setDebugMode(true);
ReturnValue_t result = reader->initializeInterface(uartCookie);
if (result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "UartTestClass::gpsPeriodic: Initializing SCEX reader "
"UART IF failed"
<< std::endl;
}
}
}
void UartTestClass::scexPeriodic() {
if (reader == nullptr) {
return;
}
if (scexMode == ScexModes::SIMPLE) {
scexSimplePeriodic();
} else {
size_t len = 0;
prepareScexPing(cmdBuf.data(), &len);
reader->sendMessage(uartCookie, cmdBuf.data(), len);
}
}
int UartTestClass::prepareScexPing(uint8_t* cmdBuf, size_t* len) {
// Send ping command
cmdBuf[0] = scex::CMD_PING;
// 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::scexSimplePeriodic() {
sif::info << "UartTestClass::scexInit: Sending ping command to SCEX" << std::endl;
uint8_t tmpCmdBuf[32] = {};
size_t len = 0;
prepareScexPing(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 occured after 0.5 seconds" << 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);
}
void UartTestClass::scexSimpleInit() {
#if defined(RASPBERRY_PI) #if defined(RASPBERRY_PI)
std::string devname = "/dev/serial0"; std::string devname = "/dev/serial0";
#else #else
@ -163,8 +256,8 @@ void UartTestClass::scexInit() {
// 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] = 1; // In units of 0.1 seconds tty.c_cc[VTIME] = 5; // In units of 0.1 seconds
tty.c_cc[VMIN] = 255; // Read up to 255 bytes tty.c_cc[VMIN] = 1; // 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)
@ -173,89 +266,10 @@ void UartTestClass::scexInit() {
} }
#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, TCIFLUSH);
} else {
#if defined(RASPBERRY_PI)
std::string devname = "/dev/serial0";
#else
std::string devname = "/dev/ul-scex";
#endif
uartCookie =
new UartCookie(this->getObjectId(), devname, UartModes::NON_CANONICAL, 57600, 4096);
reader->setDebugMode(true);
ReturnValue_t result = reader->initializeInterface(uartCookie);
}
}
void UartTestClass::scexPeriodic() {
if (reader == nullptr) {
return;
}
if (scexMode == ScexModes::SIMPLE) {
sif::info << "UartTestClass::scexInit: Sending ping command to SCEX" << std::endl;
// reader->sendMessage(nullptr, nullptr, 0);
uint8_t tmpCmdBuf[32] = {};
size_t len = 0;
prepareScexPing(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 << "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);
} else {
size_t len = 0;
prepareScexPing(cmdBuf.data(), &len);
reader->sendMessage(uartCookie, cmdBuf.data(), len);
}
}
int UartTestClass::prepareScexPing(uint8_t* cmdBuf, size_t* len) {
// Send ping command
cmdBuf[0] = scex::CMD_PING;
// 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;
} }

View File

@ -35,6 +35,10 @@ class UartTestClass : public TestTask {
void scexInit(); void scexInit();
void scexPeriodic(); void scexPeriodic();
int prepareScexPing(uint8_t* cmdBuf, size_t* len); int prepareScexPing(uint8_t* cmdBuf, size_t* len);
void scexSimplePeriodic();
void scexSimpleInit();
TestModes mode = TestModes::GPS; TestModes mode = TestModes::GPS;
DleEncoder dleEncoder = DleEncoder(); DleEncoder dleEncoder = DleEncoder();
UartCookie* uartCookie = nullptr; UartCookie* uartCookie = nullptr;

View File

@ -3,7 +3,6 @@
#include "OBSWConfig.h" #include "OBSWConfig.h"
#include "fsfw/datapool/PoolReadGuard.h" #include "fsfw/datapool/PoolReadGuard.h"
#include "fsfw/timemanager/Clock.h" #include "fsfw/timemanager/Clock.h"
#include "linux/utility/utility.h" #include "linux/utility/utility.h"
#include "mission/utility/compileTime.h" #include "mission/utility/compileTime.h"

View File

@ -111,7 +111,7 @@ void P60DockHandler::parseHkTableReply(const uint8_t *packet) {
dataOffset += 6; dataOffset += 6;
coreHk.bootCount = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 | coreHk.bootCount = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 |
*(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3); *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3);
if(firstHk) { if (firstHk) {
triggerEvent(P60_BOOT_COUNT, coreHk.bootCount.value); triggerEvent(P60_BOOT_COUNT, coreHk.bootCount.value);
} }
dataOffset += 6; dataOffset += 6;

2
tmtc

@ -1 +1 @@
Subproject commit 3a1c7c62887eb377c498bd9cdac47b93f40c85ba Subproject commit 091cf2dd632c71a0fa8000312bb11e84f1a755db