libsri.so¶
This library implements an interface between non-real-time LuckyServer and the real-time LuckyApplication. Its purpose it to set states for control and get states for passing information.
The interface is implemented as a struct (i.e. condition) which lives only in the local space, and a lockable struct (i.e. as shared_condition) which is used for sharing between the processes.
The memory segment used for is identified by the SHARED_CONDITION_KEY. The first step to use libsri.so is initializing the shared memory segment using initialize_shared_condition
. This overwrittes anything already in place, and should therefore be only used by the LuckyApp. Afterwards, one can attach the shared segment with access_shared_condition
, and read/write by pointing it to the local copy. It is best practice not to read/write the shared_condition directly.
Read/Write keeps the local copy untouched if the shared segment is currently locked. LuckyApp runs a continuous loop. Therefore, if the shared condition is locked, it will just failback to its local copy and try again next cycle. As the LuckyServer only read/writes the shared condition when a client has send a message. It therefore needs to wait until the lock is free, e.g. by putting the function call into a while loop.
Defines
-
VERSION
Defines the version, that will be shown to a client
-
SHARED_CONDITION_KEY
the key used to identify the shared memory writable for LuckyServer
-
CONDITION_DEFAULT
the default conditions when initializing a shared or local instance
Functions
-
void
initialize_shared_condition
(int key) initialize a struct in shared memory This function releases any locks and sets the condition to default values as defined in CONDITION_DEFAULT
- Parameters
key – the key to identify the shared memory
-
shared_condition *
access_shared_condition
(int key) gain access to a struct storing conditions in shared memory
- Parameters
key – the key to identify the shared memory
-
int
read_shared_condition
(shared_condition *shared, condition *local) read conditions from shared memory If access to the shared memory is locked, the local conditions will be used as fallback and not be changed. Otherwise, the local copy will become a copy a copy of the shared conditions. Because the function is assumed to be run continually in a loop, we return a bool. This bool indicates whether there actually was any change in the content of the local copy.
- Parameters
shared – the conditions living in the shared memory
local – the fallback conditions living in your local memory.
- Returns
1 if the conditions in fallback were actually changed
-
int
write_shared_condition
(shared_condition *shared, const condition local) write the conditions to shared memory
- Parameters
shared – the conditions living in the shared memory
local – the local values to be shared
- Returns
1 if i could acquire the lock and overwrite, 0 otherwise. The function is assumed to be run continually in a loop. If not, consider to put it into a while loop which breaks once written.
-
condition
create_local_condition
() create a struct storing conditions in local memory
-
int
are_conditions_equal
(const condition a, const shared_condition b) compare two conditions for equality
- Parameters
a – the first condition
b – the other (shared) condition
- Returns
0 in case of inequality, 1 if equal
-
char *
create_condition_JSON
(condition cond)
-
char *
create_status_JSON
(condition cond, char *session_ID)
-
void
print_condition
(condition cond) print the parameters of a condition to stdout
- Parameters
cond – the condition to print
-
struct
shared_condition
- #include <sri.h>
A sharable structure containing the current settings of the EtherCat Main
Public Members
-
int
threshold
the target threshold in a.u.
-
int
target_phase
the target phase in degree
-
int
target_frequency
the target frequency in Hz
-
int
trigger
the current state of the trigger
-
int
lock
this mutex is either locked or unlocked
-
int
-
struct
condition
- #include <sri.h>
A structure containing the current settings of the EtherCat Main
Public Members
-
int
threshold
the target threshold in a.u.
-
int
target_phase
the target phase in degree
-
int
target_frequency
the target frequency in Hz
-
int
trigger
the current state of the trigger
-
int