WIP: SCEX Init #272

Closed
muellerr wants to merge 62 commits from irini into develop
4 changed files with 66 additions and 51 deletions
Showing only changes of commit 44c8f5f730 - Show all commits

View File

@ -78,7 +78,7 @@ void ObjectFactory::produce(void* args) {
createRpiAcsBoard(gpioIF, spiDev); createRpiAcsBoard(gpioIF, spiDev);
#endif #endif
#if OBSW_ADD_SUN_SENSORS == 1 || defined(OBSW_ADD_RTD_DEVICES) #if OBSW_ADD_SUN_SENSORS == 1 || OBSW_ADD_RTD_DEVICES == 1
#ifdef RASPBERRY_PI #ifdef RASPBERRY_PI
rpi::gpio::initSpiCsDecoder(gpioIF); rpi::gpio::initSpiCsDecoder(gpioIF);
#endif #endif

View File

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

View File

@ -8,6 +8,7 @@
#include <array> #include <array>
#include "lwgps/lwgps.h" #include "lwgps/lwgps.h"
#include "mission/devices/devicedefinitions/SCEXDefinitions.h"
#include "test/testtasks/TestTask.h" #include "test/testtasks/TestTask.h"
class ScexUartReader; class ScexUartReader;
@ -34,11 +35,12 @@ class UartTestClass : public TestTask {
void scexInit(); void scexInit();
void scexPeriodic(); void scexPeriodic();
int prepareScexPing(uint8_t* cmdBuf, size_t* len); int prepareScexCmd(scex::ScexCmds cmd, bool tempCheck, uint8_t* cmdBuf, size_t* len);
void scexSimplePeriodic(); void scexSimplePeriodic();
void scexSimpleInit(); void scexSimpleInit();
scex::ScexCmds currCmd = scex::ScexCmds::PING;
TestModes mode = TestModes::GPS; TestModes mode = TestModes::GPS;
DleEncoder dleEncoder = DleEncoder(); DleEncoder dleEncoder = DleEncoder();
UartCookie* uartCookie = nullptr; UartCookie* uartCookie = nullptr;

View File

@ -6,7 +6,17 @@
// Definitions for the Solar Cell Experiment // Definitions for the Solar Cell Experiment
namespace scex { namespace scex {
static constexpr uint8_t CMD_PING = 0x4e; enum ScexCmds: uint8_t {
PING = 0b00111,
ONE_CELL = 0b00110
};
static constexpr uint8_t IDLE_BIT_0_DEF_STATE = 0;
static constexpr uint8_t IDLE_BIT_1_DEF_STATE = 1;
uint8_t createCmdByte(ScexCmds cmd, bool tempCheck) {
return (IDLE_BIT_0_DEF_STATE << 7) | (IDLE_BIT_1_DEF_STATE << 6) | (cmd << 1) | tempCheck;
}
} }