From a7ebdff308b7b2c2dd654989991bfa7006060056 Mon Sep 17 00:00:00 2001 From: Ferdi Franceschini Date: Tue, 25 Jul 2006 16:48:14 +1000 Subject: [PATCH] Created anstoutil to share the getParam function. Modified motor_dmc2280 and counterdiv to use anstoutil r1033 | ffr | 2006-07-25 16:48:14 +1000 (Tue, 25 Jul 2006) | 3 lines --- site_ansto/Makefile | 9 ++- site_ansto/anstoutil.c | 25 ++++++ site_ansto/anstoutil.h | 7 ++ site_ansto/counterdriv.c | 159 +++++++++++++++++++++++++++++-------- site_ansto/motor_dmc2280.c | 25 +----- 5 files changed, 166 insertions(+), 59 deletions(-) create mode 100644 site_ansto/anstoutil.c create mode 100644 site_ansto/anstoutil.h diff --git a/site_ansto/Makefile b/site_ansto/Makefile index 8dfd9920..3aa488eb 100644 --- a/site_ansto/Makefile +++ b/site_ansto/Makefile @@ -62,10 +62,11 @@ TANGOLIBS = \ # itc4.o itc4driv.o \ # hm_mrpd.o scan_mrpd.o -OBJ= site_ansto.o \ +OBJ= site_ansto.o anstoutil.o\ motor_asim.o motor_dmc2280.o\ lh45.o lh45driv.o \ lakeshore340.o lakeshore340driv.o \ + counterdriv.o\ ../psi/tcpdocho.o ../psi/tcpdornier.o all: ../matrix/libmatrix.a $(COREOBJ:%=../%) libansto.a libhardsup @@ -88,13 +89,15 @@ hm_mrpd.o : hm_mrpd.cpp hm_asim.o : hm_asim.cpp $(CXX) -c hm_asim.cpp $(CFLAGS) $(CXXFLAGS) -Wno-all -clean: - $(PSI_CLEAN_MATRIX) +anstoclean: $(MAKE) -C hardsup clean rm -f SICServer rm -f *.a rm -f *.o +clean: anstoclean + $(PSI_CLEAN_MATRIX) + MZOBJ=fsm.o logger.o sugar.o pardef.o ease.o strobj.o oxinst.o \ ipsdriv.o ilmdriv.o itcdriv.o ighdriv.o euro2kdriv.o modbus.o diff --git a/site_ansto/anstoutil.c b/site_ansto/anstoutil.c new file mode 100644 index 00000000..b75ce89e --- /dev/null +++ b/site_ansto/anstoutil.c @@ -0,0 +1,25 @@ +#include +#include +#include "anstoutil.h" + +/** \brief Get configuration parameter + * \param *pCon (r) connection object. + * \param *pTcl (r) Tcl interpreter + * \param *params Tcl array of configuration parameters + * \param *parName name of parameter to get from the array + * \param mustHave indicates optional or mandatory parameters\n + * possible values + * - _REQUIRED + * - _OPTIONAL + * \return (r) a reference to a string representation of the parameter value + */ +char *getParam(SConnection *pCon, Tcl_Interp *pTcl, char *params, char *parName, int mustHave ) { + char *pPtr=NULL; + char pError[ERRLEN]; + pPtr = Tcl_GetVar2(pTcl,params,parName,TCL_GLOBAL_ONLY); + if((mustHave == _REQUIRED) && !pPtr){ + snprintf(pError, ERRLEN,"ERROR: No '%s' parameter given for dmc2280 motor", parName); + SCWrite(pCon,pError, eError); + } + return pPtr; +} diff --git a/site_ansto/anstoutil.h b/site_ansto/anstoutil.h new file mode 100644 index 00000000..30abe7ff --- /dev/null +++ b/site_ansto/anstoutil.h @@ -0,0 +1,7 @@ +#ifndef ANSTOUTIL_H +#define ANSTOUTIL_H +#define _REQUIRED 1 +#define _OPTIONAL 0 +#define ERRLEN 256 +/*@observer@*/ char *getParam(/*@dependent@*/SConnection *pCon, Tcl_Interp *pTcl, char *params, char *parName, int mustHave ); +#endif diff --git a/site_ansto/counterdriv.c b/site_ansto/counterdriv.c index e82bcc38..57223f67 100644 --- a/site_ansto/counterdriv.c +++ b/site_ansto/counterdriv.c @@ -1,14 +1,31 @@ +/** \file motor_dmc2280.c + * \brief Driver for Galil DMC2280 motor controller. + * + * Implements a SICS motor object with a MotorDriver interface. + * + * Copyright: see file Copyright.txt + * + * Ferdi Franceschini July 2006 + * + */ #include #include #include #include #include "fortify.h" #include -#include "sics.h" -#include "countdriv.h" +#include +#include +#include +#include "anstoutil.h" +/*@-incondefs@*/ +/*@observer@*//*@dependent@*/ Tcl_Interp *InterpGetTcl(SicsInterp *pSics); +/*@observer@*//*@dependent@*/ pCounterDriver CreateCounterDriver(char *name, char *type); +/*@+incondefs@*/ + +#if 0 typedef struct __COUNTDRIV { - /* variables */ char *name; char *type; CounterMode eMode; @@ -19,58 +36,136 @@ typedef struct __COUNTDRIV { long lCounts[MAXCOUNT]; int iPause; int iErrorCode; - /* functions */ - int (*GetStatus)(CounterDriver *self, float *fControl); - int (*Start)(CounterDriver *self); - int (*Pause)(CounterDriver *self); - int (*Continue)(CounterDriver *self); - int (*Halt)(CounterDriver *self); - int (*ReadValues)(CounterDriver *self); - int (*GetError)(CounterDriver *self, int *iCode, char *error, int iErrLen); - int (*TryAndFixIt)(CounterDriver *self, int iCode); - int (*Set)(CounterDriver *self,char *name, int iCter, float fVal); - int (*Get)(CounterDriver *self,char *name, int iCter, float *fVal); - int (*Send)(CounterDriver *self, char *pText, char *pReply, int iReplyLen); - void (*KillPrivate)(CounterDriver *self); - void *pData; /* counter specific data goes here, ONLY for - internal driver use! - */ -} CountDriv, *pCountDriv; + + int (*GetStatus)(CounterDriver *cntrData, float *fControl); + int (*Start)(CounterDriver *cntrData); + int (*Pause)(CounterDriver *cntrData); + int (*Continue)(CounterDriver *cntrData); + int (*Halt)(CounterDriver *cntrData); + int (*ReadValues)(CounterDriver *cntrData); + int (*GetError)(CounterDriver *cntrData, int *iCode, char *error, int iErrLen); + int (*TryAndFixIt)(CounterDriver *cntrData, int iCode); + int (*Set)(CounterDriver *cntrData,char *name, int iCter, float fVal); + int (*Get)(CounterDriver *cntrData,char *name, int iCter, float *fVal); + int (*Send)(CounterDriver *cntrData, char *pText, char *pReply, int iReplyLen); + void (*KillPrivate)(CounterDriver *cntrData); + void *pData; /* counter specific data */ + /*@observer@*//*@dependent@*/SConnection *pCon; + prs232 controller; + +} CountDriv, *BeamMon; +#endif + +typedef struct { + char *host; + int iPort; + int iChannel; + void *pData; + int finishCount; +} BeamMon; /*---------------------------------------------------------------------------*/ -static int MonGetStatus(CounterDriver *self, float *fControl) { +static int MonGetStatus(CounterDriver *cntrData, float *fControl) { + BeamMon *self = NULL; + + self = (BeamMon *) cntrData; } -static int MonStart(CounterDriver *self) { +static int MonStart(CounterDriver *cntrData) { + BeamMon *self = NULL; + + self = (BeamMon *) cntrData; } -static int MonPause(CounterDriver *self) { +static int MonPause(CounterDriver *cntrData) { + BeamMon *self = NULL; + + self = (BeamMon *) cntrData; } -static int MonContinue(CounterDriver *self) { +static int MonContinue(CounterDriver *cntrData) { + BeamMon *self = NULL; + + self = (BeamMon *) cntrData; } -static int MonHalt(CounterDriver *self) { +static int MonHalt(CounterDriver *cntrData) { + BeamMon *self = NULL; + + self = (BeamMon *) cntrData; } -static int MonReadValues(CounterDriver *self) { +static int MonReadValues(CounterDriver *cntrData) { + BeamMon *self = NULL; + + self = (BeamMon *) cntrData; } -static int MonGetError(CounterDriver *self, int *iCode, char *error, int iErrLen) { +static int MonGetError(CounterDriver *cntrData, int *iCode, char *error, int iErrLen) { + BeamMon *self = NULL; + + self = (BeamMon *) cntrData; } -static int MonTryAndFixIt(CounterDriver *self, int iCode) { +static int MonTryAndFixIt(CounterDriver *cntrData, int iCode) { + BeamMon *self = NULL; + + self = (BeamMon *) cntrData; } -static int MonSet(CounterDriver *self, char *name, int iCter, float FVal) { +static int MonSet(CounterDriver *cntrData, char *name, int iCter, float FVal) { + BeamMon *self = NULL; + + self = (BeamMon *) cntrData; } -static int MonGet(CounterDriver *self, char *name, int iCter, float *fVal) { +static int MonGet(CounterDriver *cntrData, char *name, int iCter, float *fVal) { + BeamMon *self = NULL; + + self = (BeamMon *) cntrData; } -static int MonSend(CounterDriver *self, char *pText, char *pReply, int iReplyLen) { +static int MonSend(CounterDriver *cntrData, char *pText, char *pReply, int iReplyLen) { + BeamMon *self = NULL; + + self = (BeamMon *) cntrData; } -pCountDriv CreateMonCounter(char *name, float fFail) { +static void KillMon(pCounterDriver self) { +} + +/*@observer@*//*@null@*/ pCounterDriver CreateMonCounter(/*@observer@*/SConnection *pCon, /*@observer@*/char *name, char *params) { + BeamMon *newCtr = NULL; + pCounterDriver pCntDriv = NULL; + char *pPtr = NULL; + char buffer[132]; + int port; + Tcl_Interp *interp; + + interp = InterpGetTcl(pServ->pSics); + + newCtr = (BeamMon *)malloc(sizeof(BeamMon)); + if(NULL == newCtr){ + (void) SCWrite(pCon,"ERROR: no memory to allocate counter driver", + eError); + return NULL; + } + pCntDriv = CreateCounterDriver(name, "MONITOR"); + if(!pCntDriv) { + return NULL; + } + /* Get hostname and port from the list of named parameters */ + if ((pPtr=getParam(pCon, interp, params,"port",1)) == NULL) { + KillMon(pCntDriv); + return NULL; + } + sscanf(pPtr,"%d",&port); + if ((pPtr=getParam(pCon, interp, params,"host",1)) == NULL) { + KillMon(pCntDriv); + return NULL; + } + strncpy(buffer,pPtr, 131); + + return pCntDriv; } diff --git a/site_ansto/motor_dmc2280.c b/site_ansto/motor_dmc2280.c index c3f6f47c..c61195c6 100644 --- a/site_ansto/motor_dmc2280.c +++ b/site_ansto/motor_dmc2280.c @@ -25,6 +25,7 @@ #include #include #include +#include "anstoutil.h" /* #include "splint/splint_fortify.h" @@ -124,12 +125,9 @@ typedef struct __MoDriv { #define INIT_STR_SIZE 256 #define STR_RESIZE_LENGTH 256 #define CMDLEN 1024 -#define ERRLEN 256 #define BUFFLEN 512 #define FAILURE 0 #define SUCCESS 1 -#define _REQUIRED 1 -#define _OPTIONAL 0 #define _SAVEPOWER 0 #define HOME "home" @@ -929,27 +927,6 @@ static void KillDMC2280(/*@only@*/void *pData){ return controller; } -/** \brief Get configuration parameter - * \param *pCon (r) connection object. - * \param *pTcl (r) Tcl interpreter - * \param *params Tcl array of configuration parameters - * \param *parName name of parameter to get from the array - * \param mustHave indicates optional or mandatory parameters\n - * possible values - * - _REQUIRED - * - _OPTIONAL - * \return (r) a reference to a string representation of the parameter value - */ -/*@observer@*/ static char *getParam(/*@dependent@*/SConnection *pCon, Tcl_Interp *pTcl, char *params, char *parName, int mustHave ) { - char *pPtr=NULL; - char pError[ERRLEN]; - pPtr = Tcl_GetVar2(pTcl,params,parName,TCL_GLOBAL_ONLY); - if((mustHave == _REQUIRED) && !pPtr){ - snprintf(pError, ERRLEN,"ERROR: No '%s' parameter given for dmc2280 motor", parName); - SCWrite(pCon,pError, eError); - } - return pPtr; -} /** \brief Create a driver for the DMC2280 Galil controller. *