writing api for scratch buffer

This commit is contained in:
Robin Müller 2021-07-09 16:57:34 +02:00
parent 567cc7eab2
commit 7facfaebff
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
7 changed files with 89 additions and 0 deletions

View File

@ -2,4 +2,5 @@ target_sources(${TARGET_NAME} PRIVATE
FileSystemHandler.cpp FileSystemHandler.cpp
SdCardAccess.cpp SdCardAccess.cpp
SdCardManager.cpp SdCardManager.cpp
scratchApi.cpp
) )

View File

@ -122,6 +122,8 @@ ReturnValue_t SdCardManager::sdCardActive(std::pair<bool, bool>& active) {
} }
sd::SdCard SdCardManager::getPreferredSdCard() const { sd::SdCard SdCardManager::getPreferredSdCard() const {
int result = std::system("xsc_scratch read PREFSD > /tmp/pref_sd.txt");
return preferredSdCard; return preferredSdCard;
} }

View File

@ -0,0 +1,12 @@
#include "scratchApi.h"
ReturnValue_t scratch::writeString(std::string name, std::string string) {
std::ostringstream oss;
oss << "xsc_scratch write " << name << " \"" << string << "\"";
int result = std::system(oss.str().c_str());
if(result != 0) {
utility::handleSystemError(result, "scratch::String");
return HasReturnvaluesIF::RETURN_FAILED;
}
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -0,0 +1,49 @@
#ifndef BSP_Q7S_MEMORY_SCRATCHAPI_H_
#define BSP_Q7S_MEMORY_SCRATCHAPI_H_
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include "linux/utility/utility.h"
#include <iostream>
#include <sstream>
#include <type_traits>
#include <cstdlib>
/**
* @brief API for the scratch buffer
*/
namespace scratch {
namespace {
static size_t counter = 0;
}
template<typename T, class = typename std::enable_if<std::is_unsigned<T>::value>::type>
inline ReturnValue_t writeNumber(std::string name, T num) noexcept {
std::ostringstream oss;
oss << "xsc_scratch write " << name << " " << num;
int result = std::system(oss.str().c_str());
if(result != 0) {
utility::handleSystemError(result, "scratch::writeNumber");
return HasReturnvaluesIF::RETURN_FAILED;
}
return HasReturnvaluesIF::RETURN_OK;
}
template<typename T, class = typename std::enable_if<std::is_unsigned<T>::value>::type>
inline ReturnValue_t readNumber(std::string name, T& num) noexcept {
std::ostringstream oss;
oss << "xsc_scratch read " << name << " > /tmp/scratchro" << counter++;
int result = std::system(oss.str().c_str());
if(result != 0) {
utility::handleSystemError(result, "scratch::writeNumber");
return HasReturnvaluesIF::RETURN_FAILED;
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t writeString(std::string name, std::string string);
}
#endif /* BSP_Q7S_MEMORY_SCRATCHAPI_H_ */

View File

@ -1,4 +1,5 @@
target_sources(${TARGET_NAME} PUBLIC target_sources(${TARGET_NAME} PUBLIC
utility.cpp
) )

11
linux/utility/utility.cpp Normal file
View File

@ -0,0 +1,11 @@
#include "OBSWConfig.h"
#include "FSFWConfig.h"
#include "utility.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
void utility::handleSystemError(int retcode, std::string function) {
#if OBSW_VERBOSE_LEVEL >= 1
sif::warning << function << ": System call failed with code " << retcode;
#endif
}

13
linux/utility/utility.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef LINUX_UTILITY_UTILITY_H_
#define LINUX_UTILITY_UTILITY_H_
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include <string>
namespace utility {
void handleSystemError(int retcode, std::string function);
}
#endif /* LINUX_UTILITY_UTILITY_H_ */