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
This commit is contained in:
2015-05-20 08:55:49 +02:00
parent 6f0e2e01df
commit c60e9920c5
3 changed files with 65 additions and 35 deletions

View File

@ -581,6 +581,7 @@ void *ANETreadPtr(int handle, int *length)
con = findSocketDescriptor(handle); con = findSocketDescriptor(handle);
if (con == NULL) { if (con == NULL) {
*length = 0;
return NULL; return NULL;
} else { } else {
data = GetRWBufferData(con->readBuffer, length); data = GetRWBufferData(con->readBuffer, length);

View File

@ -527,7 +527,7 @@ static hdbCallbackReturn SecMotorCallback(pHdb node, void *userData,
SCSetInterrupt(pCon, eAbortBatch); SCSetInterrupt(pCon, eAbortBatch);
self->pDrivInt->iErrorCount = 0; self->pDrivInt->iErrorCount = 0;
child = GetHipadabaNode(self->pDescriptor->parNode, "status"); child = GetHipadabaNode(self->pDescriptor->parNode, "status");
UpdateHipadabaPar(child, MakeHdbText("run"), pCon); UpdateHipadabaPar(child, MakeHdbText("error"), pCon);
return hdbAbort; return hdbAbort;
} }

View File

@ -489,6 +489,44 @@ static OutCode findOutCode(char *txt)
return eValue; 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) static int WriteResponseTask(void *pData)
{ {
pRemoteOBJ self = (pRemoteOBJ)pData; pRemoteOBJ self = (pRemoteOBJ)pData;
@ -560,6 +598,7 @@ static int WriteResponseTask(void *pData)
*/ */
if(transID == POCHACT){ if(transID == POCHACT){
pText = ANETreadPtr(self->handle,&length); pText = ANETreadPtr(self->handle,&length);
json_object_put(message);
continue; continue;
} }
@ -567,41 +606,21 @@ static int WriteResponseTask(void *pData)
process update messages process update messages
*/ */
if(transID == READACT){ 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); traceIO("RO","Received %s from remote",pText);
pText = ANETreadPtr(self->handle,&length); pText = ANETreadPtr(self->handle,&length);
json_object_put(message);
continue; 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); pText = ANETreadPtr(self->handle,&length);
} }
@ -661,10 +680,15 @@ static hdbCallbackReturn ROWriteCallback(pHdb currentNode, void *userData,
free(command); free(command);
DeleteDynString(data); DeleteDynString(data);
if(status < 0){ if(status < 0){
if(pCon != NULL){ self->connected = 0;
SCPrintf(pCon,eError,"ERROR: remote %s on %s disconnected", remoteNode, self->host); 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; return hdbContinue;
} }
@ -694,6 +718,11 @@ static int ConnectWrite(pRemoteOBJ self, SConnection *pCon, ReadData rd)
SetHdbProperty(localNode,"remotewrite",rd.remoteNode); SetHdbProperty(localNode,"remotewrite",rd.remoteNode);
AppendHipadabaCallback(localNode, MakeHipadabaCallback(ROWriteCallback, AppendHipadabaCallback(localNode, MakeHipadabaCallback(ROWriteCallback,
self,NULL)); 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 * 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); memset(answer,0,sizeof(answer)-1);
status = transactCommand(self->transactHandle,command,answer,sizeof(answer)); status = transactCommand(self->transactHandle,command,answer,sizeof(answer));
if(status){ if(status == 1){
SCWrite(pCon,answer,eValue); SCWrite(pCon,answer,eValue);
} else { } else {
SCPrintf(pCon,eError,"ERROR: Disconnected from %s %d", self->host, self->port); SCPrintf(pCon,eError,"ERROR: Disconnected from %s %d", self->host, self->port);