various bugfixes, watchdog working now

This commit is contained in:
Robin Müller 2021-07-29 17:21:27 +02:00
parent ff86c8af73
commit dba620baf2
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
6 changed files with 40 additions and 12 deletions

View File

@ -33,7 +33,7 @@ endif()
include(${CMAKE_SCRIPT_PATH}/PreProjectConfig.cmake)
pre_project_config()
set(PROJECT_NAME_TO_SET eive-obsw)
set(PROJECT_NAME_TO_SET eive-obsw-$ENV{USERNAME})
if(BUILD_WATCHDOG)
set(PROJECT_NAME_TO_SET eive-watchdog)
endif()

View File

@ -55,7 +55,6 @@ 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 << ": " <<

View File

@ -1,4 +1,5 @@
#include "SpiTestClass.h"
#include "OBSWConfig.h"
#include "devices/gpioIds.h"

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;
}

View File

@ -32,6 +32,7 @@ private:
bool obswRunning = false;
bool watchdogRunning = false;
bool printTimeoutLatch = false;
std::array<uint8_t, 64> buf;
States state = States::NOT_STARTED;
@ -41,6 +42,7 @@ private:
int performRunningOperation();
int performTimeoutOperation();
int performSuspendOperation();
};
#endif /* WATCHDOG_WATCHDOG_H_ */

View File

@ -10,7 +10,7 @@
namespace watchdog {
static constexpr int TIMEOUT_MS = 10 * 1000;
static constexpr int TIMEOUT_MS = 5 * 1000;
const std::string FIFO_NAME = "/tmp/watchdog-pipe";
const std::string RUNNING_FILE_NAME = "/tmp/obsw-running";