|
Low-Energy Muon (LEM) Experiment
0.5.1
|
#include <stdio.h>#include <stdlib.h>#include <stdarg.h>#include <string.h>#include <math.h>#include <time.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#include <netdb.h>#include <ctype.h>#include "midas.h"
Go to the source code of this file.
Data Structures | |
| struct | LEMPLUG_SETTINGS |
| device specific information stored in the DD ODB More... | |
| struct | LEMPLUG_INFO |
| This structure contains private variables for the device driver. More... | |
Macros | |
| #define | closesocket(s) close(s) |
| #define | LEMPLUG_MAX_READ 5 |
| maximal number of attempts to read More... | |
| #define | LEMPLUG_SUCCESS 0 |
| #define | LEMPLUG_NOSUCCESS -1 |
| #define | LEMPLUG_STARTUP_ERROR -2 |
| #define | LEMPLUG_NO_HOST_ERROR -3 |
| #define | LEMPLUG_CONNECT_ERROR -4 |
| #define | LEMPLUG_SETTINGS_STR "\Enable Log = INT : 0\n\Log = STRING : [64]\n\Read Time = DWORD : 5\n\Host = STRING : [32]\n\Port = INT : 23\n\User Name = STRING : [32]\n\Pwd = STRING : [32]\n\Firmware Tag = INT : 0\n\" |
| Initializing string for the struct LEMPLUG_SETTINGS. More... | |
Functions | |
| void | lemplug_base64_encode (char *s, char *d) |
| INT | lemplug_strip_whitespace (char *str) |
| void | lemplug_write_log (LEMPLUG_INFO *info, char *log) |
| INT | lemplug_cmd_0 (LEMPLUG_INFO *info) |
| INT | lemplug_read_0 (LEMPLUG_INFO *info) |
| INT | lemplug_cmd_1 (LEMPLUG_INFO *info) |
| INT | lemplug_cmd_2 (LEMPLUG_INFO *info) |
| INT | lemplug_init (HNDLE hkey, void **pinfo, INT channels, INT(*bd)(INT cmd,...)) |
| INT | lemplug_exit (LEMPLUG_INFO *info) |
| INT | lemplug_set (LEMPLUG_INFO *info, INT channel, float value) |
| INT | lemplug_get (LEMPLUG_INFO *info, INT channel, float *pvalue) |
| INT | lemplug_get_label (LEMPLUG_INFO *info, INT channel, char *name) |
| INT | lemplug (INT cmd,...) |
Variables | |
| char * | map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" |
| char | request [10000] |
| char | response [10000] |
| #define closesocket | ( | s | ) | close(s) |
Definition at line 26 of file lemplug.c.
Referenced by lemplug_cmd_0(), lemplug_cmd_1(), lemplug_cmd_2(), and lemplug_read_0().
| #define LEMPLUG_CONNECT_ERROR -4 |
Definition at line 34 of file lemplug.c.
Referenced by lemplug_cmd_0(), lemplug_cmd_1(), lemplug_cmd_2(), and lemplug_read_0().
| #define LEMPLUG_MAX_READ 5 |
| #define LEMPLUG_NO_HOST_ERROR -3 |
Definition at line 33 of file lemplug.c.
Referenced by lemplug_cmd_0(), lemplug_cmd_1(), lemplug_cmd_2(), and lemplug_read_0().
| #define LEMPLUG_NOSUCCESS -1 |
Definition at line 31 of file lemplug.c.
Referenced by lemplug_cmd_0(), lemplug_cmd_1(), lemplug_cmd_2(), and lemplug_read_0().
| #define LEMPLUG_SETTINGS_STR "\Enable Log = INT : 0\n\Log = STRING : [64]\n\Read Time = DWORD : 5\n\Host = STRING : [32]\n\Port = INT : 23\n\User Name = STRING : [32]\n\Pwd = STRING : [32]\n\Firmware Tag = INT : 0\n\" |
Initializing string for the struct LEMPLUG_SETTINGS.
Definition at line 51 of file lemplug.c.
Referenced by lemplug_init().
| #define LEMPLUG_STARTUP_ERROR -2 |
Definition at line 32 of file lemplug.c.
Referenced by lemplug_get().
| INT lemplug | ( | INT | cmd, |
| ... | |||
| ) |
The lemplug device driver handles the communication between the ePowerSwitch M8 (Leunig GmbH) and midas.
Definition at line 865 of file lemplug.c.
References hKey, info, lemplug_exit(), lemplug_get(), lemplug_get_label(), lemplug_init(), and lemplug_set().
| void lemplug_base64_encode | ( | char * | s, |
| char * | d | ||
| ) |
base 64 encoding routine (from S. Ritt).
| s | input string. |
| d | base64 encoded output string. |
Definition at line 88 of file lemplug.c.
References map.
Referenced by lemplug_get(), lemplug_init(), and lemplug_set().
| INT lemplug_cmd_0 | ( | LEMPLUG_INFO * | info | ) |
sends a command to the ePowerSwitch M8 and reads the response to it.
return:
| info | is a pointer to the DD specific info structure |
Definition at line 184 of file lemplug.c.
References closesocket, LEMPLUG_INFO::dd_settings, LEMPLUG_SETTINGS::host, LEMPLUG_CONNECT_ERROR, LEMPLUG_NO_HOST_ERROR, LEMPLUG_NOSUCCESS, LEMPLUG_SETTINGS::port, request, and response.
Referenced by lemplug_init(), and lemplug_set().
| INT lemplug_cmd_1 | ( | LEMPLUG_INFO * | info | ) |
sets and/or reads the current state of the ePowerSwitch M8+R2.
return:
| info | is a pointer to the DD specific info structure |
Definition at line 360 of file lemplug.c.
References closesocket, LEMPLUG_INFO::dd_settings, LEMPLUG_SETTINGS::host, LEMPLUG_CONNECT_ERROR, LEMPLUG_NO_HOST_ERROR, LEMPLUG_NOSUCCESS, LEMPLUG_INFO::outlet_state, LEMPLUG_SETTINGS::port, request, and response.
Referenced by lemplug_get(), and lemplug_set().
| INT lemplug_cmd_2 | ( | LEMPLUG_INFO * | info | ) |
sets and/or reads the current state of the ePowerSwitch M8+R1.
return:
| info | is a pointer to the DD specific info structure |
Definition at line 465 of file lemplug.c.
References closesocket, LEMPLUG_INFO::dd_settings, LEMPLUG_SETTINGS::host, LEMPLUG_CONNECT_ERROR, LEMPLUG_NO_HOST_ERROR, LEMPLUG_NOSUCCESS, LEMPLUG_INFO::outlet_state, LEMPLUG_SETTINGS::port, request, and response.
Referenced by lemplug_get(), and lemplug_set().
| INT lemplug_exit | ( | LEMPLUG_INFO * | info | ) |
quits the bus driver and free's the memory allocated for the info structure.
return: FE_SUCCESS
| info | is a pointer to the DD specific info structure |
Definition at line 673 of file lemplug.c.
References LEMPLUG_INFO::bd, and LEMPLUG_INFO::bd_info.
Referenced by lemplug().
| INT lemplug_get | ( | LEMPLUG_INFO * | info, |
| INT | channel, | ||
| float * | pvalue | ||
| ) |
reads the current state of the ePowerSwitch M8. This is done only in some rather slow time intervalls given by read_time in the DD, in order to keep the network traffic low.
return: FE_SUCCESS
| info | is a pointer to the DD specific info structure |
| channel | device channel number |
| pvalue | read back value |
Definition at line 781 of file lemplug.c.
References LEMPLUG_INFO::dd_settings, LEMPLUG_SETTINGS::enable_log, LEMPLUG_SETTINGS::firmware_tag, lemplug_base64_encode(), lemplug_cmd_1(), lemplug_cmd_2(), lemplug_read_0(), LEMPLUG_STARTUP_ERROR, lemplug_write_log(), LEMPLUG_INFO::outlet_state, LEMPLUG_SETTINGS::pwd, LEMPLUG_SETTINGS::read_time, LEMPLUG_INFO::read_time_stamp, request, response, LEMPLUG_INFO::startup_error, and LEMPLUG_SETTINGS::user_name.
Referenced by lemplug().
| INT lemplug_get_label | ( | LEMPLUG_INFO * | info, |
| INT | channel, | ||
| char * | name | ||
| ) |
Gets the names of the various outlets from the ePowerSwitch M8 and hands it over to the midas system.
return: FE_SUCCESS
| info | is a pointer to the DD specific info structure |
| channel | device channel number |
| name | of the power outlet |
Definition at line 858 of file lemplug.c.
Referenced by lemplug().
| INT lemplug_init | ( | HNDLE | hkey, |
| void ** | pinfo, | ||
| INT | channels, | ||
| INT(*)(INT cmd,...) | bd | ||
| ) |
Initializes the lemplug device driver, i.e. generates all the necessary structures in the ODB if necessary, initializes the bus driver and the ePowerSwitch M8.
return:
| hkey | is the device driver handle given from the class driver |
| pinfo | is needed to store the internal info structure |
| channels | is the number of channels of the device (from the class driver) |
| bd | is a pointer to the bus driver |
Definition at line 575 of file lemplug.c.
References LEMPLUG_INFO::bd, LEMPLUG_INFO::bd_info, LEMPLUG_INFO::dd_settings, LEMPLUG_SETTINGS::enable_log, LEMPLUG_SETTINGS::firmware_tag, hDB, LEMPLUG_INFO::hkey, info, lemplug_base64_encode(), lemplug_cmd_0(), LEMPLUG_SETTINGS_STR, lemplug_write_log(), LEMPLUG_INFO::num_channels, LEMPLUG_SETTINGS::pwd, LEMPLUG_SETTINGS::read_time, LEMPLUG_INFO::read_time_stamp, request, response, LEMPLUG_INFO::startup_error, and LEMPLUG_SETTINGS::user_name.
Referenced by lemplug().
| INT lemplug_read_0 | ( | LEMPLUG_INFO * | info | ) |
reads the current state of the ePowerSwitch M8.
return:
| info | is a pointer to the DD specific info structure |
Definition at line 261 of file lemplug.c.
References closesocket, LEMPLUG_INFO::dd_settings, LEMPLUG_SETTINGS::host, LEMPLUG_CONNECT_ERROR, LEMPLUG_NO_HOST_ERROR, LEMPLUG_NOSUCCESS, lemplug_strip_whitespace(), LEMPLUG_INFO::outlet_name, LEMPLUG_INFO::outlet_state, LEMPLUG_SETTINGS::port, request, and response.
Referenced by lemplug_get().
| INT lemplug_set | ( | LEMPLUG_INFO * | info, |
| INT | channel, | ||
| float | value | ||
| ) |
sends a switching command to the ePowerSwitch M8.
return: FE_SUCCESS
| info | is a pointer to the DD specific info structure |
| channel | device channel number |
| value | to be set |
Definition at line 694 of file lemplug.c.
References LEMPLUG_INFO::dd_settings, LEMPLUG_SETTINGS::enable_log, LEMPLUG_SETTINGS::firmware_tag, lemplug_base64_encode(), lemplug_cmd_0(), lemplug_cmd_1(), lemplug_cmd_2(), lemplug_write_log(), LEMPLUG_SETTINGS::pwd, request, response, LEMPLUG_INFO::startup_error, and LEMPLUG_SETTINGS::user_name.
Referenced by lemplug().
| INT lemplug_strip_whitespace | ( | char * | str | ) |
Strips white spaces at the end of a string
| str | string at which the white spaces are to removed |
Definition at line 123 of file lemplug.c.
Referenced by lemplug_read_0().
| void lemplug_write_log | ( | LEMPLUG_INFO * | info, |
| char * | log | ||
| ) |
Routine to log the communication.
| info | is a pointer to the DD specific info structure |
| log | output name for the log-file |
Definition at line 149 of file lemplug.c.
References LEMPLUG_INFO::dd_settings, and LEMPLUG_SETTINGS::log.
Referenced by lemplug_get(), lemplug_init(), and lemplug_set().
| char* map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" |
Definition at line 78 of file lemplug.c.
Referenced by lemplug_base64_encode().
| char request[10000] |
Definition at line 79 of file lemplug.c.
Referenced by lemplug_cmd_0(), lemplug_cmd_1(), lemplug_cmd_2(), lemplug_get(), lemplug_init(), lemplug_read_0(), and lemplug_set().
| char response[10000] |
Definition at line 79 of file lemplug.c.
Referenced by lemplug_cmd_0(), lemplug_cmd_1(), lemplug_cmd_2(), lemplug_get(), lemplug_init(), lemplug_read_0(), and lemplug_set().