diff --git a/bsp_linux_board/InitMission.cpp b/bsp_linux_board/InitMission.cpp index 86d5fb4b..3e5bb0fb 100644 --- a/bsp_linux_board/InitMission.cpp +++ b/bsp_linux_board/InitMission.cpp @@ -1,4 +1,8 @@ #include "InitMission.h" +#include "OBSWConfig.h" +#include "ObjectFactory.h" +#include "objects/systemObjectList.h" +#include "pollingsequence/pollingSequenceFactory.h" #include #include @@ -11,11 +15,6 @@ #include -#include "OBSWConfig.h" -#include "ObjectFactory.h" -#include "objects/systemObjectList.h" -#include "pollingsequence/pollingSequenceFactory.h" - ServiceInterfaceStream sif::debug("DEBUG"); ServiceInterfaceStream sif::info("INFO"); ServiceInterfaceStream sif::warning("WARNING"); @@ -211,7 +210,7 @@ void initmission::createTestTasks(TaskFactory& factory, if (result != HasReturnvaluesIF::RETURN_OK) { initmission::printAddObjectError("TEST_TASK", objects::TEST_TASK); } -#if RPI_ADD_SPI_TEST == 1 +#if OBSW_ADD_SPI_TEST_CODE == 1 result = testTask->addComponent(objects::SPI_TEST); if (result != HasReturnvaluesIF::RETURN_OK) { initmission::printAddObjectError("SPI_TEST", objects::SPI_TEST); @@ -223,12 +222,13 @@ void initmission::createTestTasks(TaskFactory& factory, initmission::printAddObjectError("GPIOD_TEST", objects::LIBGPIOD_TEST); } #endif /* RPI_ADD_GPIO_TEST == 1 */ -#if RPI_ADD_UART_TEST == 1 +#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 /* RPI_ADD_GPIO_TEST == 1 */ + taskVec.push_back(testTask); bool startTestPst = true; static_cast(startTestPst); diff --git a/bsp_linux_board/ObjectFactory.cpp b/bsp_linux_board/ObjectFactory.cpp index fcc08a66..1f7649ee 100644 --- a/bsp_linux_board/ObjectFactory.cpp +++ b/bsp_linux_board/ObjectFactory.cpp @@ -178,11 +178,11 @@ void ObjectFactory::produce(void* args) { void ObjectFactory::createTestTasks() { new TestTask(objects::TEST_TASK); -#if RPI_ADD_SPI_TEST == 1 +#if OBSW_ADD_SPI_TEST_CODE == 1 new SpiTestClass(objects::SPI_TEST, gpioIF); #endif -#if RPI_ADD_UART_TEST == 1 +#if OBSW_ADD_UART_TEST_CODE == 1 new UartTestClass(objects::UART_TEST); #else new UartComIF(objects::UART_COM_IF); diff --git a/linux/boardtest/UartTestClass.cpp b/linux/boardtest/UartTestClass.cpp index b8e7da10..9336df9f 100644 --- a/linux/boardtest/UartTestClass.cpp +++ b/linux/boardtest/UartTestClass.cpp @@ -1,11 +1,6 @@ #include "UartTestClass.h" - +#include "OBSWConfig.h" #include -#if defined(RASPBERRY_PI) -#include "rpiConfig.h" -#elif defined(XIPHOS_Q7S) -#include "q7sConfig.h" -#endif #include // Error integer and strerror() function #include // Contains file controls like O_RDWR @@ -42,7 +37,7 @@ ReturnValue_t UartTestClass::performPeriodicAction() { } void UartTestClass::gpsInit() { -#if RPI_TEST_GPS_DEVICE == 1 +#if RPI_TEST_GPS_HANDLER == 1 int result = lwgps_init(&gpsData); if (result == 0) { sif::warning << "lwgps_init error: " << result << std::endl; @@ -90,7 +85,7 @@ void UartTestClass::gpsInit() { } void UartTestClass::gpsPeriodic() { -#if RPI_TEST_GPS_DEVICE == 1 +#if RPI_TEST_GPS_HANDLER == 1 int bytesRead = 0; do { bytesRead = read(serialPort, reinterpret_cast(recBuf.data()), @@ -129,7 +124,7 @@ void UartTestClass::gpsPeriodic() { void UartTestClass::scexInit() { #if defined(RASPBERRY_PI) - std::string devname = "/dev/ttyUSB1"; + std::string devname = "/dev/serial0"; #else std::string devname = "/dev/ul-scex"; #endif @@ -165,37 +160,12 @@ void UartTestClass::scexInit() { } void UartTestClass::scexPeriodic() { - auto dleEncoder = DleEncoder(); - std::array 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; + sif::info << "UartTestClass::scexInit: Sending ping command to SCEX" << std::endl; + int result = prepareScexPing(); + if(result != 0) { 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; } @@ -210,8 +180,7 @@ void UartTestClass::scexPeriodic() { << ", " << strerror(errno) << "]" << std::endl; break; } else if (bytesRead >= static_cast(recBuf.size())) { - sif::debug << "UartTestClass::performPeriodicAction: " - "recv buffer might not be large enough" + 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; @@ -219,3 +188,26 @@ void UartTestClass::scexPeriodic() { } } while (bytesRead > 0); } + +int UartTestClass::prepareScexPing() { + std::array 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; + 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 -1; + } + return 0; +} diff --git a/linux/boardtest/UartTestClass.h b/linux/boardtest/UartTestClass.h index 33194598..786d01ce 100644 --- a/linux/boardtest/UartTestClass.h +++ b/linux/boardtest/UartTestClass.h @@ -1,6 +1,7 @@ #ifndef LINUX_BOARDTEST_UARTTESTCLASS_H_ #define LINUX_BOARDTEST_UARTTESTCLASS_H_ +#include #include // Contains POSIX terminal control definitions #include @@ -28,7 +29,10 @@ class UartTestClass : public TestTask { void scexInit(); void scexPeriodic(); + int prepareScexPing(); TestModes mode = TestModes::GPS; + DleEncoder dleEncoder = DleEncoder(); + size_t encodedLen = 0; lwgps_t gpsData = {}; struct termios tty = {}; int serialPort = 0; diff --git a/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index 0c7fcd9c..a27dd98f 100644 --- a/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -443,6 +443,7 @@ ReturnValue_t pst::pstSpi(FixedTimeslotTaskIF *thisSequence) { ReturnValue_t pst::pstI2c(FixedTimeslotTaskIF *thisSequence) { // Length of a communication cycle uint32_t length = thisSequence->getPeriodMs(); + static_cast(length); #if OBSW_ADD_MGT == 1 thisSequence->addSlot(objects::IMTQ_HANDLER, length * 0, DeviceHandlerIF::PERFORM_OPERATION); thisSequence->addSlot(objects::IMTQ_HANDLER, length * 0.2, DeviceHandlerIF::SEND_WRITE);