diff --git a/README.md b/README.md index e9d4a9ef..ba494d96 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 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/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/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..af963180 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; @@ -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,6 +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"); 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..09bf6bab --- /dev/null +++ b/bsp_q7s/memory/scratchApi.h @@ -0,0 +1,70 @@ +#ifndef BSP_Q7S_MEMORY_SCRATCHAPI_H_ +#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 + +/** + * @brief API for the scratch buffer + */ +namespace scratch { + +namespace { +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; + 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 { + using namespace std; + string filename = "/tmp/sro" + std::to_string(counter++); + ostringstream oss; + oss << "xsc_scratch read " << name << " > " << filename; + + 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 + 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; +} + +ReturnValue_t writeString(std::string name, std::string string); + +} + +#endif /* BSP_Q7S_MEMORY_SCRATCHAPI_H_ */ 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_ */ 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/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_ */ 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 */