mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-21 19:30:03 +02:00
deleted a few unnecessary c files
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@409 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
parent
499be37d0c
commit
3d6530f043
@ -1,423 +0,0 @@
|
||||
#include "angularConversionStatic.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <math.h>
|
||||
#include "angleConversionConstant.h"
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
#include "angleFunction.h"
|
||||
using namespace std;
|
||||
|
||||
angularConversionStatic::angularConversionStatic()
|
||||
{
|
||||
//angleFunctionPointer=0;
|
||||
registerAngleFunctionCallback(&defaultAngleFunction);
|
||||
|
||||
}
|
||||
|
||||
angularConversionStatic::~angularConversionStatic(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
double* angularConversionStatic::convertAngles(double pos, int nch, int *chansPerMod, angleConversionConstant **angOff, int *mF, double fo, double go, int angdir) {
|
||||
int imod=0;
|
||||
double *ang=new double[nch];
|
||||
double enc=pos;
|
||||
angleConversionConstant *p=NULL;
|
||||
|
||||
int ch0=0;
|
||||
int chlast=chansPerMod[0]-1;
|
||||
int nchmod=chansPerMod[0];
|
||||
p=angOff[imod];
|
||||
if (mF[imod]==0)
|
||||
enc=0;
|
||||
else
|
||||
enc=pos;
|
||||
|
||||
for (int ip=0; ip<nch; ip++) {
|
||||
#ifdef VERBOSE
|
||||
// cout << "ip " << ip << " ch0 " << ch0 << " chlast " << chlast << " imod " << imod << endl;
|
||||
#endif
|
||||
if (ip>chlast) {
|
||||
imod++;
|
||||
p=angOff[imod];
|
||||
if (mF[imod]==0)
|
||||
enc=0;
|
||||
else
|
||||
enc=pos;
|
||||
|
||||
ch0=chlast+1;
|
||||
nchmod=chansPerMod[imod];
|
||||
if (nchmod>0)
|
||||
chlast=ch0+nchmod-1;
|
||||
}
|
||||
|
||||
if (p)
|
||||
ang[ip]=angle(ip-ch0, \
|
||||
enc, \
|
||||
fo+go, \
|
||||
p->r_conversion, \
|
||||
p->center, \
|
||||
p->offset, \
|
||||
p->tilt, \
|
||||
angdir );
|
||||
}
|
||||
return ang;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
double angularConversionStatic::convertAngle(double pos, int ich, angleConversionConstant *p, int mF, double fo, double go, int angdir) {
|
||||
|
||||
|
||||
double enc=0, trans=0;
|
||||
double ang;
|
||||
|
||||
switch (mF) {
|
||||
case 0:
|
||||
enc=0;
|
||||
trans=0;
|
||||
break;
|
||||
case 1:
|
||||
enc=pos;
|
||||
trans=0;
|
||||
break;
|
||||
case -1:
|
||||
enc=-pos;
|
||||
trans=0;
|
||||
break;
|
||||
case 2:
|
||||
enc=0;
|
||||
trans=pos;
|
||||
break;
|
||||
case -2:
|
||||
enc=0;
|
||||
trans=-pos;
|
||||
break;
|
||||
default:
|
||||
enc=0;
|
||||
trans=0;
|
||||
}
|
||||
|
||||
if (p)
|
||||
ang=angle(ich, \
|
||||
enc, \
|
||||
fo+go, \
|
||||
p->r_conversion, \
|
||||
p->center, \
|
||||
p->offset, \
|
||||
trans, \
|
||||
angdir );
|
||||
|
||||
return ang;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
double angularConversionStatic::convertAngle(double pos, int ich, int *chansPerMod, angleConversionConstant **angOff, int *mF, double fo, double go, int angdir) {
|
||||
|
||||
int imod=0;
|
||||
double ang;
|
||||
double enc=0, trans=0;
|
||||
angleConversionConstant *p=NULL;
|
||||
|
||||
int ch0=0;
|
||||
int chlast=chansPerMod[0]-1;
|
||||
int nchmod=chansPerMod[0];
|
||||
|
||||
|
||||
|
||||
while (ich>chlast) {
|
||||
imod++;
|
||||
ch0=chlast+1;
|
||||
nchmod=chansPerMod[imod];
|
||||
chlast=ch0+nchmod-1;
|
||||
}
|
||||
|
||||
p=angOff[imod];
|
||||
|
||||
|
||||
ang=convertAngle(pos, ich-ch0, p, mF[imod], fo, go, angdir);
|
||||
|
||||
return ang;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//static!
|
||||
int angularConversionStatic::readAngularConversion(string fname, int nmod, angleConversionConstant *angOff) {
|
||||
|
||||
ifstream infile;
|
||||
string ss;
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Opening file "<< fname << std::endl;
|
||||
#endif
|
||||
infile.open(fname.c_str(), ios_base::in);
|
||||
if (infile.is_open()) {
|
||||
readAngularConversion(infile, nmod, angOff);
|
||||
infile.close();
|
||||
} else {
|
||||
std::cout<< "Could not open calibration file "<< fname << std::endl;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//static
|
||||
int angularConversionStatic::readAngularConversion( ifstream& infile, int nmod, angleConversionConstant *angOff) {
|
||||
string str;
|
||||
int mod;
|
||||
double center, ecenter, pitch, epitch;
|
||||
double r_conv, er_conv;
|
||||
double off, eoff;
|
||||
string ss;
|
||||
int interrupt=0;
|
||||
int nm=0;
|
||||
int newangconv=0;
|
||||
//" module %i center %E +- %E conversion %E +- %E offset %f +- %f \n"
|
||||
while (infile.good() and interrupt==0) {
|
||||
getline(infile,str);
|
||||
#ifdef VERBOSE
|
||||
cout << "** mod " << nm << " " ;
|
||||
std::cout<< str << std::endl;
|
||||
#endif
|
||||
istringstream ssstr(str);
|
||||
ssstr >> ss >> mod;
|
||||
ssstr >> ss >> center;
|
||||
if (ss==string("center"))
|
||||
newangconv=1;
|
||||
ssstr >> ss >> ecenter;
|
||||
if (newangconv) {
|
||||
ssstr >> ss >> pitch;
|
||||
ssstr >> ss >> epitch;
|
||||
}
|
||||
ssstr >> ss >> r_conv;
|
||||
ssstr >> ss >> er_conv;
|
||||
ssstr >> ss >> off;
|
||||
ssstr >> ss >> eoff;
|
||||
if (nm<nmod && nm>=0 ) {
|
||||
if (newangconv==0) {
|
||||
angOff[nm].center=center;
|
||||
angOff[nm].r_conversion=r_conv;
|
||||
angOff[nm].offset=off;
|
||||
angOff[nm].ecenter=ecenter;
|
||||
angOff[nm].er_conversion=er_conv;
|
||||
angOff[nm].eoffset=eoff;
|
||||
} else {
|
||||
|
||||
angOff[nm].tilt=pitch;
|
||||
angOff[nm].etilt=epitch;
|
||||
|
||||
}
|
||||
} else
|
||||
break;
|
||||
//cout << nm<<" " << angOff[nm].offset << endl;
|
||||
nm++;
|
||||
if (nm>=nmod)
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
return nm;
|
||||
}
|
||||
|
||||
//static
|
||||
int angularConversionStatic:: writeAngularConversion(string fname, int nmod, angleConversionConstant *angOff) {
|
||||
|
||||
ofstream outfile;
|
||||
outfile.open (fname.c_str(),ios_base::out);
|
||||
if (outfile.is_open())
|
||||
{
|
||||
writeAngularConversion(outfile, nmod, angOff);
|
||||
outfile.close();
|
||||
} else {
|
||||
std::cout<< "Could not open file " << fname << "for writing"<< std::endl;
|
||||
return -1;
|
||||
}
|
||||
//" module %i center %E +- %E conversion %E +- %E offset %f +- %f \n"
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//static
|
||||
int angularConversionStatic:: writeAngularConversion(ofstream& outfile, int nmod, angleConversionConstant *angOff) {
|
||||
|
||||
for (int imod=0; imod<nmod; imod++) {
|
||||
outfile << " module " << imod << " center "<< angOff[imod].center<<" +- "<< angOff[imod].ecenter<<" conversion "<< angOff[imod].r_conversion << " +- "<< angOff[imod].er_conversion << " offset "<< angOff[imod].offset << " +- "<< angOff[imod].eoffset << std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//static
|
||||
int angularConversionStatic::resetMerging(double *mp, double *mv, double *me, int *mm, int nb) {
|
||||
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "creating merging arrays "<< nb << endl;
|
||||
#endif
|
||||
|
||||
|
||||
for (int ibin=0; ibin<nb; ibin++) {
|
||||
mp[ibin]=0;
|
||||
mv[ibin]=0;
|
||||
me[ibin]=0;
|
||||
mm[ibin]=0;
|
||||
}
|
||||
return slsDetectorDefs::OK;
|
||||
}
|
||||
|
||||
|
||||
//static
|
||||
int angularConversionStatic::finalizeMerging(double *mp, double *mv, double *me, int *mm,int nb) {
|
||||
int np=0;
|
||||
for (int ibin=0; ibin<nb; ibin++) {
|
||||
if (mm[ibin]>0) {
|
||||
|
||||
// #ifdef VERBOSE
|
||||
// cout << "finalize " << ibin << " "<< mm[ibin] << " " << mp[ibin]<< mv[ibin] << me[ibin] << endl;
|
||||
// #endif
|
||||
mp[np]=mp[ibin]/mm[ibin];
|
||||
mv[np]=mv[ibin]/mm[ibin];
|
||||
me[np]=me[ibin]/mm[ibin];
|
||||
me[np]=sqrt(me[ibin]);
|
||||
mm[np]=mm[ibin];
|
||||
np++;
|
||||
}
|
||||
}
|
||||
return np;
|
||||
}
|
||||
|
||||
//static
|
||||
int angularConversionStatic::addToMerging(double *p1, double *v1, double *e1, double *mp, double *mv,double *me, int *mm, int nchans, double binsize,int nbins, int *badChanMask ) {
|
||||
|
||||
|
||||
double binmi=-180.;
|
||||
int ibin=0;
|
||||
|
||||
if (p1==NULL)
|
||||
return 0;
|
||||
if (v1==NULL)
|
||||
return slsDetectorDefs::FAIL;
|
||||
|
||||
if (mp==NULL) //can be changed if we want to use a fixed bin algorithm!
|
||||
return slsDetectorDefs::FAIL;
|
||||
|
||||
if (mv==NULL)
|
||||
return slsDetectorDefs::FAIL;
|
||||
if (me==NULL)
|
||||
return slsDetectorDefs::FAIL;
|
||||
if (mm==NULL)
|
||||
return slsDetectorDefs::FAIL;
|
||||
if (nchans==0)
|
||||
return slsDetectorDefs::FAIL;
|
||||
|
||||
if (binsize<=0)
|
||||
return slsDetectorDefs::FAIL;
|
||||
|
||||
if (nbins<=0)
|
||||
return slsDetectorDefs::FAIL;
|
||||
|
||||
for (int ip=0; ip<nchans; ip++) {
|
||||
if (badChanMask) {
|
||||
if (badChanMask[ip]) {
|
||||
#ifdef VERBOSE
|
||||
cout << "channel " << ip << " is bad " << endl;
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
}
|
||||
ibin=(int)((p1[ip]-binmi)/binsize);
|
||||
|
||||
|
||||
if (ibin<nbins && ibin>=0) {
|
||||
mp[ibin]+=p1[ip];
|
||||
mv[ibin]+=v1[ip];
|
||||
if (e1)
|
||||
me[ibin]+=(e1[ip]*e1[ip]);
|
||||
else
|
||||
me[ibin]+=v1[ip];
|
||||
mm[ibin]++;
|
||||
|
||||
// #ifdef VERBOSE
|
||||
// cout << "add " << ibin << " "<< mm[ibin] << " " << mp[ibin]<< mv[ibin] << me[ibin] << endl;
|
||||
// #endif
|
||||
} else
|
||||
return slsDetectorDefs::FAIL;
|
||||
}
|
||||
|
||||
|
||||
return slsDetectorDefs::OK;
|
||||
|
||||
}
|
||||
|
||||
int angularConversionStatic::addPointToMerging(double p1, double v1, double e1, double *mp, double *mv,double *me, int *mm, double binsize,int nbins) {
|
||||
|
||||
|
||||
double binmi=-180.;
|
||||
int ibin=0;
|
||||
|
||||
|
||||
if (mp==NULL) //can be changed if we want to use a fixed bin algorithm!
|
||||
return slsDetectorDefs::FAIL;
|
||||
|
||||
if (mv==NULL)
|
||||
return slsDetectorDefs::FAIL;
|
||||
if (me==NULL)
|
||||
return slsDetectorDefs::FAIL;
|
||||
if (mm==NULL)
|
||||
return slsDetectorDefs::FAIL;
|
||||
|
||||
if (binsize<=0)
|
||||
return slsDetectorDefs::FAIL;
|
||||
|
||||
if (nbins<=0)
|
||||
return slsDetectorDefs::FAIL;
|
||||
|
||||
|
||||
ibin=(int)((p1-binmi)/binsize);
|
||||
|
||||
|
||||
if (ibin<nbins && ibin>=0) {
|
||||
mp[ibin]+=p1;
|
||||
mv[ibin]+=v1;
|
||||
if (e1)
|
||||
me[ibin]+=(e1*e1);
|
||||
else
|
||||
me[ibin]+=v1;
|
||||
mm[ibin]++;
|
||||
|
||||
// #ifdef VERBOSE
|
||||
// cout << "add " << ibin << " "<< mm[ibin] << " " << mp[ibin]<< mv[ibin] << me[ibin] << endl;
|
||||
// #endif
|
||||
} else
|
||||
return slsDetectorDefs::FAIL;
|
||||
|
||||
|
||||
return slsDetectorDefs::OK;
|
||||
|
||||
}
|
@ -1,181 +0,0 @@
|
||||
|
||||
#ifndef ANGULARCONVERSIONSTATIC_H
|
||||
#define ANGULARCONVERSIONSTATIC_H
|
||||
|
||||
#ifdef __CINT
|
||||
#define MYROOT
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
//#include "angleConversionConstant.h"
|
||||
|
||||
|
||||
//double angle(int ichan, double encoder, double totalOffset, double conv_r, double center, double offset, double tilt, int direction)
|
||||
|
||||
class angleConversionConstant;
|
||||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
@short Angular conversion constants needed for a detector module
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@short methods to set/unset the angular conversion and merge the data
|
||||
class containing the methods to set/unset the angular conversion and merge the data
|
||||
|
||||
|
||||
The angular conversion itself is defined by the angle() function defined in usersFunctions.cpp
|
||||
|
||||
*/
|
||||
class angularConversionStatic
|
||||
// : public virtual slsDetectorDefs
|
||||
{
|
||||
|
||||
public:
|
||||
/** default constructor */
|
||||
angularConversionStatic();
|
||||
/** virtual destructor */
|
||||
virtual ~angularConversionStatic();
|
||||
|
||||
|
||||
|
||||
//virtual int readAngularConversion(string fname)=0;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
reads an angular conversion file
|
||||
\param fname file to be read
|
||||
\param nmod number of modules (maximum) to be read
|
||||
\param angOff pointer to array of angleConversionConstants
|
||||
\returns OK or FAIL
|
||||
*/
|
||||
static int readAngularConversion(string fname, int nmod, angleConversionConstant *angOff);
|
||||
|
||||
/**
|
||||
reads an angular conversion file
|
||||
\param ifstream input file stream to be read
|
||||
\param nmod number of modules (maximum) to be read
|
||||
\param angOff pointer to array of angleConversionConstants
|
||||
\returns OK or FAIL
|
||||
|
||||
*/
|
||||
static int readAngularConversion(ifstream& ifs, int nmod, angleConversionConstant *angOff);
|
||||
/**
|
||||
writes an angular conversion file
|
||||
\param fname file to be written
|
||||
\param nmod number of modules to be written
|
||||
\param angOff pointer to array of angleConversionConstants
|
||||
\returns OK or FAIL
|
||||
*/
|
||||
static int writeAngularConversion(string fname, int nmod, angleConversionConstant *angOff);
|
||||
|
||||
/**
|
||||
writes an angular conversion file
|
||||
\param ofstream output file stream
|
||||
\param nmod number of modules to be written
|
||||
\param angOff pointer to array of angleConversionConstants
|
||||
\returns OK or FAIL
|
||||
*/
|
||||
static int writeAngularConversion(ofstream& ofs, int nmod, angleConversionConstant *angOff);
|
||||
|
||||
/**
|
||||
sets the arrays of the merged data to 0. NB The array should be created with size nbins >= 360./getBinSize();
|
||||
\param mp already merged postions
|
||||
\param mv already merged data
|
||||
\param me already merged errors (squared sum)
|
||||
\param mm multiplicity of merged arrays
|
||||
\param nbins number of bins
|
||||
\returns OK or FAIL
|
||||
*/
|
||||
static int resetMerging(double *mp, double *mv,double *me, int *mm, int nbins);
|
||||
|
||||
/**
|
||||
merge dataset
|
||||
\param p1 angular positions of dataset
|
||||
\param v1 data
|
||||
\param e1 errors
|
||||
\param mp already merged postions
|
||||
\param mv already merged data
|
||||
\param me already merged errors (squared sum)
|
||||
\param mm multiplicity of merged arrays
|
||||
\param nchans number of channels
|
||||
\param binsize size of angular bin
|
||||
\param nb number of angular bins
|
||||
\param badChanMask badchannelmask (if NULL does not correct for bad channels)
|
||||
\returns OK or FAIL
|
||||
*/
|
||||
|
||||
static int addToMerging(double *p1, double *v1, double *e1, double *mp, double *mv,double *me, int *mm, int nchans, double binsize,int nb, int *badChanMask=NULL);
|
||||
|
||||
|
||||
/**
|
||||
merge dataset
|
||||
\param p1 angular positions of dataset
|
||||
\param v1 data
|
||||
\param e1 errors
|
||||
\param mp already merged postions
|
||||
\param mv already merged data
|
||||
\param me already merged errors (squared sum)
|
||||
\param mm multiplicity of merged arrays
|
||||
\param nchans number of channels
|
||||
\param binsize size of angular bin
|
||||
\param nb number of angular bins
|
||||
\param badChanMask badchannelmask (if NULL does not correct for bad channels)
|
||||
\returns OK or FAIL
|
||||
*/
|
||||
|
||||
static int addPointToMerging(double p1, double v1, double e1, double *mp, double *mv,double *me, int *mm, double binsize, int nb);
|
||||
|
||||
|
||||
/**
|
||||
calculates the "final" positions, data value and errors for the merged data
|
||||
\param mp already merged postions
|
||||
\param mv already merged data
|
||||
\param me already merged errors (squared sum)
|
||||
\param mm multiplicity of merged arrays
|
||||
\param nb number of bins
|
||||
\returns FAIL or the number of non empty bins (i.e. points belonging to the pattern)
|
||||
*/
|
||||
|
||||
static int finalizeMerging(double *mp, double *mv,double *me, int *mm, int nb);
|
||||
|
||||
/**
|
||||
converts channel number to angle
|
||||
\param pos encoder position
|
||||
\returns array of angles corresponding to the channels
|
||||
*/
|
||||
|
||||
double* convertAngles(double pos, int nch, int *chansPerMod, angleConversionConstant **angOff, int *mF, double fo, double go, int angdir);
|
||||
|
||||
double convertAngle(double pos, int ich, int *chansPerMod, angleConversionConstant **angOff, int *mF, double fo, double go, int angdir);
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
|
||||
|
||||
int registerAngleFunctionCallback(double (*fun)(double, double, double, double, double, double, double, int)) {angle = fun; return 0;};
|
||||
|
||||
|
||||
double (*angle)(double, double, double, double, double, double, double, int);
|
||||
|
||||
|
||||
// private:
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
@ -1 +0,0 @@
|
||||
../commonFiles/communication_funcs.c
|
@ -1 +0,0 @@
|
||||
../commonFiles/communication_funcs.h
|
@ -1,73 +0,0 @@
|
||||
/* A simple server in the internet domain using TCP
|
||||
The port number is passed as an argument */
|
||||
#include "communication_funcs.h"
|
||||
#include "slsReceiver_funcs.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
extern int sockfd;
|
||||
|
||||
|
||||
void error(char *msg)
|
||||
{
|
||||
perror(msg);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int portno = DEFAULT_PORTNO+2;
|
||||
int retval = OK;
|
||||
int sd, fd;
|
||||
|
||||
|
||||
//init_receiver(argv[1]); //defined in slsReceiver_funcs
|
||||
|
||||
|
||||
sd=bindSocket(portno); //defined in communication_funcs
|
||||
|
||||
sockfd=sd;
|
||||
|
||||
|
||||
if (getServerError(sd)) { //defined in communication_funcs
|
||||
printf("server error!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* assign function table */
|
||||
function_table(); //defined in slsReceiver_funcs
|
||||
#ifdef VERBOSE
|
||||
printf("function table assigned \n");
|
||||
#endif
|
||||
|
||||
printf("Ready...\n");
|
||||
|
||||
/* waits for connection */
|
||||
while(retval!=GOODBYE) {
|
||||
#ifdef VERBOSE
|
||||
printf("\n");
|
||||
#endif
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("Waiting for client call\n");
|
||||
#endif
|
||||
fd=acceptConnection(sockfd); //defined in communication_funcs
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("Conenction accepted\n");
|
||||
#endif
|
||||
if (fd>0) {
|
||||
retval=decode_function(fd); //defined in slsReceiverServer_funcs
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("function executed\n");
|
||||
#endif
|
||||
closeConnection(fd); //defined in communication_funcs
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("connection closed\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
exitServer(sockfd); //defined in communication_funcs
|
||||
printf("Goodbye!\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,398 +0,0 @@
|
||||
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||
#include "slsReceiverFunctionList.h"
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>/* exit() */
|
||||
#include <string.h> /* memset(), memcpy() */
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h> /* fork(), write(), close() */
|
||||
#include <asm/page.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <sys/socket.h>/* socket(), bind(), listen(), accept() */
|
||||
#include <signal.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/utsname.h> /* uname() */
|
||||
|
||||
#include <pthread.h> /* thread */
|
||||
|
||||
//constants
|
||||
#define MAX_BUFLEN 1048576
|
||||
#define TCP_PORT_NUMBER 2233
|
||||
|
||||
#define SRVNAME "localhost"
|
||||
#define SERVER_PORT 50001
|
||||
#define BUFFER_LENGTH 1286
|
||||
#define FALSE 0
|
||||
|
||||
int gui_acquisition_thread_running = 0;
|
||||
int err = 0;
|
||||
pthread_t gui_acquisition_thread;
|
||||
|
||||
|
||||
char buffer[BUFFER_LENGTH*2];
|
||||
char sendbuffer[BUFFER_LENGTH*2];
|
||||
|
||||
char onebuffer[BUFFER_LENGTH];
|
||||
int sd = -1;
|
||||
int sockfd;
|
||||
|
||||
FILE *sfilefd;
|
||||
|
||||
|
||||
char savefilename[128];
|
||||
char filePath[MAX_STR_LENGTH]="";
|
||||
char fileName[MAX_STR_LENGTH]="run";
|
||||
int fileIndex=0;
|
||||
int frameIndexNeeded=1;
|
||||
|
||||
//for each scan
|
||||
int frameIndex=0;
|
||||
int startFrameIndex=-1;
|
||||
int framesCaught=0;
|
||||
|
||||
//for each acquisition
|
||||
int acquisitionIndex=0;
|
||||
int startAcquisitionIndex=-1;//to remember progress for scans
|
||||
int totalFramesCaught=0;
|
||||
|
||||
int framesInFile=0;//to know when to start next file
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
enum runStatus status = IDLE;
|
||||
|
||||
|
||||
|
||||
void closeFile(){
|
||||
if(gui_acquisition_thread_running){
|
||||
printf("Closing file\n");
|
||||
fclose(sfilefd);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
enum runStatus getReceiverStatus(){
|
||||
#ifdef VERBOSE
|
||||
printf("Status:%d\n",status);
|
||||
#endif
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
char* getFileName(){
|
||||
return fileName;
|
||||
}
|
||||
|
||||
char* setFileName(char fName[]){
|
||||
if(strlen(fName)){
|
||||
strcpy(fileName,fName);
|
||||
}
|
||||
return getFileName();
|
||||
}
|
||||
|
||||
|
||||
|
||||
char* getFilePath(){
|
||||
return filePath;
|
||||
}
|
||||
|
||||
char* setFilePath(char fPath[]){
|
||||
if(strlen(fPath)){
|
||||
/*check if filepath exists and chop off last '/'*/
|
||||
struct stat st;
|
||||
if(stat(fPath,&st) == 0)
|
||||
strcpy(filePath,fPath);
|
||||
}
|
||||
return getFilePath();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int getFileIndex(){
|
||||
return fileIndex;
|
||||
}
|
||||
|
||||
int setFileIndex(int index){
|
||||
if(index>=0){
|
||||
fileIndex=index;
|
||||
}
|
||||
return getFileIndex();
|
||||
}
|
||||
|
||||
|
||||
|
||||
int getStartFrameIndex(){
|
||||
return startFrameIndex;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int getFrameIndex(){
|
||||
if(startFrameIndex==-1)
|
||||
frameIndex=0;
|
||||
else
|
||||
frameIndex=((int)(*((int*)buffer)) - startFrameIndex)/2;
|
||||
return frameIndex;
|
||||
}
|
||||
|
||||
|
||||
int getAcquisitionIndex(){
|
||||
if(startAcquisitionIndex==-1)
|
||||
acquisitionIndex=0;
|
||||
else
|
||||
acquisitionIndex=((int)(*((int*)buffer)) - startAcquisitionIndex)/2;
|
||||
return acquisitionIndex;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int getFramesCaught(){
|
||||
return framesCaught;
|
||||
}
|
||||
|
||||
|
||||
int getTotalFramesCaught(){
|
||||
return totalFramesCaught;
|
||||
}
|
||||
|
||||
|
||||
int resetTotalFramesCaught(int index){
|
||||
startAcquisitionIndex=-1;
|
||||
totalFramesCaught=0;
|
||||
frameIndexNeeded=index;
|
||||
return frameIndexNeeded;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void* startListening(void *arg){
|
||||
#ifdef VERYVERBOSE
|
||||
printf("In startListening()\n");
|
||||
#endif
|
||||
/***********************************************************************/
|
||||
/* Variable and structure definitions. */
|
||||
/***********************************************************************/
|
||||
sd = -1;
|
||||
int rc1, rc2, rc;
|
||||
int currframenum, prevframenum;
|
||||
struct sockaddr_in serveraddr;
|
||||
struct sockaddr_in clientaddr;
|
||||
|
||||
socklen_t clientaddrlen = sizeof(clientaddr);
|
||||
framesInFile=0;
|
||||
frameIndex=0;
|
||||
startFrameIndex=-1;
|
||||
framesCaught=0;
|
||||
|
||||
|
||||
/***********************************************************************/
|
||||
/* Catch signal SIGINT to close files properly */
|
||||
/***********************************************************************/
|
||||
signal(SIGINT, closeFile);
|
||||
|
||||
|
||||
//create file name
|
||||
if(!frameIndexNeeded)
|
||||
sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex);
|
||||
else
|
||||
sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,framesCaught,fileIndex);
|
||||
|
||||
/***********************************************************************/
|
||||
/* A do/while(FALSE) loop is used to make error cleanup easier. The */
|
||||
/* close() of each of the socket descriptors is only done once at the */
|
||||
/* very end of the program. */
|
||||
/***********************************************************************/
|
||||
do {
|
||||
/********************************************************************/
|
||||
/* The socket() function returns a socket descriptor, which represents */
|
||||
/* an endpoint. The statement also identifies that the INET */
|
||||
/* (Internet Protocol) address family with the UDP transport */
|
||||
/* (SOCK_DGRAM) will be used for this socket. */
|
||||
/********************************************************************/
|
||||
sd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (sd < 0) {
|
||||
perror("socket() failed");
|
||||
break;
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
/* After the socket descriptor is created, a bind() function gets a */
|
||||
/* unique name for the socket. In this example, the user sets the */
|
||||
/* s_addr to zero, which means that the UDP port of 3555 will be */
|
||||
/* bound to all IP addresses on the system. */
|
||||
/********************************************************************/
|
||||
memset(&serveraddr, 0, sizeof(serveraddr));
|
||||
serveraddr.sin_family = AF_INET;
|
||||
serveraddr.sin_port = htons(SERVER_PORT);
|
||||
//serveraddr.sin_addr.s_addr = inet_addr(server_ip);
|
||||
serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
|
||||
rc = bind(sd, (struct sockaddr *) &serveraddr, sizeof(serveraddr));
|
||||
if (rc < 0) {
|
||||
perror("bind() failed");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
sfilefd = fopen((const char *) (savefilename), "w");
|
||||
printf("Saving to ... %s. Ready! \n", savefilename);
|
||||
|
||||
while (gui_acquisition_thread_running) {
|
||||
/********************************************************************/
|
||||
/* The server uses the recvfrom() function to receive that data. */
|
||||
/* The recvfrom() function waits indefinitely for data to arrive. */
|
||||
/********************************************************************/
|
||||
|
||||
|
||||
if (framesInFile == 20000) {
|
||||
fclose(sfilefd);
|
||||
|
||||
currframenum=(int)(*((int*)buffer));
|
||||
getFrameIndex();
|
||||
//create file name
|
||||
if(!frameIndexNeeded)
|
||||
sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex);
|
||||
else
|
||||
sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,framesCaught,fileIndex);
|
||||
|
||||
printf("saving to %s\t\tpacket loss %f %%\t\tframenum %d\n", savefilename,((currframenum-prevframenum-(2*framesInFile))/(double)(2*framesInFile))*100.000,currframenum);
|
||||
sfilefd = fopen((const char *) (savefilename), "w");
|
||||
prevframenum=currframenum;
|
||||
framesInFile = 0;
|
||||
}
|
||||
status = RUNNING;
|
||||
|
||||
rc1 = recvfrom(sd, buffer, sizeof(onebuffer), 0,
|
||||
(struct sockaddr *) &clientaddr, &clientaddrlen);
|
||||
//printf("rc1 done\n");
|
||||
rc2 = recvfrom(sd, buffer+sizeof(onebuffer), sizeof(onebuffer), 0,
|
||||
(struct sockaddr *) &clientaddr, &clientaddrlen);
|
||||
|
||||
|
||||
//for each scan
|
||||
if(startFrameIndex==-1){
|
||||
startFrameIndex=(int)(*((int*)buffer))-2;
|
||||
prevframenum=startFrameIndex;
|
||||
}
|
||||
//start of acquisition
|
||||
if(startAcquisitionIndex==-1)
|
||||
startAcquisitionIndex=startFrameIndex;
|
||||
|
||||
//printf("rc2 done\n");
|
||||
if ((rc1 < 0) || (rc2 < 0)) {
|
||||
perror("recvfrom() failed");
|
||||
break;
|
||||
}
|
||||
|
||||
//so that it doesnt write the last frame twice
|
||||
if(gui_acquisition_thread_running){
|
||||
fwrite(buffer, 1, rc1, sfilefd);
|
||||
fwrite(buffer+sizeof(onebuffer), 1, rc2, sfilefd);
|
||||
framesInFile++;
|
||||
framesCaught++;
|
||||
totalFramesCaught++;
|
||||
//printf("saving\n");
|
||||
}
|
||||
}
|
||||
} while (gui_acquisition_thread_running);
|
||||
gui_acquisition_thread_running=0;
|
||||
status = IDLE;
|
||||
|
||||
|
||||
/***********************************************************************/
|
||||
/* Close down any open socket descriptors */
|
||||
/***********************************************************************/
|
||||
if (sd != -1){
|
||||
printf("Closing sd\n");fflush(stdout);
|
||||
close(sd);
|
||||
}
|
||||
|
||||
//close file
|
||||
fclose(sfilefd);
|
||||
printf("sfield:%d\n",(int)sfilefd);
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int startReceiver(){
|
||||
#ifdef VERBOSE
|
||||
printf("Starting Receiver\n");
|
||||
#endif
|
||||
|
||||
if(!gui_acquisition_thread_running){
|
||||
printf("Starting new acquisition threadddd ....\n");
|
||||
gui_acquisition_thread_running=1;
|
||||
//status = RUNNING;
|
||||
err = pthread_create(&gui_acquisition_thread, NULL,&startListening, NULL);
|
||||
if(!err){
|
||||
while(status!=RUNNING);
|
||||
printf("\n Thread created successfully.\n");
|
||||
}else{
|
||||
gui_acquisition_thread_running=0;
|
||||
status = IDLE;
|
||||
printf("\n Cant create thread. Status:%d\n",status);
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int stopReceiver(){
|
||||
#ifdef VERBOSE
|
||||
printf("Stopping Receiver\n");
|
||||
#endif
|
||||
|
||||
if(gui_acquisition_thread_running){
|
||||
printf("Stopping new acquisition threadddd ....\n");
|
||||
//stop thread
|
||||
gui_acquisition_thread_running=0;
|
||||
if (sd != -1)
|
||||
shutdown(sd, SHUT_RDWR);
|
||||
pthread_join(gui_acquisition_thread,NULL);
|
||||
status = IDLE;
|
||||
}
|
||||
printf("Status:%d\n",status);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
char* readFrame(char* fName){
|
||||
strcpy(fName,savefilename);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
#endif
|
@ -1,941 +0,0 @@
|
||||
//#include "sls_detector_defs.h"
|
||||
#include "slsReceiver_funcs.h"
|
||||
#include "slsReceiverFunctionList.h"
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
#include "sls_detector_funcs.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// Global variables
|
||||
|
||||
int (*flist[256])(int);
|
||||
|
||||
|
||||
//defined in the detector specific file
|
||||
#ifdef MYTHEND
|
||||
const enum detectorType myDetectorType=MYTHEN;
|
||||
#elif GOTTHARDD
|
||||
const enum detectorType myDetectorType=GOTTHARD;
|
||||
#elif EIGERD
|
||||
const enum detectorType myDetectorType=EIGER;
|
||||
#elif PICASSOD
|
||||
const enum detectorType myDetectorType=PICASSO;
|
||||
#else
|
||||
const enum detectorType myDetectorType=GENERIC;
|
||||
#endif
|
||||
|
||||
|
||||
//define in communication_funcs
|
||||
extern int lockStatus;
|
||||
extern char lastClientIP[INET_ADDRSTRLEN];
|
||||
extern char thisClientIP[INET_ADDRSTRLEN];
|
||||
extern int differentClients;
|
||||
|
||||
|
||||
|
||||
/* global variables for optimized readout */
|
||||
|
||||
char *dataretval=NULL;
|
||||
int dataret;
|
||||
char mess[1000];
|
||||
int dataBytes;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
int init_receiver() {
|
||||
|
||||
|
||||
initializeReceiver();
|
||||
|
||||
strcpy(mess,"dummy message");
|
||||
strcpy(lastClientIP,"none");
|
||||
strcpy(thisClientIP,"none1");
|
||||
lockStatus=0;
|
||||
return OK;
|
||||
}
|
||||
*/
|
||||
|
||||
int decode_function(int file_des) {
|
||||
int fnum,n;
|
||||
int retval=FAIL;
|
||||
#ifdef VERBOSE
|
||||
printf( "receive data\n");
|
||||
#endif
|
||||
n = receiveDataOnly(file_des,&fnum,sizeof(fnum));
|
||||
if (n <= 0) {
|
||||
#ifdef VERBOSE
|
||||
printf("ERROR reading from socket %d, %d %d\n", n, fnum, file_des);
|
||||
#endif
|
||||
return FAIL;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
else
|
||||
printf("size of data received %d\n",n);
|
||||
#endif
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf( "calling function fnum = %d %x\n",fnum,flist[fnum]);
|
||||
#endif
|
||||
if (fnum<0 || fnum>255)
|
||||
fnum=255;
|
||||
retval=(*flist[fnum])(file_des);
|
||||
if (retval==FAIL)
|
||||
printf( "Error executing the function = %d \n",fnum);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
int function_table() {
|
||||
int i;
|
||||
for (i=0;i<256;i++){
|
||||
flist[i]=&M_nofunc;
|
||||
}
|
||||
flist[F_EXIT_SERVER]=&exit_server; //not implemented in client
|
||||
flist[F_EXEC_COMMAND]=&exec_command; //not implemented in client
|
||||
|
||||
|
||||
flist[F_SET_FILE_NAME]=&set_file_name;
|
||||
flist[F_SET_FILE_PATH]=&set_file_dir;
|
||||
flist[F_SET_FILE_INDEX]=&set_file_index;
|
||||
flist[F_START_RECEIVER]=&start_receiver;
|
||||
flist[F_STOP_RECEIVER]=&stop_receiver;
|
||||
flist[F_GET_RECEIVER_STATUS]=&get_receiver_status;
|
||||
flist[F_GET_FRAMES_CAUGHT]=&get_frames_caught;
|
||||
flist[F_GET_FRAME_INDEX]=&get_frame_index;
|
||||
flist[F_RESET_FRAMES_CAUGHT]=&reset_frames_caught;
|
||||
flist[F_READ_FRAME]=&read_frame;
|
||||
|
||||
flist[F_LOCK_RECEIVER]=&lock_receiver;
|
||||
flist[F_SET_PORT]=&set_port;
|
||||
flist[F_GET_LAST_CLIENT_IP]=&get_last_client_ip;
|
||||
flist[F_UPDATE_CLIENT]=&update_client;
|
||||
|
||||
|
||||
#ifdef VERBOSE
|
||||
/* for (i=0;i<256;i++){
|
||||
printf("function %d located at %x\n",i,flist[i]);
|
||||
}*/
|
||||
#endif
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int set_file_name(int file_des) {
|
||||
int ret=OK;
|
||||
int n=0;
|
||||
char fName[MAX_STR_LENGTH],retval[MAX_STR_LENGTH]="";
|
||||
|
||||
strcpy(mess,"Could not set file name");
|
||||
|
||||
|
||||
/* receive arguments */
|
||||
n = receiveDataOnly(file_des,fName,MAX_STR_LENGTH);
|
||||
if (n < 0) {
|
||||
sprintf(mess,"Error reading from socket\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
|
||||
/* execute action if the arguments correctly arrived*/
|
||||
if (ret==OK) {
|
||||
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||
|
||||
if (lockStatus==1 && differentClients==1){//necessary???
|
||||
sprintf(mess,"Receiver locked by %s\n", lastClientIP);
|
||||
ret=FAIL;
|
||||
}
|
||||
/* else if((strlen(fName))&&(getReceiverStatus()==RUNNING)){
|
||||
strcpy(mess,"Can not set file name while receiver running");
|
||||
ret = FAIL;
|
||||
}
|
||||
*/ else
|
||||
strcpy(retval,setFileName(fName));
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifdef VERBOSE
|
||||
if(ret!=FAIL)
|
||||
printf("file name:%s\n",retval);
|
||||
else
|
||||
printf("%s",mess);
|
||||
#endif
|
||||
|
||||
if(ret==OK && differentClients){
|
||||
printf("Force update\n");
|
||||
ret=FORCE_UPDATE;
|
||||
}
|
||||
|
||||
/* send answer */
|
||||
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||
if(ret==FAIL)
|
||||
n = sendDataOnly(file_des,mess,sizeof(mess));
|
||||
n = sendDataOnly(file_des,retval,MAX_STR_LENGTH);
|
||||
|
||||
/*return ok/fail*/
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int set_file_dir(int file_des) {
|
||||
int ret=OK;
|
||||
int n=0;
|
||||
char fPath[MAX_STR_LENGTH],retval[MAX_STR_LENGTH]="";
|
||||
|
||||
strcpy(mess,"Could not set file path\n");
|
||||
|
||||
|
||||
/* receive arguments */
|
||||
n = receiveDataOnly(file_des,fPath,MAX_STR_LENGTH);
|
||||
if (n < 0) {
|
||||
sprintf(mess,"Error reading from socket\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
|
||||
/* execute action if the arguments correctly arrived*/
|
||||
if (ret==OK) {
|
||||
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||
|
||||
if (lockStatus==1 && differentClients==1){//necessary???
|
||||
sprintf(mess,"Receiver locked by %s\n", lastClientIP);
|
||||
ret=FAIL;
|
||||
}
|
||||
else if((strlen(fPath))&&(getReceiverStatus()==RUNNING)){
|
||||
strcpy(mess,"Can not set file path while receiver running\n");
|
||||
ret = FAIL;
|
||||
}
|
||||
else{
|
||||
strcpy(retval,setFilePath(fPath));
|
||||
/* if file path doesnt exist*/
|
||||
if(strlen(fPath))
|
||||
if (strcmp(retval,fPath)){
|
||||
strcpy(mess,"receiver file path does not exist\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
#ifdef VERBOSE
|
||||
if(ret!=FAIL)
|
||||
printf("file path:%s\n",retval);
|
||||
else
|
||||
printf("%s",mess);
|
||||
#endif
|
||||
|
||||
if(ret==OK && differentClients){
|
||||
printf("Force update\n");
|
||||
ret=FORCE_UPDATE;
|
||||
}
|
||||
|
||||
/* send answer */
|
||||
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||
if(ret==FAIL)
|
||||
n = sendDataOnly(file_des,mess,sizeof(mess));
|
||||
n = sendDataOnly(file_des,retval,MAX_STR_LENGTH);
|
||||
|
||||
/*return ok/fail*/
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int set_file_index(int file_des) {
|
||||
int ret=OK;
|
||||
int n=0;
|
||||
int index,retval=-1;
|
||||
|
||||
strcpy(mess,"Could not set file index\n");
|
||||
|
||||
|
||||
/* receive arguments */
|
||||
n = receiveDataOnly(file_des,&index,sizeof(index));
|
||||
if (n < 0) {
|
||||
sprintf(mess,"Error reading from socket\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
|
||||
/* execute action if the arguments correctly arrived*/
|
||||
if (ret==OK) {
|
||||
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||
|
||||
if (lockStatus==1 && differentClients==1){//necessary???
|
||||
sprintf(mess,"Receiver locked by %s\n", lastClientIP);
|
||||
ret=FAIL;
|
||||
}
|
||||
/* else if((index>=0)&&(getReceiverStatus()==RUNNING)){
|
||||
strcpy(mess,"Can not set file index while receiver running\n");
|
||||
ret = FAIL;
|
||||
}
|
||||
*/ else
|
||||
retval=setFileIndex(index);
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifdef VERBOSE
|
||||
if(ret!=FAIL)
|
||||
printf("file index:%d\n",retval);
|
||||
else
|
||||
printf("%s",mess);
|
||||
#endif
|
||||
|
||||
if(ret==OK && differentClients){
|
||||
printf("Force update\n");
|
||||
ret=FORCE_UPDATE;
|
||||
}
|
||||
|
||||
/* send answer */
|
||||
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||
if(ret==FAIL)
|
||||
n = sendDataOnly(file_des,mess,sizeof(mess));
|
||||
n = sendDataOnly(file_des,&retval,sizeof(retval));
|
||||
|
||||
/*return ok/fail*/
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int start_receiver(int file_des) {
|
||||
int ret=OK;
|
||||
int n=0;
|
||||
|
||||
strcpy(mess,"Could not start receiver\n");
|
||||
|
||||
/* execute action if the arguments correctly arrived*/
|
||||
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||
if (lockStatus==1 && differentClients==1){//necessary???
|
||||
sprintf(mess,"Receiver locked by %s\n", lastClientIP);
|
||||
ret=FAIL;
|
||||
}
|
||||
else if(!strlen(setFilePath(""))){
|
||||
strcpy(mess,"receiver not set up. set receiver ip again.\n");
|
||||
ret = FAIL;
|
||||
}
|
||||
else if(getReceiverStatus()!=RUNNING)
|
||||
ret=startReceiver();
|
||||
#endif
|
||||
|
||||
|
||||
if(ret==OK && differentClients){
|
||||
printf("Force update\n");
|
||||
ret=FORCE_UPDATE;
|
||||
}
|
||||
|
||||
/* send answer */
|
||||
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||
if(ret==FAIL)
|
||||
n = sendDataOnly(file_des,mess,sizeof(mess));
|
||||
/*return ok/fail*/
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int stop_receiver(int file_des) {
|
||||
int ret=OK;
|
||||
int n=0;
|
||||
|
||||
strcpy(mess,"Could not stop receiver\n");
|
||||
|
||||
/* execute action if the arguments correctly arrived*/
|
||||
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||
if (lockStatus==1 && differentClients==1){//necessary???
|
||||
sprintf(mess,"Receiver locked by %s\n", lastClientIP);
|
||||
ret=FAIL;
|
||||
}
|
||||
else if(getReceiverStatus()!=IDLE)
|
||||
ret=stopReceiver();
|
||||
#endif
|
||||
|
||||
|
||||
if(ret==OK && differentClients){
|
||||
printf("Force update\n");
|
||||
ret=FORCE_UPDATE;
|
||||
}
|
||||
|
||||
/* send answer */
|
||||
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||
if(ret==FAIL)
|
||||
n = sendDataOnly(file_des,mess,sizeof(mess));
|
||||
/*return ok/fail*/
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int get_receiver_status(int file_des) {
|
||||
int ret=OK;
|
||||
int n=0;
|
||||
enum runStatus retval;
|
||||
|
||||
/* execute action if the arguments correctly arrived*/
|
||||
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||
retval=getReceiverStatus();
|
||||
#endif
|
||||
|
||||
if(ret==OK && differentClients){
|
||||
printf("Force update\n");
|
||||
ret=FORCE_UPDATE;
|
||||
}
|
||||
|
||||
/* send answer */
|
||||
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||
n = sendDataOnly(file_des,&retval,sizeof(retval));
|
||||
/*return ok/fail*/
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int get_frames_caught(int file_des) {
|
||||
int ret=OK;
|
||||
int n=0;
|
||||
int retval=-1;
|
||||
|
||||
/* execute action if the arguments correctly arrived*/
|
||||
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||
retval=getTotalFramesCaught();
|
||||
#endif
|
||||
|
||||
if(ret==OK && differentClients){
|
||||
printf("Force update\n");
|
||||
ret=FORCE_UPDATE;
|
||||
}
|
||||
|
||||
/* send answer */
|
||||
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||
n = sendDataOnly(file_des,&retval,sizeof(retval));
|
||||
/*return ok/fail*/
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int get_frame_index(int file_des) {
|
||||
int ret=OK;
|
||||
int n=0;
|
||||
int retval=-1;
|
||||
|
||||
/* execute action if the arguments correctly arrived*/
|
||||
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||
retval=getAcquisitionIndex();
|
||||
#endif
|
||||
|
||||
if(ret==OK && differentClients){
|
||||
printf("Force update\n");
|
||||
ret=FORCE_UPDATE;
|
||||
}
|
||||
|
||||
/* send answer */
|
||||
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||
n = sendDataOnly(file_des,&retval,sizeof(retval));
|
||||
/*return ok/fail*/
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int reset_frames_caught(int file_des) {
|
||||
int ret=OK;
|
||||
int n=0;
|
||||
int retval=-1;
|
||||
int index=-1;
|
||||
|
||||
strcpy(mess,"Could not reset frames caught\n");
|
||||
|
||||
|
||||
/* receive arguments */
|
||||
n = receiveDataOnly(file_des,&index,sizeof(index));
|
||||
if (n < 0) {
|
||||
sprintf(mess,"Error reading from socket\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
|
||||
if (ret==OK) {
|
||||
/* execute action if the arguments correctly arrived*/
|
||||
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||
if (lockStatus==1 && differentClients==1){//necessary???
|
||||
sprintf(mess,"Receiver locked by %s\n", lastClientIP);
|
||||
ret=FAIL;
|
||||
}
|
||||
else
|
||||
retval=resetTotalFramesCaught(index);
|
||||
#endif
|
||||
}
|
||||
|
||||
if(ret==OK && differentClients){
|
||||
printf("Force update\n");
|
||||
ret=FORCE_UPDATE;
|
||||
}
|
||||
|
||||
/* send answer */
|
||||
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||
if(ret==FAIL)
|
||||
n = sendDataOnly(file_des,mess,sizeof(mess));
|
||||
n = sendDataOnly(file_des,&retval,sizeof(retval));
|
||||
/*return ok/fail*/
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int read_frame(int file_des) {
|
||||
int ret=OK;
|
||||
int n=0,i,startIndex=-1;
|
||||
|
||||
char* retval=NULL;
|
||||
char buffer[1286*2];
|
||||
char fName[MAX_STR_LENGTH];
|
||||
int arg[2];
|
||||
arg[1]=1;//do not flip
|
||||
int index=-1,index2=-1,fIndex=-1;;
|
||||
|
||||
|
||||
strcpy(mess,"Could not read frame\n");
|
||||
|
||||
|
||||
/* execute action if the arguments correctly arrived*/
|
||||
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||
//wait till you get first frame 1. to get index(from startindex 2. filename corresponds to buffer value
|
||||
if(startIndex==-1){
|
||||
ret=FAIL;
|
||||
strcpy(mess,"did not start index\n");
|
||||
for(i=0;i<10;i++){
|
||||
startIndex=getStartFrameIndex();
|
||||
if(startIndex==-1)
|
||||
usleep(1000000);
|
||||
else {
|
||||
ret=OK;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//got atleast first frame, read buffer
|
||||
if(ret==OK){
|
||||
int count=0;
|
||||
do{
|
||||
if(count>0){ printf("\nunmatching: index:%d index2:%d\n",index,index2);fflush(stdout);}
|
||||
retval=readFrame(fName);
|
||||
index=(int)(*((int*)retval));
|
||||
char* retval2= retval+1286;
|
||||
index2= (int)(*((int*)retval2));
|
||||
count++;
|
||||
|
||||
}while((index%2)==(index2%2));
|
||||
|
||||
fIndex=((int)(*((int*)retval)) - startIndex)/2;
|
||||
arg[0]=fIndex-1;
|
||||
arg[1]=(index%2);
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("\nstartIndex:%d\n",startIndex);
|
||||
printf("fName:%s\n",fName);
|
||||
if((index%2)==0){
|
||||
printf("\nEven Index, must flip:%d\n",index);
|
||||
fflush(stdout);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
if(ret==OK && differentClients){
|
||||
printf("Force update\n");
|
||||
ret=FORCE_UPDATE;
|
||||
}
|
||||
/*if(getReceiverStatus()==IDLE){
|
||||
ret=FAIL;
|
||||
printf("*************STOPPPED***\n");
|
||||
}*/
|
||||
/* send answer */
|
||||
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||
if(ret==FAIL)
|
||||
n = sendDataOnly(file_des,mess,sizeof(mess));
|
||||
else{
|
||||
n = sendDataOnly(file_des,fName,MAX_STR_LENGTH);
|
||||
n = sendDataOnly(file_des,arg,sizeof(arg));
|
||||
n = sendDataOnly(file_des,retval,sizeof(buffer));
|
||||
}
|
||||
/*return ok/fail*/
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int M_nofunc(int file_des){
|
||||
|
||||
int retval=FAIL;
|
||||
sprintf(mess,"Unrecognized Function\n");
|
||||
printf(mess);
|
||||
sendDataOnly(file_des,&retval,sizeof(retval));
|
||||
sendDataOnly(file_des,mess,sizeof(mess));
|
||||
return GOODBYE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int exit_server(int file_des) {
|
||||
int retval=FAIL;
|
||||
sendDataOnly(file_des,&retval,sizeof(retval));
|
||||
printf("closing server.");
|
||||
sprintf(mess,"closing server");
|
||||
sendDataOnly(file_des,mess,sizeof(mess));
|
||||
return GOODBYE;
|
||||
}
|
||||
|
||||
int exec_command(int file_des) {
|
||||
char cmd[MAX_STR_LENGTH];
|
||||
char answer[MAX_STR_LENGTH];
|
||||
int retval=OK;
|
||||
int sysret=0;
|
||||
int n=0;
|
||||
|
||||
// receive arguments
|
||||
n = receiveDataOnly(file_des,cmd,MAX_STR_LENGTH);
|
||||
if (n < 0) {
|
||||
sprintf(mess,"Error reading from socket\n");
|
||||
retval=FAIL;
|
||||
}
|
||||
|
||||
// execute action if the arguments correctly arrived
|
||||
if (retval==OK) {
|
||||
//#ifdef VERBOSE
|
||||
printf("executing command %s\n", cmd);
|
||||
//#endif
|
||||
if (lockStatus==0 || differentClients==0)
|
||||
sysret=system(cmd);
|
||||
|
||||
//should be replaced by popen
|
||||
if (sysret==0) {
|
||||
sprintf(answer,"Succeeded\n");
|
||||
if (lockStatus==1 && differentClients==1)
|
||||
sprintf(answer,"Detector locked by %s\n", lastClientIP);
|
||||
} else {
|
||||
sprintf(answer,"Failed\n");
|
||||
retval=FAIL;
|
||||
}
|
||||
} else {
|
||||
sprintf(answer,"Could not receive the command\n");
|
||||
}
|
||||
|
||||
// send answer
|
||||
n = sendDataOnly(file_des,&retval,sizeof(retval));
|
||||
n = sendDataOnly(file_des,answer,MAX_STR_LENGTH);
|
||||
if (n < 0) {
|
||||
sprintf(mess,"Error writing to socket");
|
||||
retval=FAIL;
|
||||
}
|
||||
|
||||
|
||||
//return ok/fail
|
||||
return retval;
|
||||
|
||||
}
|
||||
|
||||
int lock_receiver(int file_des) {
|
||||
|
||||
|
||||
int n;
|
||||
int ret=OK;
|
||||
|
||||
int lock;
|
||||
n = receiveDataOnly(file_des,&lock,sizeof(lock));
|
||||
if (n < 0) {
|
||||
sprintf(mess,"Error reading from socket\n");
|
||||
printf("Error reading from socket (lock)\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
if (lock>=0) {
|
||||
if (lockStatus==0 || strcmp(lastClientIP,thisClientIP)==0 || strcmp(lastClientIP,"none")==0) {
|
||||
lockStatus=lock;
|
||||
strcpy(lastClientIP,thisClientIP);
|
||||
} else {
|
||||
ret=FAIL;
|
||||
sprintf(mess,"Receiver already locked by %s\n", lastClientIP);
|
||||
}
|
||||
}
|
||||
if (differentClients && ret==OK)
|
||||
ret=FORCE_UPDATE;
|
||||
|
||||
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||
if (ret==FAIL) {
|
||||
n = sendDataOnly(file_des,mess,sizeof(mess));
|
||||
} else
|
||||
n = sendDataOnly(file_des,&lockStatus,sizeof(lockStatus));
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int set_port(int file_des) {
|
||||
int n;
|
||||
int ret=OK;
|
||||
int sd=-1;
|
||||
|
||||
enum portType p_type; /** data? control? stop? Unused! */
|
||||
int p_number; /** new port number */
|
||||
|
||||
n = receiveDataOnly(file_des,&p_type,sizeof(p_type));
|
||||
if (n < 0) {
|
||||
sprintf(mess,"Error reading from socket\n");
|
||||
printf("Error reading from socket (ptype)\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
|
||||
n = receiveDataOnly(file_des,&p_number,sizeof(p_number));
|
||||
if (n < 0) {
|
||||
sprintf(mess,"Error reading from socket\n");
|
||||
printf("Error reading from socket (pnum)\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
if (differentClients==1 && lockStatus==1 ) {
|
||||
ret=FAIL;
|
||||
sprintf(mess,"Detector locked by %s\n",lastClientIP);
|
||||
} else {
|
||||
if (p_number<1024) {
|
||||
sprintf(mess,"Too low port number %d\n", p_number);
|
||||
printf("\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
|
||||
printf("set port %d to %d\n",p_type, p_number);
|
||||
|
||||
sd=bindSocket(p_number);
|
||||
}
|
||||
if (sd>=0) {
|
||||
ret=OK;
|
||||
if (differentClients )
|
||||
ret=FORCE_UPDATE;
|
||||
} else {
|
||||
ret=FAIL;
|
||||
sprintf(mess,"Could not bind port %d\n", p_number);
|
||||
printf("Could not bind port %d\n", p_number);
|
||||
if (sd==-10) {
|
||||
sprintf(mess,"Port %d already set\n", p_number);
|
||||
printf("Port %d already set\n", p_number);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||
if (ret==FAIL) {
|
||||
n = sendDataOnly(file_des,mess,sizeof(mess));
|
||||
} else {
|
||||
n = sendDataOnly(file_des,&p_number,sizeof(p_number));
|
||||
closeConnection(file_des);
|
||||
exitServer(sockfd);
|
||||
sockfd=sd;
|
||||
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
int get_last_client_ip(int file_des) {
|
||||
int ret=OK;
|
||||
int n;
|
||||
if (differentClients )
|
||||
ret=FORCE_UPDATE;
|
||||
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||
n = sendDataOnly(file_des,lastClientIP,sizeof(lastClientIP));
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int send_update(int file_des) {
|
||||
|
||||
int ret=OK;
|
||||
int n,ind;
|
||||
char path[MAX_STR_LENGTH];
|
||||
|
||||
|
||||
n = sendDataOnly(file_des,lastClientIP,sizeof(lastClientIP));
|
||||
//index
|
||||
ind=getFileIndex(-1);
|
||||
n = sendDataOnly(file_des,&ind,sizeof(ind));
|
||||
//filepath
|
||||
strcpy(path,getFilePath(""));
|
||||
n = sendDataOnly(file_des,path,MAX_STR_LENGTH);
|
||||
//filename
|
||||
strcpy(path,getFileName(""));
|
||||
n = sendDataOnly(file_des,path,MAX_STR_LENGTH);
|
||||
|
||||
if (lockStatus==0) {
|
||||
strcpy(lastClientIP,thisClientIP);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
int update_client(int file_des) {
|
||||
|
||||
int ret=OK;
|
||||
sendDataOnly(file_des,&ret,sizeof(ret));
|
||||
return send_update(file_des);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
int set_master(int file_des) {
|
||||
|
||||
enum masterFlags retval=GET_MASTER;
|
||||
enum masterFlags arg;
|
||||
int n;
|
||||
int ret=OK;
|
||||
// int regret=OK;
|
||||
|
||||
|
||||
sprintf(mess,"can't set master flags\n");
|
||||
|
||||
|
||||
n = receiveDataOnly(file_des,&arg,sizeof(arg));
|
||||
if (n < 0) {
|
||||
sprintf(mess,"Error reading from socket\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("setting master flags to %d\n",arg);
|
||||
#endif
|
||||
|
||||
if (differentClients==1 && lockStatus==1 && arg!=GET_READOUT_FLAGS) {
|
||||
ret=FAIL;
|
||||
sprintf(mess,"Detector locked by %s\n",lastClientIP);
|
||||
} else {
|
||||
retval=setMaster(arg);
|
||||
|
||||
}
|
||||
if (retval==GET_MASTER) {
|
||||
ret=FAIL;
|
||||
}
|
||||
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||
if (ret==FAIL) {
|
||||
n = sendDataOnly(file_des,mess,sizeof(mess));
|
||||
} else {
|
||||
n = sendDataOnly(file_des,&retval,sizeof(retval));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int set_synchronization(int file_des) {
|
||||
|
||||
enum synchronizationMode retval=GET_MASTER;
|
||||
enum synchronizationMode arg;
|
||||
int n;
|
||||
int ret=OK;
|
||||
//int regret=OK;
|
||||
|
||||
|
||||
sprintf(mess,"can't set synchronization mode\n");
|
||||
|
||||
|
||||
n = receiveDataOnly(file_des,&arg,sizeof(arg));
|
||||
if (n < 0) {
|
||||
sprintf(mess,"Error reading from socket\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
printf("setting master flags to %d\n",arg);
|
||||
#endif
|
||||
|
||||
if (differentClients==1 && lockStatus==1 && arg!=GET_READOUT_FLAGS) {
|
||||
ret=FAIL;
|
||||
sprintf(mess,"Detector locked by %s\n",lastClientIP);
|
||||
} else {
|
||||
retval=setSynchronization(arg);
|
||||
}
|
||||
if (retval==GET_SYNCHRONIZATION_MODE) {
|
||||
ret=FAIL;
|
||||
}
|
||||
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||
if (ret==FAIL) {
|
||||
n = sendDataOnly(file_des,mess,sizeof(mess));
|
||||
} else {
|
||||
n = sendDataOnly(file_des,&retval,sizeof(retval));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
*/
|
@ -1,328 +0,0 @@
|
||||
#include "usersFunctions.h"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
double pos;
|
||||
double i0=0;
|
||||
#ifdef EPICS
|
||||
|
||||
#include <cadef.h>
|
||||
#include <epicsEvent.h>
|
||||
|
||||
static double timeout = 3.0;
|
||||
|
||||
chid ch_pos,ch_i0, ch_getpos;
|
||||
void *ch_arg,*ch_darg,*ch_parg,*ch_poarg,*ch_ioarg;
|
||||
|
||||
|
||||
|
||||
|
||||
/* connect to a PV */
|
||||
int connect_channel(const char *name, chid *ch_id) {
|
||||
int status = ECA_NORMAL;
|
||||
status = ca_create_channel(name, NULL, NULL, CA_PRIORITY_DEFAULT, ch_id);
|
||||
if (status != ECA_NORMAL)
|
||||
return status;
|
||||
|
||||
status = ca_pend_io(timeout);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* disconnect to a PV */
|
||||
int disconnect_channel(chid ch_id)
|
||||
{
|
||||
ca_clear_channel(ch_id);
|
||||
ca_flush_io();
|
||||
}
|
||||
|
||||
int caget(chid ch_id, double *value) {
|
||||
|
||||
int status = ECA_NORMAL;
|
||||
|
||||
status = ca_get(DBR_DOUBLE, ch_id, value);
|
||||
if (status != ECA_NORMAL) {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = ca_pend_io(timeout);
|
||||
if (status != ECA_NORMAL) {
|
||||
return status;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int caputq(chid ch_id, double value) {
|
||||
// does not wait!
|
||||
int status = ECA_NORMAL;
|
||||
|
||||
status = ca_put(DBR_DOUBLE, ch_id, &value);
|
||||
if (status != ECA_NORMAL)
|
||||
return status;
|
||||
|
||||
status = ca_pend_io(timeout);
|
||||
if (status != ECA_NORMAL) {
|
||||
return status;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
void put_callback(struct event_handler_args args)
|
||||
{
|
||||
epicsEventId eid = (epicsEventId)args.usr;
|
||||
epicsEventSignal(eid);
|
||||
}
|
||||
|
||||
int caput(chid ch_id, double value) {
|
||||
|
||||
// waits!
|
||||
int status = ECA_NORMAL;
|
||||
epicsEventId eid = epicsEventCreate(epicsEventEmpty);
|
||||
|
||||
status = ca_put_callback(DBR_DOUBLE,
|
||||
ch_id,
|
||||
&value,
|
||||
put_callback,
|
||||
eid);
|
||||
status = ca_pend_io(timeout);
|
||||
if (status != ECA_NORMAL)
|
||||
return status;
|
||||
|
||||
if (epicsEventWait(eid) != epicsEventWaitOK)
|
||||
status = ECA_TIMEOUT;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
//int main(int argc, char *argv[]) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
contains the conversion channel-angle for a module channel
|
||||
conv_r=pitch/radius
|
||||
*/
|
||||
|
||||
|
||||
double angle(int ichan, double encoder, double totalOffset, double conv_r, double center, double offset, double tilt, int direction) {
|
||||
|
||||
|
||||
(void) tilt; /* to avoid warning: unused parameter */
|
||||
double ang;
|
||||
|
||||
|
||||
|
||||
ang=180./PI*(center*conv_r+atan((double)(ichan-center)*conv_r))+encoder+totalOffset+offset;
|
||||
|
||||
|
||||
cout <<"***" << offset << " " << ang << endl;
|
||||
|
||||
|
||||
return direction*ang;
|
||||
|
||||
}
|
||||
|
||||
/* reads the encoder and returns the position */
|
||||
|
||||
double get_position(void *ch_poarg) {
|
||||
#ifdef VERBOSE
|
||||
printf("Getting motor position \n");
|
||||
#endif
|
||||
// caget X04SA-ES2-TH2:RO.RBV
|
||||
|
||||
#ifdef EPICS
|
||||
int status;
|
||||
|
||||
double value = 256;
|
||||
if (ch_getpos<0) return -1;
|
||||
|
||||
/* /\* caget *\/ */
|
||||
if (caget(ch_getpos, &value) == ECA_NORMAL) {
|
||||
#ifdef VERBOSE
|
||||
printf("caget: %f\n", value);
|
||||
#endif
|
||||
pos=value;
|
||||
} else
|
||||
printf(ca_message(status));
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
/* moves the encoder to position p */
|
||||
|
||||
|
||||
int go_to_position(double p,void *ch_parg) {
|
||||
#ifdef VERBOSE
|
||||
printf("Setting motor position \n");
|
||||
#endif
|
||||
|
||||
#ifdef EPICS
|
||||
int status;
|
||||
if (ch_pos<0) return -1;
|
||||
/* /\* caput and wait until done *\/ */
|
||||
if ((status = caput(ch_pos, p)) == ECA_NORMAL)
|
||||
;
|
||||
#ifdef VERBOSE
|
||||
printf("caput: success\n");
|
||||
#endif
|
||||
else
|
||||
printf(ca_message(status));
|
||||
#else
|
||||
pos=p;
|
||||
#endif
|
||||
//"caputq X04SA-ES2-TH2:RO p"
|
||||
//cawait -nounit -timeout 3600 X04SA-ES2-TH2:RO.DMOV '==1'
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
/* moves the encoder to position p without waiting */
|
||||
|
||||
int go_to_position_no_wait(double p) {
|
||||
#ifdef VERBOSE
|
||||
printf("Setting motor position no wait \n");
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef EPICS
|
||||
int status;
|
||||
if (ch_pos<0) return -1;
|
||||
/* /\* caput and wait until done *\/ */
|
||||
if ((status = caputq(ch_pos, p)) == ECA_NORMAL)
|
||||
;
|
||||
#ifdef VERBOSE
|
||||
printf("caputq: success\n");
|
||||
#endif
|
||||
|
||||
else
|
||||
printf(ca_message(status));
|
||||
#else
|
||||
pos=p;
|
||||
#endif
|
||||
//"caputq X04SA-ES2-TH2:RO p"
|
||||
|
||||
return p;
|
||||
|
||||
|
||||
|
||||
|
||||
pos=p;
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
/* reads I0 and returns the intensity */
|
||||
|
||||
double get_i0(void *ch_ioarg) {
|
||||
#ifdef VERBOSE
|
||||
printf("Getting I0 readout \n");
|
||||
#endif
|
||||
|
||||
#ifdef EPICS
|
||||
int status;
|
||||
|
||||
double value = 256;
|
||||
/* /\* caget *\/ */
|
||||
if (ch_i0<0) return -1;
|
||||
if (caget(ch_i0, &value) == ECA_NORMAL) {
|
||||
#ifdef VERBOSE
|
||||
printf("caget: %f\n", value);
|
||||
#endif
|
||||
i0=value;
|
||||
} else
|
||||
printf(ca_message(status));
|
||||
#else
|
||||
i0++;
|
||||
#endif
|
||||
|
||||
//"ca_get X04SA-ES2-SC:CH6"
|
||||
return i0;
|
||||
}
|
||||
|
||||
|
||||
int connect_channels(void *ch_arg) {
|
||||
#ifdef EPICS
|
||||
//double value = 256;
|
||||
/* channel name */
|
||||
//const char *name = "ARIDI-PCT:CURRENT";
|
||||
/* channel id */
|
||||
/* status code */
|
||||
int status;
|
||||
|
||||
printf("starting...\n");
|
||||
|
||||
/* init channel access context before any caget/put */
|
||||
ca_context_create(ca_enable_preemptive_callback);
|
||||
|
||||
printf("context created\n");
|
||||
|
||||
//"caputq X04SA-ES2-TH2:RO p"
|
||||
|
||||
//"ca_get X04SA-ES2-SC:CH6"
|
||||
|
||||
/* open the channel by name and return ch_id */
|
||||
status = connect_channel("NULLX04SA-ES2-SC:CH6", &ch_i0);
|
||||
if (status == ECA_NORMAL)
|
||||
printf("I0 channel connected \n");
|
||||
else {
|
||||
printf(ca_message(status));
|
||||
//ch_i0=-1;;
|
||||
}
|
||||
status = connect_channel("X04SA-ES2-TH2:RO", &ch_pos);
|
||||
if (status == ECA_NORMAL)
|
||||
printf("Detector position channel connected \n");
|
||||
else {
|
||||
printf(ca_message(status));
|
||||
//ch_i0=-1;;
|
||||
}
|
||||
status = connect_channel("X04SA-ES2-TH2:RO.RBV", &ch_getpos);
|
||||
if (status == ECA_NORMAL)
|
||||
printf("Detector get position channel connected \n");
|
||||
else {
|
||||
printf(ca_message(status));
|
||||
//ch_getpos=-1;;
|
||||
}
|
||||
|
||||
// caget X04SA-ES2-TH2:RO.RBV
|
||||
|
||||
//cawait -nounit -timeout 3600 X04SA-ES2-TH2:RO.DMOV '==1'
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int disconnect_channels(void *ch_darg) {
|
||||
#ifdef EPICS
|
||||
/* close channel connect */
|
||||
disconnect_channel(ch_i0);
|
||||
disconnect_channel(ch_pos);
|
||||
disconnect_channel(ch_getpos);
|
||||
|
||||
/* delete channel access context before program exits */
|
||||
ca_context_destroy();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user