Merge branch 'mueller/master' of https://egit.irs.uni-stuttgart.de/eive/eive-obsw into mueller/master
This commit is contained in:
commit
f74f7bb533
@ -697,6 +697,12 @@ candump can0
|
||||
|
||||
## Useful Q7S Linux Commands
|
||||
|
||||
Display currently running image:
|
||||
|
||||
```sh
|
||||
xsc_boot_copy
|
||||
```
|
||||
|
||||
Rebooting currently running image:
|
||||
|
||||
```sh
|
||||
|
@ -3,6 +3,8 @@
|
||||
#include "fsfw/timemanager/Stopwatch.h"
|
||||
#include "fsfw/tasks/TaskFactory.h"
|
||||
|
||||
#include "bsp_q7s/memory/scratchApi.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cstdio>
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,9 @@ private:
|
||||
|
||||
void sdCardTests();
|
||||
void fileTests();
|
||||
|
||||
void testScratchApi();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -2,4 +2,5 @@ target_sources(${TARGET_NAME} PRIVATE
|
||||
FileSystemHandler.cpp
|
||||
SdCardAccess.cpp
|
||||
SdCardManager.cpp
|
||||
scratchApi.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<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,6 +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");
|
||||
return preferredSdCard;
|
||||
}
|
||||
|
||||
|
12
bsp_q7s/memory/scratchApi.cpp
Normal file
12
bsp_q7s/memory/scratchApi.cpp
Normal file
@ -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;
|
||||
}
|
70
bsp_q7s/memory/scratchApi.h
Normal file
70
bsp_q7s/memory/scratchApi.h
Normal file
@ -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 <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <type_traits>
|
||||
#include <cstdlib>
|
||||
|
||||
/**
|
||||
* @brief API for the scratch buffer
|
||||
*/
|
||||
namespace scratch {
|
||||
|
||||
namespace {
|
||||
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;
|
||||
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<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" + 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_ */
|
@ -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_ */
|
||||
|
@ -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();
|
||||
|
@ -1,4 +1,5 @@
|
||||
target_sources(${TARGET_NAME} PUBLIC
|
||||
utility.cpp
|
||||
)
|
||||
|
||||
|
||||
|
11
linux/utility/utility.cpp
Normal file
11
linux/utility/utility.cpp
Normal file
@ -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
|
||||
}
|
13
linux/utility/utility.h
Normal file
13
linux/utility/utility.h
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef LINUX_UTILITY_UTILITY_H_
|
||||
#define LINUX_UTILITY_UTILITY_H_
|
||||
|
||||
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||
#include <string>
|
||||
|
||||
namespace utility {
|
||||
|
||||
void handleSystemError(int retcode, std::string function);
|
||||
|
||||
}
|
||||
|
||||
#endif /* LINUX_UTILITY_UTILITY_H_ */
|
@ -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