SCEX test code #135
@ -350,18 +350,17 @@ void initmission::createPusTasks(TaskFactory& factory,
|
|||||||
void initmission::createTestTasks(TaskFactory& factory,
|
void initmission::createTestTasks(TaskFactory& factory,
|
||||||
TaskDeadlineMissedFunction missedDeadlineFunc,
|
TaskDeadlineMissedFunction missedDeadlineFunc,
|
||||||
std::vector<PeriodicTaskIF*>& taskVec) {
|
std::vector<PeriodicTaskIF*>& taskVec) {
|
||||||
#if OBSW_ADD_TEST_TASK == 1 || OBSW_ADD_SPI_TEST_CODE == 1 || OBSW_ADD_I2C_TEST_CODE == 1 || \
|
#if OBSW_ADD_TEST_TASK == 1 && OBSW_ADD_TEST_CODE == 1
|
||||||
(BOARD_TE0720 == 1 && OBSW_TEST_LIBGPIOD == 1)
|
|
||||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||||
#endif
|
static_cast<void>(result); // supress warning in case it is not used
|
||||||
|
|
||||||
PeriodicTaskIF* testTask = factory.createPeriodicTask(
|
PeriodicTaskIF* testTask = factory.createPeriodicTask(
|
||||||
"TEST_TASK", 60, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1, missedDeadlineFunc);
|
"TEST_TASK", 60, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1, missedDeadlineFunc);
|
||||||
#if OBSW_ADD_TEST_TASK == 1
|
|
||||||
result = testTask->addComponent(objects::TEST_TASK);
|
result = testTask->addComponent(objects::TEST_TASK);
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
initmission::printAddObjectError("TEST_TASK", objects::TEST_TASK);
|
initmission::printAddObjectError("TEST_TASK", objects::TEST_TASK);
|
||||||
}
|
}
|
||||||
#endif /* OBSW_ADD_TEST_TASK == 1 */
|
|
||||||
|
|
||||||
#if OBSW_ADD_SPI_TEST_CODE == 1
|
#if OBSW_ADD_SPI_TEST_CODE == 1
|
||||||
result = testTask->addComponent(objects::SPI_TEST);
|
result = testTask->addComponent(objects::SPI_TEST);
|
||||||
@ -375,6 +374,13 @@ void initmission::createTestTasks(TaskFactory& factory,
|
|||||||
initmission::printAddObjectError("I2C_TEST", objects::I2C_TEST);
|
initmission::printAddObjectError("I2C_TEST", objects::I2C_TEST);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#if OBSW_ADD_UART_TEST_CODE == 1
|
||||||
|
result = testTask->addComponent(objects::UART_TEST);
|
||||||
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
initmission::printAddObjectError("UART_TEST", objects::UART_TEST);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if BOARD_TE0720 == 1 && OBSW_TEST_LIBGPIOD == 1
|
#if BOARD_TE0720 == 1 && OBSW_TEST_LIBGPIOD == 1
|
||||||
result = testTask->addComponent(objects::LIBGPIOD_TEST);
|
result = testTask->addComponent(objects::LIBGPIOD_TEST);
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
@ -382,4 +388,6 @@ void initmission::createTestTasks(TaskFactory& factory,
|
|||||||
}
|
}
|
||||||
#endif /* BOARD_TE0720 == 1 && OBSW_TEST_LIBGPIOD == 1 */
|
#endif /* BOARD_TE0720 == 1 && OBSW_TEST_LIBGPIOD == 1 */
|
||||||
taskVec.push_back(testTask);
|
taskVec.push_back(testTask);
|
||||||
|
|
||||||
|
#endif // OBSW_ADD_TEST_TASK == 1 && OBSW_ADD_TEST_CODE == 1
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "ObjectFactory.h"
|
#include "ObjectFactory.h"
|
||||||
|
|
||||||
#include <linux/boardtest/I2cTestClass.h>
|
#include <linux/boardtest/I2cTestClass.h>
|
||||||
|
#include <linux/boardtest/UartTestClass.h>
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
@ -1135,4 +1136,7 @@ void ObjectFactory::createTestComponents(LinuxLibgpioIF* gpioComIF) {
|
|||||||
#if OBSW_ADD_I2C_TEST_CODE == 1
|
#if OBSW_ADD_I2C_TEST_CODE == 1
|
||||||
new I2cTestClass(objects::I2C_TEST, q7s::I2C_DEFAULT_DEV);
|
new I2cTestClass(objects::I2C_TEST, q7s::I2C_DEFAULT_DEV);
|
||||||
#endif
|
#endif
|
||||||
|
#if OBSW_ADD_UART_TEST_CODE == 1
|
||||||
|
new UartTestClass(objects::UART_TEST);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -9,18 +9,21 @@
|
|||||||
#include <fcntl.h> // Contains file controls like O_RDWR
|
#include <fcntl.h> // Contains file controls like O_RDWR
|
||||||
#include <unistd.h> // write(), read(), close()
|
#include <unistd.h> // write(), read(), close()
|
||||||
|
|
||||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
#include "fsfw/globalfunctions/CRC.h"
|
||||||
#include "lwgps/lwgps.h"
|
#include "fsfw/globalfunctions/arrayprinter.h"
|
||||||
|
#include "fsfw/serviceinterface.h"
|
||||||
|
#include "mission/devices/devicedefinitions/SCEXDefinitions.h"
|
||||||
|
|
||||||
#define GPS_REPLY_WIRETAPPING 0
|
#define GPS_REPLY_WIRETAPPING 0
|
||||||
|
|
||||||
UartTestClass::UartTestClass(object_id_t objectId) : TestTask(objectId) {}
|
UartTestClass::UartTestClass(object_id_t objectId) : TestTask(objectId) { mode = TestModes::SCEX; }
|
||||||
|
|
||||||
ReturnValue_t UartTestClass::initialize() {
|
ReturnValue_t UartTestClass::initialize() {
|
||||||
if (mode == TestModes::GPS) {
|
if (mode == TestModes::GPS) {
|
||||||
gpsInit();
|
gpsInit();
|
||||||
|
} else if (mode == TestModes::SCEX) {
|
||||||
|
scexInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,6 +32,8 @@ ReturnValue_t UartTestClass::performOneShotAction() { return HasReturnvaluesIF::
|
|||||||
ReturnValue_t UartTestClass::performPeriodicAction() {
|
ReturnValue_t UartTestClass::performPeriodicAction() {
|
||||||
if (mode == TestModes::GPS) {
|
if (mode == TestModes::GPS) {
|
||||||
gpsPeriodic();
|
gpsPeriodic();
|
||||||
|
} else if (mode == TestModes::SCEX) {
|
||||||
|
scexPeriodic();
|
||||||
}
|
}
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
@ -118,3 +123,77 @@ void UartTestClass::gpsPeriodic() {
|
|||||||
} while (bytesRead > 0);
|
} while (bytesRead > 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UartTestClass::scexInit() {
|
||||||
|
#if defined(RASPBERRY_PI)
|
||||||
|
std::string devname = "/dev/ttyUSB1";
|
||||||
|
#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
|
||||||
|
tty.c_cc[VTIME] = 1; // In units of 0.1 seconds
|
||||||
|
tty.c_cc[VMIN] = 1;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UartTestClass::scexPeriodic() {
|
||||||
|
// 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.data(), 5);
|
||||||
|
cmdBuf[5] = (crc >> 8) & 0xff;
|
||||||
|
cmdBuf[6] = crc & 0xff;
|
||||||
|
size_t bytesWritten = write(serialPort, cmdBuf.data(), 7);
|
||||||
|
if (bytesWritten != 7) {
|
||||||
|
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 << " from the Solar Cell Experiment:" << std::endl;
|
||||||
|
arrayprinter::print(recBuf.data(), bytesRead);
|
||||||
|
}
|
||||||
|
} while (bytesRead > 0);
|
||||||
|
}
|
||||||
|
@ -20,16 +20,20 @@ class UartTestClass : public TestTask {
|
|||||||
enum TestModes {
|
enum TestModes {
|
||||||
GPS,
|
GPS,
|
||||||
// Solar Cell Experiment
|
// Solar Cell Experiment
|
||||||
SCE
|
SCEX
|
||||||
};
|
};
|
||||||
|
|
||||||
void gpsInit();
|
void gpsInit();
|
||||||
void gpsPeriodic();
|
void gpsPeriodic();
|
||||||
|
|
||||||
|
void scexInit();
|
||||||
|
void scexPeriodic();
|
||||||
TestModes mode = TestModes::GPS;
|
TestModes mode = TestModes::GPS;
|
||||||
lwgps_t gpsData = {};
|
lwgps_t gpsData = {};
|
||||||
struct termios tty = {};
|
struct termios tty = {};
|
||||||
int serialPort = 0;
|
int serialPort = 0;
|
||||||
std::array<uint8_t, 512> recBuf;
|
std::array<uint8_t, 64> cmdBuf = {};
|
||||||
|
std::array<uint8_t, 4096> recBuf = {};
|
||||||
uint8_t recvCnt = 0;
|
uint8_t recvCnt = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -68,12 +68,14 @@ debugging. */
|
|||||||
|
|
||||||
#define OBSW_SYRLINKS_SIMULATED 1
|
#define OBSW_SYRLINKS_SIMULATED 1
|
||||||
#define OBSW_ADD_TEST_CODE 0
|
#define OBSW_ADD_TEST_CODE 0
|
||||||
|
#define OBSW_ADD_TEST_TASK 0
|
||||||
|
#define OBSW_ADD_TEST_PST 0
|
||||||
// If this is enabled, all other SPI code should be disabled
|
// If this is enabled, all other SPI code should be disabled
|
||||||
#define OBSW_ADD_SPI_TEST_CODE 0
|
#define OBSW_ADD_SPI_TEST_CODE 0
|
||||||
// If this is enabled, all other I2C code should be disabled
|
// If this is enabled, all other I2C code should be disabled
|
||||||
#define OBSW_ADD_I2C_TEST_CODE 0
|
#define OBSW_ADD_I2C_TEST_CODE 0
|
||||||
#define OBSW_ADD_TEST_PST 0
|
#define OBSW_ADD_UART_TEST_CODE 0
|
||||||
#define OBSW_ADD_TEST_TASK 0
|
|
||||||
#define OBSW_TEST_LIBGPIOD 0
|
#define OBSW_TEST_LIBGPIOD 0
|
||||||
#define OBSW_TEST_RADIATION_SENSOR_HANDLER 0
|
#define OBSW_TEST_RADIATION_SENSOR_HANDLER 0
|
||||||
#define OBSW_TEST_SUS_HANDLER 0
|
#define OBSW_TEST_SUS_HANDLER 0
|
||||||
|
13
mission/devices/devicedefinitions/SCEXDefinitions.h
Normal file
13
mission/devices/devicedefinitions/SCEXDefinitions.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_SCEXDEFINITIONS_H_
|
||||||
|
#define MISSION_DEVICES_DEVICEDEFINITIONS_SCEXDEFINITIONS_H_
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
// Definitions for the Solar Cell Experiment
|
||||||
|
namespace scex {
|
||||||
|
|
||||||
|
static constexpr uint8_t CMD_PING = 0x4e;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_SCEXDEFINITIONS_H_ */
|
Loading…
x
Reference in New Issue
Block a user