#pragma once #include #include #include namespace cms { struct LazyGateConfig { int threshold_percent{15}; int can_timeout_ms{1000}; int motion_timeout_ms{300}; }; struct InferenceStatus { bool models_ready{}; bool enabled{true}; bool can_valid{}; bool left_front_trigger{},left_rear_trigger{}; std::array positions{{-1,-1,-1,-1}}; // LF, RF, LR, RR; percent std::array direction{}; // LF, LR: -1 closing, 0 stationary, +1 opening std::uint64_t generation{1},sample_monotonic_ns{}; double can_age_ms{-1}; std::string reason{"CAN_UNAVAILABLE"}; }; // Pure state machine. Caller serializes access. Time is monotonic nanoseconds. class LazyGate { public: explicit LazyGate(LazyGateConfig config={}); void receive(std::uint32_t id,std::uint8_t const* data,std::size_t size,std::uint64_t now); InferenceStatus snapshot(std::uint64_t now); private: LazyGateConfig config_; bool have_sample_{}; std::uint64_t last_sample_{}; std::array last_change_{}; InferenceStatus state_; }; }