⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 conn5.c

📁 关于DeviceNet协议的仅限组2的从站代码
💻 C
📖 第 1 页 / 共 2 页
字号:
 *
 * Input:       	none	
 *                  
 * Output:      	none
 *
 * Side Effects:    none
 *
 * Overview:        Process data for this connection.
 *
 * Note:            This event occurs when the buffer has successfully
 *					placed the requested data on the bus.
 ********************************************************************/
void _Conn5TxEvent(void)
{
	#if CONN_MULTICAST_TX_FRAG		
	// If fragmented
	if (uConn5.attrib.produced_con_size.word > 8)
	{
		// Test the status of the process		
		if (uConn5.tx.fragFlags.bits.b0)
		{
			// Reset finish flag to be captured later
			uConn5.tx.fragFlags.bits.b0 = 0;
			
			// Set flag indicating data has been placed on the bus
 			_txFinFlags.bits.multi = 1; 	
 			
 			// Notify the application
 			UsrConnTxDataEvent(5);
		}
	}
	else
	#endif
	{
		// Set flag indicating data has been placed on the bus
 		_txFinFlags.bits.multi = 1; 
 		
 		// Notify the application
 		UsrConnTxDataEvent(5);
 	}
}





/*********************************************************************
 * Function:        unsigned char _Conn5ExplicitEvent(void)
 *
 * PreCondition:    none
 *
 * Input:       	none	
 *                  
 * Output:      	unsigned char success of the request
 *
 * Side Effects:    none
 *
 * Overview:        Handle explicit messaging for this instance
 *
 * Note:            None
 ********************************************************************/
unsigned char _Conn5ExplicitEvent(void)
{
	switch(mRouteGetServiceID())
   	{
   		case SRVS_GET_ATTRIB_SINGLE:
   			return (_Conn5GetAttrib());
   		case SRVS_SET_ATTRIB_SINGLE:
   			return (_Conn5SetAttrib());
   	   	default:
   			mRoutePutError(ERR_SERVICE_NOT_SUPPORTED);
   			break;
   	}
		
	return (1);
}


/*********************************************************************
 * Function:        unsigned char _Conn5GetAttrib()
 *
 * PreCondition:    none
 *
 * Input:       	none
 *                  
 * Output:      	unsigned char success of the request
 *
 * Side Effects:    none
 *
 * Overview:        Handle explicit messaging
 *
 * Note:            None
 ********************************************************************/
unsigned char _Conn5GetAttrib(void)
{
	UINT	work;
	USINT 	i;

	switch (mRouteGetAttributeID())
	{
		case	_ATTRIB_STATE:
			mRoutePutByte(uConn5.attrib.state);
			break;
		case	_ATTRIB_INSTANCE_TYPE:
			mRoutePutByte(1);
			break;
		case	_ATTRIB_CLASS_TRIGGER:
			mRoutePutByte(uConn5.attrib.transportClass.byte);
			break;
		case 	_ATTRIB_PRODUCED_CID:
			work.word = (uConn5.attrib.produced_cid.word >> 5);
			mRoutePutByte(work.bytes.LSB);
			mRoutePutByte(work.bytes.MSB);
			break;
		case	_ATTRIB_CONSUMED_CID:
			work.word = (uConn5.attrib.consumed_cid.word >> 5);
			mRoutePutByte(work.bytes.LSB);
			mRoutePutByte(work.bytes.MSB);
			break;	
		case 	_ATTRIB_INITIAL_COMM_CHAR:
			mRoutePutByte(0x01);
			break;
		case	_ATTRIB_PRODUCED_CONN_SIZE:
			mRoutePutByte(uConn5.attrib.produced_con_size.bytes.LSB);
			mRoutePutByte(uConn5.attrib.produced_con_size.bytes.MSB);
			break;
		case	_ATTRIB_CONSUMED_CONN_SIZE:
			mRoutePutByte(uConn5.attrib.consumed_con_size.bytes.LSB);
			mRoutePutByte(uConn5.attrib.consumed_con_size.bytes.MSB);
			break;
		case	_ATTRIB_EXPECTED_RATE:
			mRoutePutByte(uConn5.attrib.expected_packet_rate.bytes.LSB);
			mRoutePutByte(uConn5.attrib.expected_packet_rate.bytes.MSB);
			break;
		case	_ATTRIB_WDT_ACTION:
			mRoutePutByte(0x00);
			break;
		case	_ATTRIB_PRODUCED_CONN_PATH_LEN:
			mRoutePutByte(uConn5.attrib.produced_path_len.bytes.LSB);
			mRoutePutByte(uConn5.attrib.produced_path_len.bytes.MSB);
			break;
		case	_ATTRIB_PRODUCED_CONN_PATH:
			if (mRouteOutLen() > uConn5.attrib.produced_path_len.bytes.LSB)  
			{
				for (i = 0; i < (uConn5.attrib.produced_path_len.bytes.LSB); i++)
				{
					mRoutePutByte(uConn5.attrib.produced_path[i]);
				}
			}
			else
			{
   				mRoutePutError(ERR_REPLY_TOO_LARGE);
			}
			break;
		case	_ATTRIB_CONSUMED_CONN_PATH_LEN:
			mRoutePutByte(uConn5.attrib.consumed_path_len.bytes.LSB);
			mRoutePutByte(uConn5.attrib.consumed_path_len.bytes.MSB);
			break;
		case	_ATTRIB_CONSUMED_CONN_PATH:
			if (mRouteOutLen() > uConn5.attrib.consumed_path_len.bytes.LSB)  
			{
				for (i = 0; i < (uConn5.attrib.consumed_path_len.bytes.LSB); i++)
				{
					mRoutePutByte(uConn5.attrib.consumed_path[i]);
				}
			}
			else
			{
				mRoutePutError(ERR_REPLY_TOO_LARGE);
			}
			break;
		default:
			mRoutePutError(ERR_ATTRIB_NOT_SUPPORTED);
			break;
	}
	return(1);
}




/*********************************************************************
 * Function:        unsigned char _Conn5SetAttrib(void)
 *
 * PreCondition:    none
 *
 * Input:       	none
 *                  
 * Output:      	unsigned char success of the request
 *
 * Side Effects:    none
 *
 * Overview:        Handle explicit messaging
 *
 * Note:            None
 ********************************************************************/
unsigned char _Conn5SetAttrib(void)
{
	UINT 	work;

	// Ignore the first byte (it is actually the attribute ID) 
	mRouteGetByte();

	switch (mRouteGetAttributeID())
	{	
		case	_ATTRIB_EXPECTED_RATE:
			// Continue only if there is sufficient data
			if (mRouteTestValidInputDataLen(2))
			{
				if (uConn5.attrib.state == _STATE_CONFIGURING) 
				{
					uConn5.attrib.state = _STATE_ESTABLISHED;
					_establishFlags.bits.multi = 1;
				}

				// Read in the requested packet rate
				uConn5.attrib.expected_packet_rate.bytes.LSB = mRouteGetByte();
				uConn5.attrib.expected_packet_rate.bytes.MSB = mRouteGetByte();
	
				// Get the ls bits
				work.word = uConn5.attrib.expected_packet_rate.bytes.LSB & (TICK_RESOLUTION - 1);
	
				// Remove the ls bits from desired resolution
				uConn5.attrib.expected_packet_rate.bytes.LSB &= (~(TICK_RESOLUTION - 1));
				
				// Round up if necessary
				if (work.word) uConn5.attrib.expected_packet_rate.word += (TICK_RESOLUTION);
	
				// Return the value actually used
				mRoutePutByte(uConn5.attrib.expected_packet_rate.bytes.LSB);
				mRoutePutByte(uConn5.attrib.expected_packet_rate.bytes.MSB);
	
				// Set the timer 4x (section 5-4.4.2)
				uConn5.timer.word = uConn5.attrib.expected_packet_rate.word << 2; 
			}	
			break;
		case	_ATTRIB_CLASS_TRIGGER:
			if (uConn5.attrib.state == _STATE_CONFIGURING)
			{
				if (mRouteTestValidInputDataLen(1))
				{ 
					// To be handled by the app
					UsrConnSetAttribEvent(5);
				}
			}
			else
			{
				mRoutePutError(ERR_OBJECT_STATE_CONFLICT);
			}
			break;
		case	_ATTRIB_PRODUCED_CONN_PATH:
			if (uConn5.attrib.state == _STATE_CONFIGURING)
			{
				if (mRouteTestValidInputDataLen(uConn4.attrib.produced_path_len.bytes.LSB))
				{
					// To be handled by the app
					UsrConnSetAttribEvent(5);
				}
			}
			else
			{
				mRoutePutError(ERR_OBJECT_STATE_CONFLICT);
			}
			break;
		case	_ATTRIB_CONSUMED_CONN_PATH:
			if (uConn5.attrib.state == _STATE_CONFIGURING)
			{
				if (mRouteTestValidInputDataLen(uConn5.attrib.consumed_path_len.bytes.LSB))
				{
					// To be handled by the app
					UsrConnSetAttribEvent(5);
				}
			}
			else
			{
				mRoutePutError(ERR_OBJECT_STATE_CONFLICT);
			}
			break;
		case	_ATTRIB_PRODUCED_CONN_SIZE:
			if (uConn5.attrib.state == _STATE_CONFIGURING)
			{
				if (mRouteTestValidInputDataLen(2))
				{
					// To be handled by the app
					UsrConnSetAttribEvent(5);
				}
			}
			else
			{
				mRoutePutError(ERR_OBJECT_STATE_CONFLICT);
			}
			break;
		case	_ATTRIB_CONSUMED_CID:
			if (mRouteTestValidInputDataLen(2))
			{
				work.bytes.LSB = mRouteGetByte();
				work.bytes.MSB = mRouteGetByte();
				
				work.word = work.word << 5;
				
				if (((work.bytes.MSB & 0xC0) == 0x80) && 
					((work.bytes.MSB & 0x3F) < 64) &&
					((work.bytes.LSB & 0xE0) == 0))
				{
					uConn5.attrib.consumed_cid.word = work.word;
					CANSetFilter(work.word);
				}
				else
				{
					mRoutePutError(ERR_INVALID_ATTRIB_VALUE);
				}
			}
			break;
		case	_ATTRIB_WDT_ACTION:
		case	_ATTRIB_CONSUMED_CONN_SIZE:
		case	_ATTRIB_STATE:
		case	_ATTRIB_INSTANCE_TYPE:
		case 	_ATTRIB_PRODUCED_CID:
		case 	_ATTRIB_INITIAL_COMM_CHAR:
		case	_ATTRIB_PRODUCED_CONN_PATH_LEN:
		case	_ATTRIB_CONSUMED_CONN_PATH_LEN:
			mRoutePutError(ERR_ATTRIB_NOT_SETTABLE);
			break;
			
		default:
			mRoutePutError(ERR_ATTRIB_NOT_SUPPORTED);
			break;
	}
	return(1);
}



#endif	// SUPPORT_MULTICAST_POLL

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -