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 setInvertChannels(InvertFirChannel invertChannels)

Sets the channels to be inverted.

Parameters:

invertChannels – The channels to be inverted (0 -> first, 1 -> second, 3 -> both).

void setFirChannels(InvertFirChannel firstChannel)

Sets the channels to be filtered using an FIR filter.

Parameters:

invertChannels – The channels to be filtered (0 -> first, 1 -> second, 3 -> both).

void setOffsetC1(int16_t offsetC1)

Sets the offset of channel 1.

Parameters:

offsetC1 – The offset of channel 1 in units of the ADC.

void setOffsetC2(int16_t offsetC2)

Sets the offset of channel 2.

Parameters:

offsetC2 – The offset of channel 2 in units of the ADC.

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 setTriggerValueC1(int16_t triggerValueC1)

Sets the trigger value of channel 1.

Parameters:

triggerValueC1 – The trigger value of channel 1 in units of the ADC.

void setTriggerValueC2(int16_t triggerValueC2)

Sets the trigger value of channel 2.

Parameters:

triggerValueC2 – The trigger value of channel 2 in units of the ADC.

void setLongGateC1(uint16_t longGateC1)

Sets the long gate of channel 1.

Parameters:

longGateC1 – The long gate of channel 1 in number of samples.

void setLongGateC2(uint16_t longGateC2)

Sets the long gate of channel 2.

Parameters:

longGateC2 – The long gate of channel 2 in number of samples.

void setPreGateC1(uint16_t preGateC1)

Sets the pre gate of channel 1.

Parameters:

preGateC1 – The pre gate of channel 1 in number of samples.

void setPreGateC2(uint16_t preGateC2)

Sets the pre gate of channel 2.

Parameters:

preGateC2 – The pre gate of channel 2 in number of samples.

void setWantsRawData(bool wantsRawData)

Sets wants raw data.

Parameters:

wantsRawData – The flag to store raw data.

void setWantsCountData(bool wantsCountData)

Sets wants count data.

Parameters:

wantsCountData – The flag to store count data.

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.

uint32_t getDmaDescriptorCount(uint32_t dmaIndex)

Returns the number of DMA descriptors for the specified DMA.

Parameters:

dmaIndex – The index of the DMA.

Returns:

The number of DMA descriptors.

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.

void printMeasurementInfo() const

Prints the current measurement config.

This function is supposed to print the measurement config before starting a measurement.

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::unordered_map<uint8_t, uint32_t> mDmaDescriptorCounts = {}

unordered_map of descriptor counts for each DMA.

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 (1 -> first, 2 -> second, 3 -> both).

InvertFirChannel mInvertChannels = InvertFirChannel::BOTH

The channels to be inverted (0 -> None, 1 -> first, 2 -> second, 3 -> both).

InvertFirChannel mFirChannels = InvertFirChannel::BOTH

The channels to be filtered using an FIR filter (0 -> None, 1 -> first, 2 -> 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.

bool mWantsRawData = false

Flag to store raw data.

bool mWantsCountData = false

Flag to store count data.