- Reworked the connection object and the IO system
- Reworked the support for TRICS - Added a second generation motor
This commit is contained in:
47
protocol.c
47
protocol.c
@ -173,7 +173,7 @@ void DeleteProtocol(void *self)
|
||||
/*------------------------------------------------------------------*/
|
||||
static int ContextDo(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
int argc, char *argv[]){
|
||||
commandContext comCon;
|
||||
SConnection *comCon = NULL;
|
||||
char buffer[1024];
|
||||
char *command;
|
||||
int status;
|
||||
@ -183,23 +183,27 @@ static int ContextDo(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
return 0;
|
||||
}
|
||||
|
||||
status = Tcl_GetInt(pSics->pTcl,argv[1],&comCon.transID);
|
||||
comCon = SCCopyConnection(pCon);
|
||||
if(comCon == NULL){
|
||||
SCWrite(pCon,"EROOR: out of memory in contextdo", eError);
|
||||
return 0;
|
||||
}
|
||||
status = Tcl_GetInt(pSics->pTcl,argv[1],&comCon->transID);
|
||||
if(status != TCL_OK){
|
||||
snprintf(buffer,1023,"ERROR: failed to convert %s to transaction ID", argv[1]);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
return 0;
|
||||
}
|
||||
strncpy(comCon.deviceID,argv[2],SCDEVIDLEN);
|
||||
strncpy(comCon->deviceID,argv[2],SCDEVIDLEN);
|
||||
memset(buffer,0,sizeof(buffer));
|
||||
command = Arg2Tcl(argc-2,&argv[2],buffer,sizeof buffer);
|
||||
if (!command) {
|
||||
SCWrite(pCon,"ERROR: no more memory",eError);
|
||||
return 0;
|
||||
}
|
||||
SCPushContext2(pCon,comCon);
|
||||
status = InterpExecute(pSics,pCon,command);
|
||||
status = InterpExecute(pSics,comCon,command);
|
||||
if (command != buffer) free(command);
|
||||
SCPopContext(pCon);
|
||||
SCDeleteConnection(comCon);
|
||||
return status;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
@ -236,7 +240,7 @@ static int ProtocolOptions(SConnection* pCon, pProtocol pPro)
|
||||
for(i=0;i<pPro->iNumPros;i++)
|
||||
{
|
||||
sprintf(pBuffer,"Protocol[%d] = %s",i,pPro->pProList[i]);
|
||||
SCWrite(pCon,pBuffer,eStatus);
|
||||
SCWrite(pCon,pBuffer,eValue);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -246,18 +250,22 @@ static int ProtocolHelp(SConnection* pCon, Protocol* pPro)
|
||||
{
|
||||
SCWrite(pCon,
|
||||
"Usage: protocol {help|list|options|reset} | set protocolName",
|
||||
eStatus);
|
||||
eValue);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
static int ProtocolSet(SConnection* pCon, Protocol* pPro, char *pProName)
|
||||
{
|
||||
SConnection *pMaster = NULL;
|
||||
|
||||
int proID;
|
||||
if(!SCVerifyConnection(pCon))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
pMaster = SCfindMaster(pCon);
|
||||
assert(pMaster != NULL);
|
||||
|
||||
/* lazy initialisation of defaultWriter since connection is verified */
|
||||
InitDefaultProtocol(pCon,pPro);
|
||||
@ -278,28 +286,35 @@ static int ProtocolSet(SConnection* pCon, Protocol* pPro, char *pProName)
|
||||
break;
|
||||
|
||||
case 1: /* normal (connection start default) */
|
||||
SCSetWriteFunc(pCon,SCNormalWrite);
|
||||
SCSetWriteFunc(pMaster,SCNormalWrite);
|
||||
SCSetWriteFunc(pCon,SCNormalWrite);
|
||||
break;
|
||||
|
||||
case 2: /* outcodes */
|
||||
SCSetWriteFunc(pCon,SCWriteWithOutcode);
|
||||
SCSetWriteFunc(pMaster,SCWriteWithOutcode);
|
||||
SCSetWriteFunc(pCon,SCWriteWithOutcode);
|
||||
break;
|
||||
|
||||
case 3: /* sycamore */
|
||||
SCSetWriteFunc(pCon,SCWriteSycamore);
|
||||
SCSetWriteFunc(pMaster,SCWriteSycamore);
|
||||
SCSetWriteFunc(pCon,SCWriteSycamore);
|
||||
break;
|
||||
case 4: /* json */
|
||||
SCSetWriteFunc(pCon,SCWriteJSON_String);
|
||||
SCSetWriteFunc(pCon,SCWriteJSON_String);
|
||||
SCSetWriteFunc(pMaster,SCWriteJSON_String);
|
||||
break;
|
||||
case 5:
|
||||
SCSetWriteFunc(pCon,SCACTWrite);
|
||||
SCSetWriteFunc(pMaster,SCACTWrite);
|
||||
SCSetWriteFunc(pCon,SCACTWrite);
|
||||
break;
|
||||
case 0: /* default = psi_sics */
|
||||
default:
|
||||
SCSetWriteFunc(pCon,pPro->defaultWriter);
|
||||
SCSetWriteFunc(pMaster,pPro->defaultWriter);
|
||||
SCSetWriteFunc(pCon,pPro->defaultWriter);
|
||||
break;
|
||||
}
|
||||
pCon->iProtocolID = proID;
|
||||
pMaster->iProtocolID = proID;
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
@ -356,7 +371,7 @@ static int ProtocolList(SConnection* pCon, Protocol* pPro)
|
||||
{
|
||||
SCWrite(pCon,
|
||||
"Usage: protocol {help|list|options|reset} | set protocolName",
|
||||
eStatus);
|
||||
eValue);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -589,7 +604,6 @@ int SCWriteSycamore(SConnection *pCon, char *pBuffer, int iOut)
|
||||
/* first the socket */
|
||||
/*strcat(pMsg, pBueffel);*/
|
||||
iRet = SCDoSockWrite(pCon,GetCharArray(pMsg));
|
||||
SCWriteToLogFiles(pCon,GetCharArray(pMsg));
|
||||
}
|
||||
if (pMsg != NULL)
|
||||
DeleteDynString(pMsg);
|
||||
@ -742,7 +756,6 @@ int SCWriteJSON_String(SConnection *pCon, char *pBuffer, int iOut)
|
||||
iRet = 0;
|
||||
} else {
|
||||
iRet = SCDoSockWrite(pCon,json_object_to_json_string(my_object));
|
||||
SCWriteToLogFiles(pCon,pBuffer);
|
||||
}
|
||||
}
|
||||
if (tmp_json != NULL && !is_error(tmp_json))
|
||||
|
Reference in New Issue
Block a user