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() {
|
ReturnValue_t CoreController::initialize() {
|
||||||
// Find a way to store this non-volatile outside of SD cards (ProASIC?)
|
// Find a way to store this non-volatile outside of SD cards (ProASIC?)
|
||||||
sd::SdCard preferredSdCard = sd::SdCard::SLOT_0;
|
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
|
// Creator or update status file
|
||||||
ReturnValue_t result = SdCardManager::instance()->updateSdCardStateFile();
|
ReturnValue_t result = SdCardManager::instance()->updateSdCardStateFile();
|
||||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
sif::warning << "CoreController::initialize: Updating SD card state file failed"
|
sif::warning << "CoreController::initialize: Updating SD card state file failed"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sif::info << "Switching on SD card " << printoutString << ".." << std::endl;
|
||||||
|
|
||||||
result = SdCardManager::instance()->switchOnSdCard(preferredSdCard);
|
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"
|
sif::warning << "CoreController::initialize: Turning SD card on failed"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
sif::info << "SD card " << printoutString << " was switched on" << std::endl;
|
||||||
|
}
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,30 +89,39 @@ ReturnValue_t SdCardManager::sdCardActive(std::pair<bool, bool>& active) {
|
|||||||
}
|
}
|
||||||
string line;
|
string line;
|
||||||
uint8_t idx = 0;
|
uint8_t idx = 0;
|
||||||
bool on = false;
|
|
||||||
|
|
||||||
while (std::getline(sdStatus, line)) {
|
while (std::getline(sdStatus, line)) {
|
||||||
istringstream iss(line);
|
istringstream iss(line);
|
||||||
string word;
|
string word;
|
||||||
|
sd::SdCard currentSd = sd::SdCard::SLOT_0;
|
||||||
while(iss >> word) {
|
while(iss >> word) {
|
||||||
|
if (word == "1:") {
|
||||||
|
currentSd = sd::SdCard::SLOT_1;
|
||||||
|
}
|
||||||
|
|
||||||
if(word == "on") {
|
if(word == "on") {
|
||||||
on = true;
|
if(currentSd == sd::SdCard::SLOT_0) {
|
||||||
|
active.first = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
active.second = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (word == "off") {
|
else if (word == "off") {
|
||||||
on = false;
|
if(currentSd == sd::SdCard::SLOT_0) {
|
||||||
|
active.first = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
active.second = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(idx == 0) {
|
|
||||||
active.first = on;
|
if(idx > 3) {
|
||||||
}
|
|
||||||
else if(idx == 1) {
|
|
||||||
active.second = on;
|
|
||||||
}
|
|
||||||
else if(idx > 1) {
|
|
||||||
sif::warning << "SdCardManager::sdCardActive: Status file has more "
|
sif::warning << "SdCardManager::sdCardActive: Status file has more "
|
||||||
"than 2 lines!" << std::endl;
|
"than 4 lines!" << std::endl;
|
||||||
return STATUS_FILE_FORMAT_INVALID;
|
return STATUS_FILE_FORMAT_INVALID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,8 +131,7 @@ ReturnValue_t SdCardManager::sdCardActive(std::pair<bool, bool>& active) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sd::SdCard SdCardManager::getPreferredSdCard() const {
|
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;
|
return preferredSdCard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,14 +17,13 @@
|
|||||||
namespace scratch {
|
namespace scratch {
|
||||||
|
|
||||||
namespace {
|
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>
|
template<typename T, class = typename std::enable_if<std::is_integral<T>::value>::type>
|
||||||
inline ReturnValue_t writeNumber(std::string name, T num) noexcept {
|
inline ReturnValue_t writeNumber(std::string name, T num) noexcept {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << "xsc_scratch write " << name << " " << num;
|
oss << "xsc_scratch write " << name << " " << num;
|
||||||
sif::debug << oss.str() << std::endl;
|
|
||||||
int result = std::system(oss.str().c_str());
|
int result = std::system(oss.str().c_str());
|
||||||
if(result != 0) {
|
if(result != 0) {
|
||||||
utility::handleSystemError(result, "scratch::writeNumber");
|
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>
|
template<typename T, class = typename std::enable_if<std::is_integral<T>::value>::type>
|
||||||
inline ReturnValue_t readNumber(std::string name, T& num) noexcept {
|
inline ReturnValue_t readNumber(std::string name, T& num) noexcept {
|
||||||
using namespace std;
|
using namespace std;
|
||||||
string filename = "/tmp/sro" + counter++;
|
string filename = "/tmp/sro" + std::to_string(counter++);
|
||||||
ostringstream oss;
|
ostringstream oss;
|
||||||
oss << "xsc_scratch read " << name << " < " << filename;
|
oss << "xsc_scratch read " << name << " > " << filename;
|
||||||
sif::debug << oss.str() << std::endl;
|
|
||||||
int result = std::system(oss.str().c_str());
|
int result = std::system(oss.str().c_str());
|
||||||
if(result != 0) {
|
if(result != 0) {
|
||||||
utility::handleSystemError(result, "scratch::writeNumber");
|
utility::handleSystemError(result, "scratch::writeNumber");
|
||||||
@ -52,9 +51,15 @@ inline ReturnValue_t readNumber(std::string name, T& num) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t pos = line.find("=");
|
size_t pos = line.find("=");
|
||||||
std::string valueAsString = line.substr(pos);
|
std::string valueAsString = line.substr(pos + 1);
|
||||||
sif::debug << valueAsString << std::endl;
|
try {
|
||||||
num = std::stoi(valueAsString);
|
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;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,8 @@ ReturnValue_t CspComIF::initializeInterface(CookieIF *cookie) {
|
|||||||
|
|
||||||
/* Perform CAN and CSP initialization only once */
|
/* Perform CAN and CSP initialization only once */
|
||||||
if(cspDeviceMap.empty()){
|
if(cspDeviceMap.empty()){
|
||||||
|
sif::info << "Performing " << canInterface << " initialization.." << std::endl;
|
||||||
|
|
||||||
/* Define the memory to allocate for the CSP stack */
|
/* Define the memory to allocate for the CSP stack */
|
||||||
int buf_count = 10;
|
int buf_count = 10;
|
||||||
int buf_size = 300;
|
int buf_size = 300;
|
||||||
@ -57,6 +59,7 @@ ReturnValue_t CspComIF::initializeInterface(CookieIF *cookie) {
|
|||||||
sif::error << "Failed to start csp route task" << std::endl;
|
sif::error << "Failed to start csp route task" << std::endl;
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
sif::info << canInterface << " initialized successfully" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t cspAddress = cspCookie->getCspAddress();
|
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;
|
struct sockaddr_can addr;
|
||||||
pthread_t rx_thread;
|
pthread_t rx_thread;
|
||||||
|
|
||||||
printf("-I-: Initiating CAN interface %s\n", ifc);
|
//printf("-I-: Initiating CAN interface %s\n", ifc);
|
||||||
|
|
||||||
#ifdef CSP_HAVE_LIBSOCKETCAN
|
#ifdef CSP_HAVE_LIBSOCKETCAN
|
||||||
/* Set interface up */
|
/* Set interface up */
|
||||||
|
Loading…
Reference in New Issue
Block a user