timestamp for file creation
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit

This commit is contained in:
Jakob Meier 2021-12-11 11:56:47 +01:00
parent f9581f3100
commit 9c42b861f4
8 changed files with 138 additions and 29 deletions

View File

@ -119,6 +119,7 @@ static const DeviceCommandId_t DOWNLOAD_MATCHED_STAR = 53;
static const DeviceCommandId_t DOWNLOAD_DB_IMAGE = 54;
static const DeviceCommandId_t STOP_IMAGE_LOADER = 55;
static const DeviceCommandId_t RESET_ERROR = 56;
static const DeviceCommandId_t CHANGE_DOWNLOAD_FILE = 57;
static const DeviceCommandId_t NONE = 0xFFFFFFFF;
static const uint32_t VERSION_SET_ID = REQ_VERSION;

View File

@ -96,10 +96,25 @@ ReturnValue_t StarTrackerHandler::executeAction(ActionId_t actionId, MessageQueu
return EXECUTION_FINISHED;
}
case(StarTracker::DOWNLOAD_IMAGE): {
strImageLoader->startImageDownload(std::string(reinterpret_cast<const char*>(data), size));
if (size > MAX_PATH_SIZE) {
return FILE_PATH_TOO_LONG;
}
result = strImageLoader->startImageDownload(
std::string(reinterpret_cast<const char*>(data), size));
if (result != RETURN_OK) {
return result;
}
imageLoaderExecuting = true;
return EXECUTION_FINISHED;
}
case(StarTracker::CHANGE_DOWNLOAD_FILE): {
if (size > MAX_FILE_NAME) {
return FILENAME_TOO_LONG;
}
strImageLoader->setDownloadImageName(
std::string(reinterpret_cast<const char*>(data), size));
return EXECUTION_FINISHED;
}
default:
break;
}
@ -266,8 +281,7 @@ void StarTrackerHandler::fillCommandAndReplyMap() {
* is specified */
this->insertInCommandAndReplyMap(StarTracker::PING_REQUEST, 3, nullptr,
StarTracker::MAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(StarTracker::BOOT, 3, nullptr,
StarTracker::MAX_FRAME_SIZE * 2 + 2);
this->insertInCommandMap(StarTracker::BOOT);
this->insertInCommandAndReplyMap(StarTracker::REQ_VERSION, 3, &versionSet,
StarTracker::MAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(StarTracker::REQ_TIME, 3, &timeSet,
@ -844,8 +858,8 @@ ReturnValue_t StarTrackerHandler::handlePingReply() {
ReturnValue_t result = RETURN_OK;
uint32_t pingId = 0;
const uint8_t* reply = dataLinkLayer.getReply();
uint8_t status = *(reply + 2);
const uint8_t* buffer = reply + 3;
uint8_t status = dataLinkLayer.getStatusField();
const uint8_t* buffer = reply + ACTION_DATA_OFFSET;
size_t size = sizeof(pingId);
SerializeAdapter::deSerialize(&pingId, &buffer, &size, SerializeIF::Endianness::LITTLE);
#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_STARTRACKER == 1

View File

@ -107,8 +107,11 @@ private:
static const ReturnValue_t INVALID_UPLOAD_COMMAND = MAKE_RETURN_CODE(0xAA);
//! [EXPORT] : [COMMENT] Received invalid path string. Exceeds allowed length
static const ReturnValue_t FILE_PATH_TOO_LONG = MAKE_RETURN_CODE(0xAB);
//! [EXPORT] : [COMMENT] Name of file received with command is too long
static const ReturnValue_t FILENAME_TOO_LONG = MAKE_RETURN_CODE(0xAC);
static const size_t MAX_PATH_SIZE = 50;
static const size_t MAX_FILE_NAME = 30;
// position (uint32) + 1024 image data
static const size_t UPLOAD_COMMAND_LEN = 1028;

View File

@ -1,4 +1,5 @@
#include "StrImageLoader.h"
#include "mission/utility/Timestamp.h"
#include <fstream>
#include <filesystem>
@ -66,22 +67,12 @@ void StrImageLoader::setComCookie(CookieIF* comCookie_) {
comCookie = comCookie_;
}
ReturnValue_t StrImageLoader::startImageUpload(std::string image) {
// Check if file is stored on SD card and if associated SD card is mounted
if (image.substr(0, sizeof(SdCardManager::SD_0_MOUNT_POINT))
== std::string(SdCardManager::SD_0_MOUNT_POINT)) {
if (!sdcMan->isSdCardMounted(sd::SLOT_0)) {
sif::warning << "StrImageLoader::getImageLocation: SD card 0 not mounted" << std::endl;
return SD_NOT_MOUNTED;
}
} else if (image.substr(0, sizeof(SdCardManager::SD_1_MOUNT_POINT))
== std::string(SdCardManager::SD_1_MOUNT_POINT)) {
if (!sdcMan->isSdCardMounted(sd::SLOT_0)) {
sif::warning << "StrImageLoader::getImageLocation: SD card 1 not mounted" << std::endl;
return SD_NOT_MOUNTED;
}
ReturnValue_t StrImageLoader::startImageUpload(std::string uploadImage_) {
ReturnValue_t result = checkPath(uploadImage_);
if (result != RETURN_OK) {
return result;
}
uploadImage = image;
uploadImage = uploadImage_;
if(not std::filesystem::exists(uploadImage)) {
return FILE_NOT_EXISTS;
}
@ -91,23 +82,40 @@ ReturnValue_t StrImageLoader::startImageUpload(std::string image) {
return RETURN_OK;
}
void StrImageLoader::startImageDownload(std::string downloadImage_) {
downloadImage = downloadImage_;
ReturnValue_t StrImageLoader::startImageDownload(std::string downloadPath_) {
ReturnValue_t result = checkPath(downloadPath_);
if (result != RETURN_OK) {
return result;
}
if(not std::filesystem::exists(downloadPath_)) {
return PATH_NOT_EXISTS;
}
downloadPath = downloadPath_;
internalState = InternalState::DOWNLOAD_IMAGE;
terminate = false;
semaphore.release();
return RETURN_OK;
}
void StrImageLoader::stopProcess() {
terminate = true;
}
void StrImageLoader::setDownloadImageName(std::string image) {
downloadImage = image;
}
ReturnValue_t StrImageLoader::performImageDownload() {
ReturnValue_t result;
struct DownloadActionRequest downloadReq;
uint32_t size = 0;
uint32_t retries = 0;
std::ofstream file(downloadImage, std::ios_base::app | std::ios_base::out);
Timestamp timestamp;
std::string image = downloadPath + "/" + timestamp.str() + downloadImage ;
std::ofstream file(image, std::ios_base::app | std::ios_base::out);
if(not std::filesystem::exists(image)) {
return FILE_CREATION_FAILED;
}
downloadReq.position = 0;
while(downloadReq.position < LAST_POSITION) {
if (terminate) {
@ -287,3 +295,20 @@ ReturnValue_t StrImageLoader::checkReplyPosition(uint32_t expectedPosition) {
}
return RETURN_OK;
}
ReturnValue_t StrImageLoader::checkPath(std::string name) {
if (name.substr(0, sizeof(SdCardManager::SD_0_MOUNT_POINT))
== std::string(SdCardManager::SD_0_MOUNT_POINT)) {
if (!sdcMan->isSdCardMounted(sd::SLOT_0)) {
sif::warning << "StrImageLoader::checkPath: SD card 0 not mounted" << std::endl;
return SD_NOT_MOUNTED;
}
} else if (name.substr(0, sizeof(SdCardManager::SD_1_MOUNT_POINT))
== std::string(SdCardManager::SD_1_MOUNT_POINT)) {
if (!sdcMan->isSdCardMounted(sd::SLOT_0)) {
sif::warning << "StrImageLoader::checkPath: SD card 1 not mounted" << std::endl;
return SD_NOT_MOUNTED;
}
}
return RETURN_OK;
}

View File

@ -68,8 +68,6 @@ public:
//!P1: Upload/download position for which the request failed
static const Event IMG_LOADER_REQUESTING_MSG_FAILED = MAKE_EVENT(13, severity::LOW);
StrImageLoader(object_id_t objectId);
virtual ~StrImageLoader();
@ -85,18 +83,25 @@ public:
* @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);
ReturnValue_t startImageUpload(std::string uploadImage_);
/**
* @brief Calling this function initiates the download of an image from the star tracker.
*
* @param Name of the image which will be created
*/
void startImageDownload(std::string downloadImage_);
ReturnValue_t startImageDownload(std::string downloadPath_);
/**
* @brief Can be used to interrupt a running upload or download process.
*/
void stopProcess();
/**
* @brief Changes the dafault name of downloaded images
*/
void setDownloadImageName(std::string image);
private:
static const uint8_t INTERFACE_ID = CLASS_ID::STR_IMG_LOADER;
@ -105,6 +110,10 @@ private:
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);
//! [EXPORT] : [COMMENT] Specified path does not exist
static const ReturnValue_t PATH_NOT_EXISTS = MAKE_RETURN_CODE(0xA2);
//! [EXPORT] : [COMMENT] Failed to create download file
static const ReturnValue_t FILE_CREATION_FAILED = MAKE_RETURN_CODE(0xA3);
// Size of one image part which can be sent per action request
static const size_t SIZE_IMAGE_PART = 1024;
@ -132,8 +141,11 @@ private:
// Name including absolute path of image to upload
std::string uploadImage;
// Name including the absolute path of downloaded image
std::string downloadImage;
// Path where the downloaded image will be stored
std::string downloadPath;
// Default name of downloaded image, can be changed via command
std::string downloadImage = "image";
SdCardManager* sdcMan = nullptr;
@ -185,6 +197,13 @@ private:
* @return RETURN_OK if received position matches expected position, otherwise RETURN_FAILED
*/
ReturnValue_t checkReplyPosition(uint32_t expectedPosition);
/**
* @brief Checks if a path points to an sd card and whether the SD card is monuted.
*
* @return SD_NOT_MOUNTED id SD card is not mounted, otherwise RETURN_OK
*/
ReturnValue_t checkPath(std::string name);
};
#endif /* BSP_Q7S_DEVICES_STRIMAGELOADER_H_ */

View File

@ -1,5 +1,6 @@
target_sources(${TARGET_NAME} PUBLIC
TmFunnel.cpp
Timestamp.cpp
)

View File

@ -0,0 +1,19 @@
#include "Timestamp.h"
#include "fsfw/serviceinterface/ServiceInterfacestream.h"
Timestamp::Timestamp() {
ReturnValue_t result = Clock::getDateAndTime(&time);
if (result != RETURN_OK) {
sif::warning << "Timestamp::Timestamp: Failed to get time" << std::endl;
}
}
Timestamp::~Timestamp() {
}
std::string Timestamp::str() {
return std::to_string(time.year) + "-" + std::to_string(time.month) + "-"
+ std::to_string(time.day) + "--" + std::to_string(time.hour) + "-"
+ std::to_string(time.minute) + "-" + std::to_string(time.second) + "-";
}

View File

@ -0,0 +1,27 @@
#ifndef MISSION_UTILITY_TIMESTAMP_H_
#define MISSION_UTILITY_TIMESTAMP_H_
#include <string>
#include "fsfw/timemanager/Clock.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
/**
* @brief This class generates timestamps for files.
*
* @author J. Meier
*/
class Timestamp : public HasReturnvaluesIF {
public:
Timestamp();
virtual ~Timestamp();
/**
* @brief Returns the timestamp string
*/
std::string str();
private:
Clock::TimeOfDay_t time;
};
#endif /* MISSION_UTILITY_TIMESTAMP_H_ */