예제 #1
0
	//Receive from module
	void Connection::receive(os::smart_ptr<crypto::message> msg, os::smart_ptr<MessageType> type)
	{
		if(!type || !msg)
			return;

		//IP address case
		if(type->getID() == ipAddressMess.getID())
		{
			std::string str = msg->popString();
			while(str!="")
			{
				manager->getLocalIP()->insert(IPAddress(str));
				str = msg->popString();
			}
			return;
		}

		//String case
		if(type->isString())
		{
			std::string str = msg->popString();
			while(str!="")
			{
				tnetout<<"Message from "<<getName()<<": "<<str<<std::endl;
				str = msg->popString();
			}
			return;
		}

		//Attempt to process messages
		manager->getMaster()->receiveMessage(msg,type,this);
	}
예제 #2
0
	//Receive a message
	//Triggered anytime a message is received
	void Controller::receiveMessage(os::smart_ptr<crypto::message> msg, os::smart_ptr<tnet::MessageType> type, os::smart_ptr<tnet::Connection> con)
	{
		if(!msg || !type || !con)
			return;

		if(type->getID()!=motorControlMessageType.getID() && type->getID()!=connectionListMessage.getID())
			return;

		//Pull from data
		os::smart_ptr<siblingData> tempDat(new siblingData(con),os::shared_type);
		auto fnd=connectionData.search(tempDat);
		if(!fnd) connectionData.insert(tempDat);
		else tempDat=&fnd;
		
		//Connection list case
		if(type->getID()==connectionListMessage.getID())
		{
			std::string strGroup,strName;
			strName=msg->popString();
			strGroup=msg->popString();
			while(strName!="" && strGroup!="")
			{
				auto temp=network()->find(strGroup,strName);
				if(temp)
					tempDat->eligibleConnections.insert(temp);
				strName=msg->popString();
				strGroup=msg->popString();
			}
			return;
		}
		tempDat->remoteType=msg->data()[1];

		//Joystick case
		if(tempDat->remoteType==RemoteController::JOYSTICK)
		{
			tempDat->xVal=(float)msg->data()[2]/256.0f;
			tempDat->yVal=(float)msg->data()[3]/256.0f;

			//Default settings
			tempDat->rightWheel=0;
			tempDat->leftWheel=0;

			tempDat->strMaster[0]="";
			tempDat->strMaster[1]="";

			tempDat->strConnection[0]="";
			tempDat->strConnection[1]="";
		}
		//Bot case
		else if(tempDat->remoteType==RemoteController::BOT)
		{
			tempDat->rightWheel=(float)msg->data()[2]/128.0f-1.0f;
			tempDat->leftWheel=(float)msg->data()[3]/128.0f-1.0f;

			char* strm;
			int arrSize;
			if(crypto::size::GROUP_SIZE>crypto::size::NAME_SIZE) arrSize=crypto::size::GROUP_SIZE;
			else arrSize=crypto::size::NAME_SIZE;
			strm=new char[arrSize+1];

			//Master name
			memset(strm,0,arrSize+1);
			memcpy(strm,msg->data()+4,crypto::size::GROUP_SIZE);
			tempDat->strMaster[0]=std::string(strm);
			memset(strm,0,arrSize+1);
			memcpy(strm,msg->data()+4+crypto::size::GROUP_SIZE,crypto::size::NAME_SIZE);
			tempDat->strMaster[1]=std::string(strm);

			//Connection name
			memset(strm,0,arrSize+1);
			memcpy(strm,msg->data()+4+crypto::size::GROUP_SIZE+crypto::size::NAME_SIZE,crypto::size::GROUP_SIZE);
			tempDat->strConnection[0]=std::string(strm);
			memset(strm,0,arrSize+1);
			memcpy(strm,msg->data()+4+2*crypto::size::GROUP_SIZE+crypto::size::NAME_SIZE,crypto::size::NAME_SIZE);
			tempDat->strConnection[1]=std::string(strm);

			delete [] strm;

			//Default settings
			tempDat->xVal=.5;
			tempDat->yVal=.5;
		}
		else tempDat->resetData();
	}