mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-12 04:47:14 +02:00
configuing master from command lineg
This commit is contained in:
@ -29,6 +29,7 @@ extern int ignoreConfigFileFlag;
|
||||
|
||||
// Variables that will be exported
|
||||
int phaseShift = DEFAULT_PHASE_SHIFT;
|
||||
int masterCommandLine = -1;
|
||||
|
||||
// Global variable from communication_funcs.c
|
||||
extern int isControlServer;
|
||||
@ -360,16 +361,28 @@ void initControlServer() {
|
||||
}
|
||||
|
||||
void initStopServer() {
|
||||
if (mapCSP0() == FAIL) {
|
||||
LOG(logERROR,
|
||||
("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (!updateFlag && initError == OK) {
|
||||
usleep(CTRL_SRVR_INIT_TIME_US);
|
||||
LOG(logINFOBLUE, ("Configuring Stop server\n"));
|
||||
if (mapCSP0() == FAIL) {
|
||||
initError = FAIL;
|
||||
strcpy(initErrorMessage,
|
||||
"Stop Server: Map Fail. Dangerous to continue. Goodbye!\n");
|
||||
LOG(logERROR, (initErrorMessage));
|
||||
initCheckDone = 1;
|
||||
return;
|
||||
}
|
||||
#ifdef VIRTUAL
|
||||
sharedMemory_setStop(0);
|
||||
sharedMemory_setStop(0);
|
||||
#endif
|
||||
// to get master from file
|
||||
readConfigFile();
|
||||
// to get master from file
|
||||
if (readConfigFile() == FAIL ||
|
||||
checkCommandLineConfiguration() == FAIL) {
|
||||
initCheckDone = 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
initCheckDone = 1;
|
||||
}
|
||||
|
||||
/* set up detector */
|
||||
@ -422,6 +435,13 @@ void setupDetector() {
|
||||
setROI(rois); // set adcsyncreg, daqreg, chipofinterestreg, cleanfifos,
|
||||
setGbitReadout();
|
||||
|
||||
// no config file or not first time server
|
||||
if (readConfigFile() == FAIL)
|
||||
return;
|
||||
|
||||
if (checkCommandLineConfiguration() == FAIL)
|
||||
return;
|
||||
|
||||
// master, slave (25um)
|
||||
setMasterSlaveConfiguration();
|
||||
|
||||
@ -626,6 +646,10 @@ void setGbitReadout() {
|
||||
|
||||
int readConfigFile() {
|
||||
|
||||
if (initError == FAIL) {
|
||||
return initError;
|
||||
}
|
||||
|
||||
if (ignoreConfigFileFlag) {
|
||||
return OK;
|
||||
}
|
||||
@ -653,7 +677,6 @@ int readConfigFile() {
|
||||
memset(key, 0, keySize);
|
||||
char value[keySize];
|
||||
memset(value, 0, keySize);
|
||||
int scan = OK;
|
||||
|
||||
// keep reading a line
|
||||
while (fgets(line, lineSize, fd)) {
|
||||
@ -673,19 +696,22 @@ int readConfigFile() {
|
||||
master = 0;
|
||||
LOG(logINFOBLUE, ("\tSlave or No Master\n"));
|
||||
} else {
|
||||
LOG(logERROR,
|
||||
("\tCould not scan masterflags %s value from config file\n",
|
||||
value));
|
||||
scan = FAIL;
|
||||
break;
|
||||
initError = FAIL;
|
||||
sprintf(
|
||||
initErrorMessage,
|
||||
"Could not scan masterflags %s value from config file\n",
|
||||
value);
|
||||
LOG(logERROR, (initErrorMessage))
|
||||
fclose(fd);
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
// not first server since detector power on
|
||||
if (!detectorFirstServer) {
|
||||
LOG(logINFOBLUE, ("\tServer has been started up before. "
|
||||
"Ignoring rest of config file\n"));
|
||||
LOG(logWARNING, ("\tServer has been started up before. "
|
||||
"Ignoring rest of config file\n"));
|
||||
fclose(fd);
|
||||
return FAIL;
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
|
||||
@ -694,11 +720,14 @@ int readConfigFile() {
|
||||
// convert value to int
|
||||
int ival = 0;
|
||||
if (sscanf(value, "%d", &ival) <= 0) {
|
||||
LOG(logERROR, ("\tCould not scan parameter %s value %s from "
|
||||
"config file\n",
|
||||
key, value));
|
||||
scan = FAIL;
|
||||
break;
|
||||
initError = FAIL;
|
||||
sprintf(initErrorMessage,
|
||||
"Could not scan parameter %s value %s from "
|
||||
"config file\n",
|
||||
key, value);
|
||||
LOG(logERROR, (initErrorMessage))
|
||||
fclose(fd);
|
||||
return FAIL;
|
||||
}
|
||||
// set value
|
||||
if (!strcasecmp(key, "masterdefaultdelay"))
|
||||
@ -716,16 +745,16 @@ int readConfigFile() {
|
||||
else if (!strcasecmp(key, "startacqdelay"))
|
||||
startacqdelay = ival;
|
||||
else {
|
||||
LOG(logERROR,
|
||||
("\tCould not scan parameter %s from config file\n", key));
|
||||
scan = FAIL;
|
||||
break;
|
||||
initError = FAIL;
|
||||
sprintf(initErrorMessage,
|
||||
"Could not scan parameter %s from config file\n", key);
|
||||
LOG(logERROR, (initErrorMessage))
|
||||
fclose(fd);
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(fd);
|
||||
if (scan == FAIL)
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
LOG(logINFOBLUE,
|
||||
("\tmasterdefaultdelay:%d\n"
|
||||
@ -740,13 +769,24 @@ int readConfigFile() {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int checkCommandLineConfiguration() {
|
||||
if (masterCommandLine != -1) {
|
||||
#ifdef VIRTUAL
|
||||
master = masterCommandLine;
|
||||
#else
|
||||
initError = FAIL;
|
||||
strcpy(initErrorMessage,
|
||||
"Cannot set Master from command line for this detector. "
|
||||
"Should have been caught before!\n");
|
||||
return FAIL;
|
||||
#endif
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
void setMasterSlaveConfiguration() {
|
||||
LOG(logINFO, ("Reading Master Slave Configuration\n"));
|
||||
|
||||
// no config file or not first time server
|
||||
if (readConfigFile() == FAIL)
|
||||
return;
|
||||
|
||||
// master configuration
|
||||
if (master) {
|
||||
// master default delay set, so reset delay
|
||||
|
Reference in New Issue
Block a user