From a6582313f74e352b90a2702f901903f61dcd1643 Mon Sep 17 00:00:00 2001 From: Irini Kosmidou Date: Tue, 30 Aug 2022 18:36:00 +0200 Subject: [PATCH] writing file works now --- bsp_linux_board/InitMission.cpp | 16 +++--- bsp_linux_board/ObjectFactory.cpp | 7 +-- linux/devices/ScexUartReader.cpp | 1 - mission/devices/ScexDeviceHandler.cpp | 72 +++++++++++++++------------ mission/devices/ScexDeviceHandler.h | 3 +- tmtc | 2 +- 6 files changed, 52 insertions(+), 49 deletions(-) diff --git a/bsp_linux_board/InitMission.cpp b/bsp_linux_board/InitMission.cpp index d009030b..c79af477 100644 --- a/bsp_linux_board/InitMission.cpp +++ b/bsp_linux_board/InitMission.cpp @@ -82,28 +82,28 @@ void initmission::initTasks() { PeriodicTaskIF* scexDevHandler = factory->createPeriodicTask( "SCEX_DEV", 35, PeriodicTaskIF::MINIMUM_STACK_SIZE * 2, 0.5, missedDeadlineFunc); result = scexDevHandler->addComponent(objects::SCEX, DeviceHandlerIF::PERFORM_OPERATION); - if (result != HasReturnvaluesIF::RETURN_OK) { + if (result != returnvalue::OK) { initmission::printAddObjectError("SCEX_DEV", objects::SCEX); } result = scexDevHandler->addComponent(objects::SCEX, DeviceHandlerIF::SEND_WRITE); - if (result != HasReturnvaluesIF::RETURN_OK) { + if (result != returnvalue::OK) { initmission::printAddObjectError("SCEX_DEV", objects::SCEX); } result = scexDevHandler->addComponent(objects::SCEX, DeviceHandlerIF::GET_WRITE); - if (result != HasReturnvaluesIF::RETURN_OK) { + if (result != returnvalue::OK) { initmission::printAddObjectError("SCEX_DEV", objects::SCEX); } result = scexDevHandler->addComponent(objects::SCEX, DeviceHandlerIF::SEND_READ); - if (result != HasReturnvaluesIF::RETURN_OK) { + if (result != returnvalue::OK) { initmission::printAddObjectError("SCEX_DEV", objects::SCEX); } result = scexDevHandler->addComponent(objects::SCEX, DeviceHandlerIF::GET_READ); - result = HasReturnvaluesIF::RETURN_OK; + result = returnvalue::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) { + if (result != returnvalue::OK) { initmission::printAddObjectError("SCEX_UART_READER", objects::SCEX_UART_READER); } #endif @@ -229,7 +229,7 @@ void initmission::createPstTasks(TaskFactory& factory, FixedTimeslotTaskIF* spiPst = factory.createFixedTimeslotTask( "SPI_PST", 70, PeriodicTaskIF::MINIMUM_STACK_SIZE * 4, 1.0, missedDeadlineFunc); result = pst::pstSpi(spiPst); - if (result != HasReturnvaluesIF::RETURN_OK) { + if (result != returnvalue::OK) { if (result != FixedTimeslotTaskIF::SLOT_LIST_EMPTY) { sif::error << "InitMission::createPstTasks: Creating PST failed!" << std::endl; } @@ -269,7 +269,7 @@ void initmission::createTestTasks(TaskFactory& factory, 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) { + if (result != returnvalue::OK) { initmission::printAddObjectError("SCEX_UART_READER", objects::SCEX_UART_READER); } taskVec.push_back(scexReaderTask); diff --git a/bsp_linux_board/ObjectFactory.cpp b/bsp_linux_board/ObjectFactory.cpp index 19a00647..2804591b 100644 --- a/bsp_linux_board/ObjectFactory.cpp +++ b/bsp_linux_board/ObjectFactory.cpp @@ -47,8 +47,8 @@ #include "fsfw_hal/linux/spi/SpiCookie.h" void Factory::setStaticFrameworkObjectIds() { - PusServiceBase::packetSource = objects::PUS_PACKET_DISTRIBUTOR; - PusServiceBase::packetDestination = objects::TM_FUNNEL; + PusServiceBase::PUS_DISTRIBUTOR = objects::PUS_PACKET_DISTRIBUTOR; + PusServiceBase::PACKET_DESTINATION = objects::TM_FUNNEL; CommandingServiceBase::defaultPacketSource = objects::PUS_PACKET_DISTRIBUTOR; CommandingServiceBase::defaultPacketDestination = objects::TM_FUNNEL; @@ -56,9 +56,6 @@ void Factory::setStaticFrameworkObjectIds() { TmFunnel::downlinkDestination = objects::TMTC_BRIDGE; // No storage object for now. TmFunnel::storageDestination = objects::NO_OBJECT; - - VerificationReporter::messageReceiver = objects::PUS_SERVICE_1_VERIFICATION; - TmPacketBase::timeStamperId = objects::TIME_STAMPER; } void ObjectFactory::produce(void* args) { diff --git a/linux/devices/ScexUartReader.cpp b/linux/devices/ScexUartReader.cpp index 84a7d7cc..f1d0d037 100644 --- a/linux/devices/ScexUartReader.cpp +++ b/linux/devices/ScexUartReader.cpp @@ -135,7 +135,6 @@ ReturnValue_t ScexUartReader::sendMessage(CookieIF *cookie, const uint8_t *sendD sif::warning << "ScexUartReader::sendMessage: Encoding failed" << std::endl; return FAILED; } - arrayprinter::print(cmdbuf.data(), encodedLen); size_t bytesWritten = write(serialPort, cmdbuf.data(), encodedLen); if (bytesWritten != encodedLen) { sif::warning << "ScexUartReader::sendMessage: Sending ping command to solar experiment failed" diff --git a/mission/devices/ScexDeviceHandler.cpp b/mission/devices/ScexDeviceHandler.cpp index b5f55a69..6432bcea 100644 --- a/mission/devices/ScexDeviceHandler.cpp +++ b/mission/devices/ScexDeviceHandler.cpp @@ -126,7 +126,6 @@ void ScexDeviceHandler::fillCommandAndReplyMap() { insertInCommandAndReplyMap(scex::Cmds::TEMP_CMD, 3); insertInCommandAndReplyMap(scex::Cmds::EXP_STATUS_CMD, 3); - // TODO: Prüfen: richtige Variablen? insertInCommandAndReplyMap(scex::Cmds::ALL_CELLS_CMD, 0, nullptr, 0, false, false, scex::Cmds::ALL_CELLS_CMD, &finishCountdown); insertInCommandAndReplyMap(scex::Cmds::ONE_CELL, 0, nullptr, 0, false, false, @@ -141,28 +140,29 @@ ReturnValue_t ScexDeviceHandler::scanForReply(const uint8_t* start, size_t remai DeviceCommandId_t* foundId, size_t* foundLen) { size_t len = remainingSize; ReturnValue_t result = helper.deSerialize(&start, &len); - bool commandFound = false; if (result == ScexHelper::INVALID_CRC) { sif::warning << "ScexDeviceHandler::scanForReply: CRC invalid" << std::endl; - } else { - *foundId = helper.getCmd(); - commandFound = true; *foundLen = remainingSize; + } else { + result = handleValidReply(remainingSize, foundId, foundLen); } - - if (commandFound) { - uint32_t remainingMillis = finishCountdown.getRemainingMillis(); - if (commandActive and finishCountdown.hasTimedOut()) { - triggerEvent(scex::EXPERIMENT_TIMEDOUT, currCmd, 0); - reader.finish(); - sif::warning << "ScexDeviceHandler::performOperationHook: Reader timeout; RemMillis: " - << remainingMillis << std::endl; - fileNameSet = false; - commandActive = false; - } + uint32_t remainingMillis = finishCountdown.getRemainingMillis(); + if (commandActive and finishCountdown.hasTimedOut()) { + triggerEvent(scex::EXPERIMENT_TIMEDOUT, currCmd, 0); + reader.finish(); + sif::warning << "ScexDeviceHandler::performOperationHook: Reader timeout; RemMillis: " + << remainingMillis << std::endl; + fileNameSet = false; + commandActive = false; } + return result; +} +ReturnValue_t ScexDeviceHandler::handleValidReply(size_t remSize, DeviceCommandId_t* foundId, + size_t* foundLen) { + using namespace scex; + ReturnValue_t result = OK; auto multiFileHandler = [&](std::string cmdName) { if ((helper.getPacketCounter() == 1) or (not fileNameSet)) { fileId = random_string(6); @@ -171,27 +171,28 @@ ReturnValue_t ScexDeviceHandler::scanForReply(const uint8_t* start, size_t remai fileName = oss.str(); fileNameSet = true; ofstream out(fileName, ofstream::binary); - if (debugMode) { - uint32_t remainingMillis = finishCountdown.getRemainingMillis(); - sif::info << "ScexDeviceHandler::interpretDeviceReply:MultifileHandler: RemMillis: " - << remainingMillis << std::endl; - } if (out.bad()) { sif::error << "ScexDeviceHandler::interpretDeviceReply: Could not open file " << fileName << std::endl; return FAILED; } + out << helper; } else { ofstream out(fileName, ofstream::binary | ofstream::app); // append - if (debugMode) { - out << helper; + if (out.bad()) { + sif::error << "ScexDeviceHandler::interpretDeviceReply: Could not open file " << fileName + << std::endl; + return FAILED; } + out << helper; } - - return OK; + if (helper.getPacketCounter() == helper.getTotalPacketCounter()) { + *foundId = helper.getCmd(); + return OK; + } + return IGNORE_FULL_PACKET; }; - ReturnValue_t status = OK; switch (helper.getCmd()) { case (FRAM): { if (debugMode) { @@ -200,18 +201,23 @@ ReturnValue_t ScexDeviceHandler::scanForReply(const uint8_t* start, size_t remai sif::info << "ScexDeviceHandler::interpretDeviceReply: RemMillis: " << remainingMillis << std::endl; } - status = multiFileHandler("fram_"); + result = multiFileHandler("fram_"); break; } case (ONE_CELL): { - status = multiFileHandler("one_cell_"); + result = multiFileHandler("one_cell_"); break; } case (ALL_CELLS_CMD): { - status = multiFileHandler("all_cell_"); + result = multiFileHandler("all_cell_"); + break; + } + default: { + *foundId = helper.getCmd(); break; } } + *foundLen = remSize; return result; } @@ -225,16 +231,13 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons std::ostringstream oss("/tmp/scex-", std::ostringstream::ate); oss << cmdName << fileId << ".bin"; fileName = oss.str(); - std::cout << fileName << std::endl; ofstream out(fileName, ofstream::binary); if (out.bad()) { sif::error << "ScexDeviceHandler::interpretDeviceReply: Could not open file " << fileName << std::endl; return FAILED; } - if (debugMode) { - out << helper; - } + out << helper; return OK; }; @@ -258,6 +261,9 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons default: // Unknown DeviceCommand + if(id == FRAM or id == ONE_CELL or id == ALL_CELLS_CMD) { + break; + } return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; } if (helper.getPacketCounter() == helper.getTotalPacketCounter()) { diff --git a/mission/devices/ScexDeviceHandler.h b/mission/devices/ScexDeviceHandler.h index eeaac755..69436e0b 100644 --- a/mission/devices/ScexDeviceHandler.h +++ b/mission/devices/ScexDeviceHandler.h @@ -22,7 +22,7 @@ class ScexDeviceHandler : public DeviceHandlerBase { std::string fileName = ""; bool fileNameSet = false; bool commandActive = false; - bool debugMode = true; + bool debugMode = false; scex::Cmds currCmd = scex::Cmds::PING; SdCardMountedIF *sdcMan = nullptr; @@ -45,6 +45,7 @@ class ScexDeviceHandler : public DeviceHandlerBase { ReturnValue_t scanForReply(const uint8_t *start, size_t remainingSize, DeviceCommandId_t *foundId, size_t *foundLen) override; ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) override; + ReturnValue_t handleValidReply(size_t remSize, DeviceCommandId_t *foundId, size_t *foundLen); uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override; ReturnValue_t getSwitches(const uint8_t **switches, uint8_t *numberOfSwitches) override; diff --git a/tmtc b/tmtc index b1eafd92..b4d4a511 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit b1eafd92c202385731a990d3bdba36c48267d63a +Subproject commit b4d4a51164af69a22eedd645775061dbb51702b1