various bugfixes, watchdog working now

This commit is contained in:
2021-07-29 17:21:27 +02:00
parent ff86c8af73
commit dba620baf2
6 changed files with 40 additions and 12 deletions

View File

@ -52,6 +52,7 @@ int WatchdogTask::performOperation() {
WatchdogTask::LoopResult loopResult = watchdogLoop();
switch(loopResult) {
case(LoopResult::OK): {
performRunningOperation();
break;
}
case(LoopResult::CANCEL_RQ): {
@ -59,29 +60,26 @@ int WatchdogTask::performOperation() {
return 0;
}
case(LoopResult::SUSPEND_RQ): {
std::cout << "eive-watchdog: Suspending watchdog operations" << std::endl;
if(state == States::RUNNING or state == States::FAULTY) {
watchdogRunning = false;
state = States::SUSPENDED;
}
performSuspendOperation();
break;
}
case(LoopResult::TIMEOUT): {
std::cout << "eive-watchdog: The FIFO timed out!" << std::endl;
performTimeoutOperation();
break;
}
case(LoopResult::RESTART_RQ): {
if(state == States::SUSPENDED or state == States::FAULTY) {
state = States::RUNNING;
watchdogRunning = true;
performRunningOperation();
}
break;
}
case(LoopResult::FAULT): {
using namespace std::chrono_literals;
// Configuration error
std::cerr << "Fault has occured in watchdog loop" << std::endl;
// Prevent spam
std::this_thread::sleep_for(2000ms);
}
}
}
@ -149,7 +147,9 @@ WatchdogTask::LoopResult WatchdogTask::pollEvent(struct pollfd& waiter) {
std::cout << "Read " << readLen << " byte(s) on the pipe " << FIFO_NAME
<< std::endl;
#endif
return parseCommandByte(readLen);
else if(readLen >= 1) {
return parseCommandByte(readLen);
}
}
else if(waiter.revents & POLLERR) {
@ -184,9 +184,20 @@ WatchdogTask::LoopResult WatchdogTask::parseCommandByte(ssize_t readLen) {
}
int WatchdogTask::performRunningOperation() {
if(state != States::RUNNING) {
state = States::RUNNING;
}
if(not obswRunning) {
if(printTimeoutLatch) {
// Reset latch so user can see timeouts
printTimeoutLatch = false;
}
obswRunning = true;
std::cout << "eive-watchdog: Running OBSW detected.." << std::endl;
#if WATCHDOG_CREATE_FILE_IF_RUNNING == 1
std::cout << "eive-watchdog: Creating " << watchdog::RUNNING_FILE_NAME << std::endl;
if (not std::filesystem::exists(watchdog::RUNNING_FILE_NAME)) {
std::ofstream obswRunningFile(watchdog::RUNNING_FILE_NAME);
if(not obswRunningFile.good()) {
@ -200,6 +211,12 @@ int WatchdogTask::performRunningOperation() {
}
int WatchdogTask::performTimeoutOperation() {
// Latch prevents spam on console
if(not printTimeoutLatch) {
std::cout << "eive-watchdog: The FIFO timed out!" << std::endl;
printTimeoutLatch = true;
}
#if WATCHDOG_CREATE_FILE_IF_RUNNING == 1
if (std::filesystem::exists(watchdog::RUNNING_FILE_NAME)) {
int result = std::remove(watchdog::RUNNING_FILE_NAME.c_str());
@ -214,3 +231,12 @@ int WatchdogTask::performTimeoutOperation() {
}
return 0;
}
int WatchdogTask::performSuspendOperation() {
if(state == States::RUNNING or state == States::FAULTY) {
std::cout << "eive-watchdog: Suspending watchdog operations" << std::endl;
watchdogRunning = false;
state = States::SUSPENDED;
}
return 0;
}