From a3605ea96bdbe87f5917666aef3d17e510f55108 Mon Sep 17 00:00:00 2001 From: Koennecke Mark Date: Tue, 30 Jun 2015 15:03:06 +0200 Subject: [PATCH] MultiCounterSec revised now passes self test --- countersec.c | 14 +++++++++++++- multicountersec.c | 26 ++++++++++++++++++++++---- status.c | 5 +++++ 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/countersec.c b/countersec.c index d2f5229d..8e3a6459 100644 --- a/countersec.c +++ b/countersec.c @@ -45,21 +45,33 @@ static void SecCounterSetError(pCounter self, char *text) /*---------------------------------------------------------------------------*/ int SecCtrInvokeFunction(pCounter self, SConnection *pCon, int code) { - pHdb node = NULL; + pHdb node = NULL, status = NULL; hdbValue v; node = GetHipadabaNode(self->pDes->parNode, "control"); + status = GetHipadabaNode(self->pDes->parNode, "status"); assert(node != NULL); + assert(status != NULL); v = MakeHdbFloat(code); + if(code != START && strcmp(status->value.v.text,"starting") == 0){ + UpdateHipadabaPar(node,MakeHdbText("run"),NULL); + } return SetHipadabaPar(node,v,pCon); } /*---------------------------------------------------------------------------*/ static int SecCtrHalt(void *pData) { pCounter self = (pCounter)pData; + pHdb node = NULL; + assert(self != NULL); SecCtrInvokeFunction(self,pServ->dummyCon, STOP); + node = GetHipadabaNode(self->pDes->parNode, "status"); + assert(node != NULL); + if(strcmp(node->value.v.text,"starting") == 0){ + UpdateHipadabaPar(node,MakeHdbText("run"),NULL); + } ReleaseCountLock(self->pCountInt); return 1; } diff --git a/multicountersec.c b/multicountersec.c index dc477ddd..b45e519b 100644 --- a/multicountersec.c +++ b/multicountersec.c @@ -17,6 +17,10 @@ #include #include #include "sicshipadaba.h" + +#define slaveSTARTING -100 + + /*---------------------------------------------------------------------------*/ typedef struct { float fPreset; @@ -39,15 +43,18 @@ static void SecCounterSetError(pCounter self, char *text) /*---------------------------------------------------------------------------------*/ static void doCountCommand(pHdb self, SConnection *pCon, int command) { - pHdb master = NULL, slaves = NULL; + pHdb master = NULL, slaves = NULL, status = NULL; char *pPtr, name[80]; pICountable pCount = NULL; void *data; master = GetHipadabaNode(self,"master"); slaves = GetHipadabaNode(self,"slaves"); + status = GetHipadabaNode(self,"status"); assert(master != NULL); assert(slaves != NULL); + assert(status != NULL); + /* treat master @@ -61,7 +68,12 @@ static void doCountCommand(pHdb self, SConnection *pCon, int command) pCount->Halt(data); break; case 1002: /*pause */ - pCount->Pause(data,pCon); + if(strcmp(status->value.v.text,"starting") == 0){ + SCWrite(pCon,"WARNINg: cannot pause when not yet started", eWarning); + return; + } else { + pCount->Pause(data,pCon); + } break; case 1003: /* continue */ pCount->Continue(data,pCon); @@ -177,7 +189,7 @@ static void startMultiCounting(pHdb self, SConnection *pCon) v = MakeHdbInt(slaveID); UpdateHipadabaPar(sID,v,pCon); - v = MakeHdbInt(-100); + v = MakeHdbInt(slaveSTARTING); UpdateHipadabaPar(mID,v,pCon); } @@ -195,10 +207,16 @@ static int checkSlavesStarted(pCounter self, SConnection *pCon) mID = GetHipadabaNode(self->objectNode,"masterID"); assert(mID != NULL); - if(mID->value.v.intValue != -100){ + if(mID->value.v.intValue != slaveSTARTING){ return 1; } + if(SCGetInterrupt(pCon) != eContinue) { + doCountCommand(self->objectNode,pCon,1001); + mID->value.v.intValue = -1; + return 0; + } + slaves = GetHipadabaNode(self->objectNode,"slaves"); assert(slaves != NULL); diff --git a/status.c b/status.c index c850e698..5cbef9a6 100644 --- a/status.c +++ b/status.c @@ -391,6 +391,11 @@ static int CheckCountStatus(void *message, void *userData) pTaskHead it; CountTaskData *countTask = NULL; + /* + This function shall never induce an interrupt + */ + SCSetInterrupt(pServ->dummyCon,eContinue); + if(*status == eCounting){ for(it = TaskIteratorStart(pServ->pTasker); it != NULL; it = TaskIteratorNext(it)){ countTask = (CountTaskData *)GetTaskData(it);