fsfw/tmtcservices/TmTcBridge.h

163 lines
4.9 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-08-26 14:55:27 +02:00
2020-08-18 13:09:15 +02:00
#include "../objectmanager/SystemObject.h"
#include "../tmtcservices/AcceptsTelemetryIF.h"
#include "../tasks/ExecutableObjectIF.h"
#include "../ipc/MessageQueueIF.h"
#include "../storagemanager/StorageManagerIF.h"
#include "../tmtcservices/AcceptsTelecommandsIF.h"
2020-08-26 14:55:27 +02:00
#include "../container/DynamicFIFO.h"
2020-08-18 13:09:15 +02:00
#include "../tmtcservices/TmTcMessage.h"
2019-12-26 19:47:46 +01:00
class TmTcBridge : public AcceptsTelemetryIF,
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-08 15:06:46 +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-08-26 14:55:27 +02:00
/**
* This will set up the bridge to overwrite old data in the FIFO.
* @param overwriteOld
*/
void setFifoToOverwriteOldData(bool overwriteOld);
2020-06-23 10:47:31 +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
*/
2020-06-23 10:47:31 +02:00
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
*/
2020-06-23 10:47:31 +02:00
virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override;
2019-12-26 19:47:46 +01:00
/** AcceptsTelemetryIF override */
virtual MessageQueueId_t getReportReceptionQueue(
2020-06-23 10:47:31 +02:00
uint8_t virtualChannel = 0) override;
/** AcceptsTelecommandsIF override */
virtual uint16_t getIdentifier() override;
virtual MessageQueueId_t getRequestQueue() override;
2019-12-26 19:47:46 +01:00
protected:
2020-07-08 15:06:46 +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.
2020-07-09 19:41:52 +02:00
//! The TmTcMessage class is used to transport messages between tasks.
MessageQueueIF* tmTcReceptionQueue = nullptr;
2020-07-08 15:06:46 +02:00
StorageManagerIF* tmStore = nullptr;
2020-07-08 15:06:46 +02:00
StorageManagerIF* tcStore = nullptr;
2020-07-09 19:41:52 +02:00
//! Used to specify whether communication link is up. Will be true
//! by default, so telemetry will be handled immediately.
2020-07-08 15:06:46 +02:00
bool communicationLinkUp = true;
bool tmStored = false;
2020-08-26 14:55:27 +02:00
bool overwriteOld = true;
uint8_t packetSentCounter = 0;
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.
* 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();
/**
2020-07-09 19:41:52 +02:00
* Read the TM Queue and send TM if necessary.
* Default implementation provided
2019-12-26 19:47:46 +01:00
* @return
*/
2020-04-23 10:20:19 +02:00
virtual ReturnValue_t handleTmQueue();
/**
* 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
2020-07-09 19:41:52 +02:00
* communication drivers or wrappers, e.g. serial communication or a socket
* call.
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-04-23 12:47:59 +02:00
/**
* This fifo can be used to store downlink data
* which can not be sent at the moment.
*/
2020-08-26 14:55:27 +02:00
DynamicFIFO<store_address_t>* tmFifo = nullptr;
2020-04-23 12:47:59 +02:00
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_ */