示例#1
0
//-----------------------------------------------
bool CanESD::receiveMsgRetry(CanMsg* pCMsg, int iNrOfRetry)
{
	CMSG NTCANMsg;
	NTCANMsg.len = 8;
	
	int32_t len;
	int i, ret;
	bool bRet = true;

	i=0;
	do
	{
		len = 1;
		ret = canTake(m_Handle, &NTCANMsg, &len);
		i++;
		Sleep(10);
	}
	while((len != 1) && (i < iNrOfRetry));

	if(i == iNrOfRetry)
	{
		std::cout << "PCan:ReceiveMessage error, msg code= " << m_LastID << std::endl;
		bRet = false;
	}
	else
	{
		pCMsg->m_iID = NTCANMsg.id;
		pCMsg->set(NTCANMsg.data[0], NTCANMsg.data[1], NTCANMsg.data[2], NTCANMsg.data[3],
			NTCANMsg.data[4], NTCANMsg.data[5], NTCANMsg.data[6], NTCANMsg.data[7]);
	}
	return bRet;
}
示例#2
0
文件: engine.cpp 项目: nicklv/pushpin
	void tryTakeSocket()
	{
		if(!canTake())
			return;

		ZWebSocket *sock = zhttpIn->takeNextSocket();
		if(!sock)
			return;

		QUrl requestUri = sock->requestUri();

		log_info("IN ws id=%s, %s", sock->rid().second.data(), requestUri.toEncoded().data());

		bool isSecure = (requestUri.scheme() == "wss");
		QString host = requestUri.host();

		// look up the route
		DomainMap::Entry route = domainMap->entry(DomainMap::WebSocket, isSecure, host, requestUri.encodedPath());

		// before we do anything else, see if this is a sockjs request
		if(!route.isNull() && !route.sockJsPath.isEmpty() && requestUri.encodedPath().startsWith(route.sockJsPath))
		{
			sockJsManager->giveSocket(sock, route.sockJsPath.length(), route.sockJsAsPath, route);
			return;
		}

		log_debug("creating wsproxysession for zws id=%s", sock->rid().second.data());
		doProxySocket(sock, route);
	}
示例#3
0
/*
	method to add a Card to the discard pile
*/
void DiscardPile::addCard(Card aCard){
	if(canTake(aCard))
	{	
		CardPile::addCard(aCard);
		if(!thePile.back().getFaceUp())
			thePile.back().flip();
	}
}
示例#4
0
//-----------------------------------------------
bool CanESD::receiveMsgRetry(CanMsg* pCMsg, int iNrOfRetry)
{
	int id = pCMsg->m_iID;
	CMSG NTCANMsg;
	NTCANMsg.len = 8;
	
	//long len;
	int32_t len;
	int i, ret;
	bool bRet = true;
	
	i=0;
	
	len = 1;
	//NTCANMsg.id = pCMsg->m_iID;
	//ret = canTake(m_Handle, &NTCANMsg, &len);
	/**/
	do
	{
		len = 1;
		//m_Mutex.lock();
		ret = canTake(m_Handle, &NTCANMsg, &len);
		//m_Mutex.unlock();
		//if( NTCANMsg.id == id ) break;
		i++;
		sleep(0.01);
	}
	//while((len != 1) && (i < iNrOfRetry));
	//while((len != 1) && (i < iNrOfRetry));
	while((len == 0) && (i < iNrOfRetry));
	/**/
	
	//if((i == iNrOfRetry) || (ret != NTCAN_SUCCESS ))
	if(i == iNrOfRetry)
	//if( (ret != NTCAN_SUCCESS) || (len & 0x10) || (len == 0) )
	{
		if( ret != NTCAN_SUCCESS )
			std::cout << "error in CANESD::receiveMsgRetry: " << GetErrorStr(ret) << std::endl;
		//std::cout << "PCan:ReceiveMessage error, msg id= " << m_LastID << std::endl;
		//std::cout.unsetf(std::ios::dec);
		//std::cout.setf(std::ios::hex);
		//std::cout << "PCan:ReceiveMessage error, msg id= " << pCMsg->m_iID << std::endl;
		//std::cout.unsetf(std::ios::hex);
		//std::cout.setf(std::ios::dec);
		bRet = false;
	}
	else
	{
		pCMsg->m_iID = NTCANMsg.id;
		pCMsg->m_iLen = NTCANMsg.len;
		pCMsg->set(NTCANMsg.data[0], NTCANMsg.data[1], NTCANMsg.data[2], NTCANMsg.data[3],
			NTCANMsg.data[4], NTCANMsg.data[5], NTCANMsg.data[6], NTCANMsg.data[7]);
	}
		
	//readEvent();

	return bRet;
}
int CESDDevice::readDevice(CProtocolMessage& rclProtocolMessage)
{
	int iRetVal = 0;
	long iNumberOfMessages = 1;
	CMSG clESDProtocolMessage;
	m_iErrorState = 0;

#if defined ( _WIN32 )
	float fTimeDiff = 0;
	double dFrequency = 0;
	LARGE_INTEGER liTime, liTimeStart, liTimeEnd;

	QueryPerformanceFrequency( &liTime );
	dFrequency = liTime.LowPart;

	QueryPerformanceCounter( &liTimeStart );
	do
	{
		iNumberOfMessages = 1;
		iRetVal = canTake( m_hDevice, &clESDProtocolMessage, &iNumberOfMessages );	
		if(iRetVal != NTCAN_SUCCESS)
		{
			warning("can read failed Errorcode: %d", iRetVal);
			m_iErrorState = getDeviceError(iRetVal);
			return m_iErrorState;
		}
		QueryPerformanceCounter( &liTimeEnd );
		fTimeDiff = (float)(liTimeEnd.LowPart - liTimeStart.LowPart) / (float)dFrequency * 1000;

		if( fTimeDiff >= m_uiTimeOut )
		{
			m_iErrorState = ERRID_DEV_READTIMEOUT;
			return m_iErrorState;
		}

	} while( iNumberOfMessages == 0 );
#else
	iRetVal = canRead(m_hDevice, &clESDProtocolMessage, &iNumberOfMessages, NULL);			
	if(iRetVal != NTCAN_SUCCESS)
	{
		warning("can read failed Errorcode: %d", iRetVal);
		m_iErrorState = getDeviceError(iRetVal);
		return m_iErrorState;
	}
#endif

	rclProtocolMessage.m_uiMessageId = clESDProtocolMessage.id;
	rclProtocolMessage.m_ucMessageLength = clESDProtocolMessage.len;
	memcpy(rclProtocolMessage.m_aucMessageData, clESDProtocolMessage.data, rclProtocolMessage.m_ucMessageLength);
        printMessage(rclProtocolMessage,READ);

	return m_iErrorState;
}
示例#6
0
文件: engine.cpp 项目: nicklv/pushpin
	void tryTakeSockJsSession()
	{
		if(!canTake())
			return;

		SockJsSession *sock = sockJsManager->takeNext();
		if(!sock)
			return;

		log_info("IN sockjs obj=%p %s", sock, sock->requestUri().toEncoded().data());

		log_debug("creating wsproxysession for sockjs=%p", sock);
		doProxySocket(sock, sock->route());
	}
示例#7
0
文件: engine.cpp 项目: nicklv/pushpin
	void tryTakeRequest()
	{
		if(!canTake())
			return;

		ZhttpRequest *req = zhttpIn->takeNextRequest();
		if(!req)
			return;

		RequestSession *rs = new RequestSession(domainMap, sockJsManager, inspect, inspectChecker, accept, this);
		connect(rs, SIGNAL(inspected(const InspectData &)), SLOT(rs_inspected(const InspectData &)));
		connect(rs, SIGNAL(inspectError()), SLOT(rs_inspectError()));
		connect(rs, SIGNAL(finished()), SLOT(rs_finished()));
		connect(rs, SIGNAL(finishedByAccept()), SLOT(rs_finishedByAccept()));

		rs->setAutoCrossOrigin(config.autoCrossOrigin);

		requestSessions += rs;

		rs->start(req);
	}
示例#8
0
//-----------------------------------------------
bool CanESD::receiveMsg(CanMsg* pCMsg)
{
  
	CMSG NTCANMsg;
	NTCANMsg.len = 8;

	int ret;
	int32_t len;
	bool bRet = true;
	len = 1;
	//ret = canRead(m_Handle, &NTCANMsg, &len, NULL);
	ret = canTake(m_Handle, &NTCANMsg, &len);
	
	if (len == 1)
	{
		// message received
		pCMsg->m_iID = NTCANMsg.id;
		pCMsg->set(NTCANMsg.data[0], NTCANMsg.data[1], NTCANMsg.data[2], NTCANMsg.data[3],
			NTCANMsg.data[4], NTCANMsg.data[5], NTCANMsg.data[6], NTCANMsg.data[7]);
		bRet = true;
	}
	else
	{
		// no message
		if( ret != NTCAN_SUCCESS)
		{
			// error
			LOGERROR("canTake() failed: " << getErrorMessage(ret));
			
		}

		pCMsg->m_iID = NTCANMsg.id;
		pCMsg->set(0,0,0,0,0,0,0,0);

		bRet = false;
	}
	return bRet;
}