eive-obsw/bsp_q7s/devices/StrImageLoader.h

104 lines
4.0 KiB
C
Raw Normal View History

2021-11-30 16:01:02 +01:00
#ifndef BSP_Q7S_DEVICES_STRIMAGELOADER_H_
#define BSP_Q7S_DEVICES_STRIMAGELOADER_H_
#include <string>
#include "fsfw/osal/linux/BinarySemaphore.h"
#include "bsp_q7s/memory/SdCardManager.h"
2021-12-02 08:05:33 +01:00
#include "bsp_q7s/devices/ArcsecDatalinkLayer.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
2021-11-30 16:01:02 +01:00
/**
* @brief An object of this class runs in a separate task and is responsible for uploading and
* downloading images to/from the star tracker. This is required because uploading and
* downloading via the star tracker handler takes a lot of time because each upload or
* download packet can transport a maximum of 1024 bytes.
*/
2021-12-02 08:05:33 +01:00
class StrImageLoader: public SystemObject, public ExecutableObjectIF, public HasReturnvaluesIF {
2021-11-30 16:01:02 +01:00
public:
2021-12-02 08:05:33 +01:00
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::STR_IMAGE_LOADER;
//! [EXPORT] : [COMMENT] Try to upload image but specified image does not exist
static const Event IMAGE_FILE_NOT_EXISTS = MAKE_EVENT(0, severity::LOW);
//! [EXPORT] : [COMMENT] Sending image upload packet to star tracker failed
//!P1: Return code of communication interface sendMessage function
//!P2: Position of upload packet for which the transmission failed
static const Event SENDING_UPLOAD_PACKET_FAILED = MAKE_EVENT(1, severity::LOW);
//! [EXPORT] : [COMMENT] Communication interface requesting reply failed
//!P1: Return code of failed request
//!P1: Upload position for which the request failed
static const Event UPLOAD_REQUESTING_MSG_FAILED = MAKE_EVENT(2, severity::LOW);
//! [EXPORT] : [COMMENT] Uploading image to star tracker was successful
static const Event IMAGE_UPLOAD_SUCCESSFUL = MAKE_EVENT(3, severity::LOW);
//! [EXPORT] : [COMMENT] Failed to read communication interface reply data
//!P1: Return code of failed communication interface read call
//!P1: Upload position for which the read call failed
static const Event UPLOAD_READING_REPLY_FAILED = MAKE_EVENT(3, severity::LOW);
//! [EXPORT] : [COMMENT] Unexpected stop of decoding sequence
//!P1: Return code of failed communication interface read call
//!P1: Upload position for which the read call failed
static const Event UPLOAD_COM_ERROR = MAKE_EVENT(4, severity::LOW);
2021-11-30 16:01:02 +01:00
StrImageLoader(object_id_t objectId);
virtual ~StrImageLoader();
ReturnValue_t performOperation(uint8_t operationCode = 0) override;
void setComIF(DeviceCommunicationIF* communicationInterface_);
void setComCookie(CookieIF* comCookie_);
2021-12-02 08:05:33 +01:00
/**
* @brief Starts sequence to upload image to star tracker
*
* @param image Name including absolute path if to image to upload. Must be previously
* transferred to the OBC with the CFDP protocoll.
*/
ReturnValue_t startImageUpload(std::string image);
2021-11-30 16:01:02 +01:00
private:
static const uint8_t INTERFACE_ID = CLASS_ID::STR_IMG_LOADER;
//! [EXPORT] : [COMMENT] SD card specified in path string not mounted
static const ReturnValue_t SD_NOT_MOUNTED = MAKE_RETURN_CODE(0xA0);
//! [EXPORT] : [COMMENT] Specified file does not exist on filesystem
static const ReturnValue_t FILE_NOT_EXISTS = MAKE_RETURN_CODE(0xA1);
2021-12-02 08:05:33 +01:00
// Size of one image part which can be sent per action request
static const size_t SIZE_IMAGE_PART = 1024;
2021-11-30 16:01:02 +01:00
enum class InternalState {
IDLE,
UPLOAD_IMAGE,
DOWNLOAD_IMAGE
};
InternalState internalState = InternalState::IDLE;
2021-12-02 08:05:33 +01:00
ArcsecDatalinkLayer datalinkLayer;
2021-11-30 16:01:02 +01:00
BinarySemaphore semaphore;
// Absolute path and name to image to upload
std::string uploadImage;
SdCardManager* sdcMan = nullptr;
/**
* Communication object responsible for low level access of star tracker
* Must be set by star tracker handler
*/
DeviceCommunicationIF * communicationInterface = nullptr;
2021-12-02 08:05:33 +01:00
// Communication cookie. Must be set by the star tracker handler
CookieIF* comCookie = nullptr;
/**
* @brief Performs image uploading
*/
ReturnValue_t uploadImage();
2021-11-30 16:01:02 +01:00
};
#endif /* BSP_Q7S_DEVICES_STRIMAGELOADER_H_ */