void LUA_RESET_CALLBACK(SLuaCallBack* p)
{
	p->outputArgCount=0;
	CLuaFunctionData D;
	int result=-1;
	if (D.readDataFromLua(p,inArgs_RESET,inArgs_RESET[0],LUA_RESET_COMMAND))
	{
		std::vector<CLuaFunctionDataItem>* inData=D.getInDataPtr();
		int port=inData->at(0).intData[0];
		CSimxSocket* s=allConnections.getConnectionFromPort(port);
		if (s!=NULL)
		{
			bool simulOnly=s->getActiveOnlyDuringSimulation();
			bool continuous=s->getContinuousService();
			bool debug=s->getDebug();
			int maxPacketS=s->getMaxPacketSize();
			bool triggerPreEnabled=s->getWaitForTriggerAuthorized();

			// Kill the thread/connection:
			allConnections.removeSocketConnection(s);
				
			// Now create a similar thread/connection:
			CSimxSocket* oneSocketConnection=new CSimxSocket(port,continuous,simulOnly,debug,maxPacketS,triggerPreEnabled);
			oneSocketConnection->start();
			allConnections.addSocketConnection(oneSocketConnection);
			
			result=1;
		}
		else
			simSetLastError(LUA_RESET_COMMAND,"Invalid port number."); // output an error
	}
	D.pushOutData(CLuaFunctionDataItem(result));
	D.writeDataToLua(p);
}
示例#2
0
void LUA_STOP_COMMAND_CALLBACK(SLuaCallBack* p)
{ // the callback function of the new Lua command
	int result=-1; // error

	if (p->inputArgCount>0)
	{ // Ok, we have at least 1 input argument
		if (p->inputArgTypeAndSize[0*2+0]==sim_lua_arg_int)
		{ // Ok, we have (at least) 1 int as argument
			CSimxSocket* s=allConnections.getConnectionFromPort(p->inputInt[0]);
			if ( (s!=NULL)&&s->getActiveOnlyDuringSimulation() )
			{
				allConnections.removeSocketConnection(s);
				result=1;
			}
			else
				simSetLastError(LUA_STOP_COMMAND,"Invalid port number."); // output an error
		}
		else
			simSetLastError(LUA_STOP_COMMAND,"Wrong argument type/size."); // output an error
	}
	else
		simSetLastError(LUA_STOP_COMMAND,"Not enough arguments."); // output an error

	// Now we prepare the return value:
	p->outputArgCount=1; // 1 return value
	p->outputArgTypeAndSize=(simInt*)simCreateBuffer(p->outputArgCount*2*sizeof(simInt)); // x return values takes x*2 simInt for the type and size buffer
	p->outputArgTypeAndSize[2*0+0]=sim_lua_arg_int;	// The return value is an int
	p->outputArgTypeAndSize[2*0+1]=1;				// Not used (table size if the return value was a table)
	p->outputInt=(simInt*)simCreateBuffer(1*sizeof(result)); // 1 int return value
	p->outputInt[0]=result; // This is the int value we want to return
}
void LUA_STOP_CALLBACK(SLuaCallBack* p)
{
	p->outputArgCount=0;
	CLuaFunctionData D;
	int result=-1;
	if (D.readDataFromLua(p,inArgs_STOP,inArgs_STOP[0],LUA_STOP_COMMAND))
	{
		std::vector<CLuaFunctionDataItem>* inData=D.getInDataPtr();
		int port=inData->at(0).intData[0];
		CSimxSocket* s=allConnections.getConnectionFromPort(port);
		if (s!=NULL)
		{
			if (!s->getContinuousService())
			{
				allConnections.removeSocketConnection(s);
				result=1;
			}
			else
				simSetLastError(LUA_STOP_COMMAND,"Can't stop a continuous remote API server service."); // output an error
		}
		else
			simSetLastError(LUA_STOP_COMMAND,"Invalid port number."); // output an error
	}
	D.pushOutData(CLuaFunctionDataItem(result));
	D.writeDataToLua(p);
}
示例#4
0
void LUA_RESET_COMMAND_CALLBACK(SLuaCallBack* p)
{ // the callback function of the new Lua command
	int result=-1; // error

	if (p->inputArgCount>0)
	{ // Ok, we have at least 1 input argument
		if (p->inputArgTypeAndSize[0*2+0]==sim_lua_arg_int)
		{ // Ok, we have (at least) 1 int as argument
			CSimxSocket* s=allConnections.getConnectionFromPort(p->inputInt[0]);
			if (s!=NULL)
			{
				bool simulOnly=s->getActiveOnlyDuringSimulation();
				bool debug=s->getDebug();
				int maxPacketS=s->getMaxPacketSize();
				bool triggerPreEnabled=s->getWaitForTriggerAuthorized();

				// Kill the thread/connection:
				allConnections.removeSocketConnection(s);
				
				// Now create a similar thread/connection:
				CSimxSocket* oneSocketConnection=new CSimxSocket(p->inputInt[0],simulOnly,debug,maxPacketS,triggerPreEnabled);
				oneSocketConnection->start();
				allConnections.addSocketConnection(oneSocketConnection);
				
				result=1;
			}
			else
				simSetLastError(LUA_RESET_COMMAND,"Invalid port number."); // output an error
		}
		else
			simSetLastError(LUA_RESET_COMMAND,"Wrong argument type/size."); // output an error
	}
	else
		simSetLastError(LUA_RESET_COMMAND,"Not enough arguments."); // output an error

	// Now we prepare the return value:
	p->outputArgCount=1; // 1 return value
	p->outputArgTypeAndSize=(simInt*)simCreateBuffer(p->outputArgCount*2*sizeof(simInt)); // x return values takes x*2 simInt for the type and size buffer
	p->outputArgTypeAndSize[2*0+0]=sim_lua_arg_int;	// The return value is an int
	p->outputArgTypeAndSize[2*0+1]=1;				// Not used (table size if the return value was a table)
	p->outputInt=(simInt*)simCreateBuffer(1*sizeof(result)); // 1 int return value
	p->outputInt[0]=result; // This is the int value we want to return
}