fsfw/tmtcservices/TmTcBridge.h

152 lines
4.6 KiB
C
Raw Normal View History

2019-12-26 19:47:46 +01:00
#ifndef FRAMEWORK_TMTCSERVICES_TMTCBRIDGE_H_
#define FRAMEWORK_TMTCSERVICES_TMTCBRIDGE_H_
2020-07-09 19:31:28 +02:00
#include <framework/objectmanager/SystemObject.h>
2019-12-26 19:47:46 +01:00
#include <framework/tmtcservices/AcceptsTelemetryIF.h>
#include <framework/tasks/ExecutableObjectIF.h>
#include <framework/ipc/MessageQueueIF.h>
#include <framework/storagemanager/StorageManagerIF.h>
2020-07-09 19:31:28 +02:00
#include <framework/tmtcservices/AcceptsTelecommandsIF.h>
2019-12-26 19:47:46 +01:00
#include <framework/container/FIFO.h>
2020-07-09 19:31:28 +02:00
#include <framework/tmtcservices/TmTcMessage.h>
2019-12-26 19:47:46 +01:00
class TmTcBridge : public AcceptsTelemetryIF,
2020-07-09 19:31:28 +02:00
public AcceptsTelecommandsIF,
2019-12-26 19:47:46 +01:00
public ExecutableObjectIF,
public HasReturnvaluesIF,
public SystemObject {
public:
static constexpr uint8_t TMTC_RECEPTION_QUEUE_DEPTH = 20;
2020-04-23 10:20:19 +02:00
static constexpr uint8_t LIMIT_STORED_DATA_SENT_PER_CYCLE = 15;
static constexpr uint8_t LIMIT_DOWNLINK_PACKETS_STORED = 20;
static constexpr uint8_t DEFAULT_STORED_DATA_SENT_PER_CYCLE = 5;
static constexpr uint8_t DEFAULT_DOWNLINK_PACKETS_STORED = 10;
2020-07-09 19:31:28 +02:00
TmTcBridge(object_id_t objectId, object_id_t tcDestination,
object_id_t tmStoreId, object_id_t tcStoreId);
2019-12-26 19:47:46 +01:00
virtual ~TmTcBridge();
/**
* 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 RETURN_OK if value was set successfully
* -@c RETURN_FAILED otherwise, stored value stays the same
*/
ReturnValue_t setNumberOfSentPacketsPerCycle(uint8_t sentPacketsPerCycle);
2020-04-23 10:20:19 +02:00
/**
* Set number of packets sent per performOperation().Please note that this
* value must be smaller than MAX_DOWNLINK_PACKETS_STORED
* @param sentPacketsPerCycle
* @return -@c RETURN_OK if value was set successfully
* -@c RETURN_FAILED otherwise, stored value stays the same
*/
ReturnValue_t setMaxNumberOfPacketsStored(uint8_t maxNumberOfPacketsStored);
2020-06-23 10:45:47 +02:00
virtual void registerCommConnect();
virtual void registerCommDisconnect();
/**
* Initializes necessary FSFW components for the TMTC Bridge
2019-12-26 19:47:46 +01:00
* @return
*/
virtual ReturnValue_t initialize() override;
2019-12-26 19:47:46 +01:00
/**
* @brief Handles TMTC reception
2019-12-26 19:47:46 +01:00
*/
virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override;
2019-12-26 19:47:46 +01:00
2020-07-09 19:31:28 +02:00
/** AcceptsTelemetryIF override */
virtual MessageQueueId_t getReportReceptionQueue(
2020-06-23 10:45:47 +02:00
uint8_t virtualChannel = 0) override;
2020-07-09 19:31:28 +02:00
/** AcceptsTelecommandsIF override */
virtual uint16_t getIdentifier() override;
virtual MessageQueueId_t getRequestQueue() override;
2019-12-26 19:47:46 +01:00
protected:
2020-07-09 19:31:28 +02:00
//! 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.
//! TmTcMessage is used to transport messages between tasks.
2020-07-09 19:31:28 +02:00
MessageQueueIF* tmTcReceptionQueue = nullptr;
StorageManagerIF* tmStore = nullptr;
2020-07-09 19:31:28 +02:00
StorageManagerIF* tcStore = nullptr;
//! Used to specify whether communication link is up by default.
bool communicationLinkUp = true;
bool tmStored = false;
2019-12-26 19:47:46 +01:00
/**
2020-04-21 21:48:47 +02:00
* @brief Handle TC reception
* @details
* Default implementation provided, but is empty.
2020-07-09 19:31:28 +02:00
* In most cases, TC reception will be handled in a separate task anyway.
2019-12-26 19:47:46 +01:00
* @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
*/
2020-04-23 10:32:05 +02:00
virtual ReturnValue_t handleTmQueue();
2019-12-26 19:47:46 +01:00
2020-04-23 10:20:19 +02:00
/**
* Send stored data if communication link is active
* @return
*/
virtual ReturnValue_t handleStoredTm();
2019-12-26 19:47:46 +01:00
/**
* Implemented by child class. Perform sending of Telemetry by implementing
* communication drivers or wrappers, e.g. UART communication or lwIP stack.
2019-12-26 19:47:46 +01:00
* @param data
* @param dataLen
* @return
*/
virtual ReturnValue_t sendTm(const uint8_t * data, size_t dataLen) = 0;
2019-12-26 19:47:46 +01:00
/**
* Store data to be sent later if communication link is not up.
* @param message
* @return
*/
2020-04-22 18:20:04 +02:00
virtual ReturnValue_t storeDownlinkData(TmTcMessage * message);
2019-12-26 19:47:46 +01:00
/**
* Print data as hexidecimal array
* @param data
* @param dataLen
*/
void printData(uint8_t * data, size_t dataLen);
2019-12-26 19:47:46 +01:00
2020-06-23 10:45:47 +02:00
/**
* This fifo can be used to store downlink data
* which can not be sent at the moment.
*/
FIFO<store_address_t, LIMIT_DOWNLINK_PACKETS_STORED> tmFifo;
uint8_t sentPacketsPerCycle = DEFAULT_STORED_DATA_SENT_PER_CYCLE;
uint8_t maxNumberOfPacketsStored = DEFAULT_DOWNLINK_PACKETS_STORED;
2019-12-26 19:47:46 +01:00
};
#endif /* FRAMEWORK_TMTCSERVICES_TMTCBRIDGE_H_ */