eive-obsw/watchdog/Watchdog.h

57 lines
1.2 KiB
C
Raw Normal View History

2021-07-29 11:35:20 +02:00
#ifndef WATCHDOG_WATCHDOG_H_
#define WATCHDOG_WATCHDOG_H_
#include <array>
2023-02-23 23:56:11 +01:00
#include <chrono>
#include <cstdint>
2023-02-23 23:56:11 +01:00
#include <optional>
2023-03-06 00:55:12 +01:00
#include <queue>
#include <string>
2021-07-29 11:35:20 +02:00
class WatchdogTask {
2023-02-23 23:56:11 +01:00
public:
enum class States { NOT_STARTED, RUNNING, SUSPENDED, FAULTY };
enum class LoopResult {
OK,
START_REQ,
START_WITH_WATCH_REQ,
SUSPEND_REQ,
CANCEL_REQ,
TIMEOUT,
HUNG_UP,
FAULT
};
WatchdogTask();
virtual ~WatchdogTask();
int performOperation();
private:
int fd = 0;
bool obswRunning = false;
bool watchingObsw = false;
bool printNotRunningLatch = false;
std::array<uint8_t, 64> buf;
2023-03-06 00:55:12 +01:00
std::queue<LoopResult> resultQueue;
std::optional<std::chrono::time_point<std::chrono::steady_clock>> notRunningStart;
2023-02-23 23:56:11 +01:00
States state = States::NOT_STARTED;
// Primary loop. Takes care of delaying, and reading from the communication pipe and translating
// messages to loop results.
2023-03-06 00:55:12 +01:00
void watchdogLoop();
2023-02-23 23:56:11 +01:00
bool stateMachine(LoopResult result);
2023-03-06 00:55:12 +01:00
void pollEvent(struct pollfd& waiter);
void parseCommands(ssize_t readLen);
2023-02-23 23:56:11 +01:00
int performRunningOperation();
int performNotRunningOperation(LoopResult type);
int performSuspendOperation();
2021-07-29 11:35:20 +02:00
};
#endif /* WATCHDOG_WATCHDOG_H_ */