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 */