Merge pull request 'SCEX test code' (#135) from mueller/scex-test-code into develop
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good

Reviewed-on: #135
Reviewed-by: Jakob.Meier <meierj@irs.uni-stuttgart.de>
This commit is contained in:
Jakob Meier 2022-02-09 14:24:49 +01:00
commit 20f091d54e
11 changed files with 459 additions and 309 deletions

View File

@ -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
} }

View File

@ -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
} }

View File

@ -1,4 +1,6 @@
#include "UartTestClass.h" #include "UartTestClass.h"
#include <fsfw/tasks/TaskFactory.h>
#if defined(RASPBERRY_PI) #if defined(RASPBERRY_PI)
#include "rpiConfig.h" #include "rpiConfig.h"
#elif defined(XIPHOS_Q7S) #elif defined(XIPHOS_Q7S)
@ -9,18 +11,22 @@
#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/DleEncoder.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 +35,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 +126,96 @@ 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, 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
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() {
auto dleEncoder = DleEncoder();
std::array<uint8_t, 128> tmpCmdBuf = {};
// Send ping command
tmpCmdBuf[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
tmpCmdBuf[1] = 1;
tmpCmdBuf[2] = 1;
uint16_t userDataLen = 0;
tmpCmdBuf[3] = (userDataLen >> 8) & 0xff;
tmpCmdBuf[4] = userDataLen & 0xff;
uint16_t crc = CRC::crc16ccitt(tmpCmdBuf.data(), 5);
tmpCmdBuf[5] = (crc >> 8) & 0xff;
tmpCmdBuf[6] = crc & 0xff;
size_t encodedLen = 0;
ReturnValue_t result =
dleEncoder.encode(tmpCmdBuf.data(), 7, cmdBuf.data(), cmdBuf.size(), &encodedLen, true);
if (result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "UartTestClass::scexInit: Encoding failed" << std::endl;
return;
}
arrayprinter::print(cmdBuf.data(), 9);
size_t bytesWritten = write(serialPort, cmdBuf.data(), encodedLen);
if (bytesWritten != encodedLen) {
sif::warning << "Sending ping command to solar experiment failed" << std::endl;
}
TaskFactory::delayTask(20);
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 << " from the Solar Cell Experiment:" << std::endl;
arrayprinter::print(recBuf.data(), bytesRead);
}
} while (bytesRead > 0);
}

View File

@ -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;
}; };

View File

@ -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

View 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_ */

View File

@ -49,6 +49,13 @@ def handle_args():
action="store_true", action="store_true",
help="Copy from Q7S to host instead. Always copies to current directory.", help="Copy from Q7S to host instead. Always copies to current directory.",
) )
parser.add_argument(
"-f",
"--flatsat",
default=False,
action="store_true",
help="Copy to flatsat instead"
)
# Positional argument(s) # Positional argument(s)
parser.add_argument( parser.add_argument(
"source", help="Source files to copy or target files to copy back to host" "source", help="Source files to copy or target files to copy back to host"
@ -61,17 +68,28 @@ def build_cmd(args):
cmd = "scp " cmd = "scp "
if args.recursive: if args.recursive:
cmd += "-r " cmd += "-r "
address = ""
port_args = ""
target = args.target target = args.target
if args.invert and target == "": if args.flatsat:
target = "." address = "eive@flatsat.eive.absatvirt.lw"
elif target == "":
target = f"/tmp"
if args.invert:
cmd += f"-P {args.port} root@localhost:{args.source} {target}"
else: else:
cmd += f"-P {args.port} {args.source} root@localhost:{target}" address = "root@localhost"
if args.target: port_args=f"-P {args.port}"
cmd += args.target if args.invert:
if target == "":
target = "."
else:
target = args.target
else:
if target == "":
target = f"/tmp"
else:
target = args.target
if args.invert:
cmd += f"{port_args} {address}:{args.source} {target}"
else:
cmd += f"{port_args} {args.source} {address}:{target}"
return cmd return cmd

@ -1 +1 @@
Subproject commit 2d10c6b85ea4cab4f4baf1918c51d54eee4202c2 Subproject commit 5d5e46b09bbd5208176c68d94c798493e705a2ee

2
tmtc

@ -1 +1 @@
Subproject commit 84c2730836e6821ff089d7567018fe4ffded62db Subproject commit 6a78311239bdf78040e43ef217035fcaa2ab9f3b