From 8980a696c9bf3e18bb54e8f90c6e69a189328c26 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 9 Jul 2021 14:11:26 +0200 Subject: [PATCH 1/5] added another useful command --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 05881a16..ee2f62f2 100644 --- a/README.md +++ b/README.md @@ -697,6 +697,12 @@ candump can0 ## Useful Q7S Linux Commands +Display currently running image: + +```sh +xsc_boot_copy +``` + Rebooting currently running image: ```sh From bef73d73571df479ac7279aa57eece2dd80a1dd7 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 9 Jul 2021 16:57:34 +0200 Subject: [PATCH 2/5] writing api for scratch buffer --- bsp_q7s/memory/CMakeLists.txt | 1 + bsp_q7s/memory/SdCardManager.cpp | 2 ++ bsp_q7s/memory/scratchApi.cpp | 12 ++++++++ bsp_q7s/memory/scratchApi.h | 49 ++++++++++++++++++++++++++++++++ linux/utility/CMakeLists.txt | 1 + linux/utility/utility.cpp | 11 +++++++ linux/utility/utility.h | 13 +++++++++ 7 files changed, 89 insertions(+) create mode 100644 bsp_q7s/memory/scratchApi.cpp create mode 100644 bsp_q7s/memory/scratchApi.h create mode 100644 linux/utility/utility.cpp create mode 100644 linux/utility/utility.h diff --git a/bsp_q7s/memory/CMakeLists.txt b/bsp_q7s/memory/CMakeLists.txt index e98971c4..ada948fb 100644 --- a/bsp_q7s/memory/CMakeLists.txt +++ b/bsp_q7s/memory/CMakeLists.txt @@ -2,4 +2,5 @@ target_sources(${TARGET_NAME} PRIVATE FileSystemHandler.cpp SdCardAccess.cpp SdCardManager.cpp + scratchApi.cpp ) \ No newline at end of file diff --git a/bsp_q7s/memory/SdCardManager.cpp b/bsp_q7s/memory/SdCardManager.cpp index 1341c132..d23a4331 100644 --- a/bsp_q7s/memory/SdCardManager.cpp +++ b/bsp_q7s/memory/SdCardManager.cpp @@ -122,6 +122,8 @@ ReturnValue_t SdCardManager::sdCardActive(std::pair& active) { } sd::SdCard SdCardManager::getPreferredSdCard() const { + int result = std::system("xsc_scratch read PREFSD > /tmp/pref_sd.txt"); + return preferredSdCard; } diff --git a/bsp_q7s/memory/scratchApi.cpp b/bsp_q7s/memory/scratchApi.cpp new file mode 100644 index 00000000..0b159775 --- /dev/null +++ b/bsp_q7s/memory/scratchApi.cpp @@ -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; +} diff --git a/bsp_q7s/memory/scratchApi.h b/bsp_q7s/memory/scratchApi.h new file mode 100644 index 00000000..32e604a1 --- /dev/null +++ b/bsp_q7s/memory/scratchApi.h @@ -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 +#include +#include +#include + +/** + * @brief API for the scratch buffer + */ +namespace scratch { + +namespace { +static size_t counter = 0; +} + +template::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::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_ */ diff --git a/linux/utility/CMakeLists.txt b/linux/utility/CMakeLists.txt index 45a7edcc..a3387531 100644 --- a/linux/utility/CMakeLists.txt +++ b/linux/utility/CMakeLists.txt @@ -1,4 +1,5 @@ target_sources(${TARGET_NAME} PUBLIC + utility.cpp ) diff --git a/linux/utility/utility.cpp b/linux/utility/utility.cpp new file mode 100644 index 00000000..69a3d08f --- /dev/null +++ b/linux/utility/utility.cpp @@ -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 +} diff --git a/linux/utility/utility.h b/linux/utility/utility.h new file mode 100644 index 00000000..3eb17a9b --- /dev/null +++ b/linux/utility/utility.h @@ -0,0 +1,13 @@ +#ifndef LINUX_UTILITY_UTILITY_H_ +#define LINUX_UTILITY_UTILITY_H_ + +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include + +namespace utility { + +void handleSystemError(int retcode, std::string function); + +} + +#endif /* LINUX_UTILITY_UTILITY_H_ */ From e9cfa0c11709343e61f5e3349bc6c985cf245cd6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 9 Jul 2021 17:21:26 +0200 Subject: [PATCH 3/5] testing scratch API --- bsp_q7s/boardtest/Q7STestTask.cpp | 15 +++++++++++++++ bsp_q7s/boardtest/Q7STestTask.h | 3 +++ bsp_q7s/memory/SdCardManager.cpp | 2 +- bsp_q7s/memory/scratchApi.h | 24 ++++++++++++++++++++---- 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/bsp_q7s/boardtest/Q7STestTask.cpp b/bsp_q7s/boardtest/Q7STestTask.cpp index ca64c8a6..a1470b79 100644 --- a/bsp_q7s/boardtest/Q7STestTask.cpp +++ b/bsp_q7s/boardtest/Q7STestTask.cpp @@ -3,6 +3,8 @@ #include "fsfw/timemanager/Stopwatch.h" #include "fsfw/tasks/TaskFactory.h" +#include "bsp_q7s/memory/scratchApi.h" + #include #include #include @@ -12,6 +14,7 @@ Q7STestTask::Q7STestTask(object_id_t objectId): TestTask(objectId) { ReturnValue_t Q7STestTask::performOneShotAction() { //sdCardTests(); + testScratchApi(); return TestTask::performOneShotAction(); } @@ -50,3 +53,15 @@ void Q7STestTask::fileTests() { system("echo \"Hallo Welt\" > /tmp/test2.txt"); system("echo \"Hallo Welt\""); } + +void Q7STestTask::testScratchApi() { + ReturnValue_t result = scratch::writeNumber("TEST", 1); + if(result != HasReturnvaluesIF::RETURN_OK) { + sif::debug << "Q7STestTask::scratchApiTest: Writing number failed" << std::endl; + } + int number = 0; + result = scratch::readNumber("TEST", number); + if(result != HasReturnvaluesIF::RETURN_OK) { + sif::debug << "Q7STestTask::scratchApiTest: Reading number failed" << std::endl; + } +} diff --git a/bsp_q7s/boardtest/Q7STestTask.h b/bsp_q7s/boardtest/Q7STestTask.h index 7056853e..664a8fa2 100644 --- a/bsp_q7s/boardtest/Q7STestTask.h +++ b/bsp_q7s/boardtest/Q7STestTask.h @@ -11,6 +11,9 @@ private: void sdCardTests(); void fileTests(); + + void testScratchApi(); + }; diff --git a/bsp_q7s/memory/SdCardManager.cpp b/bsp_q7s/memory/SdCardManager.cpp index d23a4331..6a7c5585 100644 --- a/bsp_q7s/memory/SdCardManager.cpp +++ b/bsp_q7s/memory/SdCardManager.cpp @@ -66,7 +66,7 @@ ReturnValue_t SdCardManager::setSdCardState(sd::SdCard sdCard, bool on) { statestring = "off"; } std::ostringstream command; - command << "h7hw sd set " << sdstring << " " << statestring; + command << "q7hw sd set " << sdstring << " " << statestring; int result = std::system(command.str().c_str()); if(result == 0) { return HasReturnvaluesIF::RETURN_OK; diff --git a/bsp_q7s/memory/scratchApi.h b/bsp_q7s/memory/scratchApi.h index 32e604a1..246515a1 100644 --- a/bsp_q7s/memory/scratchApi.h +++ b/bsp_q7s/memory/scratchApi.h @@ -2,9 +2,11 @@ #define BSP_Q7S_MEMORY_SCRATCHAPI_H_ #include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/serviceinterface/ServiceInterface.h" #include "linux/utility/utility.h" #include +#include #include #include #include @@ -18,10 +20,11 @@ namespace { static size_t counter = 0; } -template::value>::type> +template::value>::type> inline ReturnValue_t writeNumber(std::string name, T num) noexcept { std::ostringstream oss; oss << "xsc_scratch write " << name << " " << num; + sif::debug << oss.str() << std::endl; int result = std::system(oss.str().c_str()); if(result != 0) { utility::handleSystemError(result, "scratch::writeNumber"); @@ -30,15 +33,28 @@ inline ReturnValue_t writeNumber(std::string name, T num) noexcept { return HasReturnvaluesIF::RETURN_OK; } -template::value>::type> +template::value>::type> inline ReturnValue_t readNumber(std::string name, T& num) noexcept { - std::ostringstream oss; - oss << "xsc_scratch read " << name << " > /tmp/scratchro" << counter++; + using namespace std; + string filename = "/tmp/sro" + counter++; + ostringstream oss; + oss << "xsc_scratch read " << name << " < " << filename; + sif::debug << oss.str() << std::endl; int result = std::system(oss.str().c_str()); if(result != 0) { utility::handleSystemError(result, "scratch::writeNumber"); return HasReturnvaluesIF::RETURN_FAILED; } + ifstream file(filename); + string line; + if (not std::getline(file, line)) { + return HasReturnvaluesIF::RETURN_FAILED; + } + + size_t pos = line.find("="); + std::string valueAsString = line.substr(pos); + sif::debug << valueAsString << std::endl; + num = std::stoi(valueAsString); return HasReturnvaluesIF::RETURN_OK; } From 59112cae76ebc2079c843acc433ac8b5b8bcf5df Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 9 Jul 2021 17:54:32 +0200 Subject: [PATCH 4/5] now a sd card will always be on --- bsp_q7s/core/CoreController.cpp | 18 +++++++++- bsp_q7s/memory/SdCardManager.cpp | 34 ++++++++++++------- bsp_q7s/memory/scratchApi.h | 21 +++++++----- linux/csp/CspComIF.cpp | 3 ++ .../libcsp/src/drivers/can/can_socketcan.c | 2 +- 5 files changed, 55 insertions(+), 23 deletions(-) diff --git a/bsp_q7s/core/CoreController.cpp b/bsp_q7s/core/CoreController.cpp index 6c2f042b..98ddb347 100644 --- a/bsp_q7s/core/CoreController.cpp +++ b/bsp_q7s/core/CoreController.cpp @@ -24,17 +24,33 @@ LocalPoolDataSetBase* CoreController::getDataSetHandle(sid_t sid) { ReturnValue_t CoreController::initialize() { // Find a way to store this non-volatile outside of SD cards (ProASIC?) sd::SdCard preferredSdCard = sd::SdCard::SLOT_0; + std::string printoutString; + if(preferredSdCard == sd::SdCard::SLOT_0) { + printoutString = "0"; + } + else { + printoutString = "1"; + } // Creator or update status file ReturnValue_t result = SdCardManager::instance()->updateSdCardStateFile(); if(result != HasReturnvaluesIF::RETURN_OK) { sif::warning << "CoreController::initialize: Updating SD card state file failed" << std::endl; } + + sif::info << "Switching on SD card " << printoutString << ".." << std::endl; + result = SdCardManager::instance()->switchOnSdCard(preferredSdCard); - if(result != HasReturnvaluesIF::RETURN_OK) { + if(result == SdCardManager::ALREADY_ON) { + sif::info << "SD card " << printoutString << " is already on" << std::endl; + } + else if(result != HasReturnvaluesIF::RETURN_OK) { sif::warning << "CoreController::initialize: Turning SD card on failed" << std::endl; } + else { + sif::info << "SD card " << printoutString << " was switched on" << std::endl; + } return HasReturnvaluesIF::RETURN_OK; } diff --git a/bsp_q7s/memory/SdCardManager.cpp b/bsp_q7s/memory/SdCardManager.cpp index 6a7c5585..af963180 100644 --- a/bsp_q7s/memory/SdCardManager.cpp +++ b/bsp_q7s/memory/SdCardManager.cpp @@ -89,30 +89,39 @@ ReturnValue_t SdCardManager::sdCardActive(std::pair& active) { } string line; uint8_t idx = 0; - bool on = false; while (std::getline(sdStatus, line)) { istringstream iss(line); string word; + sd::SdCard currentSd = sd::SdCard::SLOT_0; while(iss >> word) { + if (word == "1:") { + currentSd = sd::SdCard::SLOT_1; + } + if(word == "on") { - on = true; + if(currentSd == sd::SdCard::SLOT_0) { + active.first = true; + } + else { + active.second = true; + } } else if (word == "off") { - on = false; + if(currentSd == sd::SdCard::SLOT_0) { + active.first = false; + } + else { + active.second = false; + } } else { continue; } - if(idx == 0) { - active.first = on; - } - else if(idx == 1) { - active.second = on; - } - else if(idx > 1) { + + if(idx > 3) { sif::warning << "SdCardManager::sdCardActive: Status file has more " - "than 2 lines!" << std::endl; + "than 4 lines!" << std::endl; return STATUS_FILE_FORMAT_INVALID; } } @@ -122,8 +131,7 @@ ReturnValue_t SdCardManager::sdCardActive(std::pair& active) { } sd::SdCard SdCardManager::getPreferredSdCard() const { - int result = std::system("xsc_scratch read PREFSD > /tmp/pref_sd.txt"); - + //int result = std::system("xsc_scratch read PREFSD > /tmp/pref_sd.txt"); return preferredSdCard; } diff --git a/bsp_q7s/memory/scratchApi.h b/bsp_q7s/memory/scratchApi.h index 246515a1..09bf6bab 100644 --- a/bsp_q7s/memory/scratchApi.h +++ b/bsp_q7s/memory/scratchApi.h @@ -17,14 +17,13 @@ namespace scratch { namespace { -static size_t counter = 0; +static uint8_t counter = 0; } template::value>::type> inline ReturnValue_t writeNumber(std::string name, T num) noexcept { std::ostringstream oss; oss << "xsc_scratch write " << name << " " << num; - sif::debug << oss.str() << std::endl; int result = std::system(oss.str().c_str()); if(result != 0) { utility::handleSystemError(result, "scratch::writeNumber"); @@ -36,10 +35,10 @@ inline ReturnValue_t writeNumber(std::string name, T num) noexcept { template::value>::type> inline ReturnValue_t readNumber(std::string name, T& num) noexcept { using namespace std; - string filename = "/tmp/sro" + counter++; + string filename = "/tmp/sro" + std::to_string(counter++); ostringstream oss; - oss << "xsc_scratch read " << name << " < " << filename; - sif::debug << oss.str() << std::endl; + oss << "xsc_scratch read " << name << " > " << filename; + int result = std::system(oss.str().c_str()); if(result != 0) { utility::handleSystemError(result, "scratch::writeNumber"); @@ -52,9 +51,15 @@ inline ReturnValue_t readNumber(std::string name, T& num) noexcept { } size_t pos = line.find("="); - std::string valueAsString = line.substr(pos); - sif::debug << valueAsString << std::endl; - num = std::stoi(valueAsString); + std::string valueAsString = line.substr(pos + 1); + try { + num = std::stoi(valueAsString); + } + catch(std::invalid_argument& e) { + sif::warning << "scratch::readNumber: stoi call failed with " << e.what() << std::endl; + } + + std::remove(filename.c_str()); return HasReturnvaluesIF::RETURN_OK; } diff --git a/linux/csp/CspComIF.cpp b/linux/csp/CspComIF.cpp index a8f13963..07fe63d3 100644 --- a/linux/csp/CspComIF.cpp +++ b/linux/csp/CspComIF.cpp @@ -24,6 +24,8 @@ ReturnValue_t CspComIF::initializeInterface(CookieIF *cookie) { /* Perform CAN and CSP initialization only once */ if(cspDeviceMap.empty()){ + sif::info << "Performing " << canInterface << " initialization.." << std::endl; + /* Define the memory to allocate for the CSP stack */ int buf_count = 10; int buf_size = 300; @@ -57,6 +59,7 @@ ReturnValue_t CspComIF::initializeInterface(CookieIF *cookie) { sif::error << "Failed to start csp route task" << std::endl; return HasReturnvaluesIF::RETURN_FAILED; } + sif::info << canInterface << " initialized successfully" << std::endl; } uint8_t cspAddress = cspCookie->getCspAddress(); diff --git a/thirdparty/libcsp/src/drivers/can/can_socketcan.c b/thirdparty/libcsp/src/drivers/can/can_socketcan.c index 94c6bdde..00d6444e 100644 --- a/thirdparty/libcsp/src/drivers/can/can_socketcan.c +++ b/thirdparty/libcsp/src/drivers/can/can_socketcan.c @@ -142,7 +142,7 @@ csp_iface_t * csp_can_socketcan_init(const char * ifc, int bitrate, int promisc) struct sockaddr_can addr; pthread_t rx_thread; - printf("-I-: Initiating CAN interface %s\n", ifc); + //printf("-I-: Initiating CAN interface %s\n", ifc); #ifdef CSP_HAVE_LIBSOCKETCAN /* Set interface up */ From 55ada72a8fb6ba84c6d9598613127b5f25d43511 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 9 Jul 2021 17:55:09 +0200 Subject: [PATCH 5/5] bumped subversion --- common/config/OBSWVersion.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/config/OBSWVersion.h b/common/config/OBSWVersion.h index 7ac812e6..b796f146 100644 --- a/common/config/OBSWVersion.h +++ b/common/config/OBSWVersion.h @@ -4,7 +4,7 @@ const char* const SW_NAME = "eive"; #define SW_VERSION 1 -#define SW_SUBVERSION 2 +#define SW_SUBVERSION 3 #define SW_SUBSUBVERSION 0 #endif /* COMMON_CONFIG_OBSWVERSION_H_ */