now a sd card will always be on
This commit is contained in:
parent
d1aa68ea80
commit
e22399c5be
@ -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;
|
||||
}
|
||||
|
||||
|
@ -89,30 +89,39 @@ ReturnValue_t SdCardManager::sdCardActive(std::pair<bool, bool>& 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<bool, bool>& 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;
|
||||
}
|
||||
|
||||
|
@ -17,14 +17,13 @@
|
||||
namespace scratch {
|
||||
|
||||
namespace {
|
||||
static size_t counter = 0;
|
||||
static uint8_t counter = 0;
|
||||
}
|
||||
|
||||
template<typename T, class = typename std::enable_if<std::is_integral<T>::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<typename T, class = typename std::enable_if<std::is_integral<T>::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;
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user