various bugfixes and improvements

This commit is contained in:
2021-07-29 18:09:54 +02:00
parent dba620baf2
commit 34d3479e81
4 changed files with 88 additions and 33 deletions

View File

@ -64,7 +64,11 @@ int WatchdogTask::performOperation() {
break;
}
case(LoopResult::TIMEOUT): {
performTimeoutOperation();
performNotRunningOperation(loopResult);
break;
}
case(LoopResult::HUNG_UP): {
performNotRunningOperation(loopResult);
break;
}
case(LoopResult::RESTART_RQ): {
@ -159,6 +163,7 @@ WatchdogTask::LoopResult WatchdogTask::pollEvent(struct pollfd& waiter) {
}
else if (waiter.revents & POLLHUP) {
// Writer closed its end
return LoopResult::HUNG_UP;
}
return LoopResult::FAULT;
}
@ -189,9 +194,9 @@ int WatchdogTask::performRunningOperation() {
}
if(not obswRunning) {
if(printTimeoutLatch) {
if(printNotRunningLatch) {
// Reset latch so user can see timeouts
printTimeoutLatch = false;
printNotRunningLatch = false;
}
obswRunning = true;
@ -210,25 +215,35 @@ int WatchdogTask::performRunningOperation() {
return 0;
}
int WatchdogTask::performTimeoutOperation() {
int WatchdogTask::performNotRunningOperation(LoopResult type) {
// Latch prevents spam on console
if(not printTimeoutLatch) {
std::cout << "eive-watchdog: The FIFO timed out!" << std::endl;
printTimeoutLatch = true;
if(not printNotRunningLatch) {
if(type == LoopResult::HUNG_UP) {
std::cout << "eive-watchdog: FIFO writer hung up!" << std::endl;
}
else {
std::cout << "eive-watchdog: The FIFO timed out!" << std::endl;
}
printNotRunningLatch = 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());
if(result != 0) {
std::cerr << "Removing " << watchdog::RUNNING_FILE_NAME << " failed with code " <<
errno << ": " << strerror(errno) << std::endl;
}
}
#endif
if(obswRunning) {
#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());
if(result != 0) {
std::cerr << "Removing " << watchdog::RUNNING_FILE_NAME << " failed with code " <<
errno << ": " << strerror(errno) << std::endl;
}
}
#endif
obswRunning = false;
}
if(type == LoopResult::HUNG_UP) {
using namespace std::chrono_literals;
// Prevent spam
std::this_thread::sleep_for(2000ms);
}
return 0;
}

View File

@ -19,6 +19,7 @@ public:
CANCEL_RQ,
RESTART_RQ,
TIMEOUT,
HUNG_UP,
FAULT
};
@ -32,7 +33,7 @@ private:
bool obswRunning = false;
bool watchdogRunning = false;
bool printTimeoutLatch = false;
bool printNotRunningLatch = false;
std::array<uint8_t, 64> buf;
States state = States::NOT_STARTED;
@ -41,7 +42,7 @@ private:
LoopResult parseCommandByte(ssize_t readLen);
int performRunningOperation();
int performTimeoutOperation();
int performNotRunningOperation(LoopResult type);
int performSuspendOperation();
};