#ifndef FSFW_TMTCSERVICES_TMTCBRIDGE_H_ #define FSFW_TMTCSERVICES_TMTCBRIDGE_H_ #include "AcceptsTelecommandsIF.h" #include "AcceptsTelemetryIF.h" #include "fsfw/container/DynamicFIFO.h" #include "fsfw/ipc/MessageQueueIF.h" #include "fsfw/objectmanager/SystemObject.h" #include "fsfw/storagemanager/StorageManagerIF.h" #include "fsfw/tasks/ExecutableObjectIF.h" #include "fsfw/tmtcservices/TmTcMessage.h" class TmTcBridge : public AcceptsTelemetryIF, public AcceptsTelecommandsIF, public ExecutableObjectIF, public SystemObject { public: static constexpr uint8_t LIMIT_STORED_DATA_SENT_PER_CYCLE = 15; static constexpr unsigned int LIMIT_DOWNLINK_PACKETS_STORED = 500; static constexpr uint8_t DEFAULT_STORED_DATA_SENT_PER_CYCLE = 5; static constexpr uint8_t DEFAULT_DOWNLINK_PACKETS_STORED = 10; TmTcBridge(const char* name, object_id_t objectId, object_id_t tcDestination, uint32_t msgQueueDepth, object_id_t tmStoreId, object_id_t tcStoreId); ~TmTcBridge() override; /** * Set number of packets sent per performOperation().Please note that this * value must be smaller than MAX_STORED_DATA_SENT_PER_CYCLE * @param sentPacketsPerCycle * @return -@c returnvalue::OK if value was set successfully * -@c returnvalue::FAILED otherwise, stored value stays the same */ ReturnValue_t setNumberOfSentPacketsPerCycle(uint8_t sentPacketsPerCycle); /** * Set number of packets sent per performOperation().Please note that this * value must be smaller than MAX_DOWNLINK_PACKETS_STORED * @param sentPacketsPerCycle * @return -@c returnvalue::OK if value was set successfully * -@c returnvalue::FAILED otherwise, stored value stays the same */ ReturnValue_t setMaxNumberOfPacketsStored(unsigned int maxNumberOfPacketsStored); /** * This will set up the bridge to overwrite old data in the FIFO. * @param overwriteOld */ void setFifoToOverwriteOldData(bool overwriteOld); virtual void registerCommConnect(); virtual void registerCommDisconnect(); /** * Initializes necessary FSFW components for the TMTC Bridge * @return */ ReturnValue_t initialize() override; /** * @brief Handles TMTC reception */ ReturnValue_t performOperation(uint8_t operationCode = 0) override; /** AcceptsTelemetryIF override */ MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel) const override; /** AcceptsTelecommandsIF override */ uint32_t getIdentifier() const override; MessageQueueId_t getRequestQueue() const override; const char* getName() const override; protected: const char* name = ""; //! Cached for initialize function. object_id_t tmStoreId = objects::NO_OBJECT; object_id_t tcStoreId = objects::NO_OBJECT; object_id_t tcDestination = objects::NO_OBJECT; //! Used to send and receive TMTC messages. //! The TmTcMessage class is used to transport messages between tasks. MessageQueueIF* tmTcReceptionQueue = nullptr; StorageManagerIF* tmStore = nullptr; StorageManagerIF* tcStore = nullptr; //! Used to specify whether communication link is up. Will be true //! by default, so telemetry will be handled immediately. bool communicationLinkUp = true; bool tmStored = false; bool warningSwitch = true; bool overwriteOld = true; uint8_t packetSentCounter = 0; /** * @brief Handle TC reception * @details * Default implementation provided, but is empty. * In most cases, TC reception will be handled in a separate task anyway. * @return */ virtual ReturnValue_t handleTc(); /** * Handle Telemetry. Default implementation provided. * Calls sendTm() * @return */ virtual ReturnValue_t handleTm(); /** * Read the TM Queue and send TM if necessary. * Default implementation provided * @return */ virtual ReturnValue_t handleTmQueue(); /** * Send stored data if communication link is active * @return */ virtual ReturnValue_t handleStoredTm(); /** * Implemented by child class. Perform sending of Telemetry by implementing * communication drivers or wrappers, e.g. serial communication or a socket * call. * @param data * @param dataLen * @return */ virtual ReturnValue_t sendTm(const uint8_t* data, size_t dataLen) = 0; /** * Store data to be sent later if communication link is not up. * @param message * @return */ virtual ReturnValue_t storeDownlinkData(TmTcMessage* message); /** * Print data as hexidecimal array * @param data * @param dataLen */ void printData(uint8_t* data, size_t dataLen); /** * This FIFO can be used to store downlink data which can not be sent at the moment. */ DynamicFIFO* tmFifo = nullptr; uint8_t sentPacketsPerCycle = DEFAULT_STORED_DATA_SENT_PER_CYCLE; unsigned int maxNumberOfPacketsStored = DEFAULT_DOWNLINK_PACKETS_STORED; }; #endif /* FSFW_TMTCSERVICES_TMTCBRIDGE_H_ */