From f5e797dd6a1895fbc1222430a16343ea554fa157 Mon Sep 17 00:00:00 2001 From: Mark Koennecke Date: Fri, 18 Jul 2014 14:02:57 +0200 Subject: [PATCH] - Cleaned all old dtatus setting code --- conman.c | 8 -------- counter.c | 4 ---- devexec.c | 7 ------- drive.c | 13 ------------- evcontroller.c | 4 ---- exebuf.c | 2 -- interface.c | 11 ----------- macro.c | 6 ------ multicountersec.c | 6 ------ nserver.c | 6 +----- script.c | 12 +++++++++--- status.c | 4 ++++ status.h | 12 ------------ stdscan.c | 1 - synchronize.c | 5 ----- tasscanub.c | 1 - velo.c | 5 ----- 17 files changed, 14 insertions(+), 93 deletions(-) diff --git a/conman.c b/conman.c index 43fa851f..a053e2c4 100644 --- a/conman.c +++ b/conman.c @@ -1521,8 +1521,6 @@ int SCPrompt(SConnection * pCon, char *pPrompt, char *pResult, int iLen) SCWrite(pCon, pPrompt, eWarning); master = SCfindMaster(pCon); - eOld = GetStatus(); - SetStatus(eInput); CostaUnlock(master->pStack); while (1) { /* @@ -1542,14 +1540,12 @@ int SCPrompt(SConnection * pCon, char *pPrompt, char *pResult, int iLen) /* do we have data ? */ iRet = CostaPop(master->pStack, &pPtr); if (iRet == 1) { - SetStatus(eOld); CostaLock(master->pStack); strlcpy(pResult, pPtr, iLen); WriteToCommandLogId(" prompted>", pCon->sockHandle, pPtr); return 1; } } - SetStatus(eOld); CostaLock(master->pStack); return 0; } @@ -1570,8 +1566,6 @@ int SCPromptTMO(SConnection * pCon, char *pPrompt, char *pResult, int iLen, int SCWrite(pCon, pPrompt, eWarning); master = SCfindMaster(pCon); - eOld = GetStatus(); - SetStatus(eInput); CostaUnlock(master->pStack); for(i = 0; i < timeout; i++) { /* @@ -1591,14 +1585,12 @@ int SCPromptTMO(SConnection * pCon, char *pPrompt, char *pResult, int iLen, int /* do we have data ? */ iRet = CostaPop(master->pStack, &pPtr); if (iRet == 1) { - SetStatus(eOld); CostaLock(master->pStack); strlcpy(pResult, pPtr, iLen); WriteToCommandLogId(" prompted>", pCon->sockHandle, pPtr); return 1; } } - SetStatus(eOld); CostaLock(master->pStack); return 0; } diff --git a/counter.c b/counter.c index 977f2239..7b75da54 100644 --- a/counter.c +++ b/counter.c @@ -409,8 +409,6 @@ int DoCount(pCounter self, float fPreset, SConnection * pCon, int iBlock) return 0; } - eOld = GetStatus(); - SetStatus(eCounting); /* set Preset */ SetCounterPreset(self, fPreset); @@ -423,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; } @@ -444,7 +441,6 @@ int DoCount(pCounter self, float fPreset, SConnection * pCon, int iBlock) SCWrite(pCon, "Counting finished", eValue); iRet = 1; } - SetStatus(eOld); return iRet; } /*-------------------------------------------------------------------------*/ diff --git a/devexec.c b/devexec.c index 964ce5b6..86e0f12f 100644 --- a/devexec.c +++ b/devexec.c @@ -295,7 +295,6 @@ int StartDevice(pExeList self, char *name, pObjectDescriptor pDes, taskID = StartDriveTask(pData, pCon, name, fNew); if(taskID > 0 && self->instStatus != eCounting){ self->instStatus = eDriving; - SetStatus(eDriving); } if(taskID > 0 && self->drivePrint == 1){ oldVal = pDrivInt->GetValue(pData, pCon); @@ -307,7 +306,6 @@ int StartDevice(pExeList self, char *name, pObjectDescriptor pDes, taskID = StartCountTask(pData,pCon,name); if(taskID > 0){ self->instStatus = eCounting; - SetStatus(eCounting); } } else { SCPrintf(pCon,eLogError, "ERROR: type unkonw, cannot start %s", name); @@ -530,7 +528,6 @@ int PauseExecution(pExeList self) if(IsCounting(self)){ TaskSignalGroup(self->pTask, IPAUSE, &interrupt, self->waitID); TaskSignalGroup(self->pTask, IPAUSE, &interrupt, self->runID); - SetStatus(ePaused); } return 1; @@ -559,7 +556,6 @@ int ContinueExecution(pExeList self) if(GetStatus() == ePaused){ TaskSignalGroup(self->pTask, CONTINUE, &interrupt, self->waitID); TaskSignalGroup(self->pTask, CONTINUE, &interrupt, self->runID); - SetStatus(eCounting); } return 1; } @@ -716,7 +712,6 @@ int Success(SConnection * pCon, SicsInterp * pSics, void *pData, pExeList self = (pExeList)pData; eOld = GetStatus(); - SetStatus(eRunning); if(argc > 1){ if(strcmp(argv[1],"RUNDRIVE") == 0){ @@ -758,7 +753,6 @@ int Success(SConnection * pCon, SicsInterp * pSics, void *pData, SCWrite(pCon, "Level done", eValue); iRet = 1; } - SetStatus(eEager); return iRet; } /*-------------------------------------------------------------------------*/ @@ -894,7 +888,6 @@ int DevExecTask(void *pData) self->lTask = -1; self->iRun = 0; self->instStatus = eEager; - SetStatus(eEager); /* This is sort of unclean. Setting DEVERROR has to be done in the device task function as it is the only one that knows about this. diff --git a/drive.c b/drive.c index 03a16bab..43e0d44f 100644 --- a/drive.c +++ b/drive.c @@ -302,19 +302,16 @@ int DriveWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, } /* interprete arguments as pairs name value and try to start */ - SetStatus(eDriving); for (i = 1; i < argc; i += 2) { if (argv[i + 1] == NULL) { snprintf(pBueffel, 511, "ERROR: no value found for driving %s", argv[i]); SCWrite(pCon, pBueffel, eError); - SetStatus(eOld); return 0; } iRet = Tcl_GetDouble(tcl_interp, argv[i + 1], &dTarget); if (iRet == TCL_ERROR) { SCWrite(pCon, Tcl_GetStringResult(tcl_interp), eError); StopExe(GetExecutor(), "ALL"); - SetStatus(eOld); return 0; } iRet = Start2Run(pCon, pSics, argv[i], RUNDRIVE, dTarget); @@ -328,7 +325,6 @@ int DriveWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, } SCWrite(pCon, pBueffel, eError); StopExe(GetExecutor(), "ALL"); - SetStatus(eOld); return 0; } } @@ -351,17 +347,14 @@ int DriveWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, sprintf(pBueffel, "Driving finished with problem"); SCWrite(pCon, pBueffel, eError); ClearExecutor(GetExecutor()); - SetStatus(eOld); return 0; } else if (iRet == DEVINT) { sprintf(pBueffel, "ERROR: Driving Interrupted!"); SCWrite(pCon, pBueffel, eError); ClearExecutor(GetExecutor()); - SetStatus(eOld); return 0; } SCWrite(pCon, "Driving finished sucessfully", eValue); - SetStatus(eOld); return 1; } @@ -399,19 +392,16 @@ int RunWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, } /* interprete arguments as pairs name value and try to start */ - SetStatus(eDriving); for (i = 1; i < argc; i += 2) { if (argv[i + 1] == NULL) { snprintf(pBueffel,511, "ERROR: no value found for driving %s", argv[i]); SCWrite(pCon, pBueffel, eError); - SetStatus(eOld); return 0; } iRet = Tcl_GetDouble(tcl_interp, argv[i + 1], &dTarget); if (iRet == TCL_ERROR) { SCWrite(pCon, Tcl_GetStringResult(tcl_interp), eError); StopExe(GetExecutor(), "ALL"); - SetStatus(eOld); return 0; } iRet = Start2Run(pCon, pSics, argv[i], RUNRUN, dTarget); @@ -420,7 +410,6 @@ int RunWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, argv[i + 1]); SCWrite(pCon, pBueffel, eError); StopExe(GetExecutor(), "ALL"); - SetStatus(eOld); return 0; } } @@ -466,14 +455,12 @@ int MoveWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, if (argv[i + 1] == NULL) { snprintf(pBueffel,511, "ERROR: no value found for driving %s", argv[i]); SCWrite(pCon, pBueffel, eError); - SetStatus(eOld); return 0; } iRet = Tcl_GetDouble(tcl_interp, argv[i + 1], &dTarget); if (iRet == TCL_ERROR) { SCWrite(pCon, Tcl_GetStringResult(tcl_interp), eError); StopExe(GetExecutor(), "ALL"); - SetStatus(eOld); return 0; } obj = FindCommandData(pSics,argv[i],NULL); diff --git a/evcontroller.c b/evcontroller.c index 33fb9abc..f1120b5c 100644 --- a/evcontroller.c +++ b/evcontroller.c @@ -80,12 +80,9 @@ static long EVIDrive(void *pData, SConnection * pCon, float fVal) assert(pCon); if (self->runScript != NULL) { - savedStatus = GetStatus(); - SetStatus(eBatch); pTcl = InterpGetTcl(pServ->pSics); snprintf(pBueffel, sizeof(pBueffel), "%s %f", self->runScript, fVal); iRet = Tcl_Eval(pTcl, pBueffel); - SetStatus(savedStatus); if (iRet != TCL_OK) { SCPrintf(pCon, eError, "ERROR: %s while processing runscript for %s", @@ -423,7 +420,6 @@ static int ErrPause(void *pData) } /* OK now, continue */ - SetStatus(eEager); self->iWarned = 0; ContinueExecution(pExe); return 1; diff --git a/exebuf.c b/exebuf.c index 0ec9d5ce..69e2fbf9 100644 --- a/exebuf.c +++ b/exebuf.c @@ -323,7 +323,6 @@ int exeBufProcess(pExeBuf self, SicsInterp * pSics, DeleteDynString(command); if (SCGetInterrupt(pCon) >= eAbortBatch) { SCWrite(pCon, "ERROR: batch processing interrupted", eError); - SetStatus(eEager); if (pCall != NULL) { InvokeCallBack(pCall, BATCHEND, self->name); } @@ -375,7 +374,6 @@ int exeBufProcessErrList(pExeBuf self, SicsInterp * pSics, DeleteDynString(command); if (SCGetInterrupt(pCon) >= eAbortBatch) { SCWrite(pCon, "ERROR: batch processing interrupted", eError); - SetStatus(eEager); return 0; } else { SCSetInterrupt(pCon, eContinue); diff --git a/interface.c b/interface.c index 9ab9c52a..0e412b5b 100644 --- a/interface.c +++ b/interface.c @@ -240,7 +240,6 @@ static int DriveTaskFunc(void *data) } else { ExeInterest(pServ->pExecutor,taskData->name, "finished with problem"); } - SetStatus(eEager); return 0; } /*--------------------------------------------------------------------------*/ @@ -370,16 +369,6 @@ static int CountTaskFunc(void *data) assert(taskData != NULL); status = taskData->pCount->CheckCountStatus(taskData->obj,taskData->pCon); - if(status == HWBusy) { - SetStatus(eCounting); - return 1; - } else if(status == HWNoBeam){ - SetStatus(eOutOfBeam); - return 1; - } else if(status == HWPause){ - SetStatus(ePaused); - return 1; - } taskData->pCount->TransferData(taskData->obj, taskData->pCon); diff --git a/macro.c b/macro.c index 76f3d914..4e5ac5e1 100644 --- a/macro.c +++ b/macro.c @@ -474,8 +474,6 @@ int MacroFileEval(SConnection * pCon, SicsInterp * pInter, void *pData, } /* handle status first */ - eOld = GetStatus(); - SetStatus(eBatch); SICSLogWrite("Evaluating in MacroFileEval", eValue); SICSLogWrite(argv[1], eValue); @@ -500,7 +498,6 @@ int MacroFileEval(SConnection * pCon, SicsInterp * pInter, void *pData, Tcl_DStringAppend(&command, pBueffel, -1); pCom = Tcl_DStringValue(&command); if (Tcl_CommandComplete(pCom)) { - SetStatus(eEager); FirstWord(pCom, pBueffel); if (FindCommand(pInter, pBueffel) != NULL) { snprintf(pBueffel,sizeof(pBueffel)-1, "%s:%d>> %s", pFile, iLine, pCom); @@ -512,7 +509,6 @@ int MacroFileEval(SConnection * pCon, SicsInterp * pInter, void *pData, iLine++; } iRet = Tcl_Eval(pTcl, pCom); - SetStatus(eBatch); if (iRet != TCL_OK) { /* write TCL error and check for total interrupt */ if (Tcl_GetVar(pTcl, SICSERROR, TCL_GLOBAL_ONLY) == NULL) { /* Tcl error */ @@ -537,7 +533,6 @@ int MacroFileEval(SConnection * pCon, SicsInterp * pInter, void *pData, fclose(fp); Tcl_DStringFree(&command); SCWrite(pCon, "ERROR: batch processing interrupted", eError); - SetStatus(eEager); return 0; } else { SCSetInterrupt(pCon, eContinue); @@ -555,7 +550,6 @@ int MacroFileEval(SConnection * pCon, SicsInterp * pInter, void *pData, /* clean up */ fclose(fp); Tcl_DStringFree(&command); - SetStatus(eOld); SCSendOK(pCon); return 1; } diff --git a/multicountersec.c b/multicountersec.c index 08fbe915..71687a9b 100644 --- a/multicountersec.c +++ b/multicountersec.c @@ -318,20 +318,16 @@ static int isMultiMasterRunning(pCounter self, SConnection *pCon, int *status) UpdateHipadabaPar(stopTime,MakeHdbInt(time(NULL)),pCon); SecCounterSetError(self,"Master counter errror"); *status = HWBusy; - ClearFixedStatus(eCounting); break; case HWPause: UpdateHipadabaPar(myStatus,MakeHdbText("paused"),pCon); *status = HWPause; - SetStatusFixed(ePaused); break; case HWNoBeam: UpdateHipadabaPar(myStatus,MakeHdbText("nobeam"),pCon); *status = HWNoBeam; - SetStatusFixed(eOutOfBeam); break; default: - SetStatusFixed(eCounting); *status = HWBusy; UpdateHipadabaPar(myStatus,MakeHdbText("run"),pCon); if (self->iCallbackCounter > 20) { @@ -414,7 +410,6 @@ static void multiEndCounting(pCounter self, SConnection *pCon) InvokeCallBack(self->pCall, COUNTEND, NULL); ReleaseCountLock(self->pCountInt); MultiSecTransfer(self,pCon); - ClearFixedStatus(eEager); } /*-------------------------------------------------------------------------------------*/ @@ -432,7 +427,6 @@ static int MultiSecStatus(void *pData, SConnection * pCon) } if(areSlavesRunning(self,pCon, &status)){ - SetStatusFixed(eCounting); return status; } diff --git a/nserver.c b/nserver.c index e87287fb..6462eca5 100644 --- a/nserver.c +++ b/nserver.c @@ -458,14 +458,10 @@ int UserWait(SConnection * pCon, SicsInterp * pSics, void *pData, return 1; } - eOld = GetStatus(); - SetStatus(eUserWait); sWait.dFinish = DoubleTime() + (double)fVal; sWait.iEnd = 0; lID = TaskRegisterN(pTask,"wait", WaitTask, WaitSignal, NULL, &sWait, 1); - TaskWait(pTask, lID); - SetStatus(eOld); - if (SCGetInterrupt(pCon) != eContinue) { + TaskWait(pTask, lID); if (SCGetInterrupt(pCon) != eContinue) { return 0; } else { return 1; diff --git a/script.c b/script.c index 5568e3cf..4b667d3c 100644 --- a/script.c +++ b/script.c @@ -143,11 +143,17 @@ int SetSICSInterrupt(SConnection * pCon, SicsInterp * pSics, void *pData, return 1; } -/*-------------------------------------------------------------------------*/ +/*------------------------------------------------------------------------- +This method does nothing anymore. Status is now calculated from the state +of SICS and no longer explicitly set. I left the code in because I am to +lazy to find all use cases and eliminate them + +M.K. 07/2014 +--------------------------------------------------------------------------*/ int SetSICSStatus(SConnection * pCon, SicsInterp * pSics, void *pData, int argc, char *argv[]) { - int iInt; + int iInt = 0; char pBueffel[132]; assert(pCon); @@ -174,7 +180,7 @@ int SetSICSStatus(SConnection * pCon, SicsInterp * pSics, void *pData, /* actually do a job */ strtolower(argv[1]); - iInt = SetStatusFromText(argv[1]); + /* iInt = SetStatusFromText(argv[1]); */ if (iInt) { SCSendOK(pCon); return 1; diff --git a/status.c b/status.c index 0d7ba93d..e30db3c1 100644 --- a/status.c +++ b/status.c @@ -13,6 +13,10 @@ Reworked restore to keep parameters from uninitialized devices Mark Koennecke, November 2007 + Reworked to determine the status from the state of the machine rather then + from explicit sets on a global variable. Which caused trouble, trouble and more + trouble. Mark Koennecke, July 2015 + Copyright: Labor fuer Neutronenstreuung diff --git a/status.h b/status.h index 5d38f2b4..457c6fe8 100644 --- a/status.h +++ b/status.h @@ -27,19 +27,7 @@ typedef enum { } Status; /* for status display */ -void SetStatus(Status eNew); -int SetStatusFromText(char *text); void KillStatus(void *pData); -/** - * set a status and disallow any further changes to the status. This serves - * in order to prevent massive message flows to the client from status - * changes while processing synchronisation files - */ -void SetStatusFixed(Status eNew); -/** - * clear a fixed status again, status will be updated again. - */ -void ClearFixedStatus(Status eNew); Status GetStatus(void); void GetStatusText(char *buf, int iBufLen); diff --git a/stdscan.c b/stdscan.c index c0df18ff..d1cc0234 100644 --- a/stdscan.c +++ b/stdscan.c @@ -903,7 +903,6 @@ int ScanCount(pScanData self, int iPoint) SCWrite(self->pCon, "ERROR: Cannot Count, Scan aborted", eLogError); return 0; } - SetStatus(eCounting); /* wait for finish */ while(DevExecLevelRunning(pServ->pExecutor, RUNDRIVE)){ TaskYield(pServ->pTasker); diff --git a/synchronize.c b/synchronize.c index b8212a48..2f532467 100644 --- a/synchronize.c +++ b/synchronize.c @@ -175,7 +175,6 @@ tryagain: /* first tell the remote server to backup */ - SetStatusFixed(eBatch); strcpy(pBueffel, "transact syncbackup"); if (syncFile != NULL) { strcat(pBueffel, " "); @@ -187,7 +186,6 @@ tryagain: NETClosePort(connection); free(connection); connection = NULL; - ClearFixedStatus(eEager); if (try > 0) goto tryagain; SCWrite(pCon, "ERROR: Failed to contact main SICS server", eError); @@ -207,7 +205,6 @@ tryagain: NETClosePort(connection); free(connection); connection = NULL; - ClearFixedStatus(eEager); pServ->simMode = 1; if (try > 0) goto tryagain; @@ -247,7 +244,6 @@ tryagain: internalCon = SCCreateDummyConnection(pSics); if (internalCon == NULL) { SCWrite(pCon, "ERROR: out of memory in sync", eError); - ClearFixedStatus(eEager); return 0; } @@ -258,7 +254,6 @@ tryagain: } test = InterpExecute(pSics, internalCon, pBueffel); SCDeleteConnection(internalCon); - ClearFixedStatus(eEager); if (test != 1) { SCWrite(pCon, "ERROR: Failed to read sync information", eError); return 0; diff --git a/tasscanub.c b/tasscanub.c index 5e6cb5de..92d060c1 100644 --- a/tasscanub.c +++ b/tasscanub.c @@ -771,7 +771,6 @@ static int TASUBScanCount(pScanData self, int iPoint) } else { status = 1; } - SetStatus(eOld); return status; } diff --git a/velo.c b/velo.c index 797bcc23..500d60e2 100644 --- a/velo.c +++ b/velo.c @@ -588,10 +588,7 @@ int VSGetLossCurrent(pVelSel self, SConnection * pCon, float *fLoss) assert(self); assert(pCon); - eOld = GetStatus(); - SetStatus(eRunning); iRet = self->pDriv->GetLossCurrent(self->pDriv, fLoss); - SetStatus(eOld); if (!iRet) { self->pDriv->GetError(self->pDriv, &iCode, pError, 131); snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s while trying to measure loss current", @@ -1161,9 +1158,7 @@ int VelSelAction(SConnection * pCon, SicsInterp * pSics, void *pData, eError); return 0; } - SetStatus(eDriving); iRet = VSSetTiltRot(self, pCon, fRot, fTilt); - SetStatus(eEager); if (iRet) { SCSendOK(pCon); return 1;