From dba620baf2c526e79758090e7b64ca5e32fe88de Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 29 Jul 2021 17:21:27 +0200 Subject: [PATCH] various bugfixes, watchdog working now --- CMakeLists.txt | 2 +- bsp_q7s/core/CoreController.cpp | 1 - linux/boardtest/SpiTestClass.cpp | 1 + watchdog/Watchdog.cpp | 44 +++++++++++++++++++++++++------- watchdog/Watchdog.h | 2 ++ watchdog/watchdogConf.h.in | 2 +- 6 files changed, 40 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e5e4482..cc476dcc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/bsp_q7s/core/CoreController.cpp b/bsp_q7s/core/CoreController.cpp index bdfac5f8..02e0adea 100644 --- a/bsp_q7s/core/CoreController.cpp +++ b/bsp_q7s/core/CoreController.cpp @@ -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 << ": " << diff --git a/linux/boardtest/SpiTestClass.cpp b/linux/boardtest/SpiTestClass.cpp index 71313f25..6f634168 100644 --- a/linux/boardtest/SpiTestClass.cpp +++ b/linux/boardtest/SpiTestClass.cpp @@ -1,4 +1,5 @@ #include "SpiTestClass.h" +#include "OBSWConfig.h" #include "devices/gpioIds.h" diff --git a/watchdog/Watchdog.cpp b/watchdog/Watchdog.cpp index 21be1e1d..9e316451 100644 --- a/watchdog/Watchdog.cpp +++ b/watchdog/Watchdog.cpp @@ -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; +} diff --git a/watchdog/Watchdog.h b/watchdog/Watchdog.h index 088acc5e..649fca6e 100644 --- a/watchdog/Watchdog.h +++ b/watchdog/Watchdog.h @@ -32,6 +32,7 @@ private: bool obswRunning = false; bool watchdogRunning = false; + bool printTimeoutLatch = false; std::array buf; States state = States::NOT_STARTED; @@ -41,6 +42,7 @@ private: int performRunningOperation(); int performTimeoutOperation(); + int performSuspendOperation(); }; #endif /* WATCHDOG_WATCHDOG_H_ */ diff --git a/watchdog/watchdogConf.h.in b/watchdog/watchdogConf.h.in index 81faf572..02d84e70 100644 --- a/watchdog/watchdogConf.h.in +++ b/watchdog/watchdogConf.h.in @@ -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";