watchdog handling finished

This commit is contained in:
2021-07-29 16:31:04 +02:00
parent 983ce045a9
commit ff86c8af73
8 changed files with 179 additions and 45 deletions

View File

@ -1,6 +1,7 @@
#include "CoreController.h"
#include "OBSWConfig.h"
#include "OBSWVersion.h"
#include "watchdogConf.h"
#include "fsfw/FSFWVersion.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
@ -13,6 +14,9 @@
#include "bsp_q7s/memory/scratchApi.h"
#include "bsp_q7s/memory/SdCardManager.h"
#include <fcntl.h>
#include <unistd.h>
#include <filesystem>
CoreController::Chip CoreController::currentChip = Chip::NO_CHIP;
@ -22,6 +26,11 @@ CoreController::CoreController(object_id_t objectId):
ExtendedControllerBase(objectId, objects::NO_OBJECT, 5) {
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
try {
result = initWatchdogFifo();
if(result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "CoreController::CoreController: Watchdog FIFO init failed" <<
std::endl;
}
result = initSdCard();
if(result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "CoreController::CoreController: SD card init failed" << std::endl;
@ -30,6 +39,7 @@ CoreController::CoreController(object_id_t objectId):
if(result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "CoreController::CoreController: Boot copy init" << std::endl;
}
}
catch(const std::filesystem::filesystem_error& e) {
sif::error << "CoreController::CoreController: Failed with exception " <<
@ -42,6 +52,16 @@ ReturnValue_t CoreController::handleCommandMessage(CommandMessage *message) {
}
void CoreController::performControlOperation() {
if(watchdogFifoFd != 0) {
// Write to OBSW watchdog FIFO here
const char writeChar = 'a';
std::cout << "Writing to FIFO.." << std::endl;
ssize_t writtenBytes = write(watchdogFifoFd, &writeChar, 1);
if(writtenBytes < 0) {
sif::error << "Errors writing to watchdog FIFO, code " << errno << ": " <<
strerror(errno) << std::endl;
}
}
}
ReturnValue_t CoreController::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
@ -406,6 +426,23 @@ void CoreController::getCurrentBootCopy(Chip &chip, Copy &copy) {
copy = currentCopy;
}
ReturnValue_t CoreController::initWatchdogFifo() {
if(not std::filesystem::exists(watchdog::FIFO_NAME)) {
// Still return RETURN_OK for now
sif::info << "Watchdog FIFO " << watchdog::FIFO_NAME << " does not exist, can't initiate" <<
" watchdog" << std::endl;
return HasReturnvaluesIF::RETURN_OK;
}
// Open FIFO write only and non-blocking
watchdogFifoFd = open(watchdog::FIFO_NAME.c_str(), O_WRONLY);
if(watchdogFifoFd < 0) {
std::cerr << "Opening pipe " << watchdog::FIFO_NAME << "write-only failed with " <<
errno << ": " << strerror(errno) << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
return HasReturnvaluesIF::RETURN_OK;
}
void CoreController::initPrint() {
#if OBSW_VERBOSE_LEVEL >= 1
#if OBSW_USE_TMTC_TCP_BRIDGE == 0
@ -415,5 +452,9 @@ void CoreController::initPrint() {
sif::info << "Created TCP server for TMTC commanding with listener port " <<
TcpTmTcBridge::DEFAULT_SERVER_PORT << std::endl;
#endif
if(watchdogFifoFd != 0) {
sif::info << "Opened watchdog FIFO successfully.." << std::endl;
}
#endif
}

View File

@ -63,12 +63,14 @@ private:
ReturnValue_t initVersionFile();
ReturnValue_t initBootCopy();
ReturnValue_t initWatchdogFifo();
ReturnValue_t actionListDirectoryIntoFile(ActionId_t actionId, MessageQueueId_t commandedBy,
const uint8_t *data, size_t size);
void initPrint();
int watchdogFifoFd = 0;
};

View File

@ -2,11 +2,15 @@
#include "OBSWVersion.h"
#include "OBSWConfig.h"
#include "InitMission.h"
#include "watchdogConf.h"
#include "fsfw/tasks/TaskFactory.h"
#include "fsfw/FSFWVersion.h"
#include <iostream>
#include <filesystem>
static int OBSW_ALREADY_RUNNING = -2;
int obsw::obsw() {
std::cout << "-- EIVE OBSW --" << std::endl;
@ -21,7 +25,13 @@ int obsw::obsw() {
std::cout << "-- " << __DATE__ << " " << __TIME__ << " --" << std::endl;
#if Q7S_CHECK_FOR_ALREADY_RUNNING_IMG == 1
// Check special file here
// Check special file here. This file is created or deleted by the eive-watchdog application
// or systemd service!
if(std::filesystem::exists(watchdog::RUNNING_FILE_NAME)) {
sif::warning << "File " << watchdog::RUNNING_FILE_NAME << " exists so the software might "
"already be running. Aborting.." << std::endl;
return OBSW_ALREADY_RUNNING;
}
#endif
initmission::initMission();