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 &storageLocation)

Constructor for the Controller class.

This constructor initializes a new Controller object with the specified memory identifier.

Parameters:
  • mem – The memory identifier.

  • storageLocation – 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 deactivateAll()

Deactivates all DMA channels.

This function deactivates all DMA channels. It also deletes the DMA objects.

void setChannels(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 setMeasurementTime(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.

void setTriggerValue(int16_t triggerValue)

Sets the trigger value.

The trigger value is set in units of the ADC.

Parameters:

triggerValue – The trigger value.

void setLongGate(uint32_t longGate)

Sets the long gate.

The long gate is set in number of samples.

Parameters:

longGate – The long gate.

void setPreGate(uint32_t preGate)

Sets the pre gate.

The pre gate is set in number of samples.

Parameters:

preGate – The pre gate.

void runLocal()

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 runNetwork(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>> &getDmas()

Returns a reference to the DMAs vector.

Returns:

A reference to the DMAs vector.

std::shared_ptr<nexmess::components::dma::Dma> getDma(uint32_t id)

Returns a pointer to the DMA object with the specified id.

Parameters:

id – The id of the DMA object.

Returns:

A reference to the DMAs vector.

bool getBufferFull(dma::Dma &dma)

Checks if the DMA buffer is full.

and logs a message if it is.

Parameters:

dma – The DMA object to be checked.

Returns:

true if the buffer is full, false otherwise.

bool createDmaObjects()

Creates the DMA objects.

This function creates the DMA objects.

Returns:

true if the DMA objects were created successfully, false otherwise.

Private Functions

void handleDmaDataLocal()

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 destroyDmaDataThread()

Destroys the DMA data thread.

This function destroys the DMA data thread. It also joins the thread to make sure it is finished.

bool createFiles()

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 mMem

The memory identifier.

std::unique_ptr<std::thread> mSignalThread = nullptr

The thread for handling the signals.

std::unordered_map<uint8_t, std::shared_ptr<nexmess::components::dma::Dma>> mDmas = {}

unordered_map of DMA objects.

std::unique_ptr<std::thread> mDmaDataThread = nullptr

Thread for handling the DMA data.

Channel mChannels = Channel::BOTH

The channels to be used for the DMA operations (0 -> first, 1 -> second, 3 -> both).

std::filesystem::path mStorageLocation

The location where the data should be stored.

std::unordered_map<uint8_t, std::ofstream> mFiles = {}

Vector of file streams for storing the data.