From c60e9920c5d1e36261fdbc4ac639f11fab3e4b61 Mon Sep 17 00:00:00 2001 From: Koennecke Mark Date: Wed, 20 May 2015 08:55:49 +0200 Subject: [PATCH] First working verion of remote object Fixed two bugs along the way: - asynnet: ANETReadPtr now sets length to 0 if ther eis no data - motorsec: if the motor does not start the status is set to error --- asynnet.c | 1 + motorsec.c | 2 +- remoteobject.c | 97 ++++++++++++++++++++++++++++++++------------------ 3 files changed, 65 insertions(+), 35 deletions(-) diff --git a/asynnet.c b/asynnet.c index 46592d9b..7b707e61 100644 --- a/asynnet.c +++ b/asynnet.c @@ -581,6 +581,7 @@ void *ANETreadPtr(int handle, int *length) con = findSocketDescriptor(handle); if (con == NULL) { + *length = 0; return NULL; } else { data = GetRWBufferData(con->readBuffer, length); diff --git a/motorsec.c b/motorsec.c index 0288e4bc..723326f7 100644 --- a/motorsec.c +++ b/motorsec.c @@ -527,7 +527,7 @@ static hdbCallbackReturn SecMotorCallback(pHdb node, void *userData, SCSetInterrupt(pCon, eAbortBatch); self->pDrivInt->iErrorCount = 0; child = GetHipadabaNode(self->pDescriptor->parNode, "status"); - UpdateHipadabaPar(child, MakeHdbText("run"), pCon); + UpdateHipadabaPar(child, MakeHdbText("error"), pCon); return hdbAbort; } diff --git a/remoteobject.c b/remoteobject.c index af72556e..0e78a3a4 100644 --- a/remoteobject.c +++ b/remoteobject.c @@ -489,6 +489,44 @@ static OutCode findOutCode(char *txt) return eValue; } /*-----------------------------------------------------------------------------------*/ +static void CheckWriteList(int writeList,int transID, OutCode eOut, char *pText) +{ + int status; + writeData WD; + + status = LLDnodePtr2First(writeList); + while(status == 1){ + LLDblobData(writeList,&WD); + if(WD.transID == transID){ + if(strstr(pText,"COMSTART") != NULL){ + /* skip */ + } else if(strstr(pText,"COMEND") != NULL && WD.waitTask == 0) { + SCDeleteConnection(WD.pCon); + LLDblobDelete(writeList); + return; + } else if(strstr(pText,"COMEND") != NULL && WD.waitTask == 1) { + /* skip */ + return; + } else if(strstr(pText,"TASKSTART") != NULL){ + WD.waitTask = 1 ; + LLDblobDelete(writeList); + LLDblobAppend(writeList,&WD, sizeof(writeData)); + return; + } else if(strstr(pText,"TASKEND") != NULL && WD.waitTask == 1){ + SCDeleteConnection(WD.pCon); + LLDblobDelete(writeList); + return; + } else { + if(strstr(pText,"OK") == NULL){ + SCWrite(WD.pCon,pText,eOut); + } + return; + } + } + status = LLDnodePtr2Next(writeList); + } + } +/*-----------------------------------------------------------------------------------*/ static int WriteResponseTask(void *pData) { pRemoteOBJ self = (pRemoteOBJ)pData; @@ -560,6 +598,7 @@ static int WriteResponseTask(void *pData) */ if(transID == POCHACT){ pText = ANETreadPtr(self->handle,&length); + json_object_put(message); continue; } @@ -567,41 +606,21 @@ static int WriteResponseTask(void *pData) process update messages */ if(transID == READACT){ - InterpExecute(pServ->pSics,pServ->dummyCon,pText); + if(strstr(pText,"hupdate") != NULL || strstr(pText,"prop") != NULL){ + InterpExecute(pServ->pSics,pServ->dummyCon,pText); + } traceIO("RO","Received %s from remote",pText); pText = ANETreadPtr(self->handle,&length); + json_object_put(message); continue; } + + /* + check write List + */ + CheckWriteList(self->writeList,transID,eOut,pText); + json_object_put(message); - status = LLDnodePtr2First(self->writeList); - while(status == 1){ - LLDblobData(self->writeList,&WD); - if(WD.transID == transID){ - if(strstr(pText,"COMSTART") != NULL){ - /* skip */ - } else if(strstr(pText,"COMEND") != NULL && WD.waitTask == 0) { - SCDeleteConnection(WD.pCon); - LLDblobDelete(self->writeList); - return 1; - } else if(strstr(pText,"COMEND") != NULL && WD.waitTask == 1) { - /* skip */ - return 1; - } else if(strstr(pText,"TASKSTART") != NULL){ - WD.waitTask = 1 ; - LLDblobDelete(self->writeList); - LLDblobAppend(self->writeList,&WD, sizeof(writeData)); - return 1; - } else if(strstr(pText,"TASKEND") != NULL && WD.waitTask == 1){ - SCDeleteConnection(WD.pCon); - LLDblobDelete(self->writeList); - return 1; - } else { - SCWrite(WD.pCon,pText,eOut); - return 1; - } - } - status = LLDnodePtr2Next(self->writeList); - } pText = ANETreadPtr(self->handle,&length); } @@ -661,10 +680,15 @@ static hdbCallbackReturn ROWriteCallback(pHdb currentNode, void *userData, free(command); DeleteDynString(data); if(status < 0){ - if(pCon != NULL){ - SCPrintf(pCon,eError,"ERROR: remote %s on %s disconnected", remoteNode, self->host); + self->connected = 0; + ConnectRemoteObject(self); + if(self->connected == 0){ + if(pCon != NULL){ + SCPrintf(pCon,eError,"ERROR: remote %s on %s disconnected", + remoteNode, self->host); + } + return hdbAbort; } - return hdbAbort; } return hdbContinue; } @@ -694,6 +718,11 @@ static int ConnectWrite(pRemoteOBJ self, SConnection *pCon, ReadData rd) SetHdbProperty(localNode,"remotewrite",rd.remoteNode); AppendHipadabaCallback(localNode, MakeHipadabaCallback(ROWriteCallback, self,NULL)); + /* + TODO: The connected write nodes should be held in a list in order to be able to + remove the write callbacks when deleting the remote object. As removing remote + objects usually only happens when SICS shuts down this is not so important. + */ /* * Get information about the remote node and check compatability @@ -764,7 +793,7 @@ static int RemoteExecute(pRemoteOBJ self, SConnection *pCon, char *command) */ memset(answer,0,sizeof(answer)-1); status = transactCommand(self->transactHandle,command,answer,sizeof(answer)); - if(status){ + if(status == 1){ SCWrite(pCon,answer,eValue); } else { SCPrintf(pCon,eError,"ERROR: Disconnected from %s %d", self->host, self->port);