/******************************************************************* * @class MachineStatus * @brief 机器状态监控类 * * 该类用于监控机器的运行状态,包括速度阈值检测、停机时间记录等功能。 * 通过速度阈值和确认延时时间判断机器是否处于运行或停机状态。 * 提供最后一次停机的开始时间、结束时间和持续时间的查询接口。 * * Version history * 1.0 2023-08-18 zoufuzhou create * *******************************************************************/ #ifndef MACHINE_STATUS_H #define MACHINE_STATUS_H #include #include class MachineStatus { private: double speedThreshold; // 速度阈值 int confirmSeconds; // 确认延时秒数 std::chrono::system_clock::time_point lastLessTime; // 上次小于阈值的时间 std::chrono::system_clock::time_point lastZeroTime; // 上次速度为0的时间 bool isZero; bool isRunning; // 当前运行状态 std::chrono::system_clock::time_point lastStopStartTime; // 最后一次停机的开始时间 std::chrono::system_clock::time_point lastStopEndTime; // 最后一次停机的结束时间 public: /** * @brief 构造函数,初始化机器状态监控类的参数。 * * @param threshold 速度阈值,用于判断机器是否处于运行状态。 * @param seconds 确认延时秒数,用于确认机器是否真正停开机。 */ MachineStatus(double threshold = 0, int seconds = 0); //init void init(double threshold, int seconds); //update machine status void updateStatus(double currentSpeed); //update machine status Quickly void stopQuickly(void); // 获取当前运行状态 bool getStatus() const; // 获取最近一次停机时长(秒) double getLastStopDuration() const; // 获取最后一次停机的开始时间 std::chrono::system_clock::time_point getLastStopStartTime() const; // 获取最后一次停机的结束时间 std::chrono::system_clock::time_point getLastStopEndTime() const; }; #endif // MACHINE_STATUS_H