154 lines
6.1 KiB
C++
154 lines
6.1 KiB
C++
#ifndef MISSION_DEVICES_STARTRACKERIMAGEHELPER_H_
|
|
#define MISSION_DEVICES_STARTRACKERIMAGEHELPER_H_
|
|
|
|
#include "OBSWConfig.h"
|
|
#include "mission/devices/devicedefinitions/StarTrackerDefinitions.h"
|
|
#include "fsfw/action/CommandActionHelper.h"
|
|
#include "fsfw/action/ActionHelper.h"
|
|
#include "fsfw/action/HasActionsIF.h"
|
|
#include "fsfw/action/CommandsActionsIF.h"
|
|
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
|
#include "fsfw/tasks/ExecutableObjectIF.h"
|
|
#include "fsfw/objectmanager/SystemObject.h"
|
|
#include "bsp_q7s/memory/SdCardManager.h"
|
|
#include "linux/fsfwconfig/objects/systemObjectList.h"
|
|
|
|
|
|
/**
|
|
* @brief An object of this class helps to download and upload images from/to the star tracker.
|
|
*
|
|
* @details The star tracker can only receive upload image commands with maximum 1024 bytes of data.
|
|
* Thus this class is used to raed the image from the file system and split the upload
|
|
* procedure into multiple steps.
|
|
* The same applies to downloading images from the star tracker (max. 1024 bytes in image
|
|
* download reply).
|
|
*
|
|
* @author J. Meier
|
|
*/
|
|
class StarTrackerImageHelper : public SystemObject,
|
|
public HasActionsIF,
|
|
public ExecutableObjectIF,
|
|
public HasReturnvaluesIF,
|
|
public CommandsActionsIF {
|
|
public:
|
|
|
|
static const ActionId_t UPLOAD_IMAGE = 0;
|
|
static const ActionId_t DOWNLOAD_IMAGE = 1;
|
|
|
|
StarTrackerImageHelper(object_id_t objectId);
|
|
virtual ~StarTrackerImageHelper();
|
|
|
|
ReturnValue_t performOperation(uint8_t operationCode = 0) override;
|
|
ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
|
|
const uint8_t* data, size_t size);
|
|
MessageQueueId_t getCommandQueue() const;
|
|
ReturnValue_t initialize() override;
|
|
MessageQueueIF* getCommandQueuePtr() override;
|
|
void stepSuccessfulReceived(ActionId_t actionId, uint8_t step) override;
|
|
void stepFailedReceived(ActionId_t actionId, uint8_t step, ReturnValue_t returnCode) override;
|
|
void dataReceived(ActionId_t actionId, const uint8_t* data, uint32_t size) override;
|
|
void completionSuccessfulReceived(ActionId_t actionId) override;
|
|
void completionFailedReceived(ActionId_t actionId, ReturnValue_t returnCode) override;
|
|
|
|
private:
|
|
|
|
static const uint8_t INTERFACE_ID = CLASS_ID::STR_IMG_HELPER;
|
|
|
|
//! [EXPORT] : [COMMENT] Image helper is already executing a command
|
|
static const ReturnValue_t IMAGE_HELPER_BUSY = MAKE_RETURN_CODE(0xA0);
|
|
//! [EXPORT] : [COMMENT] Invalid path to image location
|
|
static const ReturnValue_t NAME_TOO_LONG = MAKE_RETURN_CODE(0xA1);
|
|
//! [EXPORT] : [COMMENT] SD card with image not mounted
|
|
static const ReturnValue_t SD_NOT_MOUNTED = MAKE_RETURN_CODE(0xA2);
|
|
//! [EXPORT] : [COMMENT] Specified image does not exist
|
|
static const ReturnValue_t FILE_NOT_EXISTS = MAKE_RETURN_CODE(0xA3);
|
|
|
|
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::STR_IMAGE_HELPER;
|
|
|
|
//! [EXPORT] : [COMMENT] Try to read image file to upload but the file does not exist.
|
|
//! P1: Refers to the upload step the reading fails
|
|
static const Event IMAGE_FILE_NOT_EXISTS = MAKE_EVENT(0, severity::LOW);
|
|
//! [EXPORT] : [COMMENT] Failed to send command to star tracker handler
|
|
//! P1: Return value of CommandActionHelper::commandAction
|
|
//! P2: Action ID of command to send
|
|
static const Event ACTION_COMMANDING_FAILED = MAKE_EVENT(1, severity::LOW);
|
|
//! [EXPORT] : [COMMENT] Star tracker handler replies with completion or step failure message to upload image command
|
|
//!P1: Return code of execution/step failure message
|
|
//!P2: Failed upload step (equal to number of commands already sent)
|
|
static const Event IMAGE_UPLOAD_FAILED = MAKE_EVENT(2, severity::LOW);
|
|
//! [EXPORT] : [COMMENT] Image upload was successful
|
|
static const Event IMAGE_UPLOAD_FINISHED = MAKE_EVENT(3, severity::LOW);
|
|
|
|
static const uint8_t MAX_RETRIES = 3;
|
|
static const uint32_t QUEUE_SIZE = config::STR_IMG_HELPER_QUEUE_SIZE;
|
|
static const size_t MAX_STR_IMAGE_PATH = 50;
|
|
static const size_t SD_PREFIX_LENGTH = 8;
|
|
// Size of one image part which can be sent per action request
|
|
static const size_t SIZE_IMAGE_PART = 1024;
|
|
// Position (uint32_t) + image data (1024 bytes)
|
|
static const size_t UPLOAD_COMMAND_SIZE = 1028;
|
|
|
|
MessageQueueIF* commandQueue = nullptr;
|
|
|
|
SdCardManager* sdcMan = nullptr;
|
|
|
|
CommandActionHelper commandActionHelper;
|
|
|
|
ActionHelper actionHelper;
|
|
|
|
enum class State: uint8_t {
|
|
IDLE,
|
|
SEND_NEXT_UPLOAD_CMD,
|
|
UPLOAD_LAST,
|
|
COMMAND_EXECUTING
|
|
};
|
|
|
|
State state = State::IDLE;
|
|
|
|
ActionId_t pendingCommand = StarTracker::NONE;
|
|
|
|
uint32_t commandsSent = 0;
|
|
uint32_t remainingCommands = 0;
|
|
// Counts retries when command was rejected by star tracker
|
|
uint8_t retries = 0;
|
|
|
|
// Path and name of active image (either upload or download image)
|
|
std::string imageFile;
|
|
// In case of upload command this variable stores the size of the image to upload
|
|
std::uintmax_t imageSize;
|
|
|
|
void readCommandQueue();
|
|
void doStateMachine();
|
|
|
|
/**
|
|
* @brief Extracts the path and name form the received command.
|
|
*
|
|
* @param data Pointer to received command
|
|
* @param size Size of the received command
|
|
*
|
|
* @details This string defines the image to upload (must be previously written to the SD card).
|
|
* In case of the download image command, this string defines the location and name of
|
|
* the image file to create.
|
|
*/
|
|
ReturnValue_t getImageLocation(const uint8_t* data, size_t size);
|
|
|
|
/**
|
|
* @brief Prepares properties for the upload image command and changes the state to initiate
|
|
* the execution of the upload image command.
|
|
*/
|
|
ReturnValue_t prepareUploadCommand(const uint8_t* data, size_t size);
|
|
|
|
/**
|
|
* @brief Reads part of image from file and sends upload image command to star tracker
|
|
* handler.
|
|
*/
|
|
void commandImageUpload();
|
|
|
|
/**
|
|
* @brief Checks whether the SD card to read from is mounted or not.
|
|
*/
|
|
bool isSdCardMounted(sd::SdCard sdCard);
|
|
};
|
|
|
|
#endif /* MISSION_DEVICES_STARTRACKERIMAGEHELPER_H_ */
|