From ea2b1fbda487e5ca6f5d32660475ea59f73b0e02 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Tue, 27 Apr 2021 17:34:50 +0200 Subject: [PATCH] basic structure for ILH PLOC control --- bsp_q7s/ObjectFactory.cpp | 15 +++++++++------ fsfwconfig/OBSWConfig.h | 3 ++- mission/devices/PlocHandler.cpp | 17 ++++++++++------- mission/devices/PlocHandler.h | 20 ++++++++++++-------- 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 9102f79e..0815b81d 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -433,12 +433,6 @@ void ObjectFactory::produce(){ gpioCookie->addGpio(gpioIds::TEST_ID_0, gpioConfigMio0); new LibgpiodTest(objects::LIBGPIOD_TEST, objects::GPIO_IF, gpioCookie); #elif TE0720 == 1 - /* Configuration for MIO0 on TE0720-03-1CFA */ - GpiodRegular* heaterGpio = new GpiodRegular(std::string("gpiochip0"), 0, std::string("MIO0"), gpio::IN, 0); - GpioCookie* gpioCookie = new GpioCookie; - gpioCookie->addGpio(gpioIds::HEATER_0, heaterGpio); - new HeaterHandler(objects::HEATER_HANDLER, objects::GPIO_IF, gpioCookie, objects::PCDU_HANDLER, - pcduSwitches::TCS_BOARD_8V_HEATER_IN); UartCookie* plocUartCookie = new UartCookie(std::string("/dev/ttyPS1"), 115200, PLOC::MAX_REPLY_SIZE); @@ -448,6 +442,15 @@ void ObjectFactory::produce(){ plocHandler->setStartUpImmediately(); #endif +#if TE0720 == 1 && TE0720_HEATER_TEST == 1 + /* Configuration for MIO0 on TE0720-03-1CFA */ + GpiodRegular* heaterGpio = new GpiodRegular(std::string("gpiochip0"), 0, std::string("MIO0"), gpio::IN, 0); + GpioCookie* gpioCookie = new GpioCookie; + gpioCookie->addGpio(gpioIds::HEATER_0, heaterGpio); + new HeaterHandler(objects::HEATER_HANDLER, objects::GPIO_IF, gpioCookie, objects::PCDU_HANDLER, + pcduSwitches::TCS_BOARD_8V_HEATER_IN); +#endif + #if Q7S_ADD_SPI_TEST == 1 new SpiTestClass(objects::SPI_TEST, gpioComIF); #endif diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index f3f7cda3..c1a6c313 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -21,7 +21,8 @@ debugging. */ #define OBSW_ADD_TEST_CODE 1 #define TEST_LIBGPIOD 0 -#define TE0720 0 +#define TE0720 1 +#define TE0720_HEATER_TEST 0 #define P60DOCK_DEBUG 0 #define PDU1_DEBUG 0 diff --git a/mission/devices/PlocHandler.cpp b/mission/devices/PlocHandler.cpp index d8ed395e..b0660ba0 100644 --- a/mission/devices/PlocHandler.cpp +++ b/mission/devices/PlocHandler.cpp @@ -156,6 +156,7 @@ ReturnValue_t PlocHandler::prepareTcMemWriteCommand(const uint8_t * commandData, | *(commandData + 2) << 8 | *(commandData + 3); const uint32_t memoryData = *(commandData + 4) << 24 | *(commandData + 5) << 16 | *(commandData + 6) << 8 | *(commandData + 7); + packetSequenceCount = (packetSequenceCount + 1) & PACKET_SEQUENCE_COUNT_MASK; PLOC::TcMemWrite tcMemWrite(memoryAddress, memoryData, packetSequenceCount); if (tcMemWrite.getFullSize() > PLOC::MAX_COMMAND_SIZE) { sif::debug << "PlocHandler::prepareTcMemWriteCommand: Command too big" << std::endl; @@ -172,6 +173,7 @@ ReturnValue_t PlocHandler::prepareTcMemReadCommand(const uint8_t * commandData, size_t commandDataLen) { const uint32_t memoryAddress = *(commandData) << 24 | *(commandData + 1) << 16 | *(commandData + 2) << 8 | *(commandData + 3); + packetSequenceCount = (packetSequenceCount + 1) & PACKET_SEQUENCE_COUNT_MASK; PLOC::TcMemRead tcMemRead(memoryAddress, packetSequenceCount); if (tcMemRead.getFullSize() > PLOC::MAX_COMMAND_SIZE) { sif::debug << "PlocHandler::prepareTcMemReadCommand: Command too big" << std::endl; @@ -482,14 +484,15 @@ void PlocHandler::disableExeReportReply() { } ReturnValue_t PlocHandler::checkPacketSequenceCount(const uint8_t* data) { - uint16_t receivedSequenceCount = *(data + 2) << 8 | *(data + 3) & PACKET_SEQUENCE_COUNT_MASK; - if (receivedSequenceCount != ((packetSequenceCount + 1) & PACKET_SEQUENCE_COUNT_MASK)) { - sif::debug << "PlocHandler::checkPacketSequenceCount: Packet sequence count mismatch" + uint16_t receivedSequenceCount = (*(data + 2) << 8 | *(data + 3)) & PACKET_SEQUENCE_COUNT_MASK; + uint16_t expectedPacketSequenceCount = ((packetSequenceCount + 1) & PACKET_SEQUENCE_COUNT_MASK); + if (receivedSequenceCount != expectedPacketSequenceCount) { + sif::debug + << "PlocHandler::checkPacketSequenceCount: Packet sequence count mismatch. " << std::endl; - /** The packet sequence count is corrected here to match the sequence count of the PLOC */ - packetSequenceCount = (receivedSequenceCount + 1) & PACKET_SEQUENCE_COUNT_MASK; - return SUBSEQUENCE_COUNT_FAILURE; + sif::debug << "Received sequence count: " << receivedSequenceCount << ". OBSW sequence " + << "count: " << expectedPacketSequenceCount << std::endl; } - packetSequenceCount = (packetSequenceCount + 1) & PACKET_SEQUENCE_COUNT_MASK; + packetSequenceCount = receivedSequenceCount; return RETURN_OK; } diff --git a/mission/devices/PlocHandler.h b/mission/devices/PlocHandler.h index 1b529484..06965d0f 100644 --- a/mission/devices/PlocHandler.h +++ b/mission/devices/PlocHandler.h @@ -8,8 +8,8 @@ /** * @brief This is the device handler for the PLOC. * - * @details The PLOC uses the space packet protocol for communication. On each command the PLOC - * answers at least with one acknowledgment and one execution report. + * @details The PLOC uses the space packet protocol for communication. To each command the PLOC + * answers with at least one acknowledgment and one execution report. * * @author J. Meier */ @@ -53,7 +53,6 @@ private: static const ReturnValue_t RECEIVED_ACK_FAILURE = MAKE_RETURN_CODE(0xA1); //!> Received ACK failure reply from PLOC static const ReturnValue_t RECEIVED_EXE_FAILURE = MAKE_RETURN_CODE(0xA2); //!> Received execution failure reply from PLOC static const ReturnValue_t INVALID_APID = MAKE_RETURN_CODE(0xA3); //!> Received space packet with invalid APID from PLOC - static const ReturnValue_t SUBSEQUENCE_COUNT_FAILURE = MAKE_RETURN_CODE(0xA4); //!> The packet sequence count does not match the expected packet sequence count. There may be one packet lost. static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PLOC_HANDLER; @@ -63,7 +62,7 @@ private: static const Event CRC_FAILURE_EVENT = MAKE_EVENT(4, severity::LOW); //!> PLOC reply has invalid crc static const uint16_t APID_MASK = 0x7FF; - static const unit16_t PACKET_SEQUENCE_COUNT_MASK = 0x3FFF; + static const uint16_t PACKET_SEQUENCE_COUNT_MASK = 0x3FFF; uint8_t commandBuffer[PLOC::MAX_COMMAND_SIZE]; @@ -184,14 +183,19 @@ private: void disableExeReportReply(); /** - * @brief This function checks the subsequence count of a received space packet to detect - * lost packets. + * @brief This function checks and increments the packet sequence count of a received space + * packet. * * @param data Pointer to a space packet. * - * @return RETURN_OK if successful, else SUBSEQUENCE_COUNT_FAILURE + * @return RETURN_OK if successful + * + * @details There should be never a case in which a wrong packet sequence count is received + * because the communication scheme between PLOC and OBC always follows a strict + * procedure. Thus this function mainly serves for debugging purposes to detected an + * invalid handling of the packet sequence count. */ - ReturnValue_t checkSubsequenceCount(const uint8_t* data); + ReturnValue_t checkPacketSequenceCount(const uint8_t* data); }; #endif /* MISSION_DEVICES_PLOCHANDLER_H_ */