mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-11 04:17:15 +02:00
some more changes, yet to do receiver
This commit is contained in:
@ -962,6 +962,18 @@ int multiSlsDetector::exitServer(int detPos) {
|
||||
}
|
||||
|
||||
|
||||
int multiSlsDetector::execCommand(std::string cmd, int detPos) {
|
||||
// single
|
||||
if (detPos >= 0) {
|
||||
return detectors[detPos]->execCommand(cmd);
|
||||
}
|
||||
|
||||
// multi
|
||||
auto r = parallelCall(&slsDetector::execCommand, cmd);
|
||||
return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL;
|
||||
}
|
||||
|
||||
|
||||
int multiSlsDetector::readConfigurationFile(std::string const fname) {
|
||||
freeSharedMemory();
|
||||
setupMultiDetector();
|
||||
|
@ -453,6 +453,14 @@ public:
|
||||
*/
|
||||
int exitServer(int detPos = -1);
|
||||
|
||||
/**
|
||||
* Execute a command on the detector server
|
||||
* @param cmd command
|
||||
* @param detPos -1 for all detectors in list or specific detector position
|
||||
* @returns OK or FAIL
|
||||
*/
|
||||
int execCommand(std::string cmd, int detPos);
|
||||
|
||||
/**
|
||||
* Load configuration from a configuration File
|
||||
* @param fname configuration file name
|
||||
|
@ -916,73 +916,58 @@ slsDetectorDefs::detectorType slsDetector::getDetectorType(const char *name, int
|
||||
|
||||
int slsDetector::setDetectorType(detectorType const type) {
|
||||
|
||||
int arg, retval=FAIL;
|
||||
int ret=FAIL;
|
||||
int fnum=F_GET_DETECTOR_TYPE,fnum2=F_GET_RECEIVER_TYPE;
|
||||
arg=int(type);
|
||||
detectorType retType=type;
|
||||
detectorType retval = type;
|
||||
char mess[MAX_STR_LENGTH];
|
||||
memset(mess, 0, MAX_STR_LENGTH);
|
||||
|
||||
|
||||
if (type != GET_DETECTOR_TYPE) {
|
||||
#ifdef VERBOSE
|
||||
std::cout<< std::endl;
|
||||
std::cout<< "Setting detector type to " << arg << std::endl;
|
||||
std::cout<< std::endl;
|
||||
std::cout<< "Setting detector type to " << arg << std::endl;
|
||||
#endif
|
||||
if (thisDetector->onlineFlag==ONLINE_FLAG) {
|
||||
if (connectControl() == OK){
|
||||
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
||||
if (retval!=FAIL)
|
||||
controlSocket->ReceiveDataOnly(&retType,sizeof(retType));
|
||||
else {
|
||||
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
||||
if (thisDetector->onlineFlag==ONLINE_FLAG) {
|
||||
if (connectControl() == OK){
|
||||
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
||||
thisDetector->myDetectorType = (detectorType)retval;
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Detector type retrieved " << retval << std::endl;
|
||||
#endif
|
||||
disconnectControl();
|
||||
if (ret==FORCE_UPDATE)
|
||||
updateDetector();
|
||||
}
|
||||
disconnectControl();
|
||||
if (retval==FORCE_UPDATE)
|
||||
updateDetector();
|
||||
} else {
|
||||
std::cout<< "Get detector type failed " << std::endl;
|
||||
thisDetector->myDetectorType = GENERIC;
|
||||
}
|
||||
} else {
|
||||
if (type==GET_DETECTOR_TYPE)
|
||||
retType=thisDetector->myDetectorType;//FIXME: throw exception?
|
||||
else {
|
||||
retType=type;
|
||||
thisDetector->myDetectorType=type;
|
||||
}
|
||||
retval=OK;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Detector type set to " << retType << std::endl;
|
||||
#endif
|
||||
if (retval==FAIL) {
|
||||
std::cout<< "Set detector type failed " << std::endl;
|
||||
retType=GENERIC;
|
||||
}
|
||||
else
|
||||
thisDetector->myDetectorType=retType;
|
||||
|
||||
|
||||
//receiver
|
||||
if((retType != GENERIC) && (thisDetector->receiverOnlineFlag==ONLINE_FLAG)
|
||||
&& (arg != GENERIC)) {
|
||||
retval = FAIL;
|
||||
if((thisDetector->myDetectorType != GENERIC) &&
|
||||
(thisDetector->receiverOnlineFlag==ONLINE_FLAG)) {
|
||||
ret = FAIL;
|
||||
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Sending detector type to Receiver " <<
|
||||
(int)thisDetector->myDetectorType << std::endl;
|
||||
#endif
|
||||
if (connectData() == OK){
|
||||
retval=thisReceiver->sendInt(fnum2,arg,(int)thisDetector->myDetectorType);
|
||||
ret=thisReceiver->sendInt(fnum2,retval,(int)thisDetector->myDetectorType);
|
||||
disconnectData();
|
||||
}
|
||||
if(retval==FAIL){
|
||||
if(ret==FAIL){
|
||||
std::cout << "ERROR: Could not send detector type to receiver" << std::endl;
|
||||
setErrorMask((getErrorMask())|(RECEIVER_DET_HOSTTYPE_NOT_SET));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return retType;
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
@ -1543,39 +1528,31 @@ std::string slsDetector::getLastClientIP() {
|
||||
if (connectControl() == OK){
|
||||
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret==FAIL) {
|
||||
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
||||
} else {
|
||||
controlSocket->ReceiveDataOnly(clientName,sizeof(clientName));
|
||||
}
|
||||
controlSocket->ReceiveDataOnly(clientName,sizeof(clientName));
|
||||
disconnectControl();
|
||||
if (ret==FORCE_UPDATE)
|
||||
updateDetector();
|
||||
}
|
||||
}
|
||||
|
||||
return std::string(clientName);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int slsDetector::exitServer() {
|
||||
|
||||
int retval;
|
||||
int ret = FAIL;
|
||||
int fnum=F_EXIT_SERVER;
|
||||
|
||||
if (thisDetector->onlineFlag==ONLINE_FLAG) {
|
||||
if (controlSocket) {
|
||||
controlSocket->Connect();
|
||||
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
disconnectControl();
|
||||
}
|
||||
}
|
||||
if (retval!=OK) {
|
||||
if (ret==OK) {
|
||||
std::cout<< std::endl;
|
||||
std::cout<< "Shutting down the server" << std::endl;
|
||||
std::cout<< "Shutting down the Detector server" << std::endl;
|
||||
std::cout<< std::endl;
|
||||
}
|
||||
return retval;
|
||||
@ -1583,13 +1560,11 @@ int slsDetector::exitServer() {
|
||||
}
|
||||
|
||||
|
||||
int slsDetector::execCommand(std::string cmd, std::string answer) {
|
||||
int slsDetector::execCommand(std::string cmd) {
|
||||
|
||||
char arg[MAX_STR_LENGTH], retval[MAX_STR_LENGTH];
|
||||
char arg[MAX_STR_LENGTH]="", retval[MAX_STR_LENGTH]="";
|
||||
int fnum=F_EXEC_COMMAND;
|
||||
|
||||
int ret=FAIL;
|
||||
|
||||
strcpy(arg,cmd.c_str());
|
||||
|
||||
#ifdef VERBOSE
|
||||
@ -1598,19 +1573,13 @@ int slsDetector::execCommand(std::string cmd, std::string answer) {
|
||||
#endif
|
||||
if (thisDetector->onlineFlag==ONLINE_FLAG) {
|
||||
if (connectControl() == OK){
|
||||
if (controlSocket->SendDataOnly(&fnum,sizeof(fnum))>=0) {
|
||||
if (controlSocket->SendDataOnly(arg,MAX_STR_LENGTH)>=0) {
|
||||
if (controlSocket->ReceiveDataOnly(retval,MAX_STR_LENGTH)>=0) {
|
||||
ret=OK;
|
||||
answer=retval;
|
||||
}
|
||||
}
|
||||
}
|
||||
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
controlSocket->SendDataOnly(arg,MAX_STR_LENGTH);
|
||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
controlSocket->ReceiveDataOnly(retval,MAX_STR_LENGTH);
|
||||
std::cout << "Detector returned:" << retval << std::endl;
|
||||
disconnectControl();
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Detector answer is " << answer << std::endl;
|
||||
#endif
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -1706,11 +1675,7 @@ int slsDetector::updateDetector() {
|
||||
if (connectControl() == OK){
|
||||
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret==FAIL) {
|
||||
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
||||
} else
|
||||
updateDetectorNoWait();
|
||||
updateDetectorNoWait();
|
||||
disconnectControl();
|
||||
}
|
||||
}
|
||||
@ -1905,8 +1870,7 @@ slsDetectorDefs::detectorSettings slsDetector::sendSettingsOnly(detectorSettings
|
||||
char mess[MAX_STR_LENGTH];
|
||||
memset(mess, 0, MAX_STR_LENGTH);
|
||||
int retval = -1;
|
||||
int arg;
|
||||
arg = isettings;
|
||||
int arg = isettings;
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Setting settings to " << arg << std::endl;
|
||||
#endif
|
||||
@ -1939,7 +1903,7 @@ slsDetectorDefs::detectorSettings slsDetector::sendSettingsOnly(detectorSettings
|
||||
int slsDetector::getThresholdEnergy() {
|
||||
|
||||
int fnum= F_GET_THRESHOLD_ENERGY;
|
||||
int retval;
|
||||
int retval = -1;
|
||||
int ret=FAIL;
|
||||
char mess[MAX_STR_LENGTH]="";
|
||||
#ifdef VERBOSE
|
||||
|
@ -105,6 +105,13 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdExitServer;
|
||||
++i;
|
||||
|
||||
/*! \page test
|
||||
- <b>execcommand</b> Executes a command on the detector server. Don't use it!!!!
|
||||
*/
|
||||
descrToFuncMap[i].m_pFuncName="execcommand";//OK
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdExitServer;
|
||||
++i;
|
||||
|
||||
/*! \page test
|
||||
- <b>flippeddatay [i]</b> enables/disables data being flipped across y axis. 1 enables, 0 disables. Not implemented.
|
||||
*/
|
||||
@ -1730,6 +1737,7 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
|
||||
|
||||
|
||||
|
||||
|
||||
/* receiver functions */
|
||||
|
||||
/*! \page receiver Receiver commands
|
||||
@ -2412,18 +2420,25 @@ string slsDetectorCommand::cmdExitServer(int narg, char *args[], int action, int
|
||||
if (action==PUT_ACTION) {
|
||||
if (cmd=="exitserver"){
|
||||
myDet->setOnline(ONLINE_FLAG, detPos);
|
||||
if (myDet->exitServer(detPos)!=OK)
|
||||
if (myDet->exitServer(detPos)==OK)
|
||||
return string("Server shut down.");
|
||||
else
|
||||
return string("Error closing server\n");
|
||||
}
|
||||
else if (cmd=="exitreceiver"){
|
||||
myDet->setReceiverOnline(ONLINE_FLAG, detPos);
|
||||
if(myDet->exitReceiver(detPos)!=OK)
|
||||
if(myDet->exitReceiver(detPos)==OK)
|
||||
return string("Receiver shut down\n");
|
||||
else
|
||||
return string("Error closing receiver\n");
|
||||
}
|
||||
else if (cmd=="execcommand"){
|
||||
myDet->setOnline(ONLINE_FLAG, detPos);
|
||||
if(myDet->execCommand(std::string(argv[1]), detPos)==OK)
|
||||
return string("Command executed successfully\n");
|
||||
else
|
||||
return string("Command failed\n");
|
||||
}
|
||||
else return("cannot decode command\n");
|
||||
} else
|
||||
return ("cannot get");
|
||||
@ -2434,6 +2449,7 @@ string slsDetectorCommand::helpExitServer(int action){
|
||||
ostringstream os;
|
||||
os << string("exitserver \t shuts down all the detector servers. Don't use it!!!!\n");
|
||||
os << string("exitreceiver \t shuts down all the receiver servers.\n");
|
||||
os << string("execcommand \t executes command in detector server. Don't use it if you do not know what you are doing.\n");
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
@ -162,14 +162,13 @@ int function_table() {
|
||||
int M_nofunc(int file_des){
|
||||
|
||||
int ret=FAIL;
|
||||
|
||||
sprintf(mess,"Unrecognized Function. Please do not proceed.\n");
|
||||
cprintf(BG_RED,"Error: %s",mess);
|
||||
|
||||
int n = 1;
|
||||
while (n > 0)
|
||||
n = receiveData(file_des,mess,MAX_STR_LENGTH,OTHER);
|
||||
|
||||
sprintf(mess,"Unrecognized Function. Please do not proceed.\n");
|
||||
cprintf(BG_RED,"Error: %s",mess);
|
||||
|
||||
sendDataOnly(file_des,&ret,sizeof(ret));
|
||||
sendDataOnly(file_des,mess,sizeof(mess));
|
||||
return GOODBYE;
|
||||
@ -232,32 +231,24 @@ int exec_command(int file_des) {
|
||||
|
||||
int get_detector_type(int file_des) {
|
||||
int n=0;
|
||||
enum detectorType ret;
|
||||
int retval=OK;
|
||||
enum detectorType retval;
|
||||
int ret = OK;
|
||||
|
||||
sprintf(mess,"Can't return detector type\n");
|
||||
|
||||
|
||||
/* receive arguments */
|
||||
/* execute action */
|
||||
ret=myDetectorType;
|
||||
retval=myDetectorType;
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("Returning detector type %d\n",ret);
|
||||
#endif
|
||||
|
||||
/* send answer */
|
||||
/* send OK/failed */
|
||||
if (differentClients==1)
|
||||
retval=FORCE_UPDATE;
|
||||
ret=FORCE_UPDATE;
|
||||
|
||||
/* send OK/failed */
|
||||
n += sendDataOnly(file_des,&ret,sizeof(ret));
|
||||
/* send return argument */
|
||||
n += sendDataOnly(file_des,&retval,sizeof(retval));
|
||||
if (retval!=FAIL) {
|
||||
/* send return argument */
|
||||
n += sendDataOnly(file_des,&ret,sizeof(ret));
|
||||
} else {
|
||||
n += sendDataOnly(file_des,mess,sizeof(mess));
|
||||
}
|
||||
|
||||
/*return ok/fail*/
|
||||
return retval;
|
||||
|
||||
@ -1646,10 +1637,10 @@ int set_speed(int file_des) {
|
||||
|
||||
|
||||
int exit_server(int file_des) {
|
||||
int retval=FAIL;
|
||||
sendDataOnly(file_des,&retval,sizeof(retval));
|
||||
printf("closing server.");
|
||||
sprintf(mess,"closing server");
|
||||
int ret=OK;
|
||||
sprintf(mess,"closing server\n");
|
||||
cprintf(BG_RED,"Command: %s",mess);
|
||||
sendDataOnly(file_des,&ret,sizeof(ret));
|
||||
sendDataOnly(file_des,mess,sizeof(mess));
|
||||
return GOODBYE;
|
||||
}
|
||||
|
@ -1681,6 +1681,9 @@ int get_threshold_energy(int file_des) {
|
||||
sprintf(mess,"get threshold energy failed\n");
|
||||
|
||||
#ifndef EIGERD
|
||||
//to receive any arguments
|
||||
while (n > 0)
|
||||
n = receiveData(file_des,mess,MAX_STR_LENGTH,OTHER);
|
||||
ret = FAIL;
|
||||
sprintf(mess,"Function (Get Threshold Energy) is not implemented for this detector\n");
|
||||
cprintf(RED, "Warning: %s", mess);
|
||||
@ -2512,9 +2515,9 @@ int set_speed(int file_des) {
|
||||
|
||||
|
||||
int exit_server(int file_des) {
|
||||
int ret=FAIL;
|
||||
int ret=OK;
|
||||
sprintf(mess,"Closing Server\n");
|
||||
cprintf(BG_RED,"Error: %s",mess);
|
||||
cprintf(BG_RED,"Command: %s",mess);
|
||||
// send ok / fail
|
||||
sendData(file_des,&ret,sizeof(ret),INT32);
|
||||
// send return argument
|
||||
|
@ -382,14 +382,6 @@ int sendModuleGeneral(int file_des, sls_detector_module *myMod, int sendAll) {
|
||||
ts+=sendData(file_des,&(myMod->ndac),sizeof(myMod->ndac),INT32);
|
||||
ts+=sendData(file_des,&(myMod->nadc),sizeof(myMod->nadc),INT32);
|
||||
ts+=sendData(file_des,&(myMod->reg),sizeof(myMod->reg),INT32);
|
||||
|
||||
#ifdef MYTHEND
|
||||
ts+=sendData(file_des,myMod->dacs,sizeof(myMod->ndac),OTHER);
|
||||
ts+=sendData(file_des,myMod->adcs,sizeof(myMod->nadc),OTHER);
|
||||
ts+=sendData(file_des,myMod->chipregs,sizeof(myMod->nchip),OTHER);
|
||||
ts+=sendData(file_des,myMod->chanregs,sizeof(myMod->nchan),OTHER);
|
||||
}
|
||||
#endif
|
||||
ts+=sendData(file_des,&(myMod->gain), sizeof(myMod->gain),OTHER);
|
||||
ts+=sendData(file_des,&(myMod->offset), sizeof(myMod->offset),OTHER);
|
||||
|
||||
@ -441,22 +433,12 @@ int receiveModuleGeneral(int file_des, sls_detector_module* myMod, int receiveA
|
||||
int nChans, nchanold=myMod->nchan, nchandiff;
|
||||
int nDacs, ndold=myMod->ndac, ndacdiff;
|
||||
int nAdcs, naold=myMod->nadc, nadcdiff;
|
||||
#ifdef VERBOSE
|
||||
int id=0;
|
||||
#endif
|
||||
// ts+= receiveDataOnly(file_des,myMod,sizeof(sls_detector_module));
|
||||
ts+=receiveData(file_des,&(myMod->serialnumber),sizeof(myMod->serialnumber),INT32);
|
||||
ts+=receiveData(file_des,&(myMod->nchan),sizeof(myMod->nchan),INT32);
|
||||
ts+=receiveData(file_des,&(myMod->nchip),sizeof(myMod->nchip),INT32);
|
||||
ts+=receiveData(file_des,&(myMod->ndac),sizeof(myMod->ndac),INT32);
|
||||
ts+=receiveData(file_des,&(myMod->nadc),sizeof(myMod->nadc),INT32);
|
||||
ts+=receiveData(file_des,&(myMod->reg),sizeof(myMod->reg),INT32);
|
||||
#ifdef MYTHEND
|
||||
ts+=receiveData(file_des,myMod->dacs,sizeof(myMod->ndac),INT32);
|
||||
ts+=receiveData(file_des,myMod->adcs,sizeof(myMod->nadc),INT32);
|
||||
ts+=receiveData(file_des,myMod->chipregs,sizeof(myMod->nchip),INT32);
|
||||
ts+=receiveData(file_des,myMod->chanregs,sizeof(myMod->nchan),INT32);
|
||||
#endif
|
||||
ts+=receiveData(file_des,&(myMod->gain), sizeof(myMod->gain),OTHER);
|
||||
ts+=receiveData(file_des,&(myMod->offset), sizeof(myMod->offset),OTHER);
|
||||
|
||||
|
Reference in New Issue
Block a user