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

📄 ecuserdefined_obj.c

📁 基于EthernetIP协议的应用程序,可以读取AB公司Controllogix系列Ethernetip协议PLC数据. 此软件代码可用于工业控制.
💻 C
📖 第 1 页 / 共 2 页
字号:
			** Attempt to get a combuf big enough for the attribute data.
			** Reply with an error if we fail.
			** Connect the new combuf to the request tribble if we succeed.
			*/
			aClassAttributesByteSize = GetClassAttributesByteSize( theClass );

			pComBufNew = CB_TradeForBiggerClear( pComBuf,
				sizeof( CI_GoodReplyHeaderType ) +
				aClassAttributesByteSize
			);
			if ( pComBufNew == NULL )
				ERROR_RET( CI_GRC_NO_RESOURCE );

			/* ! */
			pTrrbl->pComBuf = pComBufNew;

			/*
			** Fill in the class attribute data and prepend a reply header.
			*/

			CB_ExpandComBuf( pComBufNew, aClassAttributesByteSize );

			aClassAttributesBuf = CB_GetDataPtrComBuf( pComBufNew );
			GetClassAttributes( aClassAttributesBuf, theClass );

			CI_PrependReplyHeader( pComBufNew, bService, CI_GRC_SUCCESS, 0 );
			break;


		case CI_SC_SET_ATTR_ALL:

			/* ! */
			if( 0!=bIOIsize )
				ERROR_RET( CI_GRC_BAD_PATH );

			/* ! */
			CI_StripIoiPath( pComBuf, 0 );
			aClassAttributesBuf = CB_GetDataPtrComBuf( pComBuf );


			/* ! check ReadOnly Attributes; H.F. 05-12-2002 */
			for(i=0; i<theClass->itsAttributesCount; i++ )
				if( theClass->itsAttributes[i].itsIsReadOnly ){
            	iERCAttributeID = theClass->itsAttributes[i].itsAttributeCode;
					ERROR_RET_EXT( CI_GRC_ATTR_NOT_SETTABLE );
            };


			/* ! check datasize; H.F. 05-12-2002 */
			aClassAttributesByteSize = GetClassAttributesByteSize( theClass );
			if( CB_GetDataSizeComBuf( pComBuf )!=aClassAttributesByteSize ){
         	if ( CB_GetDataSizeComBuf( pComBuf )>aClassAttributesByteSize )
            	ERROR_RET( CI_GRC_CONFIG_TOO_BIG );
           	ERROR_RET( CI_GRC_CONFIG_TOO_SMALL );
         };


			/* ! */
			SetClassAttributes( aClassAttributesBuf, theClass );

			/* ! */
			CI_PrependReplyHeader( pComBuf, bService, CI_GRC_SUCCESS, 0 );

			/* ! */
			break;

		case CI_SC_GET_ATTR_SINGLE:

			/*
			** Parse off the attribute.
			*/
			if( CI_GRC_SUCCESS!=CI_ParseIoiSegment( pComBuf, &bSegType, &iAttribute, TRUE ) )
				ERROR_RET( CI_GRC_BAD_PATH );
			if( CI_LOGICAL_SEG_ATTRIBUTE!=bSegType  )
				ERROR_RET(CI_GRC_BAD_PATH);

			/*
			** Strip any remaining IOI.
			** Parse off any member size (or use the default).
			*/
			CI_StripIoiPath( pComBuf, 0 );

			/*
			**	Need to read IOI for which attribute to get, so if its empty we have a problem.
			*/

			if ( 0==bIOIsize )
				ERROR_RET( CI_GRC_BAD_PATH );

			/*
			**  Algorithm for retrieving an individual object
			**
			**	 1.  Allocate enough space for the object on the buffer
			**	 2.  Copy the data to the buffer
			**	 3.  Concatenate data to reply message
			*/

			/* ! */
			if( NULL==(aAttribute=GetClassAttribute( theClass, iAttribute )) )
				ERROR_RET( CI_GRC_UNDEFINED_ATTR );

			/* ! */
			aClassAttributeSize = GetAttributeByteSize( aAttribute );

			/* ! */
			pComBufNew = CB_TradeForBiggerClear(pComBuf,
				sizeof(CI_GoodReplyHeaderType) +
				aClassAttributeSize + 1
			);
			if ( pComBufNew == NULL )
				ERROR_RET( CI_GRC_NO_RESOURCE );

			pTrrbl->pComBuf = pComBufNew;

			CB_PrependComBuf(pComBufNew, aAttribute->itsDataPtr, aClassAttributeSize );
			CI_PrependReplyHeader( pComBufNew, bService, CI_GRC_SUCCESS, 0 );

			/* ! */
			break;

		case CI_SC_SET_ATTR_SINGLE:

			/*
			** Parse off the attribute.
			*/
			if( CI_GRC_SUCCESS!=CI_ParseIoiSegment( pComBuf, &bSegType, &iAttribute, TRUE ) )
				ERROR_RET( CI_GRC_BAD_PATH );
			if( CI_LOGICAL_SEG_ATTRIBUTE!=bSegType  )
				ERROR_RET(CI_GRC_BAD_PATH);

			/*
			** Strip any remaining IOI.
			** Parse off any member size (or use the default).
			*/
			CI_StripIoiPath( pComBuf, 0 );

			/* ! */
			if( NULL==(aAttribute=GetClassAttribute( theClass, iAttribute )) )
				ERROR_RET( CI_GRC_UNDEFINED_ATTR );

			/* ! */
			if( aAttribute->itsIsReadOnly )
				ERROR_RET( CI_GRC_ATTR_NOT_SETTABLE );

			/* ! */
			aClassAttributeSize = GetAttributeByteSize( aAttribute );

			/* ! */
			if( CB_GetDataSizeComBuf( pComBuf )!=aClassAttributeSize ){
         	if ( CB_GetDataSizeComBuf( pComBuf )>aClassAttributeSize ) /* H.F. 06-12-2002 */
            	ERROR_RET( CI_GRC_CONFIG_TOO_BIG ); /* H.F. 06-12-2002 */
           	ERROR_RET( CI_GRC_CONFIG_TOO_SMALL ); /* H.F. 06-12-2002 */
         };

			/* ! */
			memcpy( aAttribute->itsDataPtr, pComBuf->pData, aClassAttributeSize );

			/* ! */
			CI_PrependReplyHeader( pComBuf, bService, CI_GRC_SUCCESS, 0 );

			/* ! */
			break;

		default:

			/*
			** Unsupported request code. Return a bad reply header only.
			*/

			CB_ClearComBuf( pComBuf );
			CI_PrependReplyHeader( pComBuf, bService, CI_GRC_BAD_SERVICE, 0 );

			break;
   }

#undef ERROR_RET_EXT /* H.F. 05-12-2002 */
#undef ERROR_RET

} /* end of UserDefined_ProcessClassRequest() */



/*---------------------------------------------------------------------------
** UserDefined_ProcessInstanceRequest()
**---------------------------------------------------------------------------
*/

BOOL UserDefined_ProcessInstanceRequest( t_Instance *theInstance, CD_PacketTrrblType  *pTrrbl )
{
   CB_ComBufType              *pComBuf;
   CB_ComBufType              *pComBufNew;
   CI_IoiType                 *pIOI;
   UINT8                       bIOIsize;
/*   UINT8                       bNameSize; */
/*   UINT8                      *pbParameter; */
   UINT8                       bService;
/*   UINT16                      iStatus; */
   int                         aInstanceAttributeSize;
   int                         aInstanceAttributesByteSize;
   UINT8                      *aInstanceAttributesBuf;
   t_Attribute                *aAttribute;
   UINT8               bSegType;
   UINT16              iAttribute, i;	/* i: index in for-loop; H.F. 05-12-2002 */
   UINT16				  iERCAttributeID; /* H.F. 05-12-2002 */

#define ERROR_RET(code){ CB_ClearComBuf( pComBuf ); CI_PrependReplyHeader( pComBuf, bService, code, 0 ); return (FALSE); }

/* error code with extended status; H.F. 05-12-2002 */
#define ERROR_RET_EXT(code){ CB_ClearComBuf( pComBuf ); CI_PrependReplyHeaderWithExtendedERC( pComBuf, bService, code, 1, &iERCAttributeID ); return (FALSE); }

   /*
   ** Valid tribble/combuf. Pull out the essential information.
   */

   pComBuf   = pTrrbl->pComBuf;
   pIOI      = CB_GetDataPtrComBuf( pComBuf );
   bService  = pIOI->bService;
   bIOIsize  = pIOI->bIoiSize;

   switch ( bService )
   {
      case CI_SC_GET_ATTR_ALL:

			/*
			** If there is anything remaining in the IOI, we have a problem.
			*/

			if ( 0!=bIOIsize )
				ERROR_RET( CI_GRC_BAD_PATH );

			/*
			** Attempt to get a combuf big enough for the attribute data.
			** Reply with an error if we fail.
			** Connect the new combuf to the request tribble if we succeed.
			*/
			aInstanceAttributesByteSize=GetInstanceAttributesByteSize( theInstance );

			pComBufNew = CB_TradeForBiggerClear( pComBuf,
			    sizeof( CI_GoodReplyHeaderType ) +
				aInstanceAttributesByteSize
			);
			if ( NULL==pComBufNew )
				ERROR_RET(CI_GRC_NO_RESOURCE);

			pTrrbl->pComBuf = pComBufNew;

			CB_ExpandComBuf( pComBufNew, aInstanceAttributesByteSize );

			aInstanceAttributesBuf = CB_GetDataPtrComBuf( pComBufNew );

			GetInstanceAttributes( aInstanceAttributesBuf, theInstance );

			CI_PrependReplyHeader( pComBufNew, bService, CI_GRC_SUCCESS, 0 );

			break;

		case CI_SC_SET_ATTR_ALL:

			/* ! */
			if ( 0!=bIOIsize )
				ERROR_RET( CI_GRC_BAD_PATH );

			/* ! */
			CI_StripIoiPath( pComBuf, 0 );
			aInstanceAttributesBuf = CB_GetDataPtrComBuf( pComBuf );

			/* ! check ReadOnly Attributes; H.F. 05-12-2002 */
			for(i=0; i<theInstance->itsAttributesCount; i++ )
				if( theInstance->itsAttributes[i].itsIsReadOnly ){
            	iERCAttributeID = theInstance->itsAttributes[i].itsAttributeCode;
					ERROR_RET_EXT( CI_GRC_ATTR_NOT_SETTABLE );
            };

			/* ! check datasize; H.F. 05-12-2002 */
			aInstanceAttributesByteSize = GetInstanceAttributesByteSize( theInstance );
			if( CB_GetDataSizeComBuf( pComBuf )!=aInstanceAttributesByteSize ){
         	if ( CB_GetDataSizeComBuf( pComBuf )>aInstanceAttributesByteSize )
            	ERROR_RET( CI_GRC_CONFIG_TOO_BIG );
           	ERROR_RET( CI_GRC_CONFIG_TOO_SMALL );
         };

			/* ! */
			SetInstanceAttributes( aInstanceAttributesBuf, theInstance );

			/* ! */
			CI_PrependReplyHeader( pComBuf, bService, CI_GRC_SUCCESS, 0 );

			/* ! */
			break;


	case CI_SC_GET_ATTR_SINGLE:

		/*
		** Parse off the attribute.
		*/
		if( CI_GRC_SUCCESS!=CI_ParseIoiSegment( pComBuf, &bSegType, &iAttribute, TRUE ) )
			ERROR_RET( CI_GRC_BAD_PATH );
		if( CI_LOGICAL_SEG_ATTRIBUTE!=bSegType  )
			ERROR_RET(CI_GRC_BAD_PATH);

		/*
		** Strip any remaining IOI.
		** Parse off any member size (or use the default).
		*/
		CI_StripIoiPath( pComBuf, 0 );

		/*
		**	Need to read IOI for which attribute to get, so if its empty we have a problem.
		*/

		if ( 0==bIOIsize )
			ERROR_RET( CI_GRC_BAD_PATH );

		/*
		**  Algorithm for retrieving an individual object
		**
		**	 1.  Allocate enough space for the object on the buffer
		**	 2.  Copy the data to the buffer
		**	 3.  Concatenate data to reply message
		*/

		/* ! */
		if( NULL==(aAttribute=GetInstanceAttribute( theInstance, iAttribute )) )
			ERROR_RET( CI_GRC_UNDEFINED_ATTR );

		/* ! */
		aInstanceAttributeSize = GetAttributeByteSize( aAttribute );

		/* ! */
		pComBufNew = CB_TradeForBiggerClear(pComBuf,
			sizeof(CI_GoodReplyHeaderType) +
			aInstanceAttributeSize + 1
		);
		if ( pComBufNew == NULL )
			ERROR_RET( CI_GRC_NO_RESOURCE );

		pTrrbl->pComBuf = pComBufNew;

		CB_PrependComBuf(pComBufNew, aAttribute->itsDataPtr, aInstanceAttributeSize );
		CI_PrependReplyHeader( pComBufNew, bService, CI_GRC_SUCCESS, 0 );

		/* ! */
		break;

	case CI_SC_SET_ATTR_SINGLE:

		/*
		** Parse off the attribute.
		*/
		if( CI_GRC_SUCCESS!=CI_ParseIoiSegment( pComBuf, &bSegType, &iAttribute, TRUE ) )
			ERROR_RET( CI_GRC_BAD_PATH );
		if( CI_LOGICAL_SEG_ATTRIBUTE!=bSegType  )
			ERROR_RET(CI_GRC_BAD_PATH);

		/*
		** Strip any remaining IOI.
		** Parse off any member size (or use the default).
		*/
		CI_StripIoiPath( pComBuf, 0 );

		/* ! */
		if( NULL==(aAttribute=GetInstanceAttribute( theInstance, iAttribute )) )
			ERROR_RET( CI_GRC_UNDEFINED_ATTR );

		/* ! */
		if( aAttribute->itsIsReadOnly )
			ERROR_RET( CI_GRC_ATTR_NOT_SETTABLE );

		/* ! */
		aInstanceAttributeSize = GetAttributeByteSize( aAttribute );

		/* ! */
		if( CB_GetDataSizeComBuf( pComBuf )!=aInstanceAttributeSize ){
      	if ( CB_GetDataSizeComBuf( pComBuf )>aInstanceAttributeSize ) /* H.F. 06-12-2002 */
           	ERROR_RET( CI_GRC_CONFIG_TOO_BIG ); /* H.F. 06-12-2002 */
         ERROR_RET( CI_GRC_CONFIG_TOO_SMALL ); /* H.F. 06-12-2002 */
      };

		/* ! */
		memcpy( aAttribute->itsDataPtr, pComBuf->pData, aInstanceAttributeSize );

		/* ! */
		CI_PrependReplyHeader( pComBuf, bService, CI_GRC_SUCCESS, 0 );

		/* ! */
		break;

      default:

		/*
		** Unsupported request code. Return a bad reply header only.
		*/
		ERROR_RET( CI_GRC_BAD_SERVICE );
   }

   /*
   ** Normal, non-reset return.
   */

   return( FALSE );

#undef ERROR_RET_EXT /* H.F. 05-12-2002 */
#undef ERROR_RET
} /* end of UserDefined_ProcessInstanceRequest() */

/****************************************************************************
*****************************************************************************
**
** End of USERDEFINED_OBJ.C
**
*****************************************************************************
*****************************************************************************
*/

⌨️ 快捷键说明

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