37 #define MIRROR_ETS_LOGOUT_SLEEP 10000
50 #define MIRROR_SETTINGS_DD_STR "\
51 ETS_IN_USE = INT : 1\n\
52 TCPIPTimeOut = INT : 500\n\
53 MirrorADC45 = INT : 1976\n\
54 Names = STRING[2] :\n\
62 INT (*bd)(INT cmd, ...);
107 cm_get_experiment_database(&hDB, NULL);
115 if (status != DB_SUCCESS)
119 status = db_find_key(hDB, hKey,
"DD", &hKeyDD);
120 if (status != DB_SUCCESS)
125 MODE_READ, NULL, NULL);
126 if (status != DB_SUCCESS)
141 if (db_find_key(info->
hDB, 0,
"/Equipment/Mirror/Variables/Demand", &info->
hKeyDemand) != DB_SUCCESS) {
142 cm_msg(MINFO,
"mirror_init",
"WARNING: Couldn't get Key '/Equipment/Mirror/Variables/Demand' wasn't found in OBD.");
146 if (db_find_key(info->
hDB, 0,
"/Info/Mirror/Angle horizontal", &info->
hKeyInfo) != DB_SUCCESS) {
147 cm_msg(MINFO,
"mirror_init",
"WARNING: Couldn't get Key '/Info/Mirror/Angle horizontal' wasn't found in OBD.");
157 status = info->
bd(CMD_INIT, hKey, &info->
bd_info);
158 if (status != SUCCESS) {
162 cm_msg(MINFO,
"mirror_init",
"MIRROR driver initialized.");
208 strcpy(cmd,
"M+0\r");
211 printf(
"\n>>gcp: cmd = %s", cmd);
218 if (strstr(str,
"HS") || strstr(str,
"ES")) {
226 printf(
"\n>>gcp: str = %s", str);
254 }
while (i<max_try && !strstr(str,
"HS") && !strstr(str,
"ES"));
277 cm_msg(MINFO,
"mirror_set",
"INFO: reset process start. This is going to take some time!");
281 strcpy(cmd,
"M-999\r");
285 printf(
"\n>>mirror reset: cmd = %s", cmd);
290 printf(
"\n>>mirror reset: i=%d, str=%s", i, str);
295 if (strstr(str,
"ES"))
299 }
while(!done && j<5);
300 cm_msg(MINFO,
"mirror_set",
"INFO: reset process: End switch reached. Start to move back.");
310 for (j=0; j<step/999; j++) {
311 strcpy(cmd,
"M+999\r");
313 printf(
"\n>>mirror reset: cmd = %s", cmd);
317 printf(
"\n>>mirror reset: i=%d, str=%s", i, str);
325 sprintf(cmd,
"M+%d\r", step);
327 printf(
"\n>>mirror reset: cmd = %s", cmd);
332 printf(
"\n>>mirror reset: i=%d, str=%s", i, str);
342 cm_msg(MINFO,
"mirror_set",
"INFO: reset process completed.");
372 printf(
"\n\n\n\n\n>>mpr: cmd = %s", cmd);
377 printf(
"\n>>mpr: i=%d, str=%s", i, str);
390 if (fabs(value-(atof(str)-2048.f)*5.f/512.f)>0.1)
422 db_set_data_index(info->
hDB, info->
hKeyDemand, &dummy,
sizeof(
float), channel+1, TID_FLOAT);
424 cm_msg(MINFO,
"mirror_set",
"ERROR: Mirror reset couldn't be performed properly.");
428 db_set_data_index(info->
hDB, info->
hKeyDemand, &dummy,
sizeof(
float), channel, TID_FLOAT);
435 status = db_set_data_index(info->
hDB, info->
hKeyDemand, &value,
sizeof(
float), channel, TID_FLOAT);
436 cm_msg(MINFO,
"mirror_set",
"ERROR: MIRROR out of range +-15. Set it to 0.");
440 status = db_set_data_index(info->
hDB, info->
hKeyDemand, &value,
sizeof(
float), channel, TID_FLOAT);
441 cm_msg(MINFO,
"mirror_set",
"ERROR: MIRROR out of range +-15. Set it to 0.");
447 measured = (atof(str)-2048.f)*5.f/512.f;
449 if (fabs(measured-value)<0.1) {
453 i = (100*fabs(measured-value) / 999);
455 if (measured - value > 0) {
457 strcpy(cmd,
"M-999\r");
458 for (j=0; j<i+1; j++) {
459 cm_msg(MINFO,
"mirror_set",
"INFO: moving mirror, this is going to take a while.");
463 cm_msg(MINFO,
"mirror_set",
"INFO: moving mirror, this is going to take a while.");
466 measured = (atof(str)-2048.f)*5.f/512.f;
467 if (value-measured > 0) {
468 sprintf(cmd,
"M+%d\r", abs(100*(value-measured)));
470 cm_msg(MINFO,
"mirror_set",
"ERROR: haven't reached demand value.");
474 strcpy(cmd,
"M-999\r");
476 sprintf(cmd,
"M+%d\r", abs(100*(value-measured)));
478 cm_msg(MINFO,
"mirror_set",
"ERROR: haven't reached demand value.");
484 strcpy(cmd,
"M+999\r");
485 for (j=0; j<i; j++) {
486 cm_msg(MINFO,
"mirror_set",
"INFO: moving mirror, this is going to take a while.");
490 cm_msg(MINFO,
"mirror_set",
"INFO: moving mirror, this is going to take a while.");
493 measured = (atof(str)-2048.f)*5.f/512.f;
494 sprintf(cmd,
"M+%d\r", abs(100*(value-measured)));
496 cm_msg(MINFO,
"mirror_set",
"ERROR: haven't reached demand value.");
500 cm_msg(MINFO,
"mirror_set",
"INFO: mirror at new position.");
523 DWORD nowtime, difftime;
537 cm_msg(MERROR,
"mirror_get",
"too many reconnection failures, bailing out :-(");
546 cm_msg(MINFO,
"mirror_get",
"mirror_get: try to disconnect and reconnect the bus driver");
555 cm_msg(MINFO,
"mirror_get",
"mirror_get: reconnection trial ...");
557 if (status != FE_SUCCESS) {
558 cm_msg(MINFO,
"mirror_get",
"mirror_get: reconnection attempted failed");
565 cm_msg(MINFO,
"mirror_get",
"mirror_get: successfully reconnected");
578 *pvalue = (float) -2;
599 printf(
"%5d",
histo[i]);
603 if (!strstr(str,
"HS") && !strstr(str,
"ES")) {
604 *pvalue = (atof(str) - 2048)*5.f/512.f;
607 db_set_data_index(info->
hDB, info->
hKeyInfo, pvalue,
sizeof(
float), 0, TID_FLOAT);
642 float value, *pvalue;
645 va_start(argptr, cmd);
650 hKey = va_arg(argptr, HNDLE);
651 info = va_arg(argptr,
void *);
652 channel = va_arg(argptr, INT);
653 flags = va_arg(argptr, DWORD);
654 bd = va_arg(argptr,
void *);
659 info = va_arg(argptr,
void *);
664 info = va_arg(argptr,
void *);
665 channel = va_arg(argptr, INT);
666 pvalue = va_arg(argptr,
float *);
671 info = va_arg(argptr,
void *);
672 channel = va_arg(argptr, INT);
673 value = (float) va_arg(argptr,
double);
678 info = va_arg(argptr,
void *);
679 channel = va_arg(argptr, INT);
680 name = va_arg(argptr,
char *);
#define MIRROR_ETS_LOGOUT_SLEEP
sleep time (us) between the telnet commands of the ets_logout
float last_value
stores the last valid value
INT ets_in_use
flag indicating if the rs232 terminal server is in use
int adc_45
45 position of the mirror ADC
This structure contains private variables for the device driver.
#define MIRROR_MAX_TRY
maximal no of attempts to read
char names[2][32]
where to find mirror init data
INT mirror_move_to_position(MIRROR_INFO *info, char *cmd, char *str, int max_try)
INT(* bd)(INT cmd,...)
bus driver entry function
INT mirror_set(MIRROR_INFO *info, INT channel, float value)
int ets_logout(void *info, int wait, int detailed_msg)
INT errorcount
error coutner
#define MIRROR_DEBUG
debug tag, if set to TRUE, additional messages will be displayed at execution time ...
DWORD last_reconnect
timer for bus driver reconnect error handling
MIRROR_DD_SETTINGS mirror_dd_settings
ODB hot-link data for the DD.
INT mirror_get_current_position(MIRROR_INFO *info, char *str)
#define MIRROR_SETTINGS_DD_STR
initializing string for MIRROR_DD_SETTINGS
int histo[MIRROR_MAX_TRY]
HNDLE hKeyInfo
handle to /Info/Mirror/Angle horizontal
void * bd_info
private info of bus driver
INT startup_error
startup error tag; if set, the get and BH_set and BH_get routines wont do anything ...
INT mirror_get(MIRROR_INFO *info, INT channel, float *pvalue)
#define MIRROR_MAX_STR
maximum string length for rs232 communication
HNDLE hkey
ODB key for bus driver info.
int bd_connected
flag showing if bus driver is connected
int time_out
tcpip time out in msec
#define MIRROR_WAIT
time (ms) to wait between commands
BOOL reset_mirror_position(MIRROR_INFO *info)
stores internal informations within the DD.
INT mirror_exit(MIRROR_INFO *info)
INT mirror_get_label(MIRROR_INFO *info, INT channel, char *name)
#define MIRROR_DELTA_TIME_ERROR
reset error counter after DELTA_TIME_ERROR seconds
int reconnection_failures
how often reconnection failed
INT mirror_init(HNDLE hKey, void **pinfo, INT channels, INT(*bd)(INT cmd,...))
HNDLE hKeyDemand
handle to /Equipment/Mirror/Variables/Demand
BOOL mirror_position_reached(MIRROR_INFO *info, char *cmd, float value)
DWORD lasterrtime
timer for error handling