Added OBSW Watchdog #67
@ -14,16 +14,7 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
WatchdogTask::WatchdogTask (): fd(0) {
|
WatchdogTask::WatchdogTask (): fd(0) {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
WatchdogTask::~WatchdogTask() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int WatchdogTask::performOperation() {
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
// Only create the FIFO if it does not exist yet
|
// Only create the FIFO if it does not exist yet
|
||||||
if(not std::filesystem::exists(watchdog::FIFO_NAME)) {
|
if(not std::filesystem::exists(watchdog::FIFO_NAME)) {
|
||||||
@ -34,20 +25,27 @@ int WatchdogTask::performOperation() {
|
|||||||
std::cerr << "eive-watchdog: Could not created named pipe at " <<
|
std::cerr << "eive-watchdog: Could not created named pipe at " <<
|
||||||
watchdog::FIFO_NAME << ", error " << errno << ": " << strerror(errno) <<
|
watchdog::FIFO_NAME << ", error " << errno << ": " << strerror(errno) <<
|
||||||
std::endl;
|
std::endl;
|
||||||
return -2;
|
throw std::runtime_error("eive-watchdog: FIFO creation failed");
|
||||||
}
|
}
|
||||||
#if WATCHDOG_VERBOSE_LEVEL >= 1
|
#if WATCHDOG_VERBOSE_LEVEL >= 1
|
||||||
std::cout << "eive-watchdog: Pipe at " << watchdog::FIFO_NAME <<
|
std::cout << "eive-watchdog: Pipe at " << watchdog::FIFO_NAME <<
|
||||||
" created successfully" << std::endl;
|
" created successfully" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WatchdogTask::~WatchdogTask() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int WatchdogTask::performOperation() {
|
||||||
// Open FIFO read only and non-blocking
|
// Open FIFO read only and non-blocking
|
||||||
fd = open(watchdog::FIFO_NAME.c_str(), O_RDONLY | O_NONBLOCK);
|
fd = open(watchdog::FIFO_NAME.c_str(), O_RDONLY | O_NONBLOCK);
|
||||||
if(fd < 0) {
|
if(fd < 0) {
|
||||||
std::cerr << "eive-watchdog: Opening pipe " << watchdog::FIFO_NAME <<
|
std::cerr << "eive-watchdog: Opening pipe " << watchdog::FIFO_NAME <<
|
||||||
"read-only failed with " << errno << ": " << strerror(errno) << std::endl;
|
"read-only failed with " << errno << ": " << strerror(errno) << std::endl;
|
||||||
}
|
}
|
||||||
|
state = States::RUNNING;
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
WatchdogTask::LoopResult loopResult = watchdogLoop();
|
WatchdogTask::LoopResult loopResult = watchdogLoop();
|
||||||
|
@ -7,9 +7,14 @@
|
|||||||
* It checks whether the OBSW writes to the the FIFO regularly.
|
* It checks whether the OBSW writes to the the FIFO regularly.
|
||||||
*/
|
*/
|
||||||
int main() {
|
int main() {
|
||||||
std::cout << "Starting OBSW watchdog.." << std::endl;
|
std::cout << "eive-watchdog: Starting OBSW watchdog.." << std::endl;
|
||||||
WatchdogTask watchdogTask;
|
try {
|
||||||
watchdogTask.performOperation();
|
WatchdogTask watchdogTask;
|
||||||
|
watchdogTask.performOperation();
|
||||||
|
}
|
||||||
|
catch(const std::runtime_error& e) {
|
||||||
|
std::cerr << "eive-watchdog: Run time exception " << e.what() << std::endl;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
namespace watchdog {
|
namespace watchdog {
|
||||||
|
|
||||||
static constexpr int TIMEOUT_MS = 10 * 1000;
|
static constexpr int TIMEOUT_MS = 10 * 1000;
|
||||||
const std::string FIFO_NAME = "/tmp/obsw-watchdog";
|
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