From 3a5e8ed7e18728ded8b087443a41e33c2066e0a6 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Tue, 27 Mar 2007 13:16:08 +1000 Subject: [PATCH] Add ActionRoutine hook to motor object r1728 | dcl | 2007-03-27 13:16:08 +1000 (Tue, 27 Mar 2007) | 2 lines --- motor.c | 8 +++++-- motor.h | 1 + site_ansto/motor_dmc2280.c | 44 ++++++++++++++++++++++++++++++++++++++ site_ansto/motor_dmc2280.h | 4 +++- site_ansto/site_ansto.c | 2 ++ 5 files changed, 56 insertions(+), 3 deletions(-) diff --git a/motor.c b/motor.c index bc27d16b..fd060d40 100644 --- a/motor.c +++ b/motor.c @@ -407,7 +407,8 @@ static void handleMoveCallback(pMotor self, SConnection *pCon) { return NULL; } - + memset(pM, 0, sizeof(Motor)); /* DFC init all to zero */ + pM->pActionRoutine = NULL; /* DFC belt and braces */ /* create and initialize parameters */ pM->ParArray = ObParCreate(MOTOBPARLENGTH); @@ -1056,7 +1057,10 @@ extern MotorDriver *MakePiPiezo(Tcl_Interp *pTcl, char *pArray); } /* 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) { sprintf(pBueffel,"ERROR: duplicate command %s not created",argv[1]); diff --git a/motor.h b/motor.h index 277afb1c..e782c4f1 100644 --- a/motor.h +++ b/motor.h @@ -20,6 +20,7 @@ ObPar *ParArray; pIDrivable pDrivInt; pICallBack pCall; + ObjectFunc pActionRoutine; char *drivername; char *name; MotorDriver *pDriver; diff --git a/site_ansto/motor_dmc2280.c b/site_ansto/motor_dmc2280.c index dc6fd667..63de86ba 100644 --- a/site_ansto/motor_dmc2280.c +++ b/site_ansto/motor_dmc2280.c @@ -72,6 +72,7 @@ typedef struct __MoDriv { int errorCode; char *errorMsg; /**< Points to memory for error messages */ char units[256]; /**< physical units for axis */ + char long_name[256]; /**< long name of motor */ float speed; /**< physical units per second */ float maxSpeed; /**< physical units per second */ float accel; /**< physical units per second^2 */ @@ -159,6 +160,7 @@ int DMC2280MotionControl = 1; /* defaults to enabled */ #define MOTOFFDELAY "motoffdelay" #define AIRPADS "airpads" #define SETTLE "settle" +#define LONG_NAME "long_name" #define BLOCKAGE_CHECK_INTERVAL "blockage_check_interval" static int DMC2280Halt(void *pData); @@ -1701,6 +1703,8 @@ static int DMC2280SetPar(void *pData, SConnection *pCon, static void DMC2280List(void *self, char *name, SConnection *pCon){ char buffer[BUFFLEN]; + snprintf(buffer, BUFFLEN, "%s.long_name = %s\n", name, ((pDMC2280Driv)self)->long_name); + SCWrite(pCon, buffer, eStatus); snprintf(buffer, BUFFLEN, "%s.axis = %c\n", name, ((pDMC2280Driv)self)->axisLabel); SCWrite(pCon, buffer, eStatus); snprintf(buffer, BUFFLEN, "%s.home = %f\n", name, ((pDMC2280Driv)self)->home); @@ -1882,6 +1886,10 @@ MotorDriver *CreateDMC2280(SConnection *pCon, char *motor, char *params) { pNew->blockage_fail = 0; /* PARAMETERS: Fetch parameter values */ + if ((pPtr=getParam(pCon, interp, params, LONG_NAME, _OPTIONAL)) != NULL) { + strncpy(pNew->long_name, pPtr, sizeof(pNew->long_name)); + pNew->long_name[sizeof(pNew->long_name) - 1] = '\0'; + } if ((pPtr=getParam(pCon, interp, params,HARDLOWERLIM,_REQUIRED)) == NULL) { KillDMC2280(pNew); return NULL; @@ -1989,3 +1997,39 @@ MotorDriver *CreateDMC2280(SConnection *pCon, char *motor, char *params) { /* TODO Initialise current position and target to get a sensible initial list output */ return (MotorDriver *)pNew; } +int DMC2280Action(SConnection *pCon, SicsInterp *pSics, void *pData, + int argc, char *argv[]) +{ + pMotor pm = (pMotor) pData; + pDMC2280Driv self = (pDMC2280Driv) pm->pDriver; + + if (argc > 1) { + if (strcasecmp("units", argv[1]) == 0) { + if (argc > 2) { + strncpy(self->units, argv[2], sizeof(self->units)); + self->units[sizeof(self->units) - 1] = '\0'; + } + else { + char line[132]; + snprintf(line, 132, "%s.units = %s", self->name, self->units); + SCWrite(pCon, line, eValue); + } + return 1; + } + if (strcasecmp("long_name", argv[1]) == 0) { + if (argc > 2) { + strncpy(self->long_name, argv[2], sizeof(self->long_name)); + self->long_name[sizeof(self->long_name) - 1] = '\0'; + } + else { + char line[132]; + snprintf(line, 132, "%s.long_name = %s", self->name, self->long_name); + SCWrite(pCon, line, eValue); + } + return 1; + } + if (strcasecmp("list", argv[1]) == 0) { + } + } + return MotorAction(pCon, pSics, pData, argc, argv); +} diff --git a/site_ansto/motor_dmc2280.h b/site_ansto/motor_dmc2280.h index d4286fa0..3aa5a817 100644 --- a/site_ansto/motor_dmc2280.h +++ b/site_ansto/motor_dmc2280.h @@ -11,7 +11,9 @@ #ifdef __cplusplus extern "C" { #endif -MotorDriver *CreateDMC2280(SConnection *pCon, int argc, char *argv[]); +MotorDriver *CreateDMC2280(SConnection *pCon, char* motor, char *params); +int DMC2280Action(SConnection *pCon, SicsInterp *pSics, void *pData, + int argc, char *argv[]); #ifdef __cplusplus } #endif diff --git a/site_ansto/site_ansto.c b/site_ansto/site_ansto.c index 4851f05f..1568fe4c 100644 --- a/site_ansto/site_ansto.c +++ b/site_ansto/site_ansto.c @@ -20,6 +20,7 @@ #include /* site-specific driver header files */ +#include "motor_dmc2280.h" #include "motor_asim.h" #include "itc4.h" /* Added code for new LH45 and Lakeshore 340 drivers */ @@ -90,6 +91,7 @@ static void RemoveCommands(SicsInterp *pSics){ SCWrite(pCon,pBueffel,eError); return NULL; } + pNew->pActionRoutine = DMC2280Action; } if(strcmp(argv[1],"asim") == 0) { pDriver = (MotorDriver *)CreateASIM(pCon,argc-2,&argv[2]);