当前位置: 首页>>代码示例>>C++>>正文


C++ Packet::FromBytes方法代码示例

本文整理汇总了C++中Packet::FromBytes方法的典型用法代码示例。如果您正苦于以下问题:C++ Packet::FromBytes方法的具体用法?C++ Packet::FromBytes怎么用?C++ Packet::FromBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Packet的用法示例。


在下文中一共展示了Packet::FromBytes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: run

void Server::run()
{
	Packet * pPacket = NULL, * pNewPacket = NULL;
	unsigned char * pNewMessage;
	int iNewMessageLength = 0;
	in_addr_t ipTX;
	std::map<in_addr_t, in_addr_t> mapNewCars;
	struct timeval tWait = MakeTime(SERVER_WAIT_SECS, SERVER_WAIT_USECS);
	std::map<in_addr_t, std::vector<Packet *> >::iterator iterPackets;
	std::map<in_addr_t, Buffer>::iterator iterBuffer;
	std::map<in_addr_t, CarModel *> * pCarRegistry;
	std::map<in_addr_t, InfrastructureNodeModel *> * pNodeRegistry;
	std::map<in_addr_t, CarModel *>::iterator iterCarReceiver;
	std::map<in_addr_t, InfrastructureNodeModel *>::iterator iterNode;
	struct timeval tRX;
	char iRSSI, iSNR;
	fd_set rfds;
	std::list<ReadBuffer> listRead;
	std::list<ReadBuffer>::iterator iterRead;

	while (!m_bCancelled)
	{
		// get any waiting messages
		m_mutexConnections.lock();
		if (FillFDs(&rfds) && Select(&rfds, tWait))
		{
			Read(&rfds, listRead);
			for (iterRead = listRead.begin(); iterRead != listRead.end(); ++iterRead)
			{
				ipTX = ntohl(iterRead->sFrom.sin_addr.s_addr);
				// if new message is not null, add it to the current buffer
				if (iterRead->pData != NULL)
					m_mapBuffers[ipTX] += Buffer(iterRead->pData, iterRead->iLength);
			}
			listRead.clear();
		}
		m_mutexConnections.unlock();

		// process non-empty buffers into messages
		for (iterBuffer = m_mapBuffers.begin(); iterBuffer != m_mapBuffers.end(); ++iterBuffer)
		{
			if (iterBuffer->second.m_iLength > 0)
			{
				//printf("processing buffer..........\n");
				//fflush(stdout);
				unsigned char * pNew = NULL;

				pCarRegistry = g_pCarRegistry->acquireLock();
				pNodeRegistry = g_pInfrastructureNodeRegistry->acquireLock();
				m_mutexBuffers.lock();
				pNewMessage = iterBuffer->second.m_pData;
				iNewMessageLength = (signed)iterBuffer->second.m_iLength;
				tRX = GetCurrentTime();
				iRSSI = rssi();
				iSNR = snr();
				while (iNewMessageLength >= (signed)PACKET_MINIMUM_LENGTH && (pPacket = CreatePacket(*(const PacketType *)pNewMessage)) != NULL) {
					//printf("got packet...\n");
					if (!pPacket->FromBytes(pNewMessage, iNewMessageLength))
					{
						//printf("failed...\n");
						DestroyPacket(pPacket);
						iNewMessageLength = 0;
						break;
					}

					//if(((SafetyPacket*)pPacket)->m_ePacketType == ptSafety)
					//	printf("data: %s\n", ((SafetyPacket*)pPacket)->m_pData);
					//if(((Packet*)pPacket)->m_ePacketType == ptGeneric)
					//	printf("long: %ld\n", ((Packet*)pPacket)->m_ptTXPosition.m_iLong);
					// add it to the proper message buffer
					pPacket->m_tRX = tRX;
					pPacket->m_iRSSI = iRSSI;
					pPacket->m_iSNR = iSNR;

					pNewPacket = pPacket->clone();
					for (iterCarReceiver = pCarRegistry->begin(); iterCarReceiver != pCarRegistry->end(); ++iterCarReceiver)
					{
						if (iterCarReceiver->second != NULL && iterCarReceiver->second->GetOwnerIPAddress() == CARMODEL_IPOWNER_LOCAL && iterCarReceiver->first != pPacket->m_ipTX) {
							pNewPacket->m_ipRX = iterCarReceiver->first;
							iterCarReceiver->second->ReceivePacket(pNewPacket);
						}
					}

					for (iterNode = pNodeRegistry->begin(); iterNode != pNodeRegistry->end(); ++iterNode)
					{
						if (iterNode->second != NULL && iterNode->first != pPacket->m_ipTX)
						{
							pNewPacket->m_ipRX = iterNode->first;
							iterNode->second->ReceivePacket(pNewPacket);
						}
					}
					DestroyPacket(pNewPacket);

					iterCarReceiver = pCarRegistry->find(pPacket->m_ID.srcID.ipCar);
					iterNode = pNodeRegistry->find(pPacket->m_ID.srcID.ipCar);

					if ((iterCarReceiver == pCarRegistry->end() || iterCarReceiver->second == NULL || iterCarReceiver->second->GetOwnerIPAddress() != CARMODEL_IPOWNER_LOCAL) && (iterNode == pNodeRegistry->end() || iterNode->second == NULL))
					{
						//printf("processing..................................\n");
						mapNewCars[pPacket->m_ID.srcID.ipCar] = iterBuffer->first;
//.........这里部分代码省略.........
开发者ID:vigneshananth,项目名称:Groovenet-Qt4,代码行数:101,代码来源:Network.cpp


注:本文中的Packet::FromBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。