- Added restart status code
- Small fixes to make regression tests work at the same level as for first generation devices
This commit is contained in:
57
countersec.c
57
countersec.c
@ -13,6 +13,8 @@
|
||||
#include <sics.h>
|
||||
#include <counter.h>
|
||||
#include "sicshipadaba.h"
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
* defines for commmands
|
||||
* -------------------------------------------------------------------------*/
|
||||
@ -26,6 +28,19 @@ typedef struct {
|
||||
float fCurrent;
|
||||
char *pName;
|
||||
} MonEvent, *pMonEvent;
|
||||
/*-------------------------------------------------------------------------*/
|
||||
static void SecCounterSetError(pCounter self, char *text)
|
||||
{
|
||||
hdbValue v;
|
||||
pHdb node;
|
||||
|
||||
node = GetHipadabaNode(self->pDes->parNode, "error");
|
||||
if(node != NULL){
|
||||
v = MakeHdbText(strdup(text));
|
||||
UpdateHipadabaPar(node,v,NULL);
|
||||
ReleaseHdbValue(&v);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int SecCtrInvokeFunction(pCounter self, SConnection *pCon, int code)
|
||||
{
|
||||
@ -52,7 +67,7 @@ static int SecStartCount(void *pData, SConnection *pCon)
|
||||
{
|
||||
pCounter self = (pCounter)pData;
|
||||
int status;
|
||||
pHdb node;
|
||||
pHdb node, statusNode;
|
||||
|
||||
assert(self != NULL);
|
||||
|
||||
@ -60,14 +75,14 @@ static int SecStartCount(void *pData, SConnection *pCon)
|
||||
return 0;
|
||||
}
|
||||
|
||||
statusNode = GetHipadabaNode(self->pDes->parNode, "status");
|
||||
UpdateHipadabaPar(statusNode,MakeHdbText("run"), pCon);
|
||||
status = SecCtrInvokeFunction(self,pCon, START);
|
||||
self->haltFixFlag = 0;
|
||||
if(status == 1){
|
||||
self->isUpToDate = 0;
|
||||
self->badStatusCount = 0;
|
||||
self->tStart = time(NULL);
|
||||
node = GetHipadabaNode(self->pDes->parNode, "status");
|
||||
UpdateHipadabaPar(node,MakeHdbText("run"), pCon);
|
||||
node = GetHipadabaNode(self->pDes->parNode, "control");
|
||||
UpdateHipadabaPar(node,MakeHdbFloat(.0), pCon);
|
||||
SetHdbProperty(node,"geterror", NULL);
|
||||
@ -79,8 +94,10 @@ static int SecStartCount(void *pData, SConnection *pCon)
|
||||
node = GetHipadabaNode(self->pDes->parNode, "time");
|
||||
UpdateHipadabaPar(node,MakeHdbFloat(.0), pCon);
|
||||
InvokeCallBack(self->pCall,COUNTSTART, pCon);
|
||||
SecCounterSetError(self,"None");
|
||||
return 1;
|
||||
} else {
|
||||
UpdateHipadabaPar(statusNode,MakeHdbText("error"), pCon);
|
||||
ReleaseCountLock(self->pCountInt);
|
||||
return HWFault;
|
||||
}
|
||||
@ -110,7 +127,8 @@ static int SecCtrCheckStatus(void *pData, SConnection *pCon)
|
||||
int status;
|
||||
MonEvent sMon;
|
||||
float fControl, fPreset;
|
||||
|
||||
char error[132];
|
||||
|
||||
assert(self != NULL);
|
||||
|
||||
node = GetHipadabaNode(self->pDes->parNode,"status");
|
||||
@ -135,9 +153,19 @@ static int SecCtrCheckStatus(void *pData, SConnection *pCon)
|
||||
status = HWNoBeam;
|
||||
} else if (strstr(v.v.text, "pause") != NULL) {
|
||||
status = HWPause;
|
||||
} else if (strstr(v.v.text, "restart") != NULL) {
|
||||
SecStartCount(self, pCon);
|
||||
return HWBusy;
|
||||
} else if (strstr(v.v.text, "error") != NULL) {
|
||||
InvokeCallBack(self->pCall, COUNTEND, NULL);
|
||||
ReleaseCountLock(self->pCountInt);
|
||||
if(GetHdbProperty(node,"geterror",error,sizeof(error)) == 1){
|
||||
SCPrintf(pCon,eError,"ERROR: %s", error);
|
||||
SecCounterSetError(self,error);
|
||||
} else {
|
||||
SecCounterSetError(self,"Undefined counter error: set status geterror");
|
||||
SCPrintf(pCon,eError,"ERROR: Unknown counter status error: set status geterror property");
|
||||
}
|
||||
status = HWFault;
|
||||
} else {
|
||||
SCPrintf(pCon, eError, "ERROR: unknown counter status %s found",
|
||||
@ -415,6 +443,20 @@ static int ContinueCmd(pSICSOBJ ccmd, SConnection * con,
|
||||
pCounter self = (pCounter)ccmd;
|
||||
return self->pCountInt->Continue(self,con);
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
extern int CounterInterest(int iEvent, void *pEvent, void *pUser);
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static int InterestCmd(pSICSOBJ ccmd, SConnection * con,
|
||||
Hdb * cmdNode, Hdb * par[], int nPar)
|
||||
{
|
||||
long lID;
|
||||
pCounter self = (pCounter)ccmd;
|
||||
lID = RegisterCallback(self->pCall, MONITOR, CounterInterest,
|
||||
SCCopyConnection(con), SCDeleteConnection);
|
||||
SCSendOK(con);
|
||||
return 1;
|
||||
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
pCounter CreateSecCounter(SConnection *pCon, char *type, char *name, int length)
|
||||
{
|
||||
@ -499,6 +541,12 @@ pCounter CreateSecCounter(SConnection *pCon, char *type, char *name, int length)
|
||||
}
|
||||
AddHipadabaChild(node, child, NULL);
|
||||
|
||||
child = MakeSICSHdbPar("error", usInternal, MakeHdbText("None"));
|
||||
if (child == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
AddHipadabaChild(node, child, NULL);
|
||||
|
||||
child = MakeSICSHdbPar("control", usUser, MakeHdbFloat(.0));
|
||||
if (child == NULL) {
|
||||
return NULL;
|
||||
@ -521,6 +569,7 @@ pCounter CreateSecCounter(SConnection *pCon, char *type, char *name, int length)
|
||||
child = AddSICSHdbPar(node,"stop", usUser, MakeSICSFunc(StopCmd));
|
||||
child = AddSICSHdbPar(node,"pause", usUser, MakeSICSFunc(PauseCmd));
|
||||
child = AddSICSHdbPar(node,"continue", usUser, MakeSICSFunc(ContinueCmd));
|
||||
child = AddSICSHdbPar(node,"interest", usUser, MakeSICSFunc(InterestCmd));
|
||||
|
||||
return pRes;
|
||||
}
|
||||
|
52
motorsec.c
52
motorsec.c
@ -47,6 +47,19 @@
|
||||
|
||||
#define ABS(x) (x < 0 ? -(x) : (x))
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
static void SecMotorSetError(pMotor self, char *text)
|
||||
{
|
||||
hdbValue v;
|
||||
pHdb node;
|
||||
|
||||
node = GetHipadabaNode(self->pDescriptor->parNode, "error");
|
||||
if(node != NULL){
|
||||
v = MakeHdbText(strdup(text));
|
||||
UpdateHipadabaPar(node,v,NULL);
|
||||
ReleaseHdbValue(&v);
|
||||
}
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static int SecMotorGetPar(pMotor self, char *name, float *fVal)
|
||||
{
|
||||
@ -106,8 +119,10 @@ static long SecMotorRun(void *sulf, SConnection * pCon, float fNew)
|
||||
}
|
||||
self->stopped = 0;
|
||||
self->stopReported = 0;
|
||||
self->fTarget = fNew;
|
||||
|
||||
v = MakeHdbFloat(fNew);
|
||||
SecMotorSetError(sulf,"None");
|
||||
status = SetHipadabaPar(self->pDescriptor->parNode, v, pCon);
|
||||
node = GetHipadabaNode(self->pDescriptor->parNode, "status");
|
||||
if(node != NULL){
|
||||
@ -200,12 +215,17 @@ static int SecMotorLimits(void *sulf, float fVal, char *error, int iErrLen)
|
||||
{
|
||||
float fHard;
|
||||
pMotor self;
|
||||
int status;
|
||||
|
||||
assert(sulf);
|
||||
|
||||
self = (pMotor) sulf;
|
||||
|
||||
return SecMotorCheckBoundary(self, fVal, &fHard, error, iErrLen);
|
||||
status = SecMotorCheckBoundary(self, fVal, &fHard, error, iErrLen);
|
||||
if(status != 1){
|
||||
SecMotorSetError(sulf,error);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
@ -231,10 +251,11 @@ static int checkPosition(pMotor self, SConnection * pCon)
|
||||
if (ABS(target - hard) > precision) {
|
||||
if (self->retryCount >= (int) maxretry) {
|
||||
SCPrintf(pCon, eLogError,
|
||||
"ERROR: Aborting %s after %d retries, off position by %f",
|
||||
"ERROR: aborting %s after %d retries, off position by %f",
|
||||
self->name, (int) maxretry, target - hard);
|
||||
node = GetHipadabaNode(self->pDescriptor->parNode, "status");
|
||||
assert(node != NULL);
|
||||
SecMotorSetError(self,"Aborted poistioning after many retries");
|
||||
UpdateHipadabaPar(node, MakeHdbText("error"), pCon);
|
||||
return HWFault;
|
||||
}
|
||||
@ -277,6 +298,7 @@ static int SecMotorStatus(void *sulf, SConnection * pCon)
|
||||
pHdb node = NULL;
|
||||
hdbValue v;
|
||||
float interrupt;
|
||||
char error[132];
|
||||
|
||||
assert(sulf);
|
||||
self = (pMotor) sulf;
|
||||
@ -298,8 +320,20 @@ static int SecMotorStatus(void *sulf, SConnection * pCon)
|
||||
handleMoveCallback(self, pCon);
|
||||
status = HWBusy;
|
||||
} else if (strstr(v.v.text, "poserror") != NULL) {
|
||||
SCWrite(pCon,"WARNING: Position not reached",eLog);
|
||||
status = checkPosition(self, pCon);
|
||||
} else if (strstr(v.v.text, "restart") != NULL) {
|
||||
SCPrintf(pCon,eLog,"WARNING: restarting motor %s", self->name);
|
||||
SecMotorRun(self,pCon,self->fTarget);
|
||||
return HWBusy;
|
||||
} else if (strstr(v.v.text, "error") != NULL) {
|
||||
if(GetHdbProperty(node,"geterror",error,sizeof(error)) == 1){
|
||||
SecMotorSetError(sulf,error);
|
||||
}
|
||||
node = GetHipadabaNode(self->pDescriptor->parNode, "targetposition");
|
||||
if(GetHdbProperty(node,"geterror",error,sizeof(error)) == 1){
|
||||
SecMotorSetError(sulf,error);
|
||||
}
|
||||
status = HWFault;
|
||||
} else {
|
||||
SCPrintf(pCon, eError, "ERROR: unknown motor status %s found",
|
||||
@ -333,9 +367,16 @@ static float SecMotorGetValue(void *pData, SConnection * pCon)
|
||||
{
|
||||
int status;
|
||||
pMotor self = (pMotor) pData;
|
||||
hdbValue v;
|
||||
hdbValue v;
|
||||
char error[132];
|
||||
|
||||
|
||||
assert(pData);
|
||||
status = GetHdbProperty(self->pDescriptor->parNode,"geterror", error,sizeof(error));
|
||||
if(status == 1 && strcmp(error,"none") != 0) {
|
||||
SCPrintf(pCon,eValue,"ERROR: Failed to read %s with %s", self->name, error);
|
||||
return -9999999.99;
|
||||
}
|
||||
status = GetHipadabaPar(self->pDescriptor->parNode, &v, pCon);
|
||||
if (status != 1) {
|
||||
return -9999999.99;
|
||||
@ -473,7 +514,7 @@ static hdbCallbackReturn SecMotorCallback(pHdb node, void *userData,
|
||||
* check for alarm condition
|
||||
*/
|
||||
SecMotorGetPar(self, "failafter", &fVal);
|
||||
if (self->pDrivInt->iErrorCount > (int) fVal) {
|
||||
if (self->pDrivInt->iErrorCount >= (int) fVal) {
|
||||
/* big alarm */
|
||||
ServerWriteGlobal("ERROR: !!! MOTOR ALARM !!! MOTOR ALARM !!!",
|
||||
eError);
|
||||
@ -744,6 +785,9 @@ pMotor SecMotorInit(char *name)
|
||||
SetHdbProperty(child, "motname", name);
|
||||
AddHipadabaChild(node, child, NULL);
|
||||
|
||||
child = MakeHipadabaNode("error", HIPTEXT, 1);
|
||||
AddHipadabaChild(node, child, NULL);
|
||||
|
||||
pM->endScriptID = 0;
|
||||
|
||||
/* initialise Drivable interface */
|
||||
|
Reference in New Issue
Block a user