Files
sics/site_ansto/lh45.c
Ferdi Franceschini 81359a740f Added to repository.
r986 | ffr | 2006-05-09 09:17:15 +1000 (Tue, 09 May 2006) | 2 lines
2012-11-15 12:44:13 +11:00

285 lines
8.5 KiB
C

/*---------------------------------------------------------------------------
L H 4 5
This is the implementation for a LH45 object derived from an more general
environment controller.
Mark Koennecke, August 1997
Mark Lesha, January 2006 (based on ITC4 code)
Copyright:
Labor fuer Neutronenstreuung
Paul Scherrer Institut
CH-5423 Villigen-PSI
The authors hereby grant permission to use, copy, modify, distribute,
and license this software and its documentation for any purpose, provided
that existing copyright notices are retained in all copies and that this
notice is included verbatim in any distributions. No written agreement,
license, or royalty fee is required for any of the authorized uses.
Modifications to this software may be copyrighted by their authors
and need not follow the licensing terms described here, provided that
the new terms are clearly indicated on the first page of each file where
they apply.
IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE
IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
MODIFICATIONS.
----------------------------------------------------------------------------*/
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <tcl.h>
#include <fortify.h>
#include <sics.h>
#include <splitter.h>
#include <obpar.h>
#include <devexec.h>
#include <nserver.h>
#include <interrupt.h>
#include <emon.h>
#include <evcontroller.h>
#include <evcontroller.i>
#include "lh45.h"
/*---------------------------------------------------------------------------*/
int LH45SetPar(pEVControl self, char *name, float fNew, SConnection *pCon)
{
int iRet;
/* check authorsisation */
if(!SCMatchRights(pCon,usUser))
{
SCWrite(pCon,"ERROR: you are not authorised to change this parameter",
eError);
return 0;
}
/* just catch those three names which we understand */
if(strcmp(name,"sensor") == 0)
{
iRet = SetSensorLH45(self->pDriv,(int)fNew);
if(!iRet)
{
SCWrite(pCon,"ERROR: value out of range",eError);
return 0;
}
iRet = ConfigLH45(self->pDriv);
if(iRet != 1)
{
SCWrite(pCon,"ERROR: LH45 configuration failed! ",eError);
SCWrite(pCon,"INFO: Probably comm problem, Retry!",eError);
return 0;
}
SCSendOK(pCon);
return 1;
}
else if(strcmp(name,"control") == 0)
{
iRet = SetControlLH45(self->pDriv,(int)fNew);
if(!iRet)
{
SCWrite(pCon,"ERROR: value out of range",eError);
return 0;
}
iRet = ConfigLH45(self->pDriv);
if(iRet != 1)
{
SCWrite(pCon,"ERROR: LH45 configuration failed! ",eError);
SCWrite(pCon,"INFO: Probably comm problem, Retry!",eError);
return 0;
}
SCSendOK(pCon);
return 1;
}
else if(strcmp(name,"timeout") == 0)
{
iRet = SetTMOLH45(self->pDriv,(int)fNew);
if(!iRet)
{
SCWrite(pCon,"ERROR: value out of range",eError);
return 0;
}
iRet = ConfigLH45(self->pDriv);
if(iRet != 1)
{
SCWrite(pCon,"ERROR: LH45 configuration failed! ",eError);
SCWrite(pCon,"INFO: Probably comm problem, Retry!",eError);
return 0;
}
SCSendOK(pCon);
return 1;
}
/* Note divisors and multipliers will not be used with the LH45
but leave in for back compatibility */
else if(strcmp(name,"divisor") == 0)
{
iRet = SetDivisorLH45(self->pDriv,fNew);
if(!iRet)
{
SCWrite(pCon,"ERROR: value out of range",eError);
return 0;
}
iRet = ConfigLH45(self->pDriv);
if(iRet != 1)
{
SCWrite(pCon,"ERROR: LH45 configuration failed! ",eError);
SCWrite(pCon,"INFO: Probably comm problem, Retry!",eError);
return 0;
}
SCSendOK(pCon);
return 1;
}
else if(strcmp(name,"multiplicator") == 0)
{
iRet = SetMultLH45(self->pDriv,fNew);
if(!iRet)
{
SCWrite(pCon,"ERROR: value out of range",eError);
return 0;
}
iRet = ConfigLH45(self->pDriv);
if(iRet != 1)
{
SCWrite(pCon,"ERROR: LH45 configuration failed! ",eError);
SCWrite(pCon,"INFO: Probably comm problem, Retry!",eError);
return 0;
}
SCSendOK(pCon);
return 1;
}
else
return EVCSetPar(self,name,fNew,pCon);
}
/*--------------------------------------------------------------------------*/
int LH45GetPar(pEVControl self, char *name, float *fNew)
{
int iRet;
float fDiv;
/* just catch those two names which we understand */
if(strcmp(name,"sensor") == 0)
{
iRet = GetSensorLH45(self->pDriv);
*fNew = (float)iRet;
return 1;
}
else if(strcmp(name,"control") == 0)
{
iRet = GetControlLH45(self->pDriv);
*fNew = (float)iRet;
return 1;
}
else if(strcmp(name,"timeout") == 0)
{
iRet = GetTMOLH45(self->pDriv);
*fNew = (float)iRet;
return 1;
}
else if(strcmp(name,"divisor") == 0)
{
fDiv = GetDivisorLH45(self->pDriv);
*fNew = fDiv;
return 1;
}
else if(strcmp(name,"multiplicator") == 0)
{
fDiv = GetMultLH45(self->pDriv);
*fNew = fDiv;
return 1;
}
else
return EVCGetPar(self,name,fNew);
}
/*---------------------------------------------------------------------------*/
int LH45List(pEVControl self, SConnection *pCon)
{
char pBueffel[132];
int iRet;
iRet = EVCList(self,pCon);
sprintf(pBueffel,"%s.sensor = %d\n",self->pName,
GetSensorLH45(self->pDriv));
SCWrite(pCon,pBueffel,eValue);
sprintf(pBueffel,"%s.control = %d\n",self->pName,
GetControlLH45(self->pDriv));
SCWrite(pCon,pBueffel,eValue);
sprintf(pBueffel,"%s.timeout = %d\n",self->pName,
GetTMOLH45(self->pDriv));
SCWrite(pCon,pBueffel,eValue);
sprintf(pBueffel,"%s.divisor = %f\n",self->pName,
GetDivisorLH45(self->pDriv));
SCWrite(pCon,pBueffel,eValue);
sprintf(pBueffel,"%s.multiplicator = %f\n",self->pName,
GetMultLH45(self->pDriv));
SCWrite(pCon,pBueffel,eValue);
return iRet;
}
/*-------------------------------------------------------------------------*/
int LH45Wrapper(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[])
{
pEVControl self = NULL;
char pBueffel[256];
int iRet;
double fNum;
float fVal;
self = (pEVControl)pData;
assert(self);
assert(pCon);
assert(pSics);
if(argc < 2)
{
return EVControlWrapper(pCon,pSics,pData,argc,argv);
}
strtolower(argv[1]);
if((strcmp(argv[1],"sensor") == 0) || (strcmp(argv[1],"control") == 0) ||
(strcmp(argv[1],"timeout") == 0) || (strcmp(argv[1],"divisor") == 0) ||
(strcmp(argv[1],"multiplicator") == 0) )
{
if(argc > 2) /* set case */
{
iRet = Tcl_GetDouble(pSics->pTcl,argv[2],&fNum);
if(iRet != TCL_OK)
{
sprintf(pBueffel,"ERROR: expected number, got %s",argv[2]);
SCWrite(pCon,pBueffel,eError);
return 0;
}
return LH45SetPar(self,argv[1],(float)fNum,pCon);
}
else /* get case */
{
iRet = LH45GetPar(self,argv[1],&fVal);
sprintf(pBueffel,"%s.%s = %f\n",self->pName,
argv[1],fVal);
SCWrite(pCon,pBueffel,eValue);
return 1;
}
}
else if(strcmp(argv[1],"list") == 0)
{
return LH45List(self,pCon);
}
else
{
return EVControlWrapper(pCon,pSics,pData,argc,argv);
}
/* not reached */
return 0;
}