Filesystem Update #53
@ -697,6 +697,12 @@ candump can0
|
|||||||
|
|
||||||
## Useful Q7S Linux Commands
|
## Useful Q7S Linux Commands
|
||||||
|
|
||||||
|
Display currently running image:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
xsc_boot_copy
|
||||||
|
```
|
||||||
|
|
||||||
Rebooting currently running image:
|
Rebooting currently running image:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
#include "fsfw/timemanager/Stopwatch.h"
|
#include "fsfw/timemanager/Stopwatch.h"
|
||||||
#include "fsfw/tasks/TaskFactory.h"
|
#include "fsfw/tasks/TaskFactory.h"
|
||||||
|
|
||||||
|
#include "bsp_q7s/memory/scratchApi.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
@ -12,6 +14,7 @@ Q7STestTask::Q7STestTask(object_id_t objectId): TestTask(objectId) {
|
|||||||
|
|
||||||
ReturnValue_t Q7STestTask::performOneShotAction() {
|
ReturnValue_t Q7STestTask::performOneShotAction() {
|
||||||
//sdCardTests();
|
//sdCardTests();
|
||||||
|
testScratchApi();
|
||||||
return TestTask::performOneShotAction();
|
return TestTask::performOneShotAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,3 +53,15 @@ void Q7STestTask::fileTests() {
|
|||||||
system("echo \"Hallo Welt\" > /tmp/test2.txt");
|
system("echo \"Hallo Welt\" > /tmp/test2.txt");
|
||||||
system("echo \"Hallo Welt\"");
|
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 sdCardTests();
|
||||||
void fileTests();
|
void fileTests();
|
||||||
|
|
||||||
|
void testScratchApi();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,4 +2,5 @@ target_sources(${TARGET_NAME} PRIVATE
|
|||||||
FileSystemHandler.cpp
|
FileSystemHandler.cpp
|
||||||
SdCardAccess.cpp
|
SdCardAccess.cpp
|
||||||
SdCardManager.cpp
|
SdCardManager.cpp
|
||||||
|
scratchApi.cpp
|
||||||
)
|
)
|
@ -66,7 +66,7 @@ ReturnValue_t SdCardManager::setSdCardState(sd::SdCard sdCard, bool on) {
|
|||||||
statestring = "off";
|
statestring = "off";
|
||||||
}
|
}
|
||||||
std::ostringstream command;
|
std::ostringstream command;
|
||||||
command << "h7hw sd set " << sdstring << " " << statestring;
|
command << "q7hw sd set " << sdstring << " " << statestring;
|
||||||
int result = std::system(command.str().c_str());
|
int result = std::system(command.str().c_str());
|
||||||
if(result == 0) {
|
if(result == 0) {
|
||||||
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,6 +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");
|
||||||
return preferredSdCard;
|
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";
|
const char* const SW_NAME = "eive";
|
||||||
|
|
||||||
#define SW_VERSION 1
|
#define SW_VERSION 1
|
||||||
#define SW_SUBVERSION 2
|
#define SW_SUBVERSION 3
|
||||||
#define SW_SUBSUBVERSION 0
|
#define SW_SUBSUBVERSION 0
|
||||||
|
|
||||||
#endif /* COMMON_CONFIG_OBSWVERSION_H_ */
|
#endif /* COMMON_CONFIG_OBSWVERSION_H_ */
|
||||||
|
@ -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();
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
target_sources(${TARGET_NAME} PUBLIC
|
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;
|
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