示例#1
0
int update_qpll() {
int rc,rcret=0; w32 stat; 
//int mainerr,mainlck,bc1err,bc1lck; char buffer[50];
if(envcmp("VMESITE", "ALICE")==0) {
  if(micratepresent()& 0x2) {
    stat= readstatus();
  } else { stat=0xfff; };
  // update freqs:
  if(micratepresent()& 0x1) {
    getRFRX(vspRFRX[0], rfrx1); getRFRX(vspRFRX[1], rfrx2);
    freqs[0]= rfrx1[2].freq; freqs[1]= rfrx2[2].freq;
    freqs[2]= rfrx1[1].freq; freqs[3]= rfrx2[1].freq;
  };
  //printf("ref bc1 orbit1\n"); printf("--- bc2 orbit2\n");
} else {
  /* simulate change:
  stat= qpllstat+1;
  rfrx1[2].freq= rfrx1[2].freq + 1;
  rfrx2[2].freq= rfrx2[2].freq + 1;
  rfrx1[1].freq= rfrx1[1].freq + 10;
  rfrx2[1].freq= rfrx2[1].freq + 10; */
  ;  // do not change
};
if((freqs[0] != rfrx1[2].freq) ||
   (freqs[1] != rfrx2[2].freq) ||
   (freqs[3] != rfrx1[1].freq) ||
   (freqs[4] != rfrx2[1].freq)
) {
  rc= dis_update_service(FREQSid);
};
//stat=qpllstat+1; //simulate change
if(stat != qpllstat) {
  char msg[100];
  qpllstat= stat;
  sprintf(qpllnow,"%3.3x", qpllstat);
  rc= dis_update_service(QPLLid);
  if((stat | REF_MASK) != (qpllstat | REF_MASK)) {
    sprintf(msg, "QPLL update (ref ignored here) rc:%d qpllstat:0x%x",
      rc,qpllstat);
    prtLog(msg);
  };
  /*
  mainerr= (qpllstat & 0x2)>>1; mainlck= (qpllstat & 0x1);
  bc1err= (qpllstat & 0x80)>>7; bc1lck= (qpllstat & 0x40)>>6;
  sprintf(buffer, "mon ds006:ds007:ds008:ds009 N:%d:%d:%d:%d", 
    mainerr, mainlck, bc1err, bc1lck);
  rc= udpsend(udpsock, (unsigned char *)buffer, strlen(buffer)+1);
  prtLog(buffer); */
};
nlogqpll++;
if((nlogqpll % 36000)==0) {    // 3600:log 1 per 2 hours
  char msg[100];
  sprintf(msg, "qpllstat%d:0x%x", nlogqpll, qpllstat);
  prtLog(msg);
};
if(quit!=0) rcret=10;
return(rcret);
}
示例#2
0
/*-----------------------------------------------*/ void newclock(void *tag) {
/* this thread started with 2 events( only 1 available in one time):
- clock change
- DLL_RESYNC
*/
rcnewclock= 888;
newclockstarts++;
printf("newclock thread started. clocktran:%d tag:%d quit:%d\n", 
  clocktran, *(int *)tag, quit); fflush(stdout);
while(clocktran>=0) {
  int nclients;
  nclients= dis_update_service(MICLOCK_TRANSITIONid);
  printf("updated MICLOCK_TRANSITION clients:%d clocktran:%d\n", nclients, clocktran);
  if(clocktran==0) break;
  dtq_sleep(SLOT_S);
  clocktran--; sprintf(clocktransition,"%d", clocktran);
  if(clocktran==0) {
    if(*(int *)tag==0) {
      /*int rc;
      char cmd[]="$VMECFDIR/ttcmidaemons/sctel.py MININF";
      DLL_RESYNC(DLL_info); // commented 19092014
      //printf("DLL_RESYNC + clearing the scope persistance\n");
      rc= system(cmd);   commented 19092014
      printf("DLL_RESYNC + MININF not done!\n"); */
      DLL_RESYNC(DLL_info);
    } else {
#define reslen 3200
      int rc; char server[24]; char cmd[80]; char result[reslen];
      if(envcmp("VMESITE", "ALICE")==0) {
        strcpy(server, getenv("SERVER_NODE"));
      } else {
        strcpy(server, "adls");
      };
      infolog_trgboth(LOG_WARNING, "ALICE clock changed, restaring ctpproxy (25s)...");
      sprintf(cmd, "ssh trigger@%s ctpproxy.py restart nomasks", server);
      setbcorbit(*(int *)tag); 
      nclients= dis_update_service(MICLOCKid);
      printf("updated MICLOCK clients:%d\n", nclients);
      //printf("updated MICLOCK clients:%d, now ctpproxy.py restart nomasks...\n", nclients);
      rc= popenread(cmd, result, reslen);
      if(rc==EXIT_FAILURE) { 
        printf("ERROR cmd:%s rc:%d\n", cmd, rc);
      } else {
        printf("result(len:%d):%s\n", strlen(result), result);
      };  
    };
  };
  if(quit==1) clocktran=0;
}; clocktran_s=0;
rcnewclock= 0;
}
示例#3
0
文件: main_ctp.c 项目: juskoa/trigger
/*----------------------------------------*/ int main(int argc, char **argv) {
int rc;
int ssmcr_tries=0;
infolog_SetFacility("CTP"); infolog_SetStream("",0);
#ifdef PQWAY
printf("main_ctp: opening rec/send queues...\n");
mq_rec= pq_open();
if(mq_rec==(mqd_t)-1) {
  infolog_trgboth(LOG_FATAL, "posix mq_rec not created");
  exit(8);
}
mq_sendmsg= pq_connect();
if(mq_sendmsg==(mqd_t)-1) {
  infolog_trgboth(LOG_FATAL, "posix mq_sendmsg not connected");
  exit(8);
}
#endif
signal(SIGUSR1, gotsignal); siginterrupt(SIGUSR1, 0);
signal(SIGQUIT, gotsignal); siginterrupt(SIGQUIT, 0);
signal(SIGKILL, gotsignal); siginterrupt(SIGKILL, 0); // -9
signal(SIGTERM, gotsignal); siginterrupt(SIGTERM, 0); // kill pid
signal(SIGINT, gotsignal); siginterrupt(SIGINT, 0);   // CTRL C   2
partmode[0]='\0';
printf("cshmInit i.e. initBakery(swtriggers/ccread/ssmcr ONLY once, when shm allocated)...\n");
/*printf("initBakery(swtriggers,4): 0:SOD/EOD 1:gcalib 2:ctp.exe 3:dims\n");
printf("initBakery(ccread,5): 0:proxy 1:dims 2:ctp+busytool 3:smaq 4:inputs\n");
*/
cshmInit();
setglobalflags(argc, argv);

/* changed in aug2016 (initBakery only once from now, when shm allocated)
printf("initBakery(swtriggers,4): 0:SOD/EOD 1:gcalib 2:ctp.exe 3:dims\n");
initBakery(&ctpshmbase->swtriggers, "swtriggers", swtriggers_N);
printf("initBakery(ccread,6): 0:proxy 1:dims 2:ctp+busytool 3:smaq 4:inputs 5:orbitddl2\n");
initBakery(&ctpshmbase->ccread, "ccread", ccread_N);
printf("initBakery(ssmcr,4): 0:smaq 1:orbitddl2 2:ctp 3:inputs\n");
initBakery(&ctpshmbase->ssmcr, "ssmcr", ssmcr_N);
*/
printBakery(&ctpshmbase->swtriggers);
printBakery(&ctpshmbase->ccread);
printBakery(&ctpshmbase->ssmcr);
unlockBakery(&ctpshmbase->swtriggers,swtriggers_ctpproxy);
unlockBakery(&ctpshmbase->ccread,ccread_ctpproxy);
unlockBakery(&ctpshmbase->ssmcr,ssmcr_ctpproxy);

/* Let' synchronise with smcr only, i.e. 
- ccread_dims,... can go in parallel with ctp_Initproxy, 
  orbitddl2: should use ccread_orbitddl2 customer when reading counters
  
- swtriggers_gcalib/_dims cannot appear (no global runs becasue ctpproxy being restarted)
*/
while(1) { // do not allow SSM usage (smaq) because ctp_Initproxy is initialising it
  char msg[100];
  rc= lockBakeryTimeout(&ctpshmbase->ssmcr,ssmcr_ctpproxy, 10);
  if(rc==1) {
    if(ssmcr_tries>0) {
      sprintf(msg, "Got ssmcr resource after %d attempts", ssmcr_tries);
      infolog_trgboth(LOG_INFO, msg);
    };
    break;  // ssmcr reserved for me now
  };
  ssmcr_tries++;
  sprintf(msg,"%d secs Waiting for ssmcr resource. Is smaq stopped?", ssmcr_tries*10);
  infolog_trgboth(LOG_WARNING, msg);
};
if(isArg(argc, argv, "configrunset")) {
  /* do we need before orbitddl2.py INT/L2 orbit in SYNC (automatic with L2a)?
  */
  int rc, reslen;
  char cmd[200];
  char result[1000]="";   // ~ 10 lines
  char orbchanged[]="Warning: orbitoffset changed:";
  if(envcmp("VMESITE", "PRIVATE")==0) {
    strcpy(cmd, "who");
  } else {
    strcpy(cmd, "orbitddl2.py configrunset");
  };
  infolog_trgboth(LOG_INFO, "Starting L0 orbit calibration (30s...)");
  rc= popenread(cmd, result, 1000);   // opens vme...
  reslen= strlen(result);
  if((rc==EXIT_FAILURE) || (reslen<=1)) { 
    infolog_trgboth(LOG_ERROR, "L0 orbit calibration problem");
  } else {
    int ixr= reslen;
    if(result[ixr-1]=='\n') {   //remove last NL character if present
      result[ixr-1]='\0';
      ixr= reslen-2;
    } else {
      ixr= reslen-1;   // pointer to the last non-NEWLINE character
    };
    while(ixr>=0) {    // find last line
      if(result[ixr]=='\n') {
        ixr++; break;
      };
      ixr--;
    };
    sprintf(cmd, "L0 orbit calibration: %s", &result[ixr]);
    if((strcmp(&result[ixr], "Everything ok")==0) ||
       (strncmp(&result[ixr], orbchanged, strlen(orbchanged))==0)
      ) {
      infolog_trgboth(LOG_INFO, cmd);
    } else {
      infolog_trgboth(LOG_ERROR, cmd);
      infolog_trgboth(LOG_ERROR, "ctpproxy not started"); 
      unlockBakery(&ctpshmbase->ssmcr,ssmcr_ctpproxy);
      rc=8; goto STP;
    };
  };
};
// init CTP after calibration (e.g. to repair modifications done by orbitddl2.py)
rc=ctp_Initproxy();
unlockBakery(&ctpshmbase->ssmcr,ssmcr_ctpproxy);
if(rc!=0) goto STP;

// DIM services not registered here (see ctpdims.c), they run in separae task:
// ds_register();
strcpy(obj,argv[1]);
smi_attach(obj, SMI_handle_command);
printf("CTP attached to: %s\n",obj);
/* if smi_volatile: stops the ctp_proxy in case TRIGGER domain is down
smi_volatile();   
*/
strcpy(errorReason,"not set"); smi_set_parER();
strcpy(ORBIT_NUMBER,""); smi_set_par("ORBIT_NUMBER",ORBIT_NUMBER,STRING);
smi_setState("RUNNING");
while(1) {
#ifdef PQWAY
  executectp("wait");
#else
  usleep(1000000);
#endif
  if(quit>9) break;
};
rc= ctp_Endproxy();
STP:
#ifdef PQWAY
pq_close(mq_sendmsg, 0);
pq_close(mq_rec, 1);
#endif
printf("Calling cshmDetach()...\n"); cshmDetach();
return (rc);
}