From 49123234d0d7eab7e7584ce4f5d897bcb21a5fe5 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Mon, 26 Nov 2012 15:10:25 +1100 Subject: [PATCH] merge work in progress --- motor.c | 33 +++++++++++++++++++++++---------- motor.h | 5 +++++ site_ansto/Makefile | 1 - site_ansto/hardsup/modbustcp.c | 4 +++- site_ansto/make_gen_variables | 10 +++++----- site_ansto/site_ansto.c | 8 +------- 6 files changed, 37 insertions(+), 24 deletions(-) diff --git a/motor.c b/motor.c index 67ddd2af..6e8f43b5 100644 --- a/motor.c +++ b/motor.c @@ -81,6 +81,7 @@ #define IGNOREFAULT 10 #define MOVECOUNT 11 +extern double DoubleTime(void); /*-------------------------------------------------------------------------*/ static void *MotorGetInterface(void *pData, int iID) @@ -344,8 +345,9 @@ static int checkPosition(pMotor self, SConnection * pCon) SCWrite(pCon, pBueffel, eWarning); return HWFault; } - snprintf(pBueffel, 131, "WARNING: %s off position by %f", - self->name, absf(fHard - self->fTarget)); + snprintf(pBueffel, 131, "WARNING: %s off position by %f%s", + self->name, absf(fHard - self->fTarget), + self->fTarget > fHard ? "-" : ""); SCWrite(pCon, pBueffel, eLog); status = statusRunTo(self, pCon); return status; @@ -354,16 +356,19 @@ static int checkPosition(pMotor self, SConnection * pCon) } /*--------------------------------------------------------------------*/ -static void finishDriving(pMotor self, SConnection * pCon) +void finishDriving(pMotor self, SConnection * pCon) { MotCallback sCall; MotorGetSoftPosition(self, pCon, &sCall.fVal); sCall.pName = self->name; self->fPosition = sCall.fVal; self->fPosition = sCall.fVal; - InvokeCallBack(self->pCall, MOTDRIVE, &sCall); /* send also very last position */ - InvokeCallBack(self->pCall, MOTEND, &sCall); - tracePar(self->name,"%f",sCall.fVal); + if (self->moving) { + InvokeCallBack(self->pCall, MOTDRIVE, &sCall); /* send also very last position */ + InvokeCallBack(self->pCall, MOTEND, &sCall); + tracePar(self->name,"%f",sCall.fVal); + } + self->moving = 0; self->running = 0; } @@ -466,13 +471,15 @@ static void handleMoveCallback(pMotor self, SConnection * pCon) { MotCallback sCall; - self->posCount++; - if (self->posCount >= ObVal(self->ParArray, MOVECOUNT)) { + double current_time, skip_time; + current_time = DoubleTime(); + skip_time = 0.001 * ObVal(self->ParArray,MOVECOUNT); + if(self->last_report_time + skip_time <= current_time) { MotorGetSoftPosition(self, pCon, &sCall.fVal); sCall.pName = self->name; InvokeCallBack(self->pCall, MOTDRIVE, &sCall); tracePar(self->name,"%f",sCall.fVal); - self->posCount = 0; + self->last_report_time = current_time; } } @@ -738,8 +745,10 @@ static long MotorRunImpl(void *sulf, SConnection * pCon, float fNew) self->posFaultCount = 0; self->retryCount = 0; self->stopped = 0; + self->moving = 1; self->fTarget = fHard; InvokeCallBack(self->pCall, HDBVAL, self); + self->last_report_time = 0.0; self->posCount = 0; iRet = self->pDriver->RunTo(self->pDriver, fHard); if (iRet != OKOK) { /* try three times to fix it */ @@ -1066,7 +1075,10 @@ int MotorCreate(SConnection * pCon, SicsInterp * pSics, void *pData, } /* create the interpreter command */ - iRet = AddCommand(pSics, argv[1], MotorAction, MotorKill, pNew); + if (pNew->pActionRoutine) + iRet = AddCommand(pSics, argv[1], pNew->pActionRoutine, MotorKill, pNew); + else + iRet = AddCommand(pSics, argv[1], MotorAction, MotorKill, pNew); if (!iRet) { snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: duplicate command %s not created", argv[1]); SCWrite(pCon, pBueffel, eError); @@ -1287,6 +1299,7 @@ int MotorAction(SConnection * pCon, SicsInterp * pSics, void *pData, } pMoti->lastValue = fValue; + RemoveCallbackCon(self->pCall, pCon); lID = RegisterCallback(self->pCall, MOTDRIVE, InterestCallback, pMoti, KillInfo); DeleteTokenList(pList); diff --git a/motor.h b/motor.h index f06bc2c6..e109326c 100644 --- a/motor.h +++ b/motor.h @@ -40,6 +40,9 @@ typedef struct __Motor { int stopReported; int errorCount; int running; + int moving; + double last_report_time; + ObjectFunc pActionRoutine; ObPar *ParArray; void *pPrivate; void (*KillPrivate) (void *); @@ -78,4 +81,6 @@ int MotorAction(SConnection * pCon, SicsInterp * pSics, void *pData, int argc, char *argv[]); pMotor FindMotor(SicsInterp * pSics, char *name); +/* Made available to oscillate.c to generate MOTEND event. Ferdi */ +void finishDriving(pMotor self, SConnection *pCon); #endif diff --git a/site_ansto/Makefile b/site_ansto/Makefile index 536146e0..856be155 100644 --- a/site_ansto/Makefile +++ b/site_ansto/Makefile @@ -150,7 +150,6 @@ OBJ= site_ansto.o anstoutil.o\ fsm.o \ counterdriv.o \ safetyplc.o \ - ../psi/tcpdornier.o \ anstohttp.o \ hmcontrol_ansto.o\ lssmonitor.o \ diff --git a/site_ansto/hardsup/modbustcp.c b/site_ansto/hardsup/modbustcp.c index 5e5c56b1..d1c092b7 100644 --- a/site_ansto/hardsup/modbustcp.c +++ b/site_ansto/hardsup/modbustcp.c @@ -21,7 +21,9 @@ Paul Barron, January 2008 #include #include #include -#include +#include "obdes.h" +#include "conman.h" +#include "rs232controller.h" #include "modbustcp.h" /*-------------------------------------------------------------------------*/ diff --git a/site_ansto/make_gen_variables b/site_ansto/make_gen_variables index 561bea89..48dbf757 100644 --- a/site_ansto/make_gen_variables +++ b/site_ansto/make_gen_variables @@ -1,17 +1,17 @@ -# vim: ft=make ts=4 sw=4 noet ciident +# vim: ft=make ts=4 sw=4 noet cindent COBJ = Sclient.o network.o ifile.o intcli.o $(FORTIFYOBJ) SOBJ = access.o alias.o anticollider.o ascon.o asyncprotocol.o asyncqueue.o callback.o \ cell.o chadapter.o choco.o circular.o commandlog.o cone.o confvirtualmot.o \ conman.o costa.o danu.o definealias.o devexec.o devser.o diffscan.o d_mod.o \ drive.o d_sign.o dynstring.o emon.o errormsg.o evcontroller.o evdriver.o \ event.o exebuf.o exeman.o fitcenter.o fomerge.o $(FORTIFYOBJ) fourlib.o \ - fourtable.o fupa.o genericcontroller.o gpibcontroller.o help.o hipadaba.o \ - histdriv.o histmem.o histregress.o histsim.o hklmot.o hkl.o hklscan.o \ + fourtable.o fupa.o gpibcontroller.o help.o hipadaba.o \ + histdriv.o histmem.o histregress.o histsim.o hklmot.o hkl.o \ hmcontrol.o hmdata.o hmslave.o ifile.o initializer.o integrate.o interface.o \ intserv.o lin2ang.o lld_blob.o lld.o logger.o logreader.o logsetup.o lomax.o \ - macro.o maximize.o mccontrol.o mcreader.o mcstascounter.o mcstashm.o mesure.o \ + macro.o maximize.o mccontrol.o mcreader.o mcstascounter.o mcstashm.o \ moregress.o motorlist.o motreglist.o motreg.o multicounter.o mumoconf.o mumo.o \ - napi5.o napi.o network.o $(NIOBJ) nread.o nserver.o nwatch.o nxcopy.o nxdata.o \ + napi5.o napi.o network.o $(NIOBJ) nread.o nserver.o nwatch.o nxcopy.o \ nxdataset.o nxdict.o nxinterhelper.o nxinter_wrap.o nxio.o nxscript.o nxstack.o \ nxupdate.o nxutil.o nxxml.o o2t.o obdes.o obpar.o ofac.o optimise.o oscillate.o \ passwd.o perfmon.o polldriv.o protocol.o proxy.o regresscter.o remob.o \ diff --git a/site_ansto/site_ansto.c b/site_ansto/site_ansto.c index 22c43b9c..6f0a63ca 100644 --- a/site_ansto/site_ansto.c +++ b/site_ansto/site_ansto.c @@ -50,11 +50,6 @@ /*@observer@*//*@null@*/ pCounterDriver CreateMonCounter(/*@observer@*/SConnection *pCon, /*@observer@*/char *name, char *params); -/* - from tcpdornier.c -*/ -extern int VelSelTcpFactory(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char *argv[]); -extern pCodri MakeTcpDoChoDriver(char *tclArray, SConnection *pCon); extern void AddGalilProtocoll(); extern void AddModbusProtocoll(); extern void AddOxfordProtocoll(); @@ -139,7 +134,6 @@ static void AddCommands(SicsInterp *pInter) ORHVPSInitProtocol(pInter); LS340InitProtocol(pInter); AddCommand(pInter,"InstallProtocolHandler", InstallProtocol,NULL,NULL); - AddCommand(pInter,"MakeTCPSelector",VelSelTcpFactory,NULL,NULL); AddCommand(pInter,"hostnam",hostNamCmd,NULL,NULL); AddCommand(pInter,"portnum",portNumCmd,NULL,NULL); AddCommand(pInter,"abortbatch",AbortBatch,NULL,NULL); @@ -237,7 +231,7 @@ static pCodri CreateController(SConnection *pCon,int argc, char *argv[]){ eError); return NULL; } - return MakeTcpDoChoDriver(argv[1], pCon); + return NULL; } return pNew; }