mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
committed by
Peter Johnson
parent
761bc3ef85
commit
7112add67f
@@ -54,7 +54,7 @@ void Watchdog::Thread::Main() {
|
||||
if (!watchdog->m_suppressTimeoutMessage) {
|
||||
wpi::outs() << "Watchdog not fed within "
|
||||
<< wpi::format("%.6f",
|
||||
watchdog->m_timeout.count() / 1.0e6)
|
||||
watchdog->m_timeout.count() / 1.0e9)
|
||||
<< "s\n";
|
||||
}
|
||||
}
|
||||
@@ -78,9 +78,10 @@ void Watchdog::Thread::Main() {
|
||||
}
|
||||
|
||||
Watchdog::Watchdog(double timeout, std::function<void()> callback)
|
||||
: m_timeout(static_cast<int64_t>(timeout * 1.0e6)),
|
||||
m_callback(callback),
|
||||
m_owner(&GetThreadOwner()) {}
|
||||
: Watchdog(units::second_t{timeout}, callback) {}
|
||||
|
||||
Watchdog::Watchdog(units::second_t timeout, std::function<void()> callback)
|
||||
: m_timeout(timeout), m_callback(callback), m_owner(&GetThreadOwner()) {}
|
||||
|
||||
Watchdog::~Watchdog() { Disable(); }
|
||||
|
||||
@@ -89,6 +90,13 @@ double Watchdog::GetTime() const {
|
||||
}
|
||||
|
||||
void Watchdog::SetTimeout(double timeout) {
|
||||
SetTimeout(units::second_t{timeout});
|
||||
}
|
||||
|
||||
void Watchdog::SetTimeout(units::second_t timeout) {
|
||||
using std::chrono::duration_cast;
|
||||
using std::chrono::microseconds;
|
||||
|
||||
m_startTime = hal::fpga_clock::now();
|
||||
m_epochs.clear();
|
||||
|
||||
@@ -96,11 +104,11 @@ void Watchdog::SetTimeout(double timeout) {
|
||||
auto thr = m_owner->GetThread();
|
||||
if (!thr) return;
|
||||
|
||||
m_timeout = std::chrono::microseconds(static_cast<int64_t>(timeout * 1.0e6));
|
||||
m_timeout = timeout;
|
||||
m_isExpired = false;
|
||||
|
||||
thr->m_watchdogs.remove(this);
|
||||
m_expirationTime = m_startTime + m_timeout;
|
||||
m_expirationTime = m_startTime + duration_cast<microseconds>(m_timeout);
|
||||
thr->m_watchdogs.emplace(this);
|
||||
thr->m_cond.notify_all();
|
||||
}
|
||||
@@ -109,7 +117,7 @@ double Watchdog::GetTimeout() const {
|
||||
// Locks mutex
|
||||
auto thr = m_owner->GetThread();
|
||||
|
||||
return m_timeout.count() / 1.0e6;
|
||||
return m_timeout.count() / 1.0e9;
|
||||
}
|
||||
|
||||
bool Watchdog::IsExpired() const {
|
||||
@@ -140,6 +148,9 @@ void Watchdog::PrintEpochs() {
|
||||
void Watchdog::Reset() { Enable(); }
|
||||
|
||||
void Watchdog::Enable() {
|
||||
using std::chrono::duration_cast;
|
||||
using std::chrono::microseconds;
|
||||
|
||||
m_startTime = hal::fpga_clock::now();
|
||||
m_epochs.clear();
|
||||
|
||||
@@ -150,7 +161,7 @@ void Watchdog::Enable() {
|
||||
m_isExpired = false;
|
||||
|
||||
thr->m_watchdogs.remove(this);
|
||||
m_expirationTime = m_startTime + m_timeout;
|
||||
m_expirationTime = m_startTime + duration_cast<microseconds>(m_timeout);
|
||||
thr->m_watchdogs.emplace(this);
|
||||
thr->m_cond.notify_all();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user