Ejemplo n.º 1
0
/* line: inpupd runn ix1 ix2 ...
 * ix1: 1..60  (24+24+12)
*/
void update_ctpins(char *line) {
unsigned int runn; 
int ixc, ixl;
char value[16];
enum Ttokentype t1;
char emsg[100];
emsg[0]='\0';
ixl= 7; t1= nxtoken(line, value, &ixl);   // runn
if(t1==tINTNUM) {
  runn= str2int(value);
} else {
  sprintf(emsg,"pydim update_ctpins: bad line:%60s",line);
  infolog_trg(LOG_ERROR, emsg); printf("%s\n",emsg);
  return;
};
for(ixc=0; ixc<NCTPINPUTS; ixc++) {
  t1= nxtoken(line, value, &ixl);   // 1..60
  if(t1==tEOCMD) {break;};
  if(t1==tINTNUM) {
    int ixin;
    ixin= str2int(value);
    ctpc_addinp(ixin, runn);
  } else {
    sprintf(emsg,"pydim update_ctpins: bad line:%60s",line);
    infolog_trg(LOG_ERROR, emsg); printf("%s\n",emsg);
    ctpc_delrun(runn);
    break;
  };
};
//updateCNAMES(); it is enough to update it in updateDAQDB
}
Ejemplo n.º 2
0
----------------------------------------*/ void read_gcalibcfg() {
FILE* gcalcfg;
enum Ttokentype token;
char line[MAXLINELENGTH], value[MAXCTPINPUTLENGTH];
char em1[200]="";
gcalcfg= openFile("gcalib.cfg","r");
if(gcalcfg==NULL) {
  prtLog("gcalib cannot be read. Using defaults");
  return;
};
while(fgets(line, MAXLINELENGTH, gcalcfg)){
  int ix,det,milsec, roc,log;
  roc=0; log=0;
  //printf("Decoding line:%s ",line);
  if(line[0]=='#') continue;
  if(line[0]=='\n') continue;
  ix=0; token= nxtoken(line, value, &ix);
  if(token==tSYMNAME) {
    char ltuname[20];
    strcpy(ltuname, value);
    det= findLTUdetnum(ltuname);
    if(det<0) {
      strcpy(em1,"bad LTU name in gcalib.cfg"); goto ERR; 
    };
    token=nxtoken(line, value, &ix);
    if(token==tINTNUM) {         // period in ms
      milsec= str2int(value);
    } else {strcpy(em1,"bad period (integer expected ms) in gcalib.cfg"); goto ERR; };
    ACTIVEDETS[det].periodms= milsec;
    token=nxtoken(line, value, &ix);
    if(token==tINTNUM) {         // roc (decimal)
      roc= str2int(value);
    } else if(token != tEOCMD) {
      strcpy(em1,"bad ROC (0-7 expected) in gcalib.cfg"); goto ERR;
    };
    token=nxtoken(line, value, &ix);
    if(token==tSYMNAME) {
      if(value[0]=='y') {
        log= 1;
      } else if(value[0]=='n') {
        log= 0;
      } else {
        sprintf(em1,"bad LOG option %s (y or n expected) in gcalib.cfg", value); goto ERR;
      }
    } else if((token != tEOCMD) && (token!=tCROSS)) {
      sprintf(em1,"bad LOG option  %s(y or n expected) in gcalib.cfg", value); goto ERR;
    };
    ACTIVEDETS[det].logroc= (log<<4) | roc;
    sprintf(em1,"gcalib.cfg:%s %dms 0x%x", ACTIVEDETS[det].name, ACTIVEDETS[det].periodms,
      ACTIVEDETS[det].logroc);
    prtLog(em1); em1[0]='\0';
  } else {strcpy(em1,"LTU name expected"); goto ERR; };
};
ERR: 
fclose(gcalcfg); if(em1[0]!='\0') prtLog(em1); return;
};
Ejemplo n.º 3
0
----------------------------*/ int getNextFunName(char *line, char *name) {
int ix=0,rc=0; enum Ttokentype token; char value[100]; 
while(1) {
  char c;
  c= line[ix];
  if((c=='|') || (c=='&') || (c==' ') || (c=='~') || (c=='(') ||(c==')')) {
    ix++;
  } else if((c==':') || (c=='\n') || (c=='\0') ) {
    rc=-1; return(-1);
  } else if(c=='0') {   // names starts with '0'
    ix++ ; break;
  };
};
//printf("gNFN:line:%s:\n",line);
strcpy(name,"0"); rc=ix;
while(1) {
  token= nxtoken(line, value, &rc);
  //printf("gNFN:%d:%s:\n", token, value);
  if(token==tEOCMD) {rc=-1; break;
  } else if((token==tERR) && (value[0]==':')) {rc=-1; break;
  } else {strcat(name, value); break;
  };
};
return(rc);
}
Ejemplo n.º 4
0
/*--------------------*/ void DOsetbm(void *tag, void *msg, int *size)  {
// msg: beammode_number beammode
int ixl, bmN; char errmsg[200]="";
char *line;
#define MAXBM 50
char value[MAXBM];
char beammode[MAXBM];
enum Ttokentype t1;
line= (char *)msg;
printf("INFO DOsetbm len:%d m:%s\n", *size, line); 
if(*size > MAXBM) {
  printf("ERROR too long msg for DOsetbm\n"); return;
};
ixl=0; t1= nxtoken(line, value, &ixl);   // beammodeN
if(t1==tINTNUM) {
  int ic; w32 maxbml;
  maxbml= strlen("INJECTION PHYSICS BEAM");
  bmN= str2int(value);
  cshmSetBM(bmN);
  /*t1= nxtoken(line, value, &ixl);   // beammode text till the EOL
  if(t1==tSYMNAME) { */
  for(ic=0; ic<(MAXBM-1); ic++) {
    if(((line[ixl+ic]) == '\n') ||
       ((line[ixl+ic]) == '\0') ||
       ((ixl+ic)>= (*size) ) ) {
      value[ic]= '\0';
      break;
    };
    value[ic]= line[ixl+ic];
  };
  printf("INFO BEAMMODE:%s=%d (set in shm)\n", value, bmN);
  if(strlen(value) <= maxbml) {
    strcpy(beammode, value); // not used yet anyhow
    /*t1= nxtoken(line, value, &ixl);   // message
    if(t1==tSTRING) {
      int rcdl;
      rcdl= daqlogbook_add_comment(0,beammode,value);
      printf("INFO DAQlogbook comment: %d %s %s rc:%d\n",
        bmN, beammode, value,rcdl);
    } else {
      strcpy(errmsg,"Bad message (\"string\" expected)");
    };*/
  } else {
    strncpy(beammode, value, maxbml); // not used yet anyhow
    beammode[maxbml]='\0';
    strcpy(errmsg,"beammode too long (longest one:INJECTION PHYSICS BEAM)");
  };
} else {
  strcpy(errmsg,"Bad beam mode number (int expected)");
};
if(errmsg[0]!='\0') {
  printf("ERROR DOsetbm:%s:%s\n",errmsg, line);
};
}
Ejemplo n.º 5
0
/*------------------------------------------------------------ gethexdec
 I: hdnum: 0xhexa or 1023   (hex. or dec. number as string)
 O: rc:0, *num is internal representation of the number
    rc:2  syntax error */
int gethexdec(char *hdnum, unsigned int *num) {
enum Ttokentype token;
int rc=0, ix=0;
char value[80];
token= nxtoken(hdnum, value, &ix);
if(token == tHEXNUM)  {
  *num= hex2int(&value[2]);
} else if(token==tINTNUM) {
  *num= str2int(value);
} else rc=2;
return(rc);
}
Ejemplo n.º 6
0
/*--------------------*/ void DOcom2daq(void *tag, void *msg, int *size)  {
// msg: runN "title" "comment" 
int ixl, runN; char errmsg[200]="";
char *line;
#define MAXDAQCOMMENT 500
char value[MAXDAQCOMMENT];
char title[MAXDAQCOMMENT];
enum Ttokentype t1;
line= (char *)msg;
printf("INFO DOcom2daq len:%d m:%s\n", *size, line); 
if(*size > MAXDAQCOMMENT) {
  printf("ERROR too long title+comment for DAQlogbook\n"); return;
};
ixl=0; t1= nxtoken(line, value, &ixl);   // runN
if(t1==tINTNUM) {
  runN= str2int(value);
  t1= nxtoken(line, value, &ixl);   // title
  if(t1==tSTRING) {
    strcpy(title, value);
    t1= nxtoken(line, value, &ixl);   // message
    if(t1==tSTRING) {
      int rcdl;
      rcdl= daqlogbook_add_comment(0,title,value);
      printf("INFO DAQlogbook comment: %d %s %s rc:%d\n",
        runN, title, value,rcdl);
    } else {
      strcpy(errmsg,"Bad message (\"string\" expected)");
    };
  } else {
    strcpy(errmsg,"Bad title (\"string\" expected)");
  };
} else {
  strcpy(errmsg,"Bad run number (int expected)");
};
if(errmsg[0]!='\0') {
  printf("ERROR DOcom2daq:%s:%s\n",errmsg, line);
};
}
Ejemplo n.º 7
0
/* Input: class runNumber clid1 classname1 clid2 classname2 ... \n
from 28.7.2010:
   Input: class runNumber 
          clid1 cg1 cgtime1 dsc1 classname1 
          clid2 cg2 cgtime2 dsc2 classname2 ... \n
Operation:
register clid:classname in DAQDB
rc: 0: ok
   !=0: ERROR message printed to stdout
1: runNumber not found
2: classname expected
3: classid 1..NCLASS expected
4: DAQDB update call error
5: bad cg (0..20) allowed (anyhow, ctp_proxy allows only 0..9)
6: bad dsc factor. Expected: dec. number (32 bits, i.e. unsigned int)
7: bad dsc factor: >0x1fffff but bit31 not set
8: premature EOCMD (unfinished line)
*/
int updateDAQDB(char *line) {
int ixl, ixiv, rcex=8;
unsigned int runN; 
int ixc;
char value[256];
enum Ttokentype t1,t2;
printf("INFO updateDAQDB... effiout:0x%x\n", effiout);
ixl=6; t1= nxtoken(line, value, &ixl);   // runNumber
if(t1==tINTNUM) {
  runN= str2int(value);
  ixiv= find_insver(runN);
  if(ixiv == -1) {
    printf("ERROR bad line (runN not found (pcfg req. missing?) ):%s",line);
    rcex=1; return(rcex);
  };
} else {
  printf("ERROR bad line (runN expected after class ):%s",line);
  rcex=1; return(rcex);
};
infolog_SetStream(insver[ixiv].parname, runN);
updateConfig(runN, insver[ixiv].parname, insver[ixiv].insname,
  insver[ixiv].insver);
del_insver(runN);
for(ixc=0; ixc<NCLASS; ixc++) {
  unsigned int classN, cg, cgtim; int rcdaq,daqlistpn;
  float cgtime;
  char dsctxt[24];   // (0.xxx% - 100%) or xxxus or xxx.xxxms
  char *dsctxtp;
  char *daqlist[MAXALIASES]; char **daqlistp;
  char msg[300];
  t1= nxtoken(line, value, &ixl);   // class number
  //printf("INFO ixc:%d token:%d tokenvalue:%s\n",ixc,t1,value);
  if(t1==tEOCMD) {rcex=0; break;};
  if(t1==tINTNUM) {
    classN= str2int(value);
    if( (classN>NCLASS) || (classN<1) ) {
      rcex=3; break;
    };
  } else {
    rcex=3; break;
  };
  t1= nxtoken(line, value, &ixl);   // class group
  if(t1==tEOCMD) break;   
  if(t1==tINTNUM) {
    cg= str2int(value);
    if( cg>NCLASS ) {
      rcex=5; break;
    };
      } else {
    rcex=5; break;
  };
  t1= nxtoken(line, value, &ixl);   // class time group
  if(t1==tEOCMD) break;   
  if(t1==tINTNUM) {
    cgtim= str2int(value);
  } else {
    rcex=3; break;
  };
  t1= nxtoken(line, value, &ixl);   // dsc
  if(t1==tEOCMD) break;   
  if(t1==tINTNUM) {
    unsigned int dsc;
    dsc= str2int(value);
    dsctxtp= dsctxt;
    if(dsc>0x1fffff) {   // class busy
      int dscus;
      if((dsc & 0x80000000)!=0x80000000) {
        printf("ERROR in downscaling factor:0x%x\n", dsc); 
        rcex=7; break;
      };
      dscus= 10*(dsc & 0x1ffffff);
      sprintf(dsctxt, "%dus", dscus);
    } else if(dsc==0) {  // not downscaled
      dsctxt[0]='\0'; dsctxtp= NULL;
    } else {             // random downscaling
      float dscrat;
      dscrat= 100- dsc*100./0x1fffff;
      sprintf(dsctxt, "%2.3f%%", dscrat);
    }
  } else {
    rcex=6; break;
  };
  t2= nxtoken1(line, value, &ixl);   // classname
  if(t2!=tSYMNAME) {rcex=2; break;};
  cgtime= cgtim;
  getClassAliases(value, daqlist); 
  daqlistpn=0;
  if(daqlist[0]==NULL) {
    daqlistp=NULL; 
  } else {
    char *dp;
    daqlistp=daqlist; dp= daqlist[0];
    while(dp!=NULL) {
      daqlistpn++; dp=daqlist[daqlistpn];
    };
  };
  if(ignoreDAQLOGBOOK) { rcdaq=0;
  } else {
    rcdaq= daqlogbook_update_triggerClassName(runN, 
      //classN-1, value, cg, cgtime, (const char **)daqlistp);
      classN-1, value, cg, cgtime, dsctxtp, (const char **)daqlistp);
  };
  sprintf(msg,
    "DAQlogbook_update_triggerClassName(%d,%d,%s,%d,%5.1f, %s, %d) rc:%d",
    runN, classN-1, value, cg, cgtime, dsctxt, daqlistpn, rcdaq);
  if(rcdaq!=0) {
    infolog_trg(LOG_ERROR, msg);
    printf("ERROR %s\n", msg);
    rcex=4; break;
  } else {
    printf("INFO %s\n", msg);
    // without the test below, server crashes (or \n received indicating STOP)
    // ??? Possible reason: cannot print 2 consequtive INFO lines?
    if(daqlistpn>0) printalist(daqlistp);
  };
  ctpc_addclass(classN, value, runN);
  fflush(stdout);
};
if(rcex!=0) {
  ctpc_delrun(runN);
};
updateCNAMES();
infolog_SetStream("",0);
return(rcex);
}
Ejemplo n.º 8
0
/*--------------------*/ void DOcmd(void *tag, void *msg, int *size)  {
/* msg: string finished by "\n\0" */
//printf("DOcmd: tag:%d size:%d msg:%s<-endofmsg\n", *tag, *size,msg);
char mymsg[400];
int stdoutyes=1;
strncpy(mymsg, (char *)msg, 400); 
mymsg[398]='\n'; mymsg[399]='\0';   // force \n (if not given)
if((strncmp(mymsg,"pcfg ",5)==0) || (strncmp(mymsg,"Ncfg ",5)==0) ||
    (strncmp(mymsg,"Acfg ",5)==0) ) {
/* pcfg RUNNUMBER partname    -try ACT download (ECS INIT)
   Ncfg RUNNUMBER partname    -NO ACT, change: Ncfg -> pcfg
   Acfg RUNNUMBER partname    - abort
   \n               -stop this server
   rcfgdel useDAQLOGBOOK
   rcfgdel ignoreDAQLOGBOOK
   rcfgdel ALL 0xc606       -ctpproxy restart
   rcfgdel PARTNAME RUNN    -process in .py, (ECS STOP)
   rcfgdel reload           -just reload parted
   csupdate
   aliasesupdate
   intupdate
   clockshift
   rcfg  -OBSOLETE!
   resetclock   -just write out
*/
  char c; unsigned int rundec=0;
  int rc, infoerr, ix=0, runnactive=0;
  char instname[100]="";
  char version[100]="";
  char pname[60]="";
  char runc[16]="";
  char emsg[500];
  //rc= getname_rn(mymsg, pname, rundec);   moved to DOrcfg()
  while(1) {
    int cix;
    c=(mymsg)[5+ix];
    if((c==' ') || (c=='\n') || (c=='\0')) {
      if(runnactive==0) {
        if(c==' ') {
          ix++; runnactive=1; cix=0;
          continue;
        } else { break; };
      } else {
        if(runc[0]!='\0') {
          rundec=atoi(runc); break;
        };
      };
    };
    if(runnactive==1) {
      runc[cix]=c; runc[cix+1]='\0'; cix++;
    } else {
      pname[ix]= c; pname[ix+1]='\0';
    };
    ix++;
    if(ix>=60) break;
  };
  infolog_SetStream(pname, rundec);
  if(mymsg[0]=='p') {
    char filter[20000]="";
    //actdb_open(); 
    rc=actdb_getPartition(pname,filter, instname, version);
    //actdb_close();
    if(rc==0) {
      sprintf(emsg,"INFO %s (run:%d inst:%s ver:%s) downloaded from ACT.", 
        pname, rundec, instname, version); 
      infoerr=LOG_INFO;
    } else if(rc==1) {
      sprintf(emsg,"ERROR %s (run:%d) not found in ACT, might be OK if shift leader disabled it in ACT (i.e. is in 'Local File' mode)", pname, rundec); 
      infoerr=LOG_ERROR;
    } else {
      sprintf(emsg,"actdb_getPartition(%s) run:%d rc:%d (-2: partition not available in ACT)", pname,rundec,rc); 
      infoerr=LOG_ERROR;
    };
  } else if(mymsg[0]=='A') {
    //printf("INFO Acfg %s %d\n", pname, rundec);
    del_insver(rundec);
  } else {   // Ncfg runnumber partname
    sprintf(emsg,"INFO %s (run:%d) not searched in ACT (ECS:ACT_CONFIG=NO)", 
      pname, rundec); 
    infoerr=LOG_INFO;
    mymsg[0]= 'p';
  };
  if(mymsg[0]=='p') {
    //prtLog(emsg);
    //myprtLog(emsg);
    infolog_trgboth(infoerr, emsg);
    rc= add_insver(rundec, pname, instname, version);
    if(rc==-1) {
      sprintf(emsg,"run:%d, instance/ver will not be stored in ACT", rundec);
      infolog_trg(LOG_FATAL, emsg);
      printf("ERROR %s", emsg);
    };
  };
  infolog_SetStream("",0);
/*---- moved to .rcfg time
  if(ignoreDAQLOGBOOK==1) {
    rcdaq=0;
  } else {
    rcdaq= daqlogbook_open(); //rcdaq=0;
    if(rcdaq!=0) {
      printf("ERROR update_cs: DAQlogbook_open failed rc:%d",rcdaq); rc=4;
      //prtError("DAQlogbook_open failed");
    }else{
      char itemname[200];
      rc= daqlogbook_update_cs(rundec, CSString);
      do_partitionCtpConfigItem(pname, itemname);
      rc_insert= daqlogbook_update_ACTConfig(rundec, itemname,instname,version);
      rcdaq= daqlogbook_close();
    };
    if((rc==0) && (rc_insert==0)) {
      infoerr=LOG_INFO;
    } else {
      infoerr=LOG_FATAL;
    };
    sprintf(emsg,"daglogbook_update_cs rc:%d _update_ACTConfig rc:%d", rc, rc_insert);
    infolog_trg(infoerr, emsg);
  };
-------- moved to .rcfg */
//                        1...,...10....,....20..3
} else if((strncmp(mymsg,"rcfgdel ignoreDAQLOGBOOK",23)==0)) {
  int rcdaq;
  ignoreDAQLOGBOOK=1;
  rcdaq= daqlogbook_close();
  if(rcdaq==-1) {
    printf("ERROR DAQlogbook_close failed\n");
  } else {
    printf("INFO DAQlogbook closed:rc:%d (ignoreDAQLOGBOOK from ctpproxy received)\n",rcdaq);
  };
  stdoutyes=0;
  //cshmSetGlobFlag(FLGignoreDAQLOGBOOK);
} else if((strncmp(mymsg,"rcfgdel useDAQLOGBOOK",20)==0)) {
  int rcdaq;
  rcdaq= daqlogbook_open(); //rcdaq=0;
  if(rcdaq!=0) {
    printf("ERROR DAQlogbook_open failed rc:%d",rcdaq);
    ignoreDAQLOGBOOK=1;
    cshmSetGlobFlag(FLGignoreDAQLOGBOOK);
  } else {
    ignoreDAQLOGBOOK=0;
    cshmClearGlobFlag(FLGignoreDAQLOGBOOK);
  };
  stdoutyes=0;
} else if((strncmp(mymsg,"rcfgdel ALL 0x...",11)==0)) {   //ctpproxy [re]start
  //int irc;
  printf("INFO rcfgdel ALL 0x... (redis, readTables...)\n");
  red_clear_detsinrun(0);
  reset_insver();
  readTables();
  ctpc_clear(); updateCNAMES();
  /*irc=*/ check_xcounters();
} else if((strncmp(mymsg,"rcfgdel reload",14)==0)) {   //reload parted
  // perhaps it is reasonable to clean (even if ctpproxy did not restart but is 
  // without active partitions)
  //reset_insver();
  //readTables();
  //ctpc_clear(); updateCNAMES();
  //printf("INFO rcfgdel reload\n");
  ;
} else if((strncmp(mymsg,"rcfgdel ",8)==0)) {   // rcfgdel partname runn
  enum Ttokentype t1; int ixl, runn; char pname[16]; char intval[16];;
  char emsg[200];
  emsg[0]='\0';
  ixl=8; t1= nxtoken(mymsg, pname, &ixl);   // runNumber
  if(t1==tSYMNAME) {
    t1= nxtoken(mymsg, intval, &ixl);   // runNumber
    if(t1==tINTNUM) {
      runn= str2int(intval);
      // from 26.2. maybe not needed here, but seems ok when INIT brings ctpproxy to LOAD_FAILURE
      del_insver(runn);  
    } else {
      sprintf(emsg,"pydimserver: bad run number in rcfgdel %s cmd", pname);
    };
  } else {
    sprintf(emsg,"pydimserver: bad part. name in %s cmd", mymsg);
  };
  if(emsg[0]=='\0') {
    red_clear_detsinrun(runn);
    ctpc_delrun(runn); updateCNAMES();
  } else {
    infolog_trg(LOG_ERROR, emsg); printf("ERROR %s\n",emsg);
  };
} else if((strncmp(mymsg,"csupdate",8)==0)) {
  int csclients; // char *cs;
  /*cs=*/ readCS();
  csclients= dis_update_service(CSid);
  printf("INFO CS update for %d clients\n", csclients);
  stdoutyes=0;
} else if((strncmp(mymsg,"aliasesupdate",13)==0)) {
  int rc;
  rc= readAliases(); 
  if(rc==-1) {
    char emsg[200];
    strcpy(emsg,"aliasesupdate: info from aliases.txt not updated correctly");
    infolog_trg(LOG_INFO, emsg); printf("ERROR %s\n",emsg);
  };
  stdoutyes=0;
} else if((strncmp(mymsg,"intupdate",9)==0)) {
  int rc1, rc2;
  rc1= getINT12fromcfg(INT1String, INT2String, MAXINT12LINE);
  printf("INFO rc:%d INT1:%s INT2:%s\n", rc1, INT1String, INT2String);
  rc1= dis_update_service(INT1id);
  rc2= dis_update_service(INT2id);
  printf("INFO INT1/INT2 update for %d/%d clients\n", rc1, rc2);
  stdoutyes=0;
} else if((strncmp(mymsg,"clockshift ",11)==0)) {
  char halfns[20]; int ix,rc;
  unsigned int hns,cordeval,last_applied;
  /* char c; halfns[0]='\0';
  for(ix=0; ix<40; ix++) {
    c= mymsg[11+ix]; 
    if((c=='\0') || (c=='\n')) {
      halfns[ix]= '\0'; break;
    };
    halfns[ix]= c;
  }; 
  halfns[20]= '\0';*/
  ix= sscanf(&mymsg[11], "%d %d %d\n", &hns, &cordeval, &last_applied);
  if( (ix<2) || (hns>63) || (cordeval>1023) ) {
    printf("ERROR set clockshift %d %d incorrect, not updated.\n",hns, cordeval);
  } else {
    //int csclients;
    sprintf(halfns, "%d %d %d", hns, cordeval, last_applied);
    rc= writedbfile("clockshift", halfns);   // 2ints: halfns cordereg
    //csclients= dis_update_service(CSid);  is not here
    printf("INFO set clockshift %s. rc(=chars):%d \n", halfns, rc);
  };
  stdoutyes=0;
} else if((strncmp(mymsg,"rcfg ",5)==0)) {   // moved to DOrcfg()
  printf("ERROR rcfg cmd ignored (processed by CTPRCFG cmd\n");
  stdoutyes=0;
} else if((strncmp(mymsg,"resetclock",9)==0)) {
  ;
};
if(strcmp(mymsg,"\n")==0) {
  //stopserving();
  myprtLog("Quitting server...");
  printf("stop\n"); fflush(stdout);
  //sleep(1);
  //exit(0);
};
if(stdoutyes==1) {   /*
  pcfg 
    -prepare .pcfg (parted.py)
    - scp .pcfg
  rcfg partName NNN clu1 clu2 ... clu6 cl1 ... clNCLASS NewLine
    -prepare .rcfg (parted.py)
    -
  smaqmv
  */
  printf("%s",mymsg); fflush(stdout);
};
}
Ejemplo n.º 9
0
int GrSetDriver(char *drvspec)
{
    static int firsttime = TRUE;
    GrVideoDriver *drv = NULL;
    char options[100];
    char *biggdims;

    if ((biggdims = getenv("MGRXBIGG")) != NULL) {
        sscanf(biggdims, "%d %d", &DRVINFO->biggw, &DRVINFO->biggh);
    }

    if(!drvspec) drvspec = getenv("MGRXDRV");
    options[0] = '\0';
    if(drvspec) {
        char t[100],name[100],*p = drvspec;
        name[0] = '\0';
        while(p = nxtoken(p,t),t[0] != '\0') {
            if(strlen(t) == 2) {
#                   define CH16(c1,c2)  (((c1) << 8) | (c2))
                void *oaddr = NULL;
                int  cf = FALSE;
                switch(CH16(tolower(t[0]),tolower(t[1]))) {
                case CH16('n','c'):
                case CH16('g','c'):
                    oaddr = &DRVINFO->defgc;
                    cf = TRUE;
                    break;
                case CH16('t','c'):
                    oaddr = &DRVINFO->deftc;
                    cf = TRUE;
                    break;
                case CH16('g','w'):
                    oaddr = &DRVINFO->defgw;
                    break;
                case CH16('t','w'):
                    oaddr = &DRVINFO->deftw;
                    break;
                case CH16('g','h'):
                    oaddr = &DRVINFO->defgh;
                    break;
                case CH16('t','h'):
                    oaddr = &DRVINFO->defth;
                    break;
                }
                if(oaddr) {
                    long optval;
                    p = nxtoken(p,t);
                    if(sscanf(t,"%ld",&optval) > 0) {
                        if(cf) {
                            switch(toupper(t[strlen(t) - 1])) {
                            case 'K':
                                optval <<= 10;
                                break;
                            case 'M':
                                optval <<= 20;
                                break;
                            }
                            *((long *)oaddr) = optval;
                            continue;
                        }
                        *((int *)oaddr) = (int)optval;
                    }
                    continue;
                }
            }
            strcpy(name,t);
        }
        for(p = name; (p = strchr(p,':')) != NULL; p++) {
            if(p[1] == ':') {
                strcpy(options,&p[2]);
                *p = '\0';
                break;
            }
        }
        if(name[0] != '\0') {
            int ii = 0,found = FALSE;
            while(!found && ((drv = _GrVideoDriverTable[ii++]) != NULL)) {
                char *n = name;
                for(p = drv->name; ; p++,n++) {
                    if(tolower(*p) != tolower(*n)) break;
                    if(*p == '\0') {
                        found = TRUE;
                        break;
                    }
                }
            }
            if(!found) return(FALSE);
        }
    }
    if(!drv) {
        GrVideoDriver *dp;
        int ii,maxmodes = 0;
        for(ii = 0; (dp = _GrVideoDriverTable[ii]) != NULL; ii++) {
            if(dp->detect && (*dp->detect)()) {
                int nm = 0;
                for( ; dp; dp = dp->inherit) nm += dp->nmodes;
                if(nm > maxmodes) {
                    drv = _GrVideoDriverTable[ii];
                    maxmodes = nm;
                }
            }
        }
        if(!drv) return(FALSE);
    }
    _GrCloseVideoDriver();
    if(firsttime) {
        atexit(_GrCloseVideoDriver);
        firsttime = FALSE;
    }
    if(!drv->init || drv->init(options)) {
        DRVINFO->vdriver = drv;
        return(TRUE);
    }
    return(FALSE);
}
Ejemplo n.º 10
0
/*--------------------*/ void DOcmd(void *tag, void *msgv, int *size)  {
/* msg: if string finished by "\n\0" remove \n */
char *mymsg= (char *)msgv; int msglen=100;
char msg[101];
enum Ttokentype token; int ix; char value[100]; char em1[200];

if(DBGCMDS) {
  char logmsg[200];
  sprintf(logmsg, "DOcmd1: tag:%d size:%d mymsg:%s<-endofmsg", *(int *)tag, *size,mymsg);
  //prtLog(logmsg);
};
if(*size <msglen) msglen=*size;
strncpy(msg, mymsg, msglen); msg[msglen]='\0';
/*if(msg[*size-2]=='\n') {
  msg[*size-2]='\0';
} else {
  msg[*size-1]='\0';
}; */
/*msg: 
u         -update from SHM (this cmd is issued by ctp_proxy at
           Start, Resume
          Following (a,d) cmnds used only from cmdline by admin when debugging
a 0 2 5   -add detectors for calibration (valid only for active run)
d 0 5     -delete detectors from calibration 
*/
ix=0; token= nxtoken(msg, value, &ix);
if(token==tSYMNAME) {
  if((strcmp(value,"u")==0) ) {   // update from global runs (in shm)
    int ads;
    ads= shmupdateDETs();
    if(ads>0){
      printf("Docmd: starting thread, # of dets:%d threadactive:%d\n", 
        ads, threadactive);
      fflush(stdout);
      if(threadactive==0) {
        startThread();
      } else { // 1: 2nd global run (ok) or what?
        // perhaps, here we should stop/start active thread.
        sprintf(em1,"u:ads:%d, threadactive, i.e. 2nd global?", ads); 
        printf("DOcmd warning: %s/n", em1); //goto ERR;
        ;
      };
    };
  } else if((strcmp(value,"a")==0) || (strcmp(value,"d")==0)) {
    int det,rc; char adddel;
    adddel=value[0];
    while(1) {
      token= nxtoken(msg, value, &ix);
      if(token == tINTNUM) {
        det= str2int(value);
        if(adddel=='a') {
          rc= addDET(det, 0);
        } else {
          rc= delDET(det);
        };
        if(rc!=0) { sprintf(em1,"add/del:%c rc:%d", adddel, rc); goto ERR; };
        if(threadactive==0) {
          startThread();
        } else {
          sprintf(em1,"a:det:%d but threadactive is 1", det); goto ERR;
        };
      } else if(token == tINTNUM) {
        break;
      } else {
        strcpy(em1,"int expected: 'a/d det1 det2 ...' "); goto ERR;
      };
    };
  } else if((strcmp(value,"p")==0)) {
    printDETS();
  } else {
    strcpy(em1,"a,d or p expected as first item in message"); goto ERR; 
  };
} else {
  strcpy(em1,"a,d or p expcted as first item in message"); goto ERR;
};
return;
ERR:
printf("DOcmd ERROR:%s msg:%s\n", em1, msg);
}