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:
248
counter.c
248
counter.c
@@ -61,7 +61,7 @@ typedef struct {
|
||||
char *pName;
|
||||
} MonEvent, *pMonEvent;
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
static int Halt(void *pData)
|
||||
{
|
||||
pCounter self = NULL;
|
||||
@@ -71,7 +71,19 @@ static int Halt(void *pData)
|
||||
|
||||
return self->pDriv->Halt(self->pDriv);
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
static void SetCounterError(void *pData, char *text)
|
||||
{
|
||||
pCounter self = NULL;
|
||||
|
||||
assert(pData);
|
||||
self = (pCounter) pData;
|
||||
|
||||
if(self->error != NULL){
|
||||
free(self->error);
|
||||
}
|
||||
self->error = strdup(text);
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static void SetCountParameters(void *pData, float fPreset,
|
||||
CounterMode eMode)
|
||||
@@ -103,6 +115,7 @@ static int StartCount(void *pData, SConnection * pCon)
|
||||
return 0;
|
||||
}
|
||||
|
||||
SetCounterError(pData,"None");
|
||||
/* try at least three times to do it */
|
||||
for (i = 0; i < 3; i++) {
|
||||
iRet = self->pDriv->Start(self->pDriv);
|
||||
@@ -122,6 +135,7 @@ static int StartCount(void *pData, SConnection * pCon)
|
||||
eError);
|
||||
SCSetInterrupt(pCon, eAbortBatch);
|
||||
ReleaseCountLock(self->pCountInt);
|
||||
SetCounterError(pData,pError);
|
||||
return HWFault;
|
||||
}
|
||||
}
|
||||
@@ -205,95 +219,6 @@ static int ContinueCount(void *pData, SConnection * pCon)
|
||||
SCSetInterrupt(pCon, eAbortBatch);
|
||||
return HWFault;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static int CheckCountStatus(void *pData, SConnection * pCon)
|
||||
{
|
||||
pCounter self = NULL;
|
||||
int i, iRet;
|
||||
int eCt;
|
||||
char pError[80], pBueffel[132];
|
||||
int iErr;
|
||||
float fControl, rate;
|
||||
MonEvent sMon;
|
||||
|
||||
self = (pCounter) pData;
|
||||
assert(self);
|
||||
assert(pCon);
|
||||
|
||||
eCt = self->pDriv->GetStatus(self->pDriv, &fControl);
|
||||
if (eCt == HWFault) {
|
||||
self->badStatusCount++;
|
||||
iRet = self->pDriv->GetError(self->pDriv, &iErr, pError, 79);
|
||||
sprintf(pBueffel, "WARNING: %s ", pError);
|
||||
SCWrite(pCon, pBueffel, eLog);
|
||||
iRet = self->pDriv->TryAndFixIt(self->pDriv, iErr);
|
||||
if (iRet == COTERM || self->badStatusCount > 3) {
|
||||
SCWrite(pCon, "ERROR: Cannot fix counter problem, aborting", eError);
|
||||
SCSetInterrupt(pCon, eAbortBatch);
|
||||
InvokeCallBack(self->pCall, COUNTEND, NULL);
|
||||
ReleaseCountLock(self->pCountInt);
|
||||
return eCt;
|
||||
} else {
|
||||
return HWBusy;
|
||||
}
|
||||
}
|
||||
|
||||
if(self->pDriv->fTime > .0){
|
||||
rate = (float)(self->pDriv->lCounts[1])/self->pDriv->fTime;
|
||||
if(rate > 10000){
|
||||
SCWrite(pCon,"WARNING: Your control monitor is running into dead time",
|
||||
eWarning);
|
||||
}
|
||||
}
|
||||
/*
|
||||
handle count parameters and notify listeners on progress
|
||||
*/
|
||||
sMon.fCurrent = fControl;
|
||||
sMon.fPreset = self->pDriv->fPreset;
|
||||
sMon.pName = self->name;
|
||||
self->badStatusCount = 0; /* clear: we managed to read OK */
|
||||
if (self->iCallbackCounter > 20) {
|
||||
InvokeCallBack(self->pCall, MONITOR, &sMon);
|
||||
tracePar(self->name,"control:%f", fControl);
|
||||
self->iCallbackCounter = 0;
|
||||
} else {
|
||||
self->iCallbackCounter++;
|
||||
}
|
||||
self->pDriv->fLastCurrent = fControl;
|
||||
|
||||
/*
|
||||
notification on finish
|
||||
*/
|
||||
if (eCt == HWIdle) {
|
||||
self->isUpToDate = 0;
|
||||
InvokeCallBack(self->pCall, COUNTEND, NULL);
|
||||
ReleaseCountLock(self->pCountInt);
|
||||
}
|
||||
return eCt;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
static int SaveCounterStatus(void *pData, char *name, FILE * fd)
|
||||
{
|
||||
pCounter self = NULL;
|
||||
|
||||
assert(pData);
|
||||
assert(fd);
|
||||
|
||||
self = (pCounter) pData;
|
||||
|
||||
fprintf(fd, "# Counter %s\n", name);
|
||||
fprintf(fd, "%s SetPreset %f\n", name, self->pDriv->fPreset);
|
||||
if (self->pDriv->eMode == eTimer) {
|
||||
fprintf(fd, "%s SetMode Timer\n", name);
|
||||
} else {
|
||||
fprintf(fd, "%s SetMode Monitor\n", name);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
static int TransferData(void *pData, SConnection * pCon)
|
||||
{
|
||||
@@ -322,6 +247,7 @@ static int TransferData(void *pData, SConnection * pCon)
|
||||
SCWrite(pCon, "ERROR: Cannot fix counter problem, aborting",
|
||||
eError);
|
||||
SCSetInterrupt(pCon, eAbortBatch);
|
||||
SetCounterError(pData,pError);
|
||||
return HWFault;
|
||||
}
|
||||
}
|
||||
@@ -331,6 +257,98 @@ static int TransferData(void *pData, SConnection * pCon)
|
||||
return HWFault;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static int CheckCountStatus(void *pData, SConnection * pCon)
|
||||
{
|
||||
pCounter self = NULL;
|
||||
int i, iRet;
|
||||
int eCt;
|
||||
char pError[80], pBueffel[132];
|
||||
int iErr;
|
||||
float fControl = .0, rate;
|
||||
MonEvent sMon;
|
||||
|
||||
self = (pCounter) pData;
|
||||
assert(self);
|
||||
assert(pCon);
|
||||
|
||||
eCt = self->pDriv->GetStatus(self->pDriv, &fControl);
|
||||
if (eCt == HWFault) {
|
||||
self->badStatusCount++;
|
||||
iRet = self->pDriv->GetError(self->pDriv, &iErr, pError, 79);
|
||||
sprintf(pBueffel, "WARNING: %s ", pError);
|
||||
SCWrite(pCon, pBueffel, eLog);
|
||||
iRet = self->pDriv->TryAndFixIt(self->pDriv, iErr);
|
||||
if (iRet == COTERM || self->badStatusCount > 3) {
|
||||
SCWrite(pCon, "ERROR: Cannot fix counter problem, aborting", eError);
|
||||
SCSetInterrupt(pCon, eAbortBatch);
|
||||
InvokeCallBack(self->pCall, COUNTEND, NULL);
|
||||
ReleaseCountLock(self->pCountInt);
|
||||
SetCounterError(pData,pError);
|
||||
return eCt;
|
||||
} else {
|
||||
return HWBusy;
|
||||
}
|
||||
}
|
||||
|
||||
/* if(self->pDriv->fTime > .0){ */
|
||||
/* rate = (float)(self->pDriv->lCounts[1])/self->pDriv->fTime; */
|
||||
/* if(rate > 10000){ */
|
||||
/* SCWrite(pCon,"WARNING: Your control monitor is running into dead time", */
|
||||
/* eLogError); */
|
||||
/* } */
|
||||
/* } */
|
||||
|
||||
/*
|
||||
handle count parameters and notify listeners on progress
|
||||
*/
|
||||
sMon.fCurrent = fControl;
|
||||
sMon.fPreset = self->pDriv->fPreset;
|
||||
sMon.pName = self->name;
|
||||
self->badStatusCount = 0; /* clear: we managed to read OK */
|
||||
if (self->iCallbackCounter > 20) {
|
||||
InvokeCallBack(self->pCall, MONITOR, &sMon);
|
||||
tracePar(self->name,"control:%f", fControl);
|
||||
self->iCallbackCounter = 0;
|
||||
} else {
|
||||
self->iCallbackCounter++;
|
||||
}
|
||||
self->pDriv->fLastCurrent = fControl;
|
||||
|
||||
/*
|
||||
notification on finish
|
||||
*/
|
||||
if (eCt == HWIdle) {
|
||||
self->isUpToDate = 0;
|
||||
TransferData(self,pCon);
|
||||
InvokeCallBack(self->pCall, COUNTEND, NULL);
|
||||
ReleaseCountLock(self->pCountInt);
|
||||
}
|
||||
return eCt;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
static int SaveCounterStatus(void *pData, char *name, FILE * fd)
|
||||
{
|
||||
pCounter self = NULL;
|
||||
|
||||
assert(pData);
|
||||
assert(fd);
|
||||
|
||||
self = (pCounter) pData;
|
||||
|
||||
fprintf(fd, "# Counter %s\n", name);
|
||||
fprintf(fd, "%s SetPreset %f\n", name, self->pDriv->fPreset);
|
||||
if (self->pDriv->eMode == eTimer) {
|
||||
fprintf(fd, "%s SetMode Timer\n", name);
|
||||
} else {
|
||||
fprintf(fd, "%s SetMode Monitor\n", name);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
static void *CounterGetInterface(void *pData, int iID)
|
||||
{
|
||||
@@ -391,8 +409,6 @@ int DoCount(pCounter self, float fPreset, SConnection * pCon, int iBlock)
|
||||
return 0;
|
||||
}
|
||||
|
||||
eOld = GetStatus();
|
||||
SetStatus(eCounting);
|
||||
|
||||
/* set Preset */
|
||||
SetCounterPreset(self, fPreset);
|
||||
@@ -405,7 +421,6 @@ int DoCount(pCounter self, float fPreset, SConnection * pCon, int iBlock)
|
||||
iRet = StartDevice(GetExecutor(), self->name, self->pDes, self, pCon,
|
||||
level, fPreset);
|
||||
if (!iRet) {
|
||||
SetStatus(eOld);
|
||||
SCWrite(pCon, "Counting aborted", eError);
|
||||
return 0;
|
||||
}
|
||||
@@ -426,7 +441,6 @@ int DoCount(pCounter self, float fPreset, SConnection * pCon, int iBlock)
|
||||
SCWrite(pCon, "Counting finished", eValue);
|
||||
iRet = 1;
|
||||
}
|
||||
SetStatus(eOld);
|
||||
return iRet;
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
@@ -444,12 +458,13 @@ int MakeCounter(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
assert(pCon);
|
||||
assert(pSics);
|
||||
|
||||
argtolower(argc, argv);
|
||||
if (argc < 3) {
|
||||
SCWrite(pCon, "ERROR: insuficient number of arguments to MakeCounter",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
strtolower(argv[1]);
|
||||
strtolower(argv[2]);
|
||||
site = getSite();
|
||||
if (site != NULL) {
|
||||
pDriv = site->CreateCounterDriver(pCon, argc, argv);
|
||||
@@ -708,13 +723,16 @@ static int isAuthorised(SConnection * pCon, int iCode)
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
static int CounterInterest(int iEvent, void *pEvent, void *pUser)
|
||||
int CounterInterest(int iEvent, void *pEvent, void *pUser)
|
||||
{
|
||||
SConnection *pCon = NULL;
|
||||
pMonEvent pMon = NULL;
|
||||
char pBueffel[512];
|
||||
int rights;
|
||||
|
||||
pCon = (SConnection *) pUser;
|
||||
pMon = (pMonEvent) pEvent;
|
||||
|
||||
if (pCon == NULL || !SCisConnected(pCon)) {
|
||||
return -1;
|
||||
}
|
||||
@@ -723,17 +741,13 @@ static int CounterInterest(int iEvent, void *pEvent, void *pUser)
|
||||
return 0;
|
||||
}
|
||||
|
||||
pCon = (SConnection *) pUser;
|
||||
pMon = (pMonEvent) pEvent;
|
||||
assert(pCon);
|
||||
assert(pMon);
|
||||
snprintf(pBueffel,511, "%s.CountStatus = %f %d", pMon->pName, pMon->fPreset,
|
||||
(int) nintf(pMon->fCurrent));
|
||||
/**
|
||||
* prevent this to be written to log files
|
||||
*/
|
||||
SCSetRights(pCon, usSpy);
|
||||
SCWrite(pCon, pBueffel, eWarning);
|
||||
SCWrite(pCon, pBueffel, eLog);
|
||||
return 1;
|
||||
}
|
||||
/*------------------------------------------------------------------------*/
|
||||
@@ -789,6 +803,7 @@ pCounter CreateCounter(char *name, pCounterDriver pDriv)
|
||||
pRes->isUpToDate = 1;
|
||||
pRes->iExponent = 0;
|
||||
pRes->name = strdup(name);
|
||||
pRes->error = strdup("None");
|
||||
return pRes;
|
||||
}
|
||||
|
||||
@@ -829,9 +844,13 @@ int CountAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
{"send", 0, {0, 0}},
|
||||
{"setpar", 3, {FUPATEXT, FUPAINT, FUPAFLOAT}},
|
||||
{"getpar", 2, {FUPATEXT, FUPAOPT}},
|
||||
{"getnmon", 0, {0, 0}},
|
||||
{"state", 0, {0, 0}},
|
||||
{"error", 0, {0, 0}},
|
||||
{"getnmon",0,{0,0}},
|
||||
{"getchannel",0,{0}},
|
||||
{"setchannel",1,{FUPAINT}}
|
||||
{"setchannel",1,{FUPAINT}},
|
||||
{"countstatus", 0, {0, 0}}
|
||||
};
|
||||
char *pMode[] = {
|
||||
"timer",
|
||||
@@ -848,7 +867,7 @@ int CountAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
argtolower(argc, argv);
|
||||
argx = &argv[1];
|
||||
iRet =
|
||||
EvaluateFuPa((pFuncTemplate) & ActionTemplate, 25, argc - 1, argx,
|
||||
EvaluateFuPa((pFuncTemplate) & ActionTemplate, 27 argc - 1, argx,
|
||||
&PaRes);
|
||||
if (iRet < 0) {
|
||||
snprintf(pBueffel, 255,"%s", PaRes.pError);
|
||||
@@ -957,6 +976,7 @@ int CountAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
case 11: /* status */
|
||||
case 25:
|
||||
self->pCountInt->TransferData(self, pCon);
|
||||
if (GetCounterMode(self) == ePreset) {
|
||||
lVal = GetCounterPreset(self);
|
||||
@@ -1008,9 +1028,9 @@ int CountAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
"ERROR: Insufficient privilege to set threshold", eError);
|
||||
return 0;
|
||||
}
|
||||
if (isInRunMode(pServ->pExecutor)) {
|
||||
if (isRunning(self->pCountInt)) {
|
||||
SCWrite(pCon,
|
||||
"ERROR: cannot change threshold while instrument is active",
|
||||
"ERROR: cannot change threshold while counting",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
@@ -1155,14 +1175,28 @@ int CountAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
case 22: /* getnmon */
|
||||
snprintf(pBueffel, 131, "%s.getnmon = %d", argv[0], GetNMonitor(self));
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
break;
|
||||
case 23: /* state */
|
||||
if(isRunning(self->pCountInt)){
|
||||
snprintf(pBueffel, 131, "%s.state = run", argv[0]);
|
||||
} else {
|
||||
snprintf(pBueffel, 131, "%s.state = idle", argv[0]);
|
||||
}
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
return 1;
|
||||
break;
|
||||
case 23: /* getchannel */
|
||||
case 24: /* error */
|
||||
snprintf(pBueffel, 131, "%s.error = %s", argv[0],self->error);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
return 1;
|
||||
return 1;
|
||||
break;
|
||||
case 25: /* getchannel */
|
||||
snprintf(pBueffel,131,"%s.getchannel = %d", argv[0], GetControlMonitor(self));
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
return 1;
|
||||
break;
|
||||
case 24: /* setchannel */
|
||||
case 26: /* setchannel */
|
||||
if (SetControlMonitor(self, PaRes.Arg[0].iVal)) {
|
||||
return 1;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user