Example #1
0
/*--------------------------------------------------- main */
int main(int argc, char **argv) {
int rc,grc=0;
//char *cs; 
char command[40];
char servername[40];
char cmd[80];

setlinebuf(stdout);
if(argc!=3) {
  printf("ERROR: Usage: linux/server servername command\n"); return(8);
};
infolog_SetFacility("CTP");
infolog_SetStream("",0);
strcpy(servername, argv[1]);
strcpy(command, argv[2]);
sprintf(cmd, "%s/%s", servername, command);   // CTPRCFG/RCFG
// following line has to be 1st line printed!
printf("DIM server:%s cmd:%s\n", servername, command); // should be 1st line

reset_insver();
/*cs=*/ readCS();
rc= readAliases(); 
if(rc==-1) {
  char emsg[200];
  strcpy(emsg,"aliases info from aliases.txt not updated correctly");
  infolog_trg(LOG_ERROR, emsg); printf("ERROR %s\n",emsg);
};
cshmInit();
readTables();   // + when ctpprxy restarted, i.e. in time of rcfgdel 0 ALL
printf("INFO ctpshmbase1:%p\n", ctpshmbase);
ctpc_clear(); ctpc_print(CNAMESString);
//updateCNAMES();
rc= getINT12fromcfg(INT1String, INT2String, MAXINT12LINE);
printf("INFO rc:%d INT1:%s INT2:%s\n", rc, INT1String, INT2String);

rc= mydbConnect();

dis_add_error_handler(error_handler);
dis_add_exit_handler(exit_handler);
dis_add_client_exit_handler (client_exit_handler);
// commands:
CTPRCFGRCFGid= dis_add_cmnd(cmd,"C", DOcmd, 88);
printf("INFO DIM cmd:%s id:%d\n", cmd, CTPRCFGRCFGid);
sprintf(cmd, "%s", servername);   // CTPRCFG binary (after LS1) RCFG request
CTPRCFGid= dis_add_cmnd(cmd,NULL, DOrcfg, 89);
printf("INFO DIM cmd:%s id:%d\n", cmd, CTPRCFGid);

sprintf(cmd, "%s/LTUCFG", servername);   // LTUCFG binary (after LS1)
LTUCFGid= dis_add_cmnd(cmd,NULL, DOltucfg, 90);
printf("INFO DIM cmd:%s id:%d\n", cmd, LTUCFGid);

sprintf(cmd, "%s/COM2DAQ", servername);   // CTPRCFG/COM2DAQ
C2Did= dis_add_cmnd(cmd,"C", DOcom2daq, 91);
printf("INFO DIM cmd:%s id:%d\n", cmd, C2Did);
sprintf(cmd, "%s/SETBM", servername);   // CTPRCFG/SETBM
SETBMid= dis_add_cmnd(cmd,"C", DOsetbm, 92);
printf("INFO DIM cmd:%s id:%d\n", cmd, SETBMid);
/*
sprintf(cmd, "%s/FSUPDATE", servername);   // CTPRCFG/FSUPDATE
FSUid= dis_add_cmnd(cmd,NULL, DOfsupdate, 92);
printf("INFO DIM cmd:%s id:%d\n", cmd, FSUid);
*/
// services:
sprintf(cmd, "%s/INT1", servername);   // CTPRCFG/INT1
INT1id=dis_add_service(cmd,"C:99", INT1String, MAXINT12LINE, NULL, 4567);
printf("INFO DIM service:%s id:%d\n", cmd, INT1id);
sprintf(cmd, "%s/INT2", servername);   // CTPRCFG/INT2
INT2id=dis_add_service(cmd,"C:99", INT2String, MAXINT12LINE, NULL, 4568);
printf("INFO DIM service:%s id:%d\n", cmd, INT2id);
sprintf(cmd, "%s/CS", servername);   // CTPRCFG/CS
CSid=dis_add_service(cmd,"C", CSString, MAXCSString, CScaba, 4569);
printf("INFO DIM service:%s id:%d\n", cmd, CSid);
sprintf(cmd, "%s/CNAMES", servername);   // CTPRCFG/CNAMES
CNAMESid=dis_add_service(cmd,"C", CNAMESString, MAXCNAMESString, CNAMEScaba, 4570);
printf("INFO DIM service:%s id:%d\n", cmd, CNAMESid);

dis_start_serving(servername);  
while(1) {
  char *frc;
#define MAXLINECS 8000
  char line[MAXLINECS];   //80 chars per class for NCLASS classes
  //sleep(10);
  frc= fgets(line, MAXLINECS, stdin);
  if(frc==NULL) break;
  if(strncmp(line,"quit",4)==0) {
    break;
  } else if(strncmp(line,"class ",6)==0) {
    int rcdaq;
    printf("INFO igDAQLOGBOOK:%d line:%s",ignoreDAQLOGBOOK, line);
    /* from 28.5.2013: DAQlogbook opened/closed when ctp_proxy restarted
    rcdaq= daqlogbook_open();
    if(rcdaq==-1) {
      printf("ERROR DAQlogbook_open failed\n");
    } else {
      if(ignoreDAQLOGBOOK==0) {
        rcdaq= updateDAQDB(line);
        if(rcdaq!=0) {
          printf("ERROR updateDAQLOGBOOK failed. rc=%d\n", rcdaq);
        };
        rcdaq= daqlogbook_close();
        if(rcdaq==-1) {
          printf("ERROR DAQlogbook_close failed\n");
        };
      };
    };*/
    rcdaq= updateDAQDB(line);
    if(rcdaq!=0) {
      printf("ERROR updateDAQLOGBOOK failed. rc=%d\n", rcdaq);
    };
  } else if(strncmp(line,"inpupd ",7)==0) {
    update_ctpins(line);
  } else if(strncmp(line,"indets ",7)==0) {
    int ix, ix1, runnumb; char *efstart;
    ix1= sscanf(&line[7], "%d ", &runnumb);
    efstart= strstr(&line[7], "0x");   // indets runN 0xeffiout 0xindets
    ix= sscanf(efstart, "0x%x 0x%x\n", &effiout, &indets);
    printf("INFO ix1:%d runnumb:%d ix:%d effiout:0x%x indets:0x%x\n",
      ix1, runnumb, ix, effiout, indets); fflush(stdout);
    //rcupd= updeff_insver(runnumb, effiout);
  } else if(strncmp(line,"cmd ",4)==0) {
    int unsigned ix,rcsystem;
    for(ix=0; ix<strlen(line); ix++) {
      if(line[ix]=='\n'){ line[ix]='\0'; break; };
    };
    rcsystem= system(&line[4]);
    printf("INFO rc:%d cmd:%s\n", rcsystem, &line[4]);   
    continue;
  } else {
    printf("ERROR %s", line); fflush(stdout);
  };
};
rc= daqlogbook_close();
if(rc==-1) {
  printf("ERROR DAQlogbook_close failed\n");
};
mydbDisconnect();
stopserving();
cshmDetach(); printf("INFO shm detached.\n");
return(grc);
}
Example #2
0
/*--------------------------------------------------------------- ds_register
*/
void ds_register() {
int ix,rc=0; int rcexit=0;
char command[MAXCMDL];

if(micratepresent()& 0x2) {
  char msg[200]="";
  vspRF2TTC=0;
  rc= vmxopenam(&vspRF2TTC, "0xf00000", "0x100000", "A32");
  sprintf(msg, "vmxopen RF2TTC rc:%d vsp:%d\n", rc, vspRF2TTC); printf(msg);
  if(rc!=0) {
    rcexit=8;
  };
} else {
  printf("RF2TTC not connected\n");
};
if(micratepresent()& 0x1) {
  rc= openrfrxs();
  if(rc!=0) {
    rcexit=8;
  };
} else {
  printf("RFRXs not connected\n");
};
if(micratepresent()& 0x2) {
  //w32 bcm, om;
  //bcm= vmer32(BCmain_MAN_SELECT); om= vmer32(ORBmain_MAN_SELECT);
  //printf("ds_register1: 0x%x 0x%x\n", bcm, om);
  writeall(); 
  //bcm= vmer32(BCmain_MAN_SELECT); om= vmer32(ORBmain_MAN_SELECT);
  //printf("ds_register2: 0x%x 0x%x\n", bcm, om);
};
if(micratepresent()& 0x1) {
  int ix;
  printf("getRFRX way:\n");
  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:"); for(ix=0; ix<3; ix++) {
    printf("%d/%f ", rfrx1[ix].ref, rfrx1[ix].freq);
  }; printf("\n");
  printf("--- bc2 orbit2:"); for(ix=0; ix<3; ix++) {
    printf("%d/%f ", rfrx2[ix].ref, rfrx2[ix].freq);
  }; printf("\n"); 
} else {
  printf("RFRXs not connected\n");
  for(ix=0; ix<=4; ix++) {
    freqs[ix]=0.0;
  };
};
if(rcexit!=0) exit(rcexit);
printenvironment();
printf("DIM server:%s\n",MYNAME);
dis_add_error_handler(error_handler);
dis_add_exit_handler(exit_handler);
//dis_add_client_exit_handler (client_exit_handler);
printf("Commands:\n");
strcpy(command, MYNAME); strcat(command, "/MICLOCK_SET");
dis_add_cmnd(command,"C", MICLOCK_SETcmd, MICLOCK_SETtag);  printf("%s\n", command);
strcpy(command, MYNAME); strcat(command, "/CORDE_SET");
dis_add_cmnd(command,"C", CORDE_SETcmd, CORDE_SETtag);  printf("%s\n", command);
strcpy(command, MYNAME); strcat(command, "/DLL_RESYNC");
dis_add_cmnd(command,"C", DLL_RESYNCcmd, DLL_RESYNCtag);  printf("%s\n", command);

printf("\nServices:\n");
strcpy(command, MYNAME); strcat(command, "/MICLOCK");
MICLOCKid=dis_add_service(command,"C", clocknow, MAXLILE+1,
  MICLOCKcaba, MICLOCKtag);  printf("%s\n", command);
strcpy(command, MYNAME); strcat(command, "/MICLOCK_TRANSITION");
MICLOCK_TRANSITIONid=dis_add_service(command,"C", clocktransition, 2,
  NULL, MICLOCK_TRANSITIONtag);  printf("%s\n", command);
strcpy(command, MYNAME); strcat(command, "/SHIFT");
SHIFTid=dis_add_service(command,"C", shiftnow, MAXLILE+1,
  SHIFTcaba, SHIFTtag);  printf("%s\n", command);
strcpy(command, MYNAME); strcat(command, "/QPLL");
//QPLLid=dis_add_service(command,"C", qpllnow, MAXLILE+1,
QPLLid=dis_add_service(command, "L", &qpllstat, sizeof(qpllstat),
//  QPLLcaba, QPLLtag);  printf("%s\n", command);
  NULL, QPLLtag);  printf("%s\n", command);
strcpy(command, MYNAME); strcat(command, "/RFRX");
FREQSid=dis_add_service(command,"F:4", freqs, 16,
  FREQScaba, FREQStag);  printf("%s\n", command);

rc=dis_start_serving(MYNAME);  
printf("serving rc:%d\n", rc);
printf("not Starting the thread reading BC*QPLL_STATUS regs...\n");
//dim_start_thread(qpll_thread, (void *)&TAGqpll_thread);
}