- Rearranged directory structure for forking out ANSTO
- Refactored site specific stuff into a site module - PSI specific stuff is now in the PSI directory. - The old version has been tagged with pre-ansto
This commit is contained in:
464
psi.c
Normal file
464
psi.c
Normal file
@@ -0,0 +1,464 @@
|
||||
/*------------------------------------------------------------------------
|
||||
P S I
|
||||
|
||||
This is the site specific interface to SICS for PSI. This file implements
|
||||
the interface defined in ../site.h
|
||||
|
||||
copyright: see file COPYRIGHT
|
||||
|
||||
Mark Koennecke, June 2003
|
||||
-----------------------------------------------------------------------*/
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <fortify.h>
|
||||
#include <sics.h>
|
||||
#include <motor.h>
|
||||
#include <tcl.h>
|
||||
#include <site.h>
|
||||
#include "buffer.h"
|
||||
#include "dmc.h"
|
||||
#include "nxsans.h"
|
||||
#include "nextrics.h"
|
||||
#include "sps.h"
|
||||
#include "pimotor.h"
|
||||
#include "sanswave.h"
|
||||
#include "faverage.h"
|
||||
#include "fowrite.h"
|
||||
#include "amor2t.h"
|
||||
#include "nxamor.h"
|
||||
#include "amorstat.h"
|
||||
#include "tas.h"
|
||||
#include "swmotor.h"
|
||||
#include "polterwrite.h"
|
||||
#include "ecb.h"
|
||||
#include "frame.h"
|
||||
#include "ecbdriv.h"
|
||||
#include "ecbcounter.h"
|
||||
#include <stringdict.h>
|
||||
#include "sinqhmdriv.i"
|
||||
#include "tdchm.h"
|
||||
#include "tecsdriv.h"
|
||||
#include "itc4.h"
|
||||
#include "bruker.h"
|
||||
#include "ltc11.h"
|
||||
#include "A1931.h"
|
||||
#include "dilludriv.h"
|
||||
#include "eurodriv.h"
|
||||
#include "el755driv.h"
|
||||
#include <evdriver.i>
|
||||
#include "amorscan.h"
|
||||
#include "serial.h"
|
||||
|
||||
static pSite sitePSI = NULL;
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
static void AddPsiCommands(SicsInterp *pInter){
|
||||
AddCommand(pInter,"MakeRuenBuffer",InitBufferSys,NULL,NULL);
|
||||
AddCommand(pInter,"InitDMC",InitDmc,NULL,NULL);
|
||||
AddCommand(pInter,"InitSANS",InitSANS,NULL,NULL);
|
||||
AddCommand(pInter,"MakeTRICSNEXUS",NexTricsFactory,NULL,NULL);
|
||||
AddCommand(pInter,"MakeSPS",SPSFactory,NULL,NULL);
|
||||
AddCommand(pInter,"MakePIMotor",PIMotorFactory,NULL,NULL);
|
||||
AddCommand(pInter,"MakeSANSWave",MakeSANSWave,NULL,NULL);
|
||||
AddCommand(pInter,"MakeFocusAverager",MakeFA,NULL,NULL);
|
||||
AddCommand(pInter,"FocusInstall",FoInstall,NULL,NULL);
|
||||
AddCommand(pInter,"MakeAmor2T",Amor2TFactory,NULL,NULL);
|
||||
AddCommand(pInter,"MakeStoreAmor",AmorStoreMake,NULL,NULL);
|
||||
AddCommand(pInter,"MakeAmorStatus",AmorStatusFactory,NULL,NULL);
|
||||
AddCommand(pInter,"MakeTAS",TASFactory,NULL,NULL);
|
||||
AddCommand(pInter,"MakeSWMotor",MakeSWMotor,NULL,NULL);
|
||||
AddCommand(pInter,"PolterInstall",PolterInstall,NULL,NULL);
|
||||
AddCommand(pInter,"MakeECB",MakeECB,NULL,NULL);
|
||||
AddCommand(pInter,"MakePSDFrame",MakeFrameFunc,NULL,NULL);
|
||||
AddCommand(pInter,"SerialInit",SerialInit,NULL,NULL);
|
||||
/*
|
||||
AddCommand(pInter,"MakeDifrac",MakeDifrac,NULL,NULL);
|
||||
*/
|
||||
}
|
||||
/*---------------------------------------------------------------------*/
|
||||
static void RemovePsiCommands(SicsInterp *pSics){
|
||||
RemoveCommand(pSics,"InitDMC");
|
||||
RemoveCommand(pSics,"InitSANS");
|
||||
RemoveCommand(pSics,"MakeTRICSNEXUS");
|
||||
RemoveCommand(pSics,"MakeSPS");
|
||||
RemoveCommand(pSics,"MakePIMotor");
|
||||
RemoveCommand(pSics,"MakeSANSWave");
|
||||
RemoveCommand(pSics,"MakeFocusAverager");
|
||||
RemoveCommand(pSics,"FocusInstall");
|
||||
RemoveCommand(pSics,"MakeAmor2T");
|
||||
RemoveCommand(pSics,"MakeStoreAmor");
|
||||
RemoveCommand(pSics,"MakeAmorStatus");
|
||||
/*
|
||||
RemoveCommand(pSics,"MakeDifrac");
|
||||
*/
|
||||
RemoveCommand(pSics,"MakeTAS");
|
||||
RemoveCommand(pSics,"MakeSWMotor");
|
||||
RemoveCommand(pSics,"PolterInstall");
|
||||
RemoveCommand(pSics,"MakeECB");
|
||||
RemoveCommand(pSics,"MakePSDFrame");
|
||||
RemoveCommand(pSics,"SerialInit");
|
||||
}
|
||||
/*---------------------------------------------------------------------*/
|
||||
MotorDriver *CreateEL734(SConnection *pCon, int argc, char *argv[]);
|
||||
MotorDriver *CreateEL734DC(SConnection *pCon, int argc, char *argv[]);
|
||||
/*-------------------------------------------------------------------*/
|
||||
static pMotor CreatePsiMotor(SConnection *pCon, int argc, char *argv[]){
|
||||
MotorDriver *pDriver = NULL;
|
||||
pMotor pNew = NULL;
|
||||
Tcl_Interp *pTcl = NULL;
|
||||
char pBueffel[132];
|
||||
|
||||
if(strcmp(argv[1],"pipiezo") == 0){
|
||||
pTcl = InterpGetTcl(pServ->pSics);
|
||||
pDriver = (MotorDriver *)MakePiPiezo(pTcl,argv[2]);
|
||||
if(!pDriver){
|
||||
SCWrite(pCon,pTcl->result,eError);
|
||||
return NULL;
|
||||
}
|
||||
/* create the motor */
|
||||
pNew = MotorInit("PIPIEZO",argv[0],pDriver);
|
||||
if(!pNew){
|
||||
sprintf(pBueffel,"Failure to create motor %s",argv[0]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return NULL;
|
||||
}
|
||||
} else if(strcmp(argv[1],"el734") == 0){
|
||||
pDriver = (MotorDriver *)CreateEL734(pCon,argc-2,&argv[2]);
|
||||
if(!pDriver){
|
||||
return NULL;
|
||||
}
|
||||
/* create the motor */
|
||||
pNew = MotorInit("EL734",argv[0],pDriver);
|
||||
if(!pNew){
|
||||
sprintf(pBueffel,"Failure to create motor %s",argv[1]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return NULL;
|
||||
}
|
||||
} else if(strcmp(argv[1],"el734dc") == 0){
|
||||
pDriver = (MotorDriver *)CreateEL734DC(pCon,argc-2,&argv[2]);
|
||||
if(!pDriver){
|
||||
return NULL;
|
||||
}
|
||||
/* create the motor */
|
||||
pNew = MotorInit("EL734DC",argv[0],pDriver);
|
||||
if(!pNew){
|
||||
sprintf(pBueffel,"Failure to create motor %s",argv[1]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return NULL;
|
||||
}
|
||||
} else if(strcmp(argv[1],"ecb") == 0){
|
||||
pDriver = (MotorDriver *)CreateECBMotor(pCon,argc-1,&argv[2]);
|
||||
if(!pDriver){
|
||||
return NULL;
|
||||
}
|
||||
/* create the motor */
|
||||
pNew = MotorInit("ECB",argv[0],pDriver);
|
||||
if(!pNew){
|
||||
sprintf(pBueffel,"Failure to create motor %s",argv[0]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return pNew;
|
||||
}
|
||||
/*-------------------------------------------------------------------*/
|
||||
extern pCounterDriver CreateEL737Counter(SConnection *pCon, char *name,
|
||||
int argc, char *argv[]);
|
||||
/*-------------------------------------------------------------------*/
|
||||
static pCounterDriver CreatePsiCounterDriver(SConnection *pCon,
|
||||
int argc,
|
||||
char *argv[]){
|
||||
pCounterDriver pNew = NULL;
|
||||
|
||||
/*
|
||||
our caller has already checked for enough arguments
|
||||
*/
|
||||
if(strcmp(argv[2],"el737") == 0){
|
||||
pNew = CreateEL737Counter(pCon,argv[1],argc-3,&argv[3]);
|
||||
} else if(strcmp(argv[2],"ecb") == 0){
|
||||
if(argc < 4){
|
||||
SCWrite(pCon,
|
||||
"ERROR: insufficient no of arguments to create ECB counter",
|
||||
eError);
|
||||
return NULL;
|
||||
pNew = MakeECBCounter(argv[3]);
|
||||
}
|
||||
}
|
||||
return pNew;
|
||||
}
|
||||
/*-------------------------------------------------------------------*/
|
||||
static HistDriver *CreatePsiHistMem(char *name, pStringDict pOptions){
|
||||
HistDriver *pNew = NULL;
|
||||
|
||||
if(strcmp(name,"sinqhm") == 0){
|
||||
pNew = CreateSINQDriver(pOptions);
|
||||
} else if(strcmp(name,"tdc") == 0){
|
||||
pNew = MakeTDCHM(pOptions);
|
||||
}
|
||||
return pNew;
|
||||
}
|
||||
/*-------------------------------------------------------------------*/
|
||||
extern pVelSelDriv VSCreateDornierSINQ(char *name,Tcl_Interp *pTcl);
|
||||
/*-------------------------------------------------------------------*/
|
||||
static pVelSelDriv CreatePsiVelSelDriv(char *name, char *array,
|
||||
Tcl_Interp *pTcl){
|
||||
pVelSelDriv pNew = NULL;
|
||||
if(strcmp(name,"dornier") == 0){
|
||||
pNew = VSCreateDornierSINQ(array,pTcl);
|
||||
}
|
||||
return pNew;
|
||||
}
|
||||
/*------------------------------------------------------------------*/
|
||||
extern pCodri MakeDoChoDriver(char *pHost, int iPort, int iChannel,
|
||||
int iSingle);
|
||||
extern pCodri MakeCookerDriver(char *pHost, int iPort, int iChannel);
|
||||
/*-------------------------------------------------------------------*/
|
||||
static pCodri CreatePsiController(SConnection *pCon,int argc, char *argv[]){
|
||||
pCodri pNew = NULL;
|
||||
Tcl_Interp *pTcl = InterpGetTcl(pServ->pSics);
|
||||
int iPort, iChannel, iRet, iSingle = 0;
|
||||
char pBueffel[512];
|
||||
|
||||
if(strcmp(argv[0],"docho") == 0) {
|
||||
if(argc < 4) {
|
||||
SCWrite(pCon,
|
||||
"ERROR: Insufficient number of arguments to install Dornier Chopper driver",
|
||||
eError);
|
||||
return NULL;
|
||||
}
|
||||
iRet = Tcl_GetInt(pTcl,argv[2],&iPort);
|
||||
if(iRet != TCL_OK){
|
||||
sprintf(pBueffel,"ERROR: expected integer as port number, got %s",
|
||||
argv[2]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return NULL;
|
||||
}
|
||||
iRet = Tcl_GetInt(pTcl,argv[3],&iChannel);
|
||||
if(iRet != TCL_OK){
|
||||
sprintf(pBueffel,"ERROR: expected integer as channel number, got %s",
|
||||
argv[3]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return NULL;
|
||||
}
|
||||
if(argc > 4) {
|
||||
iRet = Tcl_GetInt(pTcl,argv[4],&iSingle);
|
||||
if(iRet != TCL_OK){
|
||||
sprintf(pBueffel,
|
||||
"ERROR: expected integer as single flag, got %s",
|
||||
argv[4]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
pNew = MakeDoChoDriver(argv[1],iPort,iChannel,iSingle);
|
||||
}else if(strcmp(argv[0],"sanscook") == 0) {
|
||||
if(argc < 4){
|
||||
SCWrite(pCon,
|
||||
"ERROR: Insufficient number of arguments to install SANS Cooker driver",
|
||||
eError);
|
||||
return NULL;
|
||||
}
|
||||
iRet = Tcl_GetInt(pTcl,argv[2],&iPort);
|
||||
if(iRet != TCL_OK){
|
||||
sprintf(pBueffel,"ERROR: expected integer as port number, got %s",
|
||||
argv[2]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return NULL;
|
||||
}
|
||||
iRet = Tcl_GetInt(pTcl,argv[3],&iChannel);
|
||||
if(iRet != TCL_OK){
|
||||
sprintf(pBueffel,"ERROR: expected integer as channel number, got %s",
|
||||
argv[3]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return NULL;
|
||||
}
|
||||
pNew = MakeCookerDriver(argv[1],iPort,iChannel);
|
||||
}
|
||||
return pNew;
|
||||
}
|
||||
/*-----------------------------------------------------------------
|
||||
ConfigureController is a helper function which configures parameters
|
||||
for certain controller types
|
||||
--------------------------------------------------------------------*/
|
||||
static void ConfigureController(char *name, pEVControl pNew,
|
||||
SConnection *pCon){
|
||||
EVCSetPar(pNew,"upperlimit",300.0,pCon);
|
||||
EVCSetPar(pNew,"lowerlimit",1.0,pCon);
|
||||
if(strcmp(name,"euro") == 0){
|
||||
EVCSetPar(pNew,"upperlimit",750.0,pCon);
|
||||
EVCSetPar(pNew,"lowerlimit",15.0,pCon);
|
||||
} else if(strcmp(name,"el755") == 0){
|
||||
EVCSetPar(pNew,"upperlimit",10.,pCon);
|
||||
EVCSetPar(pNew,"lowerlimit",-10.,pCon);
|
||||
} else if(strcmp(name,"bruker") == 0){
|
||||
EVCSetPar(pNew,"upperlimit",45.,pCon);
|
||||
EVCSetPar(pNew,"lowerlimit",0.,pCon);
|
||||
} else if(strcmp(name,"ltc11") == 0){
|
||||
EVCSetPar(pNew,"upperlimit",500.,pCon);
|
||||
EVCSetPar(pNew,"lowerlimit",1.5,pCon);
|
||||
}
|
||||
}
|
||||
/*-------------------------------------------------------------------*/
|
||||
extern pEVDriver CreateSLSDriv(int argc, char *argv[]);
|
||||
/*------------------------------------------------------------------*/
|
||||
static pEVControl InstallPsiEnvironmentController(SicsInterp *pSics,
|
||||
SConnection *pCon,
|
||||
int argc, char *argv[]){
|
||||
pEVControl pNew = NULL;
|
||||
pEVDriver pDriv = NULL;
|
||||
int status = 1, checkError = 0, commandInstalled = 0;
|
||||
char pBueffel[512], pError[132];
|
||||
|
||||
/*
|
||||
flag usage:
|
||||
checkError becomes 1 when a driver has been recognized and an error
|
||||
must be issued if something failed.
|
||||
commandInstalled becomes 1 when the command has already been installed
|
||||
for the device. If 0 the default command will be installed later on
|
||||
*/
|
||||
|
||||
if(strcmp(argv[3],"tecs") == 0){
|
||||
checkError = 1;
|
||||
pDriv = CreateTecsDriver(argc-4,&argv[4]);
|
||||
if(pDriv != NULL){
|
||||
pNew = CreateEVController(pDriv,argv[2],&status);
|
||||
if(pNew){
|
||||
AddCommand(pSics,argv[2],TecsWrapper,DeleteEVController,pNew);
|
||||
commandInstalled = 1;
|
||||
}
|
||||
}
|
||||
} else if(strcmp(argv[3],"itc4") == 0) {
|
||||
checkError = 1;
|
||||
pDriv = CreateITC4Driver(argc-4,&argv[4]);
|
||||
if(pDriv){
|
||||
pNew = CreateEVController(pDriv,argv[2],&status);
|
||||
if(pNew != NULL){
|
||||
AddCommand(pSics,argv[2],ITC4Wrapper,DeleteEVController,
|
||||
pNew);
|
||||
commandInstalled = 1;
|
||||
}
|
||||
}
|
||||
} else if(strcmp(argv[3],"bruker") == 0){
|
||||
checkError = 1;
|
||||
pDriv = CreateBrukerDriver(argc-4,&argv[4]);
|
||||
if(pDriv != NULL){
|
||||
pNew = CreateEVController(pDriv,argv[2],&status);
|
||||
if(pNew != NULL){
|
||||
AddCommand(pSics,argv[2],BrukerAction,DeleteEVController,
|
||||
pNew);
|
||||
commandInstalled = 1;
|
||||
}
|
||||
}
|
||||
} else if(strcmp(argv[2],"ltc11") == 0){
|
||||
checkError = 1;
|
||||
pDriv = CreateLTC11Driver(argc-4,&argv[4]);
|
||||
if(pDriv != NULL){
|
||||
pNew = CreateEVController(pDriv,argv[2],&status);
|
||||
if(pNew != NULL){
|
||||
AddCommand(pSics,argv[2],LTC11Action,DeleteEVController,pNew);
|
||||
commandInstalled = 1;
|
||||
}
|
||||
}
|
||||
} else if(strcmp(argv[3],"a1931") == 0){
|
||||
checkError = 1;
|
||||
pDriv = CreateA1931Driver(argc-4,&argv[4]);
|
||||
if(pDriv != NULL){
|
||||
pNew = CreateEVController(pDriv,argv[2],&status);
|
||||
if(pNew != NULL){
|
||||
AddCommand(pSics,argv[2],A1931Action,DeleteEVController, pNew);
|
||||
commandInstalled = 1;
|
||||
}
|
||||
}
|
||||
} else if(strcmp(argv[3],"dillu") == 0){
|
||||
checkError = 1;
|
||||
pDriv = CreateDILLUDriv(argc-4,&argv[4]);
|
||||
if(pDriv != NULL){
|
||||
pNew = CreateEVController(pDriv,argv[2],&status);
|
||||
}
|
||||
} else if(strcmp(argv[3],"euro") == 0){
|
||||
checkError = 1;
|
||||
pDriv = CreateEURODriv(argc-4,&argv[4]);
|
||||
if(pDriv != NULL){
|
||||
pNew = CreateEVController(pDriv,argv[2],&status);
|
||||
}
|
||||
} else if(strcmp(argv[3],"psi-dsp") == 0) {
|
||||
pDriv = CreateSLSDriv(argc-4,&argv[4]);
|
||||
if(pDriv != NULL){
|
||||
pNew = CreateEVController(pDriv,argv[2],&status);
|
||||
}
|
||||
} else if(strcmp(argv[3],"el755") == 0){
|
||||
checkError = 1;
|
||||
pDriv = CreateEL755Driv(argc-4,&argv[4]);
|
||||
if(pDriv != NULL){
|
||||
pNew = CreateEVController(pDriv,argv[2],&status);
|
||||
}
|
||||
}
|
||||
|
||||
/* if we recognized the driver, check for installation errors */
|
||||
if(checkError == 1){
|
||||
if(pDriv == NULL){
|
||||
SCWrite(pCon,"ERROR: failed to create driver",eError);
|
||||
return NULL;
|
||||
}
|
||||
if(pNew == NULL){
|
||||
SCWrite(pCon,"ERROR: failed to create environment device object",
|
||||
eError);
|
||||
DeleteEVDriver(pDriv);
|
||||
return NULL;
|
||||
}
|
||||
if(status != 1) {
|
||||
SCWrite(pCon,"ERROR: failed to initialize device",
|
||||
eError);
|
||||
pDriv->GetError(pDriv,&status,pError,131);
|
||||
sprintf(pBueffel,"HW reported: %s",pError);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
}
|
||||
if(commandInstalled == 0){
|
||||
AddCommand(pSics,argv[2],EVControlWrapper,DeleteEVController,pNew);
|
||||
}
|
||||
ConfigureController(argv[3],pNew,pCon);
|
||||
}
|
||||
|
||||
return pNew;
|
||||
}
|
||||
/*-----------------------------------------------------------------*/
|
||||
static int ConfigurePsiScan(pScanData self, char *option){
|
||||
if(strcmp(option,"amor") == 0){
|
||||
ConfigureAmor(self);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*--------------------------------------------------------------------*/
|
||||
static void KillPsi(void *site){
|
||||
free(site);
|
||||
sitePSI = NULL;
|
||||
}
|
||||
/*---------------------------------------------------------------------
|
||||
The scheme here goes along the lines of the singleton design pattern
|
||||
---------------------------------------------------------------------*/
|
||||
pSite getSite(void){
|
||||
if(sitePSI == NULL){
|
||||
sitePSI = (pSite)malloc(sizeof(Site));
|
||||
/*
|
||||
we cannot go on if we do not even have enough memory to allocate
|
||||
the site data structure
|
||||
*/
|
||||
assert(sitePSI);
|
||||
/*
|
||||
initializing function pointers
|
||||
*/
|
||||
sitePSI->AddSiteCommands = AddPsiCommands;
|
||||
sitePSI->RemoveSiteCommands = RemovePsiCommands;
|
||||
sitePSI->CreateMotor = CreatePsiMotor;
|
||||
sitePSI->CreateCounterDriver = CreatePsiCounterDriver;
|
||||
sitePSI->CreateHistogramMemoryDriver = CreatePsiHistMem;
|
||||
sitePSI->CreateVelocitySelector = CreatePsiVelSelDriv;
|
||||
sitePSI->CreateControllerDriver = CreatePsiController;
|
||||
sitePSI->InstallEnvironmentController = InstallPsiEnvironmentController;
|
||||
sitePSI->ConfigureScan = ConfigurePsiScan;
|
||||
sitePSI->KillSite = KillPsi;
|
||||
}
|
||||
return sitePSI;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user