bugfixes and improvements
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good
- Tests finished
This commit is contained in:
@ -1,6 +1,9 @@
|
||||
#include "CoreController.h"
|
||||
|
||||
#include <fsfw/events/EventManager.h>
|
||||
#include <fsfw/ipc/QueueFactory.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "OBSWConfig.h"
|
||||
#include "OBSWVersion.h"
|
||||
@ -8,7 +11,6 @@
|
||||
#include "fsfw/timemanager/Stopwatch.h"
|
||||
#include "fsfw/version.h"
|
||||
#include "watchdogConf.h"
|
||||
#include <algorithm>
|
||||
#if OBSW_USE_TMTC_TCP_BRIDGE == 0
|
||||
#include "fsfw/osal/common/UdpTmTcBridge.h"
|
||||
#else
|
||||
@ -22,6 +24,7 @@
|
||||
#include "bsp_q7s/memory/SdCardManager.h"
|
||||
#include "bsp_q7s/memory/scratchApi.h"
|
||||
#include "bsp_q7s/xadc/Xadc.h"
|
||||
#include "linux/utility/utility.h"
|
||||
|
||||
xsc::Chip CoreController::CURRENT_CHIP = xsc::Chip::NO_CHIP;
|
||||
xsc::Copy CoreController::CURRENT_COPY = xsc::Copy::NO_COPY;
|
||||
@ -51,6 +54,7 @@ CoreController::CoreController(object_id_t objectId)
|
||||
} catch (const std::filesystem::filesystem_error &e) {
|
||||
sif::error << "CoreController::CoreController: Failed with exception " << e.what() << std::endl;
|
||||
}
|
||||
eventQueue = QueueFactory::instance()->createMessageQueue(5, EventMessage::MAX_MESSAGE_SIZE);
|
||||
}
|
||||
|
||||
ReturnValue_t CoreController::handleCommandMessage(CommandMessage *message) {
|
||||
@ -62,10 +66,10 @@ void CoreController::performControlOperation() {
|
||||
for (ReturnValue_t result = eventQueue->receiveMessage(&event); result == RETURN_OK;
|
||||
result = eventQueue->receiveMessage(&event)) {
|
||||
switch (event.getEvent()) {
|
||||
case(GpsHyperion::GPS_FIX_CHANGE): {
|
||||
gpsFix = static_cast<GpsHyperion::FixMode>(event.getParameter2());
|
||||
break;
|
||||
}
|
||||
case (GpsHyperion::GPS_FIX_CHANGE): {
|
||||
gpsFix = static_cast<GpsHyperion::FixMode>(event.getParameter2());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
performWatchdogControlOperation();
|
||||
@ -90,8 +94,10 @@ LocalPoolDataSetBase *CoreController::getDataSetHandle(sid_t sid) {
|
||||
}
|
||||
|
||||
ReturnValue_t CoreController::initialize() {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
|
||||
ReturnValue_t result = ExtendedControllerBase::initialize();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::warning << "CoreController::initialize: Base init failed" << std::endl;
|
||||
}
|
||||
result = scratch::writeNumber(scratch::ALLOC_FAILURE_COUNT, 0);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::warning << "CoreController::initialize: Setting up alloc failure "
|
||||
@ -102,18 +108,23 @@ ReturnValue_t CoreController::initialize() {
|
||||
sdStateMachine();
|
||||
|
||||
triggerEvent(REBOOT_SW, CURRENT_CHIP, CURRENT_COPY);
|
||||
EventManagerIF* eventManager = ObjectManager::instance()->get<EventManagerIF>(
|
||||
objects::EVENT_MANAGER);
|
||||
EventManagerIF *eventManager =
|
||||
ObjectManager::instance()->get<EventManagerIF>(objects::EVENT_MANAGER);
|
||||
if (eventManager == nullptr or eventQueue == nullptr) {
|
||||
sif::warning << "CoreController::initialize: No valid event manager found or "
|
||||
"queue invalid"
|
||||
<< std::endl;
|
||||
}
|
||||
result = eventManager->registerListener(eventQueue->getId());
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::warning << "CoreController::initialize: Registering as event listener failed" << std::endl;
|
||||
}
|
||||
result = eventManager->subscribeToEvent(this->getCommandQueue(),
|
||||
event::getEventId(GpsHyperion::GPS_FIX_CHANGE));
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
result = eventManager->subscribeToEvent(eventQueue->getId(),
|
||||
event::getEventId(GpsHyperion::GPS_FIX_CHANGE));
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::warning << "Subscribing for GPS GPS_FIX_CHANGE event failed" << std::endl;
|
||||
}
|
||||
return ExtendedControllerBase::initialize();
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t CoreController::initializeAfterTaskCreation() {
|
||||
@ -661,8 +672,7 @@ ReturnValue_t CoreController::initVersionFile() {
|
||||
fsfw::FSFW_VERSION.getVersion(versionString, sizeof(versionString));
|
||||
std::string fullFsfwVersionString = "FSFW: v" + std::string(versionString);
|
||||
std::string systemString = "System: " + unameLine;
|
||||
std::string mountPrefix = SdCardManager::instance()->getCurrentMountPrefix();
|
||||
std::string versionFilePath = mountPrefix + VERSION_FILE;
|
||||
std::string versionFilePath = currMntPrefix + VERSION_FILE;
|
||||
std::fstream versionFile;
|
||||
|
||||
if (not std::filesystem::exists(versionFilePath)) {
|
||||
@ -1220,15 +1230,17 @@ void CoreController::performWatchdogControlOperation() {
|
||||
}
|
||||
|
||||
void CoreController::performMountedSdCardOperations() {
|
||||
currMntPrefix = sdcMan->getCurrentMountPrefix();
|
||||
if (doPerformMountedSdCardOps) {
|
||||
bool sdCardMounted = false;
|
||||
sdCardMounted = sdcMan->isSdCardMounted(sdInfo.pref);
|
||||
if (sdCardMounted) {
|
||||
std::string path = sdcMan->getCurrentMountPrefix(sdInfo.pref) + "/" + CONF_FOLDER;
|
||||
std::string path = currMntPrefix + "/" + CONF_FOLDER;
|
||||
if (not std::filesystem::exists(path)) {
|
||||
std::filesystem::create_directory(path);
|
||||
}
|
||||
initVersionFile();
|
||||
initClockFromTimeFile();
|
||||
performRebootFileHandling(false);
|
||||
doPerformMountedSdCardOps = false;
|
||||
}
|
||||
@ -1238,7 +1250,7 @@ void CoreController::performMountedSdCardOperations() {
|
||||
|
||||
void CoreController::performRebootFileHandling(bool recreateFile) {
|
||||
using namespace std;
|
||||
std::string path = sdcMan->getCurrentMountPrefix(sdInfo.pref) + REBOOT_FILE;
|
||||
std::string path = currMntPrefix + REBOOT_FILE;
|
||||
if (not std::filesystem::exists(path) or recreateFile) {
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
sif::info << "CoreController::performRebootFileHandling: Recreating reboot file" << std::endl;
|
||||
@ -1617,7 +1629,7 @@ bool CoreController::parseRebootFile(std::string path, RebootFile &rf) {
|
||||
}
|
||||
|
||||
void CoreController::resetRebootCount(xsc::Chip tgtChip, xsc::Copy tgtCopy) {
|
||||
std::string path = sdcMan->getCurrentMountPrefix(sdInfo.pref) + REBOOT_FILE;
|
||||
std::string path = currMntPrefix + REBOOT_FILE;
|
||||
// Disable the reboot file mechanism
|
||||
parseRebootFile(path, rebootFile);
|
||||
if (tgtChip == xsc::ALL_CHIP and tgtCopy == xsc::ALL_COPY) {
|
||||
@ -1644,7 +1656,7 @@ void CoreController::resetRebootCount(xsc::Chip tgtChip, xsc::Copy tgtCopy) {
|
||||
}
|
||||
|
||||
void CoreController::rewriteRebootFile(RebootFile file) {
|
||||
std::string path = sdcMan->getCurrentMountPrefix(sdInfo.pref) + REBOOT_FILE;
|
||||
std::string path = currMntPrefix + REBOOT_FILE;
|
||||
std::ofstream rebootFile(path);
|
||||
if (rebootFile.is_open()) {
|
||||
// Initiate reboot file first. Reboot handling will be on on initialization
|
||||
@ -1681,15 +1693,15 @@ void CoreController::setRebootMechanismLock(bool lock, xsc::Chip tgtChip, xsc::C
|
||||
}
|
||||
|
||||
ReturnValue_t CoreController::timeFileHandler() {
|
||||
if(gpsFix == GpsHyperion::FixMode::FIX_2D or gpsFix == GpsHyperion::FixMode::FIX_3D) {
|
||||
if (gpsFix == GpsHyperion::FixMode::FIX_2D or gpsFix == GpsHyperion::FixMode::FIX_3D) {
|
||||
// It is assumed that the system time is set from the GPS time
|
||||
timeval currentTime = {};
|
||||
ReturnValue_t result = Clock::getClock_timeval(¤tTime);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
std::ofstream timeFile(TIME_FILE);
|
||||
timeFile << "UNIX SECONDS: " << currentTime.tv_sec;
|
||||
std::ofstream timeFile(currMntPrefix + TIME_FILE);
|
||||
timeFile << "UNIX SECONDS: " << currentTime.tv_sec << std::endl;
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
@ -1697,30 +1709,30 @@ ReturnValue_t CoreController::timeFileHandler() {
|
||||
ReturnValue_t CoreController::initClockFromTimeFile() {
|
||||
using namespace GpsHyperion;
|
||||
using namespace std;
|
||||
if ((gpsFix == FixMode::UNKNOWN or gpsFix == FixMode::NOT_SEEN) and
|
||||
std::filesystem::exists(TIME_FILE)) {
|
||||
|
||||
ifstream timeFile(TIME_FILE);
|
||||
std::string fileName = currMntPrefix + TIME_FILE;
|
||||
if (std::filesystem::exists(fileName) and
|
||||
((gpsFix == FixMode::UNKNOWN or gpsFix == FixMode::NOT_SEEN) or
|
||||
not utility::timeSanityCheck())) {
|
||||
ifstream timeFile(fileName);
|
||||
string nextWord;
|
||||
getline(timeFile, nextWord);
|
||||
istringstream iss(nextWord);
|
||||
iss >> nextWord;
|
||||
if(iss.bad() or nextWord != "UNIX") {
|
||||
if (iss.bad() or nextWord != "UNIX") {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
iss >> nextWord;
|
||||
if(iss.bad() or nextWord != "SECONDS:") {
|
||||
if (iss.bad() or nextWord != "SECONDS:") {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
iss >> nextWord;
|
||||
timeval currentTime = {};
|
||||
char* checkPtr;
|
||||
char *checkPtr;
|
||||
currentTime.tv_sec = strtol(nextWord.c_str(), &checkPtr, 10);
|
||||
if(iss.bad() or *checkPtr) {
|
||||
if (iss.bad() or *checkPtr) {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
Clock::setClock(¤tTime);
|
||||
return RETURN_OK;
|
||||
return Clock::setClock(¤tTime);
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
@ -1759,8 +1771,7 @@ void CoreController::readHkData() {
|
||||
}
|
||||
}
|
||||
|
||||
bool CoreController::isNumber(const std::string& s)
|
||||
{
|
||||
return !s.empty() && std::find_if(s.begin(),
|
||||
s.end(), [](unsigned char c) { return !std::isdigit(c); }) == s.end();
|
||||
bool CoreController::isNumber(const std::string &s) {
|
||||
return !s.empty() && std::find_if(s.begin(), s.end(),
|
||||
[](unsigned char c) { return !std::isdigit(c); }) == s.end();
|
||||
}
|
||||
|
@ -7,10 +7,10 @@
|
||||
#include <cstddef>
|
||||
|
||||
#include "CoreDefinitions.h"
|
||||
#include "mission/devices/devicedefinitions/GPSDefinitions.h"
|
||||
#include "bsp_q7s/memory/SdCardManager.h"
|
||||
#include "events/subsystemIdRanges.h"
|
||||
#include "fsfw/controller/ExtendedControllerBase.h"
|
||||
#include "mission/devices/devicedefinitions/GPSDefinitions.h"
|
||||
|
||||
class Timer;
|
||||
class SdCardManager;
|
||||
@ -59,8 +59,7 @@ class CoreController : public ExtendedControllerBase {
|
||||
"/" + std::string(CONF_FOLDER) + "/" + std::string(VERSION_FILE_NAME);
|
||||
const std::string REBOOT_FILE =
|
||||
"/" + std::string(CONF_FOLDER) + "/" + std::string(REBOOT_FILE_NAME);
|
||||
const std::string TIME_FILE =
|
||||
"/" + std::string(CONF_FOLDER) + "/" + std::string(TIME_FILE_NAME);
|
||||
const std::string TIME_FILE = "/" + std::string(CONF_FOLDER) + "/" + std::string(TIME_FILE_NAME);
|
||||
|
||||
static constexpr ActionId_t LIST_DIRECTORY_INTO_FILE = 0;
|
||||
static constexpr ActionId_t SWITCH_REBOOT_FILE_HANDLING = 5;
|
||||
@ -179,6 +178,7 @@ class CoreController : public ExtendedControllerBase {
|
||||
sd::SdState commandedState = sd::SdState::OFF;
|
||||
} sdInfo;
|
||||
RebootFile rebootFile = {};
|
||||
std::string currMntPrefix;
|
||||
bool doPerformMountedSdCardOps = true;
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user