Update before changing history #55
@ -1,10 +1,13 @@
|
|||||||
#include <bsp_q7s/memory/SdCardManager.h>
|
|
||||||
#include "Q7STestTask.h"
|
#include "Q7STestTask.h"
|
||||||
|
|
||||||
|
#include "bsp_q7s/memory/SdCardManager.h"
|
||||||
|
#include "bsp_q7s/memory/scratchApi.h"
|
||||||
|
|
||||||
#include "fsfw/timemanager/Stopwatch.h"
|
#include "fsfw/timemanager/Stopwatch.h"
|
||||||
#include "fsfw/tasks/TaskFactory.h"
|
#include "fsfw/tasks/TaskFactory.h"
|
||||||
|
|
||||||
#include "bsp_q7s/memory/scratchApi.h"
|
#include "test/DummyParameter.h"
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -16,16 +19,9 @@ Q7STestTask::Q7STestTask(object_id_t objectId): TestTask(objectId) {
|
|||||||
|
|
||||||
ReturnValue_t Q7STestTask::performOneShotAction() {
|
ReturnValue_t Q7STestTask::performOneShotAction() {
|
||||||
//sdCardTests();
|
//sdCardTests();
|
||||||
testScratchApi();
|
//testScratchApi();
|
||||||
Stopwatch stopwatch;
|
//testJsonLibDirect();
|
||||||
// for convenience
|
testDummyParams();
|
||||||
using json = nlohmann::json;
|
|
||||||
json helloTest;
|
|
||||||
// add a number that is stored as double (note the implicit conversion of j to an object)
|
|
||||||
helloTest["pi"] = 3.141;
|
|
||||||
std::string mntPrefix = SdCardManager::instance()->getCurrentMountPrefix();
|
|
||||||
std::ofstream o("/mnt/sd0/pretty.json");
|
|
||||||
o << std::setw(4) << helloTest << std::endl;
|
|
||||||
return TestTask::performOneShotAction();
|
return TestTask::performOneShotAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,3 +72,42 @@ void Q7STestTask::testScratchApi() {
|
|||||||
sif::debug << "Q7STestTask::scratchApiTest: Reading number failed" << std::endl;
|
sif::debug << "Q7STestTask::scratchApiTest: Reading number failed" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Q7STestTask::testJsonLibDirect() {
|
||||||
|
Stopwatch stopwatch;
|
||||||
|
// for convenience
|
||||||
|
using json = nlohmann::json;
|
||||||
|
json helloTest;
|
||||||
|
// add a number that is stored as double (note the implicit conversion of j to an object)
|
||||||
|
helloTest["pi"] = 3.141;
|
||||||
|
std::string mntPrefix = SdCardManager::instance()->getCurrentMountPrefix();
|
||||||
|
std::string fileName = mntPrefix + "/pretty.json";
|
||||||
|
std::ofstream o(fileName);
|
||||||
|
o << std::setw(4) << helloTest << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Q7STestTask::testDummyParams() {
|
||||||
|
std::string mntPrefix = SdCardManager::instance()->getCurrentMountPrefix();
|
||||||
|
DummyParameter param(mntPrefix, "dummy_json.txt");
|
||||||
|
param.printKeys();
|
||||||
|
param.print();
|
||||||
|
if(not param.getJsonFileExists()) {
|
||||||
|
param.writeJsonFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t result = param.readJsonFile();
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
param.setValue(DummyParameter::DUMMY_KEY_PARAM_1, 3);
|
||||||
|
param.setValue(DummyParameter::DUMMY_KEY_PARAM_2, "blirb");
|
||||||
|
|
||||||
|
param.writeJsonFile();
|
||||||
|
param.print();
|
||||||
|
|
||||||
|
int test = param.getValue<int>(DummyParameter::DUMMY_KEY_PARAM_1);
|
||||||
|
std::string test2 = param.getValue<std::string>(DummyParameter::DUMMY_KEY_PARAM_2);
|
||||||
|
sif::info << "Test value (3 expected): " << test << std::endl;
|
||||||
|
sif::info << "Test value 2 (\"blirb\" expected): " << test2 << std::endl;
|
||||||
|
}
|
||||||
|
@ -13,6 +13,8 @@ private:
|
|||||||
void fileTests();
|
void fileTests();
|
||||||
|
|
||||||
void testScratchApi();
|
void testScratchApi();
|
||||||
|
void testJsonLibDirect();
|
||||||
|
void testDummyParams();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
8
bsp_q7s/core/ParameterHandler.cpp
Normal file
8
bsp_q7s/core/ParameterHandler.cpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include "ParameterHandler.h"
|
||||||
|
|
||||||
|
ParameterHandler::ParameterHandler(std::string mountPrefix): mountPrefix(mountPrefix) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParameterHandler::setMountPrefix(std::string prefix) {
|
||||||
|
mountPrefix = prefix;
|
||||||
|
}
|
22
bsp_q7s/core/ParameterHandler.h
Normal file
22
bsp_q7s/core/ParameterHandler.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef BSP_Q7S_CORE_PARAMETERHANDLER_H_
|
||||||
|
#define BSP_Q7S_CORE_PARAMETERHANDLER_H_
|
||||||
|
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class ParameterHandler {
|
||||||
|
public:
|
||||||
|
ParameterHandler(std::string mountPrefix);
|
||||||
|
|
||||||
|
void setMountPrefix(std::string prefix);
|
||||||
|
|
||||||
|
void setUpDummyParameter();
|
||||||
|
private:
|
||||||
|
std::string mountPrefix;
|
||||||
|
DummyParameter dummyParam;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BSP_Q7S_CORE_PARAMETERHANDLER_H_ */
|
@ -3,8 +3,7 @@ if(NOT DEFINED ENV{Q7S_SYSROOT})
|
|||||||
# Sysroot has not been cached yet and was not set in environment either
|
# Sysroot has not been cached yet and was not set in environment either
|
||||||
if(NOT DEFINED SYSROOT_PATH)
|
if(NOT DEFINED SYSROOT_PATH)
|
||||||
message(FATAL_ERROR
|
message(FATAL_ERROR
|
||||||
"Define the Q7S_ROOTFS variable to "
|
"Define the Q7S_ROOTFS variable to point to the Q7S rootfs."
|
||||||
"point to the raspbian rootfs."
|
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
|
33
cmake/scripts/Q7S/ninja_release_cfg.sh
Executable file
33
cmake/scripts/Q7S/ninja_release_cfg.sh
Executable file
@ -0,0 +1,33 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
counter=0
|
||||||
|
while [ ${counter} -lt 5 ]
|
||||||
|
do
|
||||||
|
cd ..
|
||||||
|
if [ -f "cmake_build_config.py" ];then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
counter=$((counter=counter + 1))
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "${counter}" -ge 5 ];then
|
||||||
|
echo "cmake_build_config.py not found in upper directories!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
os_fsfw="linux"
|
||||||
|
tgt_bsp="arm/q7s"
|
||||||
|
build_dir="build-Debug-Q7S"
|
||||||
|
build_generator="Ninja"
|
||||||
|
if [ "${OS}" = "Windows_NT" ]; then
|
||||||
|
python="py"
|
||||||
|
# Could be other OS but this works for now.
|
||||||
|
else
|
||||||
|
python="python3"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Running command (without the leading +):"
|
||||||
|
set -x # Print command
|
||||||
|
${python} cmake_build_config.py -o "${os_fsfw}" -g "${build_generator}" -b "release" -t "${tgt_bsp}" \
|
||||||
|
-l"${build_dir}"
|
||||||
|
# set +x
|
||||||
|
|
@ -1,3 +1,4 @@
|
|||||||
add_subdirectory(core)
|
add_subdirectory(core)
|
||||||
add_subdirectory(devices)
|
add_subdirectory(devices)
|
||||||
add_subdirectory(utility)
|
add_subdirectory(utility)
|
||||||
|
add_subdirectory(memory)
|
||||||
|
5
mission/memory/CMakeLists.txt
Normal file
5
mission/memory/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
target_sources(${TARGET_NAME} PUBLIC
|
||||||
|
NVMParameterBase.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
|
50
mission/memory/NVMParameterBase.cpp
Normal file
50
mission/memory/NVMParameterBase.cpp
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#include "NVMParameterBase.h"
|
||||||
|
#include "fsfw/memory/HasFileSystemIF.h"
|
||||||
|
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
NVMParameterBase::NVMParameterBase(std::string fullName): fullName(fullName) {
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t NVMParameterBase::readJsonFile() {
|
||||||
|
if(std::filesystem::exists(fullName)) {
|
||||||
|
// Read JSON file content into object
|
||||||
|
std::ifstream i(fullName);
|
||||||
|
i >> json;
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
return HasFileSystemIF::FILE_DOES_NOT_EXIST;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t NVMParameterBase::writeJsonFile() {
|
||||||
|
std::ofstream o(fullName);
|
||||||
|
o << std::setw(4) << json;
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NVMParameterBase::setFullName(std::string fullName) {
|
||||||
|
this->fullName = fullName;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string NVMParameterBase::getFullName() const {
|
||||||
|
return fullName;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NVMParameterBase::getJsonFileExists() {
|
||||||
|
return std::filesystem::exists(fullName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NVMParameterBase::printKeys() const {
|
||||||
|
sif::info << "Printing keys for JSON file " << fullName << std::endl;
|
||||||
|
for(const auto& key: keys) {
|
||||||
|
sif::info << key << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void NVMParameterBase::print() const {
|
||||||
|
sif::info << "Printing JSON file " << fullName << std::endl;
|
||||||
|
for(const auto& key: keys) {
|
||||||
|
sif::info << key << ": " << json[key] << std::endl;
|
||||||
|
}
|
||||||
|
}
|
69
mission/memory/NVMParameterBase.h
Normal file
69
mission/memory/NVMParameterBase.h
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
#ifndef BSP_Q7S_CORE_NVMPARAMS_NVMPARAMIF_H_
|
||||||
|
#define BSP_Q7S_CORE_NVMPARAMS_NVMPARAMIF_H_
|
||||||
|
|
||||||
|
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||||
|
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <string>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
|
class NVMParameterBase {
|
||||||
|
public:
|
||||||
|
virtual~ NVMParameterBase() {}
|
||||||
|
|
||||||
|
NVMParameterBase(std::string fullName);
|
||||||
|
|
||||||
|
bool getJsonFileExists();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns RETURN_OK on successfull read and HasFileSystemIF::FILE_DOES_NOT_EXIST if
|
||||||
|
* file does not exist yet.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t readJsonFile();
|
||||||
|
|
||||||
|
virtual ReturnValue_t writeJsonFile();
|
||||||
|
|
||||||
|
void setFullName(std::string fullName);
|
||||||
|
std::string getFullName() const;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
ReturnValue_t insertValue(std::string key, T value);
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
ReturnValue_t setValue(std::string key, T value);
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T getValue(std::string key) const;
|
||||||
|
|
||||||
|
void printKeys() const;
|
||||||
|
void print() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
nlohmann::json json;
|
||||||
|
std::vector<std::string> keys;
|
||||||
|
std::string fullName;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline ReturnValue_t NVMParameterBase::insertValue(std::string key, T value) {
|
||||||
|
// Check whether key already exists. If it does not, insert it
|
||||||
|
if (std::find(keys.begin(), keys.end(), key) == keys.end()) {
|
||||||
|
keys.push_back(key);
|
||||||
|
}
|
||||||
|
json[key] = value;
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline ReturnValue_t NVMParameterBase::setValue(std::string key, T value) {
|
||||||
|
json[key] = value;
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline T NVMParameterBase::getValue(std::string key) const {
|
||||||
|
return json[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* BSP_Q7S_CORE_NVMPARAMS_NVMPARAMIF_H_ */
|
1
test/CMakeLists.txt
Normal file
1
test/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
add_subdirectory(testtasks)
|
26
test/DummyParameter.h
Normal file
26
test/DummyParameter.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef BSP_Q7S_CORE_NVMPARAMS_PARAMETERDEFINITIONS_H_
|
||||||
|
#define BSP_Q7S_CORE_NVMPARAMS_PARAMETERDEFINITIONS_H_
|
||||||
|
|
||||||
|
#include "mission/memory/NVMParameterBase.h"
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
|
class DummyParameter: public NVMParameterBase {
|
||||||
|
public:
|
||||||
|
static constexpr char DUMMY_KEY_PARAM_1[] = "dummy1";
|
||||||
|
static constexpr char DUMMY_KEY_PARAM_2[] = "dummy2";
|
||||||
|
|
||||||
|
DummyParameter(std::string mountPrefix, std::string jsonFileName):
|
||||||
|
NVMParameterBase(mountPrefix + "/conf/" + jsonFileName),
|
||||||
|
mountPrefix(mountPrefix) {
|
||||||
|
insertValue(DUMMY_KEY_PARAM_1, 1);
|
||||||
|
insertValue(DUMMY_KEY_PARAM_2, "blablub");
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string mountPrefix;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BSP_Q7S_CORE_NVMPARAMS_PARAMETERDEFINITIONS_H_ */
|
Loading…
Reference in New Issue
Block a user