From 005e548059053b67add4e1c43d495176c67b7592 Mon Sep 17 00:00:00 2001 From: Irini Kosmidou Date: Tue, 21 Jun 2022 16:44:14 +0200 Subject: [PATCH] comntinued scex handler --- bsp_linux_board/InitMission.cpp | 36 ++++++------- common/config/devConf.h | 1 + fsfw | 2 +- linux/ObjectFactory.cpp | 6 ++- linux/devices/ScexDleParser.h | 5 +- linux/devices/ScexUartReader.cpp | 31 ++++++----- linux/devices/ScexUartReader.h | 5 +- mission/devices/CMakeLists.txt | 2 + mission/devices/ScexDeviceHandler.cpp | 54 ++++++++++--------- mission/devices/ScexDeviceHandler.h | 1 - .../devicedefinitions/ScexDefinitions.cpp | 4 +- .../devicedefinitions/ScexDefinitions.h | 6 +-- scripts/rpi-port.sh | 4 +- tmtc | 2 +- 14 files changed, 82 insertions(+), 77 deletions(-) diff --git a/bsp_linux_board/InitMission.cpp b/bsp_linux_board/InitMission.cpp index 3611524c..16fac3f6 100644 --- a/bsp_linux_board/InitMission.cpp +++ b/bsp_linux_board/InitMission.cpp @@ -81,37 +81,31 @@ void initmission::initTasks() { #if OBSW_ADD_SCEX == 1 PeriodicTaskIF* scexDevHandler = factory->createPeriodicTask( "SCEX_DEV", 35, PeriodicTaskIF::MINIMUM_STACK_SIZE * 2, 0.5, missedDeadlineFunc); - result = tmtcPollingTask->addComponent(objects::SCEX, DeviceHandlerIF::PERFORM_OPERATION); + result = scexDevHandler->addComponent(objects::SCEX, DeviceHandlerIF::PERFORM_OPERATION); if (result != HasReturnvaluesIF::RETURN_OK) { initmission::printAddObjectError("SCEX_DEV", objects::SCEX); } - result = tmtcPollingTask->addComponent(objects::SCEX, DeviceHandlerIF::SEND_WRITE); + result = scexDevHandler->addComponent(objects::SCEX, DeviceHandlerIF::SEND_WRITE); if (result != HasReturnvaluesIF::RETURN_OK) { initmission::printAddObjectError("SCEX_DEV", objects::SCEX); } - result = tmtcPollingTask->addComponent(objects::SCEX, DeviceHandlerIF::GET_WRITE); + result = scexDevHandler->addComponent(objects::SCEX, DeviceHandlerIF::GET_WRITE); if (result != HasReturnvaluesIF::RETURN_OK) { initmission::printAddObjectError("SCEX_DEV", objects::SCEX); } - result = tmtcPollingTask->addComponent(objects::SCEX, DeviceHandlerIF::SEND_READ); + result = scexDevHandler->addComponent(objects::SCEX, DeviceHandlerIF::SEND_READ); if (result != HasReturnvaluesIF::RETURN_OK) { initmission::printAddObjectError("SCEX_DEV", objects::SCEX); } - result = tmtcPollingTask->addComponent(objects::SCEX, DeviceHandlerIF::GET_READ); -#endif + result = scexDevHandler->addComponent(objects::SCEX, DeviceHandlerIF::GET_READ); -#if OBSW_ADD_SCEX_READER == 1 result = HasReturnvaluesIF::RETURN_OK; - PeriodicTaskIF* scexReaderTask = factory->createPeriodicTask( - "SCEX_UART_READER", 20, PeriodicTaskIF::MINIMUM_STACK_SIZE, 2.0, missedDeadlineFunc); - result = scexReaderTask->addComponent(objects::SCEX_UART_READER); - if (result != HasReturnvaluesIF::RETURN_OK) { - initmission::printAddObjectError("SCEX_UART_READER", objects::SCEX_UART_READER); - } - sif::info << "Starting tasks.." << std::endl; - tmTcDistributor->startTask(); - tmtcBridgeTask->startTask(); - tmtcPollingTask->startTask(); + PeriodicTaskIF* scexReaderTask = factory->createPeriodicTask( + "SCEX_UART_READER", 20, PeriodicTaskIF::MINIMUM_STACK_SIZE, 2.0, missedDeadlineFunc); + result = scexReaderTask->addComponent(objects::SCEX_UART_READER); + if (result != HasReturnvaluesIF::RETURN_OK) { + initmission::printAddObjectError("SCEX_UART_READER", objects::SCEX_UART_READER); + } #endif /* PUS Services */ @@ -148,6 +142,7 @@ void initmission::initTasks() { #if OBSW_ADD_SCEX == 1 scexDevHandler->startTask(); + scexReaderTask->startTask(); #endif #if OBSW_ADD_TEST_PST == 1 if (startTestPst) { @@ -235,9 +230,12 @@ void initmission::createPstTasks(TaskFactory& factory, "SPI_PST", 70, PeriodicTaskIF::MINIMUM_STACK_SIZE * 4, 1.0, missedDeadlineFunc); result = pst::pstSpi(spiPst); if (result != HasReturnvaluesIF::RETURN_OK) { - sif::error << "InitMission::initTasks: Creating PST failed!" << std::endl; + if (result != FixedTimeslotTaskIF::SLOT_LIST_EMPTY) { + sif::error << "InitMission::initTasks: Creating PST failed!" << std::endl; + } + } else { + taskVec.push_back(spiPst); } - taskVec.push_back(spiPst); #endif } diff --git a/common/config/devConf.h b/common/config/devConf.h index 51da9011..68a3e199 100644 --- a/common/config/devConf.h +++ b/common/config/devConf.h @@ -55,6 +55,7 @@ namespace uart { static constexpr size_t HYPERION_GPS_REPLY_MAX_BUFFER = 1024; static constexpr UartBaudRate SYRLINKS_BAUD = UartBaudRate::RATE_38400; +static constexpr UartBaudRate SCEX_BAUD = UartBaudRate::RATE_57600; static constexpr UartBaudRate GNSS_BAUD = UartBaudRate::RATE_9600; static constexpr UartBaudRate PLOC_MPSOC_BAUD = UartBaudRate::RATE_115200; static constexpr UartBaudRate PLOC_SUPV_BAUD = UartBaudRate::RATE_115200; diff --git a/fsfw b/fsfw index ebbe0863..1910a783 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit ebbe08639caae43667829d2cc2bcbdf91260e175 +Subproject commit 1910a7838c712f1cf34031d2a8b53e2f7cd24f66 diff --git a/linux/ObjectFactory.cpp b/linux/ObjectFactory.cpp index bb8b183f..6424dd00 100644 --- a/linux/ObjectFactory.cpp +++ b/linux/ObjectFactory.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -323,10 +324,11 @@ void ObjectFactory::createRtdComponents(std::string spiDev, GpioIF* gpioComIF, void ObjectFactory::createScexComponents(std::string uartDev, PowerSwitchIF* pwrSwitcher) { // objekte anlegen SdCardMountedIF* sdcMan = nullptr; - CookieIF* cookie = new CookieIF; + auto* cookie = new UartCookie(objects::SCEX, uartDev, uart::SCEX_BAUD, 4096); auto scexUartReader = new ScexUartReader(objects::SCEX_UART_READER); - new ScexDeviceHandler(objects::SCEX, *scexUartReader, cookie, sdcMan); + auto scexHandler = new ScexDeviceHandler(objects::SCEX, *scexUartReader, cookie, sdcMan); + scexHandler->setStartUpImmediately(); } void ObjectFactory::gpioChecker(ReturnValue_t result, std::string output) { diff --git a/linux/devices/ScexDleParser.h b/linux/devices/ScexDleParser.h index ef87abb7..a8b04ca7 100644 --- a/linux/devices/ScexDleParser.h +++ b/linux/devices/ScexDleParser.h @@ -1,5 +1,4 @@ -#ifndef LINUX_DEVICES_SCEXDLEPARSER_H_ -#define LINUX_DEVICES_SCEXDLEPARSER_H_ +#pragma once #include @@ -16,5 +15,3 @@ class ScexDleParser : public DleParser { private: }; - -#endif /* LINUX_DEVICES_SCEXDLEPARSER_H_ */ diff --git a/linux/devices/ScexUartReader.cpp b/linux/devices/ScexUartReader.cpp index a33040a8..f7a65f12 100644 --- a/linux/devices/ScexUartReader.cpp +++ b/linux/devices/ScexUartReader.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include // write(), read(), close() #include // Error integer and strerror() function @@ -21,7 +20,7 @@ ScexUartReader::ScexUartReader(object_id_t objectId) ipcRingBuf(200 * 2048, true), ipcQueue(200), dleParser(decodeRingBuf, dleEncoder, {encodedBuf.data(), encodedBuf.size()}, - {decodedBuf.data(), decodedBuf.size()}, &foundDlePacketHandler, this) { + {decodedBuf.data(), decodedBuf.size()}, &foundDlePacketHandler, (void *)this) { semaphore = SemaphoreFactory::instance()->createBinarySemaphore(); semaphore->acquire(); lock = MutexFactory::instance()->createMutex(); @@ -80,8 +79,8 @@ ReturnValue_t ScexUartReader::initializeInterface(CookieIF *cookie) { /* 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; + sif::warning << "ScexUartReader::initializeInterface: open call failed with error [" << errno + << ", " << strerror(errno) << std::endl; return HasReturnvaluesIF::RETURN_FAILED; } // Setting up UART parameters @@ -107,8 +106,8 @@ ReturnValue_t ScexUartReader::initializeInterface(CookieIF *cookie) { #endif if (tcsetattr(serialPort, TCSANOW, &tty) != 0) { - sif::warning << "tcsetattr call failed with error [" << errno << ", " << strerror(errno) - << std::endl; + sif::warning << "ScexUartReader::initializeInterface: tcsetattr call failed with error [" + << errno << ", " << strerror(errno) << std::endl; } // Flush received and unread data tcflush(serialPort, TCIOFLUSH); @@ -117,6 +116,9 @@ ReturnValue_t ScexUartReader::initializeInterface(CookieIF *cookie) { ReturnValue_t ScexUartReader::sendMessage(CookieIF *cookie, const uint8_t *sendData, size_t sendLen) { + if (sendData == nullptr or sendLen == 0) { + return HasReturnvaluesIF::RETURN_FAILED; + } lock->lockMutex(); if (state == States::NOT_READY or state == States::RUNNING) { lock->unlockMutex(); @@ -128,17 +130,18 @@ ReturnValue_t ScexUartReader::sendMessage(CookieIF *cookie, const uint8_t *sendD ReturnValue_t result = dleEncoder.encode(sendData, sendLen, cmdbuf.data(), cmdbuf.size(), &encodedLen, true); if (result != HasReturnvaluesIF::RETURN_OK) { - sif::warning << "UartTestClass::scexInit: Encoding failed" << std::endl; + sif::warning << "ScexUartReader::sendMessage: Encoding failed" << std::endl; return RETURN_FAILED; } size_t bytesWritten = write(serialPort, cmdbuf.data(), encodedLen); if (bytesWritten != encodedLen) { - sif::warning << "Sending ping command to solar experiment failed" << std::endl; + sif::warning << "ScexUartReader::sendMessage: Sending ping command to solar experiment failed" + << std::endl; return RETURN_FAILED; } result = semaphore->release(); if (result != HasReturnvaluesIF::RETURN_OK) { - std::cout << "ScexUartReader::sendMessag: Releasing semaphore failed" << std::endl; + std::cout << "ScexUartReader::sendMessage: Releasing semaphore failed" << std::endl; } return RETURN_OK; } @@ -160,12 +163,12 @@ ReturnValue_t ScexUartReader::finish() { return RETURN_OK; } -void ScexUartReader::foundDlePacketHandler(const DleParser::Context &ctx) { +void ScexUartReader::foundDlePacketHandler(const ScexDleParser::Context &ctx) { ScexUartReader *obj = reinterpret_cast(ctx.userArgs); - if (ctx.getType() == DleParser::ContextType::PACKET_FOUND) { + if (ctx.getType() == ScexDleParser::ContextType::PACKET_FOUND) { obj->handleFoundDlePacket(ctx.decodedPacket.first, ctx.decodedPacket.second); } else { - DleParser::defaultErrorHandler(ctx.error.first, ctx.error.second); + ScexDleParser::defaultErrorHandler(ctx.error.first, ctx.error.second); } } @@ -175,11 +178,11 @@ void ScexUartReader::handleFoundDlePacket(uint8_t *packet, size_t len) { MutexGuard mg(lock); ReturnValue_t result = ipcQueue.insert(len); if (result != RETURN_OK) { - sif::warning << "IPCQueue error" << std::endl; + sif::warning << "ScexUartReader::handleFoundDlePacket: IPCQueue error" << std::endl; } result = ipcRingBuf.writeData(packet, len); if (result != RETURN_OK) { - sif::warning << "IPCRingBuf error" << std::endl; + sif::warning << "ScexUartReader::handleFoundDlePacket: IPCRingBuf error" << std::endl; } // sif::info << "DLE handler done" << std::endl; } diff --git a/linux/devices/ScexUartReader.h b/linux/devices/ScexUartReader.h index 4abbfd86..bdce5b65 100644 --- a/linux/devices/ScexUartReader.h +++ b/linux/devices/ScexUartReader.h @@ -1,5 +1,4 @@ -#ifndef LINUX_DEVICES_SCEXUARTREADER_H_ -#define LINUX_DEVICES_SCEXUARTREADER_H_ +#pragma once #include #include @@ -58,5 +57,3 @@ class ScexUartReader : public SystemObject, // strg+shift+n ReturnValue_t requestReceiveMessage(CookieIF *cookie, size_t requestLen) override; ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) override; }; - -#endif /* LINUX_DEVICES_SCEXUARTREADER_H_ */ diff --git a/mission/devices/CMakeLists.txt b/mission/devices/CMakeLists.txt index 3efb68ab..56184ea4 100644 --- a/mission/devices/CMakeLists.txt +++ b/mission/devices/CMakeLists.txt @@ -21,3 +21,5 @@ target_sources( PayloadPcduHandler.cpp SolarArrayDeploymentHandler.cpp ScexDeviceHandler.cpp) + +add_subdirectory(devicedefinitions) diff --git a/mission/devices/ScexDeviceHandler.cpp b/mission/devices/ScexDeviceHandler.cpp index f732447f..be280365 100644 --- a/mission/devices/ScexDeviceHandler.cpp +++ b/mission/devices/ScexDeviceHandler.cpp @@ -14,7 +14,7 @@ using std::ofstream; ScexDeviceHandler::ScexDeviceHandler(object_id_t objectId, ScexUartReader& reader, CookieIF* cookie, SdCardMountedIF* sdcMan) - : DeviceHandlerBase(objectId, reader.getObjectId(), cookie), reader(reader), sdcMan(sdcMan) {} + : DeviceHandlerBase(objectId, reader.getObjectId(), cookie), sdcMan(sdcMan), reader(reader) {} ScexDeviceHandler::~ScexDeviceHandler() {} @@ -42,48 +42,52 @@ ReturnValue_t ScexDeviceHandler::buildCommandFromCommand(DeviceCommandId_t devic if (std::find(VALID_CMDS.begin(), VALID_CMDS.end(), deviceCommand) == VALID_CMDS.end()) { return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; } - if (commandDataLen < 1) { - return DeviceHandlerIF::INVALID_COMMAND_PARAMETER; + bool tempCheck = false; + if (commandDataLen == 1) { + tempCheck = commandData[0]; } switch (deviceCommand) { case (PING): { - // rawPacket = cmdBuf.data(); - prepareScexCmd(cmdTyped, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, - {nullptr, 0}); - return RETURN_OK; + prepareScexCmd(cmdTyped, {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, {nullptr, 0}, + tempCheck); + break; } case (EXP_STATUS_CMD): { - prepareScexCmd(cmdTyped, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, - {nullptr, 0}); - return RETURN_OK; + prepareScexCmd(cmdTyped, {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, {nullptr, 0}, + tempCheck); + break; } case (ION_CMD): { - prepareScexCmd(cmdTyped, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, - {nullptr, 0}); - return RETURN_OK; + prepareScexCmd(cmdTyped, {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, {nullptr, 0}, + tempCheck); + break; } case (TEMP_CMD): { - prepareScexCmd(cmdTyped, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, - {nullptr, 0}); - return RETURN_OK; + prepareScexCmd(cmdTyped, {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, {nullptr, 0}, + tempCheck); + break; } case (FRAM): { - prepareScexCmd(cmdTyped, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, - {commandData + 1, commandDataLen - 1}); - return RETURN_OK; + prepareScexCmd(cmdTyped, {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, + {commandData + 1, commandDataLen - 1}, tempCheck); + break; } case (ONE_CELL): { - prepareScexCmd(cmdTyped, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, - {commandData + 1, commandDataLen - 1}); - return RETURN_OK; + prepareScexCmd(cmdTyped, {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, + {commandData + 1, commandDataLen - 1}, tempCheck); + break; } case (ALL_CELLS_CMD): { - prepareScexCmd(cmdTyped, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, - {commandData + 1, commandDataLen - 1}); - return RETURN_OK; + prepareScexCmd(cmdTyped, {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, + {commandData + 1, commandDataLen - 1}, tempCheck); + break; + } + default: { + return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; } } + rawPacket = cmdBuf.data(); return RETURN_OK; } diff --git a/mission/devices/ScexDeviceHandler.h b/mission/devices/ScexDeviceHandler.h index a719fc49..ad549e68 100644 --- a/mission/devices/ScexDeviceHandler.h +++ b/mission/devices/ScexDeviceHandler.h @@ -9,7 +9,6 @@ class SdCardMountedIF; class ScexDeviceHandler : public DeviceHandlerBase { public: - // ctor vervollständigen ScexDeviceHandler(object_id_t objectId, ScexUartReader &reader, CookieIF *cookie, SdCardMountedIF *sdcMan); virtual ~ScexDeviceHandler(); diff --git a/mission/devices/devicedefinitions/ScexDefinitions.cpp b/mission/devices/devicedefinitions/ScexDefinitions.cpp index 68bf0d76..8685862e 100644 --- a/mission/devices/devicedefinitions/ScexDefinitions.cpp +++ b/mission/devices/devicedefinitions/ScexDefinitions.cpp @@ -8,8 +8,8 @@ uint8_t scex::createCmdByte(Cmds cmd, bool tempCheck) { return (IDLE_BIT_0_DEF_STATE << 7) | (IDLE_BIT_1_DEF_STATE << 6) | (cmd << 1) | tempCheck; } -ReturnValue_t scex::prepareScexCmd(Cmds cmd, bool tempCheck, std::pair cmdBufPair, - size_t& cmdLen, std::pair usrDataPair) { +ReturnValue_t scex::prepareScexCmd(Cmds cmd, std::pair cmdBufPair, size_t& cmdLen, + std::pair usrDataPair, bool tempCheck) { using namespace scex; uint8_t* cmdBuf = cmdBufPair.first; const uint8_t* userData = usrDataPair.first; diff --git a/mission/devices/devicedefinitions/ScexDefinitions.h b/mission/devices/devicedefinitions/ScexDefinitions.h index 55264f3e..685f0cc0 100644 --- a/mission/devices/devicedefinitions/ScexDefinitions.h +++ b/mission/devices/devicedefinitions/ScexDefinitions.h @@ -38,10 +38,10 @@ static constexpr uint8_t CRC_LEN = 2; static constexpr uint8_t IDLE_BIT_0_DEF_STATE = 0; static constexpr uint8_t IDLE_BIT_1_DEF_STATE = 1; -uint8_t createCmdByte(Cmds cmd, bool tempCheck); +uint8_t createCmdByte(Cmds cmd, bool tempCheck = false); -ReturnValue_t prepareScexCmd(Cmds cmd, bool tempCheck, std::pair cmdBufPair, - size_t& cmdLen, std::pair usrDataPair); +ReturnValue_t prepareScexCmd(Cmds cmd, std::pair cmdBufPair, size_t& cmdLen, + std::pair usrDataPair, bool tempCheck = false); } // namespace scex diff --git a/scripts/rpi-port.sh b/scripts/rpi-port.sh index 5801fb50..e8832c89 100755 --- a/scripts/rpi-port.sh +++ b/scripts/rpi-port.sh @@ -1,8 +1,10 @@ #!/bin/bash echo "-L 1538:raspberrypi.local:1538 for Raspberry Pi connect with TCF agent" echo "-L 1539:raspberrypi.local:22 for Raspberry Pi file transfers" +echo "-L 7301:raspberrypi.local:7301 for Raspberry Pi TMTC Commands" ssh -L 1538:raspberrypi.local:1534 \ -L 1539:raspberrypi.local:22 \ - eive@2001:7c0:2018:1099:babe:0:e1fe:f1a5 \ + -L 7301:raspberrypi.local:7301 \ + eive@2001:7c0:2018:1099:babe:0:e1fe:f1a5 \ -t 'CONSOLE_PREFIX="[RPi Tunnel]" /bin/bash' diff --git a/tmtc b/tmtc index ef349856..7012a6c4 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit ef349856d614be7a408ffadf0c27c677d8be3157 +Subproject commit 7012a6c41f6e211c060f583c21061fe7ca3f4c45