112 #include "lemSCWatchdog.h"
119 #define FP_1000 0x0001
120 #define FP_1001 0x0002
121 #define FP_AI_110 0x0101
122 #define FP_AO_200 0x0102
123 #define FP_DI_330 0x0103
124 #define FP_DO_400 0x0104
125 #define FP_DI_301 0x0105
126 #define FP_DO_401 0x0106
127 #define FP_TC_120 0x0107
128 #define FP_RLY_420 0x0108
129 #define FP_DI_300 0x0109
130 #define FP_AI_100 0x010A
131 #define FP_RTD_122 0x010B
132 #define FP_AI_111 0x010C
133 #define FP_AO_210 0x010F
151 #define FP_IO_NUM_CH 8
152 #define FP_AI_110_RANGE 0x04
153 #define FP_AI_110_FILTER 0x00
154 #define FP_AO_210_RANGE 0x04
155 #define FP_RLY_SETTING 0x10
156 #define FP_IO_RESOL 65536
157 #define FP_AO_NORM 0.9804
158 #define FP_AI_NORM 1.04
166 #define FP_ERR_PUCLR_EXP 0x00
167 #ifndef DOXYGEN_SHOULD_SKIP_THIS
168 #define FP_ERR_INVALID_CMD 0x01
169 #define FP_ERR_BAD_CHECKSUM 0x02
170 #define FP_ERR_INBUF_OVERFLO 0x03
171 #define FP_ERR_ILLEGAL_CHAR 0x04
172 #define FP_ERR_INSUFF_CHARS 0x05
173 #define FP_ERR_WATCHDOG_TMO 0x06
174 #define FP_ERR_INV_LIMS_GOT 0x07
175 #define FP_ERR_ILLEGAL_DIGIT 0x80
176 #define FP_ERR_BAD_ADDRESS 0x81
177 #define FP_ERR_INBUF_FRMERR 0x82
178 #define FP_ERR_NO_MODULE 0x83
179 #define FP_ERR_INV_CHNL 0x84
180 #define FP_ERR_INV_RANGE 0x85
181 #define FP_ERR_INV_ATTR 0x86
182 #define FP_ERR_HOTSWAP 0x88
183 #define FP_ERR_ADDR_NOT_SAME 0x89
184 #define FP_ERR_NO_RESEND_BUF 0x8A
185 #define FP_ERR_HW_FAILURE 0x8B
186 #define FP_ERR_UNKNOWN 0x8C
187 #endif // DOXYGEN_SHOULD_SKIP_THIS
190 #define HV_FUG_TIME_OUT 3000
193 #define HV_FUG_MAX_ERROR 5
194 #define HV_FUG_DELTA_TIME_ERROR 3600
196 #define HV_FUG_MAX_READBACK_FAILURE 5
198 #define HV_FUG_RECONNECTION_TIMEOUT 10
200 #define HV_FUG_READ_ERROR -99
204 #define HV_FUG_ETS_LOGOUT_SLEEP 10000
215 char fp_io_modules[128];
216 char map_fp_fug_input[12][64];
217 char map_fp_fug_output[12][64];
218 char fug_properties[12][64];
225 #define HV_FUG_SETTINGS_INTERNAL_STR "\
226 Detailed Messages = INT : 0\n\
227 ETS_IN_USE = INT : 1\n\
228 SCW_IN_USE = INT : 1\n\
235 #define HV_FUG_SETTINGS_ODB_OFFSET_STR "\
236 ODB Channel Offset = INT : 0\n\
243 #define HV_FUG_SETTINGS_NO_STR "\
244 No of FP-IO Modules = INT : 9\n\
251 #define HV_FUG_SETTINGS_MODULE_STR "\
252 Modules = STRING : [128] 0:FP-1000; 1:FP-AO-210; 2:FP-AI-110; 3:FP-AI-110; 4:FP-AO-210; 5:FP-AI-110; 6:FP-AO-210; 7:FP-AI-110; 8:FP-RLY-420;\n\
295 #define HV_FUG_SETTINGS_OUT_STR "\
296 FUG fp mapping output = STRING[12] : \n\
297 [64] Moderator 04 0x0004 04 0x0008 N 00 0x0000 \n\
298 [64] Mod_Guard 04 0x0010 04 0x0020 N 00 0x0000 \n\
299 [64] Mod_Grid 01 0x0001 01 0x0002 N 00 0x0000 \n\
300 [64] Lense_1 01 0x0004 01 0x0008 N 00 0x0000 \n\
301 [64] Mirror 04 0x0001 04 0x0002 N 00 0x0000 \n\
302 [64] Lense_2 01 0x0040 01 0x0080 N 00 0x0000 \n\
303 [64] Lense_3 01 0x0010 01 0x0020 N 00 0x0000 \n\
304 [64] RA-L 06 0x0010 06 0x0020 Y 08 0x0008 \n\
305 [64] RA-R 06 0x0004 06 0x0008 Y 08 0x0004 \n\
306 [64] RA-T 06 0x0001 06 0x0002 Y 08 0x0002 \n\
307 [64] RA-B 04 0x0040 04 0x0080 Y 08 0x0001 \n\
308 [64] Sample 06 0x0040 06 0x0080 Y 08 0x0010 \n\
350 #define HV_FUG_SETTINGS_IN_STR "\
351 FUG fp mapping input = STRING[12] : \n\
352 [64] Moderator 03 0x0004 03 0x0008 N 00 0x0000 \n\
353 [64] Mod_Guard 03 0x0010 03 0x0020 N 00 0x0000 \n\
354 [64] Mod_Grid 02 0x0001 02 0x0002 N 00 0x0000 \n\
355 [64] Lense_1 02 0x0004 02 0x0008 N 00 0x0000 \n\
356 [64] Mirror 03 0x0001 03 0x0002 N 00 0x0000 \n\
357 [64] Lense_2 02 0x0040 02 0x0080 N 00 0x0000 \n\
358 [64] Lense_3 02 0x0010 02 0x0020 N 00 0x0000 \n\
359 [64] RA-L 07 0x0010 07 0x0020 Y 05 0x0008 \n\
360 [64] RA-R 07 0x0004 07 0x0008 Y 05 0x0004 \n\
361 [64] RA-T 07 0x0001 07 0x0002 Y 05 0x0002 \n\
362 [64] RA-B 03 0x0040 03 0x0080 Y 05 0x0001 \n\
363 [64] Sample 07 0x0040 07 0x0080 Y 05 0x0010 \n\
386 #define HV_FUG_SETTINGS_PROPERTIES_STR "\
387 Properties = STRING[12] : \n\
388 [64] Moderator @35.0kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\
389 [64] Mod_Guard @20.0kV #0.6mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\
390 [64] Mod_Grid @12.5kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\
391 [64] Lense_1 @12.5kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\
392 [64] Mirror @35.0kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\
393 [64] Lense_2 @35.0kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\
394 [64] Lense_3 @35.0kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\
395 [64] RA-L @35.0kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\
396 [64] RA-R @35.0kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\
397 [64] RA-T @20.0kV #0.6mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\
398 [64] RA-B @20.0kV #0.6mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\
399 [64] Sample @12.5kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\
403 #define HV_FUG_SCW_STR "\
404 Proc Name = STRING : [32]\n\
406 Log Name = STRING : [64]\n\
407 DD Name = STRING : [32] FUG\n\
408 Last Updated = DWORD : 0\n\
409 Timeout = DWORD : 180\n\
419 INT (*bd)(INT cmd, ...);
424 float last_valid_hv[25];
425 float last_valid_current[25];
489 if (strlen(error)<3) {
492 cm_msg(MERROR, where,
"Unrecognized Error (%d,%s). Possibly a communication problem.",
493 strlen(error), error);
497 sscanf(error,
"N%i", &err_num);
500 sprintf(err_msg,
"FP ERROR %d: Power Up Clear expected.", err_num);
502 case FP_ERR_INVALID_CMD:
503 sprintf(err_msg,
"FP ERROR %d: Undefined command.", err_num);
505 case FP_ERR_BAD_CHECKSUM:
506 sprintf(err_msg,
"FP ERROR %d: Checksum error.", err_num);
508 case FP_ERR_INBUF_OVERFLO:
509 sprintf(err_msg,
"FP ERROR %d: Input buffer overrun.", err_num);
511 case FP_ERR_ILLEGAL_CHAR:
512 sprintf(err_msg,
"FP ERROR %d: Non-printable ASCII character received.", err_num);
514 case FP_ERR_INSUFF_CHARS:
515 sprintf(err_msg,
"FP ERROR %d: Data field error. Insufficient or incorrect number of characters were received.", err_num);
517 case FP_ERR_WATCHDOG_TMO:
518 sprintf(err_msg,
"FP ERROR %d: Communication link network watchdog timed out.", err_num);
520 case FP_ERR_INV_LIMS_GOT:
521 sprintf(err_msg,
"FP ERROR %d: Specified limits invalid for the command.", err_num);
523 case FP_ERR_ILLEGAL_DIGIT:
524 sprintf(err_msg,
"FP ERROR %d: One or more characters sent in the command could not be correctely converted to a digit.", err_num);
526 case FP_ERR_BAD_ADDRESS:
527 sprintf(err_msg,
"FP ERROR %d: Addressed module does not support the sent command.", err_num);
529 case FP_ERR_INBUF_FRMERR:
530 sprintf(err_msg,
"FP ERROR %d: Serial framing error.", err_num);
532 case FP_ERR_NO_MODULE:
533 sprintf(err_msg,
"FP ERROR %d: Addressed module does not exist.", err_num);
535 case FP_ERR_INV_CHNL:
536 sprintf(err_msg,
"FP ERROR %d: Channel command error.", err_num);
538 case FP_ERR_INV_RANGE:
539 sprintf(err_msg,
"FP ERROR %d: Channel command error.", err_num);
541 case FP_ERR_INV_ATTR:
542 sprintf(err_msg,
"FP ERROR %d: Channel command error.", err_num);
545 sprintf(err_msg,
"FP ERROR %d: The module has been hot-swapped since the last sent command.", err_num);
547 case FP_ERR_ADDR_NOT_SAME:
548 sprintf(err_msg,
"FP ERROR %d: Module switched.", err_num);
550 case FP_ERR_NO_RESEND_BUF:
551 sprintf(err_msg,
"FP ERROR %d: Response to the last command is unavailable.", err_num);
553 case FP_ERR_HW_FAILURE:
554 sprintf(err_msg,
"FP ERROR %d: An irrecoverable fault has occured.", err_num);
557 sprintf(err_msg,
"FP ERROR %d: An unidentifiable error condition has occured.", err_num);
560 strcpy(err_msg,
"Unrecognized Error. Possibly a communication problem.");
564 cm_msg(MERROR, where, err_msg);
586 s=strstr(line, start);
587 strcpy(result, s+strlen(start));
588 e=strstr(result, stop);
604 void sub_str(
int start,
int stop,
char *
line,
char *result,
int size_line,
int size_result)
608 if (stop > size_line)
611 for (i=start; i<stop; i++){
612 if (j < size_result) {
633 char *pstart, *pstop;
635 if ((pstart=strstr(str, start))==NULL)
return NULL;
637 strcpy(result, pstart);
638 if ((pstop=strstr(result, stop))==NULL)
return NULL;
656 int i, sum=0, checksum=0;
658 sscanf(chksum,
"%X", &checksum);
660 for (i=0; i<strlen(line); i++)
691 strncpy(str, line+(i<<2), 2);
692 sscanf(str,
"%X", &value);
695 cm_msg(MERROR,
"hv_fug_init",
"Input Module %d, Module-Channel %d, wrong filter setting.", module, i+1);
700 strncpy(str, line+((i<<2)+2), 2);
701 sscanf(str,
"%X", &value);
704 cm_msg(MERROR,
"hv_fug_init",
"Input Module %d, Module-Channel %d, wrong range setting.", module, i+1);
733 strncpy(str, line+(i<<1), 2);
734 sscanf(str,
"%X", &value);
737 cm_msg(MERROR,
"hv_fug_init",
"Output Module %d, Module-Channel %d, wrong range setting.", module, i+1);
766 strncpy(str, line+(i<<1), 2);
767 sscanf(str,
"%X", &value);
770 cm_msg(MERROR,
"hv_fug_init",
"Relais Module %d, Module-Channel %d, wrong range setting.", module, i+1);
795 sscanf(line,
"%X", &code);
796 sprintf(msg,
"hv_fug_init: module %d, channel(s) ( ", module);
797 for (i=0; i<16; i++) {
799 sprintf(substr,
"%d ", i);
802 if ((hv_fug_fp_set[j].module_cdc_out==module) && (hv_fug_fp_set[j].channel_cdc_out==1<<i)) {
803 sprintf(substr,
"(%s) ", hv_fug_fp_set[j].name);
809 strcat(msg,
" ) are bad.");
811 cm_msg(MERROR,
"hv_fug_init", msg);
831 int status, err, size;
833 char name[128], str[10];
838 for (i=0; i<channels; i++){
843 if (strstr(str,
"Y"))
848 for (i=0; i<channels; i++){
854 for (i=0; i<channels; i++){
862 if ((err=db_find_key(hDB, 0,
"/Equipment/HV/Settings/Voltage Limit", &hkey))!=DB_SUCCESS)
865 if ((err=db_get_data_index(hDB, hkey, &dummy, &size, 0+info->
hv_settings.
odb_offset, TID_FLOAT))!=DB_SUCCESS)
867 if ((dummy==3000.f) || (dummy==0.f)) {
868 for (i=0; i<channels; i++){
869 if ((err=db_set_data_index(hDB, hkey, &hv_fug_fp_set[i].max_volt,
sizeof(
float), i+info->
hv_settings.
odb_offset, TID_FLOAT))!=DB_SUCCESS)
875 if ((err=db_find_key(hDB, 0,
"/Equipment/HV/Settings/Current Limit", &hkey))!=DB_SUCCESS)
878 if ((err=db_get_data_index(hDB, hkey, &dummy, &size, 0+info->
hv_settings.
odb_offset, TID_FLOAT))!=DB_SUCCESS)
880 if ((dummy==3000.f) || (dummy==0.f)) {
881 for (i=0; i<channels; i++){
882 if ((err=db_set_data_index(hDB, hkey, &hv_fug_fp_set[i].init_curr,
sizeof(
float), i+info->
hv_settings.
odb_offset, TID_FLOAT))!=DB_SUCCESS)
888 if ((err=db_find_key(hDB, 0,
"/Equipment/HV/Settings/Ramp Up Speed", &hkey))!=DB_SUCCESS)
891 if ((err=db_get_data_index(hDB, hkey, &dummy, &size, 0+info->
hv_settings.
odb_offset, TID_FLOAT))!=DB_SUCCESS)
894 for (i=0; i<channels; i++){
895 if ((err=db_set_data_index(hDB, hkey, &hv_fug_fp_set[i].ramping_speed_up,
sizeof(
float), i+info->
hv_settings.
odb_offset, TID_FLOAT))!=DB_SUCCESS)
901 if ((err=db_find_key(hDB, 0,
"/Equipment/HV/Settings/Ramp Down Speed", &hkey))!=DB_SUCCESS)
904 if ((err=db_get_data_index(hDB, hkey, &dummy, &size, 0+info->
hv_settings.
odb_offset, TID_FLOAT))!=DB_SUCCESS)
907 for (i=0; i<channels; i++){
908 if ((err=db_set_data_index(hDB, hkey, &hv_fug_fp_set[i].ramping_speed_down,
sizeof(
float), i+info->
hv_settings.
odb_offset, TID_FLOAT))!=DB_SUCCESS)
914 status = db_find_key(hDB, 0,
"/Equipment/HV/Settings/Update Threshold Measured", &hkey);
915 if (status != DB_SUCCESS)
return FE_ERR_ODB;
916 for (i=0; i<channels; i++) {
917 size =
sizeof(float);
925 status = db_find_key(hDB, 0,
"/Equipment/HV/Settings/Update Threshold Current", &hkey);
926 if (status != DB_SUCCESS)
return FE_ERR_ODB;
927 for (i=0; i<channels; i++) {
928 size =
sizeof(float);
958 sprintf(str,
">0%dA??\r",i);
963 cm_msg(MERROR,
"fp_power_up_clear",
"Field point module %d does not respond. Check power/RS232 conection.", i);
989 int tot_num_modules=0;
993 char module_name[128];
996 strcpy(str,
">00!B??\r");
999 if (str[0]!=
'A')
return fp_error_msg(info,
"fp_check_modules in hv_fug_init", str);
1002 strncpy(sub, &str[1], 2);
1004 sscanf(sub,
"%d", &tot_num_modules);
1008 sprintf(str,
"# Modules according DB = %d, # Modules according FP = %d. They have to be equal!",
1011 cm_msg(MERROR,
"hv_fug_init", str);
1017 if (strlen(str)!=tot_num_modules*4+6) {
1019 cm_msg(MERROR,
"hv_fug_init",
"Recieved data from FP1000 are corrupted.");
1026 strcpy(type_str,
"");
1027 for (i=0; i<tot_num_modules; i++) {
1028 sprintf(parse,
"%d:", i);
1029 mid_str(parse,
";", db_str, module_name);
1030 if (!strcmp(module_name,
"FP-1000"))
1031 strcat(type_str,
"0001");
1032 else if (!strcmp(module_name,
"FP-AI-110"))
1033 strcat(type_str,
"0101");
1034 else if (!strcmp(module_name,
"FP-AO-210"))
1035 strcat(type_str,
"010F");
1036 else if (!strcmp(module_name,
"FP-RLY-420"))
1037 strcat(type_str,
"0108");
1040 cm_msg(MERROR,
"hv_fug_init",
"Wrong FP-Module entry in DB.");
1046 if (!strstr(str, type_str)) {
1048 cm_msg(MERROR,
"hv_fug_init",
"FP-Module order differs between DB and FP.");
1088 char str[512], substr[512], chksumstr[4];
1091 sprintf(str,
">%02X!A??\r", i);
1095 cm_msg(MINFO,
"fp_check_attrib_settings",
"debug> (0) fp_check_attrib_settings: str=%s", str);
1096 if (strstr(str,
"0101")) {
1112 sprintf(str,
">%02X!E00FF0001100011000110001100011000110001100011??\r", i);
1116 cm_msg(MINFO,
"fp_check_attrib_settings",
"debug> (1) fp_check_attrib_settings, str=%s", str);
1118 return fp_error_msg(info,
"fp_check_attrib_settings in hv_fug_init", str);
1120 sub_str(strlen(str)-3, strlen(str), str, chksumstr,
sizeof(str),
sizeof(chksumstr));
1122 return fp_error_msg(info,
"fp_check_attrib_settings in hv_fug_init (FP-AI-110)",
"N02");
1126 if (strstr(str,
"010F")) {
1127 sprintf(str,
">%02X!E00FF0000100001000010000100001000010000100001??\r", i);
1131 cm_msg(MINFO,
"fp_check_attrib_settings",
"debug> (2) fp_check_attrib_settings, str='%s'", str);
1133 return fp_error_msg(info,
"fp_check_attrib_settings in hv_fug_init", str);
1135 sub_str(strlen(str)-3, strlen(str), str, chksumstr,
sizeof(str),
sizeof(chksumstr));
1137 return fp_error_msg(info,
"fp_check_attrib_settings in hv_fug_init (FP-AO-210)",
"N02");
1141 if (strstr(str,
"0108")) {
1142 sprintf(str,
">%02X!E00FF0000100001000010000100001000010000100001??\r", i);
1146 cm_msg(MINFO,
"fp_check_attrib_settings",
"debug> (3) fp_check_attrib_settings, str=%s", str);
1148 return fp_error_msg(info,
"fp_check_attrib_settings in hv_fug_init (FP-RLY-420)", str);
1150 sub_str(strlen(str)-3, strlen(str), str, chksumstr,
sizeof(str),
sizeof(chksumstr));
1152 return fp_error_msg(info,
"fp_check_attrib_settings in hv_fug_init",
"N02");
1180 float curr_ratio[8];
1183 char str[128], substr[5], res[128];
1187 cmd[i] = (
char *) malloc(512*
sizeof(
char));
1194 mod[hv_fug_fp_set[i].
module_cdc_out].curr_ratio[mod[hv_fug_fp_set[i].
module_cdc_out].hits] = hv_fug_fp_set[i].init_curr/hv_fug_fp_set[i].max_curr;
1195 mod[hv_fug_fp_set[i].module_cdc_out].hits += 1;
1199 if (mod[i].mask != 0) {
1200 sprintf(cmd[i],
">%02X!I%04X", i, mod[i].mask);
1201 for (j=mod[i].hits-1; j>=0; j--) {
1203 strcat(cmd[i], str);
1205 strcat(cmd[i],
"??\r");
1212 if (mod[i].mask != 0) {
1215 if (str[0]!=
'A')
return fp_error_msg(info,
"fp_write_defaults in hv_fug_init", str);
1216 sub_str(1, 5, str, substr,
sizeof(str),
sizeof(substr));
1217 if (strcmp(substr,
"0000")) {
1226 if (mod[i].mask != 0) {
1227 sprintf(cmd[i],
">%02X!F%04X??\r", i, mod[i].mask);
1230 if (res[0]!=
'A')
return fp_error_msg(info,
"fp_write_defaults in hv_fug_init", res);
1232 sub_str(1, strlen(res)-3, res, res,
sizeof(res),
sizeof(res));
1235 for (j=mod[i].hits-1; j>=0; j--) {
1237 strcat(str, substr);
1239 if (strcmp(res, str)) {
1241 cm_msg(MERROR,
"hv_fug_init",
"current limit readback error in module %d.", i);
1282 cm_get_experiment_database(&hDB, NULL);
1292 status = db_create_record(hDB, hKey,
"DD/FUG", str);
1293 if ((status != DB_SUCCESS) && (status != DB_OPEN_RECORD)) {
1295 cm_msg(MERROR,
"hv_fug_init",
"hv_fug_init: Couldn't create DD/FUG in ODB: status=%d", status);
1302 if ((status != DB_SUCCESS) && (status != DB_OPEN_RECORD)) {
1304 cm_msg(MERROR,
"hv_fug_init",
"hv_fug_init: Couldn't create DD/SCW in ODB: status=%d", status);
1310 status = db_find_key(hDB, hKey,
"DD/FUG", &hDDKey);
1311 if (status != DB_SUCCESS) {
1318 db_get_record(hDB, hDDKey, &info->
hv_settings, &size, 0);
1335 status = info->
bd(CMD_INIT, hKey, &info->
bd_info);
1336 if (status != SUCCESS) {
1345 return FE_ERR_DRIVER;
1348 cm_msg(MINFO,
"hv_fug_init",
"HV FUG INIT: Power Up Clear.");
1351 cm_msg(MERROR,
"hv_fug_init",
"**ERROR** HV FUG INIT: Power Up Clear failed.");
1356 cm_msg(MINFO,
"hv_fug_init",
"HV FUG INIT: Check Modules and DB Settings.");
1359 cm_msg(MERROR,
"hv_fug_init",
"**ERROR** HV FUG INIT: Check Modules and DB Settings failed.");
1364 cm_msg(MINFO,
"hv_fug_init",
"HV FUG INIT: Check Module Attributes and Range Settings.");
1368 cm_msg(MERROR,
"hv_fug_init",
"**ERROR** HV FUG INIT: Check Module Attributes and Range Settings failed.");
1373 cm_msg(MINFO,
"hv_fug_init",
"HV FUG INIT: Write Defaults for HV and Current Limits.");
1377 cm_msg(MERROR,
"hv_fug_init",
"**ERROR** HV FUG INIT: Write Defaults for HV and Current Limits failed.");
1385 db_find_key(hDB, hKey,
"DD/SCW", &hDDKey);
1387 size =
sizeof(info->
scw);
1388 db_get_record(hDB, hDDKey, &info->
scw, &size, 0);
1390 info->
scw.pid = ss_getpid();
1391 info->
scw.last_updated = ss_time();
1393 db_set_record(hDB, hDDKey, &info->
scw,
sizeof(info->
scw), 0);
1396 status = lem_scw_init(&info->
scw);
1397 if (status != LEM_SCW_SUCCESS) {
1398 cm_msg(MINFO,
"hv_fug_init",
"Couldn't register with lem watchdog");
1425 lem_scw_exit(&info->
scw);
1445 int status, val, ch;
1447 char str[512], err[512], dat[512], substr[5];
1455 cm_msg(MERROR,
"hv_fug_set",
1456 "set HV not possible at the moment, since the bus driver is not available!");
1461 if (hv_fug_fp_set[channel].hv_switchable) {
1463 sprintf(str,
">%02X!G%04X??\r", hv_fug_fp_set[channel].module_relais_in,
1464 hv_fug_fp_set[channel].channel_relais_in);
1468 if ((str[0]!=
'A') || (strlen(str)!=12)) {
1469 ch = (int)(log(hv_fug_fp_set[channel].channel_vdc_out)/log(2))+1;
1470 sprintf(err,
"hv_fug_set, module %d, channel %d", hv_fug_fp_set[channel].module_vdc_out, ch);
1473 if (strstr(str,
"FFFF")) {
1479 if (sign != value/fabs(value)) {
1482 strcpy(dat,
"FFFF");
1484 strcpy(dat,
"0000");
1486 sprintf(str,
">%02X!M%04X%s??\r", hv_fug_fp_set[channel].module_relais_out,
1487 hv_fug_fp_set[channel].channel_relais_out, dat);
1491 if ((str[0]!=
'A') || (strlen(str)!=8)) {
1492 ch = (int)(log(hv_fug_fp_set[channel].channel_vdc_out)/log(2))+1;
1493 sprintf(err,
"hv_fug_set, module %d, channel %d", hv_fug_fp_set[channel].module_vdc_out, ch);
1502 sprintf(str,
">%02X!I%04X%04X??\r", hv_fug_fp_set[channel].module_vdc_out,
1503 hv_fug_fp_set[channel].channel_vdc_out,
1510 if ((str[0]!=
'A') || (strlen(str)!=8)) {
1511 ch = (int)(log(hv_fug_fp_set[channel].channel_vdc_out)/log(2))+1;
1512 sprintf(err,
"hv_fug_set, module %d, channel %d", hv_fug_fp_set[channel].module_vdc_out, ch);
1516 sub_str(strlen(str)-3, strlen(str)-1, str, substr,
sizeof(str),
sizeof(substr));
1517 sub_str(1, strlen(str)-3, str, dat,
sizeof(str),
sizeof(dat));
1519 ch = (int)(log(hv_fug_fp_set[channel].channel_vdc_out)/log(2))+1;
1521 cm_msg(MERROR,
"hv_fug_set",
"Checksum Error Response, Module %d, Channel %d", hv_fug_fp_set[channel].module_vdc_out, ch);
1541 int status, value, ch;
1542 char str[512], err[512], dat[512], substr[5];
1544 DWORD nowtime, difftime;
1554 nowtime = ss_time();
1564 cm_msg(MERROR,
"hv_fug_get",
"too many reconnection failures, bailing out :-(");
1572 info->
scw.last_updated = ss_time();
1573 lem_scw_update(&info->
scw);
1580 cm_msg(MINFO,
"hv_fug_get",
"HV FUG: reconnection trial ...");
1582 if (status != FE_SUCCESS) {
1586 cm_msg(MINFO,
"hv_fug_get",
"HV FUG: reconnection attempted failed");
1595 cm_msg(MINFO,
"hv_fug_get",
"HV FUG: successfully reconnected");
1603 if (hv_fug_fp_set[channel].hv_switchable) {
1605 sprintf(str,
">%02X!G%04X??\r", hv_fug_fp_set[channel].module_relais_in,
1606 hv_fug_fp_set[channel].channel_relais_in);
1609 if (strstr(str,
"FFFF"))
1616 sprintf(str,
">%02X!G%04X??\r", hv_fug_fp_set[channel].module_vdc_in,
1617 hv_fug_fp_set[channel].channel_vdc_in);
1622 if ((str[0]!=
'A') || (strlen(str)!=12)) {
1632 cm_msg(MINFO,
"hv_fug_get",
"HV FUG: try to disconnect and reconnect the bus driver");
1640 ch = (int)(log(hv_fug_fp_set[channel].channel_vdc_in)/log(2))+1;
1641 sprintf(err,
"hv_fug_get, module %d, channel %d",
1642 hv_fug_fp_set[channel].module_vdc_in, ch);
1645 sub_str(strlen(str)-3, strlen(str)-1, str, substr,
sizeof(str),
sizeof(substr));
1646 sub_str(1, strlen(str)-3, str, dat,
sizeof(str),
sizeof(dat));
1648 ch = (int)(log(hv_fug_fp_set[channel].channel_vdc_in)/log(2))+1;
1650 cm_msg(MERROR,
"hv_fug_get",
"Checksum Error Read, Module %d, Channel %d",
1651 hv_fug_fp_set[channel].module_vdc_in, ch);
1657 sub_str(5, 9, str, substr,
sizeof(str),
sizeof(substr));
1658 sscanf(substr,
"%04X", &value);
1680 sprintf(name,
"FUG%%%s", hv_fug_fp_set[channel].name);
1696 int status, value, ch;
1697 char str[512], err[512], dat[512], substr[5];
1698 DWORD nowtime, difftime;
1703 nowtime = ss_time();
1717 sprintf(str,
">%02X!G%04X??\r", hv_fug_fp_set[channel].module_cdc_in,
1718 hv_fug_fp_set[channel].channel_cdc_in);
1723 if ((str[0]!=
'A') || (strlen(str)!=12)) {
1724 ch = (int)(log(hv_fug_fp_set[channel].channel_cdc_in)/log(2))+1;
1725 sprintf(err,
"hv_fug_get_current, module %d, channel %d", hv_fug_fp_set[channel].module_cdc_in, ch);
1728 sub_str(strlen(str)-3, strlen(str)-1, str, substr,
sizeof(str),
sizeof(substr));
1729 sub_str(1, strlen(str)-3, str, dat,
sizeof(str),
sizeof(dat));
1731 ch = (int)(log(hv_fug_fp_set[channel].channel_cdc_in)/log(2))+1;
1733 cm_msg(MERROR,
"hv_fug_get_current",
"Checksum Error Read, Module %d, Channel %d", hv_fug_fp_set[channel].module_cdc_in, ch);
1739 sub_str(5, 9, str, substr,
sizeof(str),
sizeof(substr));
1740 sscanf(substr,
"%04X", &value);
1761 char str[512], err[512];
1767 cm_msg(MERROR,
"hv_fug_set_current_limit",
1768 "set current limit cannot be executed at the moment, since the bus driver is not available!");
1773 sprintf(str,
">%02X!I%04X%04X??\r", hv_fug_fp_set[channel].module_cdc_out,
1774 hv_fug_fp_set[channel].channel_cdc_out,
1780 ch = (int)(log(hv_fug_fp_set[channel].channel_cdc_in)/log(2))+1;
1781 sprintf(err,
"hv_fug_set_current_limit, module %X, channel %X", hv_fug_fp_set[channel].module_cdc_out, ch);
1794 INT channel, status;
1795 float value, *pvalue;
1800 va_start(argptr, cmd);
1801 status = FE_SUCCESS;
1805 hKey = va_arg(argptr, HNDLE);
1806 info = va_arg(argptr,
void *);
1807 channel = va_arg(argptr, INT);
1808 flags = va_arg(argptr, DWORD);
1809 bd = va_arg(argptr,
void *);
1814 info = va_arg(argptr,
void *);
1819 info = va_arg(argptr,
void *);
1820 channel = va_arg(argptr, INT);
1821 value = (float) va_arg(argptr,
double);
1826 info = va_arg(argptr,
void *);
1827 channel = va_arg(argptr, INT);
1828 pvalue = va_arg(argptr,
float*);
1833 info = va_arg(argptr,
void *);
1834 channel = va_arg(argptr, INT);
1835 name = va_arg(argptr,
char *);
1839 case CMD_GET_CURRENT:
1840 info = va_arg(argptr,
void *);
1841 channel = va_arg(argptr, INT);
1842 pvalue = va_arg(argptr,
float*);
1846 case CMD_SET_CURRENT_LIMIT:
1847 info = va_arg(argptr,
void *);
1848 channel = va_arg(argptr, INT);
1849 value = (float) va_arg(argptr,
double);
1854 case CMD_SET_TRIP_TIME:
1855 case CMD_SET_RAMPUP:
1856 case CMD_SET_RAMPDOWN:
1857 case CMD_SET_VOLTAGE_LIMIT:
1859 case CMD_GET_DEMAND:
1860 case CMD_GET_THRESHOLD:
1861 case CMD_GET_THRESHOLD_CURRENT:
1862 case CMD_GET_THRESHOLD_ZERO:
1863 case CMD_GET_CURRENT_LIMIT:
1864 case CMD_GET_TRIP_TIME:
1865 case CMD_GET_RAMPUP:
1866 case CMD_GET_RAMPDOWN:
static INT fp_write_defaults(HNDLE hDB, HV_FUG_INFO *info)
int chk_attrib_rly(HV_FUG_INFO *info, int module, char *line)
INT startup_error
startup error tag
char * filter_sub_str(char *str, char *start, char *stop, char *result)
int num_channels
number of channels in the DD
int module_cdc_in
FP module address for current measured.
DWORD last_reconnect
timer for bus driver reconnect error handling
int module_vdc_out
FP module address for HV demand.
float ramping_speed_up
ramping speed up (kV/s)
HNDLE hDDkey
ODB key to the device driver info.
static INT fp_power_up_clear(HNDLE hDB, HV_FUG_INFO *info)
#define FP_AI_110_RANGE
0 - 10.4 V
HNDLE hDB
main handle to the ODB
#define HV_FUG_SETTINGS_INTERNAL_STR
#define HV_FUG_READ_ERROR
return value in case a read back error occured
#define HV_FUG_SETTINGS_PROPERTIES_STR
static HV_FUG_FP hv_fug_fp_set[12]
char map_fp_fug_output[12][64]
mapping field point<->FUG of the output channels
#define HV_FUG_TIME_OUT
time out for read rs232 communication in (ms).
float max_volt
maximal high voltage for this FUG device (kV)
#define FP_RLY_SETTING
default reply
LEM_SC_WATCHDOG scw
slowcontrol watchdog info structure
#define FP_AO_210_RANGE
0 - 10.2 V
#define FP_AO_NORM
Max FUG prog / Max AO.
float ramping_speed_down
ramping speed down (kV/s)
#define HV_FUG_DELTA_TIME_ERROR
reset error counter after HV_FUG_DELTA_TIME_ERROR seconds
INT hv_fug_get(HV_FUG_INFO *info, INT channel, float *pvalue)
INT hv_fug_get_current(HV_FUG_INFO *info, INT channel, float *pvalue)
void * bd_info
private info of bus driver
#define HV_FUG_SETTINGS_OUT_STR
#define HV_FUG_SETTINGS_ODB_OFFSET_STR
void err_bad_channels(char *line, int module, HV_FUG_INFO *info)
int channel_cdc_in
FP module channel for current measured.
void mid_str(char *start, char *stop, char *line, char *result)
float last_valid_hv[25]
last valid measured hv
char fp_io_modules[128]
list of the field point modules
#define HV_FUG_SCW_STR
defines the slowcontrol default watchdog info structure
static INT fp_check_modules(HNDLE hDB, HV_FUG_INFO *info)
BOOL hv_switchable
flag: FUG device for which polarity is remote switchable
INT scw_in_use
flag indicating if the slowcontrol watchdog shall be used
int ets_logout(void *info, int wait, int detailed_msg)
#define FP_IO_NUM_CH
channels per module
INT readback_failure
counts the number of readback failures
int bd_connected
flag showing if the bus driver is connected
INT ets_in_use
flag indicating if the rs232 terminal server is in use
#define HV_FUG_MAX_READBACK_FAILURE
maximum number of readback failures before a reconnect will take place
int no_fp_modules
number of field point modules
static INT fp_check_attrib_settings(HNDLE hDB, HV_FUG_INFO *info)
int chksumchk(char *line, char *chksum)
INT hv_fug_set_current_limit(HV_FUG_INFO *info, INT channel, float limit)
float last_valid_current[25]
last valid measured current
void sub_str(int start, int stop, char *line, char *result, int size_line, int size_result)
#define HV_FUG_RECONNECTION_TIMEOUT
timeout in (sec) for before trying to reconnect again (after a communication breakdown) ...
float init_curr
initial current limit (mA)
char name[80]
name of the FUG device
#define FP_IO_RESOL
resolution of the i/o commands 2^16
HNDLE hkey
ODB equipment key.
int channel_relais_in
FP relay module channel for the measured polarity.
int channel_relais_out
FP relay module channel for the demand polarity.
#define HV_FUG_SETTINGS_IN_STR
char fug_properties[12][64]
property list of the FUG HV devices
int module_relais_in
FP relay module address for the measured polarity.
float init_volt
initial HV demand (kV)
INT hv_fug_init(HNDLE hKey, void **pinfo, INT channels, INT(*bd)(INT cmd,...))
#define HV_FUG_ETS_LOGOUT_SLEEP
sleep time (us) between the telnet commands of the ets_logout
INT errorcount
error limiter
#define FP_AI_NORM
Max AI / Max FUG prog.
int module_cdc_out
FP module address for current demand.
int chk_attrib_in(HV_FUG_INFO *info, int module, char *line)
INT hv_fug_set(HV_FUG_INFO *info, INT channel, float value)
int reconnection_failures
how often reconnection failed
int channel_vdc_in
FP module channel for HV measured.
#define HV_FUG_SETTINGS_MODULE_STR
char map_fp_fug_input[12][64]
mapping field point<->FUG of the input channels
int odb_offset
channel offset within ODB
INT hv_fug_get_label(INT channel, char *name)
HV_FUG_SETTINGS hv_settings
ODB hot-link data for the DD.
INT detailed_msg
flag indicating if detailed status/error messages are wanted
float max_curr
maximal current for this FUG device (mA)
int module_vdc_in
FP module address for HV measured.
INT(* bd)(INT cmd,...)
bus driver entry function
#define HV_FUG_MAX_ERROR
maximum number of error messages
INT fp_error_msg(HV_FUG_INFO *info, char *where, char *error)
#define HV_FUG_SETTINGS_NO_STR
INT hv_fug_exit(HV_FUG_INFO *info)
int channel_vdc_out
FP module channel for HV demand.
#define FP_AI_110_FILTER
60 Hz
INT first_bd_error
flag showing if the bus driver error message is already given
static INT hv_fug_update_db_settings(HNDLE hDB, HV_FUG_INFO *info, INT channels)
int chk_attrib_out(HV_FUG_INFO *info, int module, char *line)
stores internal informations within the DD.
DWORD lasterrtime
timer for error limiter
int channel_cdc_out
FP module channel for current demand.
int module_relais_out
FP relay module address for the demand polarity.