WPILibC++  2019.1.1-beta-2-31-g26e8e58
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Watchdog.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <chrono>
11 #include <functional>
12 
13 #include <hal/cpp/fpga_clock.h>
14 #include <wpi/SafeThread.h>
15 #include <wpi/StringMap.h>
16 #include <wpi/StringRef.h>
17 
18 namespace frc {
19 
29 class Watchdog {
30  public:
38  Watchdog(double timeout, std::function<void()> callback);
39 
40  ~Watchdog();
41 
42  Watchdog(Watchdog&&) = default;
43  Watchdog& operator=(Watchdog&&) = default;
44 
48  double GetTime() const;
49 
56  void SetTimeout(double timeout);
57 
61  double GetTimeout() const;
62 
66  bool IsExpired() const;
67 
76  void AddEpoch(wpi::StringRef epochName);
77 
81  void PrintEpochs();
82 
88  void Reset();
89 
93  void Enable();
94 
98  void Disable();
99 
100  private:
101  hal::fpga_clock::time_point m_startTime;
102  std::chrono::microseconds m_timeout;
103  hal::fpga_clock::time_point m_expirationTime;
104  std::function<void()> m_callback;
105 
107  bool m_isExpired = false;
108 
109  class Thread;
111 
112  bool operator>(const Watchdog& rhs);
113 
114  static wpi::SafeThreadOwner<Thread>& GetThreadOwner();
115 };
116 
117 } // namespace frc
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
void Enable()
Enables the watchdog timer.
double GetTimeout() const
Returns the watchdog's timeout in seconds.
bool IsExpired() const
Returns true if the watchdog timer has expired.
void Reset()
Resets the watchdog timer.
double GetTime() const
Returns the time in seconds since the watchdog was last fed.
void PrintEpochs()
Prints list of epochs added so far and their times.
void SetTimeout(double timeout)
Sets the watchdog's timeout.
void Disable()
Disables the watchdog timer.
A class that's a wrapper around a watchdog timer.
Definition: Watchdog.h:29
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Watchdog(double timeout, std::function< void()> callback)
Watchdog constructor.
void AddEpoch(wpi::StringRef epochName)
Adds time since last epoch to the list printed by PrintEpochs().