Controller
The controller handles an actual measurement. It either starts a measurement locally and saves the data to files or it starts a server and waits for a client to connect and request a measurement. It controls the Dma objects and the Dma objects control the actual hardware.
Classes
Controller class
-
class Controller : public std::enable_shared_from_this<Controller>
The Controller class represents a controller for managing DMA operations and data acquisition.
The Controller class is responsible for managing DMA operations and data acquisition. It provides methods to start and stop DMA operations, set measurement settings, and manage DMA data transfer threads. It also provides methods for storing the DMA data to files. The controller can be run in local mode, where the data is stored to local files, or in network mode, where the data is sent to the clients. In network mode, it is possible to control the measurement process remotely. The controller is designed to be used in conjunction with a server object in network mode, which provides the necessary functionality for controlling the measurement process.
Public Functions
-
Controller(int mem, std::filesystem::path &storage_location)
Constructor for the Controller class.
This constructor initializes a new Controller object with the specified memory identifier.
- Parameters:
mem – The memory identifier.
storage_location – The location where the data should be stored.
-
~Controller()
Destructor for the Controller class.
This destructor destroys the DMA data thread as well.
-
Controller() = delete
-
Controller(const Controller&) = delete
-
Controller(Controller&&) = delete
-
void operator=(const Controller&) = delete
-
Controller &operator=(Controller&&) = delete
-
void deactivate_all()
Deactivates all DMA channels.
This function deactivates all DMA channels. It also deletes the DMA objects.
-
void set_channels(Channel channels)
Sets the channels to be used for the DMA operations.
- Parameters:
channels – The channels to be used for the DMA operations (0 -> first, 1 -> second, 3 -> both).
-
void set_invert_channels(BLRInvertFIRChannel invert_channels)
Sets the channels to be inverted.
- Parameters:
invert_channels – The channels to be inverted (0 -> first, 1 -> second, 3 -> both).
-
void set_fir_channels(BLRInvertFIRChannel fir_channels)
Sets the channels to be filtered using an FIR filter.
- Parameters:
fir_channels – The channels to be filtered (0 -> first, 1 -> second, 3 -> both).
-
void set_blr_channels(BLRInvertFIRChannel blr_channels)
Sets the channels to be used for baseline restoration.
- Parameters:
blr_channels – The channels to be used for baseline restoration (0 -> first, 1 -> second, 3 -> both).
-
void set_wants_raw_data(bool wants_raw_data)
Sets wants raw data.
- Parameters:
wants_raw_data – The flag to store raw data.
-
void set_wants_count_data(bool wants_count_data)
Sets wants count data.
- Parameters:
wants_count_data – The flag to store count data.
-
void run_local()
Runs the controller in local mode.
This function is responsible for executing the main logic of the controller in local mode. All data will be stored to local files. It is impossible to control measurements remotely.
-
void run_network(uint16_t port)
Runs the controller in network mode.
This function is responsible for executing the main logic of the controller in network mode. All data will be sent to the clients. It is possible to control measurements remotely.
- Parameters:
port – The port to be used for the network communication.
-
std::unordered_map<uint8_t, std::shared_ptr<nexmess::components::dma::Dma>> &get_dmas()
Returns a reference to the DMAs vector.
- Returns:
A reference to the DMAs vector.
-
std::shared_ptr<nexmess::components::dma::Dma> get_dma(uint32_t dma_id)
Returns a pointer to the DMA object with the specified dma_id.
- Parameters:
dma_id – The dma_id of the DMA object.
- Returns:
A reference to the DMAs vector.
-
uint32_t get_dma_descriptor_count(uint32_t dma_index)
Returns the number of DMA descriptors for the specified DMA.
- Parameters:
dma_index – The index of the DMA.
- Returns:
The number of DMA descriptors.
-
bool create_dma_objects()
Creates the DMA objects.
This function creates the DMA objects.
- Returns:
true if the DMA objects were created successfully, false otherwise.
-
void print_measurement_info() const
Prints the current measurement config.
This function is supposed to print the measurement config before starting a measurement.
Public Static Functions
-
static void set_offset_c1(int16_t offset_c1)
Sets the offset of channel 1.
- Parameters:
offset_c1 – The offset of channel 1 in units of the ADC.
-
static void set_offset_c2(int16_t offset_c2)
Sets the offset of channel 2.
- Parameters:
offset_c2 – The offset of channel 2 in units of the ADC.
-
static void set_measurement_time(uint32_t time)
Sets the measurement time.
The measurement time is set in ms. If it is set to 0 the measurement time is infinite.
- Parameters:
time – The measurement time.
-
static void set_trigger_value_c1(int16_t trigger_value_c1)
Sets the trigger value of channel 1.
- Parameters:
trigger_value_c1 – The trigger value of channel 1 in units of the ADC.
-
static void set_trigger_value_c2(int16_t trigger_value_c2)
Sets the trigger value of channel 2.
- Parameters:
trigger_value_c2 – The trigger value of channel 2 in units of the ADC.
-
static void set_long_gate_c1(uint16_t long_gate_c1)
Sets the long gate of channel 1.
- Parameters:
long_gate_c1 – The long gate of channel 1 in number of samples.
-
static void set_long_gate_c2(uint16_t long_gate_c2)
Sets the long gate of channel 2.
- Parameters:
long_gate_c2 – The long gate of channel 2 in number of samples.
-
static void set_pre_gate_c1(uint16_t pre_gate_c1)
Sets the pre gate of channel 1.
- Parameters:
pre_gate_c1 – The pre gate of channel 1 in number of samples.
-
static void set_pre_gate_c2(uint16_t pre_gate_c2)
Sets the pre gate of channel 2.
- Parameters:
pre_gate_c2 – The pre gate of channel 2 in number of samples.
-
static void set_blr_pre_gate_c1(uint16_t blr_pre_gate_c1)
Sets the pre gate of channel 1 for baseline restoration.
- Parameters:
blr_pre_gate_c1 – The pre gate for baseline restoration of channel 1 in number of samples.
-
static void set_blr_pre_gate_c2(uint16_t blr_pre_gate_c2)
Sets the pre gate of channel 2 for baseline restoration.
- Parameters:
blr_pre_gate_c2 – The pre gate for baseline restoration of channel 2 in number of samples.
Private Functions
-
void handle_dma_data_local()
Handles the DMA data and stores in the set storage location if set.
This function is responsible for handling the DMA data. It performs the necessary operations on the received data. This function contains the loop which runs until the DMA is stopped the hardware or user signal
-
void destroy_dma_data_thread()
Destroys the DMA data thread.
This function destroys the DMA data thread. It also joins the thread to make sure it is finished.
-
bool create_files()
Creates the files for each DMA if a storage location is set.
- Returns:
true if the files were created successfully, false otherwise.
Private Members
-
int mem_
The memory identifier.
-
std::unique_ptr<std::thread> signal_thread_
The thread for handling the signals.
-
std::unordered_map<uint8_t, std::shared_ptr<nexmess::components::dma::Dma>> dmas_
unordered_map of DMA objects.
-
std::unordered_map<uint8_t, uint32_t> dma_descriptor_counts_
unordered_map of descriptor counts for each DMA.
-
std::unique_ptr<std::thread> dma_data_thread_ = nullptr
Thread for handling the DMA data.
-
Channel channels_ = Channel::kBoth
The channels to be used for the DMA operations (1 -> first, 2 -> second, 3 -> both).
-
BLRInvertFIRChannel invert_channels_ = BLRInvertFIRChannel::kBoth
The channels to be inverted (0 -> None, 1 -> first, 2 -> second, 3 -> both).
-
BLRInvertFIRChannel fir_channels_ = BLRInvertFIRChannel::kBoth
The channels to be filtered using an FIR filter (0 -> None, 1 -> first, 2 -> second, 3 -> both).
-
BLRInvertFIRChannel blr_channels_ = BLRInvertFIRChannel::kBoth
The channels to be used for baseline restoration (0 -> None, 1 -> first, 2 -> second, 3 -> both).
-
std::filesystem::path storage_location_
The location where the data should be stored.
-
std::unordered_map<uint8_t, std::ofstream> files_
Vector of file streams for storing the data.
-
bool wants_raw_data_ = false
Flag to store raw data.
-
bool wants_count_data_ = false
Flag to store count data.
-
Controller(int mem, std::filesystem::path &storage_location)