TaskController 2.2.23
A light-weight UI that serves as the task/parameter front-end.
Loading...
Searching...
No Matches
Network Connections

Encompasses network connection functions and configuration settings. This group includes functions and structures related to establishing and managing network connections between the controller application and other components, such as servers or devices. More...

Functions

int initSockets (Config *config)
 Initializes UDP sockets and server address structures.
 
int SendCommandToServer (Command cmd)
 Sends a command to the server.
 
int SendTaskParametersToServer (TaskParameters *params)
 Sends task parameters to the server.
 
int SendNextTargetToServer (TrialTargets *tSeq)
 Sends task target data to the server.
 
int SendCalibrationDataToServer (CalibrationData *calData)
 Sends the current calibration data to the server.
 
int SendDispenseCommandToRewardServer ()
 Sends a command to the reward device to issue the desired dispense.
 
void ReceiveStateUpdatesFromServer (char *state_input_buffer, socklen_t *serverAddrStateInLen)
 Receives state updates from the server via UDP socket.
 
void ReceiveParameterUpdatesFromServer (char *parameters_input_buffer, socklen_t *serverAddrParametersInLen, TaskParameters *parameters)
 Receives parameter updates from the server via UDP socket.
 
void ReceiveRequestsFromServer (char *req_input_buffer, socklen_t *serverAddrReqInLen)
 Receives requests from the server via UDP socket.
 
void ReceiveCalibrationsFromServer (char *calibration_buffer, socklen_t *serverAddrCalibrationInLen, CalibrationData *calData, TaskParameters *parameters)
 Receives calibration UDP data packets from the server.
 

Variables

Config * config
 Configuration struct used by the application.
 
SOCKET udpSockCommandOut
 UDP socket to send "control" commands to the server.
 
SOCKET udpSockParametersOut
 UDP socket to send parameter changes to the server.
 
SOCKET udpSockTargetOut
 UDP socket to send updates in target positions to the server.
 
SOCKET udpSockRewardOut
 UDP socket to send commands to the reward dispenser.
 
SOCKET udpSockCalibrationOut
 UDP socket to send calibration data to the server.
 
SOCKET udpSockStateIn
 UDP socket to receive state updates (trial counts etc) from the server.
 
SOCKET udpSockParametersIn
 UDP socket to receive initial parameter state message from server.
 
SOCKET udpSockReqIn
 UDP socket to receive requests from the server, such as to issue a reward or generate new targets.
 
SOCKET udpSockCalibrationIn
 UDP socket to receive calibration updates from the server.
 
struct sockaddr_in serverAddrCommandOut
 UDP socket addresses associated with each socket.
 
struct sockaddr_in serverAddrParametersOut
 
struct sockaddr_in serverAddrTargetOut
 
struct sockaddr_in serverAddrRewardOut
 
struct sockaddr_in serverAddrCalibrationOut
 
struct sockaddr_in serverAddrStateIn
 
struct sockaddr_in serverAddrParametersIn
 
struct sockaddr_in serverAddrReqIn
 
struct sockaddr_in serverAddrCalibrationIn
 
char state_command_output_buffer [BYTES_STATE_COMMAND_BUFFER]
 Buffer for UDP Control Commands to be sent to server.
 
char reward_command_output_buffer [BYTES_REWARD_COMMAND_BUFFER]
 Buffer for UDP Control Commands to be sent to reward device.
 
char target_output_buffer [BYTES_STATE_TARGET_BUFFER]
 Buffer for UDP Target Locations to be sent to server.
 
char calibration_buffer [BYTES_STATE_CALIBRATION_BUFFER]
 Buffer for UDP calibration messages exchanged between server and application.
 
char edit_buffer [128]
 Buffer that holds string inputs from parameter UI elements.
 
char prev_subject [24]
 Global buffer to save the name of the subject sent with previous parameters.
 
Orientation prev_orientation
 Global variable to save the orientation sent with previous parameters.
 
char parameters_output_buffer [BYTES_STATE_PARAMETER_BUFFER]
 Buffer that is only used for exchanging parameters with server.
 

Detailed Description

Encompasses network connection functions and configuration settings. This group includes functions and structures related to establishing and managing network connections between the controller application and other components, such as servers or devices.

Function Documentation

◆ initSockets()

int initSockets ( Config * config)

Initializes UDP sockets and server address structures.

This function initializes UDP sockets and server address structures for communicating with the server. It creates separate sockets for controller and targets, and sets up the server address structures accordingly.

Parameters
configPointer to the configuration structure containing network settings.
Returns
EXIT_SUCCESS if sockets are initialized correctly, otherwise EXIT_FAILURE.

◆ ReceiveCalibrationsFromServer()

void ReceiveCalibrationsFromServer ( char * calibration_buffer,
socklen_t * serverAddrCalibrationInLen,
CalibrationData * calData,
TaskParameters * parameters )

Receives calibration UDP data packets from the server.

This function receives updated calibration data, for example on initialization or after the SendCalibrationCenterCommandToServer function has been invoked.

Parameters
calibration_bufferBuffer to store the received calibration message bytes.
serverAddrCalibrationInLenPointer to the length of the server address structure.
calDataPointer to the calibration data to update based on message contents.
parametersPointer to the parameter data structure.

◆ ReceiveParameterUpdatesFromServer()

void ReceiveParameterUpdatesFromServer ( char * parameters_input_buffer,
socklen_t * serverAddrParametersInLen,
TaskParameters * parameters )

Receives parameter updates from the server via UDP socket.

This function receives parameter updates from the server using a UDP socket, unpacks the received data into a TaskParameters struct, and updates the UI accordingly.

Parameters
parameters_input_bufferBuffer to store the received parameter data.
serverAddrParametersInLenPointer to the length of the server address structure.
parametersPointer to parameter data structure.

The parameter data is expected to be formatted according to the packing format used by the packParameters function.

◆ ReceiveRequestsFromServer()

void ReceiveRequestsFromServer ( char * req_input_buffer,
socklen_t * serverAddrReqInLen )

Receives requests from the server via UDP socket.

This function receives requests from the server using a UDP socket, parses the received data, and performs corresponding actions or operations.

Parameters
req_input_bufferBuffer to store the received request data.
serverAddrReqInLenPointer to the length of the server address structure.

The request data is expected to be formatted as follows:

  • Single character representing the type of request ('r' for reward, etc.)
  • Additional fields depending on the type of request

    Todo
    Implement handling of different types of requests:
    • Send the reward command to the reward dispenser device.
    • Send the next queued target.
    • Log or send information about direction, target, reward time, and volume.

◆ ReceiveStateUpdatesFromServer()

void ReceiveStateUpdatesFromServer ( char * state_input_buffer,
socklen_t * serverAddrStateInLen )

Receives state updates from the server via UDP socket.

This function receives state updates from the server using a UDP socket, updates local variables accordingly, and performs necessary UI updates.

Parameters
state_input_bufferBuffer to store the received state data.
serverAddrStateInLenPointer to the length of the server address structure.

The state data is expected to be formatted as a comma-separated string with the following fields:

  • Current successes (unsigned short)
  • Current attempts (unsigned short)
  • Total successes (unsigned short)
  • Total attempts (unsigned short)
  • Set index (unsigned short)
  • Paused status (unsigned char, 0 or 1)
  • Logging status (unsigned char, 0 or 1)

◆ SendCalibrationDataToServer()

int SendCalibrationDataToServer ( CalibrationData * calData)

Sends the current calibration data to the server.

Todo
Implement SendCalibrationDataToServer

◆ SendCommandToServer()

int SendCommandToServer ( Command cmd)

Sends a command to the server.

Parameters
cmdThe command to be sent to the server.
Returns
EXIT_SUCCESS if message sent successfully, else EXIT_FAILURE.

◆ SendDispenseCommandToRewardServer()

int SendDispenseCommandToRewardServer ( )

Sends a command to the reward device to issue the desired dispense.

Todo
Implement SendDispenseCommandToRewardServer

◆ SendNextTargetToServer()

int SendNextTargetToServer ( TrialTargets * tSeq)

Sends task target data to the server.

If there are no targets in the table, populates random targets before sending.

Parameters
tSeqPointer to the TaskTargets structure containing target data.
Returns
Returns EXIT_SUCCESS on successful sending, EXIT_FAILURE otherwise.

◆ SendTaskParametersToServer()

int SendTaskParametersToServer ( TaskParameters * params)

Sends task parameters to the server.

Parameters
paramsPointer to the task parameters structure to be sent.
Returns
EXIT_SUCCESS if message sent successfully, else EXIT_FAILURE.

Variable Documentation

◆ calibration_buffer

char calibration_buffer[BYTES_STATE_CALIBRATION_BUFFER]
extern

Buffer for UDP calibration messages exchanged between server and application.

◆ config

Config* config
extern

Configuration struct used by the application.

◆ edit_buffer

char edit_buffer[128]
extern

Buffer that holds string inputs from parameter UI elements.

◆ parameters_output_buffer

char parameters_output_buffer[BYTES_STATE_PARAMETER_BUFFER]
extern

Buffer that is only used for exchanging parameters with server.

◆ prev_orientation

Orientation prev_orientation
extern

Global variable to save the orientation sent with previous parameters.

◆ prev_subject

char prev_subject[24]
extern

Global buffer to save the name of the subject sent with previous parameters.

◆ reward_command_output_buffer

char reward_command_output_buffer[BYTES_REWARD_COMMAND_BUFFER]

Buffer for UDP Control Commands to be sent to reward device.

◆ serverAddrCalibrationIn

struct sockaddr_in serverAddrCalibrationIn
extern

◆ serverAddrCalibrationOut

struct sockaddr_in serverAddrCalibrationOut
extern

◆ serverAddrCommandOut

struct sockaddr_in serverAddrCommandOut
extern

UDP socket addresses associated with each socket.

◆ serverAddrParametersIn

struct sockaddr_in serverAddrParametersIn
extern

◆ serverAddrParametersOut

struct sockaddr_in serverAddrParametersOut
extern

◆ serverAddrReqIn

struct sockaddr_in serverAddrReqIn
extern

◆ serverAddrRewardOut

struct sockaddr_in serverAddrRewardOut
extern

◆ serverAddrStateIn

struct sockaddr_in serverAddrStateIn
extern

◆ serverAddrTargetOut

struct sockaddr_in serverAddrTargetOut
extern

◆ state_command_output_buffer

char state_command_output_buffer[BYTES_STATE_COMMAND_BUFFER]
extern

Buffer for UDP Control Commands to be sent to server.

◆ target_output_buffer

char target_output_buffer[BYTES_STATE_TARGET_BUFFER]
extern

Buffer for UDP Target Locations to be sent to server.

◆ udpSockCalibrationIn

SOCKET udpSockCalibrationIn
extern

UDP socket to receive calibration updates from the server.

◆ udpSockCalibrationOut

SOCKET udpSockCalibrationOut
extern

UDP socket to send calibration data to the server.

◆ udpSockCommandOut

SOCKET udpSockCommandOut
extern

UDP socket to send "control" commands to the server.

◆ udpSockParametersIn

SOCKET udpSockParametersIn
extern

UDP socket to receive initial parameter state message from server.

◆ udpSockParametersOut

SOCKET udpSockParametersOut
extern

UDP socket to send parameter changes to the server.

◆ udpSockReqIn

SOCKET udpSockReqIn
extern

UDP socket to receive requests from the server, such as to issue a reward or generate new targets.

◆ udpSockRewardOut

SOCKET udpSockRewardOut
extern

UDP socket to send commands to the reward dispenser.

◆ udpSockStateIn

SOCKET udpSockStateIn
extern

UDP socket to receive state updates (trial counts etc) from the server.

◆ udpSockTargetOut

SOCKET udpSockTargetOut
extern

UDP socket to send updates in target positions to the server.