Merge branch 'mohr/startracker' into meier/startracker
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
target_sources(${OBSW_NAME} PRIVATE
|
||||
LibgpiodTest.cpp
|
||||
I2cTestClass.cpp
|
||||
SpiTestClass.cpp
|
||||
|
@ -1,4 +1,6 @@
|
||||
#include "UartTestClass.h"
|
||||
|
||||
#include <fsfw/tasks/TaskFactory.h>
|
||||
#if defined(RASPBERRY_PI)
|
||||
#include "rpiConfig.h"
|
||||
#elif defined(XIPHOS_Q7S)
|
||||
@ -9,18 +11,22 @@
|
||||
#include <fcntl.h> // Contains file controls like O_RDWR
|
||||
#include <unistd.h> // write(), read(), close()
|
||||
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
#include "lwgps/lwgps.h"
|
||||
#include "fsfw/globalfunctions/CRC.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
|
||||
|
||||
UartTestClass::UartTestClass(object_id_t objectId) : TestTask(objectId) {}
|
||||
UartTestClass::UartTestClass(object_id_t objectId) : TestTask(objectId) { mode = TestModes::SCEX; }
|
||||
|
||||
ReturnValue_t UartTestClass::initialize() {
|
||||
if (mode == TestModes::GPS) {
|
||||
gpsInit();
|
||||
} else if (mode == TestModes::SCEX) {
|
||||
scexInit();
|
||||
}
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
@ -29,6 +35,8 @@ ReturnValue_t UartTestClass::performOneShotAction() { return HasReturnvaluesIF::
|
||||
ReturnValue_t UartTestClass::performPeriodicAction() {
|
||||
if (mode == TestModes::GPS) {
|
||||
gpsPeriodic();
|
||||
} else if (mode == TestModes::SCEX) {
|
||||
scexPeriodic();
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
@ -118,3 +126,96 @@ void UartTestClass::gpsPeriodic() {
|
||||
} while (bytesRead > 0);
|
||||
#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);
|
||||
}
|
||||
|
@ -20,16 +20,20 @@ class UartTestClass : public TestTask {
|
||||
enum TestModes {
|
||||
GPS,
|
||||
// Solar Cell Experiment
|
||||
SCE
|
||||
SCEX
|
||||
};
|
||||
|
||||
void gpsInit();
|
||||
void gpsPeriodic();
|
||||
|
||||
void scexInit();
|
||||
void scexPeriodic();
|
||||
TestModes mode = TestModes::GPS;
|
||||
lwgps_t gpsData = {};
|
||||
struct termios tty = {};
|
||||
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;
|
||||
};
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
target_sources(${TARGET_NAME} PUBLIC
|
||||
target_sources(${OBSW_NAME} PUBLIC
|
||||
CspComIF.cpp
|
||||
CspCookie.cpp
|
||||
)
|
||||
|
@ -1,4 +1,4 @@
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
target_sources(${OBSW_NAME} PRIVATE
|
||||
SolarArrayDeploymentHandler.cpp
|
||||
SusHandler.cpp
|
||||
)
|
||||
|
@ -1,4 +1,4 @@
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
target_sources(${OBSW_NAME} PRIVATE
|
||||
StarTrackerHandler.cpp
|
||||
StarTrackerJsonCommands.cpp
|
||||
ArcsecDatalinkLayer.cpp
|
||||
|
@ -1,22 +1,22 @@
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
target_sources(${OBSW_NAME} PRIVATE
|
||||
ipc/MissionMessageTypes.cpp
|
||||
pollingsequence/pollingSequenceFactory.cpp
|
||||
)
|
||||
|
||||
target_include_directories(${TARGET_NAME} PUBLIC
|
||||
target_include_directories(${OBSW_NAME} PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
# If a special translation file for object IDs exists, compile it.
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/objects/translateObjects.cpp")
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
target_sources(${OBSW_NAME} PRIVATE
|
||||
objects/translateObjects.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
# If a special translation file for events exists, compile it.
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/objects/translateObjects.cpp")
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
target_sources(${OBSW_NAME} PRIVATE
|
||||
events/translateEvents.cpp
|
||||
)
|
||||
endif()
|
||||
|
@ -75,12 +75,14 @@ debugging. */
|
||||
|
||||
#define OBSW_SYRLINKS_SIMULATED 1
|
||||
#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
|
||||
#define OBSW_ADD_SPI_TEST_CODE 0
|
||||
// If this is enabled, all other I2C code should be disabled
|
||||
#define OBSW_ADD_I2C_TEST_CODE 0
|
||||
#define OBSW_ADD_TEST_PST 0
|
||||
#define OBSW_ADD_TEST_TASK 0
|
||||
#define OBSW_ADD_UART_TEST_CODE 0
|
||||
|
||||
#define OBSW_TEST_LIBGPIOD 0
|
||||
#define OBSW_TEST_RADIATION_SENSOR_HANDLER 0
|
||||
#define OBSW_TEST_SUS_HANDLER 0
|
||||
|
@ -3,6 +3,6 @@
|
||||
|
||||
#include "fsfw/events/Event.h"
|
||||
|
||||
const char * translateEvents(Event event);
|
||||
const char* translateEvents(Event event);
|
||||
|
||||
#endif /* FSFWCONFIG_EVENTS_TRANSLATEEVENTS_H_ */
|
||||
|
@ -1,4 +1,4 @@
|
||||
target_sources(${TARGET_NAME} PUBLIC
|
||||
target_sources(${OBSW_NAME} PUBLIC
|
||||
PapbVcInterface.cpp
|
||||
Ptme.cpp
|
||||
PdecHandler.cpp
|
||||
|
@ -1,4 +1,4 @@
|
||||
target_sources(${TARGET_NAME} PUBLIC
|
||||
target_sources(${OBSW_NAME} PUBLIC
|
||||
utility.cpp
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user