LuckyServer¶
The server is listening on LuckyLoop at port 1219. During boot-up of the app, it will print the host IP address to the TFT. Read it from there. Start the Python Client on your measurement PC, i.e. luckyloop.client.Client(host, port)
using these values to connect it with the LuckyServer.
The server accepts specific ascii-encoded commands following the format
[command: arg1, arg2, ...]
Example command
[set_condition: threshold, target_phase, target_frequency, trigger]
Defines
-
PORT
port at which clients should expect the server. Defaults to 1219
-
MAX_LISTENERS
how many listeners can be enqueued at max defaults to 1
Functions
-
static void
error_exit
(char *errorMessage) shuts the server down with an error message
- Parameters
errorMessage – the errormessage to stderr
-
int
send_condition
(int client, condition *cond) send the current status to the connected client The status message will be encoded as defined by sri::create_condition_JSON
- Parameters
client – to whom to send the message
cond – the status information to be sent
- Returns
0 if successful
-
int
send_status
(int client, condition *cond, char *session_ID) send the current status to the connected client The status message will be encoded as defined by sri:: create_status_JSON
- Parameters
client – to whom to send the message
cond – the condition information to be sent
session_ID – the session_ID as read from the config file
- Returns
0 if successful
-
void
removeSpaces
(char *str) removes all spaces from a string
-
int
accept_client
() accept a TCP/IP client blocks until a client connects
- Returns
the client file descriptor
-
int
start_server
() start and bind a TCP/IP server
- Returns
the server file descriptor
-
int
get_lsl_config_filename
(char *filename) This function determines the filename of the LSL config file.
- Parameters
filename – is a string that will contain the filname
- Returns
EXIT_SUCCESS or error code
-
int
change_session_id
(char *argument) This function reads a message from the client and changes the LSL config file accordingly.
The message format is a string formatted with one arguments
Format: [set_lsl_session_ID: <session_ID>]
It will create the config file in ~/lsl_api/lsl_api.cfg If the directory/file does not exist, it will be created.- Parameters
argument – is a string that contains the session_ID
- Returns
EXIT_SUCCESS or error code
-
int
get_session_id
(char *session_ID, int buffersize) This function reads the session ID from the LSL config.
The function reads the config file in ~/lsl_api/lsl_api.cfg and extracts the session ID
- Parameters
session_ID – The destination where to write the session_ID
buffersize – The size of session_ID
- Returns
int indicates success
-
int
set_condition_from_arguments
(char *arguments, condition *condition) Overwrite an already existing condition based on arguments from a command message
- Parameters
arguments – the arguments part of the message received from a client the positional order of the arguments is <threshold>, <frequency>, <phase>, <trigger>. Each argument is either an integer to overwrite the current setting or an equality symbol to keep the current setting. For example if the message
[set_condition: =, =, 12, 0]
would be received, the arguments part would be=, =, 12, 0
which would keep threshold and target phase untouched while the target_frequency is changed to 12 and the trigger is disarmed by setting it to zero.
-
condition
recv_message
(int client, condition *new_status) This function reads a message from the client and executes the given command.
The message format is a string formatted with positional arguments
Format: [<command>: <arg1>, <arg2>, …, <argN>]
Implemented are:[set_condition: <threshold>, <frequency>, <phase>, <trigger>]
where each argument can be either an integer or the equality symbol =.[shutdown:]
shuts the server down gracefully.[send_status:]
just return the current conditions without changing anything[set_lsl_session_ID: <session_ID>]
sets lsl config file to a new session ID. Change will be applyed after restart.
- Parameters
client – is the socket from whom the server will read. This is the client returned by :func:
~.accept_client()
condition – *new_status the status object which will be filled based on the message received from the client
- Returns
EXIT_SUCCESS or error code
-
int
loop
() The main loop accepting clients, parsing messages and executing commands
Will be started when the executable is started
Note
shut the loop down by sending the shutdown command with a client