165 lines
3.8 KiB
C++
165 lines
3.8 KiB
C++
/*
|
||
* Scope.hh
|
||
*
|
||
* Created on: 22 апр. 2020 г.
|
||
* Author: LeonidTitov
|
||
*/
|
||
|
||
#ifndef UMLIBRARY_DRIVER_SCOPE_HH_
|
||
#define UMLIBRARY_DRIVER_SCOPE_HH_
|
||
|
||
#include "../systemic/IStatus.hh"
|
||
|
||
#include "CircularBinaryRemoteBuffer.hh"
|
||
|
||
#include <utility>
|
||
#include <memory_resource>
|
||
|
||
namespace driver {
|
||
|
||
class Scope {
|
||
public:
|
||
|
||
enum TriggerMode {
|
||
Once,
|
||
Repeat,
|
||
Cyclic
|
||
};
|
||
|
||
typedef unsigned int Times;
|
||
|
||
struct Frame {
|
||
virtual const char * data() const = 0;
|
||
virtual std::size_t size() const = 0;
|
||
|
||
virtual ~Frame() = default;
|
||
};
|
||
|
||
typedef float Time;
|
||
typedef std::size_t FrameIndex;
|
||
typedef systemic::IValue<bool> Condition;
|
||
|
||
bool setup( Frame * frame, Condition * condition, TriggerMode mode, Times times_to_on,
|
||
Time time_before, Time time_after );
|
||
void reset();
|
||
|
||
bool isSetup() const;
|
||
|
||
void start(); //!<Запуск с существующими настройками.
|
||
void stop(); //!<Остановить после завершения записи.
|
||
void disable(); //!<Остановить на текущем кадре.
|
||
|
||
std::pair<Times, Times> trigger_progress() const;
|
||
std::pair<FrameIndex, FrameIndex> data_progress() const;
|
||
|
||
std::pair<FrameIndex, FrameIndex> data_info() const;
|
||
Time sample_time() const;
|
||
|
||
bool isActive() const;
|
||
bool isTriggerFixed() const;
|
||
|
||
std::pair<const char *, std::size_t> getFrame( FrameIndex );
|
||
void freeFrame( FrameIndex );
|
||
|
||
Scope( peripheral::IMemoryAccess & memory_access,
|
||
std::pmr::memory_resource * initialization, std::size_t put_cache_size, std::size_t get_cache_size );
|
||
|
||
public:
|
||
void setSampleTime( float ts_in_second );
|
||
void process();
|
||
|
||
private:
|
||
Frame * frame;
|
||
|
||
peripheral::IMemoryAccess & memory;
|
||
|
||
std::pmr::polymorphic_allocator<CircularBinaryRemoteBuffer> buffer_constructor;
|
||
CircularBinaryRemoteBuffer * buffer;
|
||
|
||
char * const put_cache; std::size_t const put_cache_size;
|
||
char * const get_cache; std::size_t const get_cache_size;
|
||
|
||
typedef driver::CircularBinaryRemoteBuffer::Index Index;
|
||
|
||
struct TriggerManager {
|
||
|
||
static Condition * default_condition();
|
||
|
||
Condition * condition;
|
||
bool prev_condition;
|
||
volatile Times counter;
|
||
Times threshold;
|
||
bool repeat_mode;
|
||
|
||
bool enable;
|
||
bool fixed;
|
||
|
||
void setup( Condition * c, Times threshold, bool repeatable );
|
||
bool at_fix();
|
||
void stop();
|
||
|
||
bool is_fixed() const;
|
||
void start();
|
||
|
||
std::pair<Times, Times> progress() const {
|
||
|
||
return { Times(counter), threshold };
|
||
}
|
||
|
||
TriggerManager();
|
||
|
||
} trigger;
|
||
|
||
struct CaptureManager {
|
||
|
||
bool before_trigger;
|
||
|
||
FrameIndex before_trigger_frame_counter;
|
||
FrameIndex before_trigger_frame_threshold;
|
||
|
||
FrameIndex trigger_position;
|
||
|
||
FrameIndex after_trigger_frame_counter;
|
||
FrameIndex after_trigger_frame_threshold;
|
||
|
||
FrameIndex step_counter;
|
||
FrameIndex step_threshold;
|
||
|
||
bool active;
|
||
|
||
Index head_index;
|
||
|
||
void setup( FrameIndex before_fix_frames, FrameIndex after_fix_frames, FrameIndex step );
|
||
void fix( std::pair<Index, std::size_t> info );
|
||
bool at_shot();
|
||
|
||
void start();
|
||
void stop();
|
||
|
||
bool is_active() const;
|
||
bool is_done() const;
|
||
|
||
Index head() const;
|
||
FrameIndex desired_trigger() const { return before_trigger_frame_threshold; }
|
||
|
||
std::pair<Times, Times> progress() const {
|
||
return { after_trigger_frame_counter, after_trigger_frame_threshold };
|
||
}
|
||
|
||
CaptureManager();
|
||
|
||
} capture;
|
||
|
||
//!Флаг белый.
|
||
bool is_setupped;
|
||
|
||
Time process_quant;
|
||
Time data_quant;
|
||
|
||
bool restart_on_done;
|
||
};
|
||
|
||
}
|
||
|
||
#endif /* UMLIBRARY_DRIVER_SCOPE_HH_ */
|