WIP: SCEX Init #272
@ -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,47 +138,7 @@ void UartTestClass::scexInit() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (scexMode == ScexModes::SIMPLE) {
|
if (scexMode == ScexModes::SIMPLE) {
|
||||||
#if defined(RASPBERRY_PI)
|
scexSimpleInit();
|
||||||
std::string devname = "/dev/serial0";
|
|
||||||
#else
|
|
||||||
std::string devname = "/dev/ul-scex";
|
|
||||||
#endif
|
|
||||||
/* Get file descriptor */
|
|
||||||
serialPort = open(devname.c_str(), O_RDWR);
|
|
||||||
if (serialPort < 0) {
|
|
||||||
sif::warning << "open call failed with error [" << errno << ", " << strerror(errno)
|
|
||||||
<< std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Setting up UART parameters
|
|
||||||
tty.c_cflag &= ~PARENB; // Clear parity bit
|
|
||||||
tty.c_cflag &= ~CSTOPB; // Clear stop field, only one stop bit used in communication
|
|
||||||
tty.c_cflag &= ~CSIZE; // Clear all the size bits
|
|
||||||
tty.c_cflag |= CS8; // 8 bits per byte
|
|
||||||
tty.c_cflag &= ~CRTSCTS; // Disable RTS/CTS hardware flow control
|
|
||||||
tty.c_cflag |= CREAD | CLOCAL; // Turn on READ & ignore ctrl lines (CLOCAL = 1)
|
|
||||||
|
|
||||||
// Use non-canonical mode and clear echo flag
|
|
||||||
tty.c_lflag &= ~(ICANON | ECHO);
|
|
||||||
|
|
||||||
// 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] = 1; // 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)
|
|
||||||
if (cfsetispeed(&tty, B57600) != 0) {
|
|
||||||
sif::warning << "UartTestClass::scexInit: Setting baud rate failed" << std::endl;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
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, TCIFLUSH);
|
|
||||||
} else {
|
} else {
|
||||||
#if defined(RASPBERRY_PI)
|
#if defined(RASPBERRY_PI)
|
||||||
std::string devname = "/dev/serial0";
|
std::string devname = "/dev/serial0";
|
||||||
@ -189,6 +149,11 @@ void UartTestClass::scexInit() {
|
|||||||
new UartCookie(this->getObjectId(), devname, UartModes::NON_CANONICAL, 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) {
|
||||||
|
sif::warning << "UartTestClass::gpsPeriodic: Initializing SCEX reader "
|
||||||
|
"UART IF failed"
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,44 +163,7 @@ void UartTestClass::scexPeriodic() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (scexMode == ScexModes::SIMPLE) {
|
if (scexMode == ScexModes::SIMPLE) {
|
||||||
sif::info << "UartTestClass::scexInit: Sending ping command to SCEX" << std::endl;
|
scexSimplePeriodic();
|
||||||
// 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 {
|
} else {
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
prepareScexPing(cmdBuf.data(), &len);
|
prepareScexPing(cmdBuf.data(), &len);
|
||||||
@ -259,3 +187,89 @@ int UartTestClass::prepareScexPing(uint8_t* cmdBuf, size_t* len) {
|
|||||||
*len = 7;
|
*len = 7;
|
||||||
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() {
|
||||||
|
#if defined(RASPBERRY_PI)
|
||||||
|
std::string devname = "/dev/serial0";
|
||||||
|
#else
|
||||||
|
std::string devname = "/dev/ul-scex";
|
||||||
|
#endif
|
||||||
|
/* Get file descriptor */
|
||||||
|
serialPort = open(devname.c_str(), O_RDWR);
|
||||||
|
if (serialPort < 0) {
|
||||||
|
sif::warning << "open call failed with error [" << errno << ", " << strerror(errno)
|
||||||
|
<< std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Setting up UART parameters
|
||||||
|
tty.c_cflag &= ~PARENB; // Clear parity bit
|
||||||
|
tty.c_cflag &= ~CSTOPB; // Clear stop field, only one stop bit used in communication
|
||||||
|
tty.c_cflag &= ~CSIZE; // Clear all the size bits
|
||||||
|
tty.c_cflag |= CS8; // 8 bits per byte
|
||||||
|
tty.c_cflag &= ~CRTSCTS; // Disable RTS/CTS hardware flow control
|
||||||
|
tty.c_cflag |= CREAD | CLOCAL; // Turn on READ & ignore ctrl lines (CLOCAL = 1)
|
||||||
|
|
||||||
|
// Use non-canonical mode and clear echo flag
|
||||||
|
tty.c_lflag &= ~(ICANON | ECHO);
|
||||||
|
|
||||||
|
// 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
|
||||||
|
|
||||||
|
// Q7S UART Lite has fixed baud rate. For other linux systems, set baud rate here.
|
||||||
|
#if !defined(XIPHOS_Q7S)
|
||||||
|
if (cfsetispeed(&tty, B57600) != 0) {
|
||||||
|
sif::warning << "UartTestClass::scexInit: Setting baud rate failed" << std::endl;
|
||||||
|
}
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -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;
|
||||||
|
@ -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"
|
||||||
|
|
||||||
|
@ -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
2
tmtc
@ -1 +1 @@
|
|||||||
Subproject commit 3a1c7c62887eb377c498bd9cdac47b93f40c85ba
|
Subproject commit 091cf2dd632c71a0fa8000312bb11e84f1a755db
|
Loading…
Reference in New Issue
Block a user