/*************************************** * cond.c * * to fork and send commands to * * conditioning program "xxcond" * * * ***************************************/ #include #include #include #include #include #include "../lib/mylib1.h" #include "a200.h" #include "../dbase/hv_dbase.h" extern int os9forkc(); extern char **environ; char *argblk[5]; int hra[6]; int ev127_id; FILE *fp, *fopen(); unsigned long pid; struct to_xxcond{ int command; /* 1: start; 2: stop; 3: show; 4: abort ( 0: command executed ) */ char cable[4]; /* e.g. 34/1 */ char cond_type; /* A, B, C ... */ unsigned long id; /* process ID of xxcond */ unsigned long ch_status; /* return value from xxcond */ unsigned long steps[20]; /* for each step gives number of trials */ int n_steps; /* total number of steps of the conditioning */ }; main(argc,argv) int argc; char **argv; { to_xxcond *mod_cond; hv_mod_struct *hv_mid; int tcp_ip_nr, cpu_nr; char *hv_config[3]; int ev127_id, ev227_id, evpro_id; int i; short sy127_crate; short dis, cr, sl; int command_to_xxcond; if (argc < 2) usage(); to_upper(argv[1]); if (strcmp(argv[1], "INIT") == 0) command_to_xxcond = 1; else if (strcmp(argv[1], "ABORT") == 0) command_to_xxcond = 2; else if (strcmp(argv[1], "START") == 0) command_to_xxcond = 3; else if (strcmp(argv[1], "STOP") == 0) command_to_xxcond = 4; else if (strcmp(argv[1], "SHOW") == 0) command_to_xxcond = 5; else usage(); if(command_toxxcond == 1){ /* first reset old semaphores and delete old data modules */ system("evdel cond_com"); /* create semaphores */ cond_com_id = sem_link_cr("cond_com", argv[0]); /* create module to communicate with xxcond */ if((cond_mod = ( to_xxcond *)modlink("to_xxcond", 0)) == (to_xxcond *)-1){ sem_wait(cond_com_id, argv[0]); if(( = (to_xxcond *)_mkdata_module("to_xxcond", sizeof(to_xxcond), 0x8001, 0x0033)) == (to_xxcond *)-1) /* see module.h for attr,perm */ exit(_errmsg(errno,"to_xxcond: err. link/create data module\n")); cond_mod->command = 0; cond_mod->id = 0; sem_free(cond_com_id, argv[0]); } /* identifies the cpu in order to point to the right database */ get_config(&tcp_ip_nr, &cpu_nr, hv_config); if ((hv_mid = (hv_mod_struct *)modlink(hv_config[cpu_nr], 0)) == (hv_mod_struct *)-1) if ((hv_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])); sy127_crate = hv_mid->hv_crate; sem_wait(cond_com_id, argv[0]); pid = cond_mod->id; sem_free(cond_com_id, argv[0]); if(pid == 0){ argblk[0] = "xxcond"; itoa(tcycle, parm1); argblk[1] = "23011925"; /* password */ argblk[2] = 0; if ((pid=os9exec(os9forkc,argblk[0],argblk,environ,0,0,3)) == -1) exit(_errmsg(0," error returned from os9exec(%s) \n", argblk[0])); sem_wait(cond_com_id, argv[0]); cond_mod->id = pid; sem_free(cond_com_id, argv[0]); printf(" cond: process xxcond forked \n"); } else printf(" cond: process xxcond already exists !! \n"); /* unlink dbase module */ munlink(hv_mid); sem_unl(cond_com_id, argv[0]); } usage() { printf(" cond : LST conditioning \n\n"); printf(" usage : cond command [ chamber ] [ cond_type ] \n"); printf(" | | | \n"); printf(" | | |-> A, B, C \n"); printf(" | |-> ( e.g. 33/1 ) \n"); printf(" | \n"); printf(" |-> INIT : to initialise 'conditioner')\n"); printf(" ABORT : to end 'conditioner') \n"); printf(" START : start the conditioning\n"); printf(" ( chamber name and cond_type \n"); printf(" must be given ) \n"); printf(" STOP : stop the conditioning of \n"); printf(" a chamber ( name must be given)\n"); printf(" This command is needed also if\n"); printf(" the conditioning is ended well\n"); printf(" in order to unlink the chamber\n"); printf(" from the conditioning program.\n"); printf(" SHOW : show conditioning info of \n"); printf(" a chamber\n"); exit(0); }