|
|
|
@ -12,7 +12,6 @@
|
|
|
|
|
#include "fsfw/globalfunctions/DleEncoder.h"
|
|
|
|
|
#include "fsfw/globalfunctions/arrayprinter.h"
|
|
|
|
|
#include "fsfw/serviceinterface.h"
|
|
|
|
|
#include "mission/devices/devicedefinitions/SCEXDefinitions.h"
|
|
|
|
|
|
|
|
|
|
#define GPS_REPLY_WIRETAPPING 0
|
|
|
|
|
|
|
|
|
@ -24,6 +23,7 @@ UartTestClass::UartTestClass(object_id_t objectId, ScexUartReader* reader)
|
|
|
|
|
: TestTask(objectId), reader(reader) {
|
|
|
|
|
mode = TestModes::SCEX;
|
|
|
|
|
scexMode = ScexModes::SIMPLE;
|
|
|
|
|
currCmd = scex::ScexCmds::ONE_CELL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ReturnValue_t UartTestClass::initialize() {
|
|
|
|
@ -166,14 +166,16 @@ void UartTestClass::scexPeriodic() {
|
|
|
|
|
scexSimplePeriodic();
|
|
|
|
|
} else {
|
|
|
|
|
size_t len = 0;
|
|
|
|
|
prepareScexPing(cmdBuf.data(), &len);
|
|
|
|
|
prepareScexCmd(scex::ScexCmds::PING, false, cmdBuf.data(), &len);
|
|
|
|
|
reader->sendMessage(uartCookie, cmdBuf.data(), len);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int UartTestClass::prepareScexPing(uint8_t* cmdBuf, size_t* len) {
|
|
|
|
|
int UartTestClass::prepareScexCmd(scex::ScexCmds cmd, bool tempCheck,
|
|
|
|
|
uint8_t* cmdBuf, size_t* len) {
|
|
|
|
|
using namespace scex;
|
|
|
|
|
// Send ping command
|
|
|
|
|
cmdBuf[0] = scex::CMD_PING;
|
|
|
|
|
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;
|
|
|
|
@ -188,48 +190,6 @@ int UartTestClass::prepareScexPing(uint8_t* cmdBuf, size_t* len) {
|
|
|
|
|
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)
|
|
|
|
|
std::string devname = "/dev/serial0";
|
|
|
|
@ -256,8 +216,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] = 5; // In units of 0.1 seconds
|
|
|
|
|
tty.c_cc[VMIN] = 1; // Read up to 255 bytes
|
|
|
|
|
tty.c_cc[VTIME] = 0; // In units of 0.1 seconds
|
|
|
|
|
tty.c_cc[VMIN] = 0; // Read up to 255 bytes
|
|
|
|
|
|
|
|
|
|
// Q7S UART Lite has fixed baud rate. For other linux systems, set baud rate here.
|
|
|
|
|
#if !defined(XIPHOS_Q7S)
|
|
|
|
@ -273,3 +233,46 @@ void UartTestClass::scexSimpleInit() {
|
|
|
|
|
<< std::endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
} while (bytesRead > 0);
|
|
|
|
|
}
|
|
|
|
|