Cleaned up ANSTO code to merge with sinqdev.sics
This is our new RELEASE-4_0 branch which was taken from ansto/93d9a7c Conflicts: .gitignore SICSmain.c asynnet.c confvirtualmot.c counter.c devexec.c drive.c event.h exebuf.c exeman.c histmem.c interface.h motor.c motorlist.c motorsec.c multicounter.c napi.c napi.h napi4.c network.c nwatch.c nxscript.c nxxml.c nxxml.h ofac.c reflist.c scan.c sicshipadaba.c sicsobj.c site_ansto/docs/Copyright.txt site_ansto/instrument/lyrebird/config/tasmad/sicscommon/nxsupport.tcl site_ansto/instrument/lyrebird/config/tasmad/taspub_sics/tasscript.tcl statusfile.c tasdrive.c tasub.c tasub.h tasublib.c tasublib.h
This commit is contained in:
233
interface.c
233
interface.c
@@ -1,4 +1,4 @@
|
||||
/*--------------------------------------------------------------------------
|
||||
/*--------------------------------------------------------------------------
|
||||
I N T E R F A C E
|
||||
|
||||
|
||||
@@ -12,6 +12,11 @@
|
||||
Paul Scherrer Institut
|
||||
CH-5423 Villigen-PSI
|
||||
|
||||
Extended over time with utility functions
|
||||
|
||||
Added Drivable and Countable task functions
|
||||
|
||||
Mark Koennecke, February 2013
|
||||
|
||||
The authors hereby grant permission to use, copy, modify, distribute,
|
||||
and license this software and its documentation for any purpose, provided
|
||||
@@ -42,6 +47,7 @@
|
||||
#include "fortify.h"
|
||||
#include "sics.h"
|
||||
#include "motor.h"
|
||||
#include <status.h>
|
||||
/*=========================================================================
|
||||
Empty driveable interface functions
|
||||
==========================================================================*/
|
||||
@@ -168,7 +174,118 @@ int GetDrivablePosition(void *pObject, SConnection * pCon, float *fPos)
|
||||
*fPos = value;
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
int id;
|
||||
void *obj;
|
||||
pIDrivable pDriv;
|
||||
SConnection *pCon;
|
||||
char *name;
|
||||
}DriveTaskData;
|
||||
/*-------------------------------------------------------------------------*/
|
||||
static void KillDriveTaskData(void *data)
|
||||
{
|
||||
DriveTaskData *taskData = (DriveTaskData *)data;
|
||||
|
||||
if(taskData == NULL){
|
||||
return;
|
||||
}
|
||||
if(taskData->name != NULL){
|
||||
free(taskData->name);
|
||||
}
|
||||
if(taskData->pCon != NULL){
|
||||
SCDeleteConnection(taskData->pCon);
|
||||
}
|
||||
free(taskData);
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
static void DriveTaskSignal(void *data, int iSignal, void *pSigData)
|
||||
{
|
||||
DriveTaskData *taskData = (DriveTaskData *)data;
|
||||
int *interrupt;
|
||||
|
||||
assert(taskData != NULL);
|
||||
|
||||
if(iSignal == SICSINT){
|
||||
interrupt = (int *)pSigData;
|
||||
if(*interrupt != eContinue){
|
||||
SCPrintf(taskData->pCon,eLogError,"ERROR: Interrupting %s", taskData->name);
|
||||
taskData->pDriv->Halt(taskData->obj);
|
||||
SCSetInterrupt(taskData->pCon,*interrupt);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static int DriveTaskFunc(void *data)
|
||||
{
|
||||
DriveTaskData *taskData = (DriveTaskData *)data;
|
||||
int status;
|
||||
|
||||
assert(taskData != NULL);
|
||||
|
||||
|
||||
status = taskData->pDriv->CheckStatus(taskData->obj,taskData->pCon);
|
||||
if(status == HWBusy){
|
||||
return 1;
|
||||
}
|
||||
if(status == HWFault){
|
||||
taskData->pDriv->iErrorCount++;
|
||||
}
|
||||
if(status == HWFault || status == HWPosFault){
|
||||
SetDevexecStatus(pServ->pExecutor,DEVERROR);
|
||||
}
|
||||
DevexecLog("STOP",taskData->name);
|
||||
if(status == HWIdle || status == OKOK){
|
||||
ExeInterest(pServ->pExecutor,taskData->name, "finished");
|
||||
|
||||
} else {
|
||||
ExeInterest(pServ->pExecutor,taskData->name, "finished with problem");
|
||||
}
|
||||
traceSys("drive","DriveTask %s finished with state %d", taskData->name,status);
|
||||
return 0;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
long StartDriveTask(void *obj, SConnection *pCon, char *name, float fTarget)
|
||||
{
|
||||
pIDrivable pDriv = NULL;
|
||||
char error[132], buffer[132];
|
||||
DriveTaskData *taskData = NULL;
|
||||
|
||||
pDriv = GetDrivableInterface(obj);
|
||||
if(pDriv == NULL){
|
||||
SCPrintf(pCon,eError,"ERROR: %s is not drivable", name);
|
||||
return -1;
|
||||
}
|
||||
if(pDriv->CheckLimits(obj,fTarget,error,sizeof(error)) != OKOK){
|
||||
SCPrintf(pCon,eError,"ERROR: %s cannot reach %f, reason %s", name,
|
||||
fTarget, error);
|
||||
return -1;
|
||||
}
|
||||
taskData = calloc(1,sizeof(DriveTaskData));
|
||||
if(taskData == NULL){
|
||||
SCPrintf(pCon,eError,"ERROR: out of memory starting %s", name);
|
||||
return -1;
|
||||
}
|
||||
if(pDriv->SetValue(obj,pCon,fTarget) != OKOK){
|
||||
return -1;
|
||||
}
|
||||
ExeInterest(pServ->pExecutor,name,"started");
|
||||
DevexecLog("START",name);
|
||||
InvokeNewTarget(pServ->pExecutor,name,fTarget);
|
||||
|
||||
taskData->id = DRIVEID;
|
||||
taskData->obj = obj;
|
||||
taskData->pDriv = pDriv;
|
||||
taskData->pCon = SCCopyConnection(pCon);
|
||||
taskData->name = strdup(name);
|
||||
|
||||
return TaskRegisterN(pServ->pTasker,
|
||||
name,
|
||||
DriveTaskFunc,
|
||||
DriveTaskSignal,
|
||||
KillDriveTaskData,
|
||||
taskData,0);
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
pICountable GetCountableInterface(void *pObject)
|
||||
{
|
||||
@@ -201,6 +318,120 @@ int isRunning(pICountable self)
|
||||
{
|
||||
return self->running;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
int id;
|
||||
void *obj;
|
||||
pICountable pCount;
|
||||
SConnection *pCon;
|
||||
char *name;
|
||||
}CountTaskData;
|
||||
/*-------------------------------------------------------------------------*/
|
||||
static void KillCountTaskData(void *data)
|
||||
{
|
||||
CountTaskData *taskData = (CountTaskData *)data;
|
||||
|
||||
if(taskData == NULL){
|
||||
return;
|
||||
}
|
||||
if(taskData->name != NULL){
|
||||
free(taskData->name);
|
||||
}
|
||||
if(taskData->pCon != NULL){
|
||||
SCDeleteConnection(taskData->pCon);
|
||||
}
|
||||
free(taskData);
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
static void CountTaskSignal(void *data, int iSignal, void *pSigData)
|
||||
{
|
||||
CountTaskData *taskData = (CountTaskData *)data;
|
||||
int *interrupt;
|
||||
|
||||
assert(taskData != NULL);
|
||||
|
||||
if(iSignal == SICSINT){
|
||||
interrupt = (int *)pSigData;
|
||||
if(*interrupt != eContinue){
|
||||
SCPrintf(taskData->pCon,eLogError,"ERROR: Interrupting %s", taskData->name);
|
||||
taskData->pCount->Halt(taskData->obj);
|
||||
SCSetInterrupt(taskData->pCon,*interrupt);
|
||||
}
|
||||
} else if(iSignal == IPAUSE){
|
||||
taskData->pCount->Pause(taskData->obj,taskData->pCon);
|
||||
} else if(iSignal == CONTINUE){
|
||||
taskData->pCount->Continue(taskData->obj,taskData->pCon);
|
||||
}
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static int CountTaskFunc(void *data)
|
||||
{
|
||||
CountTaskData *taskData = (CountTaskData *)data;
|
||||
int status;
|
||||
|
||||
assert(taskData != NULL);
|
||||
|
||||
status = taskData->pCount->CheckCountStatus(taskData->obj,taskData->pCon);
|
||||
if(status == HWBusy) {
|
||||
return 1;
|
||||
} else if(status == HWNoBeam){
|
||||
return 1;
|
||||
} else if(status == HWPause){
|
||||
return 1;
|
||||
}
|
||||
|
||||
taskData->pCount->TransferData(taskData->obj, taskData->pCon);
|
||||
|
||||
if(status == HWFault){
|
||||
SetDevexecStatus(pServ->pExecutor,DEVERROR);
|
||||
}
|
||||
|
||||
DevexecLog("STOP",taskData->name);
|
||||
if(status == HWIdle || status == OKOK){
|
||||
ExeInterest(pServ->pExecutor,taskData->name, "finished");
|
||||
} else {
|
||||
ExeInterest(pServ->pExecutor,taskData->name, "finished with problem");
|
||||
}
|
||||
traceSys("count","CountTask %s finished with state %d", taskData->name,status);
|
||||
return 0;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
long StartCountTask(void *obj, SConnection *pCon, char *name)
|
||||
{
|
||||
pICountable pCount = NULL;
|
||||
char error[132], buffer[132];
|
||||
CountTaskData *taskData = NULL;
|
||||
|
||||
pCount = FindInterface(obj,COUNTID);
|
||||
if(pCount == NULL){
|
||||
SCPrintf(pCon,eError,"ERROR: %s is not countable", name);
|
||||
return 1;
|
||||
}
|
||||
taskData = calloc(1,sizeof(CountTaskData));
|
||||
if(taskData == NULL){
|
||||
SCPrintf(pCon,eError,"ERROR: out of memory starting %s", name);
|
||||
return -1;
|
||||
}
|
||||
if(pCount->StartCount(obj,pCon) != OKOK){
|
||||
pCount->running = 0;
|
||||
return -1;
|
||||
}
|
||||
ExeInterest(pServ->pExecutor,name,"started");
|
||||
DevexecLog("START",name);
|
||||
|
||||
taskData->id = COUNTID;
|
||||
taskData->obj = obj;
|
||||
taskData->pCount = pCount;
|
||||
taskData->pCon = SCCopyConnection(pCon);
|
||||
taskData->name = strdup(name);
|
||||
|
||||
return TaskRegisterN(pServ->pTasker,
|
||||
name,
|
||||
CountTaskFunc,
|
||||
CountTaskSignal,
|
||||
KillCountTaskData,
|
||||
taskData,0);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
pICallBack GetCallbackInterface(void *pObject)
|
||||
|
||||
Reference in New Issue
Block a user