diff --git a/event.h b/event.h index ef9dbabf..b39a241d 100644 --- a/event.h +++ b/event.h @@ -49,6 +49,10 @@ #define STEND 22 #define NEWTARGET 23 #define DIMCHANGE 24 +#define STPAUSE 25 +#define STCONTINUE 26 +#define STBUSY 27 +#define STIDLE 28 #line 118 "event.w" diff --git a/site_ansto/Makefile b/site_ansto/Makefile index 856be155..d65c80dc 100644 --- a/site_ansto/Makefile +++ b/site_ansto/Makefile @@ -138,7 +138,6 @@ GHTTP_LIBS = \ OBJ= site_ansto.o anstoutil.o\ ansto_sctdriveadapter.o\ - ansto_tclmotdriv.o\ sctemonadapter.o\ motor_asim.o motor_dmc2280.o\ lh45.o lh45driv.o \ diff --git a/statemon.c b/statemon.c index 8a7a5364..0c6de683 100644 --- a/statemon.c +++ b/statemon.c @@ -3,7 +3,7 @@ * from the device executor and from scan and batch commands. Clients can * listen to this in order to figure out what is actually going on in a * given SICS installation. This might in the end supersede the status code - * managment in status.c + * management in status.c * * copyright: see file COPYRIGHT * @@ -16,11 +16,16 @@ #include "stptok.h" #include "statemon.h" #include "sicshipadaba.h" +#include "sicsvar.h" + +#define SICS_SUID "sics_suid" +pICallBack statemon_cbinterface = NULL; /*==========================================================================*/ typedef struct __STATEMON { pObjectDescriptor pDes; pICallBack pCall; } StateMon; +SConnection *pStateMonDummyCon = NULL; /*============================ Callbacks =================================*/ static int DevexecCallback(int iEvent, void *text, void *pData) { @@ -101,22 +106,41 @@ static int StateInterest(int iEvent, void *pEvent, void *pUser) SConnection *pCon = (SConnection *) pUser; char *device = (char *) pEvent; char buffer[256]; - + pSicsVariable pVar = NULL; + if (pCon == NULL || !SCisConnected(pCon)) { return -1; } + if (pCon == NULL || device == NULL) { printf("Bad StateInterest in statemon\n"); return 0; - } - if (iEvent == STSTART) { - snprintf(buffer, 255, "STARTED = %s", device); - SCWrite(pCon, buffer, eWarning); - } - if (iEvent == STEND) { - snprintf(buffer, 255, "FINISH = %s", device); - SCWrite(pCon, buffer, eWarning); + } else if (pCon == pStateMonDummyCon) { + if(iEvent == STSTART){ + snprintf(buffer,255,"SUID MSG STARTED = %s", device); + SCWrite(pStateMonDummyCon,buffer,eError); + } + if(iEvent == STEND){ + snprintf(buffer,255,"SUID MSG FINISH = %s", device); + SCWrite(pStateMonDummyCon,buffer,eError); + } + pVar = (pSicsVariable)FindCommandData(pServ->pSics,SICS_SUID,"SicsVariable"); + if (pVar == NULL) { + SCWrite(pStateMonDummyCon,"ERROR: StateMon.c: Could not find SUID SicsVariable",eError); + return 0; + } + (pVar->iVal)++; + InvokeCallBack(pVar->pCall, VALUECHANGE, pVar); + } else { + if (iEvent == STSTART) { + snprintf(buffer, 255, "STARTED = %s", device); + SCWrite(pCon, buffer, eWarning); + } + if (iEvent == STEND) { + snprintf(buffer, 255, "FINISH = %s", device); + SCWrite(pCon, buffer, eWarning); + } } return 1; } @@ -230,6 +254,9 @@ static void killStateMon(void *pData) if (self->pCall != NULL) { DeleteCallBackInterface(self->pCall); } + if(pStateMonDummyCon != NULL) { + SCDeleteConnection(pStateMonDummyCon); + } free(self); } } @@ -238,10 +265,12 @@ static void killStateMon(void *pData) int StateMonFactory(SConnection * pCon, SicsInterp * pSics, void *pData, int argc, char *argv[]) { + long lID; pStateMon pNew = NULL; commandContext cc; pICallBack target = NULL; void *pPtr = NULL, *exe = NULL, *pDevexec = NULL; + pSicsVariable pRes = NULL; exe = FindCommandData(pSics, "exe", "ExeManager"); pDevexec = FindCommandData(pSics, "stopexe", "DeviceExecutor"); @@ -265,6 +294,7 @@ int StateMonFactory(SConnection * pCon, SicsInterp * pSics, void *pData, memset(pNew, 0, sizeof(StateMon)); pNew->pDes = CreateDescriptor("statemon"); pNew->pCall = CreateCallBackInterface(); + statemon_cbinterface = pNew->pCall; if (pNew->pDes == NULL || pNew->pCall == NULL) { SCWrite(pCon, "ERROR: out of memory creating StateMon", eError); return 0; @@ -283,7 +313,7 @@ int StateMonFactory(SConnection * pCon, SicsInterp * pSics, void *pData, if (argc > 1) { pPtr = FindCommandData(pSics, argv[1], "ScanObject"); if (pPtr == NULL) { - SCWrite(pCon, "ERROR: failked to locate scan object", eError); + SCWrite(pCon,"ERROR: failed to locate scan object",eError); } else { target = GetCallbackInterface(pPtr); assert(target != NULL); @@ -292,6 +322,17 @@ int StateMonFactory(SConnection * pCon, SicsInterp * pSics, void *pData, RegisterCallback(target, SCANEND, StateMonScanInterest, pNew, NULL); } } + /* Make dummy connection for SUID (instrument state id) */ + pStateMonDummyCon = SCCreateDummyConnection(pSics); + lID = RegisterCallback(pNew->pCall, STSTART, StateInterest, pStateMonDummyCon, NULL); + SCRegister(pStateMonDummyCon,pSics, pNew->pCall,lID); + lID = RegisterCallback(pNew->pCall, STEND, StateInterest, pStateMonDummyCon, NULL); + SCRegister(pStateMonDummyCon,pSics, pNew->pCall,lID); + pRes = VarCreate(usInternal,veInt,SICS_SUID); + AddCommand(pSics,SICS_SUID,VarWrapper,(KillFunc)VarKill,pRes); + /* + * TODO: add kill functions + */ AddCommand(pSics, "statemon", StateMonAction, killStateMon, pNew); return 1; } @@ -319,8 +360,21 @@ int StateMonAction(SConnection * pCon, SicsInterp * pSics, void *pData, SCWrite(pCon, "ERROR: out of memory registering interest", eError); return 0; } + lID = RegisterCallback(self->pCall, STSTART, StateInterest, - callCon, SCDeleteConnection); + callCon, NULL); + SCRegister(pCon, pSics, self->pCall, lID); + lID = RegisterCallback(self->pCall, STEND, StateInterest, + callCon, NULL); + SCRegister(pCon, pSics, self->pCall, lID); + lID = RegisterCallback(self->pCall, STPAUSE, StateInterest, + callCon, NULL); + SCRegister(pCon, pSics, self->pCall, lID); + lID = RegisterCallback(self->pCall, STCONTINUE, StateInterest, + callCon, NULL); + SCRegister(pCon, pSics, self->pCall, lID); + lID = RegisterCallback(self->pCall, STBUSY, StateInterest, + callCon, NULL); SCRegister(pCon, pSics, self->pCall, lID); lID = RegisterCallback(self->pCall, STEND, StateInterest, callCon, NULL); @@ -332,6 +386,7 @@ int StateMonAction(SConnection * pCon, SicsInterp * pSics, void *pData, lID = SCgetCallbackID(pCon, self->pCall); if (lID >= 0) { RemoveCallback(self->pCall, lID); + SCUnregisterID(pCon,lID); } } SCSendOK(pCon); @@ -344,8 +399,10 @@ int StateMonAction(SConnection * pCon, SicsInterp * pSics, void *pData, } lID = RegisterCallback(self->pCall, STSTART, StateHdbInterest, callCon, SCDeleteConnection); + /* TODO: why not SCRegister(pCon, pSics, self->pCall, lID); */ lID = RegisterCallback(self->pCall, STEND, StateHdbInterest, callCon, NULL); + /* TODO: why not SCRegister(pCon, pSics, self->pCall, lID); */ SCSendOK(pCon); return 1; } else if (strcmp(argv[1], "start") == 0) { @@ -362,7 +419,36 @@ int StateMonAction(SConnection * pCon, SicsInterp * pSics, void *pData, return 1; } return 0; + } else if(strcmp(argv[1],"pause") == 0) { + if(argc > 2){ + InvokeCallBack(self->pCall,STPAUSE,argv[2]); + SCSendOK(pCon); + return 1; + } + return 0; + } else if(strcmp(argv[1],"continue") == 0) { + if(argc > 2){ + InvokeCallBack(self->pCall,STCONTINUE,argv[2]); + SCSendOK(pCon); + return 1; + } + return 0; + } else if(strcmp(argv[1],"busy") == 0) { + if(argc > 2){ + InvokeCallBack(self->pCall,STBUSY,argv[2]); + SCSendOK(pCon); + return 1; + } + return 0; + } else if(strcmp(argv[1],"idle") == 0) { + if(argc > 2){ + InvokeCallBack(self->pCall,STIDLE,argv[2]); + SCSendOK(pCon); + return 1; + } + return 0; } + SCWrite(pCon, "ERROR: keyword not recognized", eError); return 0;