From 72f9e59150eeb35ed797081338812a9a022949ac Mon Sep 17 00:00:00 2001 From: Mark Koennecke Date: Mon, 5 May 2014 13:52:00 +0200 Subject: [PATCH] Multiple bug fixes - Arrayutil was not summing correctly - Added interest to motorsec in order to support old status clients - core dump because of bad free in devser - fixed transferring of count time in multicounter - added stack debugging to sllinux_def - Modifications to tasdrive to wait for finish of monochromator properly --- arrayutil.c | 15 ++++++--- counter.c | 6 ++-- countersec.c | 37 ++++++++++++++++++++++ devser.c | 3 +- motorsec.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++ multicountersec.c | 11 +++++-- sllinux_def | 2 +- tasdrive.c | 16 ++++++++-- 8 files changed, 156 insertions(+), 13 deletions(-) diff --git a/arrayutil.c b/arrayutil.c index 9d9c458a..4c352212 100644 --- a/arrayutil.c +++ b/arrayutil.c @@ -36,11 +36,18 @@ long sumWindow(int *data, int xstart, int xend, int xlength, } - for(j = ystart; j < yend; j++){ - row = data + j*xlength; - for(i = xstart; i < xend; i++){ - result += row[i]; + /* for(j = ystart; j < yend; j++){ */ + /* row = data + j*xlength; */ + /* for(i = xstart; i < xend; i++){ */ + /* result += row[i]; */ + /* } */ + /* } */ + for(i = xstart; i < xend; i++){ + row = data + i*ylength; + for(j = ystart; j < yend; j++){ + result += row[j]; } } + return result; } diff --git a/counter.c b/counter.c index 53b4ac80..38593a4e 100644 --- a/counter.c +++ b/counter.c @@ -835,7 +835,8 @@ int CountAction(SConnection * pCon, SicsInterp * pSics, void *pData, {"getpar", 2, {FUPATEXT, FUPAOPT}}, {"getnmon", 0, {0, 0}}, {"state", 0, {0, 0}}, - {"error", 0, {0, 0}} + {"error", 0, {0, 0}}, + {"countstatus", 0, {0, 0}} }; char *pMode[] = { "timer", @@ -852,7 +853,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, 26, argc - 1, argx, &PaRes); if (iRet < 0) { snprintf(pBueffel, 255,"%s", PaRes.pError); @@ -961,6 +962,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); diff --git a/countersec.c b/countersec.c index 9cad865a..5eb78ad5 100644 --- a/countersec.c +++ b/countersec.c @@ -9,6 +9,7 @@ * * Mark Koennecke, February 2009 */ +#include #include #include #include @@ -507,6 +508,41 @@ static int InterestCmd(pSICSOBJ ccmd, SConnection * con, } /*--------------------------------------------------------------------------*/ +static int CountStatusCmd(pSICSOBJ ccmd, SConnection * con, + Hdb * cmdNode, Hdb * par[], int nPar) +{ + float preset, done; + int exponent; + pHdb node, data; + + node = GetHipadabaNode(ccmd->objectNode,"preset"); + assert(node != NULL); + preset = node->value.v.doubleValue; + + node = GetHipadabaNode(ccmd->objectNode,"mode"); + assert(node != NULL); + strtolower(node->value.v.text); + if(strcmp(node->value.v.text,"timer") == 0) { + data = GetHipadabaNode(ccmd->objectNode,"time"); + assert(data != NULL); + done = data->value.v.doubleValue; + } else { + data = GetHipadabaNode(ccmd->objectNode,"values"); + assert(data != NULL); + done = data->value.v.intArray[0]; + data = GetHipadabaNode(ccmd->objectNode,"exponent"); + assert(data != NULL); + exponent = data->value.v.intValue; + if(exponent != 0){ + done /= pow(10,exponent); + } + } + SCPrintf(con,eValue,"%s.CountStatus = %f %f", + ccmd->objectNode->name, preset, done); + + return 1; +} +/*--------------------------------------------------------------------------*/ pCounter CreateSecCounter(SConnection *pCon, char *type, char *name, int length) { pCounter pRes = NULL; @@ -634,6 +670,7 @@ pCounter CreateSecCounter(SConnection *pCon, char *type, char *name, int length) child = AddSICSHdbPar(node,"pause", usUser, MakeSICSFunc(PauseCmd)); child = AddSICSHdbPar(node,"continue", usUser, MakeSICSFunc(ContinueCmd)); child = AddSICSHdbPar(node,"interest", usUser, MakeSICSFunc(InterestCmd)); + child = AddSICSHdbPar(node,"countstatus", usUser, MakeSICSFunc(CountStatusCmd)); return pRes; } diff --git a/devser.c b/devser.c index 0525188d..fc1f90b2 100644 --- a/devser.c +++ b/devser.c @@ -333,7 +333,8 @@ static void DevReset(DevSer * devser) devser->current->kill(devser->current->data); } devser->killCurrent = 0; - /* free(devser->current); */ + free(devser->current); + devser->current = NULL; } } diff --git a/motorsec.c b/motorsec.c index 3f6710b5..af3cf59e 100644 --- a/motorsec.c +++ b/motorsec.c @@ -47,6 +47,7 @@ #define ABS(x) (x < 0 ? -(x) : (x)) + /*-------------------------------------------------------------------------*/ static void SecMotorSetError(pMotor self, char *text) { @@ -655,6 +656,80 @@ static hdbCallbackReturn SecMotorZeroCallback(pHdb node, void *userData, return hdbContinue; } +/*--------------------------------------------------------------------------*/ +typedef struct { + char *pName; + SConnection *pCon; + float lastValue; +} MotInfo, *pMotInfo; +/*--------------------------------------------------------------------------*/ +static void KillInfo(void *pData) +{ + pMotInfo self = NULL; + + assert(pData); + self = (pMotInfo) pData; + if (self->pName) { + free(self->pName); + } + if (self->pCon != NULL) { + SCDeleteConnection(self->pCon); + } + free(self); +} +/*-------------------------------------------------------------------------*/ +static hdbCallbackReturn InterestCallback(pHdb node, void *userData, + pHdbMessage message) +{ + pHdbDataMessage mm = NULL; + pMotor self = (pMotor) userData; + float fVal; + hdbValue v; + pMotInfo priv = (pMotInfo)userData; + + + assert(self != NULL); + + mm = GetHdbUpdateMessage(message); + if (mm != NULL) { + v = *mm->v; + if(!SCisConnected(priv->pCon)){ + return hdbKill; + } + if(ABS(v.v.doubleValue - priv->lastValue) > .1) { + SCPrintf(priv->pCon,eValue,"%s.position = %f", + priv->pName, v.v.doubleValue); + priv->lastValue = v.v.doubleValue; + } + return hdbContinue; + } + return hdbContinue; +} +/*---------------------------------------------------------------------------*/ +static int InterestCmd(pSICSOBJ ccmd, SConnection * con, + Hdb * cmdNode, Hdb * par[], int nPar) +{ + pMotInfo priv = NULL; + + priv = malloc(sizeof(MotInfo)); + if(priv == NULL){ + SCWrite(con,"ERROR: out of memory registering interest",eError); + return 0; + } + + if(nPar >= 1 && (strcmp(par[0]->value.v.text,"UNKNOWN") != 0)) { + priv->pName = strdup(par[0]->value.v.text); + } else { + priv->pName = strdup(ccmd->objectNode->name); + } + priv->lastValue = .0; + priv->pCon = SCCopyConnection(con); + AppendHipadabaCallback(ccmd->objectNode, + MakeHipadabaCallback(InterestCallback,priv,KillInfo)); + SCSendOK(con); + return 1; + +} /*---------------------------------------------------------------------------*/ pMotor SecMotorInit(char *name) { @@ -793,6 +868,10 @@ pMotor SecMotorInit(char *name) child = MakeHipadabaNode("error", HIPTEXT, 1); AddHipadabaChild(node, child, NULL); + child = AddSICSHdbPar(node,"interest", usUser, MakeSICSFunc(InterestCmd)); + AddSICSHdbPar(child, "name", usUser, MakeHdbText("UNKNOWN")); + + pM->endScriptID = 0; /* initialise Drivable interface */ diff --git a/multicountersec.c b/multicountersec.c index 659b6486..3dc133f6 100644 --- a/multicountersec.c +++ b/multicountersec.c @@ -134,6 +134,7 @@ static void startMultiCounting(pHdb self, SConnection *pCon) assert(sID != NULL); assert(mID != NULL); + strtolower(mode->value.v.text); if(strcmp(mode->value.v.text,"timer") == 0) { eMode = eTimer; } else { @@ -234,12 +235,12 @@ static hdbCallbackReturn MultiSecControllCallback(pHdb node, /*-------------------------------------------------------------------------------------*/ static int isMultiMasterRunning(pCounter self, SConnection *pCon, int *status) { - pHdb mID, master, myStatus, control, ccd, stopTime; + pHdb mID, master, myStatus, control, ccd, stopTime, timeNode; hdbValue v; long mlID; void *data; pICountable pCount; - float controlVal; + float controlVal, tVal; mID = GetHipadabaNode(self->objectNode,"masterID"); master = GetHipadabaNode(self->objectNode,"master"); @@ -247,12 +248,14 @@ static int isMultiMasterRunning(pCounter self, SConnection *pCon, int *status) control = GetHipadabaNode(self->objectNode,"control"); ccd = GetHipadabaNode(self->objectNode,"ccd"); stopTime = GetHipadabaNode(self->objectNode,"stopTime"); + timeNode = GetHipadabaNode(self->objectNode,"time"); assert(mID != NULL); assert(master != NULL); assert(myStatus != NULL); assert(control != NULL); assert(ccd != NULL); assert(stopTime != NULL); + assert(timeNode != NULL); mlID = mID->value.v.intValue; @@ -269,6 +272,8 @@ static int isMultiMasterRunning(pCounter self, SConnection *pCon, int *status) *status = pCount->CheckCountStatus(data,pCon); controlVal = GetControlValue((pCounter)data); UpdateHipadabaPar(control,MakeHdbFloat(controlVal),pCon); + tVal = GetCountTime((pCounter)data,pCon); + UpdateHipadabaPar(timeNode,MakeHdbFloat(tVal),pCon); SecCounterSetError(self,"None"); switch(*status){ case HWFault: @@ -296,6 +301,8 @@ static int isMultiMasterRunning(pCounter self, SConnection *pCon, int *status) *status = HWBusy; UpdateHipadabaPar(myStatus,MakeHdbText("run"),pCon); UpdateHipadabaPar(stopTime,MakeHdbInt(time(NULL)),pCon); + tVal = GetCountTime((pCounter)data,pCon); + UpdateHipadabaPar(timeNode,MakeHdbFloat(tVal),pCon); if(ccd->value.v.intValue != 1) { doCountCommand(self->objectNode,pCon,1011); } diff --git a/sllinux_def b/sllinux_def index bdd73884..0ebae7a9 100644 --- a/sllinux_def +++ b/sllinux_def @@ -12,4 +12,4 @@ MFLAGS=-f makefile_linux$(DUMMY) HDFROOT=/afs/psi.ch/project/sinq/sl6 TCLINC=. -DBG= -g +DBG= -g -fstack-protector-all diff --git a/tasdrive.c b/tasdrive.c index 4ba2144f..4808f7ca 100644 --- a/tasdrive.c +++ b/tasdrive.c @@ -352,6 +352,7 @@ static int startMotors(ptasMot self, tasAngles angles, { double curve; int status, silent, stopFixed; + long monoID; silent = self->math->silent; stopFixed = self->math->stopFixed; @@ -363,9 +364,9 @@ static int startMotors(ptasMot self, tasAngles angles, monochromator */ status = self->math->mono->SetValue(self->math->monoData, - pCon,angles.monochromator_two_theta); + pCon,angles.monochromator_two_theta); /* - The call to CheckStatus is necessary because the eiger monochromator may not + The call to CheckStatus is necessary because the eiger monochromator may not start until then. Deferred until all parameters are known. */ self->math->mono->CheckStatus(self->math->monoData,pCon); @@ -374,6 +375,14 @@ static int startMotors(ptasMot self, tasAngles angles, } else { AddTaskToGroup(pServ->pTasker, self->math->monoTaskID, self->math->groupID); } + /* monoID = StartDriveTask(self->math->monoData, pCon,"mono", */ + /* angles.monochromator_two_theta); */ + /* self->math->mono->CheckStatus(self->math->monoData,pCon); */ + /* if(monoID < 0){ */ + /* SCWrite(pCon,"ERROR: failed to start monochromator",eLogError); */ + /* } else { */ + /* AddTaskToGroup(pServ->pTasker,monoID, self->math->groupID); */ + /* } */ /* analyzer @@ -588,7 +597,8 @@ static int checkMotors(ptasMot self, SConnection * pCon) { self->math->mustRecalculate = 1; - if(isTaskGroupRunning(pServ->pTasker,self->math->groupID)){ + if(isTaskGroupRunning(pServ->pTasker,self->math->groupID) || + isTaskGroupRunning(pServ->pTasker,self->math->monoTaskID)){ return HWBusy; } else { return HWIdle;