From 09299802f0cc4456c510f6d6dac3260b96c08777 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 28 Sep 2021 15:01:01 +0200 Subject: [PATCH 01/89] TCP refactoring This refactoring keeps the TCP connection opened until the client closes it. It also increased the robustness of the TCP reception. Because TCP is stream based and usually applied to newline separated data, a special way to handle binary space packets is required. The new SpacePacketParser class takes care of this by taking TC packet IDs as as optional start markers to parse for space packets in a given buffer. The refactored TCP server uses a ring buffer, a reception buffer and the new parser to extract space packets from a stream in a safer way. --- src/fsfw/osal/common/TcpTmTcServer.cpp | 229 ++++++++++++++++---- src/fsfw/osal/common/TcpTmTcServer.h | 68 ++++-- src/fsfw/tmtcpacket/SpacePacket.h | 109 +++++----- src/fsfw/tmtcservices/SpacePacketParser.cpp | 77 +++++++ src/fsfw/tmtcservices/SpacePacketParser.h | 96 ++++++++ 5 files changed, 473 insertions(+), 106 deletions(-) create mode 100644 src/fsfw/tmtcservices/SpacePacketParser.cpp create mode 100644 src/fsfw/tmtcservices/SpacePacketParser.h diff --git a/src/fsfw/osal/common/TcpTmTcServer.cpp b/src/fsfw/osal/common/TcpTmTcServer.cpp index 11ab71af..e320b46b 100644 --- a/src/fsfw/osal/common/TcpTmTcServer.cpp +++ b/src/fsfw/osal/common/TcpTmTcServer.cpp @@ -1,8 +1,11 @@ -#include "fsfw/osal/common/TcpTmTcServer.h" -#include "fsfw/osal/common/TcpTmTcBridge.h" -#include "fsfw/osal/common/tcpipHelpers.h" - #include "fsfw/platform.h" +#include "fsfw/FSFW.h" + +#include "TcpTmTcServer.h" +#include "TcpTmTcBridge.h" +#include "tcpipHelpers.h" + +#include "fsfw/tasks/TaskFactory.h" #include "fsfw/container/SharedRingBuffer.h" #include "fsfw/ipc/MessageQueueSenderIF.h" #include "fsfw/ipc/MutexGuard.h" @@ -17,6 +20,7 @@ #elif defined(PLATFORM_UNIX) #include #endif +#include #ifndef FSFW_TCP_RECV_WIRETAPPING_ENABLED #define FSFW_TCP_RECV_WIRETAPPING_ENABLED 0 @@ -25,12 +29,11 @@ const std::string TcpTmTcServer::DEFAULT_SERVER_PORT = tcpip::DEFAULT_SERVER_PORT; TcpTmTcServer::TcpTmTcServer(object_id_t objectId, object_id_t tmtcTcpBridge, - size_t receptionBufferSize, std::string customTcpServerPort): - SystemObject(objectId), tmtcBridgeId(tmtcTcpBridge), - tcpPort(customTcpServerPort), receptionBuffer(receptionBufferSize) { - if(tcpPort == "") { - tcpPort = DEFAULT_SERVER_PORT; - } + size_t receptionBufferSize, size_t ringBufferSize, std::string customTcpServerPort, + ReceptionModes receptionMode): + SystemObject(objectId), tmtcBridgeId(tmtcTcpBridge), receptionMode(receptionMode), + tcpConfig(customTcpServerPort), receptionBuffer(receptionBufferSize), + ringBuffer(ringBufferSize, true), validPacketIds() { } ReturnValue_t TcpTmTcServer::initialize() { @@ -41,6 +44,16 @@ ReturnValue_t TcpTmTcServer::initialize() { return result; } + switch(receptionMode) { + case(ReceptionModes::SPACE_PACKETS): { + spacePacketParser = new SpacePacketParser(validPacketIds); + if(spacePacketParser == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } + tcpConfig.tcpFlags |= MSG_DONTWAIT; + } + } + tcStore = ObjectManager::instance()->get(objects::TC_STORE); if (tcStore == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -63,7 +76,7 @@ ReturnValue_t TcpTmTcServer::initialize() { hints.ai_flags = AI_PASSIVE; // Listen to all addresses (0.0.0.0) by using AI_PASSIVE in the hint flags - retval = getaddrinfo(nullptr, tcpPort.c_str(), &hints, &addrResult); + retval = getaddrinfo(nullptr, tcpConfig.tcpPort.c_str(), &hints, &addrResult); if (retval != 0) { handleError(Protocol::TCP, ErrorSources::GETADDRINFO_CALL); return HasReturnvaluesIF::RETURN_FAILED; @@ -105,7 +118,7 @@ ReturnValue_t TcpTmTcServer::performOperation(uint8_t opCode) { // Listen for connection requests permanently for lifetime of program while(true) { - retval = listen(listenerTcpSocket, tcpBacklog); + retval = listen(listenerTcpSocket, tcpConfig.tcpBacklog); if(retval == SOCKET_ERROR) { handleError(Protocol::TCP, ErrorSources::LISTEN_CALL, 500); continue; @@ -123,11 +136,12 @@ ReturnValue_t TcpTmTcServer::performOperation(uint8_t opCode) { handleServerOperation(connSocket); // Done, shut down connection and go back to listening for client requests - retval = shutdown(connSocket, SHUT_SEND); + retval = shutdown(connSocket, SHUT_BOTH); if(retval != 0) { handleError(Protocol::TCP, ErrorSources::SHUTDOWN_CALL); } closeSocket(connSocket); + connSocket = 0; } return HasReturnvaluesIF::RETURN_OK; } @@ -144,51 +158,82 @@ ReturnValue_t TcpTmTcServer::initializeAfterTaskCreation() { return HasReturnvaluesIF::RETURN_OK; } -void TcpTmTcServer::handleServerOperation(socket_t connSocket) { - int retval = 0; - do { - // Read all telecommands sent by the client - retval = recv(connSocket, +void TcpTmTcServer::handleServerOperation(socket_t& connSocket) { + while (true) { + int retval = recv( + connSocket, reinterpret_cast(receptionBuffer.data()), receptionBuffer.capacity(), - tcpFlags); - if (retval > 0) { - handleTcReception(retval); + tcpConfig.tcpFlags + ); + if(retval == 0) { + // Client closed connection + return; } - else if(retval == 0) { - // Client has finished sending telecommands, send telemetry now - handleTmSending(connSocket); + else if(retval > 0) { + // The ring buffer was configured for overwrite, so the returnvalue does not need to + // be checked for now + ringBuffer.writeData(receptionBuffer.data(), retval); } - else { - // Should not happen - tcpip::handleError(tcpip::Protocol::TCP, tcpip::ErrorSources::RECV_CALL); + else if(retval < 0) { + if(errno == EAGAIN) { + // No data available. Check whether any packets have been read, then send back + // telemetry if available + bool tcAvailable = false; + bool tmSent = false; + size_t availableReadData = ringBuffer.getAvailableReadData(); + if(availableReadData > lastRingBufferSize) { + tcAvailable = true; + handleTcRingBufferData(availableReadData); + } + ReturnValue_t result = handleTmSending(connSocket, tmSent); + if(result == CONN_BROKEN) { + return; + } + if(not tcAvailable and not tmSent) { + TaskFactory::delayTask(DEFAULT_LOOP_DELAY_MS); + } + } + else { + tcpip::handleError(tcpip::Protocol::TCP, tcpip::ErrorSources::RECV_CALL); + } } - } while(retval > 0); + } } -ReturnValue_t TcpTmTcServer::handleTcReception(size_t bytesRecvd) { +ReturnValue_t TcpTmTcServer::handleTcReception(uint8_t* spacePacket, size_t packetSize) { #if FSFW_TCP_RECV_WIRETAPPING_ENABLED == 1 arrayprinter::print(receptionBuffer.data(), bytesRead); #endif + if(spacePacket == nullptr or packetSize == 0) { + return HasReturnvaluesIF::RETURN_FAILED; + } store_address_t storeId; - ReturnValue_t result = tcStore->addData(&storeId, receptionBuffer.data(), bytesRecvd); + ReturnValue_t result = tcStore->addData(&storeId, spacePacket, packetSize); if (result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning<< "TcpTmTcServer::handleServerOperation: Data storage failed." << std::endl; - sif::warning << "Packet size: " << bytesRecvd << std::endl; + sif::warning << "TcpTmTcServer::handleServerOperation: Data storage with packet size" << + packetSize << " failed" << std::endl; +#else + sif::printWarning("TcpTmTcServer::handleServerOperation: Data storage with packet size %d " + "failed\n", packetSize); #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ #endif /* FSFW_VERBOSE_LEVEL >= 1 */ + return result; } TmTcMessage message(storeId); - result = MessageQueueSenderIF::sendMessage(targetTcDestination, &message); + result = MessageQueueSenderIF::sendMessage(targetTcDestination, &message); if (result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "UdpTcPollingTask::handleSuccessfullTcRead: " + sif::warning << "TcpTmTcServer::handleServerOperation: " " Sending message to queue failed" << std::endl; +#else + sif::printWarning("TcpTmTcServer::handleServerOperation: " + " Sending message to queue failed\n"); #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ #endif /* FSFW_VERBOSE_LEVEL >= 1 */ tcStore->deleteData(storeId); @@ -196,21 +241,26 @@ ReturnValue_t TcpTmTcServer::handleTcReception(size_t bytesRecvd) { return result; } -void TcpTmTcServer::setTcpBacklog(uint8_t tcpBacklog) { - this->tcpBacklog = tcpBacklog; -} - std::string TcpTmTcServer::getTcpPort() const { - return tcpPort; + return tcpConfig.tcpPort; } -ReturnValue_t TcpTmTcServer::handleTmSending(socket_t connSocket) { +void TcpTmTcServer::setSpacePacketParsingOptions(std::vector validPacketIds) { + this->validPacketIds = validPacketIds; +} + +TcpTmTcServer::TcpConfig& TcpTmTcServer::getTcpConfigStruct() { + return tcpConfig; +} + +ReturnValue_t TcpTmTcServer::handleTmSending(socket_t connSocket, bool& tmSent) { // Access to the FIFO is mutex protected because it is filled by the bridge MutexGuard(tmtcBridge->mutex, tmtcBridge->timeoutType, tmtcBridge->mutexTimeoutMs); store_address_t storeId; while((not tmtcBridge->tmFifo->empty()) and (tmtcBridge->packetSentCounter < tmtcBridge->sentPacketsPerCycle)) { - tmtcBridge->tmFifo->retrieve(&storeId); + // Send can fail, so only peek from the FIFO + tmtcBridge->tmFifo->peek(&storeId); // Using the store accessor will take care of deleting TM from the store automatically ConstStorageAccessor storeAccessor(storeId); @@ -221,10 +271,101 @@ ReturnValue_t TcpTmTcServer::handleTmSending(socket_t connSocket) { int retval = send(connSocket, reinterpret_cast(storeAccessor.data()), storeAccessor.size(), - tcpTmFlags); - if(retval != static_cast(storeAccessor.size())) { - tcpip::handleError(tcpip::Protocol::TCP, tcpip::ErrorSources::SEND_CALL); + tcpConfig.tcpTmFlags); + if(retval == static_cast(storeAccessor.size())) { + // Packet sent, clear FIFO entry + tmtcBridge->tmFifo->pop(); + tmSent = true; + + } + else if(retval <= 0) { + // Assume that the client has closed the connection here for now + handleSocketError(storeAccessor); + return CONN_BROKEN; } } return HasReturnvaluesIF::RETURN_OK; } + +ReturnValue_t TcpTmTcServer::handleTcRingBufferData(size_t availableReadData) { + ReturnValue_t status = HasReturnvaluesIF::RETURN_OK; + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + size_t readAmount = availableReadData; + lastRingBufferSize = availableReadData; + if(readAmount >= ringBuffer.getMaxSize()) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + // Possible configuration error, too much data or/and data coming in too fast, + // requiring larger buffers + sif::warning << "TcpTmTcServer::handleServerOperation: Ring buffer reached " << + "fill count" << std::endl; +#else + sif::printWarning("TcpTmTcServer::handleServerOperation: Ring buffer reached " + "fill count"); +#endif +#endif + } + if(readAmount >= receptionBuffer.size()) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + // Possible configuration error, too much data or/and data coming in too fast, + // requiring larger buffers + sif::warning << "TcpTmTcServer::handleServerOperation: " + "Reception buffer too small " << std::endl; +#else + sif::printWarning("TcpTmTcServer::handleServerOperation: Reception buffer too small\n"); +#endif +#endif + readAmount = receptionBuffer.size(); + } + ringBuffer.readData(receptionBuffer.data(), readAmount, true); + const uint8_t* bufPtr = receptionBuffer.data(); + const uint8_t** bufPtrPtr = &bufPtr; + size_t startIdx = 0; + size_t foundSize = 0; + size_t readLen = 0; + while(readLen < readAmount) { + result = spacePacketParser->parseSpacePackets(bufPtrPtr, readAmount, + startIdx, foundSize, readLen); + switch(result) { + case(SpacePacketParser::NO_PACKET_FOUND): + case(SpacePacketParser::SPLIT_PACKET): { + break; + } + case(HasReturnvaluesIF::RETURN_OK): { + result = handleTcReception(receptionBuffer.data() + startIdx, foundSize); + if(result != HasReturnvaluesIF::RETURN_OK) { + status = result; + } + } + } + ringBuffer.deleteData(foundSize); + lastRingBufferSize = ringBuffer.getAvailableReadData(); + std::memset(receptionBuffer.data() + startIdx, 0, foundSize); + } + return status; +} + +void TcpTmTcServer::handleSocketError(ConstStorageAccessor &accessor) { + // Don't delete data + accessor.release(); + auto socketError = getLastSocketError(); + switch(socketError) { +#if defined PLATFORM_WIN + case(WSAECONNRESET): { + // See https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-send + // Remote client might have shut down connection + return; + } +#else + case(EPIPE): { + // See https://man7.org/linux/man-pages/man2/send.2.html + // Remote client might have shut down connection + return; + } +#endif + default: { + tcpip::handleError(tcpip::Protocol::TCP, tcpip::ErrorSources::SEND_CALL); + } + } +} diff --git a/src/fsfw/osal/common/TcpTmTcServer.h b/src/fsfw/osal/common/TcpTmTcServer.h index c6916080..a0a31655 100644 --- a/src/fsfw/osal/common/TcpTmTcServer.h +++ b/src/fsfw/osal/common/TcpTmTcServer.h @@ -1,11 +1,13 @@ #ifndef FSFW_OSAL_COMMON_TCP_TMTC_SERVER_H_ #define FSFW_OSAL_COMMON_TCP_TMTC_SERVER_H_ +#include #include "TcpIpBase.h" #include "fsfw/platform.h" #include "fsfw/osal/common/tcpipHelpers.h" #include "fsfw/ipc/messageQueueDefinitions.h" +#include "fsfw/container/SimpleRingBuffer.h" #include "fsfw/ipc/MessageQueueIF.h" #include "fsfw/objectmanager/frameworkObjects.h" #include "fsfw/objectmanager/SystemObject.h" @@ -42,9 +44,37 @@ class TcpTmTcServer: public TcpIpBase, public ExecutableObjectIF { public: + enum class ReceptionModes { + SPACE_PACKETS + }; + + struct TcpConfig { + public: + TcpConfig(std::string tcpPort): tcpPort(tcpPort) {} + + /** + * Passed to the recv call + */ + int tcpFlags = 0; + int tcpBacklog = 3; + + /** + * Passed to the select call which is used to ensure non-blocking TC reception + */ + //uint32_t selectTimeoutMs = DEFAULT_SELECT_TIMEOUT_MS; + /** + * Passed to the send call + */ + int tcpTmFlags = 0; + + const std::string tcpPort; + }; + static const std::string DEFAULT_SERVER_PORT; static constexpr size_t ETHERNET_MTU_SIZE = 1500; + static constexpr size_t RING_BUFFER_SIZE = ETHERNET_MTU_SIZE * 3; + static constexpr uint32_t DEFAULT_LOOP_DELAY_MS = 200; /** * TCP Server Constructor @@ -55,11 +85,19 @@ public: * @param customTcpServerPort The user can specify another port than the default (7301) here. */ TcpTmTcServer(object_id_t objectId, object_id_t tmtcTcpBridge, - size_t receptionBufferSize = ETHERNET_MTU_SIZE + 1, - std::string customTcpServerPort = ""); + size_t receptionBufferSize = RING_BUFFER_SIZE, + size_t ringBufferSize = RING_BUFFER_SIZE, + std::string customTcpServerPort = DEFAULT_SERVER_PORT, + ReceptionModes receptionMode = ReceptionModes::SPACE_PACKETS); virtual~ TcpTmTcServer(); - void setTcpBacklog(uint8_t tcpBacklog); + /** + * Get a handle to the TCP configuration struct, which can be used to configure TCP + * properties + * @return + */ + TcpConfig& getTcpConfigStruct(); + void setSpacePacketParsingOptions(std::vector validPacketIds); ReturnValue_t initialize() override; ReturnValue_t performOperation(uint8_t opCode) override; @@ -71,25 +109,29 @@ protected: StorageManagerIF* tcStore = nullptr; StorageManagerIF* tmStore = nullptr; private: + static constexpr ReturnValue_t CONN_BROKEN = HasReturnvaluesIF::makeReturnCode(1, 0); //! TMTC bridge is cached. object_id_t tmtcBridgeId = objects::NO_OBJECT; TcpTmTcBridge* tmtcBridge = nullptr; - std::string tcpPort; - int tcpFlags = 0; - socket_t listenerTcpSocket = 0; + ReceptionModes receptionMode; + TcpConfig tcpConfig; struct sockaddr tcpAddress; + socket_t listenerTcpSocket = 0; + MessageQueueId_t targetTcDestination = MessageQueueIF::NO_QUEUE; - int tcpAddrLen = sizeof(tcpAddress); - int tcpBacklog = 3; std::vector receptionBuffer; - int tcpSockOpt = 0; - int tcpTmFlags = 0; + SimpleRingBuffer ringBuffer; + std::vector validPacketIds; + SpacePacketParser* spacePacketParser = nullptr; + uint8_t lastRingBufferSize = 0; - void handleServerOperation(socket_t connSocket); - ReturnValue_t handleTcReception(size_t bytesRecvd); - ReturnValue_t handleTmSending(socket_t connSocket); + virtual void handleServerOperation(socket_t& connSocket); + ReturnValue_t handleTcReception(uint8_t* spacePacket, size_t packetSize); + ReturnValue_t handleTmSending(socket_t connSocket, bool& tmSent); + ReturnValue_t handleTcRingBufferData(size_t availableReadData); + void handleSocketError(ConstStorageAccessor& accessor); }; #endif /* FSFW_OSAL_COMMON_TCP_TMTC_SERVER_H_ */ diff --git a/src/fsfw/tmtcpacket/SpacePacket.h b/src/fsfw/tmtcpacket/SpacePacket.h index 49dd5ae5..9eec87a8 100644 --- a/src/fsfw/tmtcpacket/SpacePacket.h +++ b/src/fsfw/tmtcpacket/SpacePacket.h @@ -15,56 +15,67 @@ */ class SpacePacket: public SpacePacketBase { public: - static const uint16_t PACKET_MAX_SIZE = 1024; - /** - * The constructor initializes the packet and sets all header information - * according to the passed parameters. - * @param packetDataLength Sets the packet data length field and therefore specifies the size of the packet. - * @param isTelecommand Sets the packet type field to either TC (true) or TM (false). - * @param apid Sets the packet's APID field. The default value describes an idle packet. - * @param sequenceCount ets the packet's Source Sequence Count field. - */ - SpacePacket(uint16_t packetDataLength, bool isTelecommand = false, - uint16_t apid = APID_IDLE_PACKET, uint16_t sequenceCount = 0); - /** - * The class's default destructor. - */ - virtual ~SpacePacket(); - /** - * With this call, the complete data content (including the CCSDS Primary - * Header) is overwritten with the byte stream given. - * @param p_data Pointer to data to overwrite the content with - * @param packet_size Size of the data - * @return @li \c true if packet_size is smaller than \c MAX_PACKET_SIZE. - * @li \c false else. - */ - bool addWholeData(const uint8_t* p_data, uint32_t packet_size); + static const uint16_t PACKET_MAX_SIZE = 1024; + /** + * The constructor initializes the packet and sets all header information + * according to the passed parameters. + * @param packetDataLength Sets the packet data length field and therefore specifies + * the size of the packet. + * @param isTelecommand Sets the packet type field to either TC (true) or TM (false). + * @param apid Sets the packet's APID field. The default value describes an idle packet. + * @param sequenceCount ets the packet's Source Sequence Count field. + */ + SpacePacket(uint16_t packetDataLength, bool isTelecommand = false, + uint16_t apid = APID_IDLE_PACKET, uint16_t sequenceCount = 0); + /** + * The class's default destructor. + */ + virtual ~SpacePacket(); + + static constexpr uint16_t getTcSpacePacketIdFromApid(uint16_t apid) { + uint16_t tcPacketId = (0x18 << 8) | (((apid >> 8) & 0x07) << 8) | (apid & 0x00ff); + return tcPacketId; + } + static constexpr uint16_t getTmSpacePacketIdFromApid(uint16_t apid) { + uint16_t tmPacketId = (0x08 << 8) | (((apid >> 8) & 0x07) << 8) | (apid & 0x00ff); + return tmPacketId; + } + + /** + * With this call, the complete data content (including the CCSDS Primary + * Header) is overwritten with the byte stream given. + * @param p_data Pointer to data to overwrite the content with + * @param packet_size Size of the data + * @return @li \c true if packet_size is smaller than \c MAX_PACKET_SIZE. + * @li \c false else. + */ + bool addWholeData(const uint8_t* p_data, uint32_t packet_size); protected: - /** - * This structure defines the data structure of a Space Packet as local data. - * There's a buffer which corresponds to the Space Packet Data Field with a - * maximum size of \c PACKET_MAX_SIZE. - */ - struct PacketStructured { - CCSDSPrimaryHeader header; - uint8_t buffer[PACKET_MAX_SIZE]; - }; - /** - * This union simplifies accessing the full data content of the Space Packet. - * This is achieved by putting the \c PacketStructured struct in a union with - * a plain buffer. - */ - union SpacePacketData { - PacketStructured fields; - uint8_t byteStream[PACKET_MAX_SIZE + sizeof(CCSDSPrimaryHeader)]; - }; - /** - * This is the data representation of the class. - * It is a struct of CCSDS Primary Header and a data field, which again is - * packed in an union, so the data can be accessed as a byte stream without - * a cast. - */ - SpacePacketData localData; + /** + * This structure defines the data structure of a Space Packet as local data. + * There's a buffer which corresponds to the Space Packet Data Field with a + * maximum size of \c PACKET_MAX_SIZE. + */ + struct PacketStructured { + CCSDSPrimaryHeader header; + uint8_t buffer[PACKET_MAX_SIZE]; + }; + /** + * This union simplifies accessing the full data content of the Space Packet. + * This is achieved by putting the \c PacketStructured struct in a union with + * a plain buffer. + */ + union SpacePacketData { + PacketStructured fields; + uint8_t byteStream[PACKET_MAX_SIZE + sizeof(CCSDSPrimaryHeader)]; + }; + /** + * This is the data representation of the class. + * It is a struct of CCSDS Primary Header and a data field, which again is + * packed in an union, so the data can be accessed as a byte stream without + * a cast. + */ + SpacePacketData localData; }; #endif /* SPACEPACKET_H_ */ diff --git a/src/fsfw/tmtcservices/SpacePacketParser.cpp b/src/fsfw/tmtcservices/SpacePacketParser.cpp new file mode 100644 index 00000000..84f861cf --- /dev/null +++ b/src/fsfw/tmtcservices/SpacePacketParser.cpp @@ -0,0 +1,77 @@ +#include +#include +#include + +SpacePacketParser::SpacePacketParser(std::vector validPacketIds): + validPacketIds(validPacketIds) { +} + +ReturnValue_t SpacePacketParser::parseSpacePackets(const uint8_t *buffer, + const size_t maxSize, size_t& startIndex, size_t& foundSize) { + const uint8_t** tempPtr = &buffer; + size_t readLen = 0; + return parseSpacePackets(tempPtr, maxSize, startIndex, foundSize, readLen); +} + +ReturnValue_t SpacePacketParser::parseSpacePackets(const uint8_t **buffer, const size_t maxSize, + size_t &startIndex, size_t &foundSize, size_t& readLen) { + if(buffer == nullptr or maxSize < 5) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "SpacePacketParser::parseSpacePackets: Frame invalid" << std::endl; +#else + sif::printWarning("SpacePacketParser::parseSpacePackets: Frame invalid\n"); +#endif + return HasReturnvaluesIF::RETURN_FAILED; + } + const uint8_t* bufPtr = *buffer; + + auto verifyLengthField = [&](size_t idx) { + uint16_t lengthField = bufPtr[idx + 4] << 8 | bufPtr[idx + 5]; + size_t packetSize = lengthField + 7; + startIndex = idx; + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + if(lengthField == 0) { + // Skip whole header for now + foundSize = 6; + result = NO_PACKET_FOUND; + } + else if(packetSize + idx > maxSize) { + // Don't increment buffer and read length here, user has to decide what to do + foundSize = packetSize; + return SPLIT_PACKET; + } + else { + foundSize = packetSize; + } + *buffer += foundSize; + readLen += foundSize; + return result; + }; + + size_t idx = 0; + // Space packet ID as start marker + if(validPacketIds.size() > 0) { + while(idx < maxSize - 5) { + uint16_t currentPacketId = bufPtr[idx] << 8 | bufPtr[idx + 1]; + if(std::find(validPacketIds.begin(), validPacketIds.end(), currentPacketId) != + validPacketIds.end()) { + if(idx + 5 >= maxSize) { + return SPLIT_PACKET; + } + return verifyLengthField(idx); + } + else { + idx++; + } + } + startIndex = 0; + foundSize = maxSize; + *buffer += foundSize; + readLen += foundSize; + return NO_PACKET_FOUND; + } + // Assume that the user verified a valid start of a space packet + else { + return verifyLengthField(idx); + } +} diff --git a/src/fsfw/tmtcservices/SpacePacketParser.h b/src/fsfw/tmtcservices/SpacePacketParser.h new file mode 100644 index 00000000..16b53ea4 --- /dev/null +++ b/src/fsfw/tmtcservices/SpacePacketParser.h @@ -0,0 +1,96 @@ +#ifndef FRAMEWORK_TMTCSERVICES_PUSPARSER_H_ +#define FRAMEWORK_TMTCSERVICES_PUSPARSER_H_ + +#include "fsfw/container/DynamicFIFO.h" +#include "fsfw/returnvalues/FwClassIds.h" + +#include +#include + +/** + * @brief This small helper class scans a given buffer for PUS packets. + * Can be used if PUS packets are serialized in a tightly packed frame. + * @details + * The parser uses the length field field of the space packets to find + * the respective space packet sizes. + * + * The parser parses a buffer by taking a pointer and the maximum size to scan. + * If space packets are found, they are stored in a FIFO which stores pairs + * consisting of the index in the buffer and the respective packet sizes. + * + * If the parser detects split packets (which means that the size of the + * next packet is larger than the remaining size to scan), it can either + * store that split packet or throw away the packet. + * @author R. Mueller + */ +class SpacePacketParser { +public: + //! The first entry is the index inside the buffer while the second index + //! is the size of the PUS packet starting at that index. + using IndexSizePair = std::pair; + + static constexpr uint8_t INTERFACE_ID = CLASS_ID::PUS_PARSER; + static constexpr ReturnValue_t NO_PACKET_FOUND = MAKE_RETURN_CODE(0x00); + static constexpr ReturnValue_t SPLIT_PACKET = MAKE_RETURN_CODE(0x01); + + /** + * @brief Parser constructor. + * @param maxExpectedPusPackets + * Maximum expected number of PUS packets. A good estimate is to divide + * the frame size by the minimum size of a PUS packet (12 bytes) + * @param storeSplitPackets + * Specifies whether split packets are also stored inside the FIFO, + * with the size being the remaining frame size. + */ + SpacePacketParser(std::vector validPacketIds); + + /** + * Parse a given frame for PUS packets + * @param frame + * @param frameSize + * @param foundPackets The number of found packets will be stored here + * @return + * -@c NO_PACKET_FOUND if no packet was found + * -@c SPLIT_PACKET if splitting is enabled and a split packet was found + * -@c RETURN_OK if a packet was found. The index and sizes are stored in the internal FIFO + */ + ReturnValue_t parseSpacePackets(const uint8_t* buffer, const size_t maxSize, + size_t& startIndex, size_t& foundSize); + + ReturnValue_t parseSpacePackets(const uint8_t **buffer, const size_t maxSize, + size_t& startIndex, size_t& foundSize, size_t& readLen); + /** + * Accessor function to get a reference to the internal FIFO which + * stores pairs of index and packet sizes. This FIFO is filled + * by the #parsePusPackets function. + * @return + */ + //DynamicFIFO& fifo(); + + /** + * Retrieve the next index and packet size pair from the FIFO. + * This also removes it from the FIFO. Please note that if the FIFO + * is empty, an empty pair will be returned. + * @return + */ + //IndexSizePair getNextFifoPair(); + +private: + /** + * A FIFO is used to store information about multiple PUS packets + * inside the receive buffer. The maximum number of entries is defined + * by the first constructor argument. + */ + //DynamicFIFO indexSizePairFIFO; + + std::vector validPacketIds; + + //bool storeSplitPackets = false; + +// ReturnValue_t readMultiplePackets(const uint8_t *frame, size_t frameSize, +// size_t startIndex, uint32_t& foundPackets); +// ReturnValue_t readNextPacket(const uint8_t *frame, +// size_t frameSize, size_t& startIndex, uint32_t& foundPackets); +}; + +#endif /* FRAMEWORK_TMTCSERVICES_PUSPARSER_H_ */ From e536918804255bf035ba78e5ddb9171b01f02761 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 28 Sep 2021 15:09:56 +0200 Subject: [PATCH 02/89] wiretapping in runtime config now --- src/fsfw/osal/common/TcpTmTcServer.cpp | 24 +++++++++++++++--------- src/fsfw/osal/common/TcpTmTcServer.h | 5 ++++- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/fsfw/osal/common/TcpTmTcServer.cpp b/src/fsfw/osal/common/TcpTmTcServer.cpp index e320b46b..5be9373e 100644 --- a/src/fsfw/osal/common/TcpTmTcServer.cpp +++ b/src/fsfw/osal/common/TcpTmTcServer.cpp @@ -5,12 +5,13 @@ #include "TcpTmTcBridge.h" #include "tcpipHelpers.h" +#include "fsfw/tmtcservices/SpacePacketParser.h" #include "fsfw/tasks/TaskFactory.h" +#include "fsfw/globalfunctions/arrayprinter.h" #include "fsfw/container/SharedRingBuffer.h" #include "fsfw/ipc/MessageQueueSenderIF.h" #include "fsfw/ipc/MutexGuard.h" #include "fsfw/objectmanager/ObjectManager.h" - #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/tmtcservices/TmTcMessage.h" @@ -20,11 +21,6 @@ #elif defined(PLATFORM_UNIX) #include #endif -#include - -#ifndef FSFW_TCP_RECV_WIRETAPPING_ENABLED -#define FSFW_TCP_RECV_WIRETAPPING_ENABLED 0 -#endif const std::string TcpTmTcServer::DEFAULT_SERVER_PORT = tcpip::DEFAULT_SERVER_PORT; @@ -202,9 +198,11 @@ void TcpTmTcServer::handleServerOperation(socket_t& connSocket) { } ReturnValue_t TcpTmTcServer::handleTcReception(uint8_t* spacePacket, size_t packetSize) { -#if FSFW_TCP_RECV_WIRETAPPING_ENABLED == 1 - arrayprinter::print(receptionBuffer.data(), bytesRead); -#endif + if(wiretappingEnabled) { + sif::info << "Received TC:" << std::endl; + arrayprinter::print(spacePacket, packetSize); + } + if(spacePacket == nullptr or packetSize == 0) { return HasReturnvaluesIF::RETURN_FAILED; } @@ -268,6 +266,10 @@ ReturnValue_t TcpTmTcServer::handleTmSending(socket_t connSocket, bool& tmSent) if(result != HasReturnvaluesIF::RETURN_OK) { return result; } + if(wiretappingEnabled) { + sif::info << "Sending TM:" << std::endl; + arrayprinter::print(storeAccessor.data(), storeAccessor.size()); + } int retval = send(connSocket, reinterpret_cast(storeAccessor.data()), storeAccessor.size(), @@ -346,6 +348,10 @@ ReturnValue_t TcpTmTcServer::handleTcRingBufferData(size_t availableReadData) { return status; } +void TcpTmTcServer::enableWiretapping(bool enable) { + this->wiretappingEnabled = enable; +} + void TcpTmTcServer::handleSocketError(ConstStorageAccessor &accessor) { // Don't delete data accessor.release(); diff --git a/src/fsfw/osal/common/TcpTmTcServer.h b/src/fsfw/osal/common/TcpTmTcServer.h index a0a31655..d5214848 100644 --- a/src/fsfw/osal/common/TcpTmTcServer.h +++ b/src/fsfw/osal/common/TcpTmTcServer.h @@ -1,7 +1,6 @@ #ifndef FSFW_OSAL_COMMON_TCP_TMTC_SERVER_H_ #define FSFW_OSAL_COMMON_TCP_TMTC_SERVER_H_ -#include #include "TcpIpBase.h" #include "fsfw/platform.h" @@ -22,6 +21,7 @@ #include class TcpTmTcBridge; +class SpacePacketParser; /** * @brief TCP server implementation @@ -91,6 +91,8 @@ public: ReceptionModes receptionMode = ReceptionModes::SPACE_PACKETS); virtual~ TcpTmTcServer(); + void enableWiretapping(bool enable); + /** * Get a handle to the TCP configuration struct, which can be used to configure TCP * properties @@ -113,6 +115,7 @@ private: //! TMTC bridge is cached. object_id_t tmtcBridgeId = objects::NO_OBJECT; TcpTmTcBridge* tmtcBridge = nullptr; + bool wiretappingEnabled = false; ReceptionModes receptionMode; TcpConfig tcpConfig; From bbea5e33bc66d05589d6143c0e75931acd99de83 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 28 Sep 2021 15:12:23 +0200 Subject: [PATCH 03/89] removed obsolete empty ctor --- src/fsfw/osal/common/TcpTmTcServer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsfw/osal/common/TcpTmTcServer.cpp b/src/fsfw/osal/common/TcpTmTcServer.cpp index 5be9373e..fb421fc7 100644 --- a/src/fsfw/osal/common/TcpTmTcServer.cpp +++ b/src/fsfw/osal/common/TcpTmTcServer.cpp @@ -29,7 +29,7 @@ TcpTmTcServer::TcpTmTcServer(object_id_t objectId, object_id_t tmtcTcpBridge, ReceptionModes receptionMode): SystemObject(objectId), tmtcBridgeId(tmtcTcpBridge), receptionMode(receptionMode), tcpConfig(customTcpServerPort), receptionBuffer(receptionBufferSize), - ringBuffer(ringBufferSize, true), validPacketIds() { + ringBuffer(ringBufferSize, true) { } ReturnValue_t TcpTmTcServer::initialize() { From f02852d8d2bf40b2941ccd0816c1ed01d703fea7 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 28 Sep 2021 15:13:46 +0200 Subject: [PATCH 04/89] cmake lists file update --- src/fsfw/tmtcservices/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fsfw/tmtcservices/CMakeLists.txt b/src/fsfw/tmtcservices/CMakeLists.txt index c30af214..96cf99b5 100644 --- a/src/fsfw/tmtcservices/CMakeLists.txt +++ b/src/fsfw/tmtcservices/CMakeLists.txt @@ -6,4 +6,5 @@ target_sources(${LIB_FSFW_NAME} TmTcBridge.cpp TmTcMessage.cpp VerificationReporter.cpp + SpacePacketParser.cpp ) \ No newline at end of file From a4d6421510575b9eda7f27c1637963c91881f922 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 28 Sep 2021 15:30:01 +0200 Subject: [PATCH 05/89] documentation and bugfixes --- src/fsfw/tmtcservices/SpacePacketParser.cpp | 2 +- src/fsfw/tmtcservices/SpacePacketParser.h | 100 ++++++++------------ 2 files changed, 42 insertions(+), 60 deletions(-) diff --git a/src/fsfw/tmtcservices/SpacePacketParser.cpp b/src/fsfw/tmtcservices/SpacePacketParser.cpp index 84f861cf..3d442458 100644 --- a/src/fsfw/tmtcservices/SpacePacketParser.cpp +++ b/src/fsfw/tmtcservices/SpacePacketParser.cpp @@ -44,7 +44,7 @@ ReturnValue_t SpacePacketParser::parseSpacePackets(const uint8_t **buffer, const foundSize = packetSize; } *buffer += foundSize; - readLen += foundSize; + readLen += idx + foundSize; return result; }; diff --git a/src/fsfw/tmtcservices/SpacePacketParser.h b/src/fsfw/tmtcservices/SpacePacketParser.h index 16b53ea4..82b15010 100644 --- a/src/fsfw/tmtcservices/SpacePacketParser.h +++ b/src/fsfw/tmtcservices/SpacePacketParser.h @@ -8,19 +8,11 @@ #include /** - * @brief This small helper class scans a given buffer for PUS packets. - * Can be used if PUS packets are serialized in a tightly packed frame. + * @brief This small helper class scans a given buffer for space packets. + * Can be used if space packets are serialized in a tightly packed frame. * @details - * The parser uses the length field field of the space packets to find - * the respective space packet sizes. - * - * The parser parses a buffer by taking a pointer and the maximum size to scan. - * If space packets are found, they are stored in a FIFO which stores pairs - * consisting of the index in the buffer and the respective packet sizes. - * - * If the parser detects split packets (which means that the size of the - * next packet is larger than the remaining size to scan), it can either - * store that split packet or throw away the packet. + * The parser uses the length field field and the 16-bit TC packet ID of the space packets to find + * find space packets in a given data stream * @author R. Mueller */ class SpacePacketParser { @@ -35,62 +27,52 @@ public: /** * @brief Parser constructor. - * @param maxExpectedPusPackets - * Maximum expected number of PUS packets. A good estimate is to divide - * the frame size by the minimum size of a PUS packet (12 bytes) - * @param storeSplitPackets - * Specifies whether split packets are also stored inside the FIFO, - * with the size being the remaining frame size. + * @param validPacketIds This vector contains the allowed 16-bit TC packet ID start markers + * The parser will search for these stark markers to detect the start of a space packet. + * It is also possible to pass an empty vector here, but this is not recommended. + * If an empty vector is passed, the parser will assume that the start of the given stream + * contains the start of a new space packet. */ SpacePacketParser(std::vector validPacketIds); + /** + * Parse a given frame for space packets but also increment the given buffer and assign the + * total number of bytes read so far + * @param buffer Parser will look for space packets in this buffer + * @param maxSize Maximum size of the buffer + * @param startIndex Start index of a found space packet + * @param foundSize Found size of the space packet + * @param readLen Length read so far. This value is incremented by the number of parsed + * bytes which also includes the size of a found packet + * -@c NO_PACKET_FOUND if no packet was found in the given buffer or the length field is + * invalid. foundSize will be set to the size of the space packet header. buffer and + * readLen will be incremented accordingly. + * -@c SPLIT_PACKET if a packet was found but the detected size exceeds maxSize. foundSize + * will be set to the detected packet size and startIndex will be set to the start of the + * detected packet. buffer and read length will not be incremented but the found length + * will be assigned. + * -@c RETURN_OK if a packet was found + */ + ReturnValue_t parseSpacePackets(const uint8_t **buffer, const size_t maxSize, + size_t& startIndex, size_t& foundSize, size_t& readLen); + /** - * Parse a given frame for PUS packets - * @param frame - * @param frameSize - * @param foundPackets The number of found packets will be stored here - * @return - * -@c NO_PACKET_FOUND if no packet was found - * -@c SPLIT_PACKET if splitting is enabled and a split packet was found - * -@c RETURN_OK if a packet was found. The index and sizes are stored in the internal FIFO + * Parse a given frame for space packets + * @param buffer Parser will look for space packets in this buffer + * @param maxSize Maximum size of the buffer + * @param startIndex Start index of a found space packet + * @param foundSize Found size of the space packet + * -@c NO_PACKET_FOUND if no packet was found in the given buffer or the length field is + * invalid. foundSize will be set to the size of the space packet header + * -@c SPLIT_PACKET if a packet was found but the detected size exceeds maxSize. foundSize + * will be set to the detected packet size and startIndex will be set to the start of the + * detected packet + * -@c RETURN_OK if a packet was found */ ReturnValue_t parseSpacePackets(const uint8_t* buffer, const size_t maxSize, size_t& startIndex, size_t& foundSize); - - ReturnValue_t parseSpacePackets(const uint8_t **buffer, const size_t maxSize, - size_t& startIndex, size_t& foundSize, size_t& readLen); - /** - * Accessor function to get a reference to the internal FIFO which - * stores pairs of index and packet sizes. This FIFO is filled - * by the #parsePusPackets function. - * @return - */ - //DynamicFIFO& fifo(); - - /** - * Retrieve the next index and packet size pair from the FIFO. - * This also removes it from the FIFO. Please note that if the FIFO - * is empty, an empty pair will be returned. - * @return - */ - //IndexSizePair getNextFifoPair(); - private: - /** - * A FIFO is used to store information about multiple PUS packets - * inside the receive buffer. The maximum number of entries is defined - * by the first constructor argument. - */ - //DynamicFIFO indexSizePairFIFO; - std::vector validPacketIds; - - //bool storeSplitPackets = false; - -// ReturnValue_t readMultiplePackets(const uint8_t *frame, size_t frameSize, -// size_t startIndex, uint32_t& foundPackets); -// ReturnValue_t readNextPacket(const uint8_t *frame, -// size_t frameSize, size_t& startIndex, uint32_t& foundPackets); }; #endif /* FRAMEWORK_TMTCSERVICES_PUSPARSER_H_ */ From 1622e23f1c15ddcf1d4b522c332c1ab156f91fd9 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 28 Sep 2021 15:32:58 +0200 Subject: [PATCH 06/89] delay configurable --- src/fsfw/osal/common/TcpTmTcServer.cpp | 2 +- src/fsfw/osal/common/TcpTmTcServer.h | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/fsfw/osal/common/TcpTmTcServer.cpp b/src/fsfw/osal/common/TcpTmTcServer.cpp index fb421fc7..c3936146 100644 --- a/src/fsfw/osal/common/TcpTmTcServer.cpp +++ b/src/fsfw/osal/common/TcpTmTcServer.cpp @@ -187,7 +187,7 @@ void TcpTmTcServer::handleServerOperation(socket_t& connSocket) { return; } if(not tcAvailable and not tmSent) { - TaskFactory::delayTask(DEFAULT_LOOP_DELAY_MS); + TaskFactory::delayTask(tcpConfig.tcpLoopDelay); } } else { diff --git a/src/fsfw/osal/common/TcpTmTcServer.h b/src/fsfw/osal/common/TcpTmTcServer.h index d5214848..da0e8bd5 100644 --- a/src/fsfw/osal/common/TcpTmTcServer.h +++ b/src/fsfw/osal/common/TcpTmTcServer.h @@ -59,9 +59,10 @@ public: int tcpBacklog = 3; /** - * Passed to the select call which is used to ensure non-blocking TC reception + * If no telecommands packets are being received and no telemetry is being sent, + * the TCP server will delay periodically by this amount to decrease the CPU load */ - //uint32_t selectTimeoutMs = DEFAULT_SELECT_TIMEOUT_MS; + uint32_t tcpLoopDelay = DEFAULT_LOOP_DELAY_MS ; /** * Passed to the send call */ From bf02f14772184394c51c500ccc6dc312839de746 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 28 Sep 2021 16:31:53 +0200 Subject: [PATCH 07/89] C++11 adaptions --- src/fsfw/tmtcpacket/SpacePacket.h | 17 ++++++++--------- src/fsfw/tmtcservices/SpacePacketParser.h | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/fsfw/tmtcpacket/SpacePacket.h b/src/fsfw/tmtcpacket/SpacePacket.h index 9eec87a8..67746859 100644 --- a/src/fsfw/tmtcpacket/SpacePacket.h +++ b/src/fsfw/tmtcpacket/SpacePacket.h @@ -32,15 +32,6 @@ public: */ virtual ~SpacePacket(); - static constexpr uint16_t getTcSpacePacketIdFromApid(uint16_t apid) { - uint16_t tcPacketId = (0x18 << 8) | (((apid >> 8) & 0x07) << 8) | (apid & 0x00ff); - return tcPacketId; - } - static constexpr uint16_t getTmSpacePacketIdFromApid(uint16_t apid) { - uint16_t tmPacketId = (0x08 << 8) | (((apid >> 8) & 0x07) << 8) | (apid & 0x00ff); - return tmPacketId; - } - /** * With this call, the complete data content (including the CCSDS Primary * Header) is overwritten with the byte stream given. @@ -78,4 +69,12 @@ protected: SpacePacketData localData; }; +constexpr uint16_t getTcSpacePacketIdFromApid(uint16_t apid) { + return (0x18 << 8) | (((apid >> 8) & 0x07) << 8) | (apid & 0x00ff); +} + +constexpr uint16_t getTmSpacePacketIdFromApid(uint16_t apid) { + return (0x08 << 8) | (((apid >> 8) & 0x07) << 8) | (apid & 0x00ff); +} + #endif /* SPACEPACKET_H_ */ diff --git a/src/fsfw/tmtcservices/SpacePacketParser.h b/src/fsfw/tmtcservices/SpacePacketParser.h index 82b15010..bed3369b 100644 --- a/src/fsfw/tmtcservices/SpacePacketParser.h +++ b/src/fsfw/tmtcservices/SpacePacketParser.h @@ -21,7 +21,7 @@ public: //! is the size of the PUS packet starting at that index. using IndexSizePair = std::pair; - static constexpr uint8_t INTERFACE_ID = CLASS_ID::PUS_PARSER; + static constexpr uint8_t INTERFACE_ID = CLASS_ID::SPACE_PACKET_PARSER; static constexpr ReturnValue_t NO_PACKET_FOUND = MAKE_RETURN_CODE(0x00); static constexpr ReturnValue_t SPLIT_PACKET = MAKE_RETURN_CODE(0x01); From 936bac5abdd6e56e8f3be85b624620948fecf714 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 28 Sep 2021 16:32:43 +0200 Subject: [PATCH 08/89] class id renamed --- src/fsfw/returnvalues/FwClassIds.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fsfw/returnvalues/FwClassIds.h b/src/fsfw/returnvalues/FwClassIds.h index cdbf5657..337709ed 100644 --- a/src/fsfw/returnvalues/FwClassIds.h +++ b/src/fsfw/returnvalues/FwClassIds.h @@ -78,6 +78,7 @@ enum: uint8_t { HAL_GPIO, //HGIO MGM_LIS3MDL, //MGMLIS3 MGM_RM3100, //MGMRM3100 + SPACE_PACKET_PARSER, //SPPA FW_CLASS_ID_COUNT // [EXPORT] : [END] }; From 32b5060c626261bd2729210f318bcc127d0117c3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 28 Sep 2021 17:26:02 +0200 Subject: [PATCH 09/89] all windows fixes --- src/fsfw/osal/common/TcpTmTcServer.cpp | 158 +++++++++++++++++++++++-- src/fsfw/osal/common/TcpTmTcServer.h | 17 ++- 2 files changed, 162 insertions(+), 13 deletions(-) diff --git a/src/fsfw/osal/common/TcpTmTcServer.cpp b/src/fsfw/osal/common/TcpTmTcServer.cpp index 11ab71af..b22f4412 100644 --- a/src/fsfw/osal/common/TcpTmTcServer.cpp +++ b/src/fsfw/osal/common/TcpTmTcServer.cpp @@ -41,6 +41,17 @@ ReturnValue_t TcpTmTcServer::initialize() { return result; } + switch(receptionMode) { + case(ReceptionModes::SPACE_PACKETS): { + spacePacketParser = new SpacePacketParser(validPacketIds); + if(spacePacketParser == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } +#if defined PLATFORM_UNIX + tcpConfig.tcpFlags |= MSG_DONTWAIT; +#endif + } + } tcStore = ObjectManager::instance()->get(objects::TC_STORE); if (tcStore == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -144,11 +155,14 @@ ReturnValue_t TcpTmTcServer::initializeAfterTaskCreation() { return HasReturnvaluesIF::RETURN_OK; } -void TcpTmTcServer::handleServerOperation(socket_t connSocket) { - int retval = 0; - do { - // Read all telecommands sent by the client - retval = recv(connSocket, +void TcpTmTcServer::handleServerOperation(socket_t& connSocket) { +#if defined PLATFORM_WIN + setSocketNonBlocking(connSocket); +#endif + + while (true) { + int retval = recv( + connSocket, reinterpret_cast(receptionBuffer.data()), receptionBuffer.capacity(), tcpFlags); @@ -159,9 +173,34 @@ void TcpTmTcServer::handleServerOperation(socket_t connSocket) { // Client has finished sending telecommands, send telemetry now handleTmSending(connSocket); } - else { - // Should not happen - tcpip::handleError(tcpip::Protocol::TCP, tcpip::ErrorSources::RECV_CALL); + else if(retval < 0) { + int errorValue = GetLastError(); +#if defined PLATFORM_UNIX + int wouldBlockValue = EAGAIN; +#elif defined PLATFORM_WIN + int wouldBlockValue = WSAEWOULDBLOCK; +#endif + if(errorValue == wouldBlockValue) { + // No data available. Check whether any packets have been read, then send back + // telemetry if available + bool tcAvailable = false; + bool tmSent = false; + size_t availableReadData = ringBuffer.getAvailableReadData(); + if(availableReadData > lastRingBufferSize) { + tcAvailable = true; + handleTcRingBufferData(availableReadData); + } + ReturnValue_t result = handleTmSending(connSocket, tmSent); + if(result == CONN_BROKEN) { + return; + } + if(not tcAvailable and not tmSent) { + TaskFactory::delayTask(tcpConfig.tcpLoopDelay); + } + } + else { + tcpip::handleError(tcpip::Protocol::TCP, tcpip::ErrorSources::RECV_CALL, 300); + } } } while(retval > 0); } @@ -228,3 +267,106 @@ ReturnValue_t TcpTmTcServer::handleTmSending(socket_t connSocket) { } return HasReturnvaluesIF::RETURN_OK; } + +ReturnValue_t TcpTmTcServer::handleTcRingBufferData(size_t availableReadData) { + ReturnValue_t status = HasReturnvaluesIF::RETURN_OK; + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + size_t readAmount = availableReadData; + lastRingBufferSize = availableReadData; + if(readAmount >= ringBuffer.getMaxSize()) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + // Possible configuration error, too much data or/and data coming in too fast, + // requiring larger buffers + sif::warning << "TcpTmTcServer::handleServerOperation: Ring buffer reached " << + "fill count" << std::endl; +#else + sif::printWarning("TcpTmTcServer::handleServerOperation: Ring buffer reached " + "fill count"); +#endif +#endif + } + if(readAmount >= receptionBuffer.size()) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + // Possible configuration error, too much data or/and data coming in too fast, + // requiring larger buffers + sif::warning << "TcpTmTcServer::handleServerOperation: " + "Reception buffer too small " << std::endl; +#else + sif::printWarning("TcpTmTcServer::handleServerOperation: Reception buffer too small\n"); +#endif +#endif + readAmount = receptionBuffer.size(); + } + ringBuffer.readData(receptionBuffer.data(), readAmount, true); + const uint8_t* bufPtr = receptionBuffer.data(); + const uint8_t** bufPtrPtr = &bufPtr; + size_t startIdx = 0; + size_t foundSize = 0; + size_t readLen = 0; + while(readLen < readAmount) { + result = spacePacketParser->parseSpacePackets(bufPtrPtr, readAmount, + startIdx, foundSize, readLen); + switch(result) { + case(SpacePacketParser::NO_PACKET_FOUND): + case(SpacePacketParser::SPLIT_PACKET): { + break; + } + case(HasReturnvaluesIF::RETURN_OK): { + result = handleTcReception(receptionBuffer.data() + startIdx, foundSize); + if(result != HasReturnvaluesIF::RETURN_OK) { + status = result; + } + } + } + ringBuffer.deleteData(foundSize); + lastRingBufferSize = ringBuffer.getAvailableReadData(); + std::memset(receptionBuffer.data() + startIdx, 0, foundSize); + } + return status; +} + +void TcpTmTcServer::enableWiretapping(bool enable) { + this->wiretappingEnabled = enable; +} + +void TcpTmTcServer::handleSocketError(ConstStorageAccessor &accessor) { + // Don't delete data + accessor.release(); + auto socketError = getLastSocketError(); + switch(socketError) { +#if defined PLATFORM_WIN + case(WSAECONNRESET): { + // See https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-send + // Remote client might have shut down connection + return; + } +#else + case(EPIPE): { + // See https://man7.org/linux/man-pages/man2/send.2.html + // Remote client might have shut down connection + return; + } +#endif + default: { + tcpip::handleError(tcpip::Protocol::TCP, tcpip::ErrorSources::SEND_CALL); + } + } +} + +void TcpTmTcServer::setSocketNonBlocking(socket_t &connSocket) { + u_long iMode = 1; + int iResult = ioctlsocket(connSocket, FIONBIO, &iMode); + if(iResult != NO_ERROR) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "TcpTmTcServer::handleServerOperation: Setting socket" + " non-blocking failed with error " << iResult; +#else + sif::printWarning("TcpTmTcServer::handleServerOperation: Setting socket" + " non-blocking failed with error %d\n", iResult); +#endif +#endif + } +} diff --git a/src/fsfw/osal/common/TcpTmTcServer.h b/src/fsfw/osal/common/TcpTmTcServer.h index c6916080..2104d859 100644 --- a/src/fsfw/osal/common/TcpTmTcServer.h +++ b/src/fsfw/osal/common/TcpTmTcServer.h @@ -84,12 +84,19 @@ private: int tcpBacklog = 3; std::vector receptionBuffer; - int tcpSockOpt = 0; - int tcpTmFlags = 0; + SimpleRingBuffer ringBuffer; + std::vector validPacketIds; + SpacePacketParser* spacePacketParser = nullptr; + uint8_t lastRingBufferSize = 0; - void handleServerOperation(socket_t connSocket); - ReturnValue_t handleTcReception(size_t bytesRecvd); - ReturnValue_t handleTmSending(socket_t connSocket); + virtual void handleServerOperation(socket_t& connSocket); + ReturnValue_t handleTcReception(uint8_t* spacePacket, size_t packetSize); + ReturnValue_t handleTmSending(socket_t connSocket, bool& tmSent); + ReturnValue_t handleTcRingBufferData(size_t availableReadData); + void handleSocketError(ConstStorageAccessor& accessor); +#if defined PLATFORM_WIN + void setSocketNonBlocking(socket_t& connSocket); +#endif }; #endif /* FSFW_OSAL_COMMON_TCP_TMTC_SERVER_H_ */ From b1a9c90087bad07c81f9f96594edf7e2fa51d077 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 28 Sep 2021 17:38:35 +0200 Subject: [PATCH 10/89] this should work for both OSes --- src/fsfw/osal/common/TcpTmTcServer.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/fsfw/osal/common/TcpTmTcServer.cpp b/src/fsfw/osal/common/TcpTmTcServer.cpp index 4348e21e..519df547 100644 --- a/src/fsfw/osal/common/TcpTmTcServer.cpp +++ b/src/fsfw/osal/common/TcpTmTcServer.cpp @@ -177,7 +177,7 @@ void TcpTmTcServer::handleServerOperation(socket_t& connSocket) { ringBuffer.writeData(receptionBuffer.data(), retval); } else if(retval < 0) { - int errorValue = GetLastError(); + int errorValue = getLastSocketError(); #if defined PLATFORM_UNIX int wouldBlockValue = EAGAIN; #elif defined PLATFORM_WIN @@ -387,6 +387,7 @@ void TcpTmTcServer::handleSocketError(ConstStorageAccessor &accessor) { } } +#if defined PLATFORM_WIN void TcpTmTcServer::setSocketNonBlocking(socket_t &connSocket) { u_long iMode = 1; int iResult = ioctlsocket(connSocket, FIONBIO, &iMode); @@ -402,3 +403,4 @@ void TcpTmTcServer::setSocketNonBlocking(socket_t &connSocket) { #endif } } +#endif From cffd77ed325aa24bef3f22bc85dbd573c2db362e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 28 Sep 2021 17:42:29 +0200 Subject: [PATCH 11/89] put functions in namespace --- src/fsfw/tmtcpacket/SpacePacket.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/fsfw/tmtcpacket/SpacePacket.h b/src/fsfw/tmtcpacket/SpacePacket.h index 67746859..fe8a1044 100644 --- a/src/fsfw/tmtcpacket/SpacePacket.h +++ b/src/fsfw/tmtcpacket/SpacePacket.h @@ -69,6 +69,8 @@ protected: SpacePacketData localData; }; +namespace spacepacket { + constexpr uint16_t getTcSpacePacketIdFromApid(uint16_t apid) { return (0x18 << 8) | (((apid >> 8) & 0x07) << 8) | (apid & 0x00ff); } @@ -77,4 +79,6 @@ constexpr uint16_t getTmSpacePacketIdFromApid(uint16_t apid) { return (0x08 << 8) | (((apid >> 8) & 0x07) << 8) | (apid & 0x00ff); } +} + #endif /* SPACEPACKET_H_ */ From 0a6a32a13003103ee6462d1c46f814e0c44ab07b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 29 Sep 2021 11:45:20 +0200 Subject: [PATCH 12/89] printout separation --- src/fsfw/osal/common/TcpTmTcServer.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/fsfw/osal/common/TcpTmTcServer.cpp b/src/fsfw/osal/common/TcpTmTcServer.cpp index 519df547..8b34b1a3 100644 --- a/src/fsfw/osal/common/TcpTmTcServer.cpp +++ b/src/fsfw/osal/common/TcpTmTcServer.cpp @@ -210,7 +210,11 @@ void TcpTmTcServer::handleServerOperation(socket_t& connSocket) { ReturnValue_t TcpTmTcServer::handleTcReception(uint8_t* spacePacket, size_t packetSize) { if(wiretappingEnabled) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 sif::info << "Received TC:" << std::endl; +#else + sif::printInfo("Received TC:\n"); +#endif arrayprinter::print(spacePacket, packetSize); } @@ -278,7 +282,11 @@ ReturnValue_t TcpTmTcServer::handleTmSending(socket_t connSocket, bool& tmSent) return result; } if(wiretappingEnabled) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 sif::info << "Sending TM:" << std::endl; +#else + sif::printInfo("Sending TM:\n"); +#endif arrayprinter::print(storeAccessor.data(), storeAccessor.size()); } int retval = send(connSocket, From 9002c12cf157aec1d84984d0316d6bf94a60ba39 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 29 Sep 2021 11:55:20 +0200 Subject: [PATCH 13/89] update FSFW.h.in --- src/fsfw/FSFW.h.in | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/fsfw/FSFW.h.in b/src/fsfw/FSFW.h.in index f0eb9365..ddc69373 100644 --- a/src/fsfw/FSFW.h.in +++ b/src/fsfw/FSFW.h.in @@ -16,8 +16,21 @@ #cmakedefine FSFW_ADD_MONITORING #cmakedefine FSFW_ADD_SGP4_PROPAGATOR +// Can be used for low-level debugging of the SPI bus +#ifndef FSFW_HAL_SPI_WIRETAPPING +#define FSFW_HAL_SPI_WIRETAPPING 0 +#endif + #ifndef FSFW_HAL_L3GD20_GYRO_DEBUG -#define FSFW_HAL_L3GD20_GYRO_DEBUG 0 +#define FSFW_HAL_L3GD20_GYRO_DEBUG 0 #endif /* FSFW_HAL_L3GD20_GYRO_DEBUG */ +#ifndef FSFW_HAL_RM3100_MGM_DEBUG +#define FSFW_HAL_RM3100_MGM_DEBUG 0 +#endif /* FSFW_HAL_RM3100_MGM_DEBUG */ + +#ifndef FSFW_HAL_LIS3MDL_MGM_DEBUG +#define FSFW_HAL_LIS3MDL_MGM_DEBUG 0 +#endif /* FSFW_HAL_LIS3MDL_MGM_DEBUG */ + #endif /* FSFW_FSFW_H_ */ From faa7e1e24f1f6943111b1445db01b70870d2e717 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 29 Sep 2021 12:00:59 +0200 Subject: [PATCH 14/89] default values for PUS c config --- src/fsfw/FSFW.h.in | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/fsfw/FSFW.h.in b/src/fsfw/FSFW.h.in index ddc69373..e2591197 100644 --- a/src/fsfw/FSFW.h.in +++ b/src/fsfw/FSFW.h.in @@ -16,6 +16,14 @@ #cmakedefine FSFW_ADD_MONITORING #cmakedefine FSFW_ADD_SGP4_PROPAGATOR +#ifndef FSFW_USE_PUS_C_TELEMETRY +#define FSFW_USE_PUS_C_TELEMETRY 1 +#endif + +#ifndef FSFW_USE_PUS_C_TELECOMMANDS +#define FSFW_USE_PUS_C_TELECOMMANDS 1 +#endif + // Can be used for low-level debugging of the SPI bus #ifndef FSFW_HAL_SPI_WIRETAPPING #define FSFW_HAL_SPI_WIRETAPPING 0 From f388878b99bd30d1faa8429a7f64c300c4cecb23 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 29 Sep 2021 12:05:15 +0200 Subject: [PATCH 15/89] added more defines --- src/fsfw/FSFW.h.in | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/fsfw/FSFW.h.in b/src/fsfw/FSFW.h.in index e2591197..512a25be 100644 --- a/src/fsfw/FSFW.h.in +++ b/src/fsfw/FSFW.h.in @@ -14,19 +14,39 @@ #cmakedefine FSFW_ADD_COORDINATES #cmakedefine FSFW_ADD_PUS #cmakedefine FSFW_ADD_MONITORING -#cmakedefine FSFW_ADD_SGP4_PROPAGATOR +#cmakedefine FSFW_ADD_SGP4_PROPAGATOR0 + +// FSFW core defines + +#ifndef FSFW_CPP_OSTREAM_ENABLED +#define FSFW_CPP_OSTREAM_ENABLED 1 +#endif /* FSFW_CPP_OSTREAM_ENABLED */ + +#ifndef FSFW_VERBOSE_LEVEL +#define FSFW_VERBOSE_LEVEL 1 +#endif /* FSFW_VERBOSE_LEVEL */ + +#ifndef FSFW_USE_REALTIME_FOR_LINUX +#define FSFW_USE_REALTIME_FOR_LINUX 0 +#endif /* FSFW_USE_REALTIME_FOR_LINUX */ + +#ifndef FSFW_NO_C99_IO +#define FSFW_NO_C99_IO 0 +#endif /* FSFW_NO_C99_IO */ #ifndef FSFW_USE_PUS_C_TELEMETRY #define FSFW_USE_PUS_C_TELEMETRY 1 -#endif +#endif /* FSFW_USE_PUS_C_TELEMETRY */ #ifndef FSFW_USE_PUS_C_TELECOMMANDS #define FSFW_USE_PUS_C_TELECOMMANDS 1 #endif +// FSFW HAL defines + // Can be used for low-level debugging of the SPI bus #ifndef FSFW_HAL_SPI_WIRETAPPING -#define FSFW_HAL_SPI_WIRETAPPING 0 +#define FSFW_HAL_SPI_WIRETAPPING 0 #endif #ifndef FSFW_HAL_L3GD20_GYRO_DEBUG From febe3cc4d45ac2a324a0d956e655a988a79abf68 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 29 Sep 2021 12:05:24 +0200 Subject: [PATCH 16/89] define fix --- src/fsfw/FSFW.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsfw/FSFW.h.in b/src/fsfw/FSFW.h.in index 512a25be..7e52b646 100644 --- a/src/fsfw/FSFW.h.in +++ b/src/fsfw/FSFW.h.in @@ -14,7 +14,7 @@ #cmakedefine FSFW_ADD_COORDINATES #cmakedefine FSFW_ADD_PUS #cmakedefine FSFW_ADD_MONITORING -#cmakedefine FSFW_ADD_SGP4_PROPAGATOR0 +#cmakedefine FSFW_ADD_SGP4_PROPAGATOR // FSFW core defines From 5749e159e4f487dbe0c2fe7b66811ee3f1d21cc7 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 7 Oct 2021 10:39:16 +0200 Subject: [PATCH 17/89] minor updates for PUS services --- src/fsfw/pus/Service5EventReporting.cpp | 10 ++++++---- src/fsfw/pus/Service8FunctionManagement.cpp | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/fsfw/pus/Service5EventReporting.cpp b/src/fsfw/pus/Service5EventReporting.cpp index 36aa7e70..2293ab20 100644 --- a/src/fsfw/pus/Service5EventReporting.cpp +++ b/src/fsfw/pus/Service5EventReporting.cpp @@ -41,8 +41,7 @@ ReturnValue_t Service5EventReporting::performService() { } } #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::debug << "Service5EventReporting::generateEventReport:" - " Too many events" << std::endl; + sif::warning << "Service5EventReporting::generateEventReport: Too many events" << std::endl; #endif return HasReturnvaluesIF::RETURN_OK; } @@ -64,8 +63,11 @@ ReturnValue_t Service5EventReporting::generateEventReport( requestQueue->getDefaultDestination(),requestQueue->getId()); if(result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::debug << "Service5EventReporting::generateEventReport:" - " Could not send TM packet" << std::endl; + sif::warning << "Service5EventReporting::generateEventReport: " + "Could not send TM packet" << std::endl; +#else + sif::printWarning("Service5EventReporting::generateEventReport: " + "Could not send TM packet\n"); #endif } return result; diff --git a/src/fsfw/pus/Service8FunctionManagement.cpp b/src/fsfw/pus/Service8FunctionManagement.cpp index 39e872a0..48820d6e 100644 --- a/src/fsfw/pus/Service8FunctionManagement.cpp +++ b/src/fsfw/pus/Service8FunctionManagement.cpp @@ -33,8 +33,8 @@ ReturnValue_t Service8FunctionManagement::getMessageQueueAndObject( if(tcDataLen < sizeof(object_id_t)) { return CommandingServiceBase::INVALID_TC; } - SerializeAdapter::deSerialize(objectId, &tcData, - &tcDataLen, SerializeIF::Endianness::BIG); + // Can't fail, size was checked before + SerializeAdapter::deSerialize(objectId, &tcData, &tcDataLen, SerializeIF::Endianness::BIG); return checkInterfaceAndAcquireMessageQueue(id,objectId); } From 76416f523d055807f5f2f8d7b57f38eaee0d7102 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 7 Oct 2021 10:44:44 +0200 Subject: [PATCH 18/89] better naming for parameter --- src/fsfw/returnvalues/HasReturnvaluesIF.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fsfw/returnvalues/HasReturnvaluesIF.h b/src/fsfw/returnvalues/HasReturnvaluesIF.h index 4a3835b6..e9321ace 100644 --- a/src/fsfw/returnvalues/HasReturnvaluesIF.h +++ b/src/fsfw/returnvalues/HasReturnvaluesIF.h @@ -22,9 +22,9 @@ public: * @param number * @return */ - static constexpr ReturnValue_t makeReturnCode(uint8_t interfaceId, + static constexpr ReturnValue_t makeReturnCode(uint8_t classId, uint8_t number) { - return (static_cast(interfaceId) << 8) + number; + return (static_cast(classId) << 8) + number; } }; From ade15ad16d9d03512b148fa83e1be14cb3d48570 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 7 Oct 2021 13:24:46 +0200 Subject: [PATCH 19/89] tests can now be built as part of FSFW This PR refactores the tests so they are built as part of the FSFW. This is done by adding Catch2 with the FetchContent directive. A future implementation might also use a system installation of Catch2 by first checking whether Catch2 can already be found as a package The custom configuration folder testcfg was moved from the user folder to the actual unittest folder. The tests can be built by setting the CMake FSFW_BUILD_UNITTESTS option to TRUE/ON. They are built with the static library and dropped inside the build folders fsfw directory. --- CMakeLists.txt | 129 +++++++++++++++++- README.md | 76 ++++++++++- scripts/coverage.py | 74 ++++++++++ tests/src/fsfw_tests/CMakeLists.txt | 2 +- .../internal/InternalUnitTester.cpp | 6 +- .../fsfw_tests/internal/osal/CMakeLists.txt | 6 +- .../internal/osal/testCmdExecutor.cpp | 1 + .../internal/osal/testCmdExecutor.h | 10 ++ .../osal/{IntTestMq.cpp => testMq.cpp} | 2 +- .../internal/osal/{IntTestMq.h => testMq.h} | 0 .../osal/{IntTestMutex.cpp => testMutex.cpp} | 2 +- .../osal/{IntTestMutex.h => testMutex.h} | 0 ...IntTestSemaphore.cpp => testSemaphore.cpp} | 2 +- .../{IntTestSemaphore.h => testSemaphore.h} | 0 tests/src/fsfw_tests/unit/CMakeLists.txt | 9 +- tests/src/fsfw_tests/unit/CatchFactory.h | 2 +- tests/src/fsfw_tests/unit/CatchRunner.cpp | 2 +- tests/src/fsfw_tests/unit/CatchRunner.h | 2 +- .../src/fsfw_tests/unit/action/CMakeLists.txt | 2 +- .../fsfw_tests/unit/container/CMakeLists.txt | 2 +- .../unit/datapoollocal/CMakeLists.txt | 2 +- .../unit/globalfunctions/CMakeLists.txt | 2 +- tests/src/fsfw_tests/unit/osal/CMakeLists.txt | 2 +- .../fsfw_tests/unit/serialize/CMakeLists.txt | 2 +- .../unit/storagemanager/CMakeLists.txt | 2 +- .../fsfw_tests/unit/testcfg/CMakeLists.txt | 28 ++++ .../fsfw_tests/unit}/testcfg/FSFWConfig.h.in | 39 +++--- .../fsfw_tests/unit/testcfg/OBSWConfig.h.in | 15 ++ .../fsfw_tests/unit}/testcfg/TestsConfig.h.in | 0 .../testcfg/devices/logicalAddresses.cpp | 0 .../unit}/testcfg/devices/logicalAddresses.h | 3 +- .../testcfg/devices/powerSwitcherList.cpp | 0 .../unit}/testcfg/devices/powerSwitcherList.h | 0 .../unit}/testcfg/events/subsystemIdRanges.h | 7 +- .../unit/testcfg/events/translateEvents.cpp | 15 ++ .../unit/testcfg/events/translateEvents.h | 8 ++ .../unit}/testcfg/ipc/MissionMessageTypes.cpp | 0 .../unit}/testcfg/ipc/MissionMessageTypes.h | 0 .../unit}/testcfg/objects/systemObjectList.h | 7 +- .../unit/testcfg/objects/translateObjects.cpp | 19 +++ .../unit/testcfg/objects/translateObjects.h | 8 ++ .../PollingSequenceFactory.cpp | 2 +- .../pollingsequence/PollingSequenceFactory.h | 0 .../unit}/testcfg/returnvalues/classIds.h | 3 +- .../fsfw_tests/unit}/testcfg/tmtc/apid.h | 1 + .../fsfw_tests/unit}/testcfg/tmtc/pusIds.h | 0 .../unit/timemanager/CMakeLists.txt | 2 +- .../fsfw_tests/unit/tmtcpacket/CMakeLists.txt | 2 +- tests/user/README.md | 19 --- tests/user/testcfg/CMakeLists.txt | 11 -- tests/user/testcfg/OBSWConfig.h.in | 8 -- 51 files changed, 429 insertions(+), 107 deletions(-) create mode 100755 scripts/coverage.py create mode 100644 tests/src/fsfw_tests/internal/osal/testCmdExecutor.cpp create mode 100644 tests/src/fsfw_tests/internal/osal/testCmdExecutor.h rename tests/src/fsfw_tests/internal/osal/{IntTestMq.cpp => testMq.cpp} (96%) rename tests/src/fsfw_tests/internal/osal/{IntTestMq.h => testMq.h} (100%) rename tests/src/fsfw_tests/internal/osal/{IntTestMutex.cpp => testMutex.cpp} (96%) rename tests/src/fsfw_tests/internal/osal/{IntTestMutex.h => testMutex.h} (100%) rename tests/src/fsfw_tests/internal/osal/{IntTestSemaphore.cpp => testSemaphore.cpp} (98%) rename tests/src/fsfw_tests/internal/osal/{IntTestSemaphore.h => testSemaphore.h} (100%) create mode 100644 tests/src/fsfw_tests/unit/testcfg/CMakeLists.txt rename tests/{user => src/fsfw_tests/unit}/testcfg/FSFWConfig.h.in (67%) create mode 100644 tests/src/fsfw_tests/unit/testcfg/OBSWConfig.h.in rename tests/{user => src/fsfw_tests/unit}/testcfg/TestsConfig.h.in (100%) rename tests/{user => src/fsfw_tests/unit}/testcfg/devices/logicalAddresses.cpp (100%) rename tests/{user => src/fsfw_tests/unit}/testcfg/devices/logicalAddresses.h (84%) rename tests/{user => src/fsfw_tests/unit}/testcfg/devices/powerSwitcherList.cpp (100%) rename tests/{user => src/fsfw_tests/unit}/testcfg/devices/powerSwitcherList.h (100%) rename tests/{user => src/fsfw_tests/unit}/testcfg/events/subsystemIdRanges.h (64%) create mode 100644 tests/src/fsfw_tests/unit/testcfg/events/translateEvents.cpp create mode 100644 tests/src/fsfw_tests/unit/testcfg/events/translateEvents.h rename tests/{user => src/fsfw_tests/unit}/testcfg/ipc/MissionMessageTypes.cpp (100%) rename tests/{user => src/fsfw_tests/unit}/testcfg/ipc/MissionMessageTypes.h (100%) rename tests/{user => src/fsfw_tests/unit}/testcfg/objects/systemObjectList.h (84%) create mode 100644 tests/src/fsfw_tests/unit/testcfg/objects/translateObjects.cpp create mode 100644 tests/src/fsfw_tests/unit/testcfg/objects/translateObjects.h rename tests/{user => src/fsfw_tests/unit}/testcfg/pollingsequence/PollingSequenceFactory.cpp (97%) rename tests/{user => src/fsfw_tests/unit}/testcfg/pollingsequence/PollingSequenceFactory.h (100%) rename tests/{user => src/fsfw_tests/unit}/testcfg/returnvalues/classIds.h (76%) rename tests/{user => src/fsfw_tests/unit}/testcfg/tmtc/apid.h (90%) rename tests/{user => src/fsfw_tests/unit}/testcfg/tmtc/pusIds.h (100%) delete mode 100644 tests/user/README.md delete mode 100644 tests/user/testcfg/CMakeLists.txt delete mode 100644 tests/user/testcfg/OBSWConfig.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ff66a6d..ff631201 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,9 @@ cmake_minimum_required(VERSION 3.13) +set(FSFW_VERSION 2) +set(FSFW_SUBVERSION 0) +set(FSFW_REVISION 0) + option(FSFW_GENERATE_SECTIONS "Generate function and data sections. Required to remove unused code" ON ) @@ -7,6 +11,11 @@ if(FSFW_GENERATE_SECTIONS) option(FSFW_REMOVE_UNUSED_CODE "Remove unused code" ON) endif() +option(FSFW_BUILD_UNITTESTS "Build unittest binary in addition to static library" OFF) +if(FSFW_BUILD_UNITTESTS) + option(FSFW_TESTS_GEN_COV "Generate coverage data for unittests" ON) +endif() + option(FSFW_WARNING_SHADOW_LOCAL_GCC "Enable -Wshadow=local warning in GCC" ON) # Options to exclude parts of the FSFW from compilation. option(FSFW_ADD_INTERNAL_TESTS "Add internal unit tests" ON) @@ -26,11 +35,57 @@ option(FSFW_ADD_TMSTORAGE "Compile with tm storage components" OFF) option(FSFW_ADD_SGP4_PROPAGATOR "Add SGP4 propagator code" OFF) set(LIB_FSFW_NAME fsfw) +set(FSFW_TEST_TGT fsfw-tests) + add_library(${LIB_FSFW_NAME}) + +if(FSFW_BUILD_UNITTESTS) + # Check whether the user has already installed Catch2 first + find_package(Catch2 3) + # Not installed, so use FetchContent to download and provide Catch2 + if(NOT Catch2_FOUND) + include(FetchContent) + + FetchContent_Declare( + Catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v3.0.0-preview3 + ) + + FetchContent_MakeAvailable(Catch2) + endif() + + configure_file(tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in tests/FSFWConfig.h) + configure_file(tests/src/fsfw_tests/unit/testcfg/TestsConfig.h.in tests/TestsConfig.h) + configure_file(tests/src/fsfw_tests/unit/testcfg/OBSWConfig.h.in tests/OBSWConfig.h) + add_executable(${FSFW_TEST_TGT}) + + if(FSFW_TESTS_GEN_COV) + include(FetchContent) + FetchContent_Declare( + cmake-modules + GIT_REPOSITORY https://github.com/bilke/cmake-modules.git + ) + FetchContent_MakeAvailable(cmake-modules) + list(APPEND CMAKE_MODULE_PATH ${cmake-modules_SOURCE_DIR}) + include(CodeCoverage) + endif() +endif() + set(FSFW_CORE_INC_PATH "inc") set_property(CACHE FSFW_OSAL PROPERTY STRINGS host linux rtems freertos) +# Configure Files +target_include_directories(${LIB_FSFW_NAME} PRIVATE + ${CMAKE_CURRENT_BINARY_DIR} +) +target_include_directories(${LIB_FSFW_NAME} INTERFACE + ${CMAKE_CURRENT_BINARY_DIR} +) +configure_file(src/fsfw/FSFW.h.in FSFW.h) +configure_file(src/fsfw/FSFWVersion.h.in FSFWVersion.h) + if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED True) @@ -63,29 +118,29 @@ endif() set(FSFW_OSAL_DEFINITION FSFW_OSAL_HOST) if(FSFW_OSAL MATCHES host) - set(OS_FSFW_NAME "Host") + set(FSFW_OS_NAME "Host") set(FSFW_OSAL_HOST ON) elseif(FSFW_OSAL MATCHES linux) - set(OS_FSFW_NAME "Linux") + set(FSFW_OS_NAME "Linux") set(FSFW_OSAL_LINUX ON) elseif(FSFW_OSAL MATCHES freertos) - set(OS_FSFW_NAME "FreeRTOS") + set(FSFW_OS_NAME "FreeRTOS") set(FSFW_OSAL_FREERTOS ON) target_link_libraries(${LIB_FSFW_NAME} PRIVATE ${LIB_OS_NAME} ) elseif(FSFW_OSAL STREQUAL rtems) - set(OS_FSFW_NAME "RTEMS") + set(FSFW_OS_NAME "RTEMS") set(FSFW_OSAL_RTEMS ON) else() message(WARNING "Invalid operating system for FSFW specified! Setting to host.." ) - set(OS_FSFW_NAME "Host") + set(FSFW_OS_NAME "Host") set(OS_FSFW "host") endif() -message(STATUS "Compiling FSFW for the ${OS_FSFW_NAME} operating system.") +message(STATUS "Compiling FSFW for the ${FSFW_OS_NAME} operating system.") add_subdirectory(src) add_subdirectory(tests) @@ -94,6 +149,66 @@ if(FSFW_ADD_HAL) endif() add_subdirectory(contrib) +if(FSFW_BUILD_UNITTESTS) + if(FSFW_TESTS_GEN_COV) + if(CMAKE_COMPILER_IS_GNUCXX) + include(CodeCoverage) + + # Remove quotes. + separate_arguments(COVERAGE_COMPILER_FLAGS + NATIVE_COMMAND "${COVERAGE_COMPILER_FLAGS}" + ) + + # Add compile options manually, we don't want coverage for Catch2 + target_compile_options(${FSFW_TEST_TGT} PRIVATE + "${COVERAGE_COMPILER_FLAGS}" + ) + target_compile_options(${LIB_FSFW_NAME} PRIVATE + "${COVERAGE_COMPILER_FLAGS}" + ) + + # Exclude directories here + if(WIN32) + set(GCOVR_ADDITIONAL_ARGS + "--exclude-throw-branches" + "--exclude-unreachable-branches" + ) + set(COVERAGE_EXCLUDES + "/c/msys64/mingw64/*" + ) + elseif(UNIX) + set(COVERAGE_EXCLUDES + "/usr/include/*" "/usr/bin/*" "Catch2/*" + ) + endif() + + target_link_options(${FSFW_TEST_TGT} PRIVATE + -fprofile-arcs + -ftest-coverage + ) + target_link_options(${LIB_FSFW_NAME} PRIVATE + -fprofile-arcs + -ftest-coverage + ) + + if(WIN32) + setup_target_for_coverage_gcovr_html( + NAME ${FSFW_TEST_TGT}_coverage + EXECUTABLE ${FSFW_TEST_TGT} + DEPENDENCIES ${FSFW_TEST_TGT} + ) + else() + setup_target_for_coverage_lcov( + NAME ${FSFW_TEST_TGT}_coverage + EXECUTABLE ${FSFW_TEST_TGT} + DEPENDENCIES ${FSFW_TEST_TGT} + ) + endif() + endif() + endif() + target_link_libraries(${FSFW_TEST_TGT} PRIVATE Catch2::Catch2 ${LIB_FSFW_NAME}) +endif() + # The project CMakeLists file has to set the FSFW_CONFIG_PATH and add it. # If this is not given, we include the default configuration and emit a warning. if(NOT FSFW_CONFIG_PATH) @@ -186,4 +301,4 @@ target_compile_options(${LIB_FSFW_NAME} PRIVATE target_link_libraries(${LIB_FSFW_NAME} PRIVATE ${FSFW_ADDITIONAL_LINK_LIBS} -) \ No newline at end of file +) diff --git a/README.md b/README.md index 48d2b8e7..a7ae0e20 100644 --- a/README.md +++ b/README.md @@ -22,17 +22,83 @@ Currently, the FSFW provides the following OSALs: - FreeRTOS - RTEMS -The recommended hardware is a microprocessor with more than 1 MB of RAM and 1 MB of non-volatile Memory. For reference, current applications use a Cobham Gaisler UT699 (LEON3FT), a ISISPACE IOBC or a Zynq-7020 SoC. The `fsfw` was also successfully run on the STM32H743ZI-Nucleo board and on a Raspberry Pi and is currently running on the active satellite mission Flying Laptop. +The recommended hardware is a microprocessor with more than 1 MB of RAM and 1 MB of non-volatile +memory. For reference, current applications use a Cobham Gaisler UT699 (LEON3FT), a +ISISPACE IOBC or a Zynq-7020 SoC. The `fsfw` was also successfully run on the +STM32H743ZI-Nucleo board and on a Raspberry Pi and is currently running on the active +satellite mission Flying Laptop. ## Getting started -The [FSFW example](https://egit.irs.uni-stuttgart.de/fsfw/fsfw_example) provides a good starting point and a demo to see the FSFW capabilities and build it with the Make or the CMake build system. It is recommended to evaluate the FSFW by building and playing around with the demo application. +The [Hosted FSFW example](https://egit.irs.uni-stuttgart.de/fsfw/fsfw-example-hosted) provides a +good starting point and a demo to see the FSFW capabilities. +It is recommended to get started by building and playing around with the demo application. +There are also other examples provided for all OSALs using the popular embedded platforms +Raspberry Pi, Beagle Bone Black and STM32H7. -Generally, the FSFW is included in a project by compiling the FSFW sources and providing -a configuration folder and adding it to the include path. There are some functions like `printChar` which are different depending on the target architecture and need to be implemented by the mission developer. +Generally, the FSFW is included in a project by providing +a configuration folder, building the static library and linking against it. +There are some functions like `printChar` which are different depending on the target architecture +and need to be implemented by the mission developer. A template configuration folder was provided and can be copied into the project root to have -a starting point. The [configuration section](doc/README-config.md#top) provides more specific information about the possible options. +a starting point. The [configuration section](doc/README-config.md#top) provides more specific +information about the possible options. + +## Adding the library + +The following steps show how to add and use FSFW components. It is still recommended to +try out the example mentioned above to get started, but the following steps show how to +add and link against the FSFW library in general. + +1. Add this repository as a submodule + + ```sh + git submodule add https://egit.irs.uni-stuttgart.de/fsfw/fsfw.git fsfw + ``` + +2. Add the following directive inside the uppermost `CMakeLists.txt` file of your project + + ```cmake + add_subdirectory(fsfw) + ``` + +3. Make sure to provide a configuration folder and supply the path to that folder with + the `FSFW_CONFIG_PATH` CMake variable from the uppermost `CMakeLists.txt` file. + It is also necessary to provide the `printChar` function. You can find an example + implementation for a hosted build + [here](https://egit.irs.uni-stuttgart.de/fsfw/fsfw-example-hosted/src/branch/master/bsp_hosted/utility/printChar.c). + +4. Link against the FSFW library + + ```cmake + target_link_libraries( PRIVATE fsfw) + ``` + +5. It should now be possible use the FSFW as a static library from the user code. + +## Building the unittests + +The FSFW also has unittests which use the [Catch2 library](https://github.com/catchorg/Catch2). +These are built by setting the CMake option `FSFW_BUILD_UNITTESTS` to `ON` or `TRUE` +from your project `CMakeLists.txt` file or from the command line. + +The fsfw-tests binary will be built as part of the static library and dropped alongside it inside +the `fsfw` folder of the build folder. + +If the unittests are built, the library and the tests will be built with coverage information by +default. This can be disabled by setting the `FSFW_TESTS_COV_GEN` option to `OFF` or `FALSE`. + +Coverage data in HTML format can be generated using the `CodeCoverage` +[CMake module](https://github.com/bilke/cmake-modules/tree/master). +To build the unittests, run them and then generare the coverage data in this format, +the following command can be used inside the build directory after the build system was set up + +```sh +cmake --build . -- fsfw-tests_coverage -j +``` + +The `coverage.py` script located in the `script` folder can also be used to do this conveniently. ## Index diff --git a/scripts/coverage.py b/scripts/coverage.py new file mode 100755 index 00000000..d15c3154 --- /dev/null +++ b/scripts/coverage.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -* +"""Small portable helper script to generate LCOV HTML coverage data""" +import os +import platform +import sys +import time +import argparse +from typing import List + + +"""Copy this helper script into your project folder. It will try to determine a CMake build folder +and then attempt to build your project with coverage information. + +See Unittest documentation at https://egit.irs.uni-stuttgart.de/fsfw/fsfw for more +information how to set up the build folder. +""" +def main(): + + parser = argparse.ArgumentParser(description="Processing arguments for LCOV helper script.") + + build_dir_list = [] + for directory in os.listdir("."): + if os.path.isdir(directory): + os.chdir(directory) + check_for_cmake_build_dir(build_dir_list) + os.chdir("..") + + if len(build_dir_list) == 0: + print("No valid CMake build directory found. Trying to set up hosted build") + build_directory = 'build-Debug-Host' + os.mkdir(build_directory) + os.chdir(build_directory) + os.system('cmake -DFSFW_OSAL=host -DFSFW_BUILD_UNITTESTS=ON ..') + os.chdir('..') + elif len(build_dir_list) == 1: + build_directory = build_dir_list[0] + else: + print("Multiple build directories found!") + build_directory = determine_build_dir(build_dir_list) + perform_lcov_operation(build_directory) + + +def check_for_cmake_build_dir(build_dir_dict: list): + if os.path.isfile("CMakeCache.txt"): + build_dir_dict.append(os.getcwd()) + + +def perform_lcov_operation(directory): + os.chdir(directory) + os.system("cmake --build . -- fsfw-tests_coverage -j") + + +def determine_build_dir(build_dir_list: List[str]): + build_directory = "" + for idx, directory in enumerate(build_dir_list): + print(f"{idx + 1}: {directory}") + while True: + idx = input("Pick the directory to perform LCOV HTML generation by index: ") + if not idx.isdigit(): + print("Invalid input!") + continue + + idx = int(idx) + if idx > len(build_dir_list) or idx < 1: + print("Invalid input!") + continue + build_directory = build_dir_list[idx - 1] + break + return build_directory + + +if __name__ == "__main__": + main() diff --git a/tests/src/fsfw_tests/CMakeLists.txt b/tests/src/fsfw_tests/CMakeLists.txt index e4a6be80..80efdeaf 100644 --- a/tests/src/fsfw_tests/CMakeLists.txt +++ b/tests/src/fsfw_tests/CMakeLists.txt @@ -3,6 +3,6 @@ if(FSFW_ADD_INTERNAL_TESTS) add_subdirectory(internal) endif() -if(FSFW_ADD_UNITTESTS) +if(FSFW_BUILD_UNITTESTS) add_subdirectory(unit) endif() diff --git a/tests/src/fsfw_tests/internal/InternalUnitTester.cpp b/tests/src/fsfw_tests/internal/InternalUnitTester.cpp index 20998d64..3c8eec1e 100644 --- a/tests/src/fsfw_tests/internal/InternalUnitTester.cpp +++ b/tests/src/fsfw_tests/internal/InternalUnitTester.cpp @@ -1,9 +1,9 @@ #include "fsfw_tests/internal/InternalUnitTester.h" #include "fsfw_tests/internal/UnittDefinitions.h" -#include "fsfw_tests/internal/osal/IntTestMq.h" -#include "fsfw_tests/internal/osal/IntTestSemaphore.h" -#include "fsfw_tests/internal/osal/IntTestMutex.h" +#include "fsfw_tests/internal/osal/testMq.h" +#include "fsfw_tests/internal/osal/testSemaphore.h" +#include "fsfw_tests/internal/osal/testMutex.h" #include "fsfw_tests/internal/serialize/IntTestSerialization.h" #include "fsfw_tests/internal/globalfunctions/TestArrayPrinter.h" diff --git a/tests/src/fsfw_tests/internal/osal/CMakeLists.txt b/tests/src/fsfw_tests/internal/osal/CMakeLists.txt index 84316089..8d79d759 100644 --- a/tests/src/fsfw_tests/internal/osal/CMakeLists.txt +++ b/tests/src/fsfw_tests/internal/osal/CMakeLists.txt @@ -1,5 +1,5 @@ target_sources(${LIB_FSFW_NAME} PRIVATE - IntTestMq.cpp - IntTestMutex.cpp - IntTestSemaphore.cpp + testMq.cpp + testMutex.cpp + testSemaphore.cpp ) diff --git a/tests/src/fsfw_tests/internal/osal/testCmdExecutor.cpp b/tests/src/fsfw_tests/internal/osal/testCmdExecutor.cpp new file mode 100644 index 00000000..f0bed8ad --- /dev/null +++ b/tests/src/fsfw_tests/internal/osal/testCmdExecutor.cpp @@ -0,0 +1 @@ +#include "testCmdExecutor.h" diff --git a/tests/src/fsfw_tests/internal/osal/testCmdExecutor.h b/tests/src/fsfw_tests/internal/osal/testCmdExecutor.h new file mode 100644 index 00000000..4779dde9 --- /dev/null +++ b/tests/src/fsfw_tests/internal/osal/testCmdExecutor.h @@ -0,0 +1,10 @@ +#ifndef FSFW_TESTS_SRC_FSFW_TESTS_INTERNAL_OSAL_TESTCMDEXECUTOR_H_ +#define FSFW_TESTS_SRC_FSFW_TESTS_INTERNAL_OSAL_TESTCMDEXECUTOR_H_ + +namespace testcmdexec { + +} + + + +#endif /* FSFW_TESTS_SRC_FSFW_TESTS_INTERNAL_OSAL_TESTCMDEXECUTOR_H_ */ diff --git a/tests/src/fsfw_tests/internal/osal/IntTestMq.cpp b/tests/src/fsfw_tests/internal/osal/testMq.cpp similarity index 96% rename from tests/src/fsfw_tests/internal/osal/IntTestMq.cpp rename to tests/src/fsfw_tests/internal/osal/testMq.cpp index 6c31b354..8a252910 100644 --- a/tests/src/fsfw_tests/internal/osal/IntTestMq.cpp +++ b/tests/src/fsfw_tests/internal/osal/testMq.cpp @@ -1,4 +1,4 @@ -#include "fsfw_tests/internal/osal/IntTestMq.h" +#include "testMq.h" #include "fsfw_tests/internal/UnittDefinitions.h" #include diff --git a/tests/src/fsfw_tests/internal/osal/IntTestMq.h b/tests/src/fsfw_tests/internal/osal/testMq.h similarity index 100% rename from tests/src/fsfw_tests/internal/osal/IntTestMq.h rename to tests/src/fsfw_tests/internal/osal/testMq.h diff --git a/tests/src/fsfw_tests/internal/osal/IntTestMutex.cpp b/tests/src/fsfw_tests/internal/osal/testMutex.cpp similarity index 96% rename from tests/src/fsfw_tests/internal/osal/IntTestMutex.cpp rename to tests/src/fsfw_tests/internal/osal/testMutex.cpp index d9184cd8..9b50121a 100644 --- a/tests/src/fsfw_tests/internal/osal/IntTestMutex.cpp +++ b/tests/src/fsfw_tests/internal/osal/testMutex.cpp @@ -1,4 +1,4 @@ -#include "fsfw_tests/internal/osal/IntTestMutex.h" +#include "testMutex.h" #include "fsfw_tests/internal/UnittDefinitions.h" #include "fsfw/platform.h" diff --git a/tests/src/fsfw_tests/internal/osal/IntTestMutex.h b/tests/src/fsfw_tests/internal/osal/testMutex.h similarity index 100% rename from tests/src/fsfw_tests/internal/osal/IntTestMutex.h rename to tests/src/fsfw_tests/internal/osal/testMutex.h diff --git a/tests/src/fsfw_tests/internal/osal/IntTestSemaphore.cpp b/tests/src/fsfw_tests/internal/osal/testSemaphore.cpp similarity index 98% rename from tests/src/fsfw_tests/internal/osal/IntTestSemaphore.cpp rename to tests/src/fsfw_tests/internal/osal/testSemaphore.cpp index 4b28f961..458dcb04 100644 --- a/tests/src/fsfw_tests/internal/osal/IntTestSemaphore.cpp +++ b/tests/src/fsfw_tests/internal/osal/testSemaphore.cpp @@ -1,5 +1,5 @@ #include "fsfw/FSFW.h" -#include "fsfw_tests/internal/osal/IntTestSemaphore.h" +#include "testSemaphore.h" #include "fsfw_tests/internal/UnittDefinitions.h" #include "fsfw/tasks/SemaphoreFactory.h" diff --git a/tests/src/fsfw_tests/internal/osal/IntTestSemaphore.h b/tests/src/fsfw_tests/internal/osal/testSemaphore.h similarity index 100% rename from tests/src/fsfw_tests/internal/osal/IntTestSemaphore.h rename to tests/src/fsfw_tests/internal/osal/testSemaphore.h diff --git a/tests/src/fsfw_tests/unit/CMakeLists.txt b/tests/src/fsfw_tests/unit/CMakeLists.txt index f30e4b6b..164e3bde 100644 --- a/tests/src/fsfw_tests/unit/CMakeLists.txt +++ b/tests/src/fsfw_tests/unit/CMakeLists.txt @@ -1,16 +1,17 @@ -target_sources(${TARGET_NAME} PRIVATE +target_sources(${FSFW_TEST_TGT} PRIVATE CatchDefinitions.cpp CatchFactory.cpp printChar.cpp ) -if(FSFW_CUSTOM_UNITTEST_RUNNER) - target_sources(${TARGET_NAME} PRIVATE +# if(FSFW_CUSTOM_UNITTEST_RUNNER) + target_sources(${FSFW_TEST_TGT} PRIVATE CatchRunner.cpp CatchSetup.cpp ) -endif() +# endif() +add_subdirectory(testcfg) add_subdirectory(action) add_subdirectory(container) add_subdirectory(osal) diff --git a/tests/src/fsfw_tests/unit/CatchFactory.h b/tests/src/fsfw_tests/unit/CatchFactory.h index 38ec46bd..cc14e3d9 100644 --- a/tests/src/fsfw_tests/unit/CatchFactory.h +++ b/tests/src/fsfw_tests/unit/CatchFactory.h @@ -1,7 +1,7 @@ #ifndef FSFW_CATCHFACTORY_H_ #define FSFW_CATCHFACTORY_H_ -#include "TestsConfig.h" +#include "tests/TestsConfig.h" #include "fsfw/objectmanager/SystemObjectIF.h" #include "fsfw/objectmanager/ObjectManager.h" diff --git a/tests/src/fsfw_tests/unit/CatchRunner.cpp b/tests/src/fsfw_tests/unit/CatchRunner.cpp index c96db7f4..1ea3ab35 100644 --- a/tests/src/fsfw_tests/unit/CatchRunner.cpp +++ b/tests/src/fsfw_tests/unit/CatchRunner.cpp @@ -14,7 +14,7 @@ extern int customSetup(); -int fsfwtest::customMain(int argc, char* argv[]) { +int main(int argc, char* argv[]) { customSetup(); // Catch internal function call diff --git a/tests/src/fsfw_tests/unit/CatchRunner.h b/tests/src/fsfw_tests/unit/CatchRunner.h index 720625c6..06ff07b6 100644 --- a/tests/src/fsfw_tests/unit/CatchRunner.h +++ b/tests/src/fsfw_tests/unit/CatchRunner.h @@ -7,7 +7,7 @@ namespace fsfwtest { * Can be called by upper level main() if default Catch2 main is overriden * @return */ -int customMain(int argc, char* argv[]); +//int customMain(int argc, char* argv[]); } diff --git a/tests/src/fsfw_tests/unit/action/CMakeLists.txt b/tests/src/fsfw_tests/unit/action/CMakeLists.txt index 0339000f..659f251a 100644 --- a/tests/src/fsfw_tests/unit/action/CMakeLists.txt +++ b/tests/src/fsfw_tests/unit/action/CMakeLists.txt @@ -1,3 +1,3 @@ -target_sources(${TARGET_NAME} PRIVATE +target_sources(${FSFW_TEST_TGT} PRIVATE TestActionHelper.cpp ) diff --git a/tests/src/fsfw_tests/unit/container/CMakeLists.txt b/tests/src/fsfw_tests/unit/container/CMakeLists.txt index 966c5834..5dae974c 100644 --- a/tests/src/fsfw_tests/unit/container/CMakeLists.txt +++ b/tests/src/fsfw_tests/unit/container/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(${TARGET_NAME} PRIVATE +target_sources(${FSFW_TEST_TGT} PRIVATE RingBufferTest.cpp TestArrayList.cpp TestDynamicFifo.cpp diff --git a/tests/src/fsfw_tests/unit/datapoollocal/CMakeLists.txt b/tests/src/fsfw_tests/unit/datapoollocal/CMakeLists.txt index 1c98e7dc..bf465282 100644 --- a/tests/src/fsfw_tests/unit/datapoollocal/CMakeLists.txt +++ b/tests/src/fsfw_tests/unit/datapoollocal/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(${TARGET_NAME} PRIVATE +target_sources(${FSFW_TEST_TGT} PRIVATE LocalPoolVariableTest.cpp LocalPoolVectorTest.cpp DataSetTest.cpp diff --git a/tests/src/fsfw_tests/unit/globalfunctions/CMakeLists.txt b/tests/src/fsfw_tests/unit/globalfunctions/CMakeLists.txt index 617c7f5a..209ce75f 100644 --- a/tests/src/fsfw_tests/unit/globalfunctions/CMakeLists.txt +++ b/tests/src/fsfw_tests/unit/globalfunctions/CMakeLists.txt @@ -1,3 +1,3 @@ -target_sources(${TARGET_NAME} PRIVATE +target_sources(${FSFW_TEST_TGT} PRIVATE testDleEncoder.cpp ) diff --git a/tests/src/fsfw_tests/unit/osal/CMakeLists.txt b/tests/src/fsfw_tests/unit/osal/CMakeLists.txt index 5ca5e400..293be2e8 100644 --- a/tests/src/fsfw_tests/unit/osal/CMakeLists.txt +++ b/tests/src/fsfw_tests/unit/osal/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(${TARGET_NAME} PRIVATE +target_sources(${FSFW_TEST_TGT} PRIVATE TestMessageQueue.cpp TestSemaphore.cpp ) diff --git a/tests/src/fsfw_tests/unit/serialize/CMakeLists.txt b/tests/src/fsfw_tests/unit/serialize/CMakeLists.txt index 5a9d9a0f..96c80f4a 100644 --- a/tests/src/fsfw_tests/unit/serialize/CMakeLists.txt +++ b/tests/src/fsfw_tests/unit/serialize/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(${TARGET_NAME} PRIVATE +target_sources(${FSFW_TEST_TGT} PRIVATE TestSerialBufferAdapter.cpp TestSerialization.cpp TestSerialLinkedPacket.cpp diff --git a/tests/src/fsfw_tests/unit/storagemanager/CMakeLists.txt b/tests/src/fsfw_tests/unit/storagemanager/CMakeLists.txt index ed7be7d5..7b6280df 100644 --- a/tests/src/fsfw_tests/unit/storagemanager/CMakeLists.txt +++ b/tests/src/fsfw_tests/unit/storagemanager/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(${TARGET_NAME} PRIVATE +target_sources(${FSFW_TEST_TGT} PRIVATE TestNewAccessor.cpp TestPool.cpp ) diff --git a/tests/src/fsfw_tests/unit/testcfg/CMakeLists.txt b/tests/src/fsfw_tests/unit/testcfg/CMakeLists.txt new file mode 100644 index 00000000..3272958a --- /dev/null +++ b/tests/src/fsfw_tests/unit/testcfg/CMakeLists.txt @@ -0,0 +1,28 @@ +target_sources(${FSFW_TEST_TGT} PRIVATE + ipc/MissionMessageTypes.cpp + pollingsequence/PollingSequenceFactory.cpp +) + +# Add include paths for the executable +target_include_directories(${FSFW_TEST_TGT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} +) + +# These translation files are actually not that relevant for the tests. However, the FSFW tests +# compile against a user-configured variant of the FSFW, which might be configured to include +# translation information. Therefore, empty dummy translation files are compiled here +# so the tests compile in any case. + +# If a special translation file for object IDs exists, compile it. +if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/objects/translateObjects.cpp") + target_sources(${FSFW_TEST_TGT} 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(${FSFW_TEST_TGT} PRIVATE + events/translateEvents.cpp + ) +endif() \ No newline at end of file diff --git a/tests/user/testcfg/FSFWConfig.h.in b/tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in similarity index 67% rename from tests/user/testcfg/FSFWConfig.h.in rename to tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in index d38f0648..d03ec3e5 100644 --- a/tests/user/testcfg/FSFWConfig.h.in +++ b/tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in @@ -7,33 +7,30 @@ //! Used to determine whether C++ ostreams are used which can increase //! the binary size significantly. If this is disabled, //! the C stdio functions can be used alternatively -#define FSFW_CPP_OSTREAM_ENABLED 0 +#define FSFW_CPP_OSTREAM_ENABLED 0 -//! More FSFW related printouts. Useful for development. -#define FSFW_ENHANCED_PRINTOUT 0 +//! More FSFW related printouts depending on level. Useful for development. +#define FSFW_VERBOSE_LEVEL 1 //! Can be used to completely disable printouts, even the C stdio ones. -//! By default, printouts will be disabled for the unit tests. -#if FSFW_CPP_OSTREAM_ENABLED == 0 && FSFW_ENHANCED_PRINTOUT == 0 - #ifndef FSFW_DISABLE_PRINTOUT - #define FSFW_DISABLE_PRINTOUT 1 - #endif +#if FSFW_CPP_OSTREAM_ENABLED == 0 && FSFW_VERBOSE_LEVEL == 0 + #define FSFW_DISABLE_PRINTOUT 0 #endif -//! Can be used to enable additional debugging printouts for developing the FSFW -#define FSFW_PRINT_VERBOSITY_LEVEL 0 +#define FSFW_USE_PUS_C_TELEMETRY 1 +#define FSFW_USE_PUS_C_TELECOMMANDS 1 //! Can be used to disable the ANSI color sequences for C stdio. -#define FSFW_COLORED_OUTPUT 0 +#define FSFW_COLORED_OUTPUT 1 //! If FSFW_OBJ_EVENT_TRANSLATION is set to one, //! additional output which requires the translation files translateObjects //! and translateEvents (and their compiled source files) -#define FSFW_OBJ_EVENT_TRANSLATION 0 +#define FSFW_OBJ_EVENT_TRANSLATION 0 #if FSFW_OBJ_EVENT_TRANSLATION == 1 //! Specify whether info events are printed too. -#define FSFW_DEBUG_INFO 1 +#define FSFW_DEBUG_INFO 1 #include "objects/translateObjects.h" #include "events/translateEvents.h" #else @@ -41,22 +38,22 @@ //! When using the newlib nano library, C99 support for stdio facilities //! will not be provided. This define should be set to 1 if this is the case. -#define FSFW_NO_C99_IO 1 +#define FSFW_NO_C99_IO 1 //! Specify whether a special mode store is used for Subsystem components. -#define FSFW_USE_MODESTORE 0 +#define FSFW_USE_MODESTORE 0 //! Defines if the real time scheduler for linux should be used. //! If set to 0, this will also disable priority settings for linux //! as most systems will not allow to set nice values without privileges //! For embedded linux system set this to 1. //! If set to 1 the binary needs "cap_sys_nice=eip" privileges to run -#define FSFW_USE_REALTIME_FOR_LINUX 1 +#define FSFW_USE_REALTIME_FOR_LINUX 1 namespace fsfwconfig { -//! Default timestamp size. The default timestamp will be an eight byte CDC -//! short timestamp. -static constexpr uint8_t FSFW_MISSION_TIMESTAMP_SIZE = 8; + +//! Default timestamp size. The default timestamp will be an seven byte CDC short timestamp. +static constexpr uint8_t FSFW_MISSION_TIMESTAMP_SIZE = 7; //! Configure the allocated pool sizes for the event manager. static constexpr size_t FSFW_EVENTMGMR_MATCHTREE_NODES = 240; @@ -65,13 +62,13 @@ static constexpr size_t FSFW_EVENTMGMR_RANGEMATCHERS = 120; //! Defines the FIFO depth of each commanding service base which //! also determines how many commands a CSB service can handle in one cycle -//! simulataneously. This will increase the required RAM for +//! simultaneously. This will increase the required RAM for //! each CSB service ! static constexpr uint8_t FSFW_CSB_FIFO_DEPTH = 6; static constexpr size_t FSFW_PRINT_BUFFER_SIZE = 124; -static constexpr size_t FSFW_MAX_TM_PACKET_SIZE = 1500; +static constexpr size_t FSFW_MAX_TM_PACKET_SIZE = 2048; } diff --git a/tests/src/fsfw_tests/unit/testcfg/OBSWConfig.h.in b/tests/src/fsfw_tests/unit/testcfg/OBSWConfig.h.in new file mode 100644 index 00000000..5d8a9255 --- /dev/null +++ b/tests/src/fsfw_tests/unit/testcfg/OBSWConfig.h.in @@ -0,0 +1,15 @@ +#ifndef CONFIG_TMTC_TMTCSIZE_H_ +#define CONFIG_TMTC_TMTCSIZE_H_ + +#include +#include + +#define OBSW_PRINT_MISSED_DEADLINES 0 +#define OBSW_VERBOSE_LEVEL 0 +#define OBSW_ADD_TEST_CODE 1 + +namespace config { +static constexpr uint32_t MAX_STORED_TELECOMMANDS = 2000; +} + +#endif /* CONFIG_TMTC_TMTCSIZE_H_ */ diff --git a/tests/user/testcfg/TestsConfig.h.in b/tests/src/fsfw_tests/unit/testcfg/TestsConfig.h.in similarity index 100% rename from tests/user/testcfg/TestsConfig.h.in rename to tests/src/fsfw_tests/unit/testcfg/TestsConfig.h.in diff --git a/tests/user/testcfg/devices/logicalAddresses.cpp b/tests/src/fsfw_tests/unit/testcfg/devices/logicalAddresses.cpp similarity index 100% rename from tests/user/testcfg/devices/logicalAddresses.cpp rename to tests/src/fsfw_tests/unit/testcfg/devices/logicalAddresses.cpp diff --git a/tests/user/testcfg/devices/logicalAddresses.h b/tests/src/fsfw_tests/unit/testcfg/devices/logicalAddresses.h similarity index 84% rename from tests/user/testcfg/devices/logicalAddresses.h rename to tests/src/fsfw_tests/unit/testcfg/devices/logicalAddresses.h index cdf87025..a0240037 100644 --- a/tests/user/testcfg/devices/logicalAddresses.h +++ b/tests/src/fsfw_tests/unit/testcfg/devices/logicalAddresses.h @@ -2,7 +2,8 @@ #define CONFIG_DEVICES_LOGICALADDRESSES_H_ #include -#include +#include "common/devices/commonAddresses.h" + #include namespace addresses { diff --git a/tests/user/testcfg/devices/powerSwitcherList.cpp b/tests/src/fsfw_tests/unit/testcfg/devices/powerSwitcherList.cpp similarity index 100% rename from tests/user/testcfg/devices/powerSwitcherList.cpp rename to tests/src/fsfw_tests/unit/testcfg/devices/powerSwitcherList.cpp diff --git a/tests/user/testcfg/devices/powerSwitcherList.h b/tests/src/fsfw_tests/unit/testcfg/devices/powerSwitcherList.h similarity index 100% rename from tests/user/testcfg/devices/powerSwitcherList.h rename to tests/src/fsfw_tests/unit/testcfg/devices/powerSwitcherList.h diff --git a/tests/user/testcfg/events/subsystemIdRanges.h b/tests/src/fsfw_tests/unit/testcfg/events/subsystemIdRanges.h similarity index 64% rename from tests/user/testcfg/events/subsystemIdRanges.h rename to tests/src/fsfw_tests/unit/testcfg/events/subsystemIdRanges.h index 24eee819..c9c7c20d 100644 --- a/tests/user/testcfg/events/subsystemIdRanges.h +++ b/tests/src/fsfw_tests/unit/testcfg/events/subsystemIdRanges.h @@ -1,8 +1,10 @@ #ifndef CONFIG_EVENTS_SUBSYSTEMIDRANGES_H_ #define CONFIG_EVENTS_SUBSYSTEMIDRANGES_H_ +#include "fsfw/events/fwSubsystemIdRanges.h" +#include "common/events/commonSubsystemIds.h" #include -#include + /** * @brief Custom subsystem IDs can be added here @@ -11,7 +13,8 @@ */ namespace SUBSYSTEM_ID { enum: uint8_t { - SUBSYSTEM_ID_START = FW_SUBSYSTEM_ID_RANGE, + SUBSYSTEM_ID_START = COMMON_SUBSYSTEM_ID_RANGE, + SUBSYSTEM_ID_END // [EXPORT] : [END] }; } diff --git a/tests/src/fsfw_tests/unit/testcfg/events/translateEvents.cpp b/tests/src/fsfw_tests/unit/testcfg/events/translateEvents.cpp new file mode 100644 index 00000000..47186727 --- /dev/null +++ b/tests/src/fsfw_tests/unit/testcfg/events/translateEvents.cpp @@ -0,0 +1,15 @@ +/** + * @brief Auto-generated event translation file. Contains 81 translations. + * @details + * Generated on: 2021-05-18 16:28:16 + */ +#include "translateEvents.h" + + +const char * translateEvents(Event event) { + switch( (event & 0xffff) ) { + default: + return "UNKNOWN_EVENT"; + } + return 0; +} diff --git a/tests/src/fsfw_tests/unit/testcfg/events/translateEvents.h b/tests/src/fsfw_tests/unit/testcfg/events/translateEvents.h new file mode 100644 index 00000000..9034dcf2 --- /dev/null +++ b/tests/src/fsfw_tests/unit/testcfg/events/translateEvents.h @@ -0,0 +1,8 @@ +#ifndef FSFWCONFIG_EVENTS_TRANSLATEEVENTS_H_ +#define FSFWCONFIG_EVENTS_TRANSLATEEVENTS_H_ + +#include + +const char * translateEvents(Event event); + +#endif /* FSFWCONFIG_EVENTS_TRANSLATEEVENTS_H_ */ diff --git a/tests/user/testcfg/ipc/MissionMessageTypes.cpp b/tests/src/fsfw_tests/unit/testcfg/ipc/MissionMessageTypes.cpp similarity index 100% rename from tests/user/testcfg/ipc/MissionMessageTypes.cpp rename to tests/src/fsfw_tests/unit/testcfg/ipc/MissionMessageTypes.cpp diff --git a/tests/user/testcfg/ipc/MissionMessageTypes.h b/tests/src/fsfw_tests/unit/testcfg/ipc/MissionMessageTypes.h similarity index 100% rename from tests/user/testcfg/ipc/MissionMessageTypes.h rename to tests/src/fsfw_tests/unit/testcfg/ipc/MissionMessageTypes.h diff --git a/tests/user/testcfg/objects/systemObjectList.h b/tests/src/fsfw_tests/unit/testcfg/objects/systemObjectList.h similarity index 84% rename from tests/user/testcfg/objects/systemObjectList.h rename to tests/src/fsfw_tests/unit/testcfg/objects/systemObjectList.h index efd21e0d..bd0daa62 100644 --- a/tests/user/testcfg/objects/systemObjectList.h +++ b/tests/src/fsfw_tests/unit/testcfg/objects/systemObjectList.h @@ -1,8 +1,9 @@ #ifndef HOSTED_CONFIG_OBJECTS_SYSTEMOBJECTLIST_H_ #define HOSTED_CONFIG_OBJECTS_SYSTEMOBJECTLIST_H_ +#include "fsfw/objectmanager/frameworkObjects.h" +#include "common/objects/commonObjectsList.h" #include -#include // The objects will be instantiated in the ID order namespace objects { @@ -11,10 +12,6 @@ namespace objects { FSFW_CONFIG_RESERVED_START = PUS_SERVICE_1_VERIFICATION, FSFW_CONFIG_RESERVED_END = TM_STORE, - CCSDS_DISTRIBUTOR = 10, - PUS_DISTRIBUTOR = 11, - TM_FUNNEL = 12, - UDP_BRIDGE = 15, UDP_POLLING_TASK = 16, diff --git a/tests/src/fsfw_tests/unit/testcfg/objects/translateObjects.cpp b/tests/src/fsfw_tests/unit/testcfg/objects/translateObjects.cpp new file mode 100644 index 00000000..63636ced --- /dev/null +++ b/tests/src/fsfw_tests/unit/testcfg/objects/translateObjects.cpp @@ -0,0 +1,19 @@ +/** + * @brief Auto-generated object translation file. + * @details + * Contains 69 translations. + * Generated on: 2021-05-18 16:37:37 + */ +#include "translateObjects.h" + +const char *NO_OBJECT_STRING = "NO_OBJECT"; + +const char* translateObject(object_id_t object) { + switch( (object & 0xFFFFFFFF) ) { + case 0xFFFFFFFF: + return NO_OBJECT_STRING; + default: + return "UNKNOWN_OBJECT"; + } + return 0; +} diff --git a/tests/src/fsfw_tests/unit/testcfg/objects/translateObjects.h b/tests/src/fsfw_tests/unit/testcfg/objects/translateObjects.h new file mode 100644 index 00000000..dbf5b468 --- /dev/null +++ b/tests/src/fsfw_tests/unit/testcfg/objects/translateObjects.h @@ -0,0 +1,8 @@ +#ifndef FSFWCONFIG_OBJECTS_TRANSLATEOBJECTS_H_ +#define FSFWCONFIG_OBJECTS_TRANSLATEOBJECTS_H_ + +#include + +const char* translateObject(object_id_t object); + +#endif /* FSFWCONFIG_OBJECTS_TRANSLATEOBJECTS_H_ */ diff --git a/tests/user/testcfg/pollingsequence/PollingSequenceFactory.cpp b/tests/src/fsfw_tests/unit/testcfg/pollingsequence/PollingSequenceFactory.cpp similarity index 97% rename from tests/user/testcfg/pollingsequence/PollingSequenceFactory.cpp rename to tests/src/fsfw_tests/unit/testcfg/pollingsequence/PollingSequenceFactory.cpp index e3ee874a..1d29ef86 100644 --- a/tests/user/testcfg/pollingsequence/PollingSequenceFactory.cpp +++ b/tests/src/fsfw_tests/unit/testcfg/pollingsequence/PollingSequenceFactory.cpp @@ -1,6 +1,6 @@ #include "PollingSequenceFactory.h" -#include +#include "tests/TestsConfig.h" #include #include diff --git a/tests/user/testcfg/pollingsequence/PollingSequenceFactory.h b/tests/src/fsfw_tests/unit/testcfg/pollingsequence/PollingSequenceFactory.h similarity index 100% rename from tests/user/testcfg/pollingsequence/PollingSequenceFactory.h rename to tests/src/fsfw_tests/unit/testcfg/pollingsequence/PollingSequenceFactory.h diff --git a/tests/user/testcfg/returnvalues/classIds.h b/tests/src/fsfw_tests/unit/testcfg/returnvalues/classIds.h similarity index 76% rename from tests/user/testcfg/returnvalues/classIds.h rename to tests/src/fsfw_tests/unit/testcfg/returnvalues/classIds.h index 606cc60b..919b9628 100644 --- a/tests/user/testcfg/returnvalues/classIds.h +++ b/tests/src/fsfw_tests/unit/testcfg/returnvalues/classIds.h @@ -1,7 +1,8 @@ #ifndef CONFIG_RETURNVALUES_CLASSIDS_H_ #define CONFIG_RETURNVALUES_CLASSIDS_H_ -#include +#include "common/returnvalues/commonClassIds.h" +#include "fsfw/returnvalues/FwClassIds.h" /** * @brief CLASS_ID defintions which are required for custom returnvalues. diff --git a/tests/user/testcfg/tmtc/apid.h b/tests/src/fsfw_tests/unit/testcfg/tmtc/apid.h similarity index 90% rename from tests/user/testcfg/tmtc/apid.h rename to tests/src/fsfw_tests/unit/testcfg/tmtc/apid.h index c0231bca..0e633afb 100644 --- a/tests/user/testcfg/tmtc/apid.h +++ b/tests/src/fsfw_tests/unit/testcfg/tmtc/apid.h @@ -12,6 +12,7 @@ */ namespace apid { static const uint16_t DEFAULT_APID = 0x00; + static const uint16_t SOURCE_OBSW = 0x73; } diff --git a/tests/user/testcfg/tmtc/pusIds.h b/tests/src/fsfw_tests/unit/testcfg/tmtc/pusIds.h similarity index 100% rename from tests/user/testcfg/tmtc/pusIds.h rename to tests/src/fsfw_tests/unit/testcfg/tmtc/pusIds.h diff --git a/tests/src/fsfw_tests/unit/timemanager/CMakeLists.txt b/tests/src/fsfw_tests/unit/timemanager/CMakeLists.txt index 2c635711..6ce1c6c6 100644 --- a/tests/src/fsfw_tests/unit/timemanager/CMakeLists.txt +++ b/tests/src/fsfw_tests/unit/timemanager/CMakeLists.txt @@ -1,3 +1,3 @@ -target_sources(${TARGET_NAME} PRIVATE +target_sources(${FSFW_TEST_TGT} PRIVATE TestCountdown.cpp ) diff --git a/tests/src/fsfw_tests/unit/tmtcpacket/CMakeLists.txt b/tests/src/fsfw_tests/unit/tmtcpacket/CMakeLists.txt index a1a4c1b6..36838b24 100644 --- a/tests/src/fsfw_tests/unit/tmtcpacket/CMakeLists.txt +++ b/tests/src/fsfw_tests/unit/tmtcpacket/CMakeLists.txt @@ -1,3 +1,3 @@ -target_sources(${TARGET_NAME} PRIVATE +target_sources(${FSFW_TEST_TGT} PRIVATE PusTmTest.cpp ) diff --git a/tests/user/README.md b/tests/user/README.md deleted file mode 100644 index d6a4bb85..00000000 --- a/tests/user/README.md +++ /dev/null @@ -1,19 +0,0 @@ -## FSFW Testing - -This folder contains testing and unit testing components. - -### Instructions - -The easiest way to run the unittest contained in this folder is to follow -the steps in the [test repository](https://egit.irs.uni-stuttgart.de/fsfw/fsfw_tests). -This is recommended even if the goal is to set up a custom test repository to have -a starting point. - -To set up a custom test repository or project, following steps can be performed: - -1. Copy the user folder content into the project root. -2. Clone [Catch2](https://github.com/catchorg/Catch2) in the project root. -3. Use the `CMakeLists.txt` as a starting point to add tests and build the test - executable. - - diff --git a/tests/user/testcfg/CMakeLists.txt b/tests/user/testcfg/CMakeLists.txt deleted file mode 100644 index dbf0256f..00000000 --- a/tests/user/testcfg/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -target_sources(${TARGET_NAME} - PRIVATE - ipc/MissionMessageTypes.cpp - pollingsequence/PollingSequenceFactory.cpp -) - -# Add include paths for the executable -target_include_directories(${TARGET_NAME} - PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR} -) diff --git a/tests/user/testcfg/OBSWConfig.h.in b/tests/user/testcfg/OBSWConfig.h.in deleted file mode 100644 index 34eda31f..00000000 --- a/tests/user/testcfg/OBSWConfig.h.in +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef TESTCFG_OBSWCONFIG_H_ -#define TESTCFG_OBSWCONFIG_H_ - - - - - -#endif /* TESTCFG_OBSWCONFIG_H_ */ From cd6d616806d55c665152485d2521ec4d3919e2db Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 7 Oct 2021 13:26:31 +0200 Subject: [PATCH 20/89] using .h.in version fle now --- src/fsfw/FSFWVersion.h | 10 ---------- src/fsfw/FSFWVersion.h.in | 11 +++++++++++ 2 files changed, 11 insertions(+), 10 deletions(-) delete mode 100644 src/fsfw/FSFWVersion.h create mode 100644 src/fsfw/FSFWVersion.h.in diff --git a/src/fsfw/FSFWVersion.h b/src/fsfw/FSFWVersion.h deleted file mode 100644 index c581a85c..00000000 --- a/src/fsfw/FSFWVersion.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef FSFW_VERSION_H_ -#define FSFW_VERSION_H_ - -const char* const FSFW_VERSION_NAME = "ASTP"; - -#define FSFW_VERSION 2 -#define FSFW_SUBVERSION 0 -#define FSFW_REVISION 0 - -#endif /* FSFW_VERSION_H_ */ diff --git a/src/fsfw/FSFWVersion.h.in b/src/fsfw/FSFWVersion.h.in new file mode 100644 index 00000000..a858d703 --- /dev/null +++ b/src/fsfw/FSFWVersion.h.in @@ -0,0 +1,11 @@ +#ifndef FSFW_VERSION_H_ +#define FSFW_VERSION_H_ + +const char* const FSFW_VERSION_NAME = "ASTP"; + +// Versioning is kept in project CMakeLists.txt file +#define FSFW_VERSION @FSFW_VERSION@ +#define FSFW_SUBVERSION @FSFW_SUBVERSION@ +#define FSFW_REVISION @FSFW_REVISION@ + +#endif /* FSFW_VERSION_H_ */ From dd1631a45623dc8cc3c96e1708f558bd1b4d0089 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 7 Oct 2021 14:20:34 +0200 Subject: [PATCH 21/89] updated CMakeLists.txt - More information about FSFW build --- CMakeLists.txt | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ff631201..fd6850a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,7 @@ set(FSFW_TEST_TGT fsfw-tests) add_library(${LIB_FSFW_NAME}) if(FSFW_BUILD_UNITTESTS) + message(STATUS "Building the FSFW unittests in addition to the static library") # Check whether the user has already installed Catch2 first find_package(Catch2 3) # Not installed, so use FetchContent to download and provide Catch2 @@ -61,12 +62,17 @@ if(FSFW_BUILD_UNITTESTS) add_executable(${FSFW_TEST_TGT}) if(FSFW_TESTS_GEN_COV) + message(STATUS "Generating coverage data for the library") + message(STATUS "Targets linking against ${LIB_FSFW_NAME} " + "will be compiled with coverage data as well" + ) include(FetchContent) FetchContent_Declare( cmake-modules GIT_REPOSITORY https://github.com/bilke/cmake-modules.git ) FetchContent_MakeAvailable(cmake-modules) + set(CMAKE_BUILD_TYPE "Debug") list(APPEND CMAKE_MODULE_PATH ${cmake-modules_SOURCE_DIR}) include(CodeCoverage) endif() @@ -190,6 +196,11 @@ if(FSFW_BUILD_UNITTESTS) -fprofile-arcs -ftest-coverage ) + # Need to specify this as an interface, otherwise there will the compile issues + target_link_options(${LIB_FSFW_NAME} INTERFACE + -fprofile-arcs + -ftest-coverage + ) if(WIN32) setup_target_for_coverage_gcovr_html( @@ -302,3 +313,16 @@ target_compile_options(${LIB_FSFW_NAME} PRIVATE target_link_libraries(${LIB_FSFW_NAME} PRIVATE ${FSFW_ADDITIONAL_LINK_LIBS} ) + +string(CONCAT POST_BUILD_COMMENT + "######################################################################\n" + "Building FSFW v${FSFW_VERSION}.${FSFW_SUBVERSION}.${FSFW_REVISION}, " + "Target OSAL: ${FSFW_OS_NAME}\n" + "######################################################################\n" +) + +add_custom_command( + TARGET ${LIB_FSFW_NAME} + POST_BUILD + COMMENT ${POST_BUILD_COMMENT} +) From 6ad7f51297bff44f07543c3875481388460a8179 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Fri, 8 Oct 2021 13:24:51 +0200 Subject: [PATCH 22/89] added bind call error string --- src/fsfw/osal/common/tcpipCommon.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/fsfw/osal/common/tcpipCommon.cpp b/src/fsfw/osal/common/tcpipCommon.cpp index 0fdbf867..2551496d 100644 --- a/src/fsfw/osal/common/tcpipCommon.cpp +++ b/src/fsfw/osal/common/tcpipCommon.cpp @@ -21,6 +21,9 @@ void tcpip::determineErrorStrings(Protocol protocol, ErrorSources errorSrc, std: if(errorSrc == ErrorSources::SETSOCKOPT_CALL) { srcString = "setsockopt call"; } + if(errorSrc == ErrorSources::BIND_CALL) { + srcString = "bind call"; + } else if(errorSrc == ErrorSources::SOCKET_CALL) { srcString = "socket call"; } From 9bcd701a50151491d3fe1b7d1c4d652556266cbd Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Fri, 8 Oct 2021 13:51:32 +0200 Subject: [PATCH 23/89] tcp server also parses TCs when client closes connection --- src/fsfw/osal/common/TcpTmTcServer.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/fsfw/osal/common/TcpTmTcServer.cpp b/src/fsfw/osal/common/TcpTmTcServer.cpp index 8b34b1a3..7e6853fc 100644 --- a/src/fsfw/osal/common/TcpTmTcServer.cpp +++ b/src/fsfw/osal/common/TcpTmTcServer.cpp @@ -168,7 +168,10 @@ void TcpTmTcServer::handleServerOperation(socket_t& connSocket) { tcpConfig.tcpFlags ); if(retval == 0) { - // Client closed connection + size_t availableReadData = ringBuffer.getAvailableReadData(); + if(availableReadData > lastRingBufferSize) { + handleTcRingBufferData(availableReadData); + } return; } else if(retval > 0) { From ad3238aa19ecbab79743a5db38e33f370591e198 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 13:48:17 +0200 Subject: [PATCH 24/89] removed problematic includes --- tests/src/fsfw_tests/unit/testcfg/events/subsystemIdRanges.h | 3 +-- tests/src/fsfw_tests/unit/testcfg/returnvalues/classIds.h | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/src/fsfw_tests/unit/testcfg/events/subsystemIdRanges.h b/tests/src/fsfw_tests/unit/testcfg/events/subsystemIdRanges.h index c9c7c20d..b88cd875 100644 --- a/tests/src/fsfw_tests/unit/testcfg/events/subsystemIdRanges.h +++ b/tests/src/fsfw_tests/unit/testcfg/events/subsystemIdRanges.h @@ -2,7 +2,6 @@ #define CONFIG_EVENTS_SUBSYSTEMIDRANGES_H_ #include "fsfw/events/fwSubsystemIdRanges.h" -#include "common/events/commonSubsystemIds.h" #include @@ -13,7 +12,7 @@ */ namespace SUBSYSTEM_ID { enum: uint8_t { - SUBSYSTEM_ID_START = COMMON_SUBSYSTEM_ID_RANGE, + SUBSYSTEM_ID_START = 0, SUBSYSTEM_ID_END // [EXPORT] : [END] }; } diff --git a/tests/src/fsfw_tests/unit/testcfg/returnvalues/classIds.h b/tests/src/fsfw_tests/unit/testcfg/returnvalues/classIds.h index 919b9628..1001d012 100644 --- a/tests/src/fsfw_tests/unit/testcfg/returnvalues/classIds.h +++ b/tests/src/fsfw_tests/unit/testcfg/returnvalues/classIds.h @@ -1,7 +1,6 @@ #ifndef CONFIG_RETURNVALUES_CLASSIDS_H_ #define CONFIG_RETURNVALUES_CLASSIDS_H_ -#include "common/returnvalues/commonClassIds.h" #include "fsfw/returnvalues/FwClassIds.h" /** From a827ec6a92b0cdf37138b084c182e7cd5cf866eb Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 13:51:08 +0200 Subject: [PATCH 25/89] removed another include --- tests/src/fsfw_tests/unit/testcfg/objects/systemObjectList.h | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/src/fsfw_tests/unit/testcfg/objects/systemObjectList.h b/tests/src/fsfw_tests/unit/testcfg/objects/systemObjectList.h index bd0daa62..accf0d81 100644 --- a/tests/src/fsfw_tests/unit/testcfg/objects/systemObjectList.h +++ b/tests/src/fsfw_tests/unit/testcfg/objects/systemObjectList.h @@ -2,7 +2,6 @@ #define HOSTED_CONFIG_OBJECTS_SYSTEMOBJECTLIST_H_ #include "fsfw/objectmanager/frameworkObjects.h" -#include "common/objects/commonObjectsList.h" #include // The objects will be instantiated in the ID order From e02ac0509702af5056a5f3b9199a96001856c50b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 13:57:00 +0200 Subject: [PATCH 26/89] fixed a bug for default cfg path --- CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fd6850a0..192134fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -223,9 +223,10 @@ endif() # The project CMakeLists file has to set the FSFW_CONFIG_PATH and add it. # If this is not given, we include the default configuration and emit a warning. if(NOT FSFW_CONFIG_PATH) - message(WARNING "Flight Software Framework configuration path not set!") - message(WARNING "Setting default configuration!") - add_subdirectory(defaultcfg/fsfwconfig) + message(WARNING "Flight Software Framework configuration path not set!") + set(DEF_CONF_PATH misc/defaultcfg/fsfwconfig) + message(WARNING "Setting default configuration from ${DEF_CONF_PATH} ..") + add_subdirectory(${DEF_CONF_PATH}) endif() # FSFW might be part of a possibly complicated folder structure, so we From c26c2a5a96e25ebb0b1352f0896a2ee456c7ae25 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 14:56:42 +0200 Subject: [PATCH 27/89] hardcoding config path --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 192134fd..847ea572 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,9 +56,8 @@ if(FSFW_BUILD_UNITTESTS) FetchContent_MakeAvailable(Catch2) endif() - configure_file(tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in tests/FSFWConfig.h) + set(FSFW_CONFIG_PATH tests/src/fsfw_tests/unit/testcfg) configure_file(tests/src/fsfw_tests/unit/testcfg/TestsConfig.h.in tests/TestsConfig.h) - configure_file(tests/src/fsfw_tests/unit/testcfg/OBSWConfig.h.in tests/OBSWConfig.h) add_executable(${FSFW_TEST_TGT}) if(FSFW_TESTS_GEN_COV) From ad117e07e0fb1875af3b4c960c724dc826348a02 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 15:03:03 +0200 Subject: [PATCH 28/89] FSFW_CONFIG_PATH update --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 847ea572..34f16d0f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -226,6 +226,7 @@ if(NOT FSFW_CONFIG_PATH) set(DEF_CONF_PATH misc/defaultcfg/fsfwconfig) message(WARNING "Setting default configuration from ${DEF_CONF_PATH} ..") add_subdirectory(${DEF_CONF_PATH}) + set(FSFW_CONFIG_PATH ${DEF_CONF_PATH}) endif() # FSFW might be part of a possibly complicated folder structure, so we From b00f61445d97b183456b5f778df32411002c745b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 15:07:52 +0200 Subject: [PATCH 29/89] works --- .gitignore | 2 ++ CMakeLists.txt | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index fbd138e9..d6efb9cf 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ .project .settings .metadata + +/build* diff --git a/CMakeLists.txt b/CMakeLists.txt index 34f16d0f..5000b9b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,9 @@ if(FSFW_BUILD_UNITTESTS) endif() set(FSFW_CONFIG_PATH tests/src/fsfw_tests/unit/testcfg) + configure_file(tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in FSFWConfig.h) configure_file(tests/src/fsfw_tests/unit/testcfg/TestsConfig.h.in tests/TestsConfig.h) + configure_file(tests/src/fsfw_tests/unit/testcfg/OBSWConfig.h.in OBSWConfig.h) add_executable(${FSFW_TEST_TGT}) if(FSFW_TESTS_GEN_COV) From 5798aa1e3abd55f94bc138ea26f93ef43644975b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 15:09:19 +0200 Subject: [PATCH 30/89] create project to suppress warning --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5000b9b0..eae1fc25 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,7 @@ if(FSFW_BUILD_UNITTESTS) configure_file(tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in FSFWConfig.h) configure_file(tests/src/fsfw_tests/unit/testcfg/TestsConfig.h.in tests/TestsConfig.h) configure_file(tests/src/fsfw_tests/unit/testcfg/OBSWConfig.h.in OBSWConfig.h) + project(${FSFW_TEST_TGT} CXX C) add_executable(${FSFW_TEST_TGT}) if(FSFW_TESTS_GEN_COV) From 1b6fa9822b35ad63d7347f5f836c7f9212a42736 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 15:40:29 +0200 Subject: [PATCH 31/89] this should work --- scripts/coverage.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/coverage.py b/scripts/coverage.py index d15c3154..71b6fb03 100755 --- a/scripts/coverage.py +++ b/scripts/coverage.py @@ -20,6 +20,8 @@ def main(): parser = argparse.ArgumentParser(description="Processing arguments for LCOV helper script.") build_dir_list = [] + if not os.path.isfile('README.md'): + os.chdir('..') for directory in os.listdir("."): if os.path.isdir(directory): os.chdir(directory) From fb67df6d7f447e651eac1e02f81ca80028500678 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 15:45:37 +0200 Subject: [PATCH 32/89] using testsconfig.h now --- tests/src/fsfw_tests/unit/CatchFactory.cpp | 1 + tests/src/fsfw_tests/unit/datapoollocal/DataSetTest.cpp | 1 + tests/src/fsfw_tests/unit/datapoollocal/LocalPoolOwnerBase.h | 2 +- .../src/fsfw_tests/unit/datapoollocal/LocalPoolVariableTest.cpp | 1 + tests/src/fsfw_tests/unit/datapoollocal/LocalPoolVectorTest.cpp | 1 + tests/src/fsfw_tests/unit/testcfg/CMakeLists.txt | 2 +- 6 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/src/fsfw_tests/unit/CatchFactory.cpp b/tests/src/fsfw_tests/unit/CatchFactory.cpp index 010ab5dd..42cb927e 100644 --- a/tests/src/fsfw_tests/unit/CatchFactory.cpp +++ b/tests/src/fsfw_tests/unit/CatchFactory.cpp @@ -1,4 +1,5 @@ #include "CatchFactory.h" +#include "tests/TestsConfig.h" #include "datapoollocal/LocalPoolOwnerBase.h" #include "mocks/HkReceiverMock.h" diff --git a/tests/src/fsfw_tests/unit/datapoollocal/DataSetTest.cpp b/tests/src/fsfw_tests/unit/datapoollocal/DataSetTest.cpp index 94b13f2f..c967b241 100644 --- a/tests/src/fsfw_tests/unit/datapoollocal/DataSetTest.cpp +++ b/tests/src/fsfw_tests/unit/datapoollocal/DataSetTest.cpp @@ -1,4 +1,5 @@ #include "LocalPoolOwnerBase.h" +#include "tests/TestsConfig.h" #include "fsfw_tests/unit/CatchDefinitions.h" #include diff --git a/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolOwnerBase.h b/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolOwnerBase.h index ea5bb7e0..1f532568 100644 --- a/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolOwnerBase.h +++ b/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolOwnerBase.h @@ -1,7 +1,7 @@ #ifndef FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_ #define FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_ -#include "objects/systemObjectList.h" +#include "tests/TestsConfig.h" #include "../mocks/MessageQueueMockBase.h" #include diff --git a/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolVariableTest.cpp b/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolVariableTest.cpp index 648a76e2..b029ec26 100644 --- a/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolVariableTest.cpp +++ b/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolVariableTest.cpp @@ -1,4 +1,5 @@ #include "LocalPoolOwnerBase.h" +#include "tests/TestsConfig.h" #include "fsfw_tests/unit/CatchDefinitions.h" #include diff --git a/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolVectorTest.cpp b/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolVectorTest.cpp index 3f846dec..5298e5b9 100644 --- a/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolVectorTest.cpp +++ b/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolVectorTest.cpp @@ -1,4 +1,5 @@ #include "LocalPoolOwnerBase.h" +#include "tests/TestsConfig.h" #include "fsfw_tests/unit/CatchDefinitions.h" #include diff --git a/tests/src/fsfw_tests/unit/testcfg/CMakeLists.txt b/tests/src/fsfw_tests/unit/testcfg/CMakeLists.txt index 3272958a..531972ac 100644 --- a/tests/src/fsfw_tests/unit/testcfg/CMakeLists.txt +++ b/tests/src/fsfw_tests/unit/testcfg/CMakeLists.txt @@ -4,7 +4,7 @@ target_sources(${FSFW_TEST_TGT} PRIVATE ) # Add include paths for the executable -target_include_directories(${FSFW_TEST_TGT} PUBLIC +target_include_directories(${FSFW_TEST_TGT} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ) From 6c75b56054c841b83a8057a0b99ff62337e5e654 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 15:51:27 +0200 Subject: [PATCH 33/89] README update --- README.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a7ae0e20..eea403a1 100644 --- a/README.md +++ b/README.md @@ -83,12 +83,17 @@ The FSFW also has unittests which use the [Catch2 library](https://github.com/ca These are built by setting the CMake option `FSFW_BUILD_UNITTESTS` to `ON` or `TRUE` from your project `CMakeLists.txt` file or from the command line. -The fsfw-tests binary will be built as part of the static library and dropped alongside it inside -the `fsfw` folder of the build folder. - +The fsfw-tests binary will be built as part of the static library and dropped alongside it. If the unittests are built, the library and the tests will be built with coverage information by default. This can be disabled by setting the `FSFW_TESTS_COV_GEN` option to `OFF` or `FALSE`. +You can use the following commands inside the `fsfw` folder to set up the build system + +```sh +mkdir build-Unittest && cd build-Unittest +cmake -DFSFW_BUILD_UNITTESTS=ON .. +``` + Coverage data in HTML format can be generated using the `CodeCoverage` [CMake module](https://github.com/bilke/cmake-modules/tree/master). To build the unittests, run them and then generare the coverage data in this format, From ad744fb593a5ce70d1a365ffcda255bc1ead89f0 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 15:56:04 +0200 Subject: [PATCH 34/89] README improvement --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eea403a1..312bc077 100644 --- a/README.md +++ b/README.md @@ -91,9 +91,11 @@ You can use the following commands inside the `fsfw` folder to set up the build ```sh mkdir build-Unittest && cd build-Unittest -cmake -DFSFW_BUILD_UNITTESTS=ON .. +cmake -DFSFW_BUILD_UNITTESTS=ON -DFSFW_OSAL=host .. ``` +You can also use `-DFSFW_OSAL=linux` on Linux systems. + Coverage data in HTML format can be generated using the `CodeCoverage` [CMake module](https://github.com/bilke/cmake-modules/tree/master). To build the unittests, run them and then generare the coverage data in this format, From ac8df112b1a51896279ab6a0bb566dcd133fbf0e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 16:01:14 +0200 Subject: [PATCH 35/89] small correction --- tests/src/fsfw_tests/unit/testcfg/events/subsystemIdRanges.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/fsfw_tests/unit/testcfg/events/subsystemIdRanges.h b/tests/src/fsfw_tests/unit/testcfg/events/subsystemIdRanges.h index b88cd875..b14c4bc5 100644 --- a/tests/src/fsfw_tests/unit/testcfg/events/subsystemIdRanges.h +++ b/tests/src/fsfw_tests/unit/testcfg/events/subsystemIdRanges.h @@ -12,7 +12,7 @@ */ namespace SUBSYSTEM_ID { enum: uint8_t { - SUBSYSTEM_ID_START = 0, + SUBSYSTEM_ID_START = FW_SUBSYSTEM_ID_RANGE, SUBSYSTEM_ID_END // [EXPORT] : [END] }; } From 22dbabba38d998108a1a7b5e2e5cccd5a6b4f512 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 16:01:58 +0200 Subject: [PATCH 36/89] removed copy and paste error --- tests/src/fsfw_tests/unit/testcfg/tmtc/apid.h | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/src/fsfw_tests/unit/testcfg/tmtc/apid.h b/tests/src/fsfw_tests/unit/testcfg/tmtc/apid.h index 0e633afb..c0231bca 100644 --- a/tests/src/fsfw_tests/unit/testcfg/tmtc/apid.h +++ b/tests/src/fsfw_tests/unit/testcfg/tmtc/apid.h @@ -12,7 +12,6 @@ */ namespace apid { static const uint16_t DEFAULT_APID = 0x00; - static const uint16_t SOURCE_OBSW = 0x73; } From 19061c3d50c74dce25159aa3e1850938f5518b6e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 16:04:43 +0200 Subject: [PATCH 37/89] removed obsolete files --- tests/src/fsfw_tests/internal/osal/testCmdExecutor.cpp | 1 - tests/src/fsfw_tests/internal/osal/testCmdExecutor.h | 10 ---------- 2 files changed, 11 deletions(-) delete mode 100644 tests/src/fsfw_tests/internal/osal/testCmdExecutor.cpp delete mode 100644 tests/src/fsfw_tests/internal/osal/testCmdExecutor.h diff --git a/tests/src/fsfw_tests/internal/osal/testCmdExecutor.cpp b/tests/src/fsfw_tests/internal/osal/testCmdExecutor.cpp deleted file mode 100644 index f0bed8ad..00000000 --- a/tests/src/fsfw_tests/internal/osal/testCmdExecutor.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "testCmdExecutor.h" diff --git a/tests/src/fsfw_tests/internal/osal/testCmdExecutor.h b/tests/src/fsfw_tests/internal/osal/testCmdExecutor.h deleted file mode 100644 index 4779dde9..00000000 --- a/tests/src/fsfw_tests/internal/osal/testCmdExecutor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef FSFW_TESTS_SRC_FSFW_TESTS_INTERNAL_OSAL_TESTCMDEXECUTOR_H_ -#define FSFW_TESTS_SRC_FSFW_TESTS_INTERNAL_OSAL_TESTCMDEXECUTOR_H_ - -namespace testcmdexec { - -} - - - -#endif /* FSFW_TESTS_SRC_FSFW_TESTS_INTERNAL_OSAL_TESTCMDEXECUTOR_H_ */ From 306a4b647f5afa72ee7cf6664103886a3a5b126b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 16:06:12 +0200 Subject: [PATCH 38/89] more review corrections --- CMakeLists.txt | 2 +- src/fsfw/FSFWVersion.h.in | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eae1fc25..101232e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -320,7 +320,7 @@ target_link_libraries(${LIB_FSFW_NAME} PRIVATE string(CONCAT POST_BUILD_COMMENT "######################################################################\n" - "Building FSFW v${FSFW_VERSION}.${FSFW_SUBVERSION}.${FSFW_REVISION}, " + "Built FSFW v${FSFW_VERSION}.${FSFW_SUBVERSION}.${FSFW_REVISION}, " "Target OSAL: ${FSFW_OS_NAME}\n" "######################################################################\n" ) diff --git a/src/fsfw/FSFWVersion.h.in b/src/fsfw/FSFWVersion.h.in index a858d703..7935b2f6 100644 --- a/src/fsfw/FSFWVersion.h.in +++ b/src/fsfw/FSFWVersion.h.in @@ -1,8 +1,6 @@ #ifndef FSFW_VERSION_H_ #define FSFW_VERSION_H_ -const char* const FSFW_VERSION_NAME = "ASTP"; - // Versioning is kept in project CMakeLists.txt file #define FSFW_VERSION @FSFW_VERSION@ #define FSFW_SUBVERSION @FSFW_SUBVERSION@ From bb9ae86159bb68a9fc830ade50581a9022266833 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 16:12:32 +0200 Subject: [PATCH 39/89] indentation fixes --- tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in b/tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in index d03ec3e5..1df7ef48 100644 --- a/tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in +++ b/tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in @@ -7,30 +7,30 @@ //! Used to determine whether C++ ostreams are used which can increase //! the binary size significantly. If this is disabled, //! the C stdio functions can be used alternatively -#define FSFW_CPP_OSTREAM_ENABLED 0 +#define FSFW_CPP_OSTREAM_ENABLED 0 //! More FSFW related printouts depending on level. Useful for development. -#define FSFW_VERBOSE_LEVEL 1 +#define FSFW_VERBOSE_LEVEL 1 //! Can be used to completely disable printouts, even the C stdio ones. #if FSFW_CPP_OSTREAM_ENABLED == 0 && FSFW_VERBOSE_LEVEL == 0 - #define FSFW_DISABLE_PRINTOUT 0 + #define FSFW_DISABLE_PRINTOUT 1 #endif #define FSFW_USE_PUS_C_TELEMETRY 1 #define FSFW_USE_PUS_C_TELECOMMANDS 1 //! Can be used to disable the ANSI color sequences for C stdio. -#define FSFW_COLORED_OUTPUT 1 +#define FSFW_COLORED_OUTPUT 1 //! If FSFW_OBJ_EVENT_TRANSLATION is set to one, //! additional output which requires the translation files translateObjects //! and translateEvents (and their compiled source files) -#define FSFW_OBJ_EVENT_TRANSLATION 0 +#define FSFW_OBJ_EVENT_TRANSLATION 0 #if FSFW_OBJ_EVENT_TRANSLATION == 1 //! Specify whether info events are printed too. -#define FSFW_DEBUG_INFO 1 +#define FSFW_DEBUG_INFO 1 #include "objects/translateObjects.h" #include "events/translateEvents.h" #else @@ -38,7 +38,7 @@ //! When using the newlib nano library, C99 support for stdio facilities //! will not be provided. This define should be set to 1 if this is the case. -#define FSFW_NO_C99_IO 1 +#define FSFW_NO_C99_IO 1 //! Specify whether a special mode store is used for Subsystem components. #define FSFW_USE_MODESTORE 0 From 3d6f28c48df51d093f01797faa90a22128ffdfca Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 16:14:30 +0200 Subject: [PATCH 40/89] printouts disable by default --- tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in b/tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in index 1df7ef48..f05ef40b 100644 --- a/tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in +++ b/tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in @@ -10,7 +10,7 @@ #define FSFW_CPP_OSTREAM_ENABLED 0 //! More FSFW related printouts depending on level. Useful for development. -#define FSFW_VERBOSE_LEVEL 1 +#define FSFW_VERBOSE_LEVEL 0 //! Can be used to completely disable printouts, even the C stdio ones. #if FSFW_CPP_OSTREAM_ENABLED == 0 && FSFW_VERBOSE_LEVEL == 0 From 460941c2251476eb9863c54422244a253441d3a9 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 16:16:49 +0200 Subject: [PATCH 41/89] tiny tweak --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 101232e9..af19b4c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,7 @@ if(FSFW_BUILD_UNITTESTS) configure_file(tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in FSFWConfig.h) configure_file(tests/src/fsfw_tests/unit/testcfg/TestsConfig.h.in tests/TestsConfig.h) configure_file(tests/src/fsfw_tests/unit/testcfg/OBSWConfig.h.in OBSWConfig.h) + project(${FSFW_TEST_TGT} CXX C) add_executable(${FSFW_TEST_TGT}) From bf5590ce2632102abd77711df3e64c5edffc7d80 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 16:25:01 +0200 Subject: [PATCH 42/89] configure file correction --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index af19b4c5..4af52a5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,8 +92,8 @@ target_include_directories(${LIB_FSFW_NAME} PRIVATE target_include_directories(${LIB_FSFW_NAME} INTERFACE ${CMAKE_CURRENT_BINARY_DIR} ) -configure_file(src/fsfw/FSFW.h.in FSFW.h) -configure_file(src/fsfw/FSFWVersion.h.in FSFWVersion.h) +configure_file(src/fsfw/FSFW.h.in fsfw/FSFW.h) +configure_file(src/fsfw/FSFWVersion.h.in fsfw/FSFWVersion.h) if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 11) From d4bb9397ee24f766be36350b7179e7e7c3df3e21 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 16:32:19 +0200 Subject: [PATCH 43/89] better handling for configure files --- CMakeLists.txt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4af52a5b..e0a0bfb0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,8 +92,14 @@ target_include_directories(${LIB_FSFW_NAME} PRIVATE target_include_directories(${LIB_FSFW_NAME} INTERFACE ${CMAKE_CURRENT_BINARY_DIR} ) -configure_file(src/fsfw/FSFW.h.in fsfw/FSFW.h) -configure_file(src/fsfw/FSFWVersion.h.in fsfw/FSFWVersion.h) + +if(FSFW_BUILD_UNITTESTS) + configure_file(src/fsfw/FSFW.h.in fsfw/FSFW.h) + configure_file(src/fsfw/FSFWVersion.h.in fsfw/FSFWVersion.h) +else() + configure_file(src/fsfw/FSFW.h.in FSFW.h) + configure_file(src/fsfw/FSFWVersion.h.in FSFWVersion.h) +endif() if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 11) From fc9101cd8f8e926ea41e87849cfc4a20dee3b226 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 17:12:42 +0200 Subject: [PATCH 44/89] deleted unrequired files, common include deleted --- .../unit/testcfg/devices/logicalAddresses.h | 1 - .../unit/testcfg/events/translateEvents.cpp | 15 --------------- .../unit/testcfg/events/translateEvents.h | 8 -------- .../unit/testcfg/objects/translateObjects.cpp | 19 ------------------- .../unit/testcfg/objects/translateObjects.h | 8 -------- 5 files changed, 51 deletions(-) delete mode 100644 tests/src/fsfw_tests/unit/testcfg/events/translateEvents.cpp delete mode 100644 tests/src/fsfw_tests/unit/testcfg/events/translateEvents.h delete mode 100644 tests/src/fsfw_tests/unit/testcfg/objects/translateObjects.cpp delete mode 100644 tests/src/fsfw_tests/unit/testcfg/objects/translateObjects.h diff --git a/tests/src/fsfw_tests/unit/testcfg/devices/logicalAddresses.h b/tests/src/fsfw_tests/unit/testcfg/devices/logicalAddresses.h index a0240037..d7b73e15 100644 --- a/tests/src/fsfw_tests/unit/testcfg/devices/logicalAddresses.h +++ b/tests/src/fsfw_tests/unit/testcfg/devices/logicalAddresses.h @@ -2,7 +2,6 @@ #define CONFIG_DEVICES_LOGICALADDRESSES_H_ #include -#include "common/devices/commonAddresses.h" #include diff --git a/tests/src/fsfw_tests/unit/testcfg/events/translateEvents.cpp b/tests/src/fsfw_tests/unit/testcfg/events/translateEvents.cpp deleted file mode 100644 index 47186727..00000000 --- a/tests/src/fsfw_tests/unit/testcfg/events/translateEvents.cpp +++ /dev/null @@ -1,15 +0,0 @@ -/** - * @brief Auto-generated event translation file. Contains 81 translations. - * @details - * Generated on: 2021-05-18 16:28:16 - */ -#include "translateEvents.h" - - -const char * translateEvents(Event event) { - switch( (event & 0xffff) ) { - default: - return "UNKNOWN_EVENT"; - } - return 0; -} diff --git a/tests/src/fsfw_tests/unit/testcfg/events/translateEvents.h b/tests/src/fsfw_tests/unit/testcfg/events/translateEvents.h deleted file mode 100644 index 9034dcf2..00000000 --- a/tests/src/fsfw_tests/unit/testcfg/events/translateEvents.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef FSFWCONFIG_EVENTS_TRANSLATEEVENTS_H_ -#define FSFWCONFIG_EVENTS_TRANSLATEEVENTS_H_ - -#include - -const char * translateEvents(Event event); - -#endif /* FSFWCONFIG_EVENTS_TRANSLATEEVENTS_H_ */ diff --git a/tests/src/fsfw_tests/unit/testcfg/objects/translateObjects.cpp b/tests/src/fsfw_tests/unit/testcfg/objects/translateObjects.cpp deleted file mode 100644 index 63636ced..00000000 --- a/tests/src/fsfw_tests/unit/testcfg/objects/translateObjects.cpp +++ /dev/null @@ -1,19 +0,0 @@ -/** - * @brief Auto-generated object translation file. - * @details - * Contains 69 translations. - * Generated on: 2021-05-18 16:37:37 - */ -#include "translateObjects.h" - -const char *NO_OBJECT_STRING = "NO_OBJECT"; - -const char* translateObject(object_id_t object) { - switch( (object & 0xFFFFFFFF) ) { - case 0xFFFFFFFF: - return NO_OBJECT_STRING; - default: - return "UNKNOWN_OBJECT"; - } - return 0; -} diff --git a/tests/src/fsfw_tests/unit/testcfg/objects/translateObjects.h b/tests/src/fsfw_tests/unit/testcfg/objects/translateObjects.h deleted file mode 100644 index dbf5b468..00000000 --- a/tests/src/fsfw_tests/unit/testcfg/objects/translateObjects.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef FSFWCONFIG_OBJECTS_TRANSLATEOBJECTS_H_ -#define FSFWCONFIG_OBJECTS_TRANSLATEOBJECTS_H_ - -#include - -const char* translateObject(object_id_t object); - -#endif /* FSFWCONFIG_OBJECTS_TRANSLATEOBJECTS_H_ */ From b2b648c4aa1f1f3cd50f23a61d01979c861b64ad Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 17:14:30 +0200 Subject: [PATCH 45/89] removed obsolete comment --- tests/src/fsfw_tests/unit/testcfg/CMakeLists.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/src/fsfw_tests/unit/testcfg/CMakeLists.txt b/tests/src/fsfw_tests/unit/testcfg/CMakeLists.txt index 531972ac..f840e38b 100644 --- a/tests/src/fsfw_tests/unit/testcfg/CMakeLists.txt +++ b/tests/src/fsfw_tests/unit/testcfg/CMakeLists.txt @@ -8,11 +8,6 @@ target_include_directories(${FSFW_TEST_TGT} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ) -# These translation files are actually not that relevant for the tests. However, the FSFW tests -# compile against a user-configured variant of the FSFW, which might be configured to include -# translation information. Therefore, empty dummy translation files are compiled here -# so the tests compile in any case. - # If a special translation file for object IDs exists, compile it. if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/objects/translateObjects.cpp") target_sources(${FSFW_TEST_TGT} PRIVATE From e8927d6aa888b78aa7db68daa277eb693913c74a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 17:22:29 +0200 Subject: [PATCH 46/89] moved testtemplate and removed user folder --- .../unit}/testtemplate/TestTemplate.cpp | 5 +- tests/user/CMakeLists.txt | 261 ------------------ tests/user/lcov.sh | 3 - 3 files changed, 2 insertions(+), 267 deletions(-) rename tests/{user => src/fsfw_tests/unit}/testtemplate/TestTemplate.cpp (90%) delete mode 100644 tests/user/CMakeLists.txt delete mode 100644 tests/user/lcov.sh diff --git a/tests/user/testtemplate/TestTemplate.cpp b/tests/src/fsfw_tests/unit/testtemplate/TestTemplate.cpp similarity index 90% rename from tests/user/testtemplate/TestTemplate.cpp rename to tests/src/fsfw_tests/unit/testtemplate/TestTemplate.cpp index 6b5fc3d2..a779d80c 100644 --- a/tests/user/testtemplate/TestTemplate.cpp +++ b/tests/src/fsfw_tests/unit/testtemplate/TestTemplate.cpp @@ -1,6 +1,5 @@ -#include -#include - +#include "fsfw_tests/unit/CatchDefinitions.h" +#include /** * @brief Template test file diff --git a/tests/user/CMakeLists.txt b/tests/user/CMakeLists.txt deleted file mode 100644 index 2e1fdee3..00000000 --- a/tests/user/CMakeLists.txt +++ /dev/null @@ -1,261 +0,0 @@ -################################################################################ -# CMake support for the Flight Software Framework Tests -# Author: R. Mueller -################################################################################ - -################################################################################ -# Pre-Project preparation -################################################################################ -cmake_minimum_required(VERSION 3.13) - -# set(CMAKE_VERBOSE TRUE) -# set(CODE_COVERAGE_VERBOSE TRUE) - -set(CMAKE_SCRIPT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") - -option(TMTC_TEST "Build binary for manual or automatic TMTC tests" FALSE) -option(GENERATE_COVERAGE - "Specify whether coverage data is generated with GCOV" - TRUE -) - -set(FSFW_ADD_UNITTESTS ON) - -if(TMTC_TEST) - set(LINK_CATCH2 FALSE) -else() - set(LINK_CATCH2 TRUE) -endif() - -# Tests can be built with the Host OSAL or with the Linux OSAL. -if(NOT FSFW_OSAL) - set(FSFW_OSAL host CACHE STRING "OS for the FSFW.") -endif() - -option(FSFW_CUSTOM_UNITTEST_RUNNER - "Specify whether custom main or Catch2 main is used" TRUE -) - -# Project Name -project(fsfw-tests C CXX) - -################################################################################ -# Pre-Sources preparation -################################################################################ - -# Specify the C++ standard -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED True) - -# Set names and variables -set(TARGET_NAME ${CMAKE_PROJECT_NAME}) -if(FSFW_CUSTOM_UNITTEST_RUNNER) - set(CATCH2_TARGET Catch2) -else() - set(CATCH2_TARGET Catch2WithMain) -endif() -set(LIB_FSFW_NAME fsfw) - -# Set path names -set(FSFW_PATH fsfw) -set(CATCH2_PATH Catch2) -set(FSFW_TESTS_PATH fsfw/unittest) -set(TEST_SETUP_PATH unittest) -set(TMTC_TEST_PATH tests) - -# Analyse different OS and architecture/target options and -# determine BSP_PATH - -# FreeRTOS -if(FSFW_OSAL STREQUAL linux) - add_definitions(-DUNIX -DLINUX) - find_package(Threads REQUIRED) -# Hosted -else() - if(WIN32) - add_definitions(-DWIN32) - elseif(UNIX) - find_package(Threads REQUIRED) - add_definitions(-DUNIX -DLINUX) - endif() -endif() - -if(GENERATE_COVERAGE) - list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/cmake-modules) - if(CMAKE_COMPILER_IS_GNUCXX) - include(CodeCoverage) - # Add compile options on target base, we don't want coverage for Catch2 - # append_coverage_compiler_flags() - endif() -endif() - -set(FSFW_CONFIG_PATH testcfg) -set(FSFW_ADDITIONAL_INC_PATHS ${CMAKE_CURRENT_BINARY_DIR}) - -configure_file(${FSFW_CONFIG_PATH}/FSFWConfig.h.in FSFWConfig.h) -configure_file(${FSFW_CONFIG_PATH}/OBSWConfig.h.in OBSWConfig.h) -configure_file(${FSFW_CONFIG_PATH}/TestsConfig.h.in TestsConfig.h) - -################################################################################ -# Executable and Sources -################################################################################ - -# Add executable -add_executable(${TARGET_NAME}) - -# Add subdirectories -add_subdirectory(${FSFW_PATH}) -add_subdirectory(${FSFW_CONFIG_PATH}) - -if(LINK_CATCH2) - add_subdirectory(${CATCH2_PATH}) - add_subdirectory(${TEST_SETUP_PATH}) -else() - target_compile_definitions(${TARGET_NAME} PRIVATE - FSFW_DISABLE_PRINTOUT=0 - ) - target_compile_definitions(${LIB_FSFW_NAME} PRIVATE - FSFW_DISABLE_PRINTOUT=0 - ) - add_subdirectory(${TMTC_TEST_PATH}) - add_subdirectory(${FSFW_TESTS_PATH}) -endif() - - -################################################################################ -# Post-Sources preparation -################################################################################ - -# Add libraries for all sources. -target_link_libraries(${TARGET_NAME} PRIVATE - ${LIB_FSFW_NAME} -) - -if(LINK_CATCH2) - target_link_libraries(${TARGET_NAME} PRIVATE - ${CATCH2_TARGET} - ) -endif() - -if(GENERATE_COVERAGE) - if(CMAKE_COMPILER_IS_GNUCXX) - # set(CODE_COVERAGE_VERBOSE TRUE) - include(CodeCoverage) - - # Remove quotes. - separate_arguments(COVERAGE_COMPILER_FLAGS - NATIVE_COMMAND "${COVERAGE_COMPILER_FLAGS}" - ) - - # Add compile options manually, we don't want coverage for Catch2 - target_compile_options(${TARGET_NAME} PRIVATE - "${COVERAGE_COMPILER_FLAGS}" - ) - target_compile_options(${LIB_FSFW_NAME} PRIVATE - "${COVERAGE_COMPILER_FLAGS}" - ) - - # Exclude internal unittest from coverage for now. - if(WIN32) - set(GCOVR_ADDITIONAL_ARGS - "--exclude-throw-branches" - "--exclude-unreachable-branches" - ) - set(COVERAGE_EXCLUDES - "/c/msys64/mingw64/*" "Catch2" - "${CMAKE_CURRENT_SOURCE_DIR}/fsfw/unittest/internal" - ) - elseif(UNIX) - set(COVERAGE_EXCLUDES - "/usr/include/*" "/usr/bin/*" "Catch2/*" - "fsfw/unittest/internal/*" - ) - endif() - - target_link_options(${TARGET_NAME} PRIVATE - -fprofile-arcs - -ftest-coverage - ) - target_link_options(${LIB_FSFW_NAME} PRIVATE - -fprofile-arcs - -ftest-coverage - ) - - if(WIN32) - setup_target_for_coverage_gcovr_html( - NAME ${TARGET_NAME}_coverage - EXECUTABLE ${TARGET_NAME} - DEPENDENCIES ${TARGET_NAME} - ) - else() - setup_target_for_coverage_lcov( - NAME ${TARGET_NAME}_coverage - EXECUTABLE ${TARGET_NAME} - DEPENDENCIES ${TARGET_NAME} - ) - endif() - endif() -endif() - -# Add include paths for all sources. -target_include_directories(${TARGET_NAME} PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR} - ${FSFW_CONFIG_PATH} - ${CMAKE_CURRENT_BINARY_DIR} -) - -if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(WARNING_FLAGS - -Wall - -Wextra - -Wshadow=local - -Wimplicit-fallthrough=1 - -Wno-unused-parameter - -Wno-psabi - ) - - # Remove unused sections. - target_compile_options(${TARGET_NAME} PRIVATE - "-ffunction-sections" - "-fdata-sections" - ) - - # Removed unused sections. - target_link_options(${TARGET_NAME} PRIVATE - "-Wl,--gc-sections" - ) - -elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - set(COMPILER_FLAGS "/permissive-") -endif() - -if(CMAKE_VERBOSE) - message(STATUS "Warning flags: ${WARNING_FLAGS}") -endif() - -# Compile options for all sources. -target_compile_options(${TARGET_NAME} PRIVATE - ${WARNING_FLAGS} -) - -if(NOT CMAKE_SIZE) - set(CMAKE_SIZE size) - if(WIN32) - set(FILE_SUFFIX ".exe") - endif() -endif() - -string(CONCAT POST_BUILD_COMMENT - "Build directory: ${CMAKE_BINARY_DIR}\n" - "Target OSAL: ${FSFW_OSAL}\n" - "Target Build Type: ${CMAKE_BUILD_TYPE}" -) - -add_custom_command(TARGET ${TARGET_NAME} - POST_BUILD - COMMAND ${CMAKE_SIZE} ${TARGET_NAME}${FILE_SUFFIX} - COMMENT ${POST_BUILD_COMMENT} -) - -include (${CMAKE_SCRIPT_PATH}/BuildType.cmake) -set_build_type() diff --git a/tests/user/lcov.sh b/tests/user/lcov.sh deleted file mode 100644 index 4db16e5f..00000000 --- a/tests/user/lcov.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -lcov --capture --directory . --output-file coverage.info -genhtml coverage.info --output-directory _coverage From 348975ba5f80bb95383c9d7618b172cc0e99a827 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 17:28:07 +0200 Subject: [PATCH 47/89] additional coverage excludes --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e0a0bfb0..0f45de01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -194,6 +194,8 @@ if(FSFW_BUILD_UNITTESTS) elseif(UNIX) set(COVERAGE_EXCLUDES "/usr/include/*" "/usr/bin/*" "Catch2/*" + "/usr/local/include/*" "*/fsfw_tests/*" + "/catch2-src/*" ) endif() From 060b3a3b2c4814e04a3122a4fff124850fecccc0 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 17:51:13 +0200 Subject: [PATCH 48/89] added missing leading * --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f45de01..923d5cc5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -195,7 +195,7 @@ if(FSFW_BUILD_UNITTESTS) set(COVERAGE_EXCLUDES "/usr/include/*" "/usr/bin/*" "Catch2/*" "/usr/local/include/*" "*/fsfw_tests/*" - "/catch2-src/*" + "*/catch2-src/*" ) endif() From c46bde417e7b56b39bab50a1faa2688b3e65eff4 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 19:37:23 +0200 Subject: [PATCH 49/89] small bugfix for LIS3 handler --- hal/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hal/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp b/hal/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp index 804e83f2..1a61bfe2 100644 --- a/hal/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp +++ b/hal/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp @@ -73,7 +73,7 @@ ReturnValue_t MgmLIS3MDLHandler::buildTransitionDeviceCommand( switch (internalState) { case(InternalState::STATE_NONE): case(InternalState::STATE_NORMAL): { - return HasReturnvaluesIF::RETURN_OK; + return DeviceHandlerBase::NOTHING_TO_SEND; } case(InternalState::STATE_FIRST_CONTACT): { *id = MGMLIS3MDL::IDENTIFY_DEVICE; From 2180c47f4fc40786af594c2df7d30492edb5c87e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 19:47:41 +0200 Subject: [PATCH 50/89] more printouts for rejected packet --- src/fsfw/tcdistribution/PUSDistributor.cpp | 27 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/fsfw/tcdistribution/PUSDistributor.cpp b/src/fsfw/tcdistribution/PUSDistributor.cpp index eec02429..1a5f713d 100644 --- a/src/fsfw/tcdistribution/PUSDistributor.cpp +++ b/src/fsfw/tcdistribution/PUSDistributor.cpp @@ -29,12 +29,31 @@ PUSDistributor::TcMqMapIter PUSDistributor::selectDestination() { tcStatus = checker.checkPacket(currentPacket); if(tcStatus != HasReturnvaluesIF::RETURN_OK) { #if FSFW_VERBOSE_LEVEL >= 1 + std::string keyword; + if(tcStatus == TcPacketCheck::INCORRECT_CHECKSUM) { + keyword = "checksum"; + } + else if(tcStatus == TcPacketCheck::INCORRECT_PRIMARY_HEADER) { + keyword = "incorrect primary header"; + } + else if(tcStatus == TcPacketCheck::ILLEGAL_APID) { + keyword = "illegal APID"; + } + else if(tcStatus == TcPacketCheck::INCORRECT_SECONDARY_HEADER) { + keyword = "incorrect secondary header"; + } + else if(tcStatus == TcPacketCheck::INCOMPLETE_PACKET) { + keyword = "incomplete packet"; + } + else { + keyword = "unnamed error"; + } #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::debug << "PUSDistributor::handlePacket: Packet format invalid, code " << - static_cast(tcStatus) << std::endl; + sif::warning << "PUSDistributor::handlePacket: Packet format invalid, " + << keyword << " error" << std::endl; #else - sif::printDebug("PUSDistributor::handlePacket: Packet format invalid, code %d\n", - static_cast(tcStatus)); + sif::printWarning("PUSDistributor::handlePacket: Packet format invalid, " + "%s error\n", keyword); #endif #endif } From cae3feb5da403405c241690220b316ef17d1892f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 11 Oct 2021 19:55:37 +0200 Subject: [PATCH 51/89] Add feature to open GPIO by line name This features was provided by Jakob Meier as part of https://egit.irs.uni-stuttgart.de/eive/fsfw/pulls/19 . It adds the feature to open GPIOs supplying their line names. --- .../fsfw_hal/common/gpio/gpioDefinitions.h | 54 +++- .../fsfw_hal/linux/gpio/LinuxLibgpioIF.cpp | 242 ++++++++++++------ hal/src/fsfw_hal/linux/gpio/LinuxLibgpioIF.h | 37 ++- 3 files changed, 235 insertions(+), 98 deletions(-) diff --git a/hal/src/fsfw_hal/common/gpio/gpioDefinitions.h b/hal/src/fsfw_hal/common/gpio/gpioDefinitions.h index 688d9c9b..c6f21195 100644 --- a/hal/src/fsfw_hal/common/gpio/gpioDefinitions.h +++ b/hal/src/fsfw_hal/common/gpio/gpioDefinitions.h @@ -9,12 +9,13 @@ using gpioId_t = uint16_t; namespace gpio { -enum Levels { +enum Levels: uint8_t { LOW = 0, - HIGH = 1 + HIGH = 1, + NONE = 99 }; -enum Direction { +enum Direction: uint8_t { IN = 0, OUT = 1 }; @@ -24,16 +25,18 @@ enum GpioOperation { WRITE }; -enum GpioTypes { +enum class GpioTypes { NONE, GPIO_REGULAR_BY_CHIP, GPIO_REGULAR_BY_LABEL, + GPIO_REGULAR_BY_LINE_NAME, CALLBACK }; static constexpr gpioId_t NO_GPIO = -1; -using gpio_cb_t = void (*) (gpioId_t gpioId, gpio::GpioOperation gpioOp, int value, void* args); +using gpio_cb_t = void (*) (gpioId_t gpioId, gpio::GpioOperation gpioOp, gpio::Levels value, + void* args); } @@ -57,7 +60,7 @@ public: GpioBase() = default; GpioBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction, - int initValue): + gpio::Levels initValue): gpioType(gpioType), consumer(consumer),direction(direction), initValue(initValue) {} virtual~ GpioBase() {}; @@ -66,15 +69,21 @@ public: gpio::GpioTypes gpioType = gpio::GpioTypes::NONE; std::string consumer; gpio::Direction direction = gpio::Direction::IN; - int initValue = 0; + gpio::Levels initValue = gpio::Levels::NONE; }; class GpiodRegularBase: public GpioBase { public: GpiodRegularBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction, - int initValue, int lineNum): GpioBase(gpioType, consumer, direction, initValue), - lineNum(lineNum) { + gpio::Levels initValue, int lineNum): + GpioBase(gpioType, consumer, direction, initValue), lineNum(lineNum) { } + + // line number will be configured at a later point for the open by line name configuration + GpiodRegularBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction, + gpio::Levels initValue): GpioBase(gpioType, consumer, direction, initValue) { + } + int lineNum = 0; struct gpiod_line* lineHandle = nullptr; }; @@ -87,7 +96,7 @@ public: } GpiodRegularByChip(std::string chipname_, int lineNum_, std::string consumer_, - gpio::Direction direction_, int initValue_) : + gpio::Direction direction_, gpio::Levels initValue_) : GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP, consumer_, direction_, initValue_, lineNum_), chipname(chipname_){ @@ -105,7 +114,7 @@ public: class GpiodRegularByLabel: public GpiodRegularBase { public: GpiodRegularByLabel(std::string label_, int lineNum_, std::string consumer_, - gpio::Direction direction_, int initValue_) : + gpio::Direction direction_, gpio::Levels initValue_) : GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL, consumer_, direction_, initValue_, lineNum_), label(label_) { @@ -120,9 +129,30 @@ public: std::string label; }; +/** + * @brief Passing this GPIO configuration to the GPIO IF object will try to open the GPIO by its + * line name. This line name can be set in the device tree and must be unique. Otherwise + * the driver will open the first line with the given name. + */ +class GpiodRegularByLineName: public GpiodRegularBase { +public: + GpiodRegularByLineName(std::string lineName_, std::string consumer_, gpio::Direction direction_, + gpio::Levels initValue_) : + GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME, consumer_, direction_, + initValue_), lineName(lineName_) { + } + + GpiodRegularByLineName(std::string lineName_, std::string consumer_) : + GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME, consumer_, + gpio::Direction::IN, gpio::LOW), lineName(lineName_) { + } + + std::string lineName; +}; + class GpioCallback: public GpioBase { public: - GpioCallback(std::string consumer, gpio::Direction direction_, int initValue_, + GpioCallback(std::string consumer, gpio::Direction direction_, gpio::Levels initValue_, gpio::gpio_cb_t callback, void* callbackArgs): GpioBase(gpio::GpioTypes::CALLBACK, consumer, direction_, initValue_), callback(callback), callbackArgs(callbackArgs) {} diff --git a/hal/src/fsfw_hal/linux/gpio/LinuxLibgpioIF.cpp b/hal/src/fsfw_hal/linux/gpio/LinuxLibgpioIF.cpp index 15c3d118..020ba964 100644 --- a/hal/src/fsfw_hal/linux/gpio/LinuxLibgpioIF.cpp +++ b/hal/src/fsfw_hal/linux/gpio/LinuxLibgpioIF.cpp @@ -1,8 +1,9 @@ -#include "fsfw_hal/linux/gpio/LinuxLibgpioIF.h" +#include "LinuxLibgpioIF.h" + #include "fsfw_hal/common/gpio/gpioDefinitions.h" #include "fsfw_hal/common/gpio/GpioCookie.h" -#include +#include "fsfw/serviceinterface/ServiceInterface.h" #include #include @@ -66,6 +67,14 @@ ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap& mapToAdd) { configureGpioByLabel(gpioConfig.first, *regularGpio); break; } + case(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME):{ + auto regularGpio = dynamic_cast(gpioConfig.second); + if(regularGpio == nullptr) { + return GPIO_INVALID_INSTANCE; + } + configureGpioByLineName(gpioConfig.first, *regularGpio); + break; + } case(gpio::GpioTypes::CALLBACK): { auto gpioCallback = dynamic_cast(gpioConfig.second); if(gpioCallback->callback == nullptr) { @@ -84,13 +93,13 @@ ReturnValue_t LinuxLibgpioIF::configureGpioByLabel(gpioId_t gpioId, std::string& label = gpioByLabel.label; struct gpiod_chip* chip = gpiod_chip_open_by_label(label.c_str()); if (chip == nullptr) { - sif::warning << "LinuxLibgpioIF::configureRegularGpio: Failed to open gpio from gpio " + sif::warning << "LinuxLibgpioIF::configureGpioByLabel: Failed to open gpio from gpio " << "group with label " << label << ". Gpio ID: " << gpioId << std::endl; return RETURN_FAILED; } std::string failOutput = "label: " + label; - return configureRegularGpio(gpioId, gpioByLabel.gpioType, chip, gpioByLabel, failOutput); + return configureRegularGpio(gpioId, chip, gpioByLabel, failOutput); } ReturnValue_t LinuxLibgpioIF::configureGpioByChip(gpioId_t gpioId, @@ -98,16 +107,41 @@ ReturnValue_t LinuxLibgpioIF::configureGpioByChip(gpioId_t gpioId, std::string& chipname = gpioByChip.chipname; struct gpiod_chip* chip = gpiod_chip_open_by_name(chipname.c_str()); if (chip == nullptr) { - sif::warning << "LinuxLibgpioIF::configureRegularGpio: Failed to open chip " + sif::warning << "LinuxLibgpioIF::configureGpioByChip: Failed to open chip " << chipname << ". Gpio ID: " << gpioId << std::endl; return RETURN_FAILED; } std::string failOutput = "chipname: " + chipname; - return configureRegularGpio(gpioId, gpioByChip.gpioType, chip, gpioByChip, failOutput); + return configureRegularGpio(gpioId, chip, gpioByChip, failOutput); } -ReturnValue_t LinuxLibgpioIF::configureRegularGpio(gpioId_t gpioId, gpio::GpioTypes gpioType, - struct gpiod_chip* chip, GpiodRegularBase& regularGpio, std::string failOutput) { +ReturnValue_t LinuxLibgpioIF::configureGpioByLineName(gpioId_t gpioId, + GpiodRegularByLineName &gpioByLineName) { + std::string& lineName = gpioByLineName.lineName; + char chipname[MAX_CHIPNAME_LENGTH]; + unsigned int lineOffset; + + int result = gpiod_ctxless_find_line(lineName.c_str(), chipname, MAX_CHIPNAME_LENGTH, + &lineOffset); + if (result != LINE_FOUND) { + parseFindeLineResult(result, lineName); + return RETURN_FAILED; + } + + gpioByLineName.lineNum = static_cast(lineOffset); + + struct gpiod_chip* chip = gpiod_chip_open_by_name(chipname); + if (chip == nullptr) { + sif::warning << "LinuxLibgpioIF::configureGpioByLineName: Failed to open chip " + << chipname << ". second->gpioType; - if(gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP or - gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL) { + if (gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP + or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL + or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME) { auto regularGpio = dynamic_cast(gpioMapIter->second); if(regularGpio == nullptr) { return GPIO_TYPE_FAILURE; @@ -187,7 +222,7 @@ ReturnValue_t LinuxLibgpioIF::pullHigh(gpioId_t gpioId) { return GPIO_INVALID_INSTANCE; } gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE, - 1, gpioCallback->callbackArgs); + gpio::Levels::HIGH, gpioCallback->callbackArgs); return RETURN_OK; } return GPIO_TYPE_FAILURE; @@ -196,13 +231,18 @@ ReturnValue_t LinuxLibgpioIF::pullHigh(gpioId_t gpioId) { ReturnValue_t LinuxLibgpioIF::pullLow(gpioId_t gpioId) { gpioMapIter = gpioMap.find(gpioId); if (gpioMapIter == gpioMap.end()) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "LinuxLibgpioIF::pullLow: Unknown GPIO ID " << gpioId << std::endl; +#else + sif::printWarning("LinuxLibgpioIF::pullLow: Unknown GPIO ID %d\n", gpioId); +#endif return UNKNOWN_GPIO_ID; } auto& gpioType = gpioMapIter->second->gpioType; - if(gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP or - gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL) { + if (gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP + or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL + or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME) { auto regularGpio = dynamic_cast(gpioMapIter->second); if(regularGpio == nullptr) { return GPIO_TYPE_FAILURE; @@ -215,7 +255,7 @@ ReturnValue_t LinuxLibgpioIF::pullLow(gpioId_t gpioId) { return GPIO_INVALID_INSTANCE; } gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE, - 0, gpioCallback->callbackArgs); + gpio::Levels::LOW, gpioCallback->callbackArgs); return RETURN_OK; } return GPIO_TYPE_FAILURE; @@ -225,8 +265,13 @@ ReturnValue_t LinuxLibgpioIF::driveGpio(gpioId_t gpioId, GpiodRegularBase& regularGpio, gpio::Levels logicLevel) { int result = gpiod_line_set_value(regularGpio.lineHandle, logicLevel); if (result < 0) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "LinuxLibgpioIF::driveGpio: Failed to pull GPIO with ID " << gpioId << " to logic level " << logicLevel << std::endl; +#else + sif::printWarning("LinuxLibgpioIF::driveGpio: Failed to pull GPIO with ID %d to " + "logic level %d\n", gpioId, logicLevel); +#endif return DRIVE_GPIO_FAILURE; } @@ -236,12 +281,18 @@ ReturnValue_t LinuxLibgpioIF::driveGpio(gpioId_t gpioId, ReturnValue_t LinuxLibgpioIF::readGpio(gpioId_t gpioId, int* gpioState) { gpioMapIter = gpioMap.find(gpioId); if (gpioMapIter == gpioMap.end()){ +#if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "LinuxLibgpioIF::readGpio: Unknown GPIOD ID " << gpioId << std::endl; +#else + sif::printWarning("LinuxLibgpioIF::readGpio: Unknown GPIOD ID %d\n", gpioId); +#endif return UNKNOWN_GPIO_ID; } + auto gpioType = gpioMapIter->second->gpioType; - if(gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP or - gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL) { + if (gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP + or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL + or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME) { auto regularGpio = dynamic_cast(gpioMapIter->second); if(regularGpio == nullptr) { return GPIO_TYPE_FAILURE; @@ -249,10 +300,14 @@ ReturnValue_t LinuxLibgpioIF::readGpio(gpioId_t gpioId, int* gpioState) { *gpioState = gpiod_line_get_value(regularGpio->lineHandle); } else { - + auto gpioCallback = dynamic_cast(gpioMapIter->second); + if(gpioCallback->callback == nullptr) { + return GPIO_INVALID_INSTANCE; + } + gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::READ, + gpio::Levels::NONE, gpioCallback->callbackArgs); + return RETURN_OK; } - - return RETURN_OK; } @@ -262,13 +317,14 @@ ReturnValue_t LinuxLibgpioIF::checkForConflicts(GpioMap& mapToAdd){ for(auto& gpioConfig: mapToAdd) { switch(gpioConfig.second->gpioType) { case(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP): - case(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL): { + case(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL): + case(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME): { auto regularGpio = dynamic_cast(gpioConfig.second); if(regularGpio == nullptr) { return GPIO_TYPE_FAILURE; } - /* Check for conflicts and remove duplicates if necessary */ - result = checkForConflictsRegularGpio(gpioConfig.first, *regularGpio, mapToAdd); + // Check for conflicts and remove duplicates if necessary + result = checkForConflictsById(gpioConfig.first, gpioConfig.second->gpioType, mapToAdd); if(result != HasReturnvaluesIF::RETURN_OK) { status = result; } @@ -279,66 +335,108 @@ ReturnValue_t LinuxLibgpioIF::checkForConflicts(GpioMap& mapToAdd){ if(callbackGpio == nullptr) { return GPIO_TYPE_FAILURE; } - /* Check for conflicts and remove duplicates if necessary */ - result = checkForConflictsCallbackGpio(gpioConfig.first, callbackGpio, mapToAdd); + // Check for conflicts and remove duplicates if necessary + result = checkForConflictsById(gpioConfig.first, + gpioConfig.second->gpioType, mapToAdd); if(result != HasReturnvaluesIF::RETURN_OK) { status = result; } break; } default: { - +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "Invalid GPIO type detected for GPIO ID " << gpioConfig.first + << std::endl; +#else + sif::printWarning("Invalid GPIO type detected for GPIO ID %d\n", gpioConfig.first); +#endif + status = GPIO_TYPE_FAILURE; } } } return status; } - -ReturnValue_t LinuxLibgpioIF::checkForConflictsRegularGpio(gpioId_t gpioIdToCheck, - GpiodRegularBase& gpioToCheck, GpioMap& mapToAdd) { - /* Cross check with private map */ +ReturnValue_t LinuxLibgpioIF::checkForConflictsById(gpioId_t gpioIdToCheck, + gpio::GpioTypes expectedType, GpioMap& mapToAdd) { + // Cross check with private map gpioMapIter = gpioMap.find(gpioIdToCheck); if(gpioMapIter != gpioMap.end()) { auto& gpioType = gpioMapIter->second->gpioType; - if(gpioType != gpio::GpioTypes::GPIO_REGULAR_BY_CHIP and - gpioType != gpio::GpioTypes::GPIO_REGULAR_BY_LABEL) { - sif::warning << "LinuxLibgpioIF::checkForConflicts: ID already exists for different " - "GPIO type" << gpioIdToCheck << ". Removing duplicate." << std::endl; - mapToAdd.erase(gpioIdToCheck); - return HasReturnvaluesIF::RETURN_OK; + bool eraseDuplicateDifferentType = false; + switch(expectedType) { + case(gpio::GpioTypes::NONE): { + break; } - auto ownRegularGpio = dynamic_cast(gpioMapIter->second); - if(ownRegularGpio == nullptr) { - return GPIO_TYPE_FAILURE; + case(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP): + case(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL): + case(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME): { + if(gpioType == gpio::GpioTypes::NONE or gpioType == gpio::GpioTypes::CALLBACK) { + eraseDuplicateDifferentType = true; + } + break; + } + case(gpio::GpioTypes::CALLBACK): { + if(gpioType != gpio::GpioTypes::CALLBACK) { + eraseDuplicateDifferentType = true; + } + } + } + if(eraseDuplicateDifferentType) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "LinuxLibgpioIF::checkForConflicts: ID already exists for " + "different GPIO type " << gpioIdToCheck << + ". Removing duplicate from map to add" << std::endl; +#else + sif::printWarning("LinuxLibgpioIF::checkForConflicts: ID already exists for " + "different GPIO type %d. Removing duplicate from map to add\n", gpioIdToCheck); +#endif + mapToAdd.erase(gpioIdToCheck); + return GPIO_DUPLICATE_DETECTED; } - /* Remove element from map to add because a entry for this GPIO - already exists */ - sif::warning << "LinuxLibgpioIF::checkForConflictsRegularGpio: Duplicate GPIO definition" - << " detected. Duplicate will be removed from map to add." << std::endl; + // Remove element from map to add because a entry for this GPIO already exists +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "LinuxLibgpioIF::checkForConflictsRegularGpio: Duplicate GPIO " + "definition with ID " << gpioIdToCheck << " detected. " << + "Duplicate will be removed from map to add" << std::endl; +#else + sif::printWarning("LinuxLibgpioIF::checkForConflictsRegularGpio: Duplicate GPIO definition " + "with ID %d detected. Duplicate will be removed from map to add\n", gpioIdToCheck); +#endif mapToAdd.erase(gpioIdToCheck); + return GPIO_DUPLICATE_DETECTED; } return HasReturnvaluesIF::RETURN_OK; } -ReturnValue_t LinuxLibgpioIF::checkForConflictsCallbackGpio(gpioId_t gpioIdToCheck, - GpioCallback *callbackGpio, GpioMap& mapToAdd) { - /* Cross check with private map */ - gpioMapIter = gpioMap.find(gpioIdToCheck); - if(gpioMapIter != gpioMap.end()) { - if(gpioMapIter->second->gpioType != gpio::GpioTypes::CALLBACK) { - sif::warning << "LinuxLibgpioIF::checkForConflicts: ID already exists for different " - "GPIO type" << gpioIdToCheck << ". Removing duplicate." << std::endl; - mapToAdd.erase(gpioIdToCheck); - return HasReturnvaluesIF::RETURN_OK; - } - - /* Remove element from map to add because a entry for this GPIO - already exists */ - sif::warning << "LinuxLibgpioIF::checkForConflictsRegularGpio: Duplicate GPIO definition" - << " detected. Duplicate will be removed from map to add." << std::endl; - mapToAdd.erase(gpioIdToCheck); +void LinuxLibgpioIF::parseFindeLineResult(int result, std::string& lineName) { + switch (result) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + case LINE_NOT_EXISTS: + case LINE_ERROR: { + sif::warning << "LinuxLibgpioIF::parseFindeLineResult: Line with name " << lineName << + " does not exist" << std::endl; + break; } - return HasReturnvaluesIF::RETURN_OK; + default: { + sif::warning << "LinuxLibgpioIF::parseFindeLineResult: Unknown return code for line " + "with name " << lineName << std::endl; + break; + } +#else + case LINE_NOT_EXISTS: + case LINE_ERROR: { + sif::printWarning("LinuxLibgpioIF::parseFindeLineResult: Line with name %s " + "does not exist\n", lineName); + break; + } + default: { + sif::printWarning("LinuxLibgpioIF::parseFindeLineResult: Unknown return code for line " + "with name %s\n", lineName); + break; + } +#endif + } + } diff --git a/hal/src/fsfw_hal/linux/gpio/LinuxLibgpioIF.h b/hal/src/fsfw_hal/linux/gpio/LinuxLibgpioIF.h index 31e4a7e8..cc32bd70 100644 --- a/hal/src/fsfw_hal/linux/gpio/LinuxLibgpioIF.h +++ b/hal/src/fsfw_hal/linux/gpio/LinuxLibgpioIF.h @@ -1,19 +1,19 @@ #ifndef LINUX_GPIO_LINUXLIBGPIOIF_H_ #define LINUX_GPIO_LINUXLIBGPIOIF_H_ -#include "../../common/gpio/GpioIF.h" -#include -#include +#include "fsfw/returnvalues/FwClassIds.h" +#include "fsfw_hal/common/gpio/GpioIF.h" +#include "fsfw/objectmanager/SystemObject.h" class GpioCookie; class GpiodRegularIF; /** - * @brief This class implements the GpioIF for a linux based system. The - * implementation is based on the libgpiod lib which requires linux 4.8 - * or higher. - * @note The Petalinux SDK from Xilinx supports libgpiod since Petalinux - * 2019.1. + * @brief This class implements the GpioIF for a linux based system. + * @details + * This implementation is based on the libgpiod lib which requires Linux 4.8 or higher. + * @note + * The Petalinux SDK from Xilinx supports libgpiod since Petalinux 2019.1. */ class LinuxLibgpioIF : public GpioIF, public SystemObject { public: @@ -28,6 +28,8 @@ public: HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 3); static constexpr ReturnValue_t GPIO_INVALID_INSTANCE = HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 4); + static constexpr ReturnValue_t GPIO_DUPLICATE_DETECTED = + HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 5); LinuxLibgpioIF(object_id_t objectId); virtual ~LinuxLibgpioIF(); @@ -38,7 +40,13 @@ public: ReturnValue_t readGpio(gpioId_t gpioId, int* gpioState) override; private: - /* Holds the information and configuration of all used GPIOs */ + + static const size_t MAX_CHIPNAME_LENGTH = 11; + static const int LINE_NOT_EXISTS = 0; + static const int LINE_ERROR = -1; + static const int LINE_FOUND = 1; + + // Holds the information and configuration of all used GPIOs GpioUnorderedMap gpioMap; GpioUnorderedMapIter gpioMapIter; @@ -53,8 +61,10 @@ private: ReturnValue_t configureGpioByLabel(gpioId_t gpioId, GpiodRegularByLabel& gpioByLabel); ReturnValue_t configureGpioByChip(gpioId_t gpioId, GpiodRegularByChip& gpioByChip); - ReturnValue_t configureRegularGpio(gpioId_t gpioId, gpio::GpioTypes gpioType, - struct gpiod_chip* chip, GpiodRegularBase& regularGpio, std::string failOutput); + ReturnValue_t configureGpioByLineName(gpioId_t gpioId, + GpiodRegularByLineName &gpioByLineName); + ReturnValue_t configureRegularGpio(gpioId_t gpioId, struct gpiod_chip* chip, + GpiodRegularBase& regularGpio, std::string failOutput); /** * @brief This function checks if GPIOs are already registered and whether @@ -67,16 +77,15 @@ private: */ ReturnValue_t checkForConflicts(GpioMap& mapToAdd); - ReturnValue_t checkForConflictsRegularGpio(gpioId_t gpiodId, GpiodRegularBase& regularGpio, + ReturnValue_t checkForConflictsById(gpioId_t gpiodId, gpio::GpioTypes type, GpioMap& mapToAdd); - ReturnValue_t checkForConflictsCallbackGpio(gpioId_t gpiodId, GpioCallback* regularGpio, - GpioMap& mapToAdd); /** * @brief Performs the initial configuration of all GPIOs specified in the GpioMap mapToAdd. */ ReturnValue_t configureGpios(GpioMap& mapToAdd); + void parseFindeLineResult(int result, std::string& lineName); }; #endif /* LINUX_GPIO_LINUXLIBGPIOIF_H_ */ From 113c992f999681bc973dd4b5ac867dd737b27db4 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 17 Oct 2021 22:56:00 +0200 Subject: [PATCH 52/89] use char* instead --- src/fsfw/tcdistribution/PUSDistributor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsfw/tcdistribution/PUSDistributor.cpp b/src/fsfw/tcdistribution/PUSDistributor.cpp index 1a5f713d..284a14c9 100644 --- a/src/fsfw/tcdistribution/PUSDistributor.cpp +++ b/src/fsfw/tcdistribution/PUSDistributor.cpp @@ -29,7 +29,7 @@ PUSDistributor::TcMqMapIter PUSDistributor::selectDestination() { tcStatus = checker.checkPacket(currentPacket); if(tcStatus != HasReturnvaluesIF::RETURN_OK) { #if FSFW_VERBOSE_LEVEL >= 1 - std::string keyword; + const char* keyword = nullptr; if(tcStatus == TcPacketCheck::INCORRECT_CHECKSUM) { keyword = "checksum"; } From 6e97bd4db4a51db75c6b5f4fc8998dcc3a731191 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 17 Oct 2021 23:27:31 +0200 Subject: [PATCH 53/89] added integration test code --- tests/src/fsfw_tests/CMakeLists.txt | 1 + .../src/fsfw_tests/integration/CMakeLists.txt | 4 + .../integration/assemblies/CMakeLists.txt | 3 + .../integration/assemblies/TestAssembly.cpp | 201 +++++ .../integration/assemblies/TestAssembly.h | 56 ++ .../integration/controller/CMakeLists.txt | 3 + .../integration/controller/TestController.cpp | 214 +++++ .../integration/controller/TestController.h | 50 ++ .../ctrldefinitions/testCtrlDefinitions.h | 18 + .../integration/devices/CMakeLists.txt | 5 + .../integration/devices/TestCookie.cpp | 14 + .../integration/devices/TestCookie.h | 22 + .../integration/devices/TestDeviceHandler.cpp | 804 ++++++++++++++++++ .../integration/devices/TestDeviceHandler.h | 142 ++++ .../integration/devices/TestEchoComIF.cpp | 86 ++ .../integration/devices/TestEchoComIF.h | 56 ++ .../devicedefinitions/testDeviceDefinitions.h | 100 +++ .../integration/task/CMakeLists.txt | 3 + .../fsfw_tests/integration/task/TestTask.cpp | 80 ++ .../fsfw_tests/integration/task/TestTask.h | 56 ++ 20 files changed, 1918 insertions(+) create mode 100644 tests/src/fsfw_tests/integration/CMakeLists.txt create mode 100644 tests/src/fsfw_tests/integration/assemblies/CMakeLists.txt create mode 100644 tests/src/fsfw_tests/integration/assemblies/TestAssembly.cpp create mode 100644 tests/src/fsfw_tests/integration/assemblies/TestAssembly.h create mode 100644 tests/src/fsfw_tests/integration/controller/CMakeLists.txt create mode 100644 tests/src/fsfw_tests/integration/controller/TestController.cpp create mode 100644 tests/src/fsfw_tests/integration/controller/TestController.h create mode 100644 tests/src/fsfw_tests/integration/controller/ctrldefinitions/testCtrlDefinitions.h create mode 100644 tests/src/fsfw_tests/integration/devices/CMakeLists.txt create mode 100644 tests/src/fsfw_tests/integration/devices/TestCookie.cpp create mode 100644 tests/src/fsfw_tests/integration/devices/TestCookie.h create mode 100644 tests/src/fsfw_tests/integration/devices/TestDeviceHandler.cpp create mode 100644 tests/src/fsfw_tests/integration/devices/TestDeviceHandler.h create mode 100644 tests/src/fsfw_tests/integration/devices/TestEchoComIF.cpp create mode 100644 tests/src/fsfw_tests/integration/devices/TestEchoComIF.h create mode 100644 tests/src/fsfw_tests/integration/devices/devicedefinitions/testDeviceDefinitions.h create mode 100644 tests/src/fsfw_tests/integration/task/CMakeLists.txt create mode 100644 tests/src/fsfw_tests/integration/task/TestTask.cpp create mode 100644 tests/src/fsfw_tests/integration/task/TestTask.h diff --git a/tests/src/fsfw_tests/CMakeLists.txt b/tests/src/fsfw_tests/CMakeLists.txt index e4a6be80..a06bf3fe 100644 --- a/tests/src/fsfw_tests/CMakeLists.txt +++ b/tests/src/fsfw_tests/CMakeLists.txt @@ -1,3 +1,4 @@ +add_subdirectory(integration) if(FSFW_ADD_INTERNAL_TESTS) add_subdirectory(internal) diff --git a/tests/src/fsfw_tests/integration/CMakeLists.txt b/tests/src/fsfw_tests/integration/CMakeLists.txt new file mode 100644 index 00000000..e44fbee7 --- /dev/null +++ b/tests/src/fsfw_tests/integration/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory(assemblies) +add_subdirectory(controller) +add_subdirectory(devices) +add_subdirectory(task) diff --git a/tests/src/fsfw_tests/integration/assemblies/CMakeLists.txt b/tests/src/fsfw_tests/integration/assemblies/CMakeLists.txt new file mode 100644 index 00000000..22c06600 --- /dev/null +++ b/tests/src/fsfw_tests/integration/assemblies/CMakeLists.txt @@ -0,0 +1,3 @@ +target_sources(${LIB_FSFW_NAME} PRIVATE + TestAssembly.cpp +) \ No newline at end of file diff --git a/tests/src/fsfw_tests/integration/assemblies/TestAssembly.cpp b/tests/src/fsfw_tests/integration/assemblies/TestAssembly.cpp new file mode 100644 index 00000000..1c497ebd --- /dev/null +++ b/tests/src/fsfw_tests/integration/assemblies/TestAssembly.cpp @@ -0,0 +1,201 @@ +#include "TestAssembly.h" + +#include + + +TestAssembly::TestAssembly(object_id_t objectId, object_id_t parentId, object_id_t testDevice0, + object_id_t testDevice1): + AssemblyBase(objectId, parentId), deviceHandler0Id(testDevice0), + deviceHandler1Id(testDevice1) { + ModeListEntry newModeListEntry; + newModeListEntry.setObject(testDevice0); + newModeListEntry.setMode(MODE_OFF); + newModeListEntry.setSubmode(SUBMODE_NONE); + + commandTable.insert(newModeListEntry); + + newModeListEntry.setObject(testDevice1); + newModeListEntry.setMode(MODE_OFF); + newModeListEntry.setSubmode(SUBMODE_NONE); + + commandTable.insert(newModeListEntry); + +} + +TestAssembly::~TestAssembly() { +} + +ReturnValue_t TestAssembly::commandChildren(Mode_t mode, + Submode_t submode) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "TestAssembly: Received command to go to mode " << mode << + " submode " << (int) submode << std::endl; +#else + sif::printInfo("TestAssembly: Received command to go to mode %d submode %d\n", mode, submode); +#endif + ReturnValue_t result = RETURN_OK; + if(mode == MODE_OFF){ + commandTable[0].setMode(MODE_OFF); + commandTable[0].setSubmode(SUBMODE_NONE); + commandTable[1].setMode(MODE_OFF); + commandTable[1].setSubmode(SUBMODE_NONE); + } + else if(mode == DeviceHandlerIF::MODE_NORMAL) { + if(submode == submodes::SINGLE){ + commandTable[0].setMode(MODE_OFF); + commandTable[0].setSubmode(SUBMODE_NONE); + commandTable[1].setMode(MODE_OFF); + commandTable[1].setSubmode(SUBMODE_NONE); + // We try to prefer 0 here but we try to switch to 1 even if it might fail + if(isDeviceAvailable(deviceHandler0Id)) { + if (childrenMap[deviceHandler0Id].mode == MODE_ON) { + commandTable[0].setMode(mode); + commandTable[0].setSubmode(SUBMODE_NONE); + } + else { + commandTable[0].setMode(MODE_ON); + commandTable[0].setSubmode(SUBMODE_NONE); + result = NEED_SECOND_STEP; + } + } + else { + if (childrenMap[deviceHandler1Id].mode == MODE_ON) { + commandTable[1].setMode(mode); + commandTable[1].setSubmode(SUBMODE_NONE); + } + else{ + commandTable[1].setMode(MODE_ON); + commandTable[1].setSubmode(SUBMODE_NONE); + result = NEED_SECOND_STEP; + } + } + } + else{ + // Dual Mode Normal + if (childrenMap[deviceHandler0Id].mode == MODE_ON) { + commandTable[0].setMode(mode); + commandTable[0].setSubmode(SUBMODE_NONE); + } + else{ + commandTable[0].setMode(MODE_ON); + commandTable[0].setSubmode(SUBMODE_NONE); + result = NEED_SECOND_STEP; + } + if (childrenMap[deviceHandler1Id].mode == MODE_ON) { + commandTable[1].setMode(mode); + commandTable[1].setSubmode(SUBMODE_NONE); + } + else{ + commandTable[1].setMode(MODE_ON); + commandTable[1].setSubmode(SUBMODE_NONE); + result = NEED_SECOND_STEP; + } + } + } + else{ + //Mode ON + if(submode == submodes::SINGLE){ + commandTable[0].setMode(MODE_OFF); + commandTable[0].setSubmode(SUBMODE_NONE); + commandTable[1].setMode(MODE_OFF); + commandTable[1].setSubmode(SUBMODE_NONE); + // We try to prefer 0 here but we try to switch to 1 even if it might fail + if(isDeviceAvailable(deviceHandler0Id)){ + commandTable[0].setMode(MODE_ON); + commandTable[0].setSubmode(SUBMODE_NONE); + } + else{ + commandTable[1].setMode(MODE_ON); + commandTable[1].setSubmode(SUBMODE_NONE); + } + } + else{ + commandTable[0].setMode(MODE_ON); + commandTable[0].setSubmode(SUBMODE_NONE); + commandTable[1].setMode(MODE_ON); + commandTable[1].setSubmode(SUBMODE_NONE); + } + } + + + + HybridIterator iter(commandTable.begin(), + commandTable.end()); + executeTable(iter); + return result; +} + +ReturnValue_t TestAssembly::isModeCombinationValid(Mode_t mode, + Submode_t submode) { + switch (mode) { + case MODE_OFF: + if (submode == SUBMODE_NONE) { + return RETURN_OK; + } else { + return INVALID_SUBMODE; + } + case DeviceHandlerIF::MODE_NORMAL: + case MODE_ON: + if (submode < 3) { + return RETURN_OK; + } else { + return INVALID_SUBMODE; + } + } + return INVALID_MODE; +} + +ReturnValue_t TestAssembly::initialize() { + ReturnValue_t result = AssemblyBase::initialize(); + if(result != RETURN_OK){ + return result; + } + handler0 = ObjectManager::instance()->get(deviceHandler0Id); + handler1 = ObjectManager::instance()->get(deviceHandler1Id); + if((handler0 == nullptr) or (handler1 == nullptr)){ + return HasReturnvaluesIF::RETURN_FAILED; + } + + handler0->setParentQueue(this->getCommandQueue()); + handler1->setParentQueue(this->getCommandQueue()); + + + result = registerChild(objects::TEST_DEVICE_HANDLER_0); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + result = registerChild(objects::TEST_DEVICE_HANDLER_1); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + return result; +} + +ReturnValue_t TestAssembly::checkChildrenStateOn( + Mode_t wantedMode, Submode_t wantedSubmode) { + if(submode == submodes::DUAL){ + for(const auto& info:childrenMap) { + if(info.second.mode != wantedMode or info.second.mode != wantedSubmode){ + return NOT_ENOUGH_CHILDREN_IN_CORRECT_STATE; + } + } + return RETURN_OK; + } + else if(submode == submodes::SINGLE) { + for(const auto& info:childrenMap) { + if(info.second.mode == wantedMode and info.second.mode != wantedSubmode){ + return RETURN_OK; + } + } + } + return INVALID_SUBMODE; +} + +bool TestAssembly::isDeviceAvailable(object_id_t object) { + if(healthHelper.healthTable->getHealth(object) == HasHealthIF::HEALTHY){ + return true; + } + else{ + return false; + } +} diff --git a/tests/src/fsfw_tests/integration/assemblies/TestAssembly.h b/tests/src/fsfw_tests/integration/assemblies/TestAssembly.h new file mode 100644 index 00000000..3cc6f450 --- /dev/null +++ b/tests/src/fsfw_tests/integration/assemblies/TestAssembly.h @@ -0,0 +1,56 @@ +#ifndef MISSION_ASSEMBLIES_TESTASSEMBLY_H_ +#define MISSION_ASSEMBLIES_TESTASSEMBLY_H_ + +#include +#include "../devices/TestDeviceHandler.h" + +class TestAssembly: public AssemblyBase { +public: + TestAssembly(object_id_t objectId, object_id_t parentId, object_id_t testDevice0, + object_id_t testDevice1); + virtual ~TestAssembly(); + ReturnValue_t initialize() override; + + enum submodes: Submode_t{ + SINGLE = 0, + DUAL = 1 + }; + +protected: + /** + * Command children to reach [mode,submode] combination + * Can be done by setting #commandsOutstanding correctly, + * or using executeTable() + * @param mode + * @param submode + * @return + * - @c RETURN_OK if ok + * - @c NEED_SECOND_STEP if children need to be commanded again + */ + ReturnValue_t commandChildren(Mode_t mode, Submode_t submode) override; + /** + * Check whether desired assembly mode was achieved by checking the modes + * or/and health states of child device handlers. + * The assembly template class will also call this function if a health + * or mode change of a child device handler was detected. + * @param wantedMode + * @param wantedSubmode + * @return + */ + ReturnValue_t isModeCombinationValid(Mode_t mode, Submode_t submode) + override; + + ReturnValue_t checkChildrenStateOn(Mode_t wantedMode, + Submode_t wantedSubmode) override; +private: + FixedArrayList commandTable; + object_id_t deviceHandler0Id = 0; + object_id_t deviceHandler1Id = 0; + TestDevice* handler0 = nullptr; + TestDevice* handler1 = nullptr; + + + bool isDeviceAvailable(object_id_t object); +}; + +#endif /* MISSION_ASSEMBLIES_TESTASSEMBLY_H_ */ diff --git a/tests/src/fsfw_tests/integration/controller/CMakeLists.txt b/tests/src/fsfw_tests/integration/controller/CMakeLists.txt new file mode 100644 index 00000000..f5655b71 --- /dev/null +++ b/tests/src/fsfw_tests/integration/controller/CMakeLists.txt @@ -0,0 +1,3 @@ +target_sources(${LIB_FSFW_NAME} PRIVATE + TestController.cpp +) \ No newline at end of file diff --git a/tests/src/fsfw_tests/integration/controller/TestController.cpp b/tests/src/fsfw_tests/integration/controller/TestController.cpp new file mode 100644 index 00000000..385d07bd --- /dev/null +++ b/tests/src/fsfw_tests/integration/controller/TestController.cpp @@ -0,0 +1,214 @@ +#include "TestController.h" +#include "OBSWConfig.h" + +#include +#include +#include + +TestController::TestController(object_id_t objectId, size_t commandQueueDepth): + ExtendedControllerBase(objectId, objects::NO_OBJECT, commandQueueDepth), + deviceDataset0(objects::TEST_DEVICE_HANDLER_0), + deviceDataset1(objects::TEST_DEVICE_HANDLER_1) { +} + +TestController::~TestController() { +} + +ReturnValue_t TestController::handleCommandMessage(CommandMessage *message) { + return HasReturnvaluesIF::RETURN_OK; +} + +void TestController::performControlOperation() { + /* We will trace vaiables if we received an update notification or snapshots */ +#if OBSW_CONTROLLER_PRINTOUT == 1 + if(not traceVariable) { + return; + } + + switch(currentTraceType) { + case(NONE): { + break; + } + case(TRACE_DEV_0_UINT8): { + if(traceCounter == 0) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "Tracing finished" << std::endl; +#else + sif::printInfo("Tracing finished\n"); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ + traceVariable = false; + traceCounter = traceCycles; + currentTraceType = TraceTypes::NONE; + break; + } + + PoolReadGuard readHelper(&deviceDataset0.testUint8Var); +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "Tracing device 0 variable 0 (UINT8), current value: " << + static_cast(deviceDataset0.testUint8Var.value) << std::endl; +#else + sif::printInfo("Tracing device 0 variable 0 (UINT8), current value: %d\n", + deviceDataset0.testUint8Var.value); +#endif + traceCounter--; + break; + } + case(TRACE_DEV_0_VECTOR): { + break; + } + + } +#endif /* OBSW_CONTROLLER_PRINTOUT == 1 */ +} + +void TestController::handleChangedDataset(sid_t sid, store_address_t storeId, bool* clearMessage) { + using namespace std; + +#if OBSW_CONTROLLER_PRINTOUT == 1 + char const* printout = nullptr; + if(storeId == storeId::INVALID_STORE_ADDRESS) { + printout = "Notification"; + } + else { + printout = "Snapshot"; + } +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "TestController::handleChangedDataset: " << printout << " update from object " + "ID " << setw(8) << setfill('0') << hex << sid.objectId << + " and set ID " << sid.ownerSetId << dec << setfill(' ') << endl; +#else + sif::printInfo("TestController::handleChangedPoolVariable: %s update from object ID 0x%08x and " + "set ID %lu\n", printout, sid.objectId, sid.ownerSetId); +#endif + + if (storeId == storeId::INVALID_STORE_ADDRESS) { + if(sid.objectId == objects::TEST_DEVICE_HANDLER_0) { + PoolReadGuard readHelper(&deviceDataset0.testFloat3Vec); + float floatVec[3]; + floatVec[0] = deviceDataset0.testFloat3Vec.value[0]; + floatVec[1] = deviceDataset0.testFloat3Vec.value[1]; + floatVec[2] = deviceDataset0.testFloat3Vec.value[2]; +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "Current float vector (3) values: [" << floatVec[0] << ", " << + floatVec[1] << ", " << floatVec[2] << "]" << std::endl; +#else + sif::printInfo("Current float vector (3) values: [%f, %f, %f]\n", + floatVec[0], floatVec[1], floatVec[2]); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ + } + } +#endif /* OBSW_CONTROLLER_PRINTOUT == 1 */ + + /* We will trace the variables for snapshots and update notifications */ + if(not traceVariable) { + traceVariable = true; + traceCounter = traceCycles; + currentTraceType = TraceTypes::TRACE_DEV_0_VECTOR; + } +} + +void TestController::handleChangedPoolVariable(gp_id_t globPoolId, store_address_t storeId, + bool* clearMessage) { + using namespace std; + +#if OBSW_CONTROLLER_PRINTOUT == 1 + char const* printout = nullptr; + if (storeId == storeId::INVALID_STORE_ADDRESS) { + printout = "Notification"; + } + else { + printout = "Snapshot"; + } + +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "TestController::handleChangedPoolVariable: " << printout << " update from object " + "ID 0x" << setw(8) << setfill('0') << hex << globPoolId.objectId << + " and local pool ID " << globPoolId.localPoolId << dec << setfill(' ') << endl; +#else + sif::printInfo("TestController::handleChangedPoolVariable: %s update from object ID 0x%08x and " + "local pool ID %lu\n", printout, globPoolId.objectId, globPoolId.localPoolId); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ + + if (storeId == storeId::INVALID_STORE_ADDRESS) { + if(globPoolId.objectId == objects::TEST_DEVICE_HANDLER_0) { + PoolReadGuard readHelper(&deviceDataset0.testUint8Var); +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "Current test variable 0 (UINT8) value: " << static_cast( + deviceDataset0.testUint8Var.value) << std::endl; +#else + sif::printInfo("Current test variable 0 (UINT8) value %d\n", + deviceDataset0.testUint8Var.value); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ + } + } +#endif /* OBSW_CONTROLLER_PRINTOUT == 1 */ + + /* We will trace the variables for snapshots and update notifications */ + if(not traceVariable) { + traceVariable = true; + traceCounter = traceCycles; + currentTraceType = TraceTypes::TRACE_DEV_0_UINT8; + } +} + +LocalPoolDataSetBase* TestController::getDataSetHandle(sid_t sid) { + return nullptr; +} + +ReturnValue_t TestController::initializeLocalDataPool(localpool::DataPool &localDataPoolMap, + LocalDataPoolManager &poolManager) { + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t TestController::initializeAfterTaskCreation() { + namespace td = testdevice; + HasLocalDataPoolIF* device0 = ObjectManager::instance()->get( + objects::TEST_DEVICE_HANDLER_0); + if(device0 == nullptr) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "TestController::initializeAfterTaskCreation: Test device handler 0 " + "handle invalid!" << std::endl; +#else + sif::printWarning("TestController::initializeAfterTaskCreation: Test device handler 0 " + "handle invalid!"); +#endif + return ObjectManagerIF::CHILD_INIT_FAILED; + } + ProvidesDataPoolSubscriptionIF* subscriptionIF = device0->getSubscriptionInterface(); + if(subscriptionIF != nullptr) { + /* For DEVICE_0, we only subscribe for notifications */ + subscriptionIF->subscribeForSetUpdateMessage(td::TEST_SET_ID, getObjectId(), + getCommandQueue(), false); + subscriptionIF->subscribeForVariableUpdateMessage(td::PoolIds::TEST_UINT8_ID, + getObjectId(), getCommandQueue(), false); + } + + + HasLocalDataPoolIF* device1 = ObjectManager::instance()->get( + objects::TEST_DEVICE_HANDLER_1); + if(device1 == nullptr) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "TestController::initializeAfterTaskCreation: Test device handler 1 " + "handle invalid!" << std::endl; +#else + sif::printWarning("TestController::initializeAfterTaskCreation: Test device handler 1 " + "handle invalid!"); +#endif + } + + subscriptionIF = device1->getSubscriptionInterface(); + if(subscriptionIF != nullptr) { + /* For DEVICE_1, we will subscribe for snapshots */ + subscriptionIF->subscribeForSetUpdateMessage(td::TEST_SET_ID, getObjectId(), + getCommandQueue(), true); + subscriptionIF->subscribeForVariableUpdateMessage(td::PoolIds::TEST_UINT8_ID, + getObjectId(), getCommandQueue(), true); + } + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t TestController::checkModeCommand(Mode_t mode, Submode_t submode, + uint32_t *msToReachTheMode) { + return HasReturnvaluesIF::RETURN_OK; +} + diff --git a/tests/src/fsfw_tests/integration/controller/TestController.h b/tests/src/fsfw_tests/integration/controller/TestController.h new file mode 100644 index 00000000..8092f945 --- /dev/null +++ b/tests/src/fsfw_tests/integration/controller/TestController.h @@ -0,0 +1,50 @@ +#ifndef MISSION_CONTROLLER_TESTCONTROLLER_H_ +#define MISSION_CONTROLLER_TESTCONTROLLER_H_ + +#include "../devices/devicedefinitions/testDeviceDefinitions.h" +#include + + +class TestController: + public ExtendedControllerBase { +public: + TestController(object_id_t objectId, size_t commandQueueDepth = 10); + virtual~ TestController(); +protected: + testdevice::TestDataSet deviceDataset0; + testdevice::TestDataSet deviceDataset1; + + /* Extended Controller Base overrides */ + ReturnValue_t handleCommandMessage(CommandMessage *message) override; + void performControlOperation() override; + + /* HasLocalDatapoolIF callbacks */ + void handleChangedDataset(sid_t sid, store_address_t storeId, bool* clearMessage) override; + void handleChangedPoolVariable(gp_id_t globPoolId, store_address_t storeId, + bool* clearMessage) override; + + LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override; + ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, + LocalDataPoolManager& poolManager) override; + + ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode, + uint32_t *msToReachTheMode) override; + + ReturnValue_t initializeAfterTaskCreation() override; + +private: + + bool traceVariable = false; + uint8_t traceCycles = 5; + uint8_t traceCounter = traceCycles; + + enum TraceTypes { + NONE, + TRACE_DEV_0_UINT8, + TRACE_DEV_0_VECTOR + }; + TraceTypes currentTraceType = TraceTypes::NONE; +}; + + +#endif /* MISSION_CONTROLLER_TESTCONTROLLER_H_ */ diff --git a/tests/src/fsfw_tests/integration/controller/ctrldefinitions/testCtrlDefinitions.h b/tests/src/fsfw_tests/integration/controller/ctrldefinitions/testCtrlDefinitions.h new file mode 100644 index 00000000..7bf045df --- /dev/null +++ b/tests/src/fsfw_tests/integration/controller/ctrldefinitions/testCtrlDefinitions.h @@ -0,0 +1,18 @@ +#ifndef MISSION_CONTROLLER_CTRLDEFINITIONS_TESTCTRLDEFINITIONS_H_ +#define MISSION_CONTROLLER_CTRLDEFINITIONS_TESTCTRLDEFINITIONS_H_ + +#include +#include + +namespace testcontroller { + +enum sourceObjectIds: object_id_t { + DEVICE_0_ID = objects::TEST_DEVICE_HANDLER_0, + DEVICE_1_ID = objects::TEST_DEVICE_HANDLER_1, +}; + +} + + + +#endif /* MISSION_CONTROLLER_CTRLDEFINITIONS_TESTCTRLDEFINITIONS_H_ */ diff --git a/tests/src/fsfw_tests/integration/devices/CMakeLists.txt b/tests/src/fsfw_tests/integration/devices/CMakeLists.txt new file mode 100644 index 00000000..cfd238d2 --- /dev/null +++ b/tests/src/fsfw_tests/integration/devices/CMakeLists.txt @@ -0,0 +1,5 @@ +target_sources(${LIB_FSFW_NAME} PRIVATE + TestCookie.cpp + TestDeviceHandler.cpp + TestEchoComIF.cpp +) diff --git a/tests/src/fsfw_tests/integration/devices/TestCookie.cpp b/tests/src/fsfw_tests/integration/devices/TestCookie.cpp new file mode 100644 index 00000000..91098f80 --- /dev/null +++ b/tests/src/fsfw_tests/integration/devices/TestCookie.cpp @@ -0,0 +1,14 @@ +#include "TestCookie.h" + +TestCookie::TestCookie(address_t address, size_t replyMaxLen): + address(address), replyMaxLen(replyMaxLen) {} + +TestCookie::~TestCookie() {} + +address_t TestCookie::getAddress() const { + return address; +} + +size_t TestCookie::getReplyMaxLen() const { + return replyMaxLen; +} diff --git a/tests/src/fsfw_tests/integration/devices/TestCookie.h b/tests/src/fsfw_tests/integration/devices/TestCookie.h new file mode 100644 index 00000000..5dac3f25 --- /dev/null +++ b/tests/src/fsfw_tests/integration/devices/TestCookie.h @@ -0,0 +1,22 @@ +#ifndef MISSION_DEVICES_TESTCOOKIE_H_ +#define MISSION_DEVICES_TESTCOOKIE_H_ + +#include +#include + +/** + * @brief Really simple cookie which does not do a lot. + */ +class TestCookie: public CookieIF { +public: + TestCookie(address_t address, size_t maxReplyLen); + virtual ~TestCookie(); + + address_t getAddress() const; + size_t getReplyMaxLen() const; +private: + address_t address = 0; + size_t replyMaxLen = 0; +}; + +#endif /* MISSION_DEVICES_TESTCOOKIE_H_ */ diff --git a/tests/src/fsfw_tests/integration/devices/TestDeviceHandler.cpp b/tests/src/fsfw_tests/integration/devices/TestDeviceHandler.cpp new file mode 100644 index 00000000..91019487 --- /dev/null +++ b/tests/src/fsfw_tests/integration/devices/TestDeviceHandler.cpp @@ -0,0 +1,804 @@ +#include "TestDeviceHandler.h" +#include "FSFWConfig.h" + +#include "fsfw/datapool/PoolReadGuard.h" + +#include + +TestDevice::TestDevice(object_id_t objectId, object_id_t comIF, + CookieIF * cookie, testdevice::DeviceIndex deviceIdx, bool fullInfoPrintout, + bool changingDataset): + DeviceHandlerBase(objectId, comIF, cookie), deviceIdx(deviceIdx), + dataset(this), fullInfoPrintout(fullInfoPrintout) { +} + +TestDevice::~TestDevice() {} + +void TestDevice::performOperationHook() { + if(periodicPrintout) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "TestDevice" << deviceIdx << "::performOperationHook: Alive!" << std::endl; +#else + sif::printInfo("TestDevice%d::performOperationHook: Alive!", deviceIdx); +#endif + } + + if(oneShot) { + oneShot = false; + } +} + + +void TestDevice::doStartUp() { + if(fullInfoPrintout) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "TestDevice" << deviceIdx << "::doStartUp: Switching On" << std::endl; +#else + sif::printInfo("TestDevice%d::doStartUp: Switching On\n", static_cast(deviceIdx)); +#endif + } + + setMode(_MODE_TO_ON); + return; +} + + +void TestDevice::doShutDown() { + if(fullInfoPrintout) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "TestDevice" << deviceIdx << "::doShutDown: Switching Off" << std::endl; +#else + sif::printInfo("TestDevice%d::doShutDown: Switching Off\n", static_cast(deviceIdx)); +#endif + } + + setMode(_MODE_SHUT_DOWN); + return; +} + + +ReturnValue_t TestDevice::buildNormalDeviceCommand(DeviceCommandId_t* id) { + using namespace testdevice; + *id = TEST_NORMAL_MODE_CMD; + if(DeviceHandlerBase::isAwaitingReply()) { + return NOTHING_TO_SEND; + } + return buildCommandFromCommand(*id, nullptr, 0); +} + +ReturnValue_t TestDevice::buildTransitionDeviceCommand(DeviceCommandId_t* id) { + if(mode == _MODE_TO_ON) { + if(fullInfoPrintout) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "TestDevice" << deviceIdx << "::buildTransitionDeviceCommand: Was called" + " from _MODE_TO_ON mode" << std::endl; +#else + sif::printInfo("TestDevice%d::buildTransitionDeviceCommand: " + "Was called from _MODE_TO_ON mode\n", deviceIdx); +#endif + } + + } + if(mode == _MODE_TO_NORMAL) { + if(fullInfoPrintout) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "TestDevice" << deviceIdx << "::buildTransitionDeviceCommand: Was called " + "from _MODE_TO_NORMAL mode" << std::endl; +#else + sif::printInfo("TestDevice%d::buildTransitionDeviceCommand: Was called from " + " _MODE_TO_NORMAL mode\n", deviceIdx); +#endif + } + + setMode(MODE_NORMAL); + } + if(mode == _MODE_SHUT_DOWN) { + if(fullInfoPrintout) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "TestDevice" << deviceIdx << "::buildTransitionDeviceCommand: Was called " + "from _MODE_SHUT_DOWN mode" << std::endl; +#else + sif::printInfo("TestDevice%d::buildTransitionDeviceCommand: Was called from " + "_MODE_SHUT_DOWN mode\n", deviceIdx); +#endif + } + + setMode(MODE_OFF); + } + return NOTHING_TO_SEND; +} + +void TestDevice::doTransition(Mode_t modeFrom, Submode_t submodeFrom) { + if(mode == _MODE_TO_NORMAL) { + if(fullInfoPrintout) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "TestDevice" << deviceIdx << "::doTransition: Custom transition to " + "normal mode" << std::endl; +#else + sif::printInfo("TestDevice%d::doTransition: Custom transition to normal mode\n", + deviceIdx); +#endif + } + + } + else { + DeviceHandlerBase::doTransition(modeFrom, submodeFrom); + } +} + +ReturnValue_t TestDevice::buildCommandFromCommand( + DeviceCommandId_t deviceCommand, const uint8_t* commandData, + size_t commandDataLen) { + using namespace testdevice; + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + switch(deviceCommand) { + case(TEST_NORMAL_MODE_CMD): { + commandSent = true; + result = buildNormalModeCommand(deviceCommand, commandData, commandDataLen); + break; + } + + case(TEST_COMMAND_0): { + commandSent = true; + result = buildTestCommand0(deviceCommand, commandData, commandDataLen); + break; + } + + case(TEST_COMMAND_1): { + commandSent = true; + result = buildTestCommand1(deviceCommand, commandData, commandDataLen); + break; + } + case(TEST_NOTIF_SNAPSHOT_VAR): { + if(changingDatasets) { + changingDatasets = false; + } + + PoolReadGuard readHelper(&dataset.testUint8Var); + if(deviceIdx == testdevice::DeviceIndex::DEVICE_0) { + /* This will trigger a variable notification to the demo controller */ + dataset.testUint8Var = 220; + dataset.testUint8Var.setValid(true); + } + else if(deviceIdx == testdevice::DeviceIndex::DEVICE_1) { + /* This will trigger a variable snapshot to the demo controller */ + dataset.testUint8Var = 30; + dataset.testUint8Var.setValid(true); + } + + break; + } + case(TEST_NOTIF_SNAPSHOT_SET): { + if(changingDatasets) { + changingDatasets = false; + } + + PoolReadGuard readHelper(&dataset.testFloat3Vec); + + if(deviceIdx == testdevice::DeviceIndex::DEVICE_0) { + /* This will trigger a variable notification to the demo controller */ + dataset.testFloat3Vec.value[0] = 60; + dataset.testFloat3Vec.value[1] = 70; + dataset.testFloat3Vec.value[2] = 55; + dataset.testFloat3Vec.setValid(true); + } + else if(deviceIdx == testdevice::DeviceIndex::DEVICE_1) { + /* This will trigger a variable notification to the demo controller */ + dataset.testFloat3Vec.value[0] = -60; + dataset.testFloat3Vec.value[1] = -70; + dataset.testFloat3Vec.value[2] = -55; + dataset.testFloat3Vec.setValid(true); + } + break; + } + default: + result = DeviceHandlerIF::COMMAND_NOT_SUPPORTED; + } + return result; +} + + +ReturnValue_t TestDevice::buildNormalModeCommand(DeviceCommandId_t deviceCommand, + const uint8_t* commandData, size_t commandDataLen) { + if(fullInfoPrintout) { +#if OBSW_VERBOSE_LEVEL >= 3 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "TestDevice::buildTestCommand1: Building normal command" << std::endl; +#else + sif::printInfo("TestDevice::buildTestCommand1: Building command from TEST_COMMAND_1\n"); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ +#endif /* OBSW_VERBOSE_LEVEL >= 3 */ + } + + if(commandDataLen > MAX_BUFFER_SIZE - sizeof(DeviceCommandId_t)) { + return DeviceHandlerIF::INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS; + } + /* The command is passed on in the command buffer as it is */ + passOnCommand(deviceCommand, commandData, commandDataLen); + return RETURN_OK; +} + +ReturnValue_t TestDevice::buildTestCommand0(DeviceCommandId_t deviceCommand, + const uint8_t* commandData, size_t commandDataLen) { + using namespace testdevice; + if(fullInfoPrintout) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "TestDevice" << deviceIdx << "::buildTestCommand0: Executing simple command " + " with completion reply" << std::endl; +#else + sif::printInfo("TestDevice%d::buildTestCommand0: Executing simple command with " + "completion reply\n", deviceIdx); +#endif + } + + if(commandDataLen > MAX_BUFFER_SIZE - sizeof(DeviceCommandId_t)) { + return DeviceHandlerIF::INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS; + } + + /* The command is passed on in the command buffer as it is */ + passOnCommand(deviceCommand, commandData, commandDataLen); + return RETURN_OK; +} + +ReturnValue_t TestDevice::buildTestCommand1(DeviceCommandId_t deviceCommand, + const uint8_t* commandData, + size_t commandDataLen) { + using namespace testdevice; + if(commandDataLen < 7) { + return DeviceHandlerIF::INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS; + } + if(fullInfoPrintout) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "TestDevice" << deviceIdx << "::buildTestCommand1: Executing command with " + "data reply" << std::endl; +#else + sif::printInfo("TestDevice%d:buildTestCommand1: Executing command with data reply\n", + deviceIdx); +#endif + } + + deviceCommand = EndianConverter::convertBigEndian(deviceCommand); + memcpy(commandBuffer, &deviceCommand, sizeof(deviceCommand)); + + /* Assign and check parameters */ + uint16_t parameter1 = 0; + size_t size = commandDataLen; + ReturnValue_t result = SerializeAdapter::deSerialize(¶meter1, + &commandData, &size, SerializeIF::Endianness::BIG); + if(result == HasReturnvaluesIF::RETURN_FAILED) { + return result; + } + + /* Parameter 1 needs to be correct */ + if(parameter1 != testdevice::COMMAND_1_PARAM1) { + return DeviceHandlerIF::INVALID_COMMAND_PARAMETER; + } + uint64_t parameter2 = 0; + result = SerializeAdapter::deSerialize(¶meter2, + &commandData, &size, SerializeIF::Endianness::BIG); + if(parameter2!= testdevice::COMMAND_1_PARAM2){ + return DeviceHandlerIF::INVALID_COMMAND_PARAMETER; + } + + /* Pass on the parameters to the Echo IF */ + commandBuffer[4] = (parameter1 & 0xFF00) >> 8; + commandBuffer[5] = (parameter1 & 0xFF); + parameter2 = EndianConverter::convertBigEndian(parameter2); + memcpy(commandBuffer + 6, ¶meter2, sizeof(parameter2)); + rawPacket = commandBuffer; + rawPacketLen = sizeof(deviceCommand) + sizeof(parameter1) + + sizeof(parameter2); + return RETURN_OK; +} + +void TestDevice::passOnCommand(DeviceCommandId_t command, const uint8_t *commandData, + size_t commandDataLen) { + DeviceCommandId_t deviceCommandBe = EndianConverter::convertBigEndian(command); + memcpy(commandBuffer, &deviceCommandBe, sizeof(deviceCommandBe)); + memcpy(commandBuffer + 4, commandData, commandDataLen); + rawPacket = commandBuffer; + rawPacketLen = sizeof(deviceCommandBe) + commandDataLen; +} + +void TestDevice::fillCommandAndReplyMap() { + namespace td = testdevice; + insertInCommandAndReplyMap(testdevice::TEST_NORMAL_MODE_CMD, 5, &dataset); + insertInCommandAndReplyMap(testdevice::TEST_COMMAND_0, 5); + insertInCommandAndReplyMap(testdevice::TEST_COMMAND_1, 5); + + /* No reply expected for these commands */ + insertInCommandMap(td::TEST_NOTIF_SNAPSHOT_SET); + insertInCommandMap(td::TEST_NOTIF_SNAPSHOT_VAR); +} + + +ReturnValue_t TestDevice::scanForReply(const uint8_t *start, size_t len, + DeviceCommandId_t *foundId, size_t *foundLen) { + using namespace testdevice; + + /* Unless a command was sent explicitely, we don't expect any replies and ignore this + the packet. On a real device, there might be replies which are sent without a previous + command. */ + if(not commandSent) { + return DeviceHandlerBase::IGNORE_FULL_PACKET; + } + else { + commandSent = false; + } + + if(len < sizeof(object_id_t)) { + return DeviceHandlerIF::LENGTH_MISSMATCH; + } + + size_t size = len; + ReturnValue_t result = SerializeAdapter::deSerialize(foundId, &start, &size, + SerializeIF::Endianness::BIG); + if (result != RETURN_OK) { + return result; + } + + DeviceCommandId_t pendingCmd = this->getPendingCommand(); + + switch(pendingCmd) { + + case(TEST_NORMAL_MODE_CMD): { + if(fullInfoPrintout) { +#if OBSW_VERBOSE_LEVEL >= 3 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "TestDevice::scanForReply: Reply for normal commnand (ID " << + TEST_NORMAL_MODE_CMD << ") received!" << std::endl; +#else + sif::printInfo("TestDevice%d::scanForReply: Reply for normal command (ID %d) " + "received!\n", deviceIdx, TEST_NORMAL_MODE_CMD); +#endif +#endif + } + + *foundLen = len; + *foundId = pendingCmd; + return RETURN_OK; + } + + case(TEST_COMMAND_0): { + if(len < TEST_COMMAND_0_SIZE) { + return DeviceHandlerIF::LENGTH_MISSMATCH; + } + if(fullInfoPrintout) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "TestDevice" << deviceIdx << "::scanForReply: Reply for simple command " + "(ID " << TEST_COMMAND_0 << ") received!" << std::endl; +#else + sif::printInfo("TestDevice%d::scanForReply: Reply for simple command (ID %d) " + "received!\n", deviceIdx, TEST_COMMAND_0); +#endif + } + + *foundLen = TEST_COMMAND_0_SIZE; + *foundId = pendingCmd; + return RETURN_OK; + } + + case(TEST_COMMAND_1): { + if(fullInfoPrintout) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "TestDevice" << deviceIdx << "::scanForReply: Reply for data command " + "(ID " << TEST_COMMAND_1 << ") received!" << std::endl; +#else + sif::printInfo("TestDevice%d::scanForReply: Reply for data command (ID %d) " + "received\n", deviceIdx, TEST_COMMAND_1); +#endif + } + + *foundLen = len; + *foundId = pendingCmd; + return RETURN_OK; + } + + default: + return DeviceHandlerIF::DEVICE_REPLY_INVALID; + } +} + + +ReturnValue_t TestDevice::interpretDeviceReply(DeviceCommandId_t id, + const uint8_t* packet) { + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + switch(id) { + /* Periodic replies */ + case testdevice::TEST_NORMAL_MODE_CMD: { + result = interpretingNormalModeReply(); + break; + } + /* Simple reply */ + case testdevice::TEST_COMMAND_0: { + result = interpretingTestReply0(id, packet); + break; + } + /* Data reply */ + case testdevice::TEST_COMMAND_1: { + result = interpretingTestReply1(id, packet); + break; + } + default: + return DeviceHandlerIF::DEVICE_REPLY_INVALID; + } + return result; +} + +ReturnValue_t TestDevice::interpretingNormalModeReply() { + CommandMessage directReplyMessage; + if(changingDatasets) { + PoolReadGuard readHelper(&dataset); + if(dataset.testUint8Var.value == 0) { + dataset.testUint8Var.value = 10; + dataset.testUint32Var.value = 777; + dataset.testFloat3Vec.value[0] = 2.5; + dataset.testFloat3Vec.value[1] = -2.5; + dataset.testFloat3Vec.value[2] = 2.5; + dataset.setValidity(true, true); + } + else { + dataset.testUint8Var.value = 0; + dataset.testUint32Var.value = 0; + dataset.testFloat3Vec.value[0] = 0.0; + dataset.testFloat3Vec.value[1] = 0.0; + dataset.testFloat3Vec.value[2] = 0.0; + dataset.setValidity(false, true); + } + return RETURN_OK; + } + + PoolReadGuard readHelper(&dataset); + if(dataset.testUint8Var.value == 0) { + /* Reset state */ + dataset.testUint8Var.value = 128; + } + else if(dataset.testUint8Var.value > 200) { + if(not resetAfterChange) { + /* This will trigger an update notification to the controller */ + dataset.testUint8Var.setChanged(true); + resetAfterChange = true; + /* Decrement by 30 automatically. This will prevent any additional notifications. */ + dataset.testUint8Var.value -= 30; + } + } + /* If the value is greater than 0, it will be decremented in a linear way */ + else if(dataset.testUint8Var.value > 128) { + size_t sizeToDecrement = 0; + if(dataset.testUint8Var.value > 128 + 30) { + sizeToDecrement = 30; + } + else { + sizeToDecrement = dataset.testUint8Var.value - 128; + resetAfterChange = false; + } + dataset.testUint8Var.value -= sizeToDecrement; + } + else if(dataset.testUint8Var.value < 50) { + if(not resetAfterChange) { + /* This will trigger an update snapshot to the controller */ + dataset.testUint8Var.setChanged(true); + resetAfterChange = true; + } + else { + /* Increment by 30 automatically. */ + dataset.testUint8Var.value += 30; + } + } + /* Increment in linear way */ + else if(dataset.testUint8Var.value < 128) { + size_t sizeToIncrement = 0; + if(dataset.testUint8Var.value < 128 - 20) { + sizeToIncrement = 20; + } + else { + sizeToIncrement = 128 - dataset.testUint8Var.value; + resetAfterChange = false; + } + dataset.testUint8Var.value += sizeToIncrement; + } + + /* TODO: Same for vector */ + float vectorMean = (dataset.testFloat3Vec.value[0] + dataset.testFloat3Vec.value[1] + + dataset.testFloat3Vec.value[2]) / 3.0; + + /* Lambda (private local function) */ + auto sizeToAdd = [](bool tooHigh, float currentVal) { + if(tooHigh) { + if(currentVal - 20.0 > 10.0) { + return -10.0; + } + else { + return 20.0 - currentVal; + } + } + else { + if(std::abs(currentVal + 20.0) > 10.0) { + return 10.0; + } + else { + return -20.0 - currentVal; + } + } + }; + + if(vectorMean > 20.0 and std::abs(vectorMean - 20.0) > 1.0) { + if(not resetAfterChange) { + dataset.testFloat3Vec.setChanged(true); + resetAfterChange = true; + } + else { + float sizeToDecrementVal0 = 0; + float sizeToDecrementVal1 = 0; + float sizeToDecrementVal2 = 0; + + sizeToDecrementVal0 = sizeToAdd(true, dataset.testFloat3Vec.value[0]); + sizeToDecrementVal1 = sizeToAdd(true, dataset.testFloat3Vec.value[1]); + sizeToDecrementVal2 = sizeToAdd(true, dataset.testFloat3Vec.value[2]); + + dataset.testFloat3Vec.value[0] += sizeToDecrementVal0; + dataset.testFloat3Vec.value[1] += sizeToDecrementVal1; + dataset.testFloat3Vec.value[2] += sizeToDecrementVal2; + } + } + else if (vectorMean < -20.0 and std::abs(vectorMean + 20.0) < 1.0) { + if(not resetAfterChange) { + dataset.testFloat3Vec.setChanged(true); + resetAfterChange = true; + } + else { + float sizeToDecrementVal0 = 0; + float sizeToDecrementVal1 = 0; + float sizeToDecrementVal2 = 0; + + sizeToDecrementVal0 = sizeToAdd(false, dataset.testFloat3Vec.value[0]); + sizeToDecrementVal1 = sizeToAdd(false, dataset.testFloat3Vec.value[1]); + sizeToDecrementVal2 = sizeToAdd(false, dataset.testFloat3Vec.value[2]); + + dataset.testFloat3Vec.value[0] += sizeToDecrementVal0; + dataset.testFloat3Vec.value[1] += sizeToDecrementVal1; + dataset.testFloat3Vec.value[2] += sizeToDecrementVal2; + } + } + else { + if(resetAfterChange) { + resetAfterChange = false; + } + } + + return RETURN_OK; +} + +ReturnValue_t TestDevice::interpretingTestReply0(DeviceCommandId_t id, const uint8_t* packet) { + CommandMessage commandMessage; + if(fullInfoPrintout) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "TestDevice::interpretingTestReply0: Generating step and finish reply" << + std::endl; +#else + sif::printInfo("TestDevice::interpretingTestReply0: Generating step and finish reply\n"); +#endif + } + + MessageQueueId_t commander = getCommanderQueueId(id); + /* Generate one step reply and the finish reply */ + actionHelper.step(1, commander, id); + actionHelper.finish(true, commander, id); + + return RETURN_OK; +} + +ReturnValue_t TestDevice::interpretingTestReply1(DeviceCommandId_t id, + const uint8_t* packet) { + CommandMessage directReplyMessage; + if(fullInfoPrintout) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "TestDevice" << deviceIdx << "::interpretingReply1: Setting data reply" << + std::endl; +#else + sif::printInfo("TestDevice%d::interpretingReply1: Setting data reply\n", deviceIdx); +#endif + } + + MessageQueueId_t commander = getCommanderQueueId(id); + /* Send reply with data */ + ReturnValue_t result = actionHelper.reportData(commander, id, packet, + testdevice::TEST_COMMAND_1_SIZE, false); + + if (result != RETURN_OK) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "TestDevice" << deviceIdx << "::interpretingReply1: Sending data " + "reply failed!" << std::endl; +#else + sif::printError("TestDevice%d::interpretingReply1: Sending data reply failed!\n", + deviceIdx); +#endif + return result; + } + + if(result == HasReturnvaluesIF::RETURN_OK) { + /* Finish reply */ + actionHelper.finish(true, commander, id); + } + else { + /* Finish reply */ + actionHelper.finish(false, commander, id, result); + } + + return RETURN_OK; +} + +uint32_t TestDevice::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { + return 5000; +} + +void TestDevice::enableFullDebugOutput(bool enable) { + this->fullInfoPrintout = enable; +} + +ReturnValue_t TestDevice::initializeLocalDataPool(localpool::DataPool &localDataPoolMap, + LocalDataPoolManager &poolManager) { + namespace td = testdevice; + localDataPoolMap.emplace(td::PoolIds::TEST_UINT8_ID, new PoolEntry({0})); + localDataPoolMap.emplace(td::PoolIds::TEST_UINT32_ID, new PoolEntry({0})); + localDataPoolMap.emplace(td::PoolIds::TEST_FLOAT_VEC_3_ID, + new PoolEntry({0.0, 0.0, 0.0})); + + sid_t sid; + if(deviceIdx == td::DeviceIndex::DEVICE_0) { + sid = td::TEST_SET_DEV_0_SID; + } + else { + sid = td::TEST_SET_DEV_1_SID; + } + /* Subscribe for periodic HK packets but do not enable reporting for now. + Non-diangostic with a period of one second */ + poolManager.subscribeForPeriodicPacket(sid, false, 1.0, false); + return HasReturnvaluesIF::RETURN_OK; +} + + +ReturnValue_t TestDevice::getParameter(uint8_t domainId, uint8_t uniqueId, + ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues, + uint16_t startAtIndex) { + using namespace testdevice; + switch (uniqueId) { + case ParameterUniqueIds::TEST_UINT32_0: { + if(fullInfoPrintout) { + uint32_t newValue = 0; + ReturnValue_t result = newValues->getElement(&newValue, 0, 0); + if(result == HasReturnvaluesIF::RETURN_OK) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "TestDevice" << deviceIdx << "::getParameter: Setting parameter 0 to " + "new value " << newValue << std::endl; +#else + sif::printInfo("TestDevice%d::getParameter: Setting parameter 0 to new value %lu\n", + deviceIdx, static_cast(newValue)); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ + } + } + parameterWrapper->set(testParameter0); + break; + } + case ParameterUniqueIds::TEST_INT32_1: { + if(fullInfoPrintout) { + int32_t newValue = 0; + ReturnValue_t result = newValues->getElement(&newValue, 0, 0); + if(result == HasReturnvaluesIF::RETURN_OK) { +#if OBSW_DEVICE_HANDLER_PRINTOUT == 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "TestDevice" << deviceIdx << "::getParameter: Setting parameter 1 to " + "new value " << newValue << std::endl; +#else + sif::printInfo("TestDevice%d::getParameter: Setting parameter 1 to new value %lu\n", + deviceIdx, static_cast(newValue)); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ +#endif /* OBSW_DEVICE_HANDLER_PRINTOUT == 1 */ + } + } + parameterWrapper->set(testParameter1); + break; + } + case ParameterUniqueIds::TEST_FLOAT_VEC3_2: { + if(fullInfoPrintout) { + float newVector[3]; + if(newValues->getElement(newVector, 0, 0) != RETURN_OK or + newValues->getElement(newVector + 1, 0, 1) != RETURN_OK or + newValues->getElement(newVector + 2, 0, 2) != RETURN_OK) { + return HasReturnvaluesIF::RETURN_FAILED; + } +#if OBSW_DEVICE_HANDLER_PRINTOUT == 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "TestDevice" << deviceIdx << "::getParameter: Setting parameter 3 to " + "(float vector with 3 entries) to new values [" << newVector[0] << ", " << + newVector[1] << ", " << newVector[2] << "]" << std::endl; +#else + sif::printInfo("TestDevice%d::getParameter: Setting parameter 3 to new values " + "[%f, %f, %f]\n", deviceIdx, newVector[0], newVector[1], newVector[2]); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ +#endif /* OBSW_DEVICE_HANDLER_PRINTOUT == 1 */ + } + parameterWrapper->setVector(vectorFloatParams2); + break; + } + case(ParameterUniqueIds::PERIODIC_PRINT_ENABLED): { + if(fullInfoPrintout) { + uint8_t enabled = 0; + ReturnValue_t result = newValues->getElement(&enabled, 0, 0); + if(result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + char const* printout = nullptr; + if (enabled) { + printout = "enabled"; + } + else { + printout = "disabled"; + } +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "TestDevice" << deviceIdx << "::getParameter: Periodic printout " << + printout << std::endl; +#else + sif::printInfo("TestDevice%d::getParameter: Periodic printout %s", printout); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ + } + + parameterWrapper->set(periodicPrintout); + break; + } + case(ParameterUniqueIds::CHANGING_DATASETS): { + + uint8_t enabled = 0; + ReturnValue_t result = newValues->getElement(&enabled, 0, 0); + if(result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + if(not enabled) { + PoolReadGuard readHelper(&dataset); + dataset.testUint8Var.value = 0; + dataset.testUint32Var.value = 0; + dataset.testFloat3Vec.value[0] = 0.0; + dataset.testFloat3Vec.value[0] = 0.0; + dataset.testFloat3Vec.value[1] = 0.0; + } + + if(fullInfoPrintout) { + char const* printout = nullptr; + if (enabled) { + printout = "enabled"; + } + else { + printout = "disabled"; + } +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "TestDevice" << deviceIdx << "::getParameter: Changing datasets " << + printout << std::endl; +#else + sif::printInfo("TestDevice%d::getParameter: Changing datasets %s", printout); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ + } + + parameterWrapper->set(changingDatasets); + break; + } + default: + return INVALID_IDENTIFIER_ID; + } + return HasReturnvaluesIF::RETURN_OK; +} + +LocalPoolObjectBase* TestDevice::getPoolObjectHandle(lp_id_t localPoolId) { + namespace td = testdevice; + if (localPoolId == td::PoolIds::TEST_UINT8_ID) { + return &dataset.testUint8Var; + } + else if (localPoolId == td::PoolIds::TEST_UINT32_ID) { + return &dataset.testUint32Var; + } + else if(localPoolId == td::PoolIds::TEST_FLOAT_VEC_3_ID) { + return &dataset.testFloat3Vec; + } + else { + return nullptr; + } +} diff --git a/tests/src/fsfw_tests/integration/devices/TestDeviceHandler.h b/tests/src/fsfw_tests/integration/devices/TestDeviceHandler.h new file mode 100644 index 00000000..0eb47731 --- /dev/null +++ b/tests/src/fsfw_tests/integration/devices/TestDeviceHandler.h @@ -0,0 +1,142 @@ +#ifndef TEST_TESTDEVICES_TESTDEVICEHANDLER_H_ +#define TEST_TESTDEVICES_TESTDEVICEHANDLER_H_ + +#include "devicedefinitions/testDeviceDefinitions.h" + +#include "fsfw/devicehandlers/DeviceHandlerBase.h" +#include "fsfw/globalfunctions/PeriodicOperationDivider.h" +#include "fsfw/timemanager/Countdown.h" + +/** + * @brief Basic dummy device handler to test device commanding without a physical device. + * @details + * This test device handler provided a basic demo for the device handler object. + * It can also be commanded with the following PUS services, using + * the specified object ID of the test device handler. + * + * 1. PUS Service 8 - Functional commanding + * 2. PUS Service 2 - Device access, raw commanding + * 3. PUS Service 20 - Parameter Management + * 4. PUS Service 3 - Housekeeping + + * @author R. Mueller + * @ingroup devices + */ +class TestDevice: public DeviceHandlerBase { +public: + /** + * Build the test device in the factory. + * @param objectId This ID will be assigned to the test device handler. + * @param comIF The ID of the Communication IF used by test device handler. + * @param cookie Cookie object used by the test device handler. This is + * also used and passed to the comIF object. + * @param onImmediately This will start a transition to MODE_ON immediately + * so the device handler jumps into #doStartUp. Should only be used + * in development to reduce need of commanding while debugging. + * @param changingDataset + * Will be used later to change the local datasets containeds in the device. + */ + TestDevice(object_id_t objectId, object_id_t comIF, CookieIF * cookie, + testdevice::DeviceIndex deviceIdx = testdevice::DeviceIndex::DEVICE_0, + bool fullInfoPrintout = false, bool changingDataset = true); + + /** + * This can be used to enable and disable a lot of demo print output. + * @param enable + */ + void enableFullDebugOutput(bool enable); + + virtual ~ TestDevice(); + + //! Size of internal buffer used for communication. + static constexpr uint8_t MAX_BUFFER_SIZE = 255; + + //! Unique index if the device handler is created multiple times. + testdevice::DeviceIndex deviceIdx = testdevice::DeviceIndex::DEVICE_0; + +protected: + testdevice::TestDataSet dataset; + //! This is used to reset the dataset after a commanded change has been made. + bool resetAfterChange = false; + bool commandSent = false; + + /** DeviceHandlerBase overrides (see DHB documentation) */ + + /** + * Hook into the DHB #performOperation call which is executed + * periodically. + */ + void performOperationHook() override; + + virtual void doStartUp() override; + virtual void doShutDown() override; + + virtual ReturnValue_t buildNormalDeviceCommand( + DeviceCommandId_t * id) override; + virtual ReturnValue_t buildTransitionDeviceCommand( + DeviceCommandId_t * id) override; + virtual ReturnValue_t buildCommandFromCommand(DeviceCommandId_t + deviceCommand, const uint8_t * commandData, + size_t commandDataLen) override; + + virtual void fillCommandAndReplyMap() override; + + virtual ReturnValue_t scanForReply(const uint8_t *start, size_t len, + DeviceCommandId_t *foundId, size_t *foundLen) override; + virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, + const uint8_t *packet) override; + virtual uint32_t getTransitionDelayMs(Mode_t modeFrom, + Mode_t modeTo) override; + + virtual void doTransition(Mode_t modeFrom, Submode_t subModeFrom) override; + + virtual ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, + LocalDataPoolManager& poolManager) override; + virtual LocalPoolObjectBase* getPoolObjectHandle(lp_id_t localPoolId) override; + + /* HasParametersIF overrides */ + virtual ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId, + ParameterWrapper *parameterWrapper, + const ParameterWrapper *newValues, uint16_t startAtIndex) override; + + uint8_t commandBuffer[MAX_BUFFER_SIZE]; + + bool fullInfoPrintout = false; + bool oneShot = true; + + /* Variables for parameter service */ + uint32_t testParameter0 = 0; + int32_t testParameter1 = -2; + float vectorFloatParams2[3] = {}; + + /* Change device handler functionality, changeable via parameter service */ + uint8_t periodicPrintout = false; + uint8_t changingDatasets = false; + + ReturnValue_t buildNormalModeCommand(DeviceCommandId_t deviceCommand, + const uint8_t* commandData, size_t commandDataLen); + ReturnValue_t buildTestCommand0(DeviceCommandId_t deviceCommand, const uint8_t* commandData, + size_t commandDataLen); + ReturnValue_t buildTestCommand1(DeviceCommandId_t deviceCommand, const uint8_t* commandData, + size_t commandDataLen); + void passOnCommand(DeviceCommandId_t command, const uint8_t* commandData, + size_t commandDataLen); + + ReturnValue_t interpretingNormalModeReply(); + ReturnValue_t interpretingTestReply0(DeviceCommandId_t id, + const uint8_t* packet); + ReturnValue_t interpretingTestReply1(DeviceCommandId_t id, + const uint8_t* packet); + ReturnValue_t interpretingTestReply2(DeviceCommandId_t id, const uint8_t* packet); + + /* Some timer utilities */ + uint8_t divider1 = 2; + PeriodicOperationDivider opDivider1 = PeriodicOperationDivider(divider1); + uint8_t divider2 = 10; + PeriodicOperationDivider opDivider2 = PeriodicOperationDivider(divider2); + static constexpr uint32_t initTimeout = 2000; + Countdown countdown1 = Countdown(initTimeout); +}; + + +#endif /* TEST_TESTDEVICES_TESTDEVICEHANDLER_H_ */ diff --git a/tests/src/fsfw_tests/integration/devices/TestEchoComIF.cpp b/tests/src/fsfw_tests/integration/devices/TestEchoComIF.cpp new file mode 100644 index 00000000..afb23a06 --- /dev/null +++ b/tests/src/fsfw_tests/integration/devices/TestEchoComIF.cpp @@ -0,0 +1,86 @@ +#include "TestEchoComIF.h" +#include "TestCookie.h" + +#include +#include +#include +#include + + +TestEchoComIF::TestEchoComIF(object_id_t objectId): + SystemObject(objectId) { +} + +TestEchoComIF::~TestEchoComIF() {} + +ReturnValue_t TestEchoComIF::initializeInterface(CookieIF * cookie) { + TestCookie* dummyCookie = dynamic_cast(cookie); + if(dummyCookie == nullptr) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "TestEchoComIF::initializeInterface: Invalid cookie!" << std::endl; +#else + sif::printWarning("TestEchoComIF::initializeInterface: Invalid cookie!\n"); +#endif + return NULLPOINTER; + } + + auto resultPair = replyMap.emplace( + dummyCookie->getAddress(), ReplyBuffer(dummyCookie->getReplyMaxLen())); + if(not resultPair.second) { + return HasReturnvaluesIF::RETURN_FAILED; + } + return RETURN_OK; +} + +ReturnValue_t TestEchoComIF::sendMessage(CookieIF *cookie, + const uint8_t * sendData, size_t sendLen) { + TestCookie* dummyCookie = dynamic_cast(cookie); + if(dummyCookie == nullptr) { + return NULLPOINTER; + } + + ReplyBuffer& replyBuffer = replyMap.find(dummyCookie->getAddress())->second; + if(sendLen > replyBuffer.capacity()) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "TestEchoComIF::sendMessage: Send length " << sendLen << " larger than " + "current reply buffer length!" << std::endl; +#else + sif::printWarning("TestEchoComIF::sendMessage: Send length %d larger than current " + "reply buffer length!\n", sendLen); +#endif + return HasReturnvaluesIF::RETURN_FAILED; + } + replyBuffer.resize(sendLen); + memcpy(replyBuffer.data(), sendData, sendLen); + return RETURN_OK; +} + +ReturnValue_t TestEchoComIF::getSendSuccess(CookieIF *cookie) { + return RETURN_OK; +} + +ReturnValue_t TestEchoComIF::requestReceiveMessage(CookieIF *cookie, + size_t requestLen) { + return RETURN_OK; +} + +ReturnValue_t TestEchoComIF::readReceivedMessage(CookieIF *cookie, + uint8_t **buffer, size_t *size) { + TestCookie* dummyCookie = dynamic_cast(cookie); + if(dummyCookie == nullptr) { + return NULLPOINTER; + } + + ReplyBuffer& replyBuffer = replyMap.find(dummyCookie->getAddress())->second; + *buffer = replyBuffer.data(); + *size = replyBuffer.size(); + + dummyReplyCounter ++; + if(dummyReplyCounter == 10) { + // add anything that needs to be read periodically by dummy handler + dummyReplyCounter = 0; + } + return RETURN_OK; + +} + diff --git a/tests/src/fsfw_tests/integration/devices/TestEchoComIF.h b/tests/src/fsfw_tests/integration/devices/TestEchoComIF.h new file mode 100644 index 00000000..38270cfe --- /dev/null +++ b/tests/src/fsfw_tests/integration/devices/TestEchoComIF.h @@ -0,0 +1,56 @@ +#ifndef TEST_TESTDEVICES_TESTECHOCOMIF_H_ +#define TEST_TESTDEVICES_TESTECHOCOMIF_H_ + +#include +#include +#include +#include + +#include + +/** + * @brief Used to simply returned sent data from device handler + * @details Assign this com IF in the factory when creating the device handler + * @ingroup test + */ +class TestEchoComIF: public DeviceCommunicationIF, public SystemObject { +public: + TestEchoComIF(object_id_t objectId); + virtual ~TestEchoComIF(); + + /** + * DeviceCommunicationIF overrides + * (see DeviceCommunicationIF documentation + */ + ReturnValue_t initializeInterface(CookieIF * cookie) override; + ReturnValue_t sendMessage(CookieIF *cookie, const uint8_t * sendData, + size_t sendLen) override; + ReturnValue_t getSendSuccess(CookieIF *cookie) override; + ReturnValue_t requestReceiveMessage(CookieIF *cookie, + size_t requestLen) override; + ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer, + size_t *size) override; + +private: + + /** + * Send TM packet which contains received data as TM[17,130]. + * Wiretapping will do the same. + * @param data + * @param len + */ + void sendTmPacket(const uint8_t *data,uint32_t len); + + AcceptsTelemetryIF* funnel = nullptr; + MessageQueueIF* tmQueue = nullptr; + size_t replyMaxLen = 0; + + using ReplyBuffer = std::vector; + std::map replyMap; + + uint8_t dummyReplyCounter = 0; + + uint16_t packetSubCounter = 0; +}; + +#endif /* TEST_TESTDEVICES_TESTECHOCOMIF_H_ */ diff --git a/tests/src/fsfw_tests/integration/devices/devicedefinitions/testDeviceDefinitions.h b/tests/src/fsfw_tests/integration/devices/devicedefinitions/testDeviceDefinitions.h new file mode 100644 index 00000000..10668b94 --- /dev/null +++ b/tests/src/fsfw_tests/integration/devices/devicedefinitions/testDeviceDefinitions.h @@ -0,0 +1,100 @@ +#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_TESTDEVICEDEFINITIONS_H_ +#define MISSION_DEVICES_DEVICEDEFINITIONS_TESTDEVICEDEFINITIONS_H_ + +#include +#include +#include + +namespace testdevice { + +enum ParameterUniqueIds: uint8_t { + TEST_UINT32_0, + TEST_INT32_1, + TEST_FLOAT_VEC3_2, + PERIODIC_PRINT_ENABLED, + CHANGING_DATASETS +}; + +enum DeviceIndex: uint32_t { + DEVICE_0, + DEVICE_1 +}; + +/** Normal mode command. This ID is also used to access the set variable via the housekeeping +service */ +static constexpr DeviceCommandId_t TEST_NORMAL_MODE_CMD = 0; + +//! Test completion reply +static constexpr DeviceCommandId_t TEST_COMMAND_0 = 1; +//! Test data reply +static constexpr DeviceCommandId_t TEST_COMMAND_1 = 2; + +/** + * Can be used to trigger a notification to the demo controller. For DEVICE_0, only notifications + * messages will be generated while for DEVICE_1, snapshot messages will be generated. + * + * DEVICE_0 VAR: Sets the set variable 0 above a treshold (200) to trigger a variable + * notification. + * DEVICE_0 SET: Sets the vector mean values above a treshold (mean larger than 20) to trigger a + * set notification. + * + * DEVICE_1 VAR: Sets the set variable 0 below a treshold (less than 50 but not 0) to trigger a + * variable snapshot. + * DEVICE_1 SET: Sets the set vector mean values below a treshold (mean smaller than -20) to + * trigger a set snapshot message. + */ +static constexpr DeviceCommandId_t TEST_NOTIF_SNAPSHOT_VAR = 3; +static constexpr DeviceCommandId_t TEST_NOTIF_SNAPSHOT_SET = 4; + +/** + * Can be used to trigger a snapshot message to the demo controller. + * Depending on the device index, a notification will be triggered for different set variables. + * + * DEVICE_0: Sets the set variable 0 below a treshold (below 50 but not 0) to trigger + * a variable snapshot + * DEVICE_1: Sets the vector mean values below a treshold (mean less than -20) to trigger a + * set snapshot + */ +static constexpr DeviceCommandId_t TEST_SNAPSHOT = 5; + +//! Generates a random value for variable 1 of the dataset. +static constexpr DeviceCommandId_t GENERATE_SET_VAR_1_RNG_VALUE = 6; + + +/** + * These parameters are sent back with the command ID as a data reply + */ +static constexpr uint16_t COMMAND_1_PARAM1 = 0xBAB0; //!< param1, 2 bytes +//! param2, 8 bytes +static constexpr uint64_t COMMAND_1_PARAM2 = 0x000000524F42494E; + +static constexpr size_t TEST_COMMAND_0_SIZE = sizeof(TEST_COMMAND_0); +static constexpr size_t TEST_COMMAND_1_SIZE = sizeof(TEST_COMMAND_1) + sizeof(COMMAND_1_PARAM1) + + sizeof(COMMAND_1_PARAM2); + +enum PoolIds: lp_id_t { + TEST_UINT8_ID = 0, + TEST_UINT32_ID = 1, + TEST_FLOAT_VEC_3_ID = 2 +}; + +static constexpr uint8_t TEST_SET_ID = TEST_NORMAL_MODE_CMD; +static const sid_t TEST_SET_DEV_0_SID = sid_t(objects::TEST_DEVICE_HANDLER_0, TEST_SET_ID); +static const sid_t TEST_SET_DEV_1_SID = sid_t(objects::TEST_DEVICE_HANDLER_1, TEST_SET_ID); + +class TestDataSet: public StaticLocalDataSet<3> { +public: + TestDataSet(HasLocalDataPoolIF* owner): StaticLocalDataSet(owner, TEST_SET_ID) {} + TestDataSet(object_id_t owner): StaticLocalDataSet(sid_t(owner, TEST_SET_ID)) {} + + lp_var_t testUint8Var = lp_var_t( + gp_id_t(this->getCreatorObjectId(), PoolIds::TEST_UINT8_ID), this); + lp_var_t testUint32Var = lp_var_t( + gp_id_t(this->getCreatorObjectId(), PoolIds::TEST_UINT32_ID), this); + lp_vec_t testFloat3Vec = lp_vec_t( + gp_id_t(this->getCreatorObjectId(), PoolIds::TEST_FLOAT_VEC_3_ID), this); +}; + +} + +#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_TESTDEVICEDEFINITIONS_H_ */ diff --git a/tests/src/fsfw_tests/integration/task/CMakeLists.txt b/tests/src/fsfw_tests/integration/task/CMakeLists.txt new file mode 100644 index 00000000..0402d093 --- /dev/null +++ b/tests/src/fsfw_tests/integration/task/CMakeLists.txt @@ -0,0 +1,3 @@ +target_sources(${TARGET_NAME} PRIVATE + TestTask.cpp +) \ No newline at end of file diff --git a/tests/src/fsfw_tests/integration/task/TestTask.cpp b/tests/src/fsfw_tests/integration/task/TestTask.cpp new file mode 100644 index 00000000..c9910e90 --- /dev/null +++ b/tests/src/fsfw_tests/integration/task/TestTask.cpp @@ -0,0 +1,80 @@ +#include "TestTask.h" + +#include +#include + +bool TestTask::oneShotAction = true; +MutexIF* TestTask::testLock = nullptr; + +TestTask::TestTask(object_id_t objectId, bool periodicPrintout, bool periodicEvent): + SystemObject(objectId), testMode(testModes::A), + periodicPrinout(periodicPrintout), periodicEvent(periodicEvent) { + if(testLock == nullptr) { + testLock = MutexFactory::instance()->createMutex(); + } + IPCStore = ObjectManager::instance()->get(objects::IPC_STORE); +} + +TestTask::~TestTask() { +} + +ReturnValue_t TestTask::performOperation(uint8_t operationCode) { + ReturnValue_t result = RETURN_OK; + testLock->lockMutex(MutexIF::TimeoutType::WAITING, 20); + if(oneShotAction) { + // Add code here which should only be run once + performOneShotAction(); + oneShotAction = false; + } + testLock->unlockMutex(); + + // Add code here which should only be run once per performOperation + performPeriodicAction(); + + // Add code here which should only be run on alternating cycles. + if(testMode == testModes::A) { + performActionA(); + testMode = testModes::B; + } + else if(testMode == testModes::B) { + performActionB(); + testMode = testModes::A; + } + return result; +} + +ReturnValue_t TestTask::performOneShotAction() { + /* Everything here will only be performed once. */ + return HasReturnvaluesIF::RETURN_OK; +} + + +ReturnValue_t TestTask::performPeriodicAction() { + /* This is performed each task cycle */ + ReturnValue_t result = RETURN_OK; + + if(periodicPrinout) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "TestTask::performPeriodicAction: Hello World!" << std::endl; +#else + sif::printInfo("TestTask::performPeriodicAction: Hello World!\n"); +#endif + } + if(periodicEvent) { + triggerEvent(TEST_EVENT, 0x1234, 0x4321); + } + return result; +} + +ReturnValue_t TestTask::performActionA() { + /* This is performed each alternating task cycle */ + ReturnValue_t result = RETURN_OK; + return result; +} + +ReturnValue_t TestTask::performActionB() { + /* This is performed each alternating task cycle */ + ReturnValue_t result = RETURN_OK; + return result; +} + diff --git a/tests/src/fsfw_tests/integration/task/TestTask.h b/tests/src/fsfw_tests/integration/task/TestTask.h new file mode 100644 index 00000000..95f27bec --- /dev/null +++ b/tests/src/fsfw_tests/integration/task/TestTask.h @@ -0,0 +1,56 @@ +#ifndef MISSION_DEMO_TESTTASK_H_ +#define MISSION_DEMO_TESTTASK_H_ + +#include +#include +#include + +#include "fsfw/events/Event.h" +#include "events/subsystemIdRanges.h" + +/** + * @brief Test class for general C++ testing and any other code which will not be part of the + * primary mission software. + * @details + * Should not be used for board specific tests. Instead, a derived board test class should be used. + */ +class TestTask : + public SystemObject, + public ExecutableObjectIF, + public HasReturnvaluesIF { +public: + TestTask(object_id_t objectId, bool periodicPrintout = false, bool periodicEvent = false); + virtual ~TestTask(); + virtual ReturnValue_t performOperation(uint8_t operationCode = 0); + + static constexpr uint8_t subsystemId = SUBSYSTEM_ID::TEST_TASK_ID; + static constexpr Event TEST_EVENT = event::makeEvent(subsystemId, 0, severity::INFO); + +protected: + virtual ReturnValue_t performOneShotAction(); + virtual ReturnValue_t performPeriodicAction(); + virtual ReturnValue_t performActionA(); + virtual ReturnValue_t performActionB(); + + enum testModes: uint8_t { + A, + B + }; + + testModes testMode; + bool periodicPrinout = false; + bool periodicEvent = false; + + bool testFlag = false; + uint8_t counter { 1 }; + uint8_t counterTrigger { 3 }; + + void performPusInjectorTest(); + void examplePacketTest(); +private: + static bool oneShotAction; + static MutexIF* testLock; + StorageManagerIF* IPCStore; +}; + +#endif /* TESTTASK_H_ */ From afe8fe6605d81b7d597e802b1b1ac980c3642014 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 18 Oct 2021 13:58:18 +0200 Subject: [PATCH 54/89] assign correct init value --- src/fsfw/tcdistribution/PUSDistributor.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/fsfw/tcdistribution/PUSDistributor.cpp b/src/fsfw/tcdistribution/PUSDistributor.cpp index 284a14c9..adab58c8 100644 --- a/src/fsfw/tcdistribution/PUSDistributor.cpp +++ b/src/fsfw/tcdistribution/PUSDistributor.cpp @@ -29,7 +29,7 @@ PUSDistributor::TcMqMapIter PUSDistributor::selectDestination() { tcStatus = checker.checkPacket(currentPacket); if(tcStatus != HasReturnvaluesIF::RETURN_OK) { #if FSFW_VERBOSE_LEVEL >= 1 - const char* keyword = nullptr; + const char* keyword = "unnamed error"; if(tcStatus == TcPacketCheck::INCORRECT_CHECKSUM) { keyword = "checksum"; } @@ -45,9 +45,6 @@ PUSDistributor::TcMqMapIter PUSDistributor::selectDestination() { else if(tcStatus == TcPacketCheck::INCOMPLETE_PACKET) { keyword = "incomplete packet"; } - else { - keyword = "unnamed error"; - } #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "PUSDistributor::handlePacket: Packet format invalid, " << keyword << " error" << std::endl; From cee42f9b70a4fc8b2bf2b593a0de6118a7173505 Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Mon, 18 Oct 2021 14:34:11 +0200 Subject: [PATCH 55/89] one } was on the wrong side of an #endif --- src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.cpp index 20a8ed89..523fb619 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.cpp @@ -118,7 +118,7 @@ void TmPacketStoredBase::handleStoreFailure(const char *const packetType, Return "%d too large\n", packetType, sizeToReserve); break; } -#endif #endif } +#endif } From a077a1b5877032bedabe931ecdbc1a1048c3e333 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 18 Oct 2021 15:07:00 +0200 Subject: [PATCH 56/89] improved constexpr macros --- src/fsfw/tmtcpacket/SpacePacket.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/fsfw/tmtcpacket/SpacePacket.h b/src/fsfw/tmtcpacket/SpacePacket.h index dad8b95e..677ba023 100644 --- a/src/fsfw/tmtcpacket/SpacePacket.h +++ b/src/fsfw/tmtcpacket/SpacePacket.h @@ -71,12 +71,20 @@ protected: namespace spacepacket { -constexpr uint16_t getTcSpacePacketIdFromApid(uint16_t apid) { - return (0x18 << 8) | (((apid >> 8) & 0x07) << 8) | (apid & 0x00ff); +constexpr uint16_t getSpacePacketIdFromApid(bool isTc, uint16_t apid, + bool secondaryHeaderFlag = true) { + return (((isTc << 5) & 0x10) | ((secondaryHeaderFlag << 4) & 0x08) | + ((apid >> 8) & 0x07)) << 8 | (apid & 0x00ff); } -constexpr uint16_t getTmSpacePacketIdFromApid(uint16_t apid) { - return (0x08 << 8) | (((apid >> 8) & 0x07) << 8) | (apid & 0x00ff); +constexpr uint16_t getTcSpacketIdFromApid(uint16_t apid, + bool secondaryHeaderFlag = true) { + return getSpacePacketIdFromApid(true, apid, secondaryHeaderFlag); +} + +constexpr uint16_t getTmSpacketIdFromApid(uint16_t apid, + bool secondaryHeaderFlag = true) { + return getSpacePacketIdFromApid(false, apid, secondaryHeaderFlag); } } From 7122c37511ebea8e6c586556db6195cf2d91f636 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 18 Oct 2021 18:26:03 +0200 Subject: [PATCH 57/89] updated function names --- src/fsfw/tmtcpacket/SpacePacket.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fsfw/tmtcpacket/SpacePacket.h b/src/fsfw/tmtcpacket/SpacePacket.h index 677ba023..16673319 100644 --- a/src/fsfw/tmtcpacket/SpacePacket.h +++ b/src/fsfw/tmtcpacket/SpacePacket.h @@ -77,12 +77,12 @@ constexpr uint16_t getSpacePacketIdFromApid(bool isTc, uint16_t apid, ((apid >> 8) & 0x07)) << 8 | (apid & 0x00ff); } -constexpr uint16_t getTcSpacketIdFromApid(uint16_t apid, +constexpr uint16_t getTcSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag = true) { return getSpacePacketIdFromApid(true, apid, secondaryHeaderFlag); } -constexpr uint16_t getTmSpacketIdFromApid(uint16_t apid, +constexpr uint16_t getTmSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag = true) { return getSpacePacketIdFromApid(false, apid, secondaryHeaderFlag); } From a5a306ff66afad64b19f9e96ecd9ced815b378b6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 21 Oct 2021 22:36:54 +0200 Subject: [PATCH 58/89] arrayprinter format improvements --- src/fsfw/globalfunctions/arrayprinter.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/fsfw/globalfunctions/arrayprinter.cpp b/src/fsfw/globalfunctions/arrayprinter.cpp index 45a1cb38..82b2a6f5 100644 --- a/src/fsfw/globalfunctions/arrayprinter.cpp +++ b/src/fsfw/globalfunctions/arrayprinter.cpp @@ -45,11 +45,11 @@ void arrayprinter::printHex(const uint8_t *data, size_t size, std::cout << "\r" << std::endl; } - std::cout << "[" << std::hex; + std::cout << "hex [" << std::hex; for(size_t i = 0; i < size; i++) { - std::cout << "0x" << static_cast(data[i]); + std::cout << "" << static_cast(data[i]); if(i < size - 1) { - std::cout << " , "; + std::cout << ","; if(i > 0 and (i + 1) % maxCharPerLine == 0) { std::cout << std::endl; @@ -69,16 +69,16 @@ void arrayprinter::printHex(const uint8_t *data, size_t size, break; } - currentPos += snprintf(printBuffer + currentPos, 6, "0x%02x", data[i]); + currentPos += snprintf(printBuffer + currentPos, 6, "%02x", data[i]); if(i < size - 1) { - currentPos += sprintf(printBuffer + currentPos, ", "); + currentPos += sprintf(printBuffer + currentPos, ","); if(i > 0 and (i + 1) % maxCharPerLine == 0) { currentPos += sprintf(printBuffer + currentPos, "\n"); } } } #if FSFW_DISABLE_PRINTOUT == 0 - printf("[%s]\n", printBuffer); + printf("hex [%s]\n", printBuffer); #endif /* FSFW_DISABLE_PRINTOUT == 0 */ #endif } @@ -90,11 +90,11 @@ void arrayprinter::printDec(const uint8_t *data, size_t size, std::cout << "\r" << std::endl; } - std::cout << "[" << std::dec; + std::cout << "dec [" << std::dec; for(size_t i = 0; i < size; i++) { std::cout << static_cast(data[i]); if(i < size - 1){ - std::cout << " , "; + std::cout << ","; if(i > 0 and (i + 1) % maxCharPerLine == 0) { std::cout << std::endl; } @@ -114,14 +114,14 @@ void arrayprinter::printDec(const uint8_t *data, size_t size, currentPos += snprintf(printBuffer + currentPos, 3, "%d", data[i]); if(i < size - 1) { - currentPos += sprintf(printBuffer + currentPos, ", "); + currentPos += sprintf(printBuffer + currentPos, ","); if(i > 0 and (i + 1) % maxCharPerLine == 0) { currentPos += sprintf(printBuffer + currentPos, "\n"); } } } #if FSFW_DISABLE_PRINTOUT == 0 - printf("[%s]\n", printBuffer); + printf("dec [%s]\n", printBuffer); #endif /* FSFW_DISABLE_PRINTOUT == 0 */ #endif } From dc6ed40bfb7ff6ecbb472ae09ccf9ca38167c563 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 22 Oct 2021 11:30:00 +0200 Subject: [PATCH 59/89] arrayprinter format improvements --- src/fsfw/globalfunctions/arrayprinter.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/fsfw/globalfunctions/arrayprinter.cpp b/src/fsfw/globalfunctions/arrayprinter.cpp index 82b2a6f5..45a1cb38 100644 --- a/src/fsfw/globalfunctions/arrayprinter.cpp +++ b/src/fsfw/globalfunctions/arrayprinter.cpp @@ -45,11 +45,11 @@ void arrayprinter::printHex(const uint8_t *data, size_t size, std::cout << "\r" << std::endl; } - std::cout << "hex [" << std::hex; + std::cout << "[" << std::hex; for(size_t i = 0; i < size; i++) { - std::cout << "" << static_cast(data[i]); + std::cout << "0x" << static_cast(data[i]); if(i < size - 1) { - std::cout << ","; + std::cout << " , "; if(i > 0 and (i + 1) % maxCharPerLine == 0) { std::cout << std::endl; @@ -69,16 +69,16 @@ void arrayprinter::printHex(const uint8_t *data, size_t size, break; } - currentPos += snprintf(printBuffer + currentPos, 6, "%02x", data[i]); + currentPos += snprintf(printBuffer + currentPos, 6, "0x%02x", data[i]); if(i < size - 1) { - currentPos += sprintf(printBuffer + currentPos, ","); + currentPos += sprintf(printBuffer + currentPos, ", "); if(i > 0 and (i + 1) % maxCharPerLine == 0) { currentPos += sprintf(printBuffer + currentPos, "\n"); } } } #if FSFW_DISABLE_PRINTOUT == 0 - printf("hex [%s]\n", printBuffer); + printf("[%s]\n", printBuffer); #endif /* FSFW_DISABLE_PRINTOUT == 0 */ #endif } @@ -90,11 +90,11 @@ void arrayprinter::printDec(const uint8_t *data, size_t size, std::cout << "\r" << std::endl; } - std::cout << "dec [" << std::dec; + std::cout << "[" << std::dec; for(size_t i = 0; i < size; i++) { std::cout << static_cast(data[i]); if(i < size - 1){ - std::cout << ","; + std::cout << " , "; if(i > 0 and (i + 1) % maxCharPerLine == 0) { std::cout << std::endl; } @@ -114,14 +114,14 @@ void arrayprinter::printDec(const uint8_t *data, size_t size, currentPos += snprintf(printBuffer + currentPos, 3, "%d", data[i]); if(i < size - 1) { - currentPos += sprintf(printBuffer + currentPos, ","); + currentPos += sprintf(printBuffer + currentPos, ", "); if(i > 0 and (i + 1) % maxCharPerLine == 0) { currentPos += sprintf(printBuffer + currentPos, "\n"); } } } #if FSFW_DISABLE_PRINTOUT == 0 - printf("dec [%s]\n", printBuffer); + printf("[%s]\n", printBuffer); #endif /* FSFW_DISABLE_PRINTOUT == 0 */ #endif } From 07a0dd5331072c536cd30fd0505bfc1b38cc813b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 22 Oct 2021 11:32:28 +0200 Subject: [PATCH 60/89] this is the correct file --- src/fsfw/globalfunctions/arrayprinter.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/fsfw/globalfunctions/arrayprinter.cpp b/src/fsfw/globalfunctions/arrayprinter.cpp index 45a1cb38..964b9d04 100644 --- a/src/fsfw/globalfunctions/arrayprinter.cpp +++ b/src/fsfw/globalfunctions/arrayprinter.cpp @@ -45,18 +45,18 @@ void arrayprinter::printHex(const uint8_t *data, size_t size, std::cout << "\r" << std::endl; } - std::cout << "[" << std::hex; + std::cout << "hex [" << std::setfill('0') << std::hex; for(size_t i = 0; i < size; i++) { - std::cout << "0x" << static_cast(data[i]); + std::cout << std::setw(2) << static_cast(data[i]); if(i < size - 1) { - std::cout << " , "; + std::cout << ","; if(i > 0 and (i + 1) % maxCharPerLine == 0) { std::cout << std::endl; } } } - std::cout << std::dec; + std::cout << std::dec << std::setfill(' '); std::cout << "]" << std::endl; #else // General format: 0x01, 0x02, 0x03 so it is number of chars times 6 @@ -69,16 +69,16 @@ void arrayprinter::printHex(const uint8_t *data, size_t size, break; } - currentPos += snprintf(printBuffer + currentPos, 6, "0x%02x", data[i]); + currentPos += snprintf(printBuffer + currentPos, 6, "%02x", data[i]); if(i < size - 1) { - currentPos += sprintf(printBuffer + currentPos, ", "); + currentPos += sprintf(printBuffer + currentPos, ","); if(i > 0 and (i + 1) % maxCharPerLine == 0) { currentPos += sprintf(printBuffer + currentPos, "\n"); } } } #if FSFW_DISABLE_PRINTOUT == 0 - printf("[%s]\n", printBuffer); + printf("hex [%s]\n", printBuffer); #endif /* FSFW_DISABLE_PRINTOUT == 0 */ #endif } @@ -90,11 +90,11 @@ void arrayprinter::printDec(const uint8_t *data, size_t size, std::cout << "\r" << std::endl; } - std::cout << "[" << std::dec; + std::cout << "dec [" << std::dec; for(size_t i = 0; i < size; i++) { std::cout << static_cast(data[i]); if(i < size - 1){ - std::cout << " , "; + std::cout << ","; if(i > 0 and (i + 1) % maxCharPerLine == 0) { std::cout << std::endl; } @@ -114,14 +114,14 @@ void arrayprinter::printDec(const uint8_t *data, size_t size, currentPos += snprintf(printBuffer + currentPos, 3, "%d", data[i]); if(i < size - 1) { - currentPos += sprintf(printBuffer + currentPos, ", "); + currentPos += sprintf(printBuffer + currentPos, ","); if(i > 0 and (i + 1) % maxCharPerLine == 0) { currentPos += sprintf(printBuffer + currentPos, "\n"); } } } #if FSFW_DISABLE_PRINTOUT == 0 - printf("[%s]\n", printBuffer); + printf("dec [%s]\n", printBuffer); #endif /* FSFW_DISABLE_PRINTOUT == 0 */ #endif } From 19f9b0280c2ae45b4f029d9d852a8fb8631e79c8 Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Mon, 25 Oct 2021 14:59:16 +0200 Subject: [PATCH 61/89] added jenkins integration --- automation/Dockerfile | 8 ++++++++ automation/Jenkinsfile | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 automation/Dockerfile create mode 100644 automation/Jenkinsfile diff --git a/automation/Dockerfile b/automation/Dockerfile new file mode 100644 index 00000000..0526d8f0 --- /dev/null +++ b/automation/Dockerfile @@ -0,0 +1,8 @@ +FROM ubuntu:focal + +RUN apt-get update +RUN apt-get --yes upgrade + +#tzdata is a dependency, won't install otherwise +ARG DEBIAN_FRONTEND=noninteractive +RUN apt-get --yes install gcc g++ cmake lcov git nano diff --git a/automation/Jenkinsfile b/automation/Jenkinsfile new file mode 100644 index 00000000..a90037f8 --- /dev/null +++ b/automation/Jenkinsfile @@ -0,0 +1,38 @@ +pipeline { + agent any + stages { + stage('Clean') { + steps { + sh 'rm -rf build-unittests' + } + } + stage('Build') { + agent { + dockerfile { + dir 'automation' + additionalBuildArgs '--no-cache' + reuseNode true + } + } + steps { + dir('build-unittests') { + sh 'cmake -DFSFW_OSAL=host -DFSFW_BUILD_UNITTESTS=ON ..' + sh 'cmake --build . -j' + } + } + } + stage('Unittests') { + agent { + dockerfile { + dir 'automation' + reuseNode true + } + } + steps { + dir('build-unittests') { + sh 'cmake --build . -- fsfw-tests_coverage -j' + } + } + } + } +} From 81bae858254d496da5e48d734e8218218cd11eaa Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 26 Oct 2021 17:10:15 +0200 Subject: [PATCH 62/89] hotfix for unittests --- tests/src/fsfw_tests/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/src/fsfw_tests/CMakeLists.txt b/tests/src/fsfw_tests/CMakeLists.txt index fb03f562..f6e1b8ab 100644 --- a/tests/src/fsfw_tests/CMakeLists.txt +++ b/tests/src/fsfw_tests/CMakeLists.txt @@ -1,9 +1,9 @@ -add_subdirectory(integration) - if(FSFW_ADD_INTERNAL_TESTS) add_subdirectory(internal) endif() if(FSFW_BUILD_UNITTESTS) add_subdirectory(unit) +else() + add_subdirectory(integration) endif() From 5f8adc63b70298c0d6163219ad8782de76c22460 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 26 Oct 2021 17:16:21 +0200 Subject: [PATCH 63/89] some more fixes for integration tests --- .../integration/assemblies/TestAssembly.cpp | 4 ++-- .../integration/controller/TestController.cpp | 11 ++++++----- .../integration/controller/TestController.h | 3 ++- .../integration/devices/TestDeviceHandler.cpp | 8 +------- .../devices/devicedefinitions/testDeviceDefinitions.h | 3 --- 5 files changed, 11 insertions(+), 18 deletions(-) diff --git a/tests/src/fsfw_tests/integration/assemblies/TestAssembly.cpp b/tests/src/fsfw_tests/integration/assemblies/TestAssembly.cpp index 1c497ebd..0ead4bfd 100644 --- a/tests/src/fsfw_tests/integration/assemblies/TestAssembly.cpp +++ b/tests/src/fsfw_tests/integration/assemblies/TestAssembly.cpp @@ -160,11 +160,11 @@ ReturnValue_t TestAssembly::initialize() { handler1->setParentQueue(this->getCommandQueue()); - result = registerChild(objects::TEST_DEVICE_HANDLER_0); + result = registerChild(deviceHandler0Id); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - result = registerChild(objects::TEST_DEVICE_HANDLER_1); + result = registerChild(deviceHandler1Id); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } diff --git a/tests/src/fsfw_tests/integration/controller/TestController.cpp b/tests/src/fsfw_tests/integration/controller/TestController.cpp index 385d07bd..96da5fe3 100644 --- a/tests/src/fsfw_tests/integration/controller/TestController.cpp +++ b/tests/src/fsfw_tests/integration/controller/TestController.cpp @@ -5,10 +5,11 @@ #include #include -TestController::TestController(object_id_t objectId, size_t commandQueueDepth): +TestController::TestController(object_id_t objectId, object_id_t device0, object_id_t device1, + size_t commandQueueDepth): ExtendedControllerBase(objectId, objects::NO_OBJECT, commandQueueDepth), - deviceDataset0(objects::TEST_DEVICE_HANDLER_0), - deviceDataset1(objects::TEST_DEVICE_HANDLER_1) { + deviceDataset0(device0), + deviceDataset1(device1) { } TestController::~TestController() { @@ -163,7 +164,7 @@ ReturnValue_t TestController::initializeLocalDataPool(localpool::DataPool &local ReturnValue_t TestController::initializeAfterTaskCreation() { namespace td = testdevice; HasLocalDataPoolIF* device0 = ObjectManager::instance()->get( - objects::TEST_DEVICE_HANDLER_0); + deviceDataset0.getCreatorObjectId()); if(device0 == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "TestController::initializeAfterTaskCreation: Test device handler 0 " @@ -185,7 +186,7 @@ ReturnValue_t TestController::initializeAfterTaskCreation() { HasLocalDataPoolIF* device1 = ObjectManager::instance()->get( - objects::TEST_DEVICE_HANDLER_1); + deviceDataset0.getCreatorObjectId()); if(device1 == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "TestController::initializeAfterTaskCreation: Test device handler 1 " diff --git a/tests/src/fsfw_tests/integration/controller/TestController.h b/tests/src/fsfw_tests/integration/controller/TestController.h index 8092f945..475d8703 100644 --- a/tests/src/fsfw_tests/integration/controller/TestController.h +++ b/tests/src/fsfw_tests/integration/controller/TestController.h @@ -8,7 +8,8 @@ class TestController: public ExtendedControllerBase { public: - TestController(object_id_t objectId, size_t commandQueueDepth = 10); + TestController(object_id_t objectId, object_id_t device0, object_id_t device1, + size_t commandQueueDepth = 10); virtual~ TestController(); protected: testdevice::TestDataSet deviceDataset0; diff --git a/tests/src/fsfw_tests/integration/devices/TestDeviceHandler.cpp b/tests/src/fsfw_tests/integration/devices/TestDeviceHandler.cpp index 91019487..46138c56 100644 --- a/tests/src/fsfw_tests/integration/devices/TestDeviceHandler.cpp +++ b/tests/src/fsfw_tests/integration/devices/TestDeviceHandler.cpp @@ -644,13 +644,7 @@ ReturnValue_t TestDevice::initializeLocalDataPool(localpool::DataPool &localData localDataPoolMap.emplace(td::PoolIds::TEST_FLOAT_VEC_3_ID, new PoolEntry({0.0, 0.0, 0.0})); - sid_t sid; - if(deviceIdx == td::DeviceIndex::DEVICE_0) { - sid = td::TEST_SET_DEV_0_SID; - } - else { - sid = td::TEST_SET_DEV_1_SID; - } + sid_t sid(this->getObjectId(), td::TEST_SET_ID); /* Subscribe for periodic HK packets but do not enable reporting for now. Non-diangostic with a period of one second */ poolManager.subscribeForPeriodicPacket(sid, false, 1.0, false); diff --git a/tests/src/fsfw_tests/integration/devices/devicedefinitions/testDeviceDefinitions.h b/tests/src/fsfw_tests/integration/devices/devicedefinitions/testDeviceDefinitions.h index 10668b94..1c112e3f 100644 --- a/tests/src/fsfw_tests/integration/devices/devicedefinitions/testDeviceDefinitions.h +++ b/tests/src/fsfw_tests/integration/devices/devicedefinitions/testDeviceDefinitions.h @@ -3,7 +3,6 @@ #include #include -#include namespace testdevice { @@ -79,8 +78,6 @@ enum PoolIds: lp_id_t { }; static constexpr uint8_t TEST_SET_ID = TEST_NORMAL_MODE_CMD; -static const sid_t TEST_SET_DEV_0_SID = sid_t(objects::TEST_DEVICE_HANDLER_0, TEST_SET_ID); -static const sid_t TEST_SET_DEV_1_SID = sid_t(objects::TEST_DEVICE_HANDLER_1, TEST_SET_ID); class TestDataSet: public StaticLocalDataSet<3> { public: From 2126e6e3754a45f09bc9c557f1703821d7e68789 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 26 Oct 2021 17:24:28 +0200 Subject: [PATCH 64/89] simplified test task --- .../fsfw_tests/integration/task/TestTask.cpp | 16 ++-------------- .../src/fsfw_tests/integration/task/TestTask.h | 17 ++--------------- 2 files changed, 4 insertions(+), 29 deletions(-) diff --git a/tests/src/fsfw_tests/integration/task/TestTask.cpp b/tests/src/fsfw_tests/integration/task/TestTask.cpp index c9910e90..b33bd51c 100644 --- a/tests/src/fsfw_tests/integration/task/TestTask.cpp +++ b/tests/src/fsfw_tests/integration/task/TestTask.cpp @@ -6,9 +6,8 @@ bool TestTask::oneShotAction = true; MutexIF* TestTask::testLock = nullptr; -TestTask::TestTask(object_id_t objectId, bool periodicPrintout, bool periodicEvent): - SystemObject(objectId), testMode(testModes::A), - periodicPrinout(periodicPrintout), periodicEvent(periodicEvent) { +TestTask::TestTask(object_id_t objectId): + SystemObject(objectId), testMode(testModes::A) { if(testLock == nullptr) { testLock = MutexFactory::instance()->createMutex(); } @@ -52,17 +51,6 @@ ReturnValue_t TestTask::performOneShotAction() { ReturnValue_t TestTask::performPeriodicAction() { /* This is performed each task cycle */ ReturnValue_t result = RETURN_OK; - - if(periodicPrinout) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "TestTask::performPeriodicAction: Hello World!" << std::endl; -#else - sif::printInfo("TestTask::performPeriodicAction: Hello World!\n"); -#endif - } - if(periodicEvent) { - triggerEvent(TEST_EVENT, 0x1234, 0x4321); - } return result; } diff --git a/tests/src/fsfw_tests/integration/task/TestTask.h b/tests/src/fsfw_tests/integration/task/TestTask.h index 95f27bec..e56b5581 100644 --- a/tests/src/fsfw_tests/integration/task/TestTask.h +++ b/tests/src/fsfw_tests/integration/task/TestTask.h @@ -5,9 +5,6 @@ #include #include -#include "fsfw/events/Event.h" -#include "events/subsystemIdRanges.h" - /** * @brief Test class for general C++ testing and any other code which will not be part of the * primary mission software. @@ -19,12 +16,9 @@ class TestTask : public ExecutableObjectIF, public HasReturnvaluesIF { public: - TestTask(object_id_t objectId, bool periodicPrintout = false, bool periodicEvent = false); + TestTask(object_id_t objectId); virtual ~TestTask(); - virtual ReturnValue_t performOperation(uint8_t operationCode = 0); - - static constexpr uint8_t subsystemId = SUBSYSTEM_ID::TEST_TASK_ID; - static constexpr Event TEST_EVENT = event::makeEvent(subsystemId, 0, severity::INFO); + virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override; protected: virtual ReturnValue_t performOneShotAction(); @@ -38,15 +32,8 @@ protected: }; testModes testMode; - bool periodicPrinout = false; - bool periodicEvent = false; - bool testFlag = false; - uint8_t counter { 1 }; - uint8_t counterTrigger { 3 }; - void performPusInjectorTest(); - void examplePacketTest(); private: static bool oneShotAction; static MutexIF* testLock; From 3c414726499e5729667e6f62a67ad5dd9d5bc7e9 Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Tue, 26 Oct 2021 20:30:22 +0200 Subject: [PATCH 65/89] tweaking Jenkinsfile --- automation/Jenkinsfile | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/automation/Jenkinsfile b/automation/Jenkinsfile index a90037f8..e5b5ecda 100644 --- a/automation/Jenkinsfile +++ b/automation/Jenkinsfile @@ -1,12 +1,10 @@ pipeline { agent any + environment { + BUILDDIR = 'build-unittests' + } stages { - stage('Clean') { - steps { - sh 'rm -rf build-unittests' - } - } - stage('Build') { + stage('Configure') { agent { dockerfile { dir 'automation' @@ -15,8 +13,21 @@ pipeline { } } steps { - dir('build-unittests') { + sh 'rm -rf $BUILDDIR' + dir($BUILDDIR) { sh 'cmake -DFSFW_OSAL=host -DFSFW_BUILD_UNITTESTS=ON ..' + } + } + } + stage('Build') { + agent { + dockerfile { + dir 'automation' + reuseNode true + } + } + steps { + dir($BUILDDIR) { sh 'cmake --build . -j' } } @@ -29,7 +40,7 @@ pipeline { } } steps { - dir('build-unittests') { + dir($BUILDDIR) { sh 'cmake --build . -- fsfw-tests_coverage -j' } } From 1923b339e92772f3f43cbc7942d3c75baca35e02 Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Tue, 26 Oct 2021 20:47:53 +0200 Subject: [PATCH 66/89] I can not jenkins --- automation/Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/automation/Jenkinsfile b/automation/Jenkinsfile index e5b5ecda..9dc716a6 100644 --- a/automation/Jenkinsfile +++ b/automation/Jenkinsfile @@ -14,7 +14,7 @@ pipeline { } steps { sh 'rm -rf $BUILDDIR' - dir($BUILDDIR) { + dir(env.BUILDDIR) { sh 'cmake -DFSFW_OSAL=host -DFSFW_BUILD_UNITTESTS=ON ..' } } @@ -27,7 +27,7 @@ pipeline { } } steps { - dir($BUILDDIR) { + dir(BUILDDIR) { sh 'cmake --build . -j' } } @@ -40,7 +40,7 @@ pipeline { } } steps { - dir($BUILDDIR) { + dir(BUILDDIR) { sh 'cmake --build . -- fsfw-tests_coverage -j' } } From b02f737418b59c1724b9ee8b64defff1f5d19623 Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Tue, 26 Oct 2021 20:53:08 +0200 Subject: [PATCH 67/89] jenkins cosmetics --- automation/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automation/Jenkinsfile b/automation/Jenkinsfile index 9dc716a6..6a5d94b5 100644 --- a/automation/Jenkinsfile +++ b/automation/Jenkinsfile @@ -14,7 +14,7 @@ pipeline { } steps { sh 'rm -rf $BUILDDIR' - dir(env.BUILDDIR) { + dir(BUILDDIR) { sh 'cmake -DFSFW_OSAL=host -DFSFW_BUILD_UNITTESTS=ON ..' } } From da42edcc0cc49a81d1dca5a897aa2ab73accd600 Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Tue, 26 Oct 2021 20:58:34 +0200 Subject: [PATCH 68/89] Jenkinsfile: added stage to be more verbose --- automation/Jenkinsfile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/automation/Jenkinsfile b/automation/Jenkinsfile index 6a5d94b5..0cb973bd 100644 --- a/automation/Jenkinsfile +++ b/automation/Jenkinsfile @@ -4,7 +4,7 @@ pipeline { BUILDDIR = 'build-unittests' } stages { - stage('Configure') { + stage('Create Docker') { agent { dockerfile { dir 'automation' @@ -14,6 +14,16 @@ pipeline { } steps { sh 'rm -rf $BUILDDIR' + } + } + stage('Configure') { + agent { + dockerfile { + dir 'automation' + reuseNode true + } + } + steps { dir(BUILDDIR) { sh 'cmake -DFSFW_OSAL=host -DFSFW_BUILD_UNITTESTS=ON ..' } From cc7250fcf5fb5e9ca890b3688d47d22a8956b14e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Oct 2021 17:08:59 +0200 Subject: [PATCH 69/89] second cmake fix --- src/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5a8f139b..e4670807 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,5 +16,3 @@ target_include_directories(${LIB_FSFW_NAME} PRIVATE target_include_directories(${LIB_FSFW_NAME} INTERFACE ${CMAKE_CURRENT_BINARY_DIR} ) - -configure_file(fsfw/FSFW.h.in fsfw/FSFW.h) From 42458725e86352e1fc38b806235ea5e8eb2b318c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Oct 2021 17:10:37 +0200 Subject: [PATCH 70/89] more important fix --- CMakeLists.txt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 923d5cc5..e78e8929 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,14 +93,6 @@ target_include_directories(${LIB_FSFW_NAME} INTERFACE ${CMAKE_CURRENT_BINARY_DIR} ) -if(FSFW_BUILD_UNITTESTS) - configure_file(src/fsfw/FSFW.h.in fsfw/FSFW.h) - configure_file(src/fsfw/FSFWVersion.h.in fsfw/FSFWVersion.h) -else() - configure_file(src/fsfw/FSFW.h.in FSFW.h) - configure_file(src/fsfw/FSFWVersion.h.in FSFWVersion.h) -endif() - if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED True) @@ -155,6 +147,14 @@ else() set(OS_FSFW "host") endif() +if(FSFW_BUILD_UNITTESTS) + configure_file(src/fsfw/FSFW.h.in fsfw/FSFW.h) + configure_file(src/fsfw/FSFWVersion.h.in fsfw/FSFWVersion.h) +else() + configure_file(src/fsfw/FSFW.h.in FSFW.h) + configure_file(src/fsfw/FSFWVersion.h.in FSFWVersion.h) +endif() + message(STATUS "Compiling FSFW for the ${FSFW_OS_NAME} operating system.") add_subdirectory(src) From 3448a8c01b4e1cc3171e93f68b600dbfa9501962 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Oct 2021 17:23:14 +0200 Subject: [PATCH 71/89] SPI ComIF updates 1. Make setting a chip select pin optional 2. Make ComIF member functions public --- hal/src/fsfw_hal/stm32h7/spi/SpiComIF.cpp | 38 +++++++++++++++-------- hal/src/fsfw_hal/stm32h7/spi/SpiComIF.h | 3 +- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/hal/src/fsfw_hal/stm32h7/spi/SpiComIF.cpp b/hal/src/fsfw_hal/stm32h7/spi/SpiComIF.cpp index 1813aac0..4c4f7744 100644 --- a/hal/src/fsfw_hal/stm32h7/spi/SpiComIF.cpp +++ b/hal/src/fsfw_hal/stm32h7/spi/SpiComIF.cpp @@ -138,12 +138,14 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) { spi::setSpiDmaMspFunctions(typedCfg); } - gpio::initializeGpioClock(gpioPort); - GPIO_InitTypeDef chipSelect = {}; - chipSelect.Pin = gpioPin; - chipSelect.Mode = GPIO_MODE_OUTPUT_PP; - HAL_GPIO_Init(gpioPort, &chipSelect); - HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_SET); + if(gpioPort != nullptr) { + gpio::initializeGpioClock(gpioPort); + GPIO_InitTypeDef chipSelect = {}; + chipSelect.Pin = gpioPin; + chipSelect.Mode = GPIO_MODE_OUTPUT_PP; + HAL_GPIO_Init(gpioPort, &chipSelect); + HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_SET); + } if(HAL_SPI_Init(&spiHandle) != HAL_OK) { sif::printWarning("SpiComIF::initialize: Error initializing SPI\n"); @@ -259,10 +261,15 @@ ReturnValue_t SpiComIF::handlePollingSendOperation(uint8_t* recvPtr, SPI_HandleT return returnval; } spiCookie.setTransferState(spi::TransferStates::WAIT); - HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_RESET); + if(gpioPort != nullptr) { + HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_RESET); + } + auto result = HAL_SPI_TransmitReceive(&spiHandle, const_cast(sendData), recvPtr, sendLen, defaultPollingTimeout); - HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_SET); + if(gpioPort != nullptr) { + HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_SET); + } spiSemaphore->release(); switch(result) { case(HAL_OK): { @@ -392,8 +399,10 @@ ReturnValue_t SpiComIF::genericIrqSendSetup(uint8_t *recvPtr, SPI_HandleTypeDef& // The SPI handle is passed to the default SPI callback as a void argument. This callback // is different from the user callbacks specified above! spi::assignSpiUserArgs(spiCookie.getSpiIdx(), reinterpret_cast(&spiHandle)); - HAL_GPIO_WritePin(spiCookie.getChipSelectGpioPort(), spiCookie.getChipSelectGpioPin(), - GPIO_PIN_RESET); + if(spiCookie.getChipSelectGpioPort() != nullptr) { + HAL_GPIO_WritePin(spiCookie.getChipSelectGpioPort(), spiCookie.getChipSelectGpioPin(), + GPIO_PIN_RESET); + } return HasReturnvaluesIF::RETURN_OK; } @@ -426,9 +435,12 @@ void SpiComIF::genericIrqHandler(void *irqArgsVoid, spi::TransferStates targetSt spiCookie->setTransferState(targetState); - // Pull CS pin high again - HAL_GPIO_WritePin(spiCookie->getChipSelectGpioPort(), spiCookie->getChipSelectGpioPin(), - GPIO_PIN_SET); + if(spiCookie->getChipSelectGpioPort() != nullptr) { + // Pull CS pin high again + HAL_GPIO_WritePin(spiCookie->getChipSelectGpioPort(), spiCookie->getChipSelectGpioPin(), + GPIO_PIN_SET); + } + #if defined FSFW_OSAL_FREERTOS // Release the task semaphore diff --git a/hal/src/fsfw_hal/stm32h7/spi/SpiComIF.h b/hal/src/fsfw_hal/stm32h7/spi/SpiComIF.h index 9548e102..cb6c4cf8 100644 --- a/hal/src/fsfw_hal/stm32h7/spi/SpiComIF.h +++ b/hal/src/fsfw_hal/stm32h7/spi/SpiComIF.h @@ -60,7 +60,6 @@ public: void addDmaHandles(DMA_HandleTypeDef* txHandle, DMA_HandleTypeDef* rxHandle); ReturnValue_t initialize() override; -protected: // DeviceCommunicationIF overrides virtual ReturnValue_t initializeInterface(CookieIF * cookie) override; @@ -72,7 +71,7 @@ protected: virtual ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) override; -private: +protected: struct SpiInstance { SpiInstance(size_t maxRecvSize): replyBuffer(std::vector(maxRecvSize)) {} From d675621b73e86449ffe88298bcc09d5582b1c5c9 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Oct 2021 17:31:04 +0200 Subject: [PATCH 72/89] grouping CS gpio definition --- hal/src/fsfw_hal/stm32h7/spi/SpiCookie.cpp | 10 +++++----- hal/src/fsfw_hal/stm32h7/spi/SpiCookie.h | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/hal/src/fsfw_hal/stm32h7/spi/SpiCookie.cpp b/hal/src/fsfw_hal/stm32h7/spi/SpiCookie.cpp index 88f1e1f1..e9cbac8e 100644 --- a/hal/src/fsfw_hal/stm32h7/spi/SpiCookie.cpp +++ b/hal/src/fsfw_hal/stm32h7/spi/SpiCookie.cpp @@ -3,10 +3,10 @@ SpiCookie::SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferModes transferMode, spi::MspCfgBase* mspCfg, uint32_t spiSpeed, spi::SpiModes spiMode, - uint16_t chipSelectGpioPin, GPIO_TypeDef* chipSelectGpioPort, size_t maxRecvSize): + size_t maxRecvSize, GpioPair csGpio): deviceAddress(deviceAddress), spiIdx(spiIdx), spiSpeed(spiSpeed), spiMode(spiMode), - transferMode(transferMode), chipSelectGpioPin(chipSelectGpioPin), - chipSelectGpioPort(chipSelectGpioPort), mspCfg(mspCfg), maxRecvSize(maxRecvSize) { + transferMode(transferMode), csGpio(csGpio), + mspCfg(mspCfg), maxRecvSize(maxRecvSize) { spiHandle.Init.DataSize = SPI_DATASIZE_8BIT; spiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB; spiHandle.Init.TIMode = SPI_TIMODE_DISABLE; @@ -24,11 +24,11 @@ SpiCookie::SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferM } uint16_t SpiCookie::getChipSelectGpioPin() const { - return chipSelectGpioPin; + return csGpio.second; } GPIO_TypeDef* SpiCookie::getChipSelectGpioPort() { - return chipSelectGpioPort; + return csGpio.first; } address_t SpiCookie::getDeviceAddress() const { diff --git a/hal/src/fsfw_hal/stm32h7/spi/SpiCookie.h b/hal/src/fsfw_hal/stm32h7/spi/SpiCookie.h index 45226b4a..f5698999 100644 --- a/hal/src/fsfw_hal/stm32h7/spi/SpiCookie.h +++ b/hal/src/fsfw_hal/stm32h7/spi/SpiCookie.h @@ -8,6 +8,8 @@ #include "stm32h743xx.h" +#include + /** * @brief SPI cookie implementation for the STM32H7 device family * @details @@ -18,6 +20,12 @@ class SpiCookie: public CookieIF { friend class SpiComIF; public: + /** + * Typedef for STM32 GPIO pair where the first entry is the port used (e.g. GPIOA) + * and the second entry is the pin number + */ + using GpioPair = std::pair; + /** * Allows construction of a SPI cookie for a connected SPI device * @param deviceAddress @@ -32,10 +40,11 @@ public: * definitions supplied in the MCU header file! (e.g. GPIO_PIN_X) * @param chipSelectGpioPort GPIO port (e.g. GPIOA) * @param maxRecvSize Maximum expected receive size. Chose as small as possible. + * @param csGpio Optional CS GPIO definition. */ SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferModes transferMode, spi::MspCfgBase* mspCfg, uint32_t spiSpeed, spi::SpiModes spiMode, - uint16_t chipSelectGpioPin, GPIO_TypeDef* chipSelectGpioPort, size_t maxRecvSize); + size_t maxRecvSize, GpioPair csGpio = GpioPair(nullptr, 0)); uint16_t getChipSelectGpioPin() const; GPIO_TypeDef* getChipSelectGpioPort(); @@ -55,8 +64,8 @@ private: spi::SpiModes spiMode; spi::TransferModes transferMode; volatile spi::TransferStates transferState = spi::TransferStates::IDLE; - uint16_t chipSelectGpioPin; - GPIO_TypeDef* chipSelectGpioPort; + GpioPair csGpio; + // The MSP configuration is cached here. Be careful when using this, it is automatically // deleted by the SPI communication interface if it is not required anymore! spi::MspCfgBase* mspCfg = nullptr; From cb7399b9998e9ec2d6439c5eb75c8312641770a4 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Oct 2021 18:05:18 +0200 Subject: [PATCH 73/89] msp init improvements --- hal/src/fsfw_hal/stm32h7/definitions.h | 25 ++++++++++ hal/src/fsfw_hal/stm32h7/spi/SpiCookie.cpp | 6 +-- hal/src/fsfw_hal/stm32h7/spi/SpiCookie.h | 10 ++-- hal/src/fsfw_hal/stm32h7/spi/mspInit.cpp | 28 +++++------ hal/src/fsfw_hal/stm32h7/spi/mspInit.h | 50 +++++++++++++------ .../fsfw_hal/stm32h7/spi/stm32h743ziSpi.cpp | 22 ++++---- 6 files changed, 90 insertions(+), 51 deletions(-) create mode 100644 hal/src/fsfw_hal/stm32h7/definitions.h diff --git a/hal/src/fsfw_hal/stm32h7/definitions.h b/hal/src/fsfw_hal/stm32h7/definitions.h new file mode 100644 index 00000000..af63a541 --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/definitions.h @@ -0,0 +1,25 @@ +#ifndef FSFW_HAL_STM32H7_DEFINITIONS_H_ +#define FSFW_HAL_STM32H7_DEFINITIONS_H_ + +#include +#include "stm32h7xx.h" + +namespace stm32h7 { + +/** + * Typedef for STM32 GPIO pair where the first entry is the port used (e.g. GPIOA) + * and the second entry is the pin number + */ +struct GpioCfg { + GpioCfg(): port(nullptr), pin(0), altFnc(0) {}; + + GpioCfg(GPIO_TypeDef* port, uint16_t pin, uint8_t altFnc = 0): + port(port), pin(pin), altFnc(altFnc) {}; + GPIO_TypeDef* port; + uint16_t pin; + uint8_t altFnc; +}; + +} + +#endif /* #ifndef FSFW_HAL_STM32H7_DEFINITIONS_H_ */ diff --git a/hal/src/fsfw_hal/stm32h7/spi/SpiCookie.cpp b/hal/src/fsfw_hal/stm32h7/spi/SpiCookie.cpp index e9cbac8e..200d4651 100644 --- a/hal/src/fsfw_hal/stm32h7/spi/SpiCookie.cpp +++ b/hal/src/fsfw_hal/stm32h7/spi/SpiCookie.cpp @@ -3,7 +3,7 @@ SpiCookie::SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferModes transferMode, spi::MspCfgBase* mspCfg, uint32_t spiSpeed, spi::SpiModes spiMode, - size_t maxRecvSize, GpioPair csGpio): + size_t maxRecvSize, stm32h7::GpioCfg csGpio): deviceAddress(deviceAddress), spiIdx(spiIdx), spiSpeed(spiSpeed), spiMode(spiMode), transferMode(transferMode), csGpio(csGpio), mspCfg(mspCfg), maxRecvSize(maxRecvSize) { @@ -24,11 +24,11 @@ SpiCookie::SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferM } uint16_t SpiCookie::getChipSelectGpioPin() const { - return csGpio.second; + return csGpio.pin; } GPIO_TypeDef* SpiCookie::getChipSelectGpioPort() { - return csGpio.first; + return csGpio.port; } address_t SpiCookie::getDeviceAddress() const { diff --git a/hal/src/fsfw_hal/stm32h7/spi/SpiCookie.h b/hal/src/fsfw_hal/stm32h7/spi/SpiCookie.h index f5698999..56c6e800 100644 --- a/hal/src/fsfw_hal/stm32h7/spi/SpiCookie.h +++ b/hal/src/fsfw_hal/stm32h7/spi/SpiCookie.h @@ -3,6 +3,7 @@ #include "spiDefinitions.h" #include "mspInit.h" +#include "../definitions.h" #include "fsfw/devicehandlers/CookieIF.h" @@ -20,11 +21,6 @@ class SpiCookie: public CookieIF { friend class SpiComIF; public: - /** - * Typedef for STM32 GPIO pair where the first entry is the port used (e.g. GPIOA) - * and the second entry is the pin number - */ - using GpioPair = std::pair; /** * Allows construction of a SPI cookie for a connected SPI device @@ -44,7 +40,7 @@ public: */ SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferModes transferMode, spi::MspCfgBase* mspCfg, uint32_t spiSpeed, spi::SpiModes spiMode, - size_t maxRecvSize, GpioPair csGpio = GpioPair(nullptr, 0)); + size_t maxRecvSize, stm32h7::GpioCfg csGpio = stm32h7::GpioCfg(nullptr, 0, 0)); uint16_t getChipSelectGpioPin() const; GPIO_TypeDef* getChipSelectGpioPort(); @@ -64,7 +60,7 @@ private: spi::SpiModes spiMode; spi::TransferModes transferMode; volatile spi::TransferStates transferState = spi::TransferStates::IDLE; - GpioPair csGpio; + stm32h7::GpioCfg csGpio; // The MSP configuration is cached here. Be careful when using this, it is automatically // deleted by the SPI communication interface if it is not required anymore! diff --git a/hal/src/fsfw_hal/stm32h7/spi/mspInit.cpp b/hal/src/fsfw_hal/stm32h7/spi/mspInit.cpp index 4df61f9b..b7ff2f70 100644 --- a/hal/src/fsfw_hal/stm32h7/spi/mspInit.cpp +++ b/hal/src/fsfw_hal/stm32h7/spi/mspInit.cpp @@ -118,40 +118,40 @@ void spi::halMspInitPolling(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) { GPIO_InitTypeDef GPIO_InitStruct = {}; /*##-1- Enable peripherals and GPIO Clocks #################################*/ /* Enable GPIO TX/RX clock */ - cfg->setupMacroWrapper(); + cfg->setupCb(); /*##-2- Configure peripheral GPIO ##########################################*/ /* SPI SCK GPIO pin configuration */ - GPIO_InitStruct.Pin = cfg->sckPin; + GPIO_InitStruct.Pin = cfg->sck.pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_PULLDOWN; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; - GPIO_InitStruct.Alternate = cfg->sckAlternateFunction; - HAL_GPIO_Init(cfg->sckPort, &GPIO_InitStruct); + GPIO_InitStruct.Alternate = cfg->sck.altFnc; + HAL_GPIO_Init(cfg->sck.port, &GPIO_InitStruct); /* SPI MISO GPIO pin configuration */ - GPIO_InitStruct.Pin = cfg->misoPin; - GPIO_InitStruct.Alternate = cfg->misoAlternateFunction; - HAL_GPIO_Init(cfg->misoPort, &GPIO_InitStruct); + GPIO_InitStruct.Pin = cfg->miso.pin; + GPIO_InitStruct.Alternate = cfg->miso.altFnc; + HAL_GPIO_Init(cfg->miso.port, &GPIO_InitStruct); /* SPI MOSI GPIO pin configuration */ - GPIO_InitStruct.Pin = cfg->mosiPin; - GPIO_InitStruct.Alternate = cfg->mosiAlternateFunction; - HAL_GPIO_Init(cfg->mosiPort, &GPIO_InitStruct); + GPIO_InitStruct.Pin = cfg->mosi.pin; + GPIO_InitStruct.Alternate = cfg->mosi.altFnc; + HAL_GPIO_Init(cfg->mosi.port, &GPIO_InitStruct); } void spi::halMspDeinitPolling(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) { auto cfg = reinterpret_cast(cfgBase); // Reset peripherals - cfg->cleanUpMacroWrapper(); + cfg->cleanupCb(); // Disable peripherals and GPIO Clocks /* Configure SPI SCK as alternate function */ - HAL_GPIO_DeInit(cfg->sckPort, cfg->sckPin); + HAL_GPIO_DeInit(cfg->sck.port, cfg->sck.pin); /* Configure SPI MISO as alternate function */ - HAL_GPIO_DeInit(cfg->misoPort, cfg->misoPin); + HAL_GPIO_DeInit(cfg->miso.port, cfg->miso.pin); /* Configure SPI MOSI as alternate function */ - HAL_GPIO_DeInit(cfg->mosiPort, cfg->mosiPin); + HAL_GPIO_DeInit(cfg->mosi.port, cfg->mosi.pin); } void spi::halMspInitInterrupt(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) { diff --git a/hal/src/fsfw_hal/stm32h7/spi/mspInit.h b/hal/src/fsfw_hal/stm32h7/spi/mspInit.h index e6de2f8e..0fb553f7 100644 --- a/hal/src/fsfw_hal/stm32h7/spi/mspInit.h +++ b/hal/src/fsfw_hal/stm32h7/spi/mspInit.h @@ -2,6 +2,7 @@ #define FSFW_HAL_STM32H7_SPI_MSPINIT_H_ #include "spiDefinitions.h" +#include "../definitions.h" #include "../dma.h" #include "stm32h7xx_hal_spi.h" @@ -12,6 +13,8 @@ extern "C" { #endif +using mspCb = void (*) (void); + /** * @brief This file provides MSP implementation for DMA, IRQ and Polling mode for the * SPI peripheral. This configuration is required for the SPI communication to work. @@ -19,27 +22,37 @@ extern "C" { namespace spi { struct MspCfgBase { + MspCfgBase(); + MspCfgBase(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso, + mspCb cleanupCb = nullptr, mspCb setupCb = nullptr): + sck(sck), mosi(mosi), miso(miso), cleanupCb(cleanupCb), + setupCb(setupCb) {} + virtual ~MspCfgBase() = default; - void (* cleanUpMacroWrapper) (void) = nullptr; - void (* setupMacroWrapper) (void) = nullptr; + stm32h7::GpioCfg sck; + stm32h7::GpioCfg mosi; + stm32h7::GpioCfg miso; - GPIO_TypeDef* sckPort = nullptr; - uint32_t sckPin = 0; - uint8_t sckAlternateFunction = 0; - GPIO_TypeDef* mosiPort = nullptr; - uint32_t mosiPin = 0; - uint8_t mosiAlternateFunction = 0; - GPIO_TypeDef* misoPort = nullptr; - uint32_t misoPin = 0; - uint8_t misoAlternateFunction = 0; + mspCb cleanupCb = nullptr; + mspCb setupCb = nullptr; }; -struct MspPollingConfigStruct: public MspCfgBase {}; +struct MspPollingConfigStruct: public MspCfgBase { + MspPollingConfigStruct(): MspCfgBase() {}; + MspPollingConfigStruct(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso, + mspCb cleanupCb = nullptr, mspCb setupCb = nullptr): + MspCfgBase(sck, mosi, miso, cleanupCb, setupCb) {} +}; /* A valid instance of this struct must be passed to the MSP initialization function as a void* argument */ struct MspIrqConfigStruct: public MspPollingConfigStruct { + MspIrqConfigStruct(): MspPollingConfigStruct() {}; + MspIrqConfigStruct(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso, + mspCb cleanupCb = nullptr, mspCb setupCb = nullptr): + MspPollingConfigStruct(sck, mosi, miso, cleanupCb, setupCb) {} + SpiBus spiBus = SpiBus::SPI_1; user_handler_t spiIrqHandler = nullptr; user_args_t spiUserArgs = nullptr; @@ -53,11 +66,16 @@ struct MspIrqConfigStruct: public MspPollingConfigStruct { /* A valid instance of this struct must be passed to the MSP initialization function as a void* argument */ struct MspDmaConfigStruct: public MspIrqConfigStruct { + MspDmaConfigStruct(): MspIrqConfigStruct() {}; + MspDmaConfigStruct(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso, + mspCb cleanupCb = nullptr, mspCb setupCb = nullptr): + MspIrqConfigStruct(sck, mosi, miso, cleanupCb, setupCb) {} void (* dmaClkEnableWrapper) (void) = nullptr; - dma::DMAIndexes txDmaIndex; - dma::DMAIndexes rxDmaIndex; - dma::DMAStreams txDmaStream; - dma::DMAStreams rxDmaStream; + + dma::DMAIndexes txDmaIndex = dma::DMAIndexes::DMA_1; + dma::DMAIndexes rxDmaIndex = dma::DMAIndexes::DMA_1; + dma::DMAStreams txDmaStream = dma::DMAStreams::STREAM_0; + dma::DMAStreams rxDmaStream = dma::DMAStreams::STREAM_0; IRQn_Type txDmaIrqNumber = DMA1_Stream0_IRQn; IRQn_Type rxDmaIrqNumber = DMA1_Stream1_IRQn; // Priorities for NVIC diff --git a/hal/src/fsfw_hal/stm32h7/spi/stm32h743ziSpi.cpp b/hal/src/fsfw_hal/stm32h7/spi/stm32h743ziSpi.cpp index 43194704..8247d002 100644 --- a/hal/src/fsfw_hal/stm32h7/spi/stm32h743ziSpi.cpp +++ b/hal/src/fsfw_hal/stm32h7/spi/stm32h743ziSpi.cpp @@ -23,17 +23,17 @@ void spiDmaClockEnableWrapper() { } void spi::h743zi::standardPollingCfg(MspPollingConfigStruct& cfg) { - cfg.setupMacroWrapper = &spiSetupWrapper; - cfg.cleanUpMacroWrapper = &spiCleanUpWrapper; - cfg.sckPort = GPIOA; - cfg.sckPin = GPIO_PIN_5; - cfg.misoPort = GPIOA; - cfg.misoPin = GPIO_PIN_6; - cfg.mosiPort = GPIOA; - cfg.mosiPin = GPIO_PIN_7; - cfg.sckAlternateFunction = GPIO_AF5_SPI1; - cfg.mosiAlternateFunction = GPIO_AF5_SPI1; - cfg.misoAlternateFunction = GPIO_AF5_SPI1; + cfg.setupCb = &spiSetupWrapper; + cfg.cleanupCb = &spiCleanUpWrapper; + cfg.sck.port = GPIOA; + cfg.sck.pin = GPIO_PIN_5; + cfg.miso.port = GPIOA; + cfg.miso.pin = GPIO_PIN_6; + cfg.mosi.port = GPIOA; + cfg.mosi.pin = GPIO_PIN_7; + cfg.sck.altFnc = GPIO_AF5_SPI1; + cfg.mosi.altFnc = GPIO_AF5_SPI1; + cfg.miso.altFnc = GPIO_AF5_SPI1; } void spi::h743zi::standardInterruptCfg(MspIrqConfigStruct& cfg, IrqPriorities spiIrqPrio, From 7c855592d05ecfc017e9806f87e40a11f8c75a8a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Oct 2021 18:11:56 +0200 Subject: [PATCH 74/89] more cleaning up --- hal/src/fsfw_hal/stm32h7/devicetest/GyroL3GD20H.cpp | 8 ++++---- hal/src/fsfw_hal/stm32h7/spi/CMakeLists.txt | 2 +- .../spi/{stm32h743ziSpi.cpp => stm32h743zi.cpp} | 10 +++++----- .../stm32h7/spi/{stm32h743ziSpi.h => stm32h743zi.h} | 11 +++++------ 4 files changed, 15 insertions(+), 16 deletions(-) rename hal/src/fsfw_hal/stm32h7/spi/{stm32h743ziSpi.cpp => stm32h743zi.cpp} (88%) rename hal/src/fsfw_hal/stm32h7/spi/{stm32h743ziSpi.h => stm32h743zi.h} (64%) diff --git a/hal/src/fsfw_hal/stm32h7/devicetest/GyroL3GD20H.cpp b/hal/src/fsfw_hal/stm32h7/devicetest/GyroL3GD20H.cpp index 051be344..d1fdd1e5 100644 --- a/hal/src/fsfw_hal/stm32h7/devicetest/GyroL3GD20H.cpp +++ b/hal/src/fsfw_hal/stm32h7/devicetest/GyroL3GD20H.cpp @@ -4,7 +4,7 @@ #include "fsfw_hal/stm32h7/spi/spiDefinitions.h" #include "fsfw_hal/stm32h7/spi/spiCore.h" #include "fsfw_hal/stm32h7/spi/spiInterrupts.h" -#include "fsfw_hal/stm32h7/spi/stm32h743ziSpi.h" +#include "fsfw_hal/stm32h7/spi/stm32h743zi.h" #include "fsfw/tasks/TaskFactory.h" #include "fsfw/serviceinterface/ServiceInterface.h" @@ -33,20 +33,20 @@ GyroL3GD20H::GyroL3GD20H(SPI_HandleTypeDef *spiHandle, spi::TransferModes transf mspCfg = new spi::MspDmaConfigStruct(); auto typedCfg = dynamic_cast(mspCfg); spi::setDmaHandles(txDmaHandle, rxDmaHandle); - spi::h743zi::standardDmaCfg(*typedCfg, IrqPriorities::HIGHEST_FREERTOS, + stm32h7::h743zi::standardDmaCfg(*typedCfg, IrqPriorities::HIGHEST_FREERTOS, IrqPriorities::HIGHEST_FREERTOS, IrqPriorities::HIGHEST_FREERTOS); spi::setSpiDmaMspFunctions(typedCfg); } else if(transferMode == spi::TransferModes::INTERRUPT) { mspCfg = new spi::MspIrqConfigStruct(); auto typedCfg = dynamic_cast(mspCfg); - spi::h743zi::standardInterruptCfg(*typedCfg, IrqPriorities::HIGHEST_FREERTOS); + stm32h7::h743zi::standardInterruptCfg(*typedCfg, IrqPriorities::HIGHEST_FREERTOS); spi::setSpiIrqMspFunctions(typedCfg); } else if(transferMode == spi::TransferModes::POLLING) { mspCfg = new spi::MspPollingConfigStruct(); auto typedCfg = dynamic_cast(mspCfg); - spi::h743zi::standardPollingCfg(*typedCfg); + stm32h7::h743zi::standardPollingCfg(*typedCfg); spi::setSpiPollingMspFunctions(typedCfg); } diff --git a/hal/src/fsfw_hal/stm32h7/spi/CMakeLists.txt b/hal/src/fsfw_hal/stm32h7/spi/CMakeLists.txt index e28c35aa..aa5541bc 100644 --- a/hal/src/fsfw_hal/stm32h7/spi/CMakeLists.txt +++ b/hal/src/fsfw_hal/stm32h7/spi/CMakeLists.txt @@ -5,5 +5,5 @@ target_sources(${LIB_FSFW_NAME} PRIVATE mspInit.cpp SpiCookie.cpp SpiComIF.cpp - stm32h743ziSpi.cpp + stm32h743zi.cpp ) diff --git a/hal/src/fsfw_hal/stm32h7/spi/stm32h743ziSpi.cpp b/hal/src/fsfw_hal/stm32h7/spi/stm32h743zi.cpp similarity index 88% rename from hal/src/fsfw_hal/stm32h7/spi/stm32h743ziSpi.cpp rename to hal/src/fsfw_hal/stm32h7/spi/stm32h743zi.cpp index 8247d002..1bafccd5 100644 --- a/hal/src/fsfw_hal/stm32h7/spi/stm32h743ziSpi.cpp +++ b/hal/src/fsfw_hal/stm32h7/spi/stm32h743zi.cpp @@ -1,4 +1,4 @@ -#include "fsfw_hal/stm32h7/spi/stm32h743ziSpi.h" +#include "fsfw_hal/stm32h7/spi/stm32h743zi.h" #include "fsfw_hal/stm32h7/spi/spiCore.h" #include "fsfw_hal/stm32h7/spi/spiInterrupts.h" @@ -22,7 +22,7 @@ void spiDmaClockEnableWrapper() { __HAL_RCC_DMA2_CLK_ENABLE(); } -void spi::h743zi::standardPollingCfg(MspPollingConfigStruct& cfg) { +void stm32h7::h743zi::standardPollingCfg(spi::MspPollingConfigStruct& cfg) { cfg.setupCb = &spiSetupWrapper; cfg.cleanupCb = &spiCleanUpWrapper; cfg.sck.port = GPIOA; @@ -36,13 +36,13 @@ void spi::h743zi::standardPollingCfg(MspPollingConfigStruct& cfg) { cfg.miso.altFnc = GPIO_AF5_SPI1; } -void spi::h743zi::standardInterruptCfg(MspIrqConfigStruct& cfg, IrqPriorities spiIrqPrio, +void stm32h7::h743zi::standardInterruptCfg(spi::MspIrqConfigStruct& cfg, IrqPriorities spiIrqPrio, IrqPriorities spiSubprio) { // High, but works on FreeRTOS as well (priorities range from 0 to 15) cfg.preEmptPriority = spiIrqPrio; cfg.subpriority = spiSubprio; cfg.spiIrqNumber = SPI1_IRQn; - cfg.spiBus = SpiBus::SPI_1; + cfg.spiBus = spi::SpiBus::SPI_1; user_handler_t spiUserHandler = nullptr; user_args_t spiUserArgs = nullptr; getSpiUserHandler(spi::SpiBus::SPI_1, &spiUserHandler, &spiUserArgs); @@ -55,7 +55,7 @@ void spi::h743zi::standardInterruptCfg(MspIrqConfigStruct& cfg, IrqPriorities sp standardPollingCfg(cfg); } -void spi::h743zi::standardDmaCfg(MspDmaConfigStruct& cfg, IrqPriorities spiIrqPrio, +void stm32h7::h743zi::standardDmaCfg(spi::MspDmaConfigStruct& cfg, IrqPriorities spiIrqPrio, IrqPriorities txIrqPrio, IrqPriorities rxIrqPrio, IrqPriorities spiSubprio, IrqPriorities txSubprio, IrqPriorities rxSubprio) { cfg.dmaClkEnableWrapper = &spiDmaClockEnableWrapper; diff --git a/hal/src/fsfw_hal/stm32h7/spi/stm32h743ziSpi.h b/hal/src/fsfw_hal/stm32h7/spi/stm32h743zi.h similarity index 64% rename from hal/src/fsfw_hal/stm32h7/spi/stm32h743ziSpi.h rename to hal/src/fsfw_hal/stm32h7/spi/stm32h743zi.h index 87689add..daa95554 100644 --- a/hal/src/fsfw_hal/stm32h7/spi/stm32h743ziSpi.h +++ b/hal/src/fsfw_hal/stm32h7/spi/stm32h743zi.h @@ -3,21 +3,20 @@ #include "mspInit.h" -namespace spi { +namespace stm32h7 { namespace h743zi { -void standardPollingCfg(MspPollingConfigStruct& cfg); -void standardInterruptCfg(MspIrqConfigStruct& cfg, IrqPriorities spiIrqPrio, +void standardPollingCfg(spi::MspPollingConfigStruct& cfg); +void standardInterruptCfg(spi::MspIrqConfigStruct& cfg, IrqPriorities spiIrqPrio, IrqPriorities spiSubprio = HIGHEST); -void standardDmaCfg(MspDmaConfigStruct& cfg, IrqPriorities spiIrqPrio, +void standardDmaCfg(spi::MspDmaConfigStruct& cfg, IrqPriorities spiIrqPrio, IrqPriorities txIrqPrio, IrqPriorities rxIrqPrio, IrqPriorities spiSubprio = HIGHEST, IrqPriorities txSubPrio = HIGHEST, IrqPriorities rxSubprio = HIGHEST); + } } - - #endif /* FSFW_HAL_STM32H7_SPI_STM32H743ZISPI_H_ */ From 36aaf3d75800db7e2d9f7229fdd95068fdb17481 Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Wed, 27 Oct 2021 20:41:04 +0200 Subject: [PATCH 75/89] say hi to my new friend valgrind --- tests/src/fsfw_tests/unit/container/RingBufferTest.cpp | 4 ++-- .../fsfw_tests/unit/datapoollocal/LocalPoolManagerTest.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/src/fsfw_tests/unit/container/RingBufferTest.cpp b/tests/src/fsfw_tests/unit/container/RingBufferTest.cpp index 819401ab..0be8b2a7 100644 --- a/tests/src/fsfw_tests/unit/container/RingBufferTest.cpp +++ b/tests/src/fsfw_tests/unit/container/RingBufferTest.cpp @@ -78,7 +78,7 @@ TEST_CASE("Ring Buffer Test" , "[RingBufferTest]") { TEST_CASE("Ring Buffer Test2" , "[RingBufferTest2]") { uint8_t testData[13]= {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; uint8_t readBuffer[10] = {13, 13, 13, 13, 13, 13, 13, 13, 13, 13}; - uint8_t* newBuffer = new uint8_t[10]; + uint8_t* newBuffer = new uint8_t[15]; SimpleRingBuffer ringBuffer(newBuffer, 10, true, 5); SECTION("Simple Test") { @@ -168,7 +168,7 @@ TEST_CASE("Ring Buffer Test2" , "[RingBufferTest2]") { TEST_CASE("Ring Buffer Test3" , "[RingBufferTest3]") { uint8_t testData[13]= {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; uint8_t readBuffer[10] = {13, 13, 13, 13, 13, 13, 13, 13, 13, 13}; - uint8_t* newBuffer = new uint8_t[10]; + uint8_t* newBuffer = new uint8_t[25]; SimpleRingBuffer ringBuffer(newBuffer, 10, true, 15); SECTION("Simple Test") { diff --git a/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolManagerTest.cpp b/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolManagerTest.cpp index 7b2f9412..b1160254 100644 --- a/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolManagerTest.cpp +++ b/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolManagerTest.cpp @@ -143,7 +143,7 @@ TEST_CASE("LocalPoolManagerTest" , "[LocManTest]") { CHECK(cdsShort.msDay_h == Catch::Approx(timeCdsNow.msDay_h).margin(1)); CHECK(cdsShort.msDay_hh == Catch::Approx(timeCdsNow.msDay_hh).margin(1)); CHECK(cdsShort.msDay_l == Catch::Approx(timeCdsNow.msDay_l).margin(1)); - CHECK(cdsShort.msDay_ll == Catch::Approx(timeCdsNow.msDay_ll).margin(1)); + CHECK(cdsShort.msDay_ll == Catch::Approx(timeCdsNow.msDay_ll).margin(5)); } SECTION("VariableSnapshotTest") { @@ -205,7 +205,7 @@ TEST_CASE("LocalPoolManagerTest" , "[LocManTest]") { CHECK(cdsShort.msDay_h == Catch::Approx(timeCdsNow.msDay_h).margin(1)); CHECK(cdsShort.msDay_hh == Catch::Approx(timeCdsNow.msDay_hh).margin(1)); CHECK(cdsShort.msDay_l == Catch::Approx(timeCdsNow.msDay_l).margin(1)); - CHECK(cdsShort.msDay_ll == Catch::Approx(timeCdsNow.msDay_ll).margin(1)); + CHECK(cdsShort.msDay_ll == Catch::Approx(timeCdsNow.msDay_ll).margin(5)); } SECTION("VariableNotificationTest") { From a53992fdc9127c435f7bdf1a68cdf1329aab31ff Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Wed, 27 Oct 2021 21:32:40 +0200 Subject: [PATCH 76/89] introducing valgrind --- automation/Dockerfile | 2 +- automation/Jenkinsfile | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/automation/Dockerfile b/automation/Dockerfile index 0526d8f0..93a4fe7d 100644 --- a/automation/Dockerfile +++ b/automation/Dockerfile @@ -5,4 +5,4 @@ RUN apt-get --yes upgrade #tzdata is a dependency, won't install otherwise ARG DEBIAN_FRONTEND=noninteractive -RUN apt-get --yes install gcc g++ cmake lcov git nano +RUN apt-get --yes install gcc g++ cmake make lcov git valgrind nano diff --git a/automation/Jenkinsfile b/automation/Jenkinsfile index 0cb973bd..d4a8e2ab 100644 --- a/automation/Jenkinsfile +++ b/automation/Jenkinsfile @@ -55,5 +55,18 @@ pipeline { } } } + stage('Valgrind') { + agent { + dockerfile { + dir 'automation' + reuseNode true + } + } + steps { + dir(BUILDDIR) { + sh 'valgrind --leak-check=full --error-exitcode=1 ./fsfw-tests' + } + } + } } } From 6d5eb5b387b05c8c9615de0544bd0fc355137a52 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 10 Nov 2021 18:48:02 +0100 Subject: [PATCH 77/89] Op Divider and bitutility updates - Added unittests for `PeriodicOperationDivider` and the `bitutil` helpers - Some API changes: Removed redundant bit part, because these functions are already in a namespace - Some bugfixes for `PeriodicOperationDivider` --- .../devicehandlers/MgmRM3100Handler.cpp | 2 +- .../datapoollocal/LocalPoolDataSetBase.cpp | 6 +- .../PeriodicOperationDivider.cpp | 39 +++++----- .../PeriodicOperationDivider.h | 77 +++++++++---------- src/fsfw/globalfunctions/bitutility.cpp | 11 +-- src/fsfw/globalfunctions/bitutility.h | 37 +++++++-- .../unit/datapoollocal/DataSetTest.cpp | 24 ++++-- .../unit/globalfunctions/CMakeLists.txt | 2 + .../unit/globalfunctions/testBitutil.cpp | 64 +++++++++++++++ .../unit/globalfunctions/testOpDivider.cpp | 64 +++++++++++++++ 10 files changed, 242 insertions(+), 84 deletions(-) create mode 100644 tests/src/fsfw_tests/unit/globalfunctions/testBitutil.cpp create mode 100644 tests/src/fsfw_tests/unit/globalfunctions/testOpDivider.cpp diff --git a/hal/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp b/hal/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp index 124eebbc..db4ea607 100644 --- a/hal/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp +++ b/hal/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp @@ -186,7 +186,7 @@ ReturnValue_t MgmRM3100Handler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t cmmValue = packet[1]; // We clear the seventh bit in any case // because this one is zero sometimes for some reason - bitutil::bitClear(&cmmValue, 6); + bitutil::clear(&cmmValue, 6); if(cmmValue == cmmRegValue and internalState == InternalState::READ_CMM) { commandExecuted = true; } diff --git a/src/fsfw/datapoollocal/LocalPoolDataSetBase.cpp b/src/fsfw/datapoollocal/LocalPoolDataSetBase.cpp index 5422c68a..d1ac0c7f 100644 --- a/src/fsfw/datapoollocal/LocalPoolDataSetBase.cpp +++ b/src/fsfw/datapoollocal/LocalPoolDataSetBase.cpp @@ -110,7 +110,7 @@ ReturnValue_t LocalPoolDataSetBase::serializeWithValidityBuffer(uint8_t **buffer for (uint16_t count = 0; count < fillCount; count++) { if(registeredVariables[count]->isValid()) { /* Set bit at correct position */ - bitutil::bitSet(validityPtr + validBufferIndex, validBufferIndexBit); + bitutil::set(validityPtr + validBufferIndex, validBufferIndexBit); } if(validBufferIndexBit == 7) { validBufferIndex ++; @@ -156,8 +156,8 @@ ReturnValue_t LocalPoolDataSetBase::deSerializeWithValidityBuffer( uint8_t validBufferIndexBit = 0; for (uint16_t count = 0; count < fillCount; count++) { // set validity buffer here. - bool nextVarValid = bitutil::bitGet(*buffer + - validBufferIndex, validBufferIndexBit); + bool nextVarValid = false; + bitutil::get(*buffer + validBufferIndex, validBufferIndexBit, nextVarValid); registeredVariables[count]->setValid(nextVarValid); if(validBufferIndexBit == 7) { diff --git a/src/fsfw/globalfunctions/PeriodicOperationDivider.cpp b/src/fsfw/globalfunctions/PeriodicOperationDivider.cpp index 62cc6f4c..ac6a78e4 100644 --- a/src/fsfw/globalfunctions/PeriodicOperationDivider.cpp +++ b/src/fsfw/globalfunctions/PeriodicOperationDivider.cpp @@ -2,43 +2,40 @@ PeriodicOperationDivider::PeriodicOperationDivider(uint32_t divider, - bool resetAutomatically): resetAutomatically(resetAutomatically), - counter(divider), divider(divider) { + bool resetAutomatically): resetAutomatically(resetAutomatically), + divider(divider) { } bool PeriodicOperationDivider::checkAndIncrement() { - bool opNecessary = check(); - if(opNecessary) { - if(resetAutomatically) { - counter = 0; - } - return opNecessary; - } - counter ++; - return opNecessary; + bool opNecessary = check(); + if(opNecessary and resetAutomatically) { + resetCounter(); + } + else { + counter++; + } + return opNecessary; } bool PeriodicOperationDivider::check() { - if(counter >= divider) { - return true; - } - return false; + if(counter >= divider) { + return true; + } + return false; } - - void PeriodicOperationDivider::resetCounter() { - counter = 0; + counter = 1; } void PeriodicOperationDivider::setDivider(uint32_t newDivider) { - divider = newDivider; + divider = newDivider; } uint32_t PeriodicOperationDivider::getCounter() const { - return counter; + return counter; } uint32_t PeriodicOperationDivider::getDivider() const { - return divider; + return divider; } diff --git a/src/fsfw/globalfunctions/PeriodicOperationDivider.h b/src/fsfw/globalfunctions/PeriodicOperationDivider.h index 7f7fb469..636849c0 100644 --- a/src/fsfw/globalfunctions/PeriodicOperationDivider.h +++ b/src/fsfw/globalfunctions/PeriodicOperationDivider.h @@ -13,51 +13,50 @@ */ class PeriodicOperationDivider { public: - /** - * Initialize with the desired divider and specify whether the internal - * counter will be reset automatically. - * @param divider - * @param resetAutomatically - */ - PeriodicOperationDivider(uint32_t divider, bool resetAutomatically = true); + /** + * Initialize with the desired divider and specify whether the internal + * counter will be reset automatically. + * @param divider Value of 0 or 1 will cause #check and #checkAndIncrement to always return + * true + * @param resetAutomatically + */ + PeriodicOperationDivider(uint32_t divider, bool resetAutomatically = true); + /** + * Check whether operation is necessary. If an operation is necessary and the class has been + * configured to be reset automatically, the counter will be reset to 1 automatically + * + * @return + * -@c true if the counter is larger or equal to the divider + * -@c false otherwise + */ + bool checkAndIncrement(); - /** - * Check whether operation is necessary. - * If an operation is necessary and the class has been - * configured to be reset automatically, the counter will be reset. - * - * @return - * -@c true if the counter is larger or equal to the divider - * -@c false otherwise - */ - bool checkAndIncrement(); + /** + * Checks whether an operation is necessary. This function will not increment the counter. + * @return + * -@c true if the counter is larger or equal to the divider + * -@c false otherwise + */ + bool check(); - /** - * Checks whether an operation is necessary. - * This function will not increment the counter! - * @return - * -@c true if the counter is larger or equal to the divider - * -@c false otherwise - */ - bool check(); + /** + * Can be used to reset the counter to 1 manually + */ + void resetCounter(); + uint32_t getCounter() const; - /** - * Can be used to reset the counter to 0 manually. - */ - void resetCounter(); - uint32_t getCounter() const; + /** + * Can be used to set a new divider value. + * @param newDivider + */ + void setDivider(uint32_t newDivider); + uint32_t getDivider() const; - /** - * Can be used to set a new divider value. - * @param newDivider - */ - void setDivider(uint32_t newDivider); - uint32_t getDivider() const; private: - bool resetAutomatically = true; - uint32_t counter = 0; - uint32_t divider = 0; + bool resetAutomatically = true; + uint32_t counter = 1; + uint32_t divider = 0; }; diff --git a/src/fsfw/globalfunctions/bitutility.cpp b/src/fsfw/globalfunctions/bitutility.cpp index 628e30c2..54e94a95 100644 --- a/src/fsfw/globalfunctions/bitutility.cpp +++ b/src/fsfw/globalfunctions/bitutility.cpp @@ -1,6 +1,6 @@ #include "fsfw/globalfunctions/bitutility.h" -void bitutil::bitSet(uint8_t *byte, uint8_t position) { +void bitutil::set(uint8_t *byte, uint8_t position) { if(position > 7) { return; } @@ -8,7 +8,7 @@ void bitutil::bitSet(uint8_t *byte, uint8_t position) { *byte |= 1 << shiftNumber; } -void bitutil::bitToggle(uint8_t *byte, uint8_t position) { +void bitutil::toggle(uint8_t *byte, uint8_t position) { if(position > 7) { return; } @@ -16,7 +16,7 @@ void bitutil::bitToggle(uint8_t *byte, uint8_t position) { *byte ^= 1 << shiftNumber; } -void bitutil::bitClear(uint8_t *byte, uint8_t position) { +void bitutil::clear(uint8_t *byte, uint8_t position) { if(position > 7) { return; } @@ -24,10 +24,11 @@ void bitutil::bitClear(uint8_t *byte, uint8_t position) { *byte &= ~(1 << shiftNumber); } -bool bitutil::bitGet(const uint8_t *byte, uint8_t position) { +bool bitutil::get(const uint8_t *byte, uint8_t position, bool& bit) { if(position > 7) { return false; } uint8_t shiftNumber = position + (7 - 2 * position); - return *byte & (1 << shiftNumber); + bit = *byte & (1 << shiftNumber); + return true; } diff --git a/src/fsfw/globalfunctions/bitutility.h b/src/fsfw/globalfunctions/bitutility.h index 1fc1290d..00f19310 100644 --- a/src/fsfw/globalfunctions/bitutility.h +++ b/src/fsfw/globalfunctions/bitutility.h @@ -5,13 +5,36 @@ namespace bitutil { -/* Helper functions for manipulating the individual bits of a byte. -Position refers to n-th bit of a byte, going from 0 (most significant bit) to -7 (least significant bit) */ -void bitSet(uint8_t* byte, uint8_t position); -void bitToggle(uint8_t* byte, uint8_t position); -void bitClear(uint8_t* byte, uint8_t position); -bool bitGet(const uint8_t* byte, uint8_t position); +// Helper functions for manipulating the individual bits of a byte. +// Position refers to n-th bit of a byte, going from 0 (most significant bit) to +// 7 (least significant bit) + +/** + * @brief Set the bit in a given byte + * @param byte + * @param position + */ +void set(uint8_t* byte, uint8_t position); +/** + * @brief Toggle the bit in a given byte + * @param byte + * @param position + */ +void toggle(uint8_t* byte, uint8_t position); +/** + * @brief Clear the bit in a given byte + * @param byte + * @param position + */ +void clear(uint8_t* byte, uint8_t position); +/** + * @brief Get the bit in a given byte + * @param byte + * @param position + * @param If the input is valid, this will be set to true if the bit is set and false otherwise. + * @return False if position is invalid, True otherwise + */ +bool get(const uint8_t* byte, uint8_t position, bool& bit); } diff --git a/tests/src/fsfw_tests/unit/datapoollocal/DataSetTest.cpp b/tests/src/fsfw_tests/unit/datapoollocal/DataSetTest.cpp index c967b241..e84f07b6 100644 --- a/tests/src/fsfw_tests/unit/datapoollocal/DataSetTest.cpp +++ b/tests/src/fsfw_tests/unit/datapoollocal/DataSetTest.cpp @@ -171,14 +171,19 @@ TEST_CASE("DataSetTest" , "[DataSetTest]") { /* We can do it like this because the buffer only has one byte for less than 8 variables */ uint8_t* validityByte = buffer + sizeof(buffer) - 1; - CHECK(bitutil::bitGet(validityByte, 0) == true); - CHECK(bitutil::bitGet(validityByte, 1) == false); - CHECK(bitutil::bitGet(validityByte, 2) == true); + bool bitSet = false; + bitutil::get(validityByte, 0, bitSet); + + CHECK(bitSet == true); + bitutil::get(validityByte, 1, bitSet); + CHECK(bitSet == false); + bitutil::get(validityByte, 2, bitSet); + CHECK(bitSet == true); /* Now we manipulate the validity buffer for the deserialization */ - bitutil::bitClear(validityByte, 0); - bitutil::bitSet(validityByte, 1); - bitutil::bitClear(validityByte, 2); + bitutil::clear(validityByte, 0); + bitutil::set(validityByte, 1); + bitutil::clear(validityByte, 2); /* Zero out everything except validity buffer */ std::memset(buffer, 0, sizeof(buffer) - 1); sizeToDeserialize = maxSize; @@ -239,8 +244,11 @@ TEST_CASE("DataSetTest" , "[DataSetTest]") { std::memcpy(validityBuffer.data(), buffer + 9 + sizeof(uint16_t) * 3, 2); /* The first 9 variables should be valid */ CHECK(validityBuffer[0] == 0xff); - CHECK(bitutil::bitGet(validityBuffer.data() + 1, 0) == true); - CHECK(bitutil::bitGet(validityBuffer.data() + 1, 1) == false); + bool bitSet = false; + bitutil::get(validityBuffer.data() + 1, 0, bitSet); + CHECK(bitSet == true); + bitutil::get(validityBuffer.data() + 1, 1, bitSet); + CHECK(bitSet == false); /* Now we invert the validity */ validityBuffer[0] = 0; diff --git a/tests/src/fsfw_tests/unit/globalfunctions/CMakeLists.txt b/tests/src/fsfw_tests/unit/globalfunctions/CMakeLists.txt index 209ce75f..3b29f23f 100644 --- a/tests/src/fsfw_tests/unit/globalfunctions/CMakeLists.txt +++ b/tests/src/fsfw_tests/unit/globalfunctions/CMakeLists.txt @@ -1,3 +1,5 @@ target_sources(${FSFW_TEST_TGT} PRIVATE testDleEncoder.cpp + testOpDivider.cpp + testBitutil.cpp ) diff --git a/tests/src/fsfw_tests/unit/globalfunctions/testBitutil.cpp b/tests/src/fsfw_tests/unit/globalfunctions/testBitutil.cpp new file mode 100644 index 00000000..2627adcf --- /dev/null +++ b/tests/src/fsfw_tests/unit/globalfunctions/testBitutil.cpp @@ -0,0 +1,64 @@ +#include "fsfw/globalfunctions/bitutility.h" +#include + +TEST_CASE("Bitutility" , "[Bitutility]") { + uint8_t dummyByte = 0; + bool bitSet = false; + for(uint8_t pos = 0; pos < 8; pos++) { + bitutil::set(&dummyByte, pos); + REQUIRE(dummyByte == (1 << (7 - pos))); + bitutil::get(&dummyByte, pos, bitSet); + REQUIRE(bitSet == 1); + dummyByte = 0; + } + + dummyByte = 0xff; + for(uint8_t pos = 0; pos < 8; pos++) { + bitutil::get(&dummyByte, pos, bitSet); + REQUIRE(bitSet == 1); + bitutil::clear(&dummyByte, pos); + bitutil::get(&dummyByte, pos, bitSet); + REQUIRE(bitSet == 0); + dummyByte = 0xff; + } + + dummyByte = 0xf0; + for(uint8_t pos = 0; pos < 8; pos++) { + if(pos < 4) { + bitutil::get(&dummyByte, pos, bitSet); + REQUIRE(bitSet == 1); + bitutil::toggle(&dummyByte, pos); + bitutil::get(&dummyByte, pos, bitSet); + REQUIRE(bitSet == 0); + } + else { + bitutil::get(&dummyByte, pos, bitSet); + REQUIRE(bitSet == false); + bitutil::toggle(&dummyByte, pos); + bitutil::get(&dummyByte, pos, bitSet); + REQUIRE(bitSet == true); + } + } + REQUIRE(dummyByte == 0x0f); + + dummyByte = 0; + bitutil::set(&dummyByte, 8); + REQUIRE(dummyByte == 0); + bitutil::set(&dummyByte, -1); + REQUIRE(dummyByte == 0); + dummyByte = 0xff; + bitutil::clear(&dummyByte, 8); + REQUIRE(dummyByte == 0xff); + bitutil::clear(&dummyByte, -1); + REQUIRE(dummyByte == 0xff); + dummyByte = 0x00; + bitutil::toggle(&dummyByte, 8); + REQUIRE(dummyByte == 0x00); + bitutil::toggle(&dummyByte, -1); + REQUIRE(dummyByte == 0x00); + + REQUIRE(bitutil::get(&dummyByte, 8, bitSet) == false); +} + + + diff --git a/tests/src/fsfw_tests/unit/globalfunctions/testOpDivider.cpp b/tests/src/fsfw_tests/unit/globalfunctions/testOpDivider.cpp new file mode 100644 index 00000000..c02ada83 --- /dev/null +++ b/tests/src/fsfw_tests/unit/globalfunctions/testOpDivider.cpp @@ -0,0 +1,64 @@ +#include "fsfw/globalfunctions/PeriodicOperationDivider.h" +#include + +TEST_CASE("OpDivider" , "[OpDivider]") { + auto opDivider = PeriodicOperationDivider(1); + REQUIRE(opDivider.getDivider() == 1); + REQUIRE(opDivider.getCounter() == 1); + REQUIRE(opDivider.check() == true); + REQUIRE(opDivider.checkAndIncrement() == true); + REQUIRE(opDivider.getCounter() == 1); + REQUIRE(opDivider.check() == true); + REQUIRE(opDivider.checkAndIncrement() == true); + REQUIRE(opDivider.checkAndIncrement() == true); + + opDivider.setDivider(0); + REQUIRE(opDivider.getCounter() == 1); + REQUIRE(opDivider.checkAndIncrement() == true); + REQUIRE(opDivider.getCounter() == 1); + REQUIRE(opDivider.checkAndIncrement() == true); + REQUIRE(opDivider.checkAndIncrement() == true); + + opDivider.setDivider(2); + opDivider.resetCounter(); + REQUIRE(opDivider.getDivider() == 2); + REQUIRE(opDivider.getCounter() == 1); + REQUIRE(opDivider.check() == false); + REQUIRE(opDivider.checkAndIncrement() == false); + REQUIRE(opDivider.getCounter() == 2); + REQUIRE(opDivider.check() == true); + REQUIRE(opDivider.checkAndIncrement() == true); + REQUIRE(opDivider.getCounter() == 1); + REQUIRE(opDivider.check() == false); + REQUIRE(opDivider.checkAndIncrement() == false); + REQUIRE(opDivider.getCounter() == 2); + REQUIRE(opDivider.checkAndIncrement() == true); + REQUIRE(opDivider.checkAndIncrement() == false); + REQUIRE(opDivider.checkAndIncrement() == true); + REQUIRE(opDivider.checkAndIncrement() == false); + + opDivider.setDivider(3); + opDivider.resetCounter(); + REQUIRE(opDivider.checkAndIncrement() == false); + REQUIRE(opDivider.checkAndIncrement() == false); + REQUIRE(opDivider.getCounter() == 3); + REQUIRE(opDivider.checkAndIncrement() == true); + REQUIRE(opDivider.getCounter() == 1); + REQUIRE(opDivider.checkAndIncrement() == false); + + auto opDividerNonResetting = PeriodicOperationDivider(2, false); + REQUIRE(opDividerNonResetting.getCounter() == 1); + REQUIRE(opDividerNonResetting.check() == false); + REQUIRE(opDividerNonResetting.checkAndIncrement() == false); + REQUIRE(opDividerNonResetting.getCounter() == 2); + REQUIRE(opDividerNonResetting.check() == true); + REQUIRE(opDividerNonResetting.checkAndIncrement() == true); + REQUIRE(opDividerNonResetting.getCounter() == 3); + REQUIRE(opDividerNonResetting.checkAndIncrement() == true); + REQUIRE(opDividerNonResetting.getCounter() == 4); + opDividerNonResetting.resetCounter(); + REQUIRE(opDividerNonResetting.getCounter() == 1); + REQUIRE(opDividerNonResetting.check() == false); + REQUIRE(opDividerNonResetting.checkAndIncrement() == false); + REQUIRE(opDividerNonResetting.getCounter() == 2); +} From 0176c07886822b697496bff1afea906b451ac75a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 10 Nov 2021 18:49:29 +0100 Subject: [PATCH 78/89] use IF instead of void pointer --- src/fsfw/memory/FileSystemArgsIF.h | 13 +++++++++++++ src/fsfw/memory/HasFileSystemIF.h | 27 +++++++++++++++++---------- 2 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 src/fsfw/memory/FileSystemArgsIF.h diff --git a/src/fsfw/memory/FileSystemArgsIF.h b/src/fsfw/memory/FileSystemArgsIF.h new file mode 100644 index 00000000..67d423ff --- /dev/null +++ b/src/fsfw/memory/FileSystemArgsIF.h @@ -0,0 +1,13 @@ +#ifndef FSFW_SRC_FSFW_MEMORY_FILESYSTEMARGS_H_ +#define FSFW_SRC_FSFW_MEMORY_FILESYSTEMARGS_H_ + +/** + * Empty base interface which can be implemented by to pass arguments via the HasFileSystemIF. + * Users can then dynamic_cast the base pointer to the require child pointer. + */ +class FileSystemArgsIF { +public: + virtual~ FileSystemArgsIF() {}; +}; + +#endif /* FSFW_SRC_FSFW_MEMORY_FILESYSTEMARGS_H_ */ diff --git a/src/fsfw/memory/HasFileSystemIF.h b/src/fsfw/memory/HasFileSystemIF.h index ec941f59..be2f8923 100644 --- a/src/fsfw/memory/HasFileSystemIF.h +++ b/src/fsfw/memory/HasFileSystemIF.h @@ -1,9 +1,10 @@ #ifndef FSFW_MEMORY_HASFILESYSTEMIF_H_ #define FSFW_MEMORY_HASFILESYSTEMIF_H_ -#include "../returnvalues/HasReturnvaluesIF.h" -#include "../returnvalues/FwClassIds.h" -#include "../ipc/messageQueueDefinitions.h" +#include "FileSystemArgsIF.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/returnvalues/FwClassIds.h" +#include "fsfw/ipc/messageQueueDefinitions.h" #include @@ -59,7 +60,7 @@ public: */ virtual ReturnValue_t appendToFile(const char* repositoryPath, const char* filename, const uint8_t* data, size_t size, - uint16_t packetNumber, void* args = nullptr) = 0; + uint16_t packetNumber, FileSystemArgsIF* args = nullptr) = 0; /** * @brief Generic function to create a new file. @@ -72,7 +73,7 @@ public: */ virtual ReturnValue_t createFile(const char* repositoryPath, const char* filename, const uint8_t* data = nullptr, - size_t size = 0, void* args = nullptr) = 0; + size_t size = 0, FileSystemArgsIF* args = nullptr) = 0; /** * @brief Generic function to delete a file. @@ -81,24 +82,30 @@ public: * @param args Any other arguments which an implementation might require * @return */ - virtual ReturnValue_t deleteFile(const char* repositoryPath, - const char* filename, void* args = nullptr) = 0; + virtual ReturnValue_t removeFile(const char* repositoryPath, + const char* filename, FileSystemArgsIF* args = nullptr) = 0; /** * @brief Generic function to create a directory * @param repositoryPath + * @param Equivalent to the -p flag in Unix systems. If some required parent directories + * do not exist, create them as well * @param args Any other arguments which an implementation might require * @return */ - virtual ReturnValue_t createDirectory(const char* repositoryPath, void* args = nullptr) = 0; + virtual ReturnValue_t createDirectory(const char* repositoryPath, const char* dirname, + bool createParentDirs, FileSystemArgsIF* args = nullptr) = 0; /** * @brief Generic function to remove a directory * @param repositoryPath * @param args Any other arguments which an implementation might require */ - virtual ReturnValue_t removeDirectory(const char* repositoryPath, - bool deleteRecurively = false, void* args = nullptr) = 0; + virtual ReturnValue_t removeDirectory(const char* repositoryPath, const char* dirname, + bool deleteRecurively = false, FileSystemArgsIF* args = nullptr) = 0; + + virtual ReturnValue_t renameFile(const char* repositoryPath, const char* oldFilename, + const char* newFilename, FileSystemArgsIF* args = nullptr) = 0; }; From 30217aa42b9ca23b1a0a8a8a972953277b124c34 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 10 Nov 2021 18:51:56 +0100 Subject: [PATCH 79/89] updated SerializeAdapter.h - Updates `SerializerAdapter` to also take simple pointer and simply assign the serialized and deSerialized size - Added related unittests --- src/fsfw/serialize/SerializeAdapter.h | 400 +++++++++++------- .../unit/serialize/TestSerialization.cpp | 297 ++++++++----- 2 files changed, 429 insertions(+), 268 deletions(-) diff --git a/src/fsfw/serialize/SerializeAdapter.h b/src/fsfw/serialize/SerializeAdapter.h index e6cd247e..2831472c 100644 --- a/src/fsfw/serialize/SerializeAdapter.h +++ b/src/fsfw/serialize/SerializeAdapter.h @@ -7,7 +7,7 @@ #include #include - /** +/** * @brief These adapters provides an interface to use the SerializeIF functions * with arbitrary template objects to facilitate and simplify the * serialization of classes with different multiple different data types @@ -20,174 +20,250 @@ */ class SerializeAdapter { public: - /*** - * This function can be used to serialize a trivial copy-able type or a - * child of SerializeIF. - * The right template to be called is determined in the function itself. - * For objects of non trivial copy-able type this function is almost never - * called by the user directly. Instead helpers for specific types like - * SerialArrayListAdapter or SerialLinkedListAdapter is the right choice here. - * - * @param[in] object Object to serialize, the used type is deduced from this pointer - * @param[in/out] buffer Buffer to serialize into. Will be moved by the function. - * @param[in/out] size Size of current written buffer. Will be incremented by the function. - * @param[in] maxSize Max size of Buffer - * @param[in] streamEndianness Endianness of serialized element as in according to SerializeIF::Endianness - * @return - * - @c BUFFER_TOO_SHORT The given buffer in is too short - * - @c RETURN_FAILED Generic Error - * - @c RETURN_OK Successful serialization - */ - template - static ReturnValue_t serialize(const T *object, uint8_t **buffer, - size_t *size, size_t maxSize, - SerializeIF::Endianness streamEndianness) { - InternalSerializeAdapter::value> adapter; - return adapter.serialize(object, buffer, size, maxSize, - streamEndianness); - } - /** - * Function to return the serialized size of the object in the pointer. - * May be a trivially copy-able object or a Child of SerializeIF - * - * @param object Pointer to Object - * @return Serialized size of object - */ - template - static size_t getSerializedSize(const T *object){ - InternalSerializeAdapter::value> adapter; - return adapter.getSerializedSize(object); - } - /** - * @brief - * Deserializes a object from a given buffer of given size. - * Object Must be trivially copy-able or a child of SerializeIF. - * - * @details - * Buffer will be moved to the current read location. Size will be decreased by the function. - * - * @param[in/out] buffer Buffer to deSerialize from. Will be moved by the function. - * @param[in/out] size Remaining size of the buffer to read from. Will be decreased by function. - * @param[in] streamEndianness Endianness as in according to SerializeIF::Endianness - * @return - * - @c STREAM_TOO_SHORT The input stream is too short to deSerialize the object - * - @c TOO_MANY_ELEMENTS The buffer has more inputs than expected - * - @c RETURN_FAILED Generic Error - * - @c RETURN_OK Successful deserialization - */ - template - static ReturnValue_t deSerialize(T *object, const uint8_t **buffer, - size_t *size, SerializeIF::Endianness streamEndianness) { - InternalSerializeAdapter::value> adapter; - return adapter.deSerialize(object, buffer, size, streamEndianness); - } + /*** + * @brief Serialize a trivial copy-able type or a child of SerializeIF. + * @details + * The right template to be called is determined in the function itself. + * For objects of non trivial copy-able type this function is almost never + * called by the user directly. Instead helpers for specific types like + * SerialArrayListAdapter or SerialLinkedListAdapter are the right choice here. + * + * @param[in] object: Object to serialize, the used type is deduced from this pointer + * @param[in/out] buffer: Pointer to the buffer to serialize into. Buffer position will be + * incremented by the function. + * @param[in/out] size: Pointer to size of current written buffer. + * SIze will be incremented by the function. + * @param[in] maxSize: Max size of Buffer + * @param[in] streamEndianness: Endianness of serialized element as in according to + * SerializeIF::Endianness + * @return + * - @c BUFFER_TOO_SHORT The given buffer in is too short + * - @c RETURN_FAILED Generic Error + * - @c RETURN_OK Successful serialization + */ + template + static ReturnValue_t serialize(const T *object, uint8_t **buffer, + size_t *size, size_t maxSize, + SerializeIF::Endianness streamEndianness) { + InternalSerializeAdapter::value> adapter; + return adapter.serialize(object, buffer, size, maxSize, + streamEndianness); + } + + /*** + * This function can be used to serialize a trivial copy-able type or a child of SerializeIF. + * The right template to be called is determined in the function itself. + * For objects of non trivial copy-able type this function is almost never + * called by the user directly. Instead helpers for specific types like + * SerialArrayListAdapter or SerialLinkedListAdapter are the right choice here. + * + * @param[in] object: Object to serialize, the used type is deduced from this pointer + * @param[in/out] buffer: Buffer to serialize into. + * @param[out] serSize: Serialized size + * @param[in] maxSize: Max size of buffer + * @param[in] streamEndianness: Endianness of serialized element as in according to + * SerializeIF::Endianness + * @return + * - @c BUFFER_TOO_SHORT The given buffer in is too short + * - @c RETURN_FAILED Generic Error + * - @c RETURN_OK Successful serialization + */ + template + static ReturnValue_t serialize(const T *object, uint8_t* const buffer, size_t* serSize, + size_t maxSize, SerializeIF::Endianness streamEndianness) { + if(object == nullptr or buffer == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } + InternalSerializeAdapter::value> adapter; + uint8_t** tempPtr = const_cast(&buffer); + size_t tmpSize = 0; + ReturnValue_t result = adapter.serialize(object, tempPtr, &tmpSize, maxSize, + streamEndianness); + if(serSize != nullptr) { + *serSize = tmpSize; + } + return result; + } + + /** + * @brief Function to return the serialized size of the object in the pointer. + * @details + * May be a trivially copy-able object or a child of SerializeIF. + * + * @param object Pointer to Object + * @return Serialized size of object + */ + template + static size_t getSerializedSize(const T *object){ + InternalSerializeAdapter::value> adapter; + return adapter.getSerializedSize(object); + } + + /** + * @brief Deserializes a object from a given buffer of given size. + * + * @details + * Object Must be trivially copy-able or a child of SerializeIF. + * Buffer will be moved to the current read location. Size will be decreased by the function. + * + * @param[in] object: Pointer to object to deserialize + * @param[in/out] buffer: Pointer to the buffer to deSerialize from. Buffer position will be + * incremented by the function + * @param[in/out] size: Pointer to remaining size of the buffer to read from. + * Will be decreased by function. + * @param[in] streamEndianness: Endianness as in according to SerializeIF::Endianness + * @return + * - @c STREAM_TOO_SHORT The input stream is too short to deSerialize the object + * - @c TOO_MANY_ELEMENTS The buffer has more inputs than expected + * - @c RETURN_FAILED Generic Error + * - @c RETURN_OK Successful deserialization + */ + template + static ReturnValue_t deSerialize(T *object, const uint8_t **buffer, + size_t *size, SerializeIF::Endianness streamEndianness) { + InternalSerializeAdapter::value> adapter; + return adapter.deSerialize(object, buffer, size, streamEndianness); + } + + /** + * @brief Deserializes a object from a given buffer of given size. + * + * @details + * Object Must be trivially copy-able or a child of SerializeIF. + * + * @param[in] object: Pointer to object to deserialize + * @param[in] buffer: Buffer to deSerialize from + * @param[out] deserSize: Deserialized length + * @param[in] streamEndianness: Endianness as in according to SerializeIF::Endianness + * @return + * - @c STREAM_TOO_SHORT The input stream is too short to deSerialize the object + * - @c TOO_MANY_ELEMENTS The buffer has more inputs than expected + * - @c RETURN_FAILED Generic Error + * - @c RETURN_OK Successful deserialization + */ + template + static ReturnValue_t deSerialize(T *object, const uint8_t* buffer, + size_t* deserSize, SerializeIF::Endianness streamEndianness) { + if(object == nullptr or buffer == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } + InternalSerializeAdapter::value> adapter; + const uint8_t** tempPtr = &buffer; + size_t maxVal = -1; + ReturnValue_t result = adapter.deSerialize(object, tempPtr, &maxVal, streamEndianness); + if(deserSize != nullptr) { + *deserSize = -1 - maxVal; + } + return result; + } + private: - /** - * Internal template to deduce the right function calls at compile time - */ - template class InternalSerializeAdapter; + /** + * Internal template to deduce the right function calls at compile time + */ + template class InternalSerializeAdapter; - /** - * Template to be used if T is not a child of SerializeIF - * - * @tparam T T must be trivially_copyable - */ - template - class InternalSerializeAdapter { - static_assert (std::is_trivially_copyable::value, - "If a type needs to be serialized it must be a child of " - "SerializeIF or trivially copy-able"); - public: - static ReturnValue_t serialize(const T *object, uint8_t **buffer, - size_t *size, size_t max_size, - SerializeIF::Endianness streamEndianness) { - size_t ignoredSize = 0; - if (size == nullptr) { - size = &ignoredSize; - } - // Check remaining size is large enough and check integer - // overflow of *size - size_t newSize = sizeof(T) + *size; - if ((newSize <= max_size) and (newSize > *size)) { - T tmp; - switch (streamEndianness) { - case SerializeIF::Endianness::BIG: - tmp = EndianConverter::convertBigEndian(*object); - break; - case SerializeIF::Endianness::LITTLE: - tmp = EndianConverter::convertLittleEndian(*object); - break; - default: - case SerializeIF::Endianness::MACHINE: - tmp = *object; - break; - } - std::memcpy(*buffer, &tmp, sizeof(T)); - *size += sizeof(T); - (*buffer) += sizeof(T); - return HasReturnvaluesIF::RETURN_OK; - } else { - return SerializeIF::BUFFER_TOO_SHORT; - } - } + /** + * Template to be used if T is not a child of SerializeIF + * + * @tparam T T must be trivially_copyable + */ + template + class InternalSerializeAdapter { + static_assert (std::is_trivially_copyable::value, + "If a type needs to be serialized it must be a child of " + "SerializeIF or trivially copy-able"); + public: + static ReturnValue_t serialize(const T *object, uint8_t **buffer, + size_t *size, size_t max_size, + SerializeIF::Endianness streamEndianness) { + size_t ignoredSize = 0; + if (size == nullptr) { + size = &ignoredSize; + } + // Check remaining size is large enough and check integer + // overflow of *size + size_t newSize = sizeof(T) + *size; + if ((newSize <= max_size) and (newSize > *size)) { + T tmp; + switch (streamEndianness) { + case SerializeIF::Endianness::BIG: + tmp = EndianConverter::convertBigEndian(*object); + break; + case SerializeIF::Endianness::LITTLE: + tmp = EndianConverter::convertLittleEndian(*object); + break; + default: + case SerializeIF::Endianness::MACHINE: + tmp = *object; + break; + } + std::memcpy(*buffer, &tmp, sizeof(T)); + *size += sizeof(T); + (*buffer) += sizeof(T); + return HasReturnvaluesIF::RETURN_OK; + } else { + return SerializeIF::BUFFER_TOO_SHORT; + } + } - ReturnValue_t deSerialize(T *object, const uint8_t **buffer, - size_t *size, SerializeIF::Endianness streamEndianness) { - T tmp; - if (*size >= sizeof(T)) { - *size -= sizeof(T); - std::memcpy(&tmp, *buffer, sizeof(T)); - switch (streamEndianness) { - case SerializeIF::Endianness::BIG: - *object = EndianConverter::convertBigEndian(tmp); - break; - case SerializeIF::Endianness::LITTLE: - *object = EndianConverter::convertLittleEndian(tmp); - break; - default: - case SerializeIF::Endianness::MACHINE: - *object = tmp; - break; - } + ReturnValue_t deSerialize(T *object, const uint8_t **buffer, + size_t *size, SerializeIF::Endianness streamEndianness) { + T tmp; + if (*size >= sizeof(T)) { + *size -= sizeof(T); + std::memcpy(&tmp, *buffer, sizeof(T)); + switch (streamEndianness) { + case SerializeIF::Endianness::BIG: + *object = EndianConverter::convertBigEndian(tmp); + break; + case SerializeIF::Endianness::LITTLE: + *object = EndianConverter::convertLittleEndian(tmp); + break; + default: + case SerializeIF::Endianness::MACHINE: + *object = tmp; + break; + } - *buffer += sizeof(T); - return HasReturnvaluesIF::RETURN_OK; - } else { - return SerializeIF::STREAM_TOO_SHORT; - } - } + *buffer += sizeof(T); + return HasReturnvaluesIF::RETURN_OK; + } else { + return SerializeIF::STREAM_TOO_SHORT; + } + } - uint32_t getSerializedSize(const T *object) { - return sizeof(T); - } - }; + uint32_t getSerializedSize(const T *object) { + return sizeof(T); + } + }; - /** - * Template for objects that inherit from SerializeIF - * - * @tparam T A child of SerializeIF - */ - template - class InternalSerializeAdapter { - public: - ReturnValue_t serialize(const T *object, uint8_t **buffer, size_t *size, - size_t max_size, - SerializeIF::Endianness streamEndianness) const { - size_t ignoredSize = 0; - if (size == nullptr) { - size = &ignoredSize; - } - return object->serialize(buffer, size, max_size, streamEndianness); - } - size_t getSerializedSize(const T *object) const { - return object->getSerializedSize(); - } + /** + * Template for objects that inherit from SerializeIF + * + * @tparam T A child of SerializeIF + */ + template + class InternalSerializeAdapter { + public: + ReturnValue_t serialize(const T *object, uint8_t **buffer, size_t *size, + size_t max_size, + SerializeIF::Endianness streamEndianness) const { + size_t ignoredSize = 0; + if (size == nullptr) { + size = &ignoredSize; + } + return object->serialize(buffer, size, max_size, streamEndianness); + } + size_t getSerializedSize(const T *object) const { + return object->getSerializedSize(); + } - ReturnValue_t deSerialize(T *object, const uint8_t **buffer, - size_t *size, SerializeIF::Endianness streamEndianness) { - return object->deSerialize(buffer, size, streamEndianness); - } - }; + ReturnValue_t deSerialize(T *object, const uint8_t **buffer, + size_t *size, SerializeIF::Endianness streamEndianness) { + return object->deSerialize(buffer, size, streamEndianness); + } + }; }; #endif /* _FSFW_SERIALIZE_SERIALIZEADAPTER_H_ */ diff --git a/tests/src/fsfw_tests/unit/serialize/TestSerialization.cpp b/tests/src/fsfw_tests/unit/serialize/TestSerialization.cpp index 64deae3b..f883fe78 100644 --- a/tests/src/fsfw_tests/unit/serialize/TestSerialization.cpp +++ b/tests/src/fsfw_tests/unit/serialize/TestSerialization.cpp @@ -3,128 +3,213 @@ #include #include +#include #include -static bool test_value_bool = true; -static uint8_t tv_uint8 {5}; -static uint16_t tv_uint16 {283}; -static uint32_t tv_uint32 {929221}; -static uint64_t tv_uint64 {2929329429}; +static bool testBool = true; +static uint8_t tvUint8 {5}; +static uint16_t tvUint16 {283}; +static uint32_t tvUint32 {929221}; +static uint64_t tvUint64 {2929329429}; -static int8_t tv_int8 {-16}; -static int16_t tv_int16 {-829}; -static int32_t tv_int32 {-2312}; +static int8_t tvInt8 {-16}; +static int16_t tvInt16 {-829}; +static int32_t tvInt32 {-2312}; -static float tv_float {8.2149214}; -static float tv_sfloat = {-922.2321321}; -static double tv_double {9.2132142141e8}; -static double tv_sdouble {-2.2421e19}; +static float tvFloat {8.2149214}; +static float tvSfloat = {-922.2321321}; +static double tvDouble {9.2132142141e8}; +static double tvSdouble {-2.2421e19}; -static std::array test_array; +static std::array TEST_ARRAY; -TEST_CASE( "Serialization size tests", "[TestSerialization]") { +TEST_CASE( "Serialization size tests", "[SerSizeTest]") { //REQUIRE(unitTestClass.test_autoserialization() == 0); - REQUIRE(SerializeAdapter::getSerializedSize(&test_value_bool) == - sizeof(test_value_bool)); - REQUIRE(SerializeAdapter::getSerializedSize(&tv_uint8) == - sizeof(tv_uint8)); - REQUIRE(SerializeAdapter::getSerializedSize(&tv_uint16) == - sizeof(tv_uint16)); - REQUIRE(SerializeAdapter::getSerializedSize(&tv_uint32 ) == - sizeof(tv_uint32)); - REQUIRE(SerializeAdapter::getSerializedSize(&tv_uint64) == - sizeof(tv_uint64)); - REQUIRE(SerializeAdapter::getSerializedSize(&tv_int8) == - sizeof(tv_int8)); - REQUIRE(SerializeAdapter::getSerializedSize(&tv_int16) == - sizeof(tv_int16)); - REQUIRE(SerializeAdapter::getSerializedSize(&tv_int32) == - sizeof(tv_int32)); - REQUIRE(SerializeAdapter::getSerializedSize(&tv_float) == - sizeof(tv_float)); - REQUIRE(SerializeAdapter::getSerializedSize(&tv_sfloat) == - sizeof(tv_sfloat )); - REQUIRE(SerializeAdapter::getSerializedSize(&tv_double) == - sizeof(tv_double)); - REQUIRE(SerializeAdapter::getSerializedSize(&tv_sdouble) == - sizeof(tv_sdouble)); + REQUIRE(SerializeAdapter::getSerializedSize(&testBool) == + sizeof(testBool)); + REQUIRE(SerializeAdapter::getSerializedSize(&tvUint8) == + sizeof(tvUint8)); + REQUIRE(SerializeAdapter::getSerializedSize(&tvUint16) == + sizeof(tvUint16)); + REQUIRE(SerializeAdapter::getSerializedSize(&tvUint32 ) == + sizeof(tvUint32)); + REQUIRE(SerializeAdapter::getSerializedSize(&tvUint64) == + sizeof(tvUint64)); + REQUIRE(SerializeAdapter::getSerializedSize(&tvInt8) == + sizeof(tvInt8)); + REQUIRE(SerializeAdapter::getSerializedSize(&tvInt16) == + sizeof(tvInt16)); + REQUIRE(SerializeAdapter::getSerializedSize(&tvInt32) == + sizeof(tvInt32)); + REQUIRE(SerializeAdapter::getSerializedSize(&tvFloat) == + sizeof(tvFloat)); + REQUIRE(SerializeAdapter::getSerializedSize(&tvSfloat) == + sizeof(tvSfloat )); + REQUIRE(SerializeAdapter::getSerializedSize(&tvDouble) == + sizeof(tvDouble)); + REQUIRE(SerializeAdapter::getSerializedSize(&tvSdouble) == + sizeof(tvSdouble)); } +TEST_CASE("Auto Serialize Adapter", "[SerAdapter]") { + size_t serializedSize = 0; + uint8_t * pArray = TEST_ARRAY.data(); -TEST_CASE("Auto Serialize Adapter testing", "[single-file]") { - size_t serialized_size = 0; - uint8_t * p_array = test_array.data(); + SECTION("SerDe") { + size_t deserSize = 0; + SerializeAdapter::serialize(&testBool, TEST_ARRAY.data(), &deserSize, TEST_ARRAY.size(), + SerializeIF::Endianness::MACHINE); + REQUIRE(deserSize == 1); + REQUIRE(TEST_ARRAY[0] == true); + bool readBack = false; + SerializeAdapter::deSerialize(&readBack, TEST_ARRAY.data(), &deserSize, + SerializeIF::Endianness::MACHINE); + REQUIRE(deserSize == 1); + REQUIRE(readBack == true); + SerializeAdapter::serialize(&tvUint8, TEST_ARRAY.data(), &deserSize, TEST_ARRAY.size(), + SerializeIF::Endianness::MACHINE); + REQUIRE(deserSize == 1); + REQUIRE(TEST_ARRAY[0] == 5); + uint8_t readBackUint8 = 0; + uint8_t* const testPtr = TEST_ARRAY.data(); + uint8_t* const shouldStayConst = testPtr; + SerializeAdapter::deSerialize(&readBackUint8, testPtr, &deserSize, + SerializeIF::Endianness::MACHINE); + REQUIRE(testPtr == shouldStayConst); + REQUIRE(deserSize == 1); + REQUIRE(readBackUint8 == 5); + SerializeAdapter::serialize(&tvUint16, TEST_ARRAY.data(), &deserSize, TEST_ARRAY.size(), + SerializeIF::Endianness::MACHINE); + REQUIRE(deserSize == 2); + deserSize = 0; + uint16_t readBackUint16 = 0; + SerializeAdapter::deSerialize(&readBackUint16, TEST_ARRAY.data(), &deserSize, + SerializeIF::Endianness::MACHINE); + REQUIRE(deserSize == 2); + REQUIRE(readBackUint16 == 283); - SECTION("Serializing...") { - SerializeAdapter::serialize(&test_value_bool, &p_array, - &serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE); - SerializeAdapter::serialize(&tv_uint8, &p_array, - &serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE); - SerializeAdapter::serialize(&tv_uint16, &p_array, - &serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE); - SerializeAdapter::serialize(&tv_uint32, &p_array, - &serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE); - SerializeAdapter::serialize(&tv_int8, &p_array, - &serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE); - SerializeAdapter::serialize(&tv_int16, &p_array, - &serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE); - SerializeAdapter::serialize(&tv_int32, &p_array, - &serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE); - SerializeAdapter::serialize(&tv_uint64, &p_array, - &serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE); - SerializeAdapter::serialize(&tv_float, &p_array, - &serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE); - SerializeAdapter::serialize(&tv_double, &p_array, - &serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE); - SerializeAdapter::serialize(&tv_sfloat, &p_array, - &serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE); - SerializeAdapter::serialize(&tv_sdouble, &p_array, - &serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE); - REQUIRE (serialized_size == 47); + SerializeAdapter::serialize(&tvUint32, TEST_ARRAY.data(), &deserSize, TEST_ARRAY.size(), + SerializeIF::Endianness::MACHINE); + REQUIRE(deserSize == 4); + uint32_t readBackUint32 = 0; + deserSize = 0; + SerializeAdapter::deSerialize(&readBackUint32, TEST_ARRAY.data(), &deserSize, + SerializeIF::Endianness::MACHINE); + REQUIRE(deserSize == 4); + REQUIRE(readBackUint32 == 929221); + + SerializeAdapter::serialize(&tvInt16, TEST_ARRAY.data(), &deserSize, TEST_ARRAY.size(), + SerializeIF::Endianness::MACHINE); + REQUIRE(deserSize == 2); + int16_t readBackInt16 = 0; + SerializeAdapter::deSerialize(&readBackInt16, TEST_ARRAY.data(), &deserSize, + SerializeIF::Endianness::MACHINE); + REQUIRE(readBackInt16 == -829); + REQUIRE(deserSize == 2); + + SerializeAdapter::serialize(&tvFloat, TEST_ARRAY.data(), &deserSize, TEST_ARRAY.size(), + SerializeIF::Endianness::MACHINE); + float readBackFloat = 0.0; + SerializeAdapter::deSerialize(&readBackFloat, TEST_ARRAY.data(), &deserSize, + SerializeIF::Endianness::MACHINE); + REQUIRE(readBackFloat == Catch::Approx(8.214921)); + + SerializeAdapter::serialize(&tvSdouble, TEST_ARRAY.data(), &deserSize, TEST_ARRAY.size(), + SerializeIF::Endianness::MACHINE); + double readBackSignedDouble = 0.0; + SerializeAdapter::deSerialize(&readBackSignedDouble, TEST_ARRAY.data(), &deserSize, + SerializeIF::Endianness::MACHINE); + REQUIRE(readBackSignedDouble == Catch::Approx(-2.2421e19)); + + uint8_t testBuf[4] = {1, 2, 3, 4}; + SerialBufferAdapter bufferAdapter(testBuf, sizeof(testBuf)); + SerializeAdapter::serialize(&bufferAdapter, TEST_ARRAY.data(), &deserSize, + TEST_ARRAY.size(), SerializeIF::Endianness::MACHINE); + REQUIRE(deserSize == 4); + for(uint8_t idx = 0; idx < 4; idx++) { + REQUIRE(TEST_ARRAY[idx] == idx + 1); + } + deserSize = 0; + testBuf[0] = 0; + testBuf[1] = 12; + SerializeAdapter::deSerialize(&bufferAdapter, TEST_ARRAY.data(), &deserSize, + SerializeIF::Endianness::MACHINE); + REQUIRE(deserSize == 4); + for(uint8_t idx = 0; idx < 4; idx++) { + REQUIRE(testBuf[idx] == idx + 1); + } + } + + SECTION("Serialize incrementing") { + SerializeAdapter::serialize(&testBool, &pArray, &serializedSize, + TEST_ARRAY.size(), SerializeIF::Endianness::MACHINE); + SerializeAdapter::serialize(&tvUint8, &pArray, &serializedSize, + TEST_ARRAY.size(), SerializeIF::Endianness::MACHINE); + SerializeAdapter::serialize(&tvUint16, &pArray, &serializedSize, + TEST_ARRAY.size(), SerializeIF::Endianness::MACHINE); + SerializeAdapter::serialize(&tvUint32, &pArray, &serializedSize, + TEST_ARRAY.size(), SerializeIF::Endianness::MACHINE); + SerializeAdapter::serialize(&tvInt8, &pArray, &serializedSize, + TEST_ARRAY.size(), SerializeIF::Endianness::MACHINE); + SerializeAdapter::serialize(&tvInt16, &pArray, &serializedSize, + TEST_ARRAY.size(), SerializeIF::Endianness::MACHINE); + SerializeAdapter::serialize(&tvInt32, &pArray, &serializedSize, + TEST_ARRAY.size(), SerializeIF::Endianness::MACHINE); + SerializeAdapter::serialize(&tvUint64, &pArray, &serializedSize, + TEST_ARRAY.size(), SerializeIF::Endianness::MACHINE); + SerializeAdapter::serialize(&tvFloat, &pArray, &serializedSize, + TEST_ARRAY.size(), SerializeIF::Endianness::MACHINE); + SerializeAdapter::serialize(&tvDouble, &pArray, &serializedSize, TEST_ARRAY.size(), + SerializeIF::Endianness::MACHINE); + SerializeAdapter::serialize(&tvSfloat, &pArray, &serializedSize, TEST_ARRAY.size(), + SerializeIF::Endianness::MACHINE); + SerializeAdapter::serialize(&tvSdouble, &pArray, &serializedSize, TEST_ARRAY.size(), + SerializeIF::Endianness::MACHINE); + REQUIRE (serializedSize == 47); } - SECTION("Deserializing") { - p_array = test_array.data(); - size_t remaining_size = serialized_size; - SerializeAdapter::deSerialize(&test_value_bool, - const_cast(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE); - SerializeAdapter::deSerialize(&tv_uint8, - const_cast(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE); - SerializeAdapter::deSerialize(&tv_uint16, - const_cast(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE); - SerializeAdapter::deSerialize(&tv_uint32, - const_cast(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE); - SerializeAdapter::deSerialize(&tv_int8, - const_cast(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE); - SerializeAdapter::deSerialize(&tv_int16, - const_cast(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE); - SerializeAdapter::deSerialize(&tv_int32, - const_cast(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE); - SerializeAdapter::deSerialize(&tv_uint64, - const_cast(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE); - SerializeAdapter::deSerialize(&tv_float, - const_cast(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE); - SerializeAdapter::deSerialize(&tv_double, - const_cast(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE); - SerializeAdapter::deSerialize(&tv_sfloat, - const_cast(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE); - SerializeAdapter::deSerialize(&tv_sdouble, - const_cast(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE); + SECTION("Deserialize decrementing") { + pArray = TEST_ARRAY.data(); + size_t remaining_size = serializedSize; + SerializeAdapter::deSerialize(&testBool, const_cast(&pArray), + &remaining_size, SerializeIF::Endianness::MACHINE); + SerializeAdapter::deSerialize(&tvUint8, const_cast(&pArray), + &remaining_size, SerializeIF::Endianness::MACHINE); + SerializeAdapter::deSerialize(&tvUint16, const_cast(&pArray), + &remaining_size, SerializeIF::Endianness::MACHINE); + SerializeAdapter::deSerialize(&tvUint32, const_cast(&pArray), + &remaining_size, SerializeIF::Endianness::MACHINE); + SerializeAdapter::deSerialize(&tvInt8, const_cast(&pArray), + &remaining_size, SerializeIF::Endianness::MACHINE); + SerializeAdapter::deSerialize(&tvInt16, const_cast(&pArray), + &remaining_size, SerializeIF::Endianness::MACHINE); + SerializeAdapter::deSerialize(&tvInt32, const_cast(&pArray), + &remaining_size, SerializeIF::Endianness::MACHINE); + SerializeAdapter::deSerialize(&tvUint64, + const_cast(&pArray), &remaining_size, SerializeIF::Endianness::MACHINE); + SerializeAdapter::deSerialize(&tvFloat, + const_cast(&pArray), &remaining_size, SerializeIF::Endianness::MACHINE); + SerializeAdapter::deSerialize(&tvDouble, + const_cast(&pArray), &remaining_size, SerializeIF::Endianness::MACHINE); + SerializeAdapter::deSerialize(&tvSfloat, + const_cast(&pArray), &remaining_size, SerializeIF::Endianness::MACHINE); + SerializeAdapter::deSerialize(&tvSdouble, + const_cast(&pArray), &remaining_size, SerializeIF::Endianness::MACHINE); - REQUIRE(test_value_bool == true); - REQUIRE(tv_uint8 == 5); - REQUIRE(tv_uint16 == 283); - REQUIRE(tv_uint32 == 929221); - REQUIRE(tv_uint64 == 2929329429); - REQUIRE(tv_int8 == -16); - REQUIRE(tv_int16 == -829); - REQUIRE(tv_int32 == -2312); + REQUIRE(testBool == true); + REQUIRE(tvUint8 == 5); + REQUIRE(tvUint16 == 283); + REQUIRE(tvUint32 == 929221); + REQUIRE(tvUint64 == 2929329429); + REQUIRE(tvInt8 == -16); + REQUIRE(tvInt16 == -829); + REQUIRE(tvInt32 == -2312); - REQUIRE(tv_float == Catch::Approx(8.214921)); - REQUIRE(tv_double == Catch::Approx(9.2132142141e8)); - REQUIRE(tv_sfloat == Catch::Approx(-922.2321321)); - REQUIRE(tv_sdouble == Catch::Approx(-2.2421e19)); + REQUIRE(tvFloat == Catch::Approx(8.214921)); + REQUIRE(tvDouble == Catch::Approx(9.2132142141e8)); + REQUIRE(tvSfloat == Catch::Approx(-922.2321321)); + REQUIRE(tvSdouble == Catch::Approx(-2.2421e19)); } } From 05c4f4fadca0ba73f1e51bd4ac50d278df11aabd Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 18 Nov 2021 19:56:24 +0100 Subject: [PATCH 80/89] Bugfix for Packet ID getters - Also added related unittests --- src/fsfw/tmtcpacket/SpacePacket.h | 2 +- tests/src/fsfw_tests/unit/tmtcpacket/CMakeLists.txt | 2 +- tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp diff --git a/src/fsfw/tmtcpacket/SpacePacket.h b/src/fsfw/tmtcpacket/SpacePacket.h index 16673319..a092712c 100644 --- a/src/fsfw/tmtcpacket/SpacePacket.h +++ b/src/fsfw/tmtcpacket/SpacePacket.h @@ -73,7 +73,7 @@ namespace spacepacket { constexpr uint16_t getSpacePacketIdFromApid(bool isTc, uint16_t apid, bool secondaryHeaderFlag = true) { - return (((isTc << 5) & 0x10) | ((secondaryHeaderFlag << 4) & 0x08) | + return ((isTc << 4) | (secondaryHeaderFlag << 3) | ((apid >> 8) & 0x07)) << 8 | (apid & 0x00ff); } diff --git a/tests/src/fsfw_tests/unit/tmtcpacket/CMakeLists.txt b/tests/src/fsfw_tests/unit/tmtcpacket/CMakeLists.txt index 36838b24..958bda40 100644 --- a/tests/src/fsfw_tests/unit/tmtcpacket/CMakeLists.txt +++ b/tests/src/fsfw_tests/unit/tmtcpacket/CMakeLists.txt @@ -1,3 +1,3 @@ target_sources(${FSFW_TEST_TGT} PRIVATE - PusTmTest.cpp + testCcsds.cpp ) diff --git a/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp b/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp new file mode 100644 index 00000000..8f531805 --- /dev/null +++ b/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp @@ -0,0 +1,11 @@ +#include + +#include "fsfw/tmtcpacket/SpacePacket.h" + +TEST_CASE( "CCSDS Test" , "[ccsds]") { + REQUIRE(spacepacket::getTcSpacePacketIdFromApid(0x22) == 0x1822); + REQUIRE(spacepacket::getTmSpacePacketIdFromApid(0x22) == 0x0822); + + REQUIRE(spacepacket::getTcSpacePacketIdFromApid(0x7ff) == 0x1fff); + REQUIRE(spacepacket::getTmSpacePacketIdFromApid(0x7ff) == 0xfff); +} From 00dced31ee17f06a112b473b4b54fea8982c5f92 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 19 Nov 2021 13:50:46 +0100 Subject: [PATCH 81/89] update unittest helper scripts - Added functionality to open HTML report immediately - Added another helper script to automatically generate unittest build folder --- scripts/coverage.py | 7 +++++++ scripts/gen-unittest.sh | 3 +++ 2 files changed, 10 insertions(+) create mode 100755 scripts/gen-unittest.sh diff --git a/scripts/coverage.py b/scripts/coverage.py index 71b6fb03..b5bd7745 100755 --- a/scripts/coverage.py +++ b/scripts/coverage.py @@ -6,6 +6,7 @@ import platform import sys import time import argparse +import webbrowser from typing import List @@ -18,6 +19,10 @@ information how to set up the build folder. def main(): parser = argparse.ArgumentParser(description="Processing arguments for LCOV helper script.") + parser.add_argument( + '-o', '--open', action='store_true', help='Open coverage data in webbrowser' + ) + args = parser.parse_args() build_dir_list = [] if not os.path.isfile('README.md'): @@ -41,6 +46,8 @@ def main(): print("Multiple build directories found!") build_directory = determine_build_dir(build_dir_list) perform_lcov_operation(build_directory) + if os.path.isdir('fsfw-tests_coverage') and args.open: + webbrowser.open('fsfw-tests_coverage/index.html') def check_for_cmake_build_dir(build_dir_dict: list): diff --git a/scripts/gen-unittest.sh b/scripts/gen-unittest.sh new file mode 100755 index 00000000..9ca8c399 --- /dev/null +++ b/scripts/gen-unittest.sh @@ -0,0 +1,3 @@ +#!/bin/sh +mkdir build-Unittest && cd build-Unittest +cmake -DFSFW_BUILD_UNITTESTS=ON -DFSFW_OSAL=host -DCMAKE_BUILD_TYPE=Debug .. From c2bf09d506899d3ef893c0d8932898b158eef23d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 1 Dec 2021 11:04:24 +0100 Subject: [PATCH 82/89] Introducing documentation with Sphinx This PR introduces the generation of documentation based on this excellent blog post: https://devblogs.microsoft.com/cppblog/clear-functional-c-documentation-with-sphinx-breathe-doxygen-cmake/ It combines the tools Sphinx, Doxygen and Breathe to generate good looking HTML documentation conveniently which can be hosted easily. The helper scripts were unified and there is now one helper.py script which can be used to create, build and open both tests and documentation. "./helper.py -h" can be used to get the different options. This PR also contains some smaller fixes which were necessary for the docs to build --- CMakeLists.txt | 18 +- README.md | 18 +- cmake/FindSphinx.cmake | 13 ++ docs/CMakeLists.txt | 66 +++++++ docs/Doxyfile.in | 7 + docs/Makefile | 20 ++ {doc => docs}/README-config.md | 0 {doc => docs}/README-controllers.md | 0 {doc => docs}/README-core.md | 0 {doc => docs}/README-devicehandlers.md | 0 {doc => docs}/README-highlevel.md | 0 {doc => docs}/README-localpools.md | 4 +- {doc => docs}/README-osal.md | 0 {doc => docs}/README-pus.md | 0 docs/api.rst | 16 ++ docs/api/action.rst | 15 ++ docs/api/controller.rst | 16 ++ docs/api/devicehandler.rst | 16 ++ docs/api/event.rst | 6 + docs/api/health.rst | 9 + docs/api/ipc.rst | 9 + docs/api/modes.rst | 10 + docs/api/objectmanager.rst | 30 +++ docs/api/returnvalue.rst | 10 + docs/api/task.rst | 8 + docs/conf.py | 56 ++++++ docs/config.rst | 41 ++++ docs/controllers.rst | 2 + docs/core.rst | 70 +++++++ docs/devicehandlers.rst | 3 + {doc => docs}/doxy/.gitignore | 0 {doc => docs}/doxy/OPUS.doxyfile | 0 docs/getting_started.rst | 115 +++++++++++ docs/highlevel.rst | 149 ++++++++++++++ {doc => docs}/images/PoolArchitecture.png | Bin docs/index.rst | 69 +++++++ docs/localpools.rst | 181 ++++++++++++++++++ docs/make.bat | 35 ++++ docs/osal.rst | 63 ++++++ docs/pus.rst | 2 + misc/defaultcfg/fsfwconfig/CMakeLists.txt | 60 ++++-- .../fsfwconfig/objects/FsfwFactory.cpp | 4 +- scripts/coverage.py | 83 -------- scripts/gen-unittest.sh | 3 - scripts/helper.py | 181 ++++++++++++++++++ .../integration/task/CMakeLists.txt | 2 +- 46 files changed, 1290 insertions(+), 120 deletions(-) create mode 100644 cmake/FindSphinx.cmake create mode 100644 docs/CMakeLists.txt create mode 100644 docs/Doxyfile.in create mode 100644 docs/Makefile rename {doc => docs}/README-config.md (100%) rename {doc => docs}/README-controllers.md (100%) rename {doc => docs}/README-core.md (100%) rename {doc => docs}/README-devicehandlers.md (100%) rename {doc => docs}/README-highlevel.md (100%) rename {doc => docs}/README-localpools.md (98%) rename {doc => docs}/README-osal.md (100%) rename {doc => docs}/README-pus.md (100%) create mode 100644 docs/api.rst create mode 100644 docs/api/action.rst create mode 100644 docs/api/controller.rst create mode 100644 docs/api/devicehandler.rst create mode 100644 docs/api/event.rst create mode 100644 docs/api/health.rst create mode 100644 docs/api/ipc.rst create mode 100644 docs/api/modes.rst create mode 100644 docs/api/objectmanager.rst create mode 100644 docs/api/returnvalue.rst create mode 100644 docs/api/task.rst create mode 100644 docs/conf.py create mode 100644 docs/config.rst create mode 100644 docs/controllers.rst create mode 100644 docs/core.rst create mode 100644 docs/devicehandlers.rst rename {doc => docs}/doxy/.gitignore (100%) rename {doc => docs}/doxy/OPUS.doxyfile (100%) create mode 100644 docs/getting_started.rst create mode 100644 docs/highlevel.rst rename {doc => docs}/images/PoolArchitecture.png (100%) create mode 100644 docs/index.rst create mode 100644 docs/localpools.rst create mode 100644 docs/make.bat create mode 100644 docs/osal.rst create mode 100644 docs/pus.rst delete mode 100755 scripts/coverage.py delete mode 100755 scripts/gen-unittest.sh create mode 100755 scripts/helper.py diff --git a/CMakeLists.txt b/CMakeLists.txt index e78e8929..bb3d48b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,9 @@ set(FSFW_VERSION 2) set(FSFW_SUBVERSION 0) set(FSFW_REVISION 0) +# Add the cmake folder so the FindSphinx module is found +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) + option(FSFW_GENERATE_SECTIONS "Generate function and data sections. Required to remove unused code" ON ) @@ -12,6 +15,7 @@ if(FSFW_GENERATE_SECTIONS) endif() option(FSFW_BUILD_UNITTESTS "Build unittest binary in addition to static library" OFF) +option(FSFW_BUILD_DOCS "Build documentation with Sphinx and Doxygen" OFF) if(FSFW_BUILD_UNITTESTS) option(FSFW_TESTS_GEN_COV "Generate coverage data for unittests" ON) endif() @@ -36,7 +40,9 @@ option(FSFW_ADD_SGP4_PROPAGATOR "Add SGP4 propagator code" OFF) set(LIB_FSFW_NAME fsfw) set(FSFW_TEST_TGT fsfw-tests) +set(FSFW_DUMMY_TGT fsfw-dummy) +project(${LIB_FSFW_NAME}) add_library(${LIB_FSFW_NAME}) if(FSFW_BUILD_UNITTESTS) @@ -59,7 +65,6 @@ if(FSFW_BUILD_UNITTESTS) set(FSFW_CONFIG_PATH tests/src/fsfw_tests/unit/testcfg) configure_file(tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in FSFWConfig.h) configure_file(tests/src/fsfw_tests/unit/testcfg/TestsConfig.h.in tests/TestsConfig.h) - configure_file(tests/src/fsfw_tests/unit/testcfg/OBSWConfig.h.in OBSWConfig.h) project(${FSFW_TEST_TGT} CXX C) add_executable(${FSFW_TEST_TGT}) @@ -147,7 +152,7 @@ else() set(OS_FSFW "host") endif() -if(FSFW_BUILD_UNITTESTS) +if(FSFW_BUILD_UNITTESTS OR FSFW_BUILD_DOCS) configure_file(src/fsfw/FSFW.h.in fsfw/FSFW.h) configure_file(src/fsfw/FSFWVersion.h.in fsfw/FSFWVersion.h) else() @@ -163,6 +168,9 @@ if(FSFW_ADD_HAL) add_subdirectory(hal) endif() add_subdirectory(contrib) +if(FSFW_BUILD_DOCS) + add_subdirectory(docs) +endif() if(FSFW_BUILD_UNITTESTS) if(FSFW_TESTS_GEN_COV) @@ -234,9 +242,11 @@ endif() # The project CMakeLists file has to set the FSFW_CONFIG_PATH and add it. # If this is not given, we include the default configuration and emit a warning. if(NOT FSFW_CONFIG_PATH) - message(WARNING "Flight Software Framework configuration path not set!") set(DEF_CONF_PATH misc/defaultcfg/fsfwconfig) - message(WARNING "Setting default configuration from ${DEF_CONF_PATH} ..") + if(NOT FSFW_BUILD_DOCS) + message(WARNING "Flight Software Framework configuration path not set!") + message(WARNING "Setting default configuration from ${DEF_CONF_PATH} ..") + endif() add_subdirectory(${DEF_CONF_PATH}) set(FSFW_CONFIG_PATH ${DEF_CONF_PATH}) endif() diff --git a/README.md b/README.md index 312bc077..0facfc9a 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ There are some functions like `printChar` which are different depending on the t and need to be implemented by the mission developer. A template configuration folder was provided and can be copied into the project root to have -a starting point. The [configuration section](doc/README-config.md#top) provides more specific +a starting point. The [configuration section](docs/README-config.md#top) provides more specific information about the possible options. ## Adding the library @@ -109,14 +109,14 @@ The `coverage.py` script located in the `script` folder can also be used to do t ## Index -[1. High-level overview](doc/README-highlevel.md#top)
-[2. Core components](doc/README-core.md#top)
-[3. Configuration](doc/README-config.md#top)
-[4. OSAL overview](doc/README-osal.md#top)
-[5. PUS services](doc/README-pus.md#top)
-[6. Device Handler overview](doc/README-devicehandlers.md#top)
-[7. Controller overview](doc/README-controllers.md#top)
-[8. Local Data Pools](doc/README-localpools.md#top)
+[1. High-level overview](docs/README-highlevel.md#top)
+[2. Core components](docs/README-core.md#top)
+[3. Configuration](docs/README-config.md#top)
+[4. OSAL overview](docs/README-osal.md#top)
+[5. PUS services](docs/README-pus.md#top)
+[6. Device Handler overview](docs/README-devicehandlers.md#top)
+[7. Controller overview](docs/README-controllers.md#top)
+[8. Local Data Pools](docs/README-localpools.md#top)
diff --git a/cmake/FindSphinx.cmake b/cmake/FindSphinx.cmake new file mode 100644 index 00000000..4a5b0700 --- /dev/null +++ b/cmake/FindSphinx.cmake @@ -0,0 +1,13 @@ +# Look for an executable called sphinx-build +find_program(SPHINX_EXECUTABLE + NAMES sphinx-build + DOC "Path to sphinx-build executable") + +include(FindPackageHandleStandardArgs) + +# Handle standard arguments to find_package like REQUIRED and QUIET +find_package_handle_standard_args( + Sphinx + "Failed to find sphinx-build executable" + SPHINX_EXECUTABLE +) \ No newline at end of file diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt new file mode 100644 index 00000000..fa5790db --- /dev/null +++ b/docs/CMakeLists.txt @@ -0,0 +1,66 @@ +# This is based on this excellent posting provided by Sy: +# https://devblogs.microsoft.com/cppblog/clear-functional-c-documentation-with-sphinx-breathe-doxygen-cmake/ +find_package(Doxygen REQUIRED) +find_package(Sphinx REQUIRED) + +get_target_property(LIB_FSFW_PUBLIC_HEADER_DIRS ${LIB_FSFW_NAME} INTERFACE_INCLUDE_DIRECTORIES) +# TODO: Add HAL as well +file(GLOB_RECURSE LIB_FSFW_PUBLIC_HEADERS ${PROJECT_SOURCE_DIR}/src/*.h) +file(GLOB_RECURSE RST_DOC_FILES ${PROJECT_SOURCE_DIR}/docs/*.rst) + +set(DOXYGEN_INPUT_DIR ${PROJECT_SOURCE_DIR}/src) +set(DOXYGEN_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/doxygen) +set(DOXYGEN_INDEX_FILE ${DOXYGEN_OUTPUT_DIR}/xml/index.xml) +set(DOXYFILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in) +set(DOXYFILE_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) + +# Replace variables inside @@ with the current values +configure_file(${DOXYFILE_IN} ${DOXYFILE_OUT} @ONLY) + +# Doxygen won't create this for us +file(MAKE_DIRECTORY ${DOXYGEN_OUTPUT_DIR}) + +# Only regenerate Doxygen when the Doxyfile or public headers change +add_custom_command( + OUTPUT ${DOXYGEN_INDEX_FILE} + DEPENDS ${LIB_FSFW_PUBLIC_HEADERS} + COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE_OUT} + MAIN_DEPENDENCY ${DOXYFILE_OUT} ${DOXYFILE_IN} + COMMENT "Generating docs" + VERBATIM +) + +# Nice named target so we can run the job easily +add_custom_target(Doxygen ALL DEPENDS ${DOXYGEN_INDEX_FILE}) + +set(SPHINX_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}) +set(SPHINX_BUILD ${CMAKE_CURRENT_BINARY_DIR}/sphinx) +set(SPHINX_INDEX_FILE ${SPHINX_BUILD}/index.html) + +# Only regenerate Sphinx when: +# - Doxygen has rerun +# - Our doc files have been updated +# - The Sphinx config has been updated +add_custom_command( + OUTPUT ${SPHINX_INDEX_FILE} + COMMAND + ${SPHINX_EXECUTABLE} -b html + # Tell Breathe where to find the Doxygen output + -Dbreathe_projects.fsfw=${DOXYGEN_OUTPUT_DIR}/xml + ${SPHINX_SOURCE} ${SPHINX_BUILD} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS + # Other docs files you want to track should go here (or in some variable) + ${RST_DOC_FILES} + ${DOXYGEN_INDEX_FILE} + MAIN_DEPENDENCY ${SPHINX_SOURCE}/conf.py + COMMENT "Generating documentation with Sphinx" +) + +# Nice named target so we can run the job easily +add_custom_target(Sphinx ALL DEPENDS ${SPHINX_INDEX_FILE}) + +# Add an install target to install the docs +include(GNUInstallDirs) +install(DIRECTORY ${SPHINX_BUILD} +DESTINATION ${CMAKE_INSTALL_DOCDIR}) diff --git a/docs/Doxyfile.in b/docs/Doxyfile.in new file mode 100644 index 00000000..3d01d126 --- /dev/null +++ b/docs/Doxyfile.in @@ -0,0 +1,7 @@ +INPUT = "@DOXYGEN_INPUT_DIR@" + +RECURSIVE = YES + +OUTPUT_DIRECTORY = "@DOXYGEN_OUTPUT_DIR@" + +GENERATE_XML = YES diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 00000000..d4bb2cbb --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/doc/README-config.md b/docs/README-config.md similarity index 100% rename from doc/README-config.md rename to docs/README-config.md diff --git a/doc/README-controllers.md b/docs/README-controllers.md similarity index 100% rename from doc/README-controllers.md rename to docs/README-controllers.md diff --git a/doc/README-core.md b/docs/README-core.md similarity index 100% rename from doc/README-core.md rename to docs/README-core.md diff --git a/doc/README-devicehandlers.md b/docs/README-devicehandlers.md similarity index 100% rename from doc/README-devicehandlers.md rename to docs/README-devicehandlers.md diff --git a/doc/README-highlevel.md b/docs/README-highlevel.md similarity index 100% rename from doc/README-highlevel.md rename to docs/README-highlevel.md diff --git a/doc/README-localpools.md b/docs/README-localpools.md similarity index 98% rename from doc/README-localpools.md rename to docs/README-localpools.md index 96ae2d0a..2ee75189 100644 --- a/doc/README-localpools.md +++ b/docs/README-localpools.md @@ -31,7 +31,9 @@ cohesive pool variables. These sets simply iterator over the list of variables a `read` and `commit` functions of each variable. The following diagram shows the high-level architecture of the local data pools. -
+.. image:: ../misc/logo/FSFW_Logo_V3_bw.png + :alt: FSFW Logo + An example is shown for using the local data pools with a Gyroscope. For example, the following code shows an implementation to access data from a Gyroscope taken diff --git a/doc/README-osal.md b/docs/README-osal.md similarity index 100% rename from doc/README-osal.md rename to docs/README-osal.md diff --git a/doc/README-pus.md b/docs/README-pus.md similarity index 100% rename from doc/README-pus.md rename to docs/README-pus.md diff --git a/docs/api.rst b/docs/api.rst new file mode 100644 index 00000000..d2ee6c69 --- /dev/null +++ b/docs/api.rst @@ -0,0 +1,16 @@ +API +==== + +.. toctree:: + :maxdepth: 4 + + api/objectmanager + api/task + api/ipc + api/returnvalue + api/event + api/modes + api/health + api/action + api/devicehandler + api/controller diff --git a/docs/api/action.rst b/docs/api/action.rst new file mode 100644 index 00000000..31825b89 --- /dev/null +++ b/docs/api/action.rst @@ -0,0 +1,15 @@ +Action Module API +================= + +``ActionHelper`` +----------------- + +.. doxygenclass:: ActionHelper + :members: + +``HasActionsIF`` +----------------- + +.. doxygenclass:: HasActionsIF + :members: + :protected-members: diff --git a/docs/api/controller.rst b/docs/api/controller.rst new file mode 100644 index 00000000..27136be6 --- /dev/null +++ b/docs/api/controller.rst @@ -0,0 +1,16 @@ +Controller API +================= + +``ControllerBase`` +------------------------- + +.. doxygenclass:: ControllerBase + :members: + :protected-members: + +``ExtendedControllerBase`` +----------------------------- + +.. doxygenclass:: ExtendedControllerBase + :members: + :protected-members: diff --git a/docs/api/devicehandler.rst b/docs/api/devicehandler.rst new file mode 100644 index 00000000..f709b640 --- /dev/null +++ b/docs/api/devicehandler.rst @@ -0,0 +1,16 @@ +Device Handler Base API +========================= + +``DeviceHandlerBase`` +----------------------- + +.. doxygenclass:: DeviceHandlerBase + :members: + :protected-members: + +``DeviceHandlerIF`` +----------------------- + +.. doxygenclass:: DeviceHandlerIF + :members: + :protected-members: diff --git a/docs/api/event.rst b/docs/api/event.rst new file mode 100644 index 00000000..7553c963 --- /dev/null +++ b/docs/api/event.rst @@ -0,0 +1,6 @@ +.. _eventapi: + +Event API +============ + +.. doxygenfile:: Event.h diff --git a/docs/api/health.rst b/docs/api/health.rst new file mode 100644 index 00000000..b1d4c1b2 --- /dev/null +++ b/docs/api/health.rst @@ -0,0 +1,9 @@ +Health API +=========== + +``HasHealthIF`` +------------------ + +.. doxygenclass:: HasHealthIF + :members: + :protected-members: diff --git a/docs/api/ipc.rst b/docs/api/ipc.rst new file mode 100644 index 00000000..17a91f00 --- /dev/null +++ b/docs/api/ipc.rst @@ -0,0 +1,9 @@ +IPC Module API +================= + +``MessageQueueIF`` +------------------- + +.. doxygenclass:: MessageQueueIF + :members: + :protected-members: diff --git a/docs/api/modes.rst b/docs/api/modes.rst new file mode 100644 index 00000000..7b6b0dca --- /dev/null +++ b/docs/api/modes.rst @@ -0,0 +1,10 @@ +Modes API +========= + + +``HasModesIF`` +--------------- + +.. doxygenclass:: HasModesIF + :members: + :protected-members: diff --git a/docs/api/objectmanager.rst b/docs/api/objectmanager.rst new file mode 100644 index 00000000..e90deb57 --- /dev/null +++ b/docs/api/objectmanager.rst @@ -0,0 +1,30 @@ +Object Manager API +========================= + +``SystemObject`` +-------------------- + +.. doxygenclass:: SystemObject + :members: + :protected-members: + +``ObjectManager`` +----------------------- + +.. doxygenclass:: ObjectManager + :members: + :protected-members: + +``SystemObjectIF`` +-------------------- + +.. doxygenclass:: SystemObjectIF + :members: + :protected-members: + +``ObjectManagerIF`` +----------------------- + +.. doxygenclass:: ObjectManagerIF + :members: + :protected-members: diff --git a/docs/api/returnvalue.rst b/docs/api/returnvalue.rst new file mode 100644 index 00000000..b0d43916 --- /dev/null +++ b/docs/api/returnvalue.rst @@ -0,0 +1,10 @@ +.. _retvalapi: + +Returnvalue API +================== + +.. doxygenfile:: HasReturnvaluesIF.h + +.. _fwclassids: + +.. doxygenfile:: FwClassIds.h diff --git a/docs/api/task.rst b/docs/api/task.rst new file mode 100644 index 00000000..b218dac1 --- /dev/null +++ b/docs/api/task.rst @@ -0,0 +1,8 @@ +Task API +========= + +``ExecutableObjectIF`` +----------------------- + +.. doxygenclass:: ExecutableObjectIF + :members: diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 00000000..44fd90c4 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,56 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +# import os +# import sys +# sys.path.insert(0, os.path.abspath('.')) + + +# -- Project information ----------------------------------------------------- + +project = 'Flight Software Framework' +copyright = '2021, Institute of Space Systems (IRS)' +author = 'Institute of Space Systems (IRS)' + +# The full version, including alpha/beta/rc tags +release = '2.0.1' + + +# -- General configuration --------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ "breathe" ] + +breathe_default_project = "fsfw" + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'alabaster' + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] \ No newline at end of file diff --git a/docs/config.rst b/docs/config.rst new file mode 100644 index 00000000..ed317aed --- /dev/null +++ b/docs/config.rst @@ -0,0 +1,41 @@ +Configuring the FSFW +===================== + +The FSFW can be configured via the ``fsfwconfig`` folder. A template folder has been provided in +``misc/defaultcfg`` to have a starting point for this. The folder should be added +to the include path. The primary configuration file is the ``FSFWConfig.h`` folder. Some +of the available options will be explained in more detail here. + +Auto-Translation of Events +---------------------------- + +The FSFW allows the automatic translation of events, which allows developers to track triggered +events directly via console output. Using this feature requires: + +1. ``FSFW_OBJ_EVENT_TRANSLATION`` set to 1 in the configuration file. +2. Special auto-generated translation files which translate event IDs and object IDs into + human readable strings. These files can be generated using the + `fsfwgen Python scripts `_. +3. The generated translation files for the object IDs should be named ``translatesObjects.cpp`` + and ``translateObjects.h`` and should be copied to the ``fsfwconfig/objects`` folder +4. The generated translation files for the event IDs should be named ``translateEvents.cpp`` and + ``translateEvents.h`` and should be copied to the ``fsfwconfig/events`` folder + +An example implementations of these translation file generators can be found as part +of the `SOURCE project here `_ +or the `FSFW example `_ + +Configuring the Event Manager +---------------------------------- + +The number of allowed subscriptions can be modified with the following +parameters: + +.. code-block:: cpp + + namespace fsfwconfig { + //! Configure the allocated pool sizes for the event manager. + static constexpr size_t FSFW_EVENTMGMR_MATCHTREE_NODES = 240; + static constexpr size_t FSFW_EVENTMGMT_EVENTIDMATCHERS = 120; + static constexpr size_t FSFW_EVENTMGMR_RANGEMATCHERS = 120; + } diff --git a/docs/controllers.rst b/docs/controllers.rst new file mode 100644 index 00000000..28f57393 --- /dev/null +++ b/docs/controllers.rst @@ -0,0 +1,2 @@ +Controllers +============= diff --git a/docs/core.rst b/docs/core.rst new file mode 100644 index 00000000..ef6f6165 --- /dev/null +++ b/docs/core.rst @@ -0,0 +1,70 @@ +.. _core: + +Core Modules +============= + +The core modules provide the most important functionalities of the Flight Software Framework. + +Clock +------ + +- This is a class of static functions that can be used at anytime +- Leap Seconds must be set if any time conversions from UTC to other times is used + +Object Manager +--------------- + +- Must be created during program startup +- The component which handles all references. All :cpp:class:`SystemObject`\s register at this + component. +- All :cpp:class:`SystemObject`\s needs to have a unique Object ID. Those can be managed like + framework objects. +- A reference to an object can be retrieved by calling the ``get`` function of + :cpp:class:`ObjectManagerIF`. The target type must be specified as a template argument. + A ``nullptr`` check of the returning pointer must be done. This function is based on + run-time type information. + + .. code-block:: cpp + + template T* ObjectManagerIF::get(object_id_t id); + +- A typical way to create all objects on startup is a handing a static produce function to the + ObjectManager on creation. By calling ``ObjectManager::instance()->initialize(produceFunc)`` the + produce function will be called and all :cpp:class:`SystemObject`\s will be initialized + afterwards. + +Event Manager +--------------- + +- Component which allows routing of events +- Other objects can subscribe to specific events, ranges of events or all events of an object. +- Subscriptions can be done during runtime but should be done during initialization +- Amounts of allowed subscriptions can be configured in ``FSFWConfig.h`` + +Health Table +--------------- + +- A component which holds every health state +- Provides a thread safe way to access all health states without the need of message exchanges + +Stores +-------------- + +- The message based communication can only exchange a few bytes of information inside the message + itself. Therefore, additional information can be exchanged with Stores. With this, only the + store address must be exchanged in the message. +- Internally, the FSFW uses an IPC Store to exchange data between processes. For incoming TCs a TC + Store is used. For outgoing TM a TM store is used. +- All of them should use the Thread Safe Class storagemanager/PoolManager + +Tasks +--------- + +There are two different types of tasks: + +- The PeriodicTask just executes objects that are of type ExecutableObjectIF in the order of the + insertion to the Tasks. +- FixedTimeslotTask executes a list of calls in the order of the given list. This is intended for + DeviceHandlers, where polling should be in a defined order. An example can be found in + ``defaultcfg/fsfwconfig/pollingSequence`` folder + diff --git a/docs/devicehandlers.rst b/docs/devicehandlers.rst new file mode 100644 index 00000000..58c2df78 --- /dev/null +++ b/docs/devicehandlers.rst @@ -0,0 +1,3 @@ +Device Handlers +================== + diff --git a/doc/doxy/.gitignore b/docs/doxy/.gitignore similarity index 100% rename from doc/doxy/.gitignore rename to docs/doxy/.gitignore diff --git a/doc/doxy/OPUS.doxyfile b/docs/doxy/OPUS.doxyfile similarity index 100% rename from doc/doxy/OPUS.doxyfile rename to docs/doxy/OPUS.doxyfile diff --git a/docs/getting_started.rst b/docs/getting_started.rst new file mode 100644 index 00000000..069e98cd --- /dev/null +++ b/docs/getting_started.rst @@ -0,0 +1,115 @@ +Getting Started +================ + + +Getting started +---------------- + +The `Hosted FSFW example`_ provides a good starting point and a demo to see the FSFW capabilities. +It is recommended to get started by building and playing around with the demo application. +There are also other examples provided for all OSALs using the popular embedded platforms +Raspberry Pi, Beagle Bone Black and STM32H7. + +Generally, the FSFW is included in a project by providing +a configuration folder, building the static library and linking against it. +There are some functions like ``printChar`` which are different depending on the target architecture +and need to be implemented by the mission developer. + +A template configuration folder was provided and can be copied into the project root to have +a starting point. The [configuration section](docs/README-config.md#top) provides more specific +information about the possible options. + +Adding the library +------------------- + +The following steps show how to add and use FSFW components. It is still recommended to +try out the example mentioned above to get started, but the following steps show how to +add and link against the FSFW library in general. + +1. Add this repository as a submodule + + .. code-block:: console + + git submodule add https://egit.irs.uni-stuttgart.de/fsfw/fsfw.git fsfw + +2. Add the following directive inside the uppermost ``CMakeLists.txt`` file of your project + + .. code-block:: cmake + + add_subdirectory(fsfw) + +3. Make sure to provide a configuration folder and supply the path to that folder with + the `FSFW_CONFIG_PATH` CMake variable from the uppermost `CMakeLists.txt` file. + It is also necessary to provide the `printChar` function. You can find an example + implementation for a hosted build + `here `_. + +4. Link against the FSFW library + + .. code-block:: cmake + + target_link_libraries( PRIVATE fsfw) + + +5. It should now be possible use the FSFW as a static library from the user code. + +Building the unittests +------------------------- + +The FSFW also has unittests which use the `Catch2 library`_. +These are built by setting the CMake option ``FSFW_BUILD_UNITTESTS`` to ``ON`` or `TRUE` +from your project `CMakeLists.txt` file or from the command line. + +The fsfw-tests binary will be built as part of the static library and dropped alongside it. +If the unittests are built, the library and the tests will be built with coverage information by +default. This can be disabled by setting the `FSFW_TESTS_COV_GEN` option to `OFF` or `FALSE`. + +You can use the following commands inside the ``fsfw`` folder to set up the build system + +.. code-block:: console + + mkdir build-tests && cd build-tests + cmake -DFSFW_BUILD_UNITTESTS=ON -DFSFW_OSAL=host .. + + +You can also use ``-DFSFW_OSAL=linux`` on Linux systems. + +Coverage data in HTML format can be generated using the `Code coverage`_ CMake module. +To build the unittests, run them and then generare the coverage data in this format, +the following command can be used inside the build directory after the build system was set up + +.. code-block:: console + + cmake --build . -- fsfw-tests_coverage -j + + +The ``helper.py`` script located in the ``script`` folder can also be used to create, build +and open the unittests conveniently. Try ``helper.py -h`` for more information. + +Building the documentation +---------------------------- + +The FSFW documentation is built using the tools Sphinx, doxygen and breathe based on the +instructions provided in `this blogpost `_. You can set up a +documentation build system using the following commands + +.. code-block:: bash + + mkdir build-docs && cd build-docs + cmake -DFSFW_BUILD_DOCS=ON -DFSFW_OSAL=host .. + +Then you can generate the documentation using + +.. code-block:: bash + + cmake --build . -j + +You can find the generated documentation inside the ``docs/sphinx`` folder inside the build +folder. Simply open the ``index.html`` in the webbrowser of your choice. + +The ``helper.py`` script located in the ``script`` folder can also be used to create, build +and open the documentation conveniently. Try ``helper.py -h`` for more information. + +.. _`Hosted FSFW example`: https://egit.irs.uni-stuttgart.de/fsfw/fsfw-example-hosted +.. _`Catch2 library`: https://github.com/catchorg/Catch2 +.. _`Code coverage`: https://github.com/bilke/cmake-modules/tree/master diff --git a/docs/highlevel.rst b/docs/highlevel.rst new file mode 100644 index 00000000..08f44777 --- /dev/null +++ b/docs/highlevel.rst @@ -0,0 +1,149 @@ +.. _highlevel: + +High-level overview +=================== + +Structure +---------- + +The general structure is driven by the usage of interfaces provided by objects. +The FSFW uses C++11 as baseline. The intention behind this is that this C++ Standard should be +widely available, even with older compilers. +The FSFW uses dynamic allocation during the initialization but provides static containers during runtime. +This simplifies the instantiation of objects and allows the usage of some standard containers. +Dynamic Allocation after initialization is discouraged and different solutions are provided in the +FSFW to achieve that. The fsfw uses run-time type information but exceptions are not allowed. + +Failure Handling +----------------- + +Functions should return a defined :cpp:type:`ReturnValue_t` to signal to the caller that something has +gone wrong. Returnvalues must be unique. For this the function :cpp:func:`HasReturnvaluesIF::makeReturnCode` +or the :ref:`macro MAKE_RETURN_CODE ` can be used. The ``CLASS_ID`` is a unique ID for that type of object. +See the :ref:`FSFW Class IDs file `. The user can add custom ``CLASS_ID``\s via the +``fsfwconfig`` folder. + +OSAL +------------ + +The FSFW provides operation system abstraction layers for Linux, FreeRTOS and RTEMS. +The OSAL provides periodic tasks, message queues, clocks and semaphores as well as mutexes. +The :ref:`OSAL README ` provides more detailed information on provided components +and how to use them. + +Core Components +---------------- + +The FSFW has following core components. More detailed informations can be found in the +:ref:`core component section `: + +1. Tasks: Abstraction for different (periodic) task types like periodic tasks or tasks + with fixed timeslots +2. ObjectManager: This module stores all `SystemObjects` by mapping a provided unique object ID + to the object handles. +3. Static Stores: Different stores are provided to store data of variable size (like telecommands + or small telemetry) in a pool structure without using dynamic memory allocation. + These pools are allocated up front. +4. Clock: This module provided common time related functions +5. EventManager: This module allows routing of events generated by `SystemObjects` +6. HealthTable: A component which stores the health states of objects + +Static IDs in the framework +-------------------------------- + +Some parts of the framework use a static routing address for communication. +An example setup of IDs can be found in the example config in ``misc/defaultcfg/fsfwconfig/objects`` +inside the function ``Factory::setStaticFrameworkObjectIds``. + +Events +---------------- + +Events are tied to objects. EventIds can be generated by calling the +:ref:`macro MAKE_EVENT ` or the function :cpp:func:`event::makeEvent`. +This works analog to the returnvalues. Every object that needs own Event IDs has to get a +unique ``SUBSYSTEM_ID``. Every :cpp:class:`SystemObject` can call +:cpp:func:`SystemObject::triggerEvent` from the parent class. +Therefore, event messages contain the specific EventId and the objectId of the object that +has triggered. + +Internal Communication +------------------------- + +Components communicate mostly via Messages through Queues. +Those queues are created by calling the singleton ``QueueFactory::instance()->create`` which +will create `MessageQueue` instances for the used OSAL. + +External Communication +-------------------------- + +The external communication with the mission control system is mostly up to the user implementation. +The FSFW provides PUS Services which can be used to but don't need to be used. +The services can be seen as a conversion from a TC to a message based communication and back. + +TMTC Communication +~~~~~~~~~~~~~~~~~~~ + +The FSFW provides some components to facilitate TMTC handling via the PUS commands. +For example, a UDP or TCP PUS server socket can be opened on a specific port using the +files located in ``osal/common``. The FSFW example uses this functionality to allow sending +telecommands and receiving telemetry using the +`TMTC commander application `_. + +Simple commands like the PUS Service 17 ping service can be tested by simply running the +``tmtc_client_cli.py`` or ``tmtc_client_gui.py`` utility in +the `example tmtc folder `_ +while the `fsfw_example` application is running. + +More generally, any class responsible for handling incoming telecommands and sending telemetry +can implement the generic ``TmTcBridge`` class located in ``tmtcservices``. Many applications +also use a dedicated polling task for reading telecommands which passes telecommands +to the ``TmTcBridge`` implementation. + +CCSDS Frames, CCSDS Space Packets and PUS +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +If the communication is based on CCSDS Frames and Space Packets, several classes can be used to +distributed the packets to the corresponding services. Those can be found in ``tcdistribution``. +If Space Packets are used, a timestamper has to be provided by the user. +An example can be found in the ``timemanager`` folder, which uses ``CCSDSTime::CDS_short``. + +Device Handlers +-------------------------- + +DeviceHandlers are another important component of the FSFW. The idea is, to have a software +counterpart of every physical device to provide a simple mode, health and commanding interface. +By separating the underlying Communication Interface with +``DeviceCommunicationIF``, a device handler (DH) can be tested on different hardware. +The DH has mechanisms to monitor the communication with the physical device which allow +for FDIR reaction. Device Handlers can be created by implementing ``DeviceHandlerBase``. +A standard FDIR component for the DH will be created automatically but can +be overwritten by the user. More information on DeviceHandlers can be found in the +related [documentation section](doc/README-devicehandlers.md#top). + +Modes and Health +-------------------- + +The two interfaces ``HasModesIF`` and ``HasHealthIF`` provide access for commanding and monitoring +of components. On-board mode management is implement in hierarchy system. + +- Device handlers and controllers are the lowest part of the hierarchy. +- The next layer are assemblies. Those assemblies act as a component which handle + redundancies of handlers. Assemblies share a common core with the top level subsystem components +- The top level subsystem components are used to group assemblies, controllers and device handlers. + For example, a spacecraft can have a atttitude control subsystem and a power subsystem. + +Those assemblies are intended to act as auto-generated components from a database which describes +the subsystem modes. The definitions contain transition and target tables which contain the DH, +Assembly and Controller Modes to be commanded. +Transition tables contain as many steps as needed to reach the mode from any other mode, e.g. a +switch into any higher AOCS mode might first turn on the sensors, than the actuators and the +controller as last component. +The target table is used to describe the state that is checked continuously by the subsystem. +All of this allows System Modes to be generated as Subsystem object as well from the same database. +This System contains list of subsystem modes in the transition and target tables. +Therefore, it allows a modular system to create system modes and easy commanding of those, because +only the highest components must be commanded. + +The health state represents if the component is able to perform its tasks. +This can be used to signal the system to avoid using this component instead of a redundant one. +The on-board FDIR uses the health state for isolation and recovery. diff --git a/doc/images/PoolArchitecture.png b/docs/images/PoolArchitecture.png similarity index 100% rename from doc/images/PoolArchitecture.png rename to docs/images/PoolArchitecture.png diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 00000000..b37c0904 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,69 @@ +.. Flight Software Framework documentation master file, created by + sphinx-quickstart on Tue Nov 30 10:56:03 2021. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Flight Software Framework (FSFW) documentation +================================================ + +.. image:: ../misc/logo/FSFW_Logo_V3_bw.png + :alt: FSFW Logo + +The Flight Software Framework is a C++ Object Oriented Framework for unmanned, +automated systems like Satellites. + +The initial version of the Flight Software Framework was developed during +the Flying Laptop Project by the University of Stuttgart in cooperation +with Airbus Defence and Space GmbH. + +Quick facts +--------------- + +The framework is designed for systems, which communicate with external devices, perform control +loops, receive telecommands and send telemetry, and need to maintain a high level of availability. +Therefore, a mode and health system provides control over the states of the software and the +controlled devices. In addition, a simple mechanism of event based fault detection, isolation and +recovery is implemented as well. + +The FSFW provides abstraction layers for operating systems to provide a uniform operating system +abstraction layer (OSAL). Some components of this OSAL are required internally by the FSFW but is +also very useful for developers to implement the same application logic on different operating +systems with a uniform interface. + +Currently, the FSFW provides the following OSALs: + +- Linux +- Host +- FreeRTOS +- RTEMS + +The recommended hardware is a microprocessor with more than 1 MB of RAM and 1 MB of non-volatile +memory. For reference, current applications use a Cobham Gaisler UT699 (LEON3FT), a +ISISPACE IOBC or a Zynq-7020 SoC. The ``fsfw`` was also successfully run on the +STM32H743ZI-Nucleo board and on a Raspberry Pi and is currently running on the active +satellite mission Flying Laptop. + +Index +------- + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + getting_started + highlevel + core + config + osal + pus + devicehandlers + controllers + localpools + api + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/localpools.rst b/docs/localpools.rst new file mode 100644 index 00000000..d2afd0a0 --- /dev/null +++ b/docs/localpools.rst @@ -0,0 +1,181 @@ +Local Data Pools +========================================= + +The following text is targeted towards mission software developers which would like +to use the local data pools provided by the FSFW to store data like sensor values so they can be +used by other software objects like controllers as well. If a custom class should have a local +pool which can be used by other software objects as well, following steps have to be performed: + +1. Create a ``LocalDataPoolManager`` member object in the custom class +2. Implement the ``HasLocalDataPoolIF`` with specifies the interface between the local pool + manager and the class owning the local pool. + +The local data pool manager is also able to process housekeeping service requests in form +of messages, generate periodic housekeeping packet, generate notification and snapshots of changed +variables and datasets and process notifications and snapshots coming from other objects. +The two former tasks are related to the external interface using telemetry and telecommands (TMTC) +while the later two are related to data consumers like controllers only acting on data change +detected by the data creator instead of checking the data manually each cycle. Two important +framework classes ``DeviceHandlerBase`` and ``ExtendedControllerBase`` already perform the two steps +shown above so the steps required are altered slightly. + +Storing and Accessing pool data +------------------------------------- + +The pool manager is responsible for thread-safe access of the pool data, but the actual +access to the pool data from the point of view of a mission software developer happens via proxy +classes like pool variable classes. These classes store a copy +of the pool variable with the matching datatype and copy the actual data from the local pool +on a ``read`` call. Changed variables can then be written to the local pool with a ``commit`` call. +The ``read`` and ``commit`` calls are thread-safe and can be called concurrently from data creators +and data consumers. Generally, a user will create a dataset class which in turn groups all +cohesive pool variables. These sets simply iterator over the list of variables and call the +``read`` and ``commit`` functions of each variable. The following diagram shows the +high-level architecture of the local data pools. + +.. image:: ../docs/images/PoolArchitecture.png + :alt: Pool Architecture + +An example is shown for using the local data pools with a Gyroscope. +For example, the following code shows an implementation to access data from a Gyroscope taken +from the SOURCE CubeSat project: + +.. code-block:: cpp + + class GyroPrimaryDataset: public StaticLocalDataSet<3 * sizeof(float)> { + public: + /** + * Constructor for data users + * @param gyroId + */ + GyroPrimaryDataset(object_id_t gyroId): + StaticLocalDataSet(sid_t(gyroId, gyrodefs::GYRO_DATA_SET_ID)) { + setAllVariablesReadOnly(); + } + + lp_var_t angVelocityX = lp_var_t(sid.objectId, + gyrodefs::ANGULAR_VELOCITY_X, this); + lp_var_t angVelocityY = lp_var_t(sid.objectId, + gyrodefs::ANGULAR_VELOCITY_Y, this); + lp_var_t angVelocityZ = lp_var_t(sid.objectId, + gyrodefs::ANGULAR_VELOCITY_Z, this); + private: + + friend class GyroHandler; + /** + * Constructor for data creator + * @param hkOwner + */ + GyroPrimaryDataset(HasLocalDataPoolIF* hkOwner): + StaticLocalDataSet(hkOwner, gyrodefs::GYRO_DATA_SET_ID) {} + }; + +There is a public constructor for users which sets all variables to read-only and there is a +constructor for the GyroHandler data creator by marking it private and declaring the ``GyroHandler`` +as a friend class. Both the atittude controller and the ``GyroHandler`` can now +use the same class definition to access the pool variables with ``read`` and ``commit`` semantics +in a thread-safe way. Generally, each class requiring access will have the set class as a member +class. The data creator will also be generally a ``DeviceHandlerBase`` subclass and some additional +steps are necessary to expose the set for housekeeping purposes. + +Using the local data pools in a ``DeviceHandlerBase`` subclass +-------------------------------------------------------------- + +It is very common to store data generated by devices like a sensor into a pool which can +then be used by other objects. Therefore, the ``DeviceHandlerBase`` already has a +local pool. Using the aforementioned example, the ``GyroHandler`` will now have the set class +as a member: + +.. code-block:: cpp + + class GyroHandler: ... { + + public: + ... + private: + ... + GyroPrimaryDataset gyroData; + ... + }; + + +The constructor used for the creators expects the owner class as a parameter, so we initialize +the object in the `GyroHandler` constructor like this: + +.. code-block:: cpp + + GyroHandler::GyroHandler(object_id_t objectId, object_id_t comIF, + CookieIF *comCookie, uint8_t switchId): + DeviceHandlerBase(objectId, comIF, comCookie), switchId(switchId), + gyroData(this) {} + + +We need to assign the set to a reply ID used in the ``DeviceHandlerBase``. +The combination of the ``GyroHandler`` object ID and the reply ID will be the 64-bit structure ID +``sid_t`` and is used to globally identify the set, for example when requesting housekeeping data or +generating update messages. We need to assign our custom set class in some way so that the local +pool manager can access the custom data sets as well. +By default, the ``getDataSetHandle`` will take care of this tasks. The default implementation for a +``DeviceHandlerBase`` subclass will use the internal command map to retrieve +a handle to a dataset from a given reply ID. Therefore, +we assign the set in the ``fillCommandAndReplyMap`` function: + +.. code-block:: cpp + + void GyroHandler::fillCommandAndReplyMap() { + ... + this->insertInCommandAndReplyMap(gyrodefs::GYRO_DATA, 3, &gyroData); + ... + } + + +Now, we need to create the actual pool entries as well, using the ``initializeLocalDataPool`` +function. Here, we also immediately subscribe for periodic housekeeping packets +with an interval of 4 seconds. They are still disabled in this example and can be enabled +with a housekeeping service command. + +.. code-block:: cpp + + ReturnValue_t GyroHandler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap, + LocalDataPoolManager &poolManager) { + localDataPoolMap.emplace(gyrodefs::ANGULAR_VELOCITY_X, + new PoolEntry({0.0})); + localDataPoolMap.emplace(gyrodefs::ANGULAR_VELOCITY_Y, + new PoolEntry({0.0})); + localDataPoolMap.emplace(gyrodefs::ANGULAR_VELOCITY_Z, + new PoolEntry({0.0})); + localDataPoolMap.emplace(gyrodefs::GENERAL_CONFIG_REG42, + new PoolEntry({0})); + localDataPoolMap.emplace(gyrodefs::RANGE_CONFIG_REG43, + new PoolEntry({0})); + + poolManager.subscribeForPeriodicPacket(gyroData.getSid(), false, 4.0, false); + return HasReturnvaluesIF::RETURN_OK; + } + +Now, if we receive some sensor data and converted them into the right format, +we can write it into the pool like this, using a guard class to ensure the set is commited back +in any case: + +.. code-block:: cpp + + PoolReadGuard readHelper(&gyroData); + if(readHelper.getReadResult() == HasReturnvaluesIF::RETURN_OK) { + if(not gyroData.isValid()) { + gyroData.setValidity(true, true); + } + + gyroData.angVelocityX = angularVelocityX; + gyroData.angVelocityY = angularVelocityY; + gyroData.angVelocityZ = angularVelocityZ; + } + + +The guard class will commit the changed data on destruction automatically. + +Using the local data pools in a ``ExtendedControllerBase`` subclass +---------------------------------------------------------------------- + +Coming soon + + diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 00000000..922152e9 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/docs/osal.rst b/docs/osal.rst new file mode 100644 index 00000000..7ac66e47 --- /dev/null +++ b/docs/osal.rst @@ -0,0 +1,63 @@ +.. _osal: + +Operating System Abstraction Layer (OSAL) +============================================ + +Some specific information on the provided OSALs are provided. + +Linux +------- + +This OSAL can be used to compile for Linux host systems like Ubuntu 20.04 or for +embedded Linux targets like the Raspberry Pi. This OSAL generally requires threading support +and real-time functionalities. For most UNIX systems, this is done by adding ``-lrt`` and +``-lpthread`` to the linked libraries in the compilation process. The CMake build support provided +will do this automatically for the ``fsfw`` target. It should be noted that most UNIX systems need +to be configured specifically to allow the real-time functionalities required by the FSFW. + +Hosted OSAL +------------------- + +This is the newest OSAL. Support for Semaphores has not been implemented yet and will propably be +implemented as soon as C++20 with Semaphore support has matured. This OSAL can be used to run the +FSFW on any host system, but currently has only been tested on Windows 10 and Ubuntu 20.04. Unlike +the other OSALs, it uses dynamic memory allocation (e.g. for the message queue implementation). +Cross-platform serial port (USB) support might be added soon. + +FreeRTOS OSAL +------------------ + +FreeRTOS is not included and the developer needs to take care of compiling the FreeRTOS sources and +adding the ``FreeRTOSConfig.h`` file location to the include path. This OSAL has only been tested +extensively with the pre-emptive scheduler configuration so far but it should in principle also be +possible to use a cooperative scheduler. It is recommended to use the `heap_4` allocation scheme. +When using newlib (nano), it is also recommended to add ``#define configUSE_NEWLIB_REENTRANT`` to +the FreeRTOS configuration file to ensure thread-safety. + +When using this OSAL, developers also need to provide an implementation for the +``vRequestContextSwitchFromISR`` function. This has been done because the call to request a context +switch from an ISR is generally located in the ``portmacro.h`` header and is different depending on +the target architecture or device. + +RTEMS OSAL +--------------- + +The RTEMS OSAL was the first implemented OSAL which is also used on the active satellite Flying Laptop. + +TCP/IP socket abstraction +------------------------------ + +The Linux and Host OSAL provide abstraction layers for the socket API. Currently, only UDP sockets +have been imlemented. This is very useful to test TMTC handling either on the host computer +directly (targeting localhost with a TMTC application) or on embedded Linux devices, sending +TMTC packets via Ethernet. + +Example Applications +---------------------- + +There are example applications available for each OSAL + +- `Hosted OSAL `_ +- `Linux OSAL for MCUs `_ +- `FreeRTOS OSAL on the STM32H743ZIT `_ +- `RTEMS OSAL on the STM32H743ZIT `_ diff --git a/docs/pus.rst b/docs/pus.rst new file mode 100644 index 00000000..8dbb2104 --- /dev/null +++ b/docs/pus.rst @@ -0,0 +1,2 @@ +PUS Services +============== diff --git a/misc/defaultcfg/fsfwconfig/CMakeLists.txt b/misc/defaultcfg/fsfwconfig/CMakeLists.txt index 178fc273..3b2064ba 100644 --- a/misc/defaultcfg/fsfwconfig/CMakeLists.txt +++ b/misc/defaultcfg/fsfwconfig/CMakeLists.txt @@ -1,23 +1,49 @@ -target_include_directories(${TARGET_NAME} PRIVATE +if(DEFINED TARGET_NAME) + target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} -) - -target_sources(${TARGET_NAME} PRIVATE - ipc/missionMessageTypes.cpp - pollingsequence/PollingSequenceFactory.cpp - objects/FsfwFactory.cpp -) - -# 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 - 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 - events/translateEvents.cpp + ipc/missionMessageTypes.cpp + pollingsequence/PollingSequenceFactory.cpp + objects/FsfwFactory.cpp ) + + # 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 + 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 + events/translateEvents.cpp + ) + endif() +else() + target_include_directories(${LIB_FSFW_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ) + + target_sources(${LIB_FSFW_NAME} PRIVATE + ipc/missionMessageTypes.cpp + pollingsequence/PollingSequenceFactory.cpp + objects/FsfwFactory.cpp + ) + + # If a special translation file for object IDs exists, compile it. + if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/objects/translateObjects.cpp") + target_sources(${LIB_FSFW_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(${LIB_FSFW_NAME} PRIVATE + events/translateEvents.cpp + ) + endif() endif() diff --git a/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp b/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp index 08ad41ec..5aef4980 100644 --- a/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp +++ b/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include @@ -48,6 +48,6 @@ void Factory::setStaticFrameworkObjectIds() { DeviceHandlerFailureIsolation::powerConfirmationId = objects::NO_OBJECT; - TmPacketStored::timeStamperId = objects::NO_OBJECT; + TmPacketBase::timeStamperId = objects::NO_OBJECT; } diff --git a/scripts/coverage.py b/scripts/coverage.py deleted file mode 100755 index b5bd7745..00000000 --- a/scripts/coverage.py +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -* -"""Small portable helper script to generate LCOV HTML coverage data""" -import os -import platform -import sys -import time -import argparse -import webbrowser -from typing import List - - -"""Copy this helper script into your project folder. It will try to determine a CMake build folder -and then attempt to build your project with coverage information. - -See Unittest documentation at https://egit.irs.uni-stuttgart.de/fsfw/fsfw for more -information how to set up the build folder. -""" -def main(): - - parser = argparse.ArgumentParser(description="Processing arguments for LCOV helper script.") - parser.add_argument( - '-o', '--open', action='store_true', help='Open coverage data in webbrowser' - ) - args = parser.parse_args() - - build_dir_list = [] - if not os.path.isfile('README.md'): - os.chdir('..') - for directory in os.listdir("."): - if os.path.isdir(directory): - os.chdir(directory) - check_for_cmake_build_dir(build_dir_list) - os.chdir("..") - - if len(build_dir_list) == 0: - print("No valid CMake build directory found. Trying to set up hosted build") - build_directory = 'build-Debug-Host' - os.mkdir(build_directory) - os.chdir(build_directory) - os.system('cmake -DFSFW_OSAL=host -DFSFW_BUILD_UNITTESTS=ON ..') - os.chdir('..') - elif len(build_dir_list) == 1: - build_directory = build_dir_list[0] - else: - print("Multiple build directories found!") - build_directory = determine_build_dir(build_dir_list) - perform_lcov_operation(build_directory) - if os.path.isdir('fsfw-tests_coverage') and args.open: - webbrowser.open('fsfw-tests_coverage/index.html') - - -def check_for_cmake_build_dir(build_dir_dict: list): - if os.path.isfile("CMakeCache.txt"): - build_dir_dict.append(os.getcwd()) - - -def perform_lcov_operation(directory): - os.chdir(directory) - os.system("cmake --build . -- fsfw-tests_coverage -j") - - -def determine_build_dir(build_dir_list: List[str]): - build_directory = "" - for idx, directory in enumerate(build_dir_list): - print(f"{idx + 1}: {directory}") - while True: - idx = input("Pick the directory to perform LCOV HTML generation by index: ") - if not idx.isdigit(): - print("Invalid input!") - continue - - idx = int(idx) - if idx > len(build_dir_list) or idx < 1: - print("Invalid input!") - continue - build_directory = build_dir_list[idx - 1] - break - return build_directory - - -if __name__ == "__main__": - main() diff --git a/scripts/gen-unittest.sh b/scripts/gen-unittest.sh deleted file mode 100755 index 9ca8c399..00000000 --- a/scripts/gen-unittest.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -mkdir build-Unittest && cd build-Unittest -cmake -DFSFW_BUILD_UNITTESTS=ON -DFSFW_OSAL=host -DCMAKE_BUILD_TYPE=Debug .. diff --git a/scripts/helper.py b/scripts/helper.py new file mode 100755 index 00000000..5ceff8c4 --- /dev/null +++ b/scripts/helper.py @@ -0,0 +1,181 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -* +"""Small portable helper script to generate test or doc configuration for the +flight software framework +""" +import os +import argparse +import webbrowser +import shutil +import sys +from typing import List + + +UNITTEST_FOLDER_NAME = 'build-tests' +DOCS_FOLDER_NAME = 'build-docs' + + +def main(): + + parser = argparse.ArgumentParser(description="FSFW helper script") + choices = ('docs', 'tests') + parser.add_argument( + 'type', metavar='type', choices=choices, + help=f'Target type. Choices: {choices}' + ) + parser.add_argument( + '-a', '--all', action='store_true', + help='Create, build and open specified type' + ) + parser.add_argument( + '-c', '--create', action='store_true', + help='Create docs or test build configuration' + ) + parser.add_argument( + '-b', '--build', action='store_true', + help='Build the specified type' + ) + parser.add_argument( + '-o', '--open', action='store_true', + help='Open test or documentation data in webbrowser' + ) + + args = parser.parse_args() + if args.all: + args.build = True + args.create = True + args.open = True + elif not args.build and not args.create and not args.open: + print( + 'Please select at least one operation to perform. ' + 'Use helper.py -h for more information' + ) + sys.exit(1) + + # This script can be called from root and from script folder + if not os.path.isfile('README.md'): + os.chdir('..') + build_dir_list = [] + if not args.create: + build_dir_list = build_build_dir_list() + + if args.type == 'tests': + handle_tests_type(args, build_dir_list) + elif args.type == 'docs': + handle_docs_type(args, build_dir_list) + else: + print('Invalid or unknown type') + sys.exit(1) + + +def handle_docs_type(args, build_dir_list: list): + if args.create: + shutil.rmtree(DOCS_FOLDER_NAME) + create_docs_build_cfg() + build_directory = DOCS_FOLDER_NAME + elif len(build_dir_list) == 0: + print('No valid CMake docs build directory found. Trying to set up docs build system') + shutil.rmtree(DOCS_FOLDER_NAME) + create_docs_build_cfg() + build_directory = DOCS_FOLDER_NAME + elif len(build_dir_list) == 1: + build_directory = build_dir_list[0] + else: + print("Multiple build directories found!") + build_directory = determine_build_dir(build_dir_list) + os.chdir(build_directory) + if args.build: + os.system('cmake --build . -j') + if args.open: + if not os.path.isfile('docs/sphinx/index.html'): + print( + "No Sphinx documentation file detected. " + "Try to build it first with the -b argument" + ) + sys.exit(1) + webbrowser.open('docs/sphinx/index.html') + + +def handle_tests_type(args, build_dir_list: list): + if args.create: + shutil.rmtree(UNITTEST_FOLDER_NAME) + create_tests_build_cfg() + build_directory = UNITTEST_FOLDER_NAME + elif len(build_dir_list) == 0: + print( + 'No valid CMake tests build directory found. ' + 'Trying to set up test build system' + ) + create_tests_build_cfg() + build_directory = UNITTEST_FOLDER_NAME + elif len(build_dir_list) == 1: + build_directory = build_dir_list[0] + else: + print("Multiple build directories found!") + build_directory = determine_build_dir(build_dir_list) + os.chdir(build_directory) + if args.build: + perform_lcov_operation(build_directory) + if args.open: + if not os.path.isdir('fsfw-tests_coverage'): + print("No Unittest folder detected. Try to build them first with the -b argument") + sys.exit(1) + webbrowser.open('fsfw-tests_coverage/index.html') + + +def create_tests_build_cfg(): + os.mkdir(UNITTEST_FOLDER_NAME) + os.chdir(UNITTEST_FOLDER_NAME) + os.system('cmake -DFSFW_OSAL=host -DFSFW_BUILD_UNITTESTS=ON ..') + os.chdir('..') + + +def create_docs_build_cfg(): + os.mkdir(DOCS_FOLDER_NAME) + os.chdir(DOCS_FOLDER_NAME) + os.system('cmake -DFSFW_OSAL=host -DFSFW_BUILD_DOCS=ON ..') + os.chdir('..') + + +def build_build_dir_list() -> list: + build_dir_list = [] + for directory in os.listdir("."): + if os.path.isdir(directory): + os.chdir(directory) + build_dir_list = check_for_cmake_build_dir(build_dir_list) + os.chdir("..") + return build_dir_list + + +def check_for_cmake_build_dir(build_dir_list: list) -> list: + if os.path.isfile("CMakeCache.txt"): + build_dir_list.append(os.getcwd()) + return build_dir_list + + +def perform_lcov_operation(directory): + os.chdir(directory) + os.system("cmake --build . -- fsfw-tests_coverage -j") + + +def determine_build_dir(build_dir_list: List[str]): + build_directory = "" + for idx, directory in enumerate(build_dir_list): + print(f"{idx + 1}: {directory}") + while True: + idx = input("Pick the directory: ") + if not idx.isdigit(): + print("Invalid input!") + continue + + idx = int(idx) + if idx > len(build_dir_list) or idx < 1: + print("Invalid input!") + continue + build_directory = build_dir_list[idx - 1] + break + return build_directory + + +if __name__ == "__main__": + main() diff --git a/tests/src/fsfw_tests/integration/task/CMakeLists.txt b/tests/src/fsfw_tests/integration/task/CMakeLists.txt index 0402d093..4cd481bf 100644 --- a/tests/src/fsfw_tests/integration/task/CMakeLists.txt +++ b/tests/src/fsfw_tests/integration/task/CMakeLists.txt @@ -1,3 +1,3 @@ -target_sources(${TARGET_NAME} PRIVATE +target_sources(${LIB_FSFW_NAME} PRIVATE TestTask.cpp ) \ No newline at end of file From fd7581f8babebdd9eeb13cc4a9800dbb80f893a4 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 1 Dec 2021 16:08:28 +0100 Subject: [PATCH 83/89] Added formatting scripts 1. Added .clang-format file which contains information for the clang-format tool on how to format source files 2. Added shell helper script to apply all changes on HAL soures, test sources and primary sources The shell script was not applied yet. This should be done shortly before introducing the release. Also, it might be good idea to provide instructions on how to set up the formatter for Eclipse --- .clang-format | 7 +++++++ scripts/apply-clang-format.sh | 8 ++++++++ 2 files changed, 15 insertions(+) create mode 100644 .clang-format create mode 100755 scripts/apply-clang-format.sh diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..a3cf6a1f --- /dev/null +++ b/.clang-format @@ -0,0 +1,7 @@ +--- +BasedOnStyle: Google +IndentWidth: 2 +--- +Language: Cpp +ColumnWidth: 100 +--- diff --git a/scripts/apply-clang-format.sh b/scripts/apply-clang-format.sh new file mode 100755 index 00000000..36f5ee92 --- /dev/null +++ b/scripts/apply-clang-format.sh @@ -0,0 +1,8 @@ +#!/bin/bash +if [[ ! -f README.md ]]; then + cd .. +fi + +find ./src -iname *.h -o -iname *.cpp | xargs clang-format --style=file -i +find ./hal -iname *.h -o -iname *.cpp | xargs clang-format --style=file -i +find ./tests -iname *.h -o -iname *.cpp | xargs clang-format --style=file -i From 15dddd7fc407fa72d752c76c64279944986b2dc1 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 1 Dec 2021 16:17:27 +0100 Subject: [PATCH 84/89] small README section for formatting --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 312bc077..5feda92c 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,12 @@ cmake --build . -- fsfw-tests_coverage -j The `coverage.py` script located in the `script` folder can also be used to do this conveniently. +## Formatting the sources + +The formatting is done by the `clang-format` tool. The configuration is contained within the +`.clang-format` file in the repository root. As long as `clang-format` is installed, you +can run the `apply-clang-format.sh` helper script to format all source files consistently. + ## Index [1. High-level overview](doc/README-highlevel.md#top)
From df45f02c393bde14b232d1668f6004256615e68a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 3 Dec 2021 14:55:00 +0100 Subject: [PATCH 85/89] script fixes, odd behaviour --- docs/conf.py | 2 +- scripts/helper.py | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 44fd90c4..62b17192 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -53,4 +53,4 @@ html_theme = 'alabaster' # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] \ No newline at end of file +html_static_path = [] \ No newline at end of file diff --git a/scripts/helper.py b/scripts/helper.py index 5ceff8c4..5c5c202b 100755 --- a/scripts/helper.py +++ b/scripts/helper.py @@ -8,6 +8,7 @@ import argparse import webbrowser import shutil import sys +import time from typing import List @@ -70,7 +71,8 @@ def main(): def handle_docs_type(args, build_dir_list: list): if args.create: - shutil.rmtree(DOCS_FOLDER_NAME) + if os.path.exists(DOCS_FOLDER_NAME): + shutil.rmtree(DOCS_FOLDER_NAME) create_docs_build_cfg() build_directory = DOCS_FOLDER_NAME elif len(build_dir_list) == 0: @@ -88,17 +90,21 @@ def handle_docs_type(args, build_dir_list: list): os.system('cmake --build . -j') if args.open: if not os.path.isfile('docs/sphinx/index.html'): - print( - "No Sphinx documentation file detected. " - "Try to build it first with the -b argument" - ) - sys.exit(1) + # try again.. + os.system('cmake --build . -j') + if not os.path.isfile('docs/sphinx/index.html'): + print( + "No Sphinx documentation file detected. " + "Try to build it first with the -b argument" + ) + sys.exit(1) webbrowser.open('docs/sphinx/index.html') def handle_tests_type(args, build_dir_list: list): if args.create: - shutil.rmtree(UNITTEST_FOLDER_NAME) + if os.path.exists(UNITTEST_FOLDER_NAME): + shutil.rmtree(UNITTEST_FOLDER_NAME) create_tests_build_cfg() build_directory = UNITTEST_FOLDER_NAME elif len(build_dir_list) == 0: From 4a5204d6f614053fea03bc10eea18613222000c0 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 6 Dec 2021 14:46:31 +0100 Subject: [PATCH 86/89] small fix for helper script --- scripts/helper.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/helper.py b/scripts/helper.py index 5c5c202b..0bb430ee 100755 --- a/scripts/helper.py +++ b/scripts/helper.py @@ -121,7 +121,7 @@ def handle_tests_type(args, build_dir_list: list): build_directory = determine_build_dir(build_dir_list) os.chdir(build_directory) if args.build: - perform_lcov_operation(build_directory) + perform_lcov_operation(build_directory, False) if args.open: if not os.path.isdir('fsfw-tests_coverage'): print("No Unittest folder detected. Try to build them first with the -b argument") @@ -159,8 +159,9 @@ def check_for_cmake_build_dir(build_dir_list: list) -> list: return build_dir_list -def perform_lcov_operation(directory): - os.chdir(directory) +def perform_lcov_operation(directory: str, chdir: bool): + if chdir: + os.chdir(directory) os.system("cmake --build . -- fsfw-tests_coverage -j") From e952a82b6565292d649260b1441383b1d484f706 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 7 Dec 2021 13:14:57 +0100 Subject: [PATCH 87/89] small tweaks and fixes --- .clang-format | 2 +- scripts/apply-clang-format.sh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.clang-format b/.clang-format index a3cf6a1f..ec53b72b 100644 --- a/.clang-format +++ b/.clang-format @@ -3,5 +3,5 @@ BasedOnStyle: Google IndentWidth: 2 --- Language: Cpp -ColumnWidth: 100 +ColumnLimit: 100 --- diff --git a/scripts/apply-clang-format.sh b/scripts/apply-clang-format.sh index 36f5ee92..27202324 100755 --- a/scripts/apply-clang-format.sh +++ b/scripts/apply-clang-format.sh @@ -3,6 +3,6 @@ if [[ ! -f README.md ]]; then cd .. fi -find ./src -iname *.h -o -iname *.cpp | xargs clang-format --style=file -i -find ./hal -iname *.h -o -iname *.cpp | xargs clang-format --style=file -i -find ./tests -iname *.h -o -iname *.cpp | xargs clang-format --style=file -i +find ./src -iname *.h -o -iname *.cpp -o -iname *.c | xargs clang-format --style=file -i +find ./hal -iname *.h -o -iname *.cpp -o -iname *.c | xargs clang-format --style=file -i +find ./tests -iname *.h -o -iname *.cpp -o -iname *.c | xargs clang-format --style=file -i From 661b7b44e070f20b0162c530ed315abaa8bcbb41 Mon Sep 17 00:00:00 2001 From: David Date: Sun, 12 Dec 2021 18:53:29 +0100 Subject: [PATCH 88/89] improved win32 define --- src/fsfw/globalfunctions/timevalOperations.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fsfw/globalfunctions/timevalOperations.h b/src/fsfw/globalfunctions/timevalOperations.h index db68f330..41f4e52f 100644 --- a/src/fsfw/globalfunctions/timevalOperations.h +++ b/src/fsfw/globalfunctions/timevalOperations.h @@ -2,8 +2,9 @@ #define TIMEVALOPERATIONS_H_ #include +#include -#ifdef WIN32 +#ifdef PLATFORM_WIN #include #else #include From d0c7878da4c7591f199d6bda2fac221005b6a74d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 14 Dec 2021 17:50:23 +0100 Subject: [PATCH 89/89] simplified test controller and added docs gitignore --- docs/.gitignore | 1 + .../integration/controller/TestController.cpp | 173 +----------------- .../integration/controller/TestController.h | 25 +-- 3 files changed, 10 insertions(+), 189 deletions(-) create mode 100644 docs/.gitignore diff --git a/docs/.gitignore b/docs/.gitignore new file mode 100644 index 00000000..a485625d --- /dev/null +++ b/docs/.gitignore @@ -0,0 +1 @@ +/_build diff --git a/tests/src/fsfw_tests/integration/controller/TestController.cpp b/tests/src/fsfw_tests/integration/controller/TestController.cpp index 96da5fe3..8c2c9330 100644 --- a/tests/src/fsfw_tests/integration/controller/TestController.cpp +++ b/tests/src/fsfw_tests/integration/controller/TestController.cpp @@ -1,15 +1,12 @@ #include "TestController.h" -#include "OBSWConfig.h" #include #include #include -TestController::TestController(object_id_t objectId, object_id_t device0, object_id_t device1, +TestController::TestController(object_id_t objectId, object_id_t parentId, size_t commandQueueDepth): - ExtendedControllerBase(objectId, objects::NO_OBJECT, commandQueueDepth), - deviceDataset0(device0), - deviceDataset1(device1) { + ExtendedControllerBase(objectId, parentId, commandQueueDepth) { } TestController::~TestController() { @@ -20,136 +17,15 @@ ReturnValue_t TestController::handleCommandMessage(CommandMessage *message) { } void TestController::performControlOperation() { - /* We will trace vaiables if we received an update notification or snapshots */ -#if OBSW_CONTROLLER_PRINTOUT == 1 - if(not traceVariable) { - return; - } - switch(currentTraceType) { - case(NONE): { - break; - } - case(TRACE_DEV_0_UINT8): { - if(traceCounter == 0) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "Tracing finished" << std::endl; -#else - sif::printInfo("Tracing finished\n"); -#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ - traceVariable = false; - traceCounter = traceCycles; - currentTraceType = TraceTypes::NONE; - break; - } - - PoolReadGuard readHelper(&deviceDataset0.testUint8Var); -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "Tracing device 0 variable 0 (UINT8), current value: " << - static_cast(deviceDataset0.testUint8Var.value) << std::endl; -#else - sif::printInfo("Tracing device 0 variable 0 (UINT8), current value: %d\n", - deviceDataset0.testUint8Var.value); -#endif - traceCounter--; - break; - } - case(TRACE_DEV_0_VECTOR): { - break; - } - - } -#endif /* OBSW_CONTROLLER_PRINTOUT == 1 */ } void TestController::handleChangedDataset(sid_t sid, store_address_t storeId, bool* clearMessage) { - using namespace std; -#if OBSW_CONTROLLER_PRINTOUT == 1 - char const* printout = nullptr; - if(storeId == storeId::INVALID_STORE_ADDRESS) { - printout = "Notification"; - } - else { - printout = "Snapshot"; - } -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "TestController::handleChangedDataset: " << printout << " update from object " - "ID " << setw(8) << setfill('0') << hex << sid.objectId << - " and set ID " << sid.ownerSetId << dec << setfill(' ') << endl; -#else - sif::printInfo("TestController::handleChangedPoolVariable: %s update from object ID 0x%08x and " - "set ID %lu\n", printout, sid.objectId, sid.ownerSetId); -#endif - - if (storeId == storeId::INVALID_STORE_ADDRESS) { - if(sid.objectId == objects::TEST_DEVICE_HANDLER_0) { - PoolReadGuard readHelper(&deviceDataset0.testFloat3Vec); - float floatVec[3]; - floatVec[0] = deviceDataset0.testFloat3Vec.value[0]; - floatVec[1] = deviceDataset0.testFloat3Vec.value[1]; - floatVec[2] = deviceDataset0.testFloat3Vec.value[2]; -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "Current float vector (3) values: [" << floatVec[0] << ", " << - floatVec[1] << ", " << floatVec[2] << "]" << std::endl; -#else - sif::printInfo("Current float vector (3) values: [%f, %f, %f]\n", - floatVec[0], floatVec[1], floatVec[2]); -#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ - } - } -#endif /* OBSW_CONTROLLER_PRINTOUT == 1 */ - - /* We will trace the variables for snapshots and update notifications */ - if(not traceVariable) { - traceVariable = true; - traceCounter = traceCycles; - currentTraceType = TraceTypes::TRACE_DEV_0_VECTOR; - } } void TestController::handleChangedPoolVariable(gp_id_t globPoolId, store_address_t storeId, bool* clearMessage) { - using namespace std; - -#if OBSW_CONTROLLER_PRINTOUT == 1 - char const* printout = nullptr; - if (storeId == storeId::INVALID_STORE_ADDRESS) { - printout = "Notification"; - } - else { - printout = "Snapshot"; - } - -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "TestController::handleChangedPoolVariable: " << printout << " update from object " - "ID 0x" << setw(8) << setfill('0') << hex << globPoolId.objectId << - " and local pool ID " << globPoolId.localPoolId << dec << setfill(' ') << endl; -#else - sif::printInfo("TestController::handleChangedPoolVariable: %s update from object ID 0x%08x and " - "local pool ID %lu\n", printout, globPoolId.objectId, globPoolId.localPoolId); -#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ - - if (storeId == storeId::INVALID_STORE_ADDRESS) { - if(globPoolId.objectId == objects::TEST_DEVICE_HANDLER_0) { - PoolReadGuard readHelper(&deviceDataset0.testUint8Var); -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "Current test variable 0 (UINT8) value: " << static_cast( - deviceDataset0.testUint8Var.value) << std::endl; -#else - sif::printInfo("Current test variable 0 (UINT8) value %d\n", - deviceDataset0.testUint8Var.value); -#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ - } - } -#endif /* OBSW_CONTROLLER_PRINTOUT == 1 */ - - /* We will trace the variables for snapshots and update notifications */ - if(not traceVariable) { - traceVariable = true; - traceCounter = traceCycles; - currentTraceType = TraceTypes::TRACE_DEV_0_UINT8; - } } LocalPoolDataSetBase* TestController::getDataSetHandle(sid_t sid) { @@ -162,50 +38,7 @@ ReturnValue_t TestController::initializeLocalDataPool(localpool::DataPool &local } ReturnValue_t TestController::initializeAfterTaskCreation() { - namespace td = testdevice; - HasLocalDataPoolIF* device0 = ObjectManager::instance()->get( - deviceDataset0.getCreatorObjectId()); - if(device0 == nullptr) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "TestController::initializeAfterTaskCreation: Test device handler 0 " - "handle invalid!" << std::endl; -#else - sif::printWarning("TestController::initializeAfterTaskCreation: Test device handler 0 " - "handle invalid!"); -#endif - return ObjectManagerIF::CHILD_INIT_FAILED; - } - ProvidesDataPoolSubscriptionIF* subscriptionIF = device0->getSubscriptionInterface(); - if(subscriptionIF != nullptr) { - /* For DEVICE_0, we only subscribe for notifications */ - subscriptionIF->subscribeForSetUpdateMessage(td::TEST_SET_ID, getObjectId(), - getCommandQueue(), false); - subscriptionIF->subscribeForVariableUpdateMessage(td::PoolIds::TEST_UINT8_ID, - getObjectId(), getCommandQueue(), false); - } - - - HasLocalDataPoolIF* device1 = ObjectManager::instance()->get( - deviceDataset0.getCreatorObjectId()); - if(device1 == nullptr) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "TestController::initializeAfterTaskCreation: Test device handler 1 " - "handle invalid!" << std::endl; -#else - sif::printWarning("TestController::initializeAfterTaskCreation: Test device handler 1 " - "handle invalid!"); -#endif - } - - subscriptionIF = device1->getSubscriptionInterface(); - if(subscriptionIF != nullptr) { - /* For DEVICE_1, we will subscribe for snapshots */ - subscriptionIF->subscribeForSetUpdateMessage(td::TEST_SET_ID, getObjectId(), - getCommandQueue(), true); - subscriptionIF->subscribeForVariableUpdateMessage(td::PoolIds::TEST_UINT8_ID, - getObjectId(), getCommandQueue(), true); - } - return HasReturnvaluesIF::RETURN_OK; + return ExtendedControllerBase::initializeAfterTaskCreation(); } ReturnValue_t TestController::checkModeCommand(Mode_t mode, Submode_t submode, diff --git a/tests/src/fsfw_tests/integration/controller/TestController.h b/tests/src/fsfw_tests/integration/controller/TestController.h index 475d8703..7d94367d 100644 --- a/tests/src/fsfw_tests/integration/controller/TestController.h +++ b/tests/src/fsfw_tests/integration/controller/TestController.h @@ -8,20 +8,18 @@ class TestController: public ExtendedControllerBase { public: - TestController(object_id_t objectId, object_id_t device0, object_id_t device1, - size_t commandQueueDepth = 10); + TestController(object_id_t objectId, object_id_t parentId, size_t commandQueueDepth = 10); virtual~ TestController(); protected: - testdevice::TestDataSet deviceDataset0; - testdevice::TestDataSet deviceDataset1; - /* Extended Controller Base overrides */ + // Extended Controller Base overrides ReturnValue_t handleCommandMessage(CommandMessage *message) override; void performControlOperation() override; - /* HasLocalDatapoolIF callbacks */ - void handleChangedDataset(sid_t sid, store_address_t storeId, bool* clearMessage) override; - void handleChangedPoolVariable(gp_id_t globPoolId, store_address_t storeId, + // HasLocalDatapoolIF callbacks + virtual void handleChangedDataset(sid_t sid, store_address_t storeId, + bool* clearMessage) override; + virtual void handleChangedPoolVariable(gp_id_t globPoolId, store_address_t storeId, bool* clearMessage) override; LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override; @@ -34,17 +32,6 @@ protected: ReturnValue_t initializeAfterTaskCreation() override; private: - - bool traceVariable = false; - uint8_t traceCycles = 5; - uint8_t traceCounter = traceCycles; - - enum TraceTypes { - NONE, - TRACE_DEV_0_UINT8, - TRACE_DEV_0_VECTOR - }; - TraceTypes currentTraceType = TraceTypes::NONE; };