Network
The network components are used to communicate with the outside world. When the controller is run in network mode a server is started which listens to incoming connections. Each connection is handled by a client object.
Additionally, there are other modules within this component to abstract the measurement state and the client configuration. The different message types are defined as well.
Classes and structures
Server class
-
class Server : public std::enable_shared_from_this<Server>
Represents a server that handles client connections and data transfer.
Represents a server that listens for connections and handles client interactions.
The Server class is responsible for managing client connections, handling data transfer, and controlling the measurement configuration. It provides methods to start and stop the server, set and retrieve the measurement configuration, and perform DMA data transfer.
The server runs on a specified port and communicates with clients using TCP sockets. It maintains a list of connected clients and allows sending notifications to all clients.
The server is designed to be used in conjunction with a controller object, which provides the necessary functionality for controlling the measurement process.
The Server class is responsible for managing client connections, handling data transfer, and controlling the measurement process. It provides methods to start and stop the server, configure measurement settings, and manage DMA data transfer threads.
Public Functions
Constructs a Server object.
- Parameters:
controller – The controller object for handling the measurement process.
port – The port on which the server listens for connections.
exit_signal – The exit signal (handled by SIGINT by Controller).
-
~Server() = default
Destroys the Server object.
-
std::mutex &get_message_mutex()
Gets the message mutex.
This mutex is used to make sure that each message is handled after each other. It is accessed by the clients when handling a message.
- Returns:
The message mutex.
-
void run()
Runs the server.
It calls stop() when the server is stopped (by SIGINT signal).
-
void stop()
Stops the server.
-
TmpMeasurementConfig get_measurement_config()
Gets the temporary measurement configuration.
The copy is a non-atomic version of the measurement configuration.
- Returns:
The temporary measurement configuration.
-
void set_measurement_config(TmpMeasurementConfig config)
Sets the temporary measurement configuration.
The atomic measurement configuration is overwritten with the temporary measurement configuration.
- Parameters:
config – The temporary measurement configuration.
-
void apply_measurement_config()
Applies the temporary measurement configuration.
It sets the corresponding measurement configuration in the controller object (hardware registers).
-
void start_dma_data_thread()
Starts the DMA data thread for each measurement.
-
void destroy_dma_data_thread()
Periodically checks if the DMA data thread is finished and destroys it.
-
bool start_measurement()
Starts a measurement.
- Returns:
True if the measurement process started successfully, false otherwise.
-
void stop_measurement()
Stops the measurement process.
It sets the remaining measurement time to 1ms to let the DMA data thread finish by itself.
Private Functions
-
void notify_clients(MessageType type, const nlohmann::json &data)
Notifies all clients with the specified message type and data.
- Parameters:
type – The message type.
data – The message data.
-
void start_exit_thread()
Starts the thread for handling the exit signal.
-
void start_dma_thread_destroy_thread()
Starts the thread for handling the DMA data thread.
Private Members
-
kn::port_t port_
The port on which the server listens for connections.
-
kn::tcp_socket listen_socket_
The socket on which the server listens for connections.
-
std::mutex clients_mutex_
The mutex for accessing the map of connected clients.
-
std::mutex message_mutex_
The mutex so that each message is handled after each other.
-
std::unique_ptr<std::thread> exit_thread_ = nullptr
The thread for handling the exit signal.
-
std::unique_ptr<std::thread> dma_data_thread_ = nullptr
The thread for handling the DMA data.
-
std::atomic<bool> dma_data_thread_finished_ = false
Indicates if the DMA data thread is finished.
-
std::unique_ptr<std::thread> destroy_dma_thread_thread_ = nullptr
The thread for destroying the DMA data thread.
-
std::shared_ptr<controller::Controller> controller_
The controller object for handling the measurement process.
-
std::atomic<bool> *exit_
The exit signal (handled by SIGINT by Controller).
-
MeasurementConfig measurement_config_ = {}
The measurement configuration.
Client class
-
class Client
Represents a client connection in the network component.
The Client class manages the communication with a client connected to the server. It handles sending and receiving data, processing messages, and managing the client’s configuration.
Public Functions
Constructor for the Client class.
- Parameters:
sock – The socket for the client connection.
server – The server object.
controller – The controller object.
client_id – The ID of the client.
-
~Client()
Destructor for the Client class.
-
Client() = delete
-
void run()
Starts the client.
It starts the threads for sending and receiving data.
-
bool is_removable()
Checks if the client can be removed.
- Returns:
True if the client can be removed, false otherwise.
-
bool get_wants_raw_data() const
Checks if the client wants to receive DMA raw data.
- Returns:
True if the client wants to receive DMA raw data, false otherwise.
-
bool get_wants_count_data() const
Checks if the client wants to receive DMA count data.
- Returns:
True if the client wants to receive DMA count data, false otherwise.
-
void set_send_data_failed(bool send_data_failed)
Sets the flag indicating if sending of DMA data failed.
- Parameters:
send_data_failed – True if sending of DMA data failed, false otherwise.
-
bool get_send_data_failed() const
Checks if sending of DMA data failed.
- Returns:
True if sending of DMA data failed, false otherwise.
-
bool receive_data()
Receives data from the client.
- Returns:
True if data was received successfully, false otherwise.
-
bool send_data()
Sends data to the client.
- Returns:
True if data was sent successfully, false otherwise.
-
bool send_raw(const std::byte *header, const std::byte *data, std::size_t size)
packs the data and sends it over the socket
This function is used by the send_data function to actually send the data.
- Parameters:
header – The header of the message.
data – The data of the message.
size – The size of the data.
- Returns:
True if the data was sent successfully, false otherwise.
-
void handle_message(MessageType type, const nlohmann::json &data)
Handles a message received from the client.
- Parameters:
type – The type of the message.
data – The data of the message.
-
void handle_start(const nlohmann::json &data)
Handles a start message received from the client.
It starts the measurement if the client is connected and the controller is not running. It optionally may set the client and measurement configuration.
Example of the JSON data to send without configuration:
{}
Example of the JSON data to send with configuration:
{ "client-config": { "wants-data": { "raw": false, "count": false } }, "measurement-config": { "channels": 1, "invert": 0, "fir": 0, "offset-1": 10, "offset-2": -10, "measurement-time": 100, "trigger-value-1": 15, "trigger-value-2": 93, "pre-gate-1": 10, "pre-gate-2": 7, "long-gate-1": 100, "long-gate-2": 80 } }
Response (error):
{ "status": { "type": "error", "message": "measurement already running" } }
Response (success):
{ "status": { "type": "success" }, "client-config": { "wants-data": { "raw": false, "count": false } }, "measurement-config": { "state": "running", "channels": 1, "invert": 0, "fir": 0, "offset-1": 10, "offset-2": -10, "measurement-time": 100, "trigger-value-1": 15, "trigger-value-2": 93, "pre-gate-1": 10, "pre-gate-2": 7, "long-gate-1": 100, "long-gate-2": 80 } }
- Parameters:
data – The data of the message.
-
void handle_stop()
Handles a stop message received from the client.
It stops the measurement if the client is connected and the controller is running. This message does not require any user data.
Example of the JSON data to send:
{}
Response (error):
{ "status": { "type": "error", "message": "measurement not running" } }
Response (success):
{ "status": { "type": "success" } }
-
void handle_connect(const nlohmann::json &data)
Handles a connect message received from the client.
It is the first message to send to the server.
The connect message must include the client version. The format of the version is “vX.Y.Z”. The response contains the server version and the client and measurement configuration on success.
Example of the JSON data to send:
{ "version": "v0.0.1", }
Response (error):
{ "status": { "type": "error", "message": "version mismatch" }, "version": "v0.0.1" }
Response (success):
{ "status": { "type": "success" }, "version": "v0.0.1", "client-config": { "wants-data": { "raw": false, "count": false } }, "measurement-config": { "state": "running", "channels": 1, "invert": 0, "fir": 0, "offset-1": 10, "offset-2": -10, "measurement-time": 100, "trigger-value-1": 15, "trigger-value-2": 93, "pre-gate-1": 10, "pre-gate-2": 7, "long-gate-1": 100, "long-gate-2": 80 } }
-
void handle_state()
Handles a state message received from the client.
It returns the current measurement state (idle, running or stopped). This message does not require any user data.
Example of the JSON data send:
{}
Response (error):
{ "status": { "type": "error", "message": "not connected" } }
Response (success):
{ "status": { "type": "success" }, "measurement-config": { "state": "running" } }
-
void handle_settings(const nlohmann::json &data)
Handles a settings message received from the client.
It sets the client and measurement configuration if the client is connected. If no configuration is sent, the current configuration is returned.
Example of the JSON data to send without configuration:
{}
Example of the JSON data to send with configuration:
{ "client-config": { "wants-data": { "raw": false, "count": false } }, "measurement-config": { "channels": 1, "invert": 0, "fir": 0, "offset-1": 10, "offset-2": -10, "measurement-time": 100, "trigger-value-1": 15, "trigger-value-2": 93, "pre-gate-1": 10, "pre-gate-2": 7, "long-gate-1": 100, "long-gate-2": 80 } }
Response (error):
{ "status": { "type": "error", "message": "cannot change measurement config during measurement" } }
Response (success):
{ "status": { "type": "success" }, "client-config": { "wants-data": { "raw": false, "count": false } }, "measurement-config": { "state": "running", "channels": 1, "invert": 0, "fir": 0, "offset-1": 10, "offset-2": -10, "measurement-time": 100, "trigger-value-1": 15, "trigger-value-2": 93, "pre-gate-1": 10, "pre-gate-2": 7, "long-gate-1": 100, "long-gate-2": 80 } }
- Parameters:
data – The data of the message.
-
void handle_ping()
Handles a ping message received from the client.
It returns the current measurement state (idle, running or stopped). This message does not require any user data.
Example of the JSON data send:
{}
Response (error):
{ "status": { "type": "error", "message": "not connected" } }
Response (success):
{ "status": { "type": "success" } }
-
bool validate_channels(uint8_t channels)
Validates the channels for DMA operations specified in the client configuration.
The channels are valid if it’s value is Channel::kChannel1, Channel::kChannel2, or Channel::kBoth.
- Parameters:
channels – The channels to validate.
- Returns:
True if the channels are valid, false otherwise.
-
void apply_client_config(ClientConfig client_config)
Applies the client configuration.
- Parameters:
client_config – The client configuration to apply.
-
void add_message_to_queue(MessageType type, const nlohmann::json &data)
Adds a message to the send queue.
- Parameters:
type – The type of the message.
data – The data of the message.
-
void wait_send_dma_data()
Waits for the sending of DMA data to complete.
This function runs in a loop until the sending of DMA data is complete.
-
bool get_dma_descriptor_handled(uint8_t dma_index, uint32_t dma_descriptor)
Checks if a DMA descriptor was handled.
- Parameters:
dma_index – The ID of the DMA.
dma_descriptor – The descriptor of the DMA.
- Returns:
True if the DMA descriptor was handled, false otherwise.
-
void set_dma_descriptor_handled(uint8_t dma_index, uint32_t dma_descriptor, bool value)
Sets the flag indicating if a DMA descriptor was handled.
- Parameters:
dma_index – The ID of the DMA.
dma_descriptor – The descriptor of the DMA.
value – The value to set.
-
void reset_dma_descriptor_handled()
Resets the flags indicating if DMA descriptors were handled.
All values are set to true.
Public Static Functions
-
static bool is_socket_valid(kn::socket_status status)
Checks if the socket status is valid.
- Parameters:
status – The socket status to check.
- Returns:
True if the socket status is valid, false otherwise.
-
static TmpMeasurementConfig parse_measurement_config(nlohmann::json data, TmpMeasurementConfig measurement_config)
Parses the measurement configuration from a JSON object.
- Parameters:
data – The JSON object containing the measurement configuration.
measurement_config – The current measurement configuration.
- Returns:
The parsed measurement configuration.
-
static ClientConfig parse_client_config(nlohmann::json data, ClientConfig client_config)
Parses the client configuration from a JSON object.
- Parameters:
data – The JSON object containing the client configuration.
client_config – The current client configuration.
- Returns:
The parsed client configuration.
Private Members
-
std::unique_ptr<kn::tcp_socket> socket_ = nullptr
The socket for the client connection.
-
ClientConfig client_config_ = {}
The configuration for the client.
-
bool send_data_failed_ = false
Indicates if the sending of DMA data was too slow and thus failed.
-
std::queue<std::tuple<MessageType, nlohmann::json>> send_queue_
The queue for messages to send to the client.
-
std::mutex queue_mutex_
The mutex for accessing the send queue.
-
std::unique_ptr<std::thread> send_thread_ = nullptr
The thread for sending data to the client.
-
std::unique_ptr<std::thread> receive_thread_ = nullptr
The thread for receiving data from the client.
-
std::weak_ptr<controller::Controller> controller_
The controller object.
-
std::array<std::array<bool, std::max(kDmaRawDescriptorPerDma, kDmaCountDescriptorPerDma)>, kDmaCount * 2> dma_descriptor_handled_ = {}
Indicates if a DMA descriptor was handled.
-
std::mutex dma_descriptor_handled_mutex_
The mutex for accessing the DMA descriptor handled array.
-
bool connected_ = false
Indicates if the client is connected.
-
std::atomic<bool> is_removable_ = false
Indicates if the client can be removed.
-
uint32_t id_
The ID of the client.
-
std::atomic<bool> exit_ = false
The exit signal (set when the client disconnects or indirectly by SIGINT by Controller).
MeasurementConfig and TmpMeasurementConfig
The measurement configuration is implemented in two different classes because the measurement holds atomic values. To modify the measurement configuration a temporary configuration is used by copying the current configuration into a non-atomic version. This is then modified and copied back into the atomic version.
-
class MeasurementConfig
The MeasurementConfig class represents the configuration for a measurement.
The MeasurementConfig class is used to store the configuration for a measurement. All values are stored as atomic values to allow for concurrent access.
Public Functions
-
inline MeasurementConfig &operator=(const TmpMeasurementConfig &other)
Copy assignment operator from TmpMeasurementConfig.
- Parameters:
other – The TmpMeasurementConfig object to copy from.
- Returns:
A reference to the modified MeasurementConfig object.
-
inline explicit operator TmpMeasurementConfig() const
Conversion operator to convert to a non-atomic copy.
- Returns:
A non-atomic copy of the MeasurementConfig object.
-
inline MeasurementState get_state() const
Get the state of the measurement.
- Returns:
The state of the measurement.
-
inline void set_state(MeasurementState state)
Set the state of the measurement.
- Parameters:
state – The state to set.
-
inline controller::Channel get_channels() const
Get the channels used for DMA operations.
The channels used for DMA operations (1 -> first, 2 -> second, 3 -> both).
- Returns:
The channels used for DMA operations.
-
inline void set_channels(controller::Channel channels)
Set the channels for DMA operations.
- Parameters:
channels – The channels to set.
-
inline controller::BLRInvertFIRChannel get_invert_channels() const
Get the channels to be inverted.
The channels to be inverted (1 -> first, 2 -> second, 3 -> both).
- Returns:
The channels to be inverted.
-
inline void set_invert_channels(controller::BLRInvertFIRChannel invert_channels)
Set the channels to be inverted.
- Parameters:
invert_channels – The channels to set.
-
inline controller::BLRInvertFIRChannel get_fir_channels() const
Get the channels to be filtered by an FIR filter.
The channels to be filtered (0 -> None, 1 -> first, 2 -> second, 3 -> both).
- Returns:
The channels to be filtered.
-
inline void set_fir_channels(controller::BLRInvertFIRChannel fir_channels)
Set the channels to be filtered by an FIR filter.
- Parameters:
fir_channels – The channels to set.
-
inline controller::BLRInvertFIRChannel get_blr_channels() const
Get the channels for baseline restoration.
The channels for baseline restoration (0 -> None, 1 -> first, 2 -> second, 3 -> both).
- Returns:
The channels for baseline restoration.
-
inline void set_blr_channels(controller::BLRInvertFIRChannel blr_channels)
Set the channels for baseline restoration.
- Parameters:
blr_channels – The channels to set.
-
inline uint16_t get_blr_pre_gate_c1() const
Get the pre gate value for baseline restoration of channel 1.
- Returns:
The pre-gate value for baseline restoration of channel 1.
-
inline void set_blr_pre_gate_c1(uint16_t blr_pre_gate_c1)
Set the pre gate value for baseline restoration of channel 1.
- Parameters:
blr_pre_gate_c1 – The pre gate value to set for baseline restoration of channel 1.
-
inline uint16_t get_blr_pre_gate_c2() const
Get the pre gate value for baseline restoration of channel 2.
- Returns:
The pre-gate value for baseline restoration of channel 2.
-
inline void set_blr_pre_gate_c2(uint16_t blr_pre_gate_c2)
Set the pre gate value for baseline restoration of channel 2.
- Parameters:
blr_pre_gate_c2 – The pre gate value to set for baseline restoration of channel 2.
-
inline int16_t get_offset_c1() const
Get the offset of channel 1.
- Returns:
The offset of channel 1.
-
inline void set_offset_c1(int16_t offset_c1)
Set the offset of channel 1.
- Parameters:
offset_c1 – The offset to set for channel 1.
-
inline int16_t get_offset_c2() const
Get the offset of channel 2.
- Returns:
The offset of channel 2.
-
inline void set_offset_c2(int16_t offset_c2)
Set the offset of channel 2.
- Parameters:
offset_c2 – The offset to set for channel 2.
-
inline uint32_t get_measurement_time() const
Get the measurement time.
- Returns:
The measurement time.
-
inline void set_measurement_time(uint32_t measurement_time)
Set the measurement time.
- Parameters:
measurement_time – The measurement time to set.
-
inline int16_t get_trigger_value_c1() const
Get the trigger value of channel 1.
- Returns:
The trigger value of channel 1.
-
inline void set_trigger_value_c1(int16_t trigger_value_c1)
Set the trigger value of channel 1.
- Parameters:
trigger_value_c1 – The trigger value to set for channel 1.
-
inline int16_t get_trigger_value_c2() const
Get the trigger value of channel 2.
- Returns:
The trigger value of channel 2.
-
inline void set_trigger_value_c2(int16_t trigger_value_c2)
Set the trigger value of channel 2.
- Parameters:
trigger_value_c2 – The trigger value to set for channel 2.
-
inline uint16_t get_pre_gate_c1() const
Get the pre-gate value of channel 1.
- Returns:
The pre-gate value of channel 1.
-
inline void set_pre_gate_c1(uint16_t pre_gate_c1)
Set the pre-gate value of channel 1.
- Parameters:
pre_gate_c1 – The pre-gate value to set for channel 1.
-
inline uint16_t get_pre_gate_c2() const
Get the pre-gate value of channel 2.
- Returns:
The pre-gate value of channel 2.
-
inline void set_pre_gate_c2(uint16_t pre_gate_c2)
Set the pre-gate value of channel 2.
- Parameters:
pre_gate_c2 – The pre-gate value to set for channel 2.
-
inline uint16_t get_long_gate_c1() const
Get the long-gate value of channel 1.
- Returns:
The long-gate value of channel 1.
-
inline void set_long_gate_c1(uint16_t long_gate_c1)
Set the long-gate value of channel 1.
- Parameters:
long_gate_c1 – The long-gate value to set for channel 1.
-
inline uint16_t get_long_gate_c2() const
Get the long-gate value of channel 2.
- Returns:
The long-gate value of channel 2.
-
inline void set_long_gate_c2(uint16_t long_gate_c2)
Set the long-gate value of channel 2.
- Parameters:
long_gate_c2 – The long-gate value to set for channel 2.
Private Members
-
std::atomic<MeasurementState> state_ = MeasurementState::kIdle
The measurement state.
-
std::atomic<controller::Channel> channels_ = controller::Channel::kNone
The channels to be used for the DMA operations (1 -> first, 2 -> second, 3 -> both).
-
std::atomic<controller::BLRInvertFIRChannel> invert_channels_ = controller::BLRInvertFIRChannel::kNoChannel
The channels to be inverted (1 -> first, 2 -> second, 3 -> both).
-
std::atomic<controller::BLRInvertFIRChannel> fir_channels_ = controller::BLRInvertFIRChannel::kNoChannel
The channels to be filtered by an FIR filter (0 -> None, 1 -> first, 2 -> second, 3 -> both).
-
std::atomic<controller::BLRInvertFIRChannel> blr_channels_ = controller::BLRInvertFIRChannel::kNoChannel
The channels for baseline restoration (0 -> None, 1 -> first, 2 -> second, 3 -> both).
-
std::atomic<uint16_t> blr_pre_gate_c1_ = 0
The number of samples to go back for the baseline restoration of channel 1.
-
std::atomic<uint16_t> blr_pre_gate_c2_ = 0
The number of samples to go back for the baseline restoration of channel 2.
-
std::atomic<int16_t> offset_c1_ = 0
The offset of channel 1 in units of the ADC.
-
std::atomic<int16_t> offset_c2_ = 0
The offset of channel 2 in units of the ADC.
-
std::atomic<uint32_t> measurement_time_ = 0
The measurement time.
-
std::atomic<int16_t> trigger_value_c1_ = 0
The trigger value of channel 1 in units of the ADC.
-
std::atomic<int16_t> trigger_value_c2_ = 0
The trigger value of channel 2 in units of the ADC.
-
std::atomic<uint16_t> pre_gate_c1_ = 0
The number of samples for the pre gate of channel 1.
-
std::atomic<uint16_t> pre_gate_c2_ = 0
The number of samples for the pre gate of channel 2.
-
std::atomic<uint16_t> long_gate_c1_ = 0
The number of samples for the long gate of channel 1.
-
std::atomic<uint16_t> long_gate_c2_ = 0
The number of samples for the long gate of channel 2.
-
inline MeasurementConfig &operator=(const TmpMeasurementConfig &other)
-
class TmpMeasurementConfig
The TmpMeasurementConfig class represents a non-atomic version of the MeasurementConfig class.
Public Functions
-
inline explicit TmpMeasurementConfig(const MeasurementConfig &other)
Copy constructor from MeasurementConfig.
- Parameters:
other – The MeasurementConfig object to copy from.
-
inline TmpMeasurementConfig &operator=(const MeasurementConfig &other)
Copy assignment operator from MeasurementConfig.
- Parameters:
other – The MeasurementConfig object to copy from.
- Returns:
A reference to the modified TmpMeasurementConfig object.
-
TmpMeasurementConfig() = default
-
inline MeasurementState get_state() const
Get the state of the measurement.
- Returns:
The state of the measurement.
-
inline void set_state(MeasurementState state)
Set the state of the measurement.
- Parameters:
state – The state to set.
-
inline controller::Channel get_channels() const
Get the channels for DMA operations.
The channels to be used for DMA operations (1 -> first, 2 -> second, 3 -> both).
- Returns:
The channels for DMA operations.
-
inline void set_channels(controller::Channel channels)
Set the channels for DMA operations.
- Parameters:
channels – The channels to set for DMA operations.
-
inline controller::BLRInvertFIRChannel get_invert_channels() const
Get the channels to be inverted.
The channels to be inverted (1 -> first, 2 -> second, 3 -> both).
- Returns:
The channels to be inverted.
-
inline void set_invert_channels(controller::BLRInvertFIRChannel invert_channels)
Set the channels to be inverted.
- Parameters:
invert_channels – The channels to be inverted.
-
inline controller::BLRInvertFIRChannel get_fir_channels() const
Get the channels to be filtered by an FIR filter.
The channels to be filtered (0 -> None, 1 -> first, 2 -> second, 3 -> both).
- Returns:
The channels to be filtered.
-
inline void set_fir_channels(controller::BLRInvertFIRChannel fir_channels)
Set the channels to be filtered by an FIR filter.
- Parameters:
fir_channels – The channels to set.
-
inline controller::BLRInvertFIRChannel get_blr_channels() const
Get the channels for baseline restoration.
The channels for baseline restoration (0 -> None, 1 -> first, 2 -> second, 3 -> both).
- Returns:
The channels for baseline restoration.
-
inline void set_blr_channels(controller::BLRInvertFIRChannel blr_channels)
Set the channels for baseline restoration.
- Parameters:
blr_channels – The channels for baseline restoration.
-
inline uint16_t get_blr_pre_gate_c1() const
Get the pre gate value for the baseline restoration of channel 1.
- Returns:
The pre gate value for the baseline restoration of channel 1.
-
inline void set_blr_pre_gate_c1(uint16_t blr_pre_gate_c1)
Set the pre gate value for the baseline restoration of channel 1.
- Parameters:
blr_pre_gate_c1 – The pre gate value to set for the baseline restoration for channel 1.
-
inline uint16_t get_blr_pre_gate_c2() const
Get the pre gate value for the baseline restoration of channel 2.
- Returns:
The pre gate value for the baseline restoration of channel 2.
-
inline void set_blr_pre_gate_c2(uint16_t blr_pre_gate_c2)
Set the pre gate value for the baseline restoration of channel 2.
- Parameters:
blr_pre_gate_c2 – The pre gate value to set for the baseline restoration for channel 2.
-
inline int16_t get_offset_c1() const
Get the offset for channel 1.
- Returns:
The offset for channel 1.
-
inline void set_offset_c1(int16_t offset_c1)
Set the offset for channel 1.
- Parameters:
offset_c1 – The offset to set for channel 1.
-
inline int16_t get_offset_c2() const
Get the offset for channel 2.
- Returns:
The offset for channel 2.
-
inline void set_offset_c2(int16_t offset_c2)
Set the offset for channel 2.
- Parameters:
offset_c2 – The offset to set for channel 2.
-
inline uint32_t get_measurement_time() const
Get the measurement time.
- Returns:
The measurement time.
-
inline void set_measurement_time(uint32_t measurement_time)
Set the measurement time.
- Parameters:
measurement_time – The measurement time to set.
-
inline int16_t get_trigger_value_c1() const
Get the trigger value for channel 1.
- Returns:
The trigger value for channel 1.
-
inline void set_trigger_value_c1(int16_t trigger_value_c1)
Set the trigger value for channel 1.
- Parameters:
trigger_value_c1 – The trigger value to set for channel 1.
-
inline int16_t get_trigger_value_c2() const
Get the trigger value for channel 2.
- Returns:
The trigger value for channel 2.
-
inline void set_trigger_value_c2(int16_t trigger_value_c2)
Set the trigger value for channel 2.
- Parameters:
trigger_value_c2 – The trigger value to set for channel 2.
-
inline uint16_t get_pre_gate_c1() const
Get the pre-gate value of channel 1.
- Returns:
The pre-gate value of channel 1.
-
inline void set_pre_gate_c1(uint16_t pre_gate_c1)
Set the pre-gate value of channel 1.
- Parameters:
pre_gate_c1 – The pre-gate value to set for channel 1.
-
inline uint16_t get_pre_gate_c2() const
Get the pre-gate value of channel 2.
- Returns:
The pre-gate value of channel 2.
-
inline void set_pre_gate_c2(uint16_t pre_gate_c2)
Set the pre-gate value of channel 2.
- Parameters:
pre_gate_c2 – The pre-gate value to set for channel 2.
-
inline uint16_t get_long_gate_c1() const
Get the long-gate value of channel 1.
- Returns:
The long-gate value of channel 1.
-
inline void set_long_gate_c1(uint16_t long_gate_c1)
Set the long-gate value of channel 1.
- Parameters:
long_gate_c1 – The long-gate value to set for channel 1.
-
inline uint16_t get_long_gate_c2() const
Get the long-gate value of channel 2.
- Returns:
The long-gate value of channel 2.
-
inline void set_long_gate_c2(uint16_t long_gate_c2)
Set the long-gate value of channel 1.
- Parameters:
long_gate_c2 – The long-gate value to set for channel 2.
Private Members
-
MeasurementState state_ = MeasurementState::kIdle
The measurement state.
-
controller::Channel channels_ = controller::Channel::kNone
The channels to be used for the DMA operations (1 -> first, 2 -> second, 3 -> both).
-
controller::BLRInvertFIRChannel invert_channels_ = controller::BLRInvertFIRChannel::kNoChannel
The channels to be inverted (1 -> first, 2 -> second, 3 -> both).
-
controller::BLRInvertFIRChannel fir_channels_ = controller::BLRInvertFIRChannel::kNoChannel
The channels to be filtered by an FIR filter (0 -> None, 1 -> first, 1 -> second, 3 -> both).
-
controller::BLRInvertFIRChannel blr_channels_ = controller::BLRInvertFIRChannel::kNoChannel
The channels for baseline restoration (0 -> None, 1 -> first, 1 -> second, 3 -> both).
-
uint16_t blr_pre_gate_c1_ = 0
The number of samples to go back for baseline restoration of channel 1.
-
uint16_t blr_pre_gate_c2_ = 0
The number of samples to go back for baseline restoration of channel 2.
-
int16_t offset_c1_ = 0
The offset of for channel 1 in units of the ADC.
-
int16_t offset_c2_ = 0
The offset of for channel 2 in units of the ADC.
-
uint32_t measurement_time_ = 0
The measurement time.
-
int16_t trigger_value_c1_ = 0
The trigger value of for channel 1 in units of the ADC.
-
int16_t trigger_value_c2_ = 0
The trigger value of for channel 2 in units of the ADC.
-
uint16_t pre_gate_c1_ = 0
The number of samples for the pre gate of channel 1.
-
uint16_t pre_gate_c2_ = 0
The number of samples for the pre gate of channel 2.
-
uint16_t long_gate_c1_ = 0
The number of samples for the long gate of channel 1.
-
uint16_t long_gate_c2_ = 0
The number of samples for the long gate of channel 2.
-
inline explicit TmpMeasurementConfig(const MeasurementConfig &other)
Client configuration structure
-
struct ClientConfig
The ClientConfig struct represents the configuration for a client.
Message types enumeration
-
enum class nexmess::components::network::MessageType : uint8_t
Enumeration representing the available message types.
Each message follows the same structure:
The first unsigned byte is the message type
The following four bytes (unsigned 32 bit integer) are the message length
The rest of the message is the actual message
Values:
-
enumerator kDmaRaw0
kDmaRaw0 is data for the first DMA (raw data)
This message is used to send the raw data from the first DMA to the client. The raw data consists of 16 bit signed integers representing the arbitrary values from the ADC.
If this message was sent by the client an error is returned as JSON.
{ "status", { "type": "error", "message": "received message type only sent by server" } }
-
enumerator kDmaRaw1
kDmaRaw1 is data for the first DMA (raw data)
See kDmaRaw0 for more information.
-
enumerator kStart
kDmaCount0 is data for the first DMA (count data)
This message is used to send the count data from the first DMA to the client. The count data consists of 64 bit unsigned integers representing the number of clock cycles between two trigger events.
If this message was sent by the client an error is returned as JSON.
{ "status", { "type": "error", "message": "received message type only sent by server" } } / kDmaCount0, kDmaCount1,
Example of the JSON data to send with configuration:
{ "client-config": { "wants-data": { "raw": false, "count": false } }, "measurement-config": { "channels": 1, "fir" : 0, "invert" : 0, "offsets" : 0, "blr" : 1, "blr-pre-gate-1" : 100, "blr-pre-gate-2" : 100, "measurement-time": 100, "trigger-values": 15, "pre-gates": 10, "long-gates": 100 } }
Response (error):
{ "status": { "type": "error", "message": "measurement already running" } }
The following error messages are possible:
”not connected”
”measurement already running”
”channels must be 1, 2 or 3 (for both)”
”could not start measurement”
Response (success):
{ "status": { "type": "success" }, "client-config": { "wants-data": { "raw": false, "count": false } }, "measurement-config": { "channels": 1, "fir" : 0, "invert" : 0, "offsets" : 0, "blr" : 1, "blr-pre-gate-1" : 100, "blr-pre-gate-2" : 50, "measurement-time": 100, "trigger-values": 15, "pre-gates": 10, "long-gates": 100 } }
-
enumerator kStop
kStop is a message to stop the acquisition
It stops the measurement if the client is connected. This message does not require any user data.
Example of the JSON data to send:
{}
Response (error):
{ "status": { "type": "error", "message": "measurement not running" } }
The following error messages are possible:
”not connected”
”measurement not running”
Response (success):
{ "status": { "type": "success" } }
- Param data:
The data of the message.
-
enumerator kConnect
kConnect is a message to connect to the server
It is the first message to send to the server.
The connect message must include the client version. The format of the version is “vX.Y.Z”. The response contains the server version and the client and measurement configuration on success.
Example of the JSON data to send:
{ "version": "v0.0.1", }
Response (error):
{ "status": { "type": "error", "message": "version mismatch" }, "version": "v0.0.1" }
The following error messages are possible:
”already connected”
”no version given”
”invalid version given”
”version mismatch”
Response (success):
{ "status": { "type": "success" }, "version": "v0.0.1", "client-config": { "wants-data": { "raw": false, "count": false } }, "measurement-config": { "channels": 1, "fir" : 0, "invert" : 0, "offsets" : 0, "blr" : 1, "blr-pre-gate-1" : 100, "blr-pre-gate-2" : 50, "measurement-time": 100, "trigger-values": 15, "pre-gates": 10, "long-gates": 100 } }
-
enumerator kState
kState is a message to get the current state of the server
It returns the current measurement state (idle, running or stopped). This message does not require any user data.
Example of the JSON data send:
{}
Response (error):
{ "status": { "type": "error", "message": "not connected" } }
The following error messages are possible:
”not connected”
Response (success):
{ "status": { "type": "success" }, "measurement-config": { "state": "running" } }
-
enumerator kSettings
kSettings is a message to send the settings to the server
It sets the client and measurement configuration if the client is connected. If no configuration is sent, the current configuration is returned.
Example of the JSON data to send without configuration:
{}
Example of the JSON data to send with configuration:
{ "client-config": { "wants-data": { "raw": false, "count": false } }, "measurement-config": { "channels": 1, "fir" : 0, "invert" : 0, "offsets" : 0, "blr" : 1, "blr-pre-gate-1" : 100, "blr-pre-gate-2" : 50, "measurement-time": 100, "trigger-values": 15, "pre-gates": 10, "long-gates": 100 } }
Response (error):
{ "status": { "type": "error", "message": "cannot change measurement config during measurement" } }
The following error messages are possible:
”not connected”
”cannot change measurement config during measurement”
”channels must be 1, 2 or 3 (for both)”
Response (success):
{ "status": { "type": "success" }, "client-config": { "wants-data": { "raw": false, "count": false } }, "measurement-config": { "channels": 1, "fir" : 0, "invert" : 0, "offsets" : 0, "blr" : 1, "blr-pre-gate-1" : 100, "blr-pre-gate-2" : 50, "measurement-time": 100, "trigger-values": 15, "pre-gates": 10, "long-gates": 100 } }
-
enumerator kNotify
kNotify is a message to notify the clients about things
It is used to notify the clients about things like the measurement state.
If this message was sent by the client an error is returned as JSON.
{ "status", { "type": "error", "message": "received message type only sent by server" } }
The JSON of a notification always contains a “status” object with a type string value. The type string value matches the name of the actual notification object with further information.
The following notifications are possible:
Measurement config:
{ "status": { "type": "measurement-config" }, "measurement-config": { "state": "stopped" } }
The state my be “idle”, “running” or “stopped”.
Buffer full:
{ "status": { "type": "dma", "message": "buffer full" }, "dma": { "id": 1 } }
The id is the id of the DMA (0 or 1).
-
enumerator kPing
kPing is a message to check if the server is still alive
It is used to check if the server is still alive. This message does not require any user data.
Example of the JSON data to send:
{}
Response (error):
{ "status": { "type": "error", "message": "not connected" } }
The following error messages are possible:
”not connected”
Response (success):
{ "status": { "type": "success" } }
-
enumerator kNone
kNone marks the last Type (is used to determine valid types)