Add time file handling

This commit is contained in:
Robin Müller 2022-04-07 17:23:50 +02:00
parent 68992e77dc
commit 796b814b49
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
8 changed files with 127 additions and 21 deletions

View File

@ -8,6 +8,7 @@
#include "fsfw/timemanager/Stopwatch.h" #include "fsfw/timemanager/Stopwatch.h"
#include "fsfw/version.h" #include "fsfw/version.h"
#include "watchdogConf.h" #include "watchdogConf.h"
#include <algorithm>
#if OBSW_USE_TMTC_TCP_BRIDGE == 0 #if OBSW_USE_TMTC_TCP_BRIDGE == 0
#include "fsfw/osal/common/UdpTmTcBridge.h" #include "fsfw/osal/common/UdpTmTcBridge.h"
#else #else
@ -57,6 +58,16 @@ ReturnValue_t CoreController::handleCommandMessage(CommandMessage *message) {
} }
void CoreController::performControlOperation() { void CoreController::performControlOperation() {
EventMessage event;
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;
}
}
}
performWatchdogControlOperation(); performWatchdogControlOperation();
sdStateMachine(); sdStateMachine();
performMountedSdCardOperations(); performMountedSdCardOperations();
@ -91,6 +102,17 @@ ReturnValue_t CoreController::initialize() {
sdStateMachine(); sdStateMachine();
triggerEvent(REBOOT_SW, CURRENT_CHIP, CURRENT_COPY); triggerEvent(REBOOT_SW, CURRENT_CHIP, CURRENT_COPY);
EventManagerIF* eventManager = ObjectManager::instance()->get<EventManagerIF>(
objects::EVENT_MANAGER);
result = eventManager->registerListener(eventQueue->getId());
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) {
sif::warning << "Subscribing for GPS GPS_FIX_CHANGE event failed" << std::endl;
}
return ExtendedControllerBase::initialize(); return ExtendedControllerBase::initialize();
} }
@ -1211,6 +1233,7 @@ void CoreController::performMountedSdCardOperations() {
doPerformMountedSdCardOps = false; doPerformMountedSdCardOps = false;
} }
} }
timeFileHandler();
} }
void CoreController::performRebootFileHandling(bool recreateFile) { void CoreController::performRebootFileHandling(bool recreateFile) {
@ -1657,6 +1680,51 @@ void CoreController::setRebootMechanismLock(bool lock, xsc::Chip tgtChip, xsc::C
rewriteRebootFile(rebootFile); rewriteRebootFile(rebootFile);
} }
ReturnValue_t CoreController::timeFileHandler() {
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(&currentTime);
if(result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
std::ofstream timeFile(TIME_FILE);
timeFile << "UNIX SECONDS: " << currentTime.tv_sec;
}
return RETURN_OK;
}
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);
string nextWord;
getline(timeFile, nextWord);
istringstream iss(nextWord);
iss >> nextWord;
if(iss.bad() or nextWord != "UNIX") {
return RETURN_FAILED;
}
iss >> nextWord;
if(iss.bad() or nextWord != "SECONDS:") {
return RETURN_FAILED;
}
iss >> nextWord;
timeval currentTime = {};
char* checkPtr;
currentTime.tv_sec = strtol(nextWord.c_str(), &checkPtr, 10);
if(iss.bad() or *checkPtr) {
return RETURN_FAILED;
}
Clock::setClock(&currentTime);
return RETURN_OK;
}
return RETURN_OK;
}
void CoreController::readHkData() { void CoreController::readHkData() {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
result = hkSet.read(TIMEOUT_TYPE, MUTEX_TIMEOUT); result = hkSet.read(TIMEOUT_TYPE, MUTEX_TIMEOUT);
@ -1690,3 +1758,9 @@ void CoreController::readHkData() {
return; return;
} }
} }
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();
}

View File

@ -7,6 +7,7 @@
#include <cstddef> #include <cstddef>
#include "CoreDefinitions.h" #include "CoreDefinitions.h"
#include "mission/devices/devicedefinitions/GPSDefinitions.h"
#include "bsp_q7s/memory/SdCardManager.h" #include "bsp_q7s/memory/SdCardManager.h"
#include "events/subsystemIdRanges.h" #include "events/subsystemIdRanges.h"
#include "fsfw/controller/ExtendedControllerBase.h" #include "fsfw/controller/ExtendedControllerBase.h"
@ -53,10 +54,13 @@ class CoreController : public ExtendedControllerBase {
static constexpr char CONF_FOLDER[] = "conf"; static constexpr char CONF_FOLDER[] = "conf";
static constexpr char VERSION_FILE_NAME[] = "version.txt"; static constexpr char VERSION_FILE_NAME[] = "version.txt";
static constexpr char REBOOT_FILE_NAME[] = "reboot.txt"; static constexpr char REBOOT_FILE_NAME[] = "reboot.txt";
static constexpr char TIME_FILE_NAME[] = "time.txt";
const std::string VERSION_FILE = const std::string VERSION_FILE =
"/" + std::string(CONF_FOLDER) + "/" + std::string(VERSION_FILE_NAME); "/" + std::string(CONF_FOLDER) + "/" + std::string(VERSION_FILE_NAME);
const std::string REBOOT_FILE = const std::string REBOOT_FILE =
"/" + std::string(CONF_FOLDER) + "/" + std::string(REBOOT_FILE_NAME); "/" + std::string(CONF_FOLDER) + "/" + std::string(REBOOT_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 LIST_DIRECTORY_INTO_FILE = 0;
static constexpr ActionId_t SWITCH_REBOOT_FILE_HANDLING = 5; static constexpr ActionId_t SWITCH_REBOOT_FILE_HANDLING = 5;
@ -126,6 +130,7 @@ class CoreController : public ExtendedControllerBase {
// Designated value for rechecking FIFO open // Designated value for rechecking FIFO open
static constexpr int RETRY_FIFO_OPEN = -2; static constexpr int RETRY_FIFO_OPEN = -2;
int watchdogFifoFd = 0; int watchdogFifoFd = 0;
GpsHyperion::FixMode gpsFix = GpsHyperion::FixMode::UNKNOWN;
// States for SD state machine, which is used in non-blocking mode // States for SD state machine, which is used in non-blocking mode
enum class SdStates { enum class SdStates {
@ -151,6 +156,7 @@ class CoreController : public ExtendedControllerBase {
static constexpr bool BLOCKING_SD_INIT = false; static constexpr bool BLOCKING_SD_INIT = false;
SdCardManager* sdcMan = nullptr; SdCardManager* sdcMan = nullptr;
MessageQueueIF* eventQueue = nullptr;
struct SdInfo { struct SdInfo {
sd::SdCard pref = sd::SdCard::NONE; sd::SdCard pref = sd::SdCard::NONE;
@ -192,6 +198,9 @@ class CoreController : public ExtendedControllerBase {
ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode, uint32_t* msToReachTheMode); ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode, uint32_t* msToReachTheMode);
void performMountedSdCardOperations(); void performMountedSdCardOperations();
ReturnValue_t initVersionFile(); ReturnValue_t initVersionFile();
ReturnValue_t initClockFromTimeFile();
ReturnValue_t timeFileHandler();
ReturnValue_t initBootCopy(); ReturnValue_t initBootCopy();
ReturnValue_t initWatchdogFifo(); ReturnValue_t initWatchdogFifo();
ReturnValue_t initSdCardBlocking(); ReturnValue_t initSdCardBlocking();
@ -226,6 +235,7 @@ class CoreController : public ExtendedControllerBase {
bool parseRebootFile(std::string path, RebootFile& file); bool parseRebootFile(std::string path, RebootFile& file);
void rewriteRebootFile(RebootFile file); void rewriteRebootFile(RebootFile file);
void readHkData(); void readHkData();
bool isNumber(const std::string& s);
}; };
#endif /* BSP_Q7S_CORE_CORECONTROLLER_H_ */ #endif /* BSP_Q7S_CORE_CORECONTROLLER_H_ */

View File

@ -6,24 +6,26 @@
namespace SUBSYSTEM_ID { namespace SUBSYSTEM_ID {
enum: uint8_t { enum: uint8_t {
COMMON_SUBSYSTEM_ID_START = FW_SUBSYSTEM_ID_RANGE, COMMON_SUBSYSTEM_ID_START = FW_SUBSYSTEM_ID_RANGE,
PCDU_HANDLER = 108, ACS_SUBSYSTEM = 112,
HEATER_HANDLER = 109, PCDU_HANDLER = 113,
SA_DEPL_HANDLER = 110, HEATER_HANDLER = 114,
PLOC_MPSOC_HANDLER = 111, SA_DEPL_HANDLER = 115,
IMTQ_HANDLER = 112, PLOC_MPSOC_HANDLER = 116,
RW_HANDLER = 113, IMTQ_HANDLER = 117,
STR_HANDLER = 114, RW_HANDLER = 118,
PLOC_SUPERVISOR_HANDLER = 115, STR_HANDLER = 119,
FILE_SYSTEM = 116, PLOC_SUPERVISOR_HANDLER = 120,
PLOC_UPDATER = 117, FILE_SYSTEM = 121,
PLOC_MEMORY_DUMPER = 118, PLOC_UPDATER = 122,
PDEC_HANDLER = 119, PLOC_MEMORY_DUMPER = 123,
STR_HELPER = 120, PDEC_HANDLER = 124,
PLOC_MPSOC_HELPER = 121, STR_HELPER = 125,
PL_PCDU_HANDLER = 122, PLOC_MPSOC_HELPER = 126,
ACS_BOARD_ASS = 123, PL_PCDU_HANDLER = 127,
SUS_BOARD_ASS = 124, ACS_BOARD_ASS = 128,
TCS_BOARD_ASS = 125, SUS_BOARD_ASS = 129,
TCS_BOARD_ASS = 130,
GPS_HANDLER = 131,
COMMON_SUBSYSTEM_ID_END COMMON_SUBSYSTEM_ID_END
}; };
} }

2
fsfw

@ -1 +1 @@
Subproject commit a11d7455dfaf2e736f73f6c4dda1f8c06b9f1234 Subproject commit 5bda877d97b41e82bf36d939c9f367cef611446a

View File

@ -132,7 +132,11 @@ void GPSHyperionLinuxController::readGpsDataFromGpsd() {
} }
// 0: Not seen, 1: No fix, 2: 2D-Fix, 3: 3D-Fix // 0: Not seen, 1: No fix, 2: 2D-Fix, 3: 3D-Fix
gpsSet.fixMode.value = gps->fix.mode; int newFixMode = gps->fix.mode;
if(gpsSet.fixMode.value != newFixMode) {
triggerEvent(GpsHyperion::GPS_FIX_CHANGE, gpsSet.fixMode.value, newFixMode);
}
gpsSet.fixMode.value = newFixMode;
if (gps->fix.mode == 0 or gps->fix.mode == 1) { if (gps->fix.mode == 0 or gps->fix.mode == 1) {
if (modeCommanded and maxTimeToReachFix.hasTimedOut()) { if (modeCommanded and maxTimeToReachFix.hasTimedOut()) {
// We are supposed to be on and functioning, but not fix was found // We are supposed to be on and functioning, but not fix was found

View File

@ -2,6 +2,7 @@
#define MISSION_DEVICES_GPSHYPERIONHANDLER_H_ #define MISSION_DEVICES_GPSHYPERIONHANDLER_H_
#include "fsfw/FSFW.h" #include "fsfw/FSFW.h"
#include "commonSubsystemIds.h"
#include "fsfw/controller/ExtendedControllerBase.h" #include "fsfw/controller/ExtendedControllerBase.h"
#include "fsfw/devicehandlers/DeviceHandlerBase.h" #include "fsfw/devicehandlers/DeviceHandlerBase.h"
#include "mission/devices/devicedefinitions/GPSDefinitions.h" #include "mission/devices/devicedefinitions/GPSDefinitions.h"
@ -22,6 +23,8 @@
class GPSHyperionLinuxController : public ExtendedControllerBase { class GPSHyperionLinuxController : public ExtendedControllerBase {
public: public:
static constexpr uint32_t MAX_SECONDS_TO_REACH_FIX = 60 * 60 * 5; static constexpr uint32_t MAX_SECONDS_TO_REACH_FIX = 60 * 60 * 5;
GPSHyperionLinuxController(object_id_t objectId, object_id_t parentId, GPSHyperionLinuxController(object_id_t objectId, object_id_t parentId,
bool debugHyperionGps = false); bool debugHyperionGps = false);
virtual ~GPSHyperionLinuxController(); virtual ~GPSHyperionLinuxController();

View File

@ -6,6 +6,19 @@
namespace GpsHyperion { namespace GpsHyperion {
enum class FixMode: uint8_t {
NOT_SEEN = 0,
NO_FIX = 1,
FIX_2D = 2,
FIX_3D = 3,
UNKNOWN = 4
};
static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::GPS_HANDLER;
//! [EXPORT] : [COMMENT] Fix has changed. P1: Old fix. P2: New fix
//! 0: Not seen, 1: No Fix, 2: 2D-Fix, 3: 3D-Fix
static constexpr Event GPS_FIX_CHANGE = event::makeEvent(SUBSYSTEM_ID, 0, severity::INFO);
static constexpr DeviceCommandId_t GPS_REPLY = 0; static constexpr DeviceCommandId_t GPS_REPLY = 0;
static constexpr DeviceCommandId_t TRIGGER_RESET_PIN = 5; static constexpr DeviceCommandId_t TRIGGER_RESET_PIN = 5;

2
tmtc

@ -1 +1 @@
Subproject commit 8f2ff3034fff627b807f32c02fd9e676126bae5f Subproject commit 25bab108df76045e10af2efc26a0397f78574f9c