Added OBSW Watchdog #67
@ -33,7 +33,7 @@ endif()
|
|||||||
include(${CMAKE_SCRIPT_PATH}/PreProjectConfig.cmake)
|
include(${CMAKE_SCRIPT_PATH}/PreProjectConfig.cmake)
|
||||||
pre_project_config()
|
pre_project_config()
|
||||||
|
|
||||||
set(PROJECT_NAME_TO_SET eive-obsw)
|
set(PROJECT_NAME_TO_SET eive-obsw-$ENV{USERNAME})
|
||||||
if(BUILD_WATCHDOG)
|
if(BUILD_WATCHDOG)
|
||||||
set(PROJECT_NAME_TO_SET eive-watchdog)
|
set(PROJECT_NAME_TO_SET eive-watchdog)
|
||||||
endif()
|
endif()
|
||||||
|
@ -55,7 +55,6 @@ void CoreController::performControlOperation() {
|
|||||||
if(watchdogFifoFd != 0) {
|
if(watchdogFifoFd != 0) {
|
||||||
// Write to OBSW watchdog FIFO here
|
// Write to OBSW watchdog FIFO here
|
||||||
const char writeChar = 'a';
|
const char writeChar = 'a';
|
||||||
std::cout << "Writing to FIFO.." << std::endl;
|
|
||||||
ssize_t writtenBytes = write(watchdogFifoFd, &writeChar, 1);
|
ssize_t writtenBytes = write(watchdogFifoFd, &writeChar, 1);
|
||||||
if(writtenBytes < 0) {
|
if(writtenBytes < 0) {
|
||||||
sif::error << "Errors writing to watchdog FIFO, code " << errno << ": " <<
|
sif::error << "Errors writing to watchdog FIFO, code " << errno << ": " <<
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "SpiTestClass.h"
|
#include "SpiTestClass.h"
|
||||||
|
#include "OBSWConfig.h"
|
||||||
|
|
||||||
#include "devices/gpioIds.h"
|
#include "devices/gpioIds.h"
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ int WatchdogTask::performOperation() {
|
|||||||
WatchdogTask::LoopResult loopResult = watchdogLoop();
|
WatchdogTask::LoopResult loopResult = watchdogLoop();
|
||||||
switch(loopResult) {
|
switch(loopResult) {
|
||||||
case(LoopResult::OK): {
|
case(LoopResult::OK): {
|
||||||
|
performRunningOperation();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(LoopResult::CANCEL_RQ): {
|
case(LoopResult::CANCEL_RQ): {
|
||||||
@ -59,29 +60,26 @@ int WatchdogTask::performOperation() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case(LoopResult::SUSPEND_RQ): {
|
case(LoopResult::SUSPEND_RQ): {
|
||||||
std::cout << "eive-watchdog: Suspending watchdog operations" << std::endl;
|
performSuspendOperation();
|
||||||
if(state == States::RUNNING or state == States::FAULTY) {
|
|
||||||
watchdogRunning = false;
|
|
||||||
state = States::SUSPENDED;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(LoopResult::TIMEOUT): {
|
case(LoopResult::TIMEOUT): {
|
||||||
std::cout << "eive-watchdog: The FIFO timed out!" << std::endl;
|
|
||||||
performTimeoutOperation();
|
performTimeoutOperation();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(LoopResult::RESTART_RQ): {
|
case(LoopResult::RESTART_RQ): {
|
||||||
if(state == States::SUSPENDED or state == States::FAULTY) {
|
if(state == States::SUSPENDED or state == States::FAULTY) {
|
||||||
state = States::RUNNING;
|
|
||||||
watchdogRunning = true;
|
|
||||||
performRunningOperation();
|
performRunningOperation();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(LoopResult::FAULT): {
|
case(LoopResult::FAULT): {
|
||||||
|
using namespace std::chrono_literals;
|
||||||
// Configuration error
|
// Configuration error
|
||||||
std::cerr << "Fault has occured in watchdog loop" << std::endl;
|
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::cout << "Read " << readLen << " byte(s) on the pipe " << FIFO_NAME
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
#endif
|
#endif
|
||||||
return parseCommandByte(readLen);
|
else if(readLen >= 1) {
|
||||||
|
return parseCommandByte(readLen);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(waiter.revents & POLLERR) {
|
else if(waiter.revents & POLLERR) {
|
||||||
@ -184,9 +184,20 @@ WatchdogTask::LoopResult WatchdogTask::parseCommandByte(ssize_t readLen) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int WatchdogTask::performRunningOperation() {
|
int WatchdogTask::performRunningOperation() {
|
||||||
|
if(state != States::RUNNING) {
|
||||||
|
state = States::RUNNING;
|
||||||
|
}
|
||||||
|
|
||||||
if(not obswRunning) {
|
if(not obswRunning) {
|
||||||
|
if(printTimeoutLatch) {
|
||||||
|
// Reset latch so user can see timeouts
|
||||||
|
printTimeoutLatch = false;
|
||||||
|
}
|
||||||
|
|
||||||
obswRunning = true;
|
obswRunning = true;
|
||||||
|
std::cout << "eive-watchdog: Running OBSW detected.." << std::endl;
|
||||||
#if WATCHDOG_CREATE_FILE_IF_RUNNING == 1
|
#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)) {
|
if (not std::filesystem::exists(watchdog::RUNNING_FILE_NAME)) {
|
||||||
std::ofstream obswRunningFile(watchdog::RUNNING_FILE_NAME);
|
std::ofstream obswRunningFile(watchdog::RUNNING_FILE_NAME);
|
||||||
if(not obswRunningFile.good()) {
|
if(not obswRunningFile.good()) {
|
||||||
@ -200,6 +211,12 @@ int WatchdogTask::performRunningOperation() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int WatchdogTask::performTimeoutOperation() {
|
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 WATCHDOG_CREATE_FILE_IF_RUNNING == 1
|
||||||
if (std::filesystem::exists(watchdog::RUNNING_FILE_NAME)) {
|
if (std::filesystem::exists(watchdog::RUNNING_FILE_NAME)) {
|
||||||
int result = std::remove(watchdog::RUNNING_FILE_NAME.c_str());
|
int result = std::remove(watchdog::RUNNING_FILE_NAME.c_str());
|
||||||
@ -214,3 +231,12 @@ int WatchdogTask::performTimeoutOperation() {
|
|||||||
}
|
}
|
||||||
return 0;
|
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;
|
||||||
|
}
|
||||||
|
@ -32,6 +32,7 @@ private:
|
|||||||
|
|
||||||
bool obswRunning = false;
|
bool obswRunning = false;
|
||||||
bool watchdogRunning = false;
|
bool watchdogRunning = false;
|
||||||
|
bool printTimeoutLatch = false;
|
||||||
std::array<uint8_t, 64> buf;
|
std::array<uint8_t, 64> buf;
|
||||||
States state = States::NOT_STARTED;
|
States state = States::NOT_STARTED;
|
||||||
|
|
||||||
@ -41,6 +42,7 @@ private:
|
|||||||
|
|
||||||
int performRunningOperation();
|
int performRunningOperation();
|
||||||
int performTimeoutOperation();
|
int performTimeoutOperation();
|
||||||
|
int performSuspendOperation();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* WATCHDOG_WATCHDOG_H_ */
|
#endif /* WATCHDOG_WATCHDOG_H_ */
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
namespace watchdog {
|
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 FIFO_NAME = "/tmp/watchdog-pipe";
|
||||||
const std::string RUNNING_FILE_NAME = "/tmp/obsw-running";
|
const std::string RUNNING_FILE_NAME = "/tmp/obsw-running";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user