#ifndef READOUT_H #define READOUT_H #include "gpx2.h" #include "gpio.h" #include #include #include #include #include #include #include #include inline static void print_hex(const std::string& str) { for (auto byte : str) { std::cout << "0x" << std::hex << std::setw(2) << std::setfill('0') << static_cast(byte) << " "; } std::cout << std::endl; } class Readout { public: Readout(double max_ref_diff = 100e-9, unsigned interrupt_pin = 20); ~Readout(); void stop(); private: [[nodiscard]] auto setup()->int; [[nodiscard]] auto read_tdc()->int; [[nodiscard]] auto process_loop()->int; void process_queue(bool ignore_max_queue = false); void dump_raw_tdc(); std::unique_ptr handler{}; std::shared_ptr callback{}; const std::chrono::milliseconds process_loop_timeout{ std::chrono::milliseconds(100) }; size_t max_queue_size{ 1000 }; size_t min_queue_size{ 50 }; const std::chrono::microseconds readout_loop_timeout{ std::chrono::microseconds(1) }; double m_max_interval{}; unsigned m_interrupt_pin{}; std::chrono::time_point start_time{}; std::chrono::time_point end_time{}; std::condition_variable queue_condition; std::array,4> tdc_stop{}; std::unique_ptr gpx2{}; std::atomic evt_count{}; std::atomic m_run{ true }; std::thread gpio_thread; std::thread analysis_thread; }; #endif // READOUT_H