- 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 SKIPPED: psi/A1931.c psi/A1931.h psi/amor2t.c psi/amor2t.h psi/amor2t.i psi/amor2t.tex psi/amor2t.w psi/amorscan.c psi/amorscan.h psi/amorscan.w psi/amorstat.c psi/amorstat.h psi/amorstat.i psi/amorstat.tex psi/amorstat.w psi/bruker.c psi/bruker.h psi/bruker.w psi/buffer.c psi/buffer.h psi/dilludriv.c psi/dilludriv.h psi/dmc.c psi/dmc.h psi/dmc.w psi/docho.c psi/ecb.c psi/ecb.h psi/ecb.i psi/ecb.w psi/ecbdriv.c psi/ecbdriv.h psi/el734dc.c psi/el734driv.c psi/el755driv.c psi/el755driv.h psi/faverage.c psi/faverage.h psi/faverage.tex psi/faverage.w psi/fowrite.c psi/fowrite.h psi/itc4.c psi/itc4.h psi/itc4.w psi/itc4driv.c psi/ltc11.c psi/ltc11.h psi/nextrics.c psi/nextrics.h psi/nxamor.c psi/nxamor.h psi/nxamor.tex psi/nxamor.w psi/pimotor.c psi/pimotor.h psi/pimotor.tex psi/pimotor.w psi/pipiezo.c psi/polterwrite.c psi/polterwrite.h psi/psi.c psi/ruli.c psi/ruli.h psi/sanscook.c psi/sanswave.c psi/sanswave.h psi/sanswave.tex psi/sanswave.w psi/serial.c psi/serial.h psi/serial.w psi/sinqhmdriv.c psi/sinqhmdriv.i psi/sinqhmdriv.w psi/slsmagnet.c psi/sps.c psi/sps.h psi/sps.i psi/sps.tex psi/sps.w psi/swmotor.c psi/swmotor.h psi/swmotor.i psi/tas.c psi/tas.h psi/tas.tex psi/tas.w psi/tasdrive.c psi/tasinit.c psi/tasscan.c psi/tasu.h psi/tasutil.c psi/tdchm.c psi/tdchm.h psi/tecsdriv.c psi/tecsdriv.h psi/velodorn.c psi/velodorn.h psi/velodorn.w psi/velodornier.c psi/hardsup/README psi/hardsup/StrMatch.c psi/hardsup/asynsrv_def.h psi/hardsup/asynsrv_errcodes.h psi/hardsup/asynsrv_mark.c psi/hardsup/asynsrv_utility.c psi/hardsup/c_interfaces.c psi/hardsup/dillutil.c psi/hardsup/dillutil.h psi/hardsup/el734_def.h psi/hardsup/el734_errcodes.h psi/hardsup/el734_utility.c psi/hardsup/el734fix.h psi/hardsup/el734tcl.c psi/hardsup/el737_def.h psi/hardsup/el737_errcodes.h psi/hardsup/el737_utility.c psi/hardsup/el737fix.h psi/hardsup/el737tcl.c psi/hardsup/el755_def.h psi/hardsup/el755_errcodes.h psi/hardsup/el755_errorlog.c psi/hardsup/el755_utility.c psi/hardsup/err.c psi/hardsup/failinet.c psi/hardsup/geterrno.c psi/hardsup/itc4util.c psi/hardsup/itc4util.h psi/hardsup/make_gen psi/hardsup/makefile_alpha psi/hardsup/makefile_linux psi/hardsup/makeprint.c psi/hardsup/rs232c_def.h psi/hardsup/serialsinq.c psi/hardsup/serialsinq.h psi/hardsup/sinq_defs.h psi/hardsup/sinq_prototypes.h psi/hardsup/sinqhm.c psi/hardsup/sinqhm.h psi/hardsup/sinqhm_def.h psi/hardsup/stredit.c psi/hardsup/strjoin.c psi/hardsup/table.c psi/hardsup/table.h psi/hardsup/velsel_def.h psi/hardsup/velsel_utility.c psi/motor/Makefile psi/motor/el734_test psi/motor/el734_test.c psi/motor/makeprint.c psi/sinqhm/FOCUS_gbl.h psi/sinqhm/FOCUS_srv_main.c psi/sinqhm/Makefile psi/sinqhm/SinqHM_bootParamsConfig.c psi/sinqhm/SinqHM_bootUtil.c psi/sinqhm/SinqHM_def.h psi/sinqhm/SinqHM_gbl.h psi/sinqhm/SinqHM_srv_filler.c psi/sinqhm/SinqHM_srv_main.c psi/sinqhm/SinqHM_srv_routines.c psi/sinqhm/SinqHM_srv_server.c psi/sinqhm/bld psi/sinqhm/bld2 psi/sinqhm/bldmen psi/sinqhm/hist_mem_notes.tex psi/sinqhm/hist_mem_spec.tex psi/sinqhm/hist_mem_spec_fig1.ps psi/sinqhm/hist_mem_spec_fig2.ps psi/sinqhm/hist_mem_spec_fig3.ps psi/sinqhm/hist_mem_spec_fig4.ps psi/sinqhm/lwl_client.c psi/sinqhm/lwl_server.c psi/sinqhm/make_sinqhm.com psi/sinqhm/monitor.c psi/sinqhm/psi_logo.ps psi/sinqhm/sinq_logo.ps psi/sinqhm/sinqhm_bootutil_client.c psi/sinqhm/sinqhm_client.c psi/sinqhm/sinqhm_ctrl.c psi/sinqhm/usrConfig.c psi/sinqhm/usrConfig.c_diffs psi/sinqhm/usrConfig2604.c psi/sinqhm/vmio10_def.h psi/sinqhm/vmio_utility.c psi/tecs/coc_client.c psi/tecs/coc_client.h psi/tecs/coc_logfile.c psi/tecs/coc_logfile.h psi/tecs/coc_server.c psi/tecs/coc_server.h psi/tecs/coc_util.c psi/tecs/coc_util.h psi/tecs/fortify1.c psi/tecs/instr_hosts.c psi/tecs/instr_hosts.h psi/tecs/keep_running.c psi/tecs/make_gen psi/tecs/make_opt psi/tecs/make_opt_alpha psi/tecs/make_opt_llc psi/tecs/makefile psi/tecs/makefile_alpha psi/tecs/makefile_linux psi/tecs/myc_buf.c psi/tecs/myc_buf.h psi/tecs/myc_err.c psi/tecs/myc_err.h psi/tecs/myc_fortran.h psi/tecs/myc_mem.h psi/tecs/myc_str.c psi/tecs/myc_str.h psi/tecs/myc_time.c psi/tecs/myc_time.h psi/tecs/myc_tmp.c psi/tecs/myc_tmp.h psi/tecs/rstart.c psi/tecs/six.c psi/tecs/str.f psi/tecs/sys_cmdpar.f psi/tecs/sys_date.f psi/tecs/sys_env.c psi/tecs/sys_get_key.f psi/tecs/sys_getenv.f psi/tecs/sys_lun.f psi/tecs/sys_open.f psi/tecs/sys_open_alpha.f psi/tecs/sys_rdline.c psi/tecs/sys_select.c psi/tecs/sys_select.h psi/tecs/sys_unix.c psi/tecs/sys_wait.f psi/tecs/tecs.bld psi/tecs/tecs.c psi/tecs/tecs.tcl psi/tecs/tecs_c.c psi/tecs/tecs_c.h psi/tecs/tecs_cli.c psi/tecs/tecs_cli.h psi/tecs/tecs_client.f psi/tecs/tecs_data.c psi/tecs/tecs_data.h psi/tecs/tecs_dlog.inc psi/tecs/tecs_for.f psi/tecs/tecs_lsc.c psi/tecs/tecs_lsc.h psi/tecs/tecs_plot.f psi/tecs/tecs_serial.c psi/tecs/tecs_serial.h psi/tecs/term.c psi/tecs/term.h psi/utils/Makefile psi/utils/SerPortServer.c psi/utils/asynsrv_test.c psi/utils/ecb-load.c psi/utils/el734.c psi/utils/el734_test.c psi/utils/el737.c psi/utils/make.ecb psi/utils/check/amorcheck psi/utils/check/dmccheck psi/utils/check/focuscheck psi/utils/check/focusstatus.tcl psi/utils/check/hrptcheck psi/utils/check/sanscheck psi/utils/check/sicssyntax.tex psi/utils/check/sicssyntaxlib.tcl psi/utils/check/test.tcl psi/utils/check/topsicheck psi/utils/check/tricscheck psi/utils/check/tst
This commit is contained in:
663
countdriv.c
663
countdriv.c
@@ -43,9 +43,6 @@
|
||||
#include <string.h>
|
||||
#include "sics.h"
|
||||
#include "countdriv.h"
|
||||
#include "hardsup/sinq_prototypes.h"
|
||||
#include "hardsup/el737_def.h"
|
||||
#include "hardsup/el737fix.h"
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
pCounterDriver CreateCounterDriver(char *name, char *type)
|
||||
@@ -92,661 +89,13 @@
|
||||
}
|
||||
if(self->pData)
|
||||
{
|
||||
free(self->pData);
|
||||
if(self->KillPrivate != NULL)
|
||||
{
|
||||
self->KillPrivate(self);
|
||||
} else {
|
||||
free(self->pData);
|
||||
}
|
||||
}
|
||||
free(self);
|
||||
}
|
||||
/*----------------------------- EL737 ------------------------------------*/
|
||||
typedef struct {
|
||||
char *host;
|
||||
int iPort;
|
||||
int iChannel;
|
||||
void *pData;
|
||||
int finishCount;
|
||||
} EL737st;
|
||||
/*------------------------------------------------------------------------*/
|
||||
static int EL737GetStatus(struct __COUNTER *self, float *fControl)
|
||||
{
|
||||
int iRet;
|
||||
int iC1, iC2, iC3,iC4,iRS;
|
||||
float fTime;
|
||||
EL737st *pEL737;
|
||||
|
||||
assert(self);
|
||||
pEL737 = (EL737st *)self->pData;
|
||||
assert(pEL737);
|
||||
iRet = EL737_GetStatus(&pEL737->pData,&iC1,&iC2,&iC3,&iC4,&fTime,&iRS);
|
||||
if(self->eMode == eTimer)
|
||||
{
|
||||
*fControl = fTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
*fControl = iC1;
|
||||
}
|
||||
/* store time */
|
||||
self->fTime = fTime;
|
||||
|
||||
if(iRet != 1)
|
||||
{
|
||||
return HWFault;
|
||||
}
|
||||
self->lCounts[0] = iC2;
|
||||
self->lCounts[1] = iC1;
|
||||
self->lCounts[2] = iC3;
|
||||
self->lCounts[3] = iC4;
|
||||
|
||||
/* get extra counters for 8-fold counter boxes */
|
||||
iRet = EL737_GetStatusExtra(&pEL737->pData,&iC1,&iC2,&iC3,&iC4);
|
||||
self->lCounts[4] = iC1;
|
||||
self->lCounts[5] = iC2;
|
||||
self->lCounts[6] = iC3;
|
||||
self->lCounts[7] = iC4;
|
||||
if(iRS == 0)
|
||||
{
|
||||
pEL737->finishCount++;
|
||||
if(pEL737->finishCount >= 2)
|
||||
{
|
||||
return HWIdle;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HWBusy;
|
||||
}
|
||||
}
|
||||
else if((iRS == 1) || (iRS == 2))
|
||||
{
|
||||
pEL737->finishCount = 0;
|
||||
return HWBusy;
|
||||
}
|
||||
else if( (iRS == 5) || (iRS == 6))
|
||||
{
|
||||
pEL737->finishCount = 0;
|
||||
return HWNoBeam;
|
||||
}
|
||||
else
|
||||
{
|
||||
pEL737->finishCount = 0;
|
||||
return HWPause;
|
||||
}
|
||||
}
|
||||
#ifdef NONINTF
|
||||
extern float nintf(float f);
|
||||
#endif
|
||||
/*-------------------------------------------------------------------------*/
|
||||
static int EL737Start(struct __COUNTER *self)
|
||||
{
|
||||
int iRet, iRS;
|
||||
EL737st *pEL737;
|
||||
|
||||
assert(self);
|
||||
pEL737 = (EL737st *)self->pData;
|
||||
assert(pEL737);
|
||||
|
||||
|
||||
self->fTime = 0.;
|
||||
|
||||
if(self->eMode == ePreset)
|
||||
{
|
||||
iRet = EL737_StartCnt(&pEL737->pData,(int)nintf(self->fPreset),&iRS);
|
||||
if(iRet == 1)
|
||||
{
|
||||
pEL737->finishCount = 0;
|
||||
return OKOK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HWFault;
|
||||
}
|
||||
}
|
||||
else if(self->eMode == eTimer)
|
||||
{
|
||||
iRet = EL737_StartTime(&pEL737->pData,self->fPreset,&iRS);
|
||||
if(iRet == 1)
|
||||
{
|
||||
pEL737->finishCount = 0;
|
||||
return OKOK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HWFault;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
static int EL737Pause(struct __COUNTER *self)
|
||||
{
|
||||
int iRet, iRS;
|
||||
EL737st *pEL737;
|
||||
|
||||
assert(self);
|
||||
pEL737 = (EL737st *)self->pData;
|
||||
assert(pEL737);
|
||||
|
||||
|
||||
iRet = EL737_Pause(&pEL737->pData,&iRS);
|
||||
if(iRet == 1)
|
||||
{
|
||||
return OKOK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HWFault;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
static int EL737Continue(struct __COUNTER *self)
|
||||
{
|
||||
int iRet, iRS;
|
||||
EL737st *pEL737;
|
||||
|
||||
assert(self);
|
||||
pEL737 = (EL737st *)self->pData;
|
||||
assert(pEL737);
|
||||
|
||||
|
||||
iRet = EL737_Continue(&pEL737->pData,&iRS);
|
||||
if(iRet == 1)
|
||||
{
|
||||
return OKOK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HWFault;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static int EL737Halt(struct __COUNTER *self)
|
||||
{
|
||||
int iRet, iC1, iC2, iC3, iC4,iRS;
|
||||
float fPreset;
|
||||
EL737st *pEL737;
|
||||
|
||||
assert(self);
|
||||
pEL737 = (EL737st *)self->pData;
|
||||
assert(pEL737);
|
||||
|
||||
|
||||
|
||||
iRet = EL737_Stop(&pEL737->pData,&iC1, &iC2,&iC3,&iC4,&fPreset,&iRS);
|
||||
if(iRet == 1)
|
||||
{
|
||||
self->lCounts[0] = iC2;
|
||||
self->lCounts[1] = iC1;
|
||||
self->lCounts[2] = iC3;
|
||||
self->lCounts[3] = iC4;
|
||||
return OKOK;
|
||||
}
|
||||
return HWFault;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static int EL737ReadValues(struct __COUNTER *self)
|
||||
{
|
||||
int iRet;
|
||||
int iC1, iC2, iC3,iC4,iRS;
|
||||
float fTime;
|
||||
EL737st *pEL737;
|
||||
|
||||
assert(self);
|
||||
pEL737 = (EL737st *)self->pData;
|
||||
assert(pEL737);
|
||||
|
||||
|
||||
iRet = EL737_GetStatus(&pEL737->pData,&iC1,&iC2,&iC3,&iC4,&fTime,&iRS);
|
||||
if(iRet != 1)
|
||||
{
|
||||
return HWFault;
|
||||
}
|
||||
self->fTime = fTime;
|
||||
|
||||
self->lCounts[0] = iC2;
|
||||
self->lCounts[1] = iC1;
|
||||
self->lCounts[2] = iC3;
|
||||
self->lCounts[3] = iC4;
|
||||
/* get extra counters for 8-fold counter boxes */
|
||||
iRet = EL737_GetStatusExtra(&pEL737->pData,&iC1,&iC2,&iC3,&iC4);
|
||||
self->lCounts[4] = iC1;
|
||||
self->lCounts[5] = iC2;
|
||||
self->lCounts[6] = iC3;
|
||||
self->lCounts[7] = iC4;
|
||||
|
||||
return OKOK;
|
||||
}
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
EL737Error2Text converts between an EL734 error code to text
|
||||
-----------------------------------------------------------------------------*/
|
||||
static void EL737Error2Text(char *pBuffer, int iErr)
|
||||
{
|
||||
switch(iErr)
|
||||
{
|
||||
case EL737__BAD_ADR:
|
||||
strcpy(pBuffer,"EL737__BAD_ADR");
|
||||
break;
|
||||
case EL737__BAD_OVFL:
|
||||
strcpy(pBuffer,"EL737__BAD_OVFL");
|
||||
break;
|
||||
case EL737__BAD_BSY:
|
||||
strcpy(pBuffer,"EL737__BAD_BSY");
|
||||
break;
|
||||
case EL737__BAD_SNTX:
|
||||
strcpy(pBuffer,"EL737__BAD_SNTX");
|
||||
break;
|
||||
case EL737__BAD_CONNECT:
|
||||
strcpy(pBuffer,"EL737__BAD_CONNECT");
|
||||
break;
|
||||
case EL737__BAD_FLUSH:
|
||||
strcpy(pBuffer,"EL737__BAD_FLUSH");
|
||||
break;
|
||||
case EL737__BAD_DEV:
|
||||
strcpy(pBuffer,"EL734__BAD_DEV");
|
||||
break;
|
||||
case EL737__BAD_ID:
|
||||
strcpy(pBuffer,"EL737__BAD_ID");
|
||||
break;
|
||||
case EL737__BAD_ILLG:
|
||||
strcpy(pBuffer,"EL737__BAD_ILLG");
|
||||
break;
|
||||
case EL737__BAD_LOC:
|
||||
strcpy(pBuffer,"EL737__BAD_LOC");
|
||||
break;
|
||||
case EL737__BAD_MALLOC:
|
||||
strcpy(pBuffer,"EL737__BAD_MALLOC");
|
||||
break;
|
||||
case EL737__BAD_NOT_BCD:
|
||||
strcpy(pBuffer,"EL737__BAD_NOT_BCD");
|
||||
break;
|
||||
case EL737__BAD_OFL:
|
||||
strcpy(pBuffer,"EL737__BAD_OFL");
|
||||
break;
|
||||
case EL737__BAD_PAR:
|
||||
strcpy(pBuffer,"EL737__BAD_PAR");
|
||||
break;
|
||||
|
||||
case EL737__BAD_RECV:
|
||||
strcpy(pBuffer,"EL737__BAD_RECV");
|
||||
break;
|
||||
case EL737__BAD_RECV_NET:
|
||||
strcpy(pBuffer,"EL737__BAD_RECV_NET");
|
||||
break;
|
||||
case EL737__BAD_RECV_PIPE:
|
||||
strcpy(pBuffer,"EL737__BAD_RECV_PIPE");
|
||||
break;
|
||||
case EL737__BAD_RECV_UNKN:
|
||||
strcpy(pBuffer,"EL737__BAD_RECV_UNKN");
|
||||
break;
|
||||
case EL737__BAD_RECVLEN:
|
||||
strcpy(pBuffer,"EL737__BAD_RECVLEN");
|
||||
break;
|
||||
case EL737__BAD_RECV1:
|
||||
strcpy(pBuffer,"EL737__BAD_RECV1");
|
||||
break;
|
||||
case EL737__BAD_RECV1_NET:
|
||||
strcpy(pBuffer,"EL737__BAD_RECV1_NET");
|
||||
break;
|
||||
case EL737__BAD_RECV1_PIPE:
|
||||
strcpy(pBuffer,"EL737__BAD_RECV1_PIPE");
|
||||
break;
|
||||
case EL737__BAD_RNG:
|
||||
strcpy(pBuffer,"EL737__BAD_RNG");
|
||||
break;
|
||||
case EL737__BAD_SEND:
|
||||
strcpy(pBuffer,"EL737__BAD_SEND");
|
||||
break;
|
||||
case EL737__BAD_SEND_PIPE:
|
||||
strcpy(pBuffer,"EL737__BAD_SEND_PIPE");
|
||||
break;
|
||||
case EL737__BAD_SEND_NET:
|
||||
strcpy(pBuffer,"EL737__BAD_SEND_NET");
|
||||
break;
|
||||
case EL737__BAD_SEND_UNKN:
|
||||
strcpy(pBuffer,"EL737__BAD_SEND_UNKN");
|
||||
break;
|
||||
case EL737__BAD_SENDLEN:
|
||||
strcpy(pBuffer,"EL737__BAD_SENDLEN");
|
||||
break;
|
||||
case EL737__BAD_SOCKET:
|
||||
strcpy(pBuffer,"EL737__BAD_SOCKET");
|
||||
break;
|
||||
case EL737__BAD_TMO:
|
||||
strcpy(pBuffer,"EL737__BAD_TMO");
|
||||
break;
|
||||
case EL737__FORCED_CLOSED:
|
||||
strcpy(pBuffer,"EL737__FORCED_CLOSED");
|
||||
break;
|
||||
case EL737__BAD_ASYNSRV:
|
||||
strcpy(pBuffer,"EL737__BAD_ASYNSRV");
|
||||
break;
|
||||
default:
|
||||
sprintf(pBuffer,"Unknown EL737 error %d", iErr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static int EL737GetError(struct __COUNTER *self, int *iCode,
|
||||
char *error, int iErrLen)
|
||||
{
|
||||
char *pErr = NULL;
|
||||
int iC1, iC2, iC3;
|
||||
char pBueffel[256];
|
||||
|
||||
if(self->iErrorCode == UNKNOWNPAR)
|
||||
{
|
||||
strncpy(error,"unknown internal parameter code",iErrLen);
|
||||
*iCode = self->iErrorCode;
|
||||
self->iErrorCode = 0;
|
||||
return 1;
|
||||
}
|
||||
else if(self->iErrorCode == BADCOUNTER)
|
||||
{
|
||||
strncpy(error,"monitor cannot be selected",iErrLen);
|
||||
*iCode = self->iErrorCode;
|
||||
self->iErrorCode = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
EL737_ErrInfo(&pErr,&iC1,&iC2, &iC3);
|
||||
EL737Error2Text(pBueffel,iC1);
|
||||
|
||||
strncpy(error,pBueffel,iErrLen);
|
||||
*iCode = iC1;
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static int EL737TryAndFixIt(struct __COUNTER *self, int iCode)
|
||||
{
|
||||
EL737st *pEL737;
|
||||
int iRet;
|
||||
char pCommand[50], pReply[50];
|
||||
|
||||
assert(self);
|
||||
pEL737 = (EL737st *)self->pData;
|
||||
assert(pEL737);
|
||||
|
||||
switch(iCode)
|
||||
{
|
||||
case EL737__BAD_ILLG:
|
||||
case EL737__BAD_ADR:
|
||||
case EL737__BAD_PAR:
|
||||
case EL737__BAD_TMO:
|
||||
case EL737__BAD_REPLY:
|
||||
case EL737__BAD_SNTX:
|
||||
case EL737__BAD_OVFL:
|
||||
return COREDO;
|
||||
break;
|
||||
case EL737__BAD_BSY:
|
||||
strcpy(pCommand,"S \r");
|
||||
iRet = EL737_SendCmnd(&pEL737->pData,pCommand,pReply,49);
|
||||
if(iRet < 0)
|
||||
{
|
||||
return COTERM;
|
||||
}
|
||||
else
|
||||
{
|
||||
return COREDO;
|
||||
}
|
||||
break;
|
||||
case EL737__BAD_LOC:
|
||||
strcpy(pCommand,"rmt 1\r");
|
||||
iRet = EL737_SendCmnd(&pEL737->pData,pCommand,pReply,49);
|
||||
if(iRet < 0)
|
||||
{
|
||||
return COTERM;
|
||||
}
|
||||
strcpy(pCommand,"echo 2\r");
|
||||
iRet = EL737_SendCmnd(&pEL737->pData,pCommand,pReply,49);
|
||||
if(iRet < 0)
|
||||
{
|
||||
return COTERM;
|
||||
}
|
||||
strcpy(pCommand,"ra\r");
|
||||
iRet = EL737_SendCmnd(&pEL737->pData,pCommand,pReply,49);
|
||||
if(iRet < 0)
|
||||
{
|
||||
return COTERM;
|
||||
}
|
||||
return COREDO;
|
||||
break;
|
||||
case EL737__BAD_DEV:
|
||||
case EL737__BAD_ID:
|
||||
case EL737__BAD_NOT_BCD:
|
||||
case UNKNOWNPAR:
|
||||
case BADCOUNTER:
|
||||
return COTERM;
|
||||
break;
|
||||
case EL737__FORCED_CLOSED:
|
||||
iRet = EL737_Open(&pEL737->pData,pEL737->host, pEL737->iPort,
|
||||
pEL737->iChannel);
|
||||
if(iRet == 1)
|
||||
{
|
||||
return COREDO;
|
||||
}
|
||||
else
|
||||
{
|
||||
return COTERM;
|
||||
}
|
||||
break;
|
||||
case EL737__BAD_OFL:
|
||||
EL737_Close(&pEL737->pData,0);
|
||||
iRet = EL737_Open(&pEL737->pData,pEL737->host, pEL737->iPort,
|
||||
pEL737->iChannel);
|
||||
if(iRet == 1)
|
||||
{
|
||||
return COREDO;
|
||||
}
|
||||
else
|
||||
{
|
||||
return COTERM;
|
||||
}
|
||||
break;
|
||||
/* case EL737__BAD_ASYNSRV:
|
||||
EL737_Close(&pEL737->pData,1);
|
||||
return COREDO;
|
||||
*/ default:
|
||||
/* try to reopen connection */
|
||||
|
||||
EL737_Close(&pEL737->pData,1);
|
||||
iRet = EL737_Open(&pEL737->pData,pEL737->host, pEL737->iPort,
|
||||
pEL737->iChannel);
|
||||
if(iRet == 1)
|
||||
{
|
||||
return COREDO;
|
||||
}
|
||||
else
|
||||
{
|
||||
return COTERM;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return COTERM;
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
static int EL737Set(struct __COUNTER *self, char *name, int iCter,
|
||||
float fVal)
|
||||
{
|
||||
int iRet;
|
||||
EL737st *pEL737;
|
||||
char pCommand[80],pReply[80];
|
||||
|
||||
assert(self);
|
||||
pEL737 = (EL737st *)self->pData;
|
||||
assert(pEL737);
|
||||
|
||||
if(strcmp(name,"threshold") == 0)
|
||||
{
|
||||
sprintf(pCommand,"DL %1.1d %f\r",iCter,fVal);
|
||||
iRet = EL737_SendCmnd(&pEL737->pData,pCommand,pReply,79);
|
||||
if(iRet == 1)
|
||||
{
|
||||
if(pCommand[0] == '?')
|
||||
{
|
||||
self->iErrorCode = BADCOUNTER;
|
||||
return HWFault;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return HWFault;
|
||||
}
|
||||
sprintf(pCommand,"DR %1.1d \r",iCter);
|
||||
iRet = EL737_SendCmnd(&pEL737->pData,pCommand,pReply,79);
|
||||
if(iRet == 1)
|
||||
{
|
||||
if(pCommand[0] == '?')
|
||||
{
|
||||
self->iErrorCode = BADCOUNTER;
|
||||
return HWFault;
|
||||
}
|
||||
return OKOK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HWFault;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
self->iErrorCode = UNKNOWNPAR;
|
||||
return HWFault;
|
||||
}
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
static int EL737Get(struct __COUNTER *self, char *name, int iCter,
|
||||
float *fVal)
|
||||
{
|
||||
int iRet;
|
||||
EL737st *pEL737;
|
||||
char pCommand[80],pReply[80];
|
||||
|
||||
assert(self);
|
||||
pEL737 = (EL737st *)self->pData;
|
||||
assert(pEL737);
|
||||
|
||||
if(strcmp(name,"threshold") == 0)
|
||||
{
|
||||
sprintf(pCommand,"DL %1.1d\r",iCter);
|
||||
iRet = EL737_SendCmnd(&pEL737->pData,pCommand,pReply,79);
|
||||
if(iRet == 1)
|
||||
{
|
||||
if(pReply[0] == '?')
|
||||
{
|
||||
self->iErrorCode = BADCOUNTER;
|
||||
return HWFault;
|
||||
}
|
||||
sscanf(pReply,"%f",fVal);
|
||||
return OKOK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HWFault;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
self->iErrorCode = UNKNOWNPAR;
|
||||
return HWFault;
|
||||
}
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
static int EL737Send(struct __COUNTER *self, char *pText, char *pReply,
|
||||
int iReplyLen)
|
||||
{
|
||||
EL737st *pEL737;
|
||||
char pBuffer[256];
|
||||
|
||||
assert(self);
|
||||
pEL737 = (EL737st *)self->pData;
|
||||
assert(pEL737);
|
||||
|
||||
/* ensure a \r at the end of the text */
|
||||
if(strlen(pText) > 254)
|
||||
{
|
||||
strncpy(pReply,"Command to long",iReplyLen);
|
||||
return 1;
|
||||
}
|
||||
strcpy(pBuffer,pText);
|
||||
if(strchr(pBuffer,(int)'\r') == NULL)
|
||||
{
|
||||
strcat(pBuffer,"\r");
|
||||
}
|
||||
|
||||
return EL737_SendCmnd(&pEL737->pData,pBuffer,pReply,iReplyLen);
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
pCounterDriver NewEL737Counter(char *name, char *host, int iPort, int iChannel)
|
||||
{
|
||||
pCounterDriver pRes = NULL;
|
||||
EL737st *pData = NULL;
|
||||
int iRet;
|
||||
int iC1, iC2, iC3;
|
||||
char *pErr;
|
||||
char pBueffel[132];
|
||||
|
||||
pRes = CreateCounterDriver(name, "EL737");
|
||||
if(!pRes)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* open connection to counter */
|
||||
pData = (EL737st *)malloc(sizeof(EL737st));
|
||||
if(!pData)
|
||||
{
|
||||
DeleteCounterDriver(pRes);
|
||||
return NULL;
|
||||
}
|
||||
pData->host = strdup(host);
|
||||
pData->iPort = iPort;
|
||||
pData->iChannel = iChannel;
|
||||
pData->pData = NULL;
|
||||
iRet = EL737_Open(&(pData->pData), host,iPort,iChannel);
|
||||
if(iRet != 1)
|
||||
{
|
||||
EL737_ErrInfo(&pErr,&iC1,&iC2, &iC3);
|
||||
DeleteCounterDriver(pRes);
|
||||
if(pData->host)
|
||||
{
|
||||
free(pData->host);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
pRes->pData = (void *)pData;
|
||||
|
||||
/* assign functions */
|
||||
pRes->GetStatus = EL737GetStatus;
|
||||
pRes->Start = EL737Start;
|
||||
pRes->Halt = EL737Halt;
|
||||
pRes->ReadValues = EL737ReadValues;
|
||||
pRes->GetError = EL737GetError;
|
||||
pRes->TryAndFixIt = EL737TryAndFixIt;
|
||||
pRes->Pause = EL737Pause;
|
||||
pRes->Continue = EL737Continue;
|
||||
pRes->Set = EL737Set;
|
||||
pRes->Get = EL737Get;
|
||||
pRes->Send = EL737Send;
|
||||
pRes->iNoOfMonitors = 7;
|
||||
pRes->fTime = 0.;
|
||||
|
||||
return pRes;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void KillEL737Counter(pCounterDriver self)
|
||||
{
|
||||
EL737st *pEL737 = NULL;
|
||||
|
||||
assert(self);
|
||||
pEL737 = (EL737st *)self->pData;
|
||||
assert(pEL737);
|
||||
|
||||
EL737_Close(&pEL737->pData,0);
|
||||
if(pEL737->host)
|
||||
{
|
||||
free(pEL737->host);
|
||||
}
|
||||
DeleteCounterDriver(self);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user