Add CAN-driven lazy inference with resident TensorRT engines
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
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<int,4> positions{{-1,-1,-1,-1}}; // LF, RF, LR, RR; percent
|
||||
std::array<int,2> 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<std::uint64_t,2> last_change_{};
|
||||
InferenceStatus state_;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user