mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-23 06:50:02 +02:00
setup receiver first working draft
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@267 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
parent
aefdcaa82e
commit
2e5dc6515f
@ -5,7 +5,8 @@
|
|||||||
All set functions with argument -1 work as get, when possible
|
All set functions with argument -1 work as get, when possible
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
#ifndef SLS_DETECTOR_FUNCS_H
|
||||||
|
#define SLS_DETECTOR_FUNCS_H
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
|
||||||
@ -102,11 +103,15 @@ enum {
|
|||||||
|
|
||||||
F_READ_COUNTER_BLOCK, /**< reads the counter block memory for gotthard */
|
F_READ_COUNTER_BLOCK, /**< reads the counter block memory for gotthard */
|
||||||
|
|
||||||
F_RESET_COUNTER_BLOCK /**< resets the counter block memory for gotthard */
|
F_RESET_COUNTER_BLOCK, /**< resets the counter block memory for gotthard */
|
||||||
|
|
||||||
|
F_SETUP_RECEIVER, /**< sets up receiver with parameters */
|
||||||
|
|
||||||
|
F_START_RECEIVER/**< starts/stops the receiver and returns status */
|
||||||
|
|
||||||
/* Always append functions hereafter!!! */
|
/* Always append functions hereafter!!! */
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif SLS_DETECTOR_FUNCS_H
|
||||||
/** @endinternal */
|
/** @endinternal */
|
||||||
|
@ -3551,3 +3551,40 @@ int multiSlsDetector::readDataFile(string fname, int *data) {
|
|||||||
return iline;
|
return iline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
string multiSlsDetector::setupReceiver(string fileName) {
|
||||||
|
cout<<"File Name:"<<fileName<<endl;
|
||||||
|
string retval1 = "",retval;
|
||||||
|
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
|
||||||
|
if (detectors[idet]) {
|
||||||
|
retval=detectors[idet]->setupReceiver(fileName);
|
||||||
|
if(!retval.empty()){
|
||||||
|
retval1.append(retval);
|
||||||
|
retval1.append("+");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
slsDetectorDefs::runStatus multiSlsDetector::startReceiver(string status,int index) {
|
||||||
|
/**master receiver or writer?*/
|
||||||
|
runStatus s, s1;
|
||||||
|
|
||||||
|
if(detectors[0]) s1 = detectors[0]->startReceiver(status,index);
|
||||||
|
|
||||||
|
for (int idet=1; idet<thisMultiDetector->numberOfDetectors; idet++) {
|
||||||
|
if (detectors[idet]) {
|
||||||
|
s=detectors[idet]->startReceiver(status,index);
|
||||||
|
if(s==ERROR)
|
||||||
|
s1=ERROR;
|
||||||
|
if(s==IDLE && s1!=IDLE)
|
||||||
|
s1=ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return s1;
|
||||||
|
}
|
||||||
|
@ -1002,6 +1002,21 @@ class multiSlsDetector : public slsDetectorUtils {
|
|||||||
|
|
||||||
slsDetector *getSlsDetector(int pos) {if (pos>=0 && pos< MAXDET) return detectors[pos]; return NULL;};
|
slsDetector *getSlsDetector(int pos) {if (pos>=0 && pos< MAXDET) return detectors[pos]; return NULL;};
|
||||||
|
|
||||||
|
/** Sets up the receiver
|
||||||
|
@param fileName file name
|
||||||
|
\returns receiver ip or none
|
||||||
|
*/
|
||||||
|
string setupReceiver(string fileName="");
|
||||||
|
|
||||||
|
|
||||||
|
/** Starts/Stops the receiver
|
||||||
|
@param status status of receiver
|
||||||
|
@param index starting index of data file
|
||||||
|
\returns status
|
||||||
|
*/
|
||||||
|
runStatus startReceiver(string status="",int index=0);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
||||||
|
@ -5317,3 +5317,97 @@ slsDetectorDefs::synchronizationMode slsDetector::setSynchronization(synchroniza
|
|||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
string slsDetector::setupReceiver(string fileName) {
|
||||||
|
int fnum=F_SETUP_RECEIVER;
|
||||||
|
int ret = FAIL;
|
||||||
|
char mess[100];
|
||||||
|
char arg[MAX_STR_LENGTH];
|
||||||
|
strcpy(arg,fileName.c_str());
|
||||||
|
|
||||||
|
MySocketTCP *receiverSocket = new MySocketTCP(thisDetector->clientIP,thisDetector->dataPort);
|
||||||
|
|
||||||
|
if (receiverSocket->getErrorStatus()){
|
||||||
|
#ifdef VERBOSE
|
||||||
|
std::cout<< "Could not connect Control socket " << thisDetector->clientIP << " " << thisDetector->dataPort << std::endl;
|
||||||
|
#endif
|
||||||
|
delete receiverSocket;
|
||||||
|
receiverSocket=NULL;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if(receiverSocket){
|
||||||
|
if (receiverSocket->Connect()>=0){
|
||||||
|
if (receiverSocket->SendDataOnly(&fnum,sizeof(fnum))>=0)
|
||||||
|
if (receiverSocket->SendDataOnly(arg,MAX_STR_LENGTH)>=0){
|
||||||
|
receiverSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||||
|
if(ret==FAIL){
|
||||||
|
receiverSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||||
|
std::cout<< "Receiver returned error: " << mess << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
receiverSocket->Disconnect();
|
||||||
|
}
|
||||||
|
else strcpy(thisDetector->clientIP,"none");
|
||||||
|
delete receiverSocket;//should I include also for good connection? cuz setTCPSocket() still uses it?
|
||||||
|
receiverSocket=NULL;//should I include also for good connection? cuz setTCPSocket() still uses it?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**if force update, updateReceiver?*/
|
||||||
|
if(ret==OK) return fileName;
|
||||||
|
return string("");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
slsDetectorDefs::runStatus slsDetector::startReceiver(string status,int index){
|
||||||
|
int fnum=F_START_RECEIVER;
|
||||||
|
int ret = FAIL;
|
||||||
|
char mess[100];
|
||||||
|
runStatus retval=ERROR;
|
||||||
|
int arg[2];
|
||||||
|
arg[1] = index;
|
||||||
|
|
||||||
|
//start=1,stop=0,get=-1
|
||||||
|
arg[0] = -1;
|
||||||
|
if(status=="start") arg[0] = 1;
|
||||||
|
else if(status=="stop") arg[0] = 0;
|
||||||
|
|
||||||
|
|
||||||
|
MySocketTCP *receiverSocket = new MySocketTCP(thisDetector->clientIP,thisDetector->dataPort);
|
||||||
|
|
||||||
|
if (receiverSocket->getErrorStatus()){
|
||||||
|
#ifdef VERBOSE
|
||||||
|
std::cout<< "Could not connect Control socket " << thisDetector->clientIP << " " << thisDetector->dataPort << std::endl;
|
||||||
|
#endif
|
||||||
|
delete receiverSocket;
|
||||||
|
receiverSocket=NULL;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if(receiverSocket){
|
||||||
|
if (receiverSocket->Connect()>=0){
|
||||||
|
if (receiverSocket->SendDataOnly(&fnum,sizeof(fnum))>=0)
|
||||||
|
if (receiverSocket->SendDataOnly(arg,sizeof(arg))>=0){
|
||||||
|
receiverSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||||
|
if(ret!=FAIL){
|
||||||
|
receiverSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
receiverSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||||
|
std::cout<< "Receiver returned error: " << mess << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
receiverSocket->Disconnect();
|
||||||
|
}
|
||||||
|
else strcpy(thisDetector->clientIP,"none");
|
||||||
|
delete receiverSocket;//should I include also for good connection? cuz setTCPSocket() still uses it?
|
||||||
|
receiverSocket=NULL;//should I include also for good connection? cuz setTCPSocket() still uses it?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**if force update, updateReceiver?*/
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
@ -1354,6 +1354,21 @@ typedef struct sharedSlsDetector {
|
|||||||
/** Frees the shared memory - should not be used*/
|
/** Frees the shared memory - should not be used*/
|
||||||
int freeSharedMemory();
|
int freeSharedMemory();
|
||||||
|
|
||||||
|
/**
|
||||||
|
Sets up the receiver
|
||||||
|
@param fileName file name
|
||||||
|
\returns receiver ip or none
|
||||||
|
*/
|
||||||
|
string setupReceiver(string fileName="");
|
||||||
|
|
||||||
|
|
||||||
|
/** Starts/Stops the receiver
|
||||||
|
@param status status of receiver
|
||||||
|
@param index starting index of data file
|
||||||
|
\returns status
|
||||||
|
*/
|
||||||
|
runStatus startReceiver(string status="",int index=0);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
||||||
|
@ -637,6 +637,13 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
|
|||||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdConfiguration;
|
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdConfiguration;
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
|
|
||||||
|
/* receiver functions */
|
||||||
|
descrToFuncMap[i].m_pFuncName="receiver";
|
||||||
|
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdReceiver;
|
||||||
|
i++;
|
||||||
|
|
||||||
|
|
||||||
numberOfCommands=i;
|
numberOfCommands=i;
|
||||||
|
|
||||||
// #ifdef VERBOSE
|
// #ifdef VERBOSE
|
||||||
@ -2075,6 +2082,8 @@ string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int actio
|
|||||||
|
|
||||||
networkParameter t;
|
networkParameter t;
|
||||||
|
|
||||||
|
string fileName = myDet->getFilePath()+string("/")+myDet->getFileName()+string("_");
|
||||||
|
|
||||||
if (action==HELP_ACTION)
|
if (action==HELP_ACTION)
|
||||||
return helpNetworkParameter(narg,args,action);
|
return helpNetworkParameter(narg,args,action);
|
||||||
|
|
||||||
@ -2086,8 +2095,13 @@ string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int actio
|
|||||||
t=SERVER_MAC;
|
t=SERVER_MAC;
|
||||||
} else return ("unknown network parameter")+cmd;
|
} else return ("unknown network parameter")+cmd;
|
||||||
|
|
||||||
if (action==PUT_ACTION)
|
if (action==PUT_ACTION){
|
||||||
myDet->setNetworkParameter(t, args[1]);
|
if(!strcmp(myDet->setNetworkParameter(t, args[1]),args[1])){
|
||||||
|
if(t==CLIENT_IP)
|
||||||
|
if(myDet->setupReceiver(fileName).empty())
|
||||||
|
return string("could not set up receiver file name.");
|
||||||
|
}
|
||||||
|
}
|
||||||
return myDet->getNetworkParameter(t);
|
return myDet->getNetworkParameter(t);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -3378,3 +3392,39 @@ string slsDetectorCommand::helpConfiguration(int narg, char *args[], int action)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action) {
|
||||||
|
runStatus s;
|
||||||
|
if (action==HELP_ACTION)
|
||||||
|
return helpReceiver(narg, args, action);
|
||||||
|
|
||||||
|
if (action==PUT_ACTION) {
|
||||||
|
if((strcasecmp(args[1],"start"))&&(strcasecmp(args[1],"stop")))
|
||||||
|
return helpReceiver(narg, args, action);
|
||||||
|
s = myDet->startReceiver(string(args[1]),myDet->getFileIndex());
|
||||||
|
//increment index by 1 if stopped successfully
|
||||||
|
if((!strcasecmp(args[1],"stop"))&&(s!=ERROR))
|
||||||
|
myDet->setFileIndex(myDet->getFileIndex()+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return myDet->runStatusType(myDet->startReceiver());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
string slsDetectorCommand::helpReceiver(int narg, char *args[], int action) {
|
||||||
|
|
||||||
|
ostringstream os;
|
||||||
|
if (action==PUT_ACTION || action==HELP_ACTION)
|
||||||
|
os << "receiver [status] \t starts/stops the receiver to listen to detector packets. - can be start or stop" << std::endl;
|
||||||
|
if (action==GET_ACTION || action==HELP_ACTION)
|
||||||
|
os << "receiver \t returns the status of receiver - can be running or idle" << std::endl;
|
||||||
|
|
||||||
|
return os.str();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -82,7 +82,7 @@ class slsDetectorCommand : public virtual slsDetectorDefs {
|
|||||||
static string helpCounter(int narg, char *args[], int action);
|
static string helpCounter(int narg, char *args[], int action);
|
||||||
static string helpADC(int narg, char *args[], int action);
|
static string helpADC(int narg, char *args[], int action);
|
||||||
static string helpEnablefwrite(int narg, char *args[], int action);
|
static string helpEnablefwrite(int narg, char *args[], int action);
|
||||||
|
static string helpReceiver(int narg, char *args[], int action);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ class slsDetectorCommand : public virtual slsDetectorDefs {
|
|||||||
string cmdCounter(int narg, char *args[], int action);
|
string cmdCounter(int narg, char *args[], int action);
|
||||||
string cmdADC(int narg, char *args[], int action);
|
string cmdADC(int narg, char *args[], int action);
|
||||||
string cmdEnablefwrite(int narg, char *args[], int action);
|
string cmdEnablefwrite(int narg, char *args[], int action);
|
||||||
|
string cmdReceiver(int narg, char *args[], int action);
|
||||||
|
|
||||||
|
|
||||||
int numberOfCommands;
|
int numberOfCommands;
|
||||||
|
@ -570,6 +570,21 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
|
|||||||
static int dummyAcquisitionFinished(double prog,int status,void* p){cout <<"Acquisition finished callback! " << prog << " " << status << endl; return 0;}
|
static int dummyAcquisitionFinished(double prog,int status,void* p){cout <<"Acquisition finished callback! " << prog << " " << status << endl; return 0;}
|
||||||
static int dummyMeasurementFinished(int im,int findex,void* p){cout <<"Measurement finished callback! " << im << " " << findex << endl; return 0;}
|
static int dummyMeasurementFinished(int im,int findex,void* p){cout <<"Measurement finished callback! " << im << " " << findex << endl; return 0;}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Sets up the receiver
|
||||||
|
@param fileName file name
|
||||||
|
\returns receiver ip or none
|
||||||
|
*/
|
||||||
|
virtual string setupReceiver(string fileName="")=0;
|
||||||
|
|
||||||
|
/** Starts/Stops the receiver
|
||||||
|
@param status status of receiver
|
||||||
|
@param index starting index of data file
|
||||||
|
\returns status
|
||||||
|
*/
|
||||||
|
virtual runStatus startReceiver(string status="",int index=0)=0;
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
static const int64_t thisSoftwareVersion=0x20120124;
|
static const int64_t thisSoftwareVersion=0x20120124;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user