[wpilib] Change Watchdog to use HAL notifier (#2602)

This makes it follow simulation timing instead of wall clock time.
This commit is contained in:
Peter Johnson
2020-07-21 22:58:16 -07:00
committed by GitHub
parent 33d8363297
commit 23ba3ca19e
3 changed files with 206 additions and 181 deletions

View File

@@ -7,13 +7,10 @@
#pragma once
#include <chrono>
#include <functional>
#include <utility>
#include <hal/cpp/fpga_clock.h>
#include <units/time.h>
#include <wpi/SafeThread.h>
#include <wpi/StringRef.h>
#include <wpi/deprecated.h>
@@ -67,8 +64,8 @@ class Watchdog {
~Watchdog();
Watchdog(Watchdog&&) = default;
Watchdog& operator=(Watchdog&&) = default;
Watchdog(Watchdog&& rhs);
Watchdog& operator=(Watchdog&& rhs);
/**
* Returns the time in seconds since the watchdog was last fed.
@@ -149,25 +146,25 @@ class Watchdog {
private:
// Used for timeout print rate-limiting
static constexpr std::chrono::milliseconds kMinPrintPeriod{1000};
static constexpr units::second_t kMinPrintPeriod = 1_s;
hal::fpga_clock::time_point m_startTime;
std::chrono::nanoseconds m_timeout;
hal::fpga_clock::time_point m_expirationTime;
units::second_t m_startTime = 0_s;
units::second_t m_timeout;
units::second_t m_expirationTime = 0_s;
std::function<void()> m_callback;
hal::fpga_clock::time_point m_lastTimeoutPrintTime = hal::fpga_clock::epoch();
units::second_t m_lastTimeoutPrintTime = 0_s;
Tracer m_tracer;
bool m_isExpired = false;
bool m_suppressTimeoutMessage = false;
class Thread;
wpi::SafeThreadOwner<Thread>* m_owner;
class Impl;
Impl* m_impl;
bool operator>(const Watchdog& rhs);
static wpi::SafeThreadOwner<Thread>& GetThreadOwner();
static Impl* GetImpl();
};
} // namespace frc