/*************************************** * * ***************************************/ #include #include #include #include #include #include #include "a200.h" #include "../lib/mylib1.h" #include "../dbase/hv_dbase.h" main(argc, argv) int argc; char *argv[]; { hv_mod_struct *mid; char old_chamber[6]; int tcp_ip_nr, cpu_nr; char *hv_config[3]; short i, j, k, chan, value, code; int dis, sl; char *par_code, *crate_code, *chan_code, *set_code, *chamber_code; short par_val, crate_val, chan_val, set_val; int is_a_cable; int n_ch_switched = 0; int n_ch_tobe_switched = 0; char cline[80], str0[20]; int conditioner = 0; int sitter = 0; int d_crate[4], d_slot[4], hv_crate, hv_ch_A, hv_ch_Ref; if (argc < 3 || *argv[1] =='-') usage(); conditioner = 0; if (argc == 4 && atoi(argv[3]) == COND_CODE) conditioner = 1; else if (argc == 4 && ( strcmp(argv[3], "tubi_sitter") == 0 || strcmp(argv[3], "TUBI_SITTER") == 0) ) sitter = 1; chamber_code = argv[1]; if ( strcmp("all", chamber_code) == 0 || strcmp("ALL", chamber_code) == 0) chamber_code = "0"; if ( strcmp("on", argv[2]) != 0 && strcmp("ON", argv[2]) != 0 && strcmp("off", argv[2]) != 0 && strcmp("OFF", argv[2]) !=0 ) usage(); is_a_cable = 0; if (*(chamber_code + 2) == '/') is_a_cable = 1; get_config(&tcp_ip_nr, &cpu_nr, hv_config); if ((mid = (hv_mod_struct *)modlink(hv_config[cpu_nr], 0)) == (hv_mod_struct *)-1) if ((mid = (hv_mod_struct *)modload(hv_config[cpu_nr], 0)) == (hv_mod_struct *)-1) exit(_errmsg(errno, " %s: error loading/linking module %s\n", argv[0], hv_config[cpu_nr])); strcpy(old_chamber, "??"); n_ch_tobe_switched = 0; for (i = 1; i < 4; i++){ d_crate[i] = -1; d_slot[i] = -1; } printf(" \n"); for(dis = 0; dis < mid->n_crates; dis++) for(sl = 0; sl < 4; sl++){ if (mid->distr[dis].slot[sl].cond IS_CONDITIONING && conditioner == 0){ printf(" operation not allowed \n"); printf(" cable %s is under conditioning \n", mid->distr[dis].slot[sl].cable_name); } else if (mid->distr[dis].slot[sl].cond IS_SITTERING && !sitter){ mid->distr[dis].slot[sl].cond &= ~SITTERING; } if((strcmp(chamber_code, mid->distr[dis].slot[sl].chamber) == 0 || ( strcmp("0", chamber_code) == 0 && mid->distr[dis].slot[sl].hv_ch_Ref >= 0 ) ) && ( !(mid->distr[dis].slot[sl].cond IS_CONDITIONING) || conditioner) && /* aggiunta condizione NO BAD (23/6/96) */ !mid->distr[dis].slot[sl].bad ){ /* printf(" d_crate %d, slot %d, hv_ch_A %d, hv_ch_Ref %d:\n", mid->distr[dis].crate_nr , sl, mid->distr[dis].slot[sl].hv_ch_A, mid->distr[dis].slot[sl].hv_ch_Ref); printf(" cable %s \n", mid->distr[dis].slot[sl].cable_name); */ if ( mid->distr[dis].slot[sl].d_used_ch ){ /* se nuova camera, esegui vecchio comando */ if(strcmp(old_chamber, mid->distr[dis].slot[sl].chamber) ){ strcpy(old_chamber, mid->distr[dis].slot[sl].chamber); if (n_ch_tobe_switched){ cline[0] = '\0'; strncat(cline, "d_hv_switch " , strlen("d_hv_switch ")); itoa(d_crate[0], str0); strncat(cline, str0, strlen(str0)); strncat(cline, " ", strlen(" ")); itoa(d_slot[0], str0); strncat(cline, str0, strlen(str0)); strncat(cline, " ", strlen(" ")); itoa(d_crate[1], str0); strncat(cline, str0, strlen(str0)); strncat(cline, " ", strlen(" ")); itoa(d_slot[1], str0); strncat(cline, str0, strlen(str0)); strncat(cline, " ", strlen(" ")); itoa(d_crate[2], str0); strncat(cline, str0, strlen(str0)); strncat(cline, " ", strlen(" ")); itoa(d_slot[2], str0); strncat(cline, str0, strlen(str0)); strncat(cline, " ", strlen(" ")); itoa(d_crate[3], str0); strncat(cline, str0, strlen(str0)); strncat(cline, " ", strlen(" ")); itoa(d_slot[3], str0); strncat(cline, str0, strlen(str0)); strncat(cline, " ", strlen(" ")); itoa(hv_crate, str0); strncat(cline, str0, strlen(str0)); strncat(cline, " ", strlen(" ")); itoa(hv_ch_A, str0); strncat(cline, str0, strlen(str0)); strncat(cline, " ", strlen(" ")); itoa(hv_ch_Ref, str0); strncat(cline, str0, strlen(str0)); strncat(cline, " ", strlen(" ")); strncat(cline, argv[2], strlen(argv[2])); strncat(cline, " &", strlen(" &")); n_ch_switched += n_ch_tobe_switched; system( cline ); printf(" command '%s' executed\n", cline); for (i = 1; i < 4; i++){ d_crate[i] = -1; d_slot[i] = -1; } n_ch_tobe_switched = 0; } } if ( strcmp(mid->distr[dis].slot[sl].chamber,"01") == 0 ){ cline[0] = '\0'; strncat(cline, "sy127_set_special " , strlen("sy127_set_special ")); strncat(cline, "switch " , strlen("switch ")); itoa((int)mid->hv_crate, str0); strncat(cline, str0, strlen(str0)); itoa((int)mid->distr[dis].slot[sl].hv_ch_Ref, str0); strncat(cline, " ", strlen(" ")); strncat(cline, str0, strlen(str0)); strncat(cline, " ", strlen(" ")); strncat(cline, argv[2], strlen(argv[2])); strncat(cline, " &", strlen(" &")); n_ch_switched++; system( cline ); printf(" command '%s' executed\n", cline); } else{ d_crate[ n_ch_tobe_switched ] = mid->distr[dis].crate_nr; d_slot[ n_ch_tobe_switched ] = sl; n_ch_tobe_switched++; hv_crate = mid->hv_crate; hv_ch_A = mid->distr[dis].slot[sl].hv_ch_A; hv_ch_Ref = mid->distr[dis].slot[sl].hv_ch_Ref; } } } } if (n_ch_tobe_switched){ cline[0] = '\0'; strncat(cline, "d_hv_switch " , strlen("d_hv_switch ")); itoa(d_crate[0], str0); strncat(cline, str0, strlen(str0)); strncat(cline, " ", strlen(" ")); itoa(d_slot[0], str0); strncat(cline, str0, strlen(str0)); strncat(cline, " ", strlen(" ")); itoa(d_crate[1], str0); strncat(cline, str0, strlen(str0)); strncat(cline, " ", strlen(" ")); itoa(d_slot[1], str0); strncat(cline, str0, strlen(str0)); strncat(cline, " ", strlen(" ")); itoa(d_crate[2], str0); strncat(cline, str0, strlen(str0)); strncat(cline, " ", strlen(" ")); itoa(d_slot[2], str0); strncat(cline, str0, strlen(str0)); strncat(cline, " ", strlen(" ")); itoa(d_crate[3], str0); strncat(cline, str0, strlen(str0)); strncat(cline, " ", strlen(" ")); itoa(d_slot[3], str0); strncat(cline, str0, strlen(str0)); strncat(cline, " ", strlen(" ")); itoa(hv_crate, str0); strncat(cline, str0, strlen(str0)); strncat(cline, " ", strlen(" ")); itoa(hv_ch_A, str0); strncat(cline, str0, strlen(str0)); strncat(cline, " ", strlen(" ")); itoa(hv_ch_Ref, str0); strncat(cline, str0, strlen(str0)); strncat(cline, " ", strlen(" ")); strncat(cline, argv[2], strlen(argv[2])); strncat(cline, " &", strlen(" &")); } if (n_ch_tobe_switched){ n_ch_switched += n_ch_tobe_switched; system( cline ); printf(" command '%s' executed\n", cline); } munlink(mid); if (!n_ch_switched) printf(" Unkown chamber name \n"); else ; /* RICORDARSI DI RIPRISTINARE store_command */ /* store_command(cpu_nr, argc, argv); */ } usage() { printf(" hv_switch : to switch on/off a Chamber\n\n"); printf(" usage : hv_switch Chamber_name command\n"); printf(" The Chamber_name is interpreted as CABLE_name\n"); printf(" if the format XX/Y is used ( e.g. : 52/2 ) \n"); printf(" - the Chamber_name can be ALL \n"); printf(" - the command can be ON or OFF \n"); exit(0); }