writing api for scratch buffer
This commit is contained in:
parent
567cc7eab2
commit
7facfaebff
@ -2,4 +2,5 @@ target_sources(${TARGET_NAME} PRIVATE
|
||||
FileSystemHandler.cpp
|
||||
SdCardAccess.cpp
|
||||
SdCardManager.cpp
|
||||
scratchApi.cpp
|
||||
)
|
@ -122,6 +122,8 @@ ReturnValue_t SdCardManager::sdCardActive(std::pair<bool, bool>& active) {
|
||||
}
|
||||
|
||||
sd::SdCard SdCardManager::getPreferredSdCard() const {
|
||||
int result = std::system("xsc_scratch read PREFSD > /tmp/pref_sd.txt");
|
||||
|
||||
return preferredSdCard;
|
||||
}
|
||||
|
||||
|
12
bsp_q7s/memory/scratchApi.cpp
Normal file
12
bsp_q7s/memory/scratchApi.cpp
Normal 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;
|
||||
}
|
49
bsp_q7s/memory/scratchApi.h
Normal file
49
bsp_q7s/memory/scratchApi.h
Normal 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_ */
|
@ -1,4 +1,5 @@
|
||||
target_sources(${TARGET_NAME} PUBLIC
|
||||
utility.cpp
|
||||
)
|
||||
|
||||
|
||||
|
11
linux/utility/utility.cpp
Normal file
11
linux/utility/utility.cpp
Normal 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
13
linux/utility/utility.h
Normal 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_ */
|
Loading…
Reference in New Issue
Block a user