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

📄 ei_obj.c

📁 基于EthernetIP协议的应用程序,可以读取AB公司Controllogix系列Ethernetip协议PLC数据. 此软件代码可用于工业控制.
💻 C
📖 第 1 页 / 共 3 页
字号:
            *pData = 0;
         }
         break;

      default:
         iStatus = CI_GRC_UNDEFINED_ATTR;
         break;
   }

   return( iStatus );

} /* end of ei_ProcessGetAttrSingleInstance() */



/*---------------------------------------------------------------------------
** ei_ProcessInstanceRequest()
**---------------------------------------------------------------------------
*/

void  ei_ProcessInstanceRequest( CD_PacketTrrblType  *pTrrbl )
{
   CI_IoiType                 *pIOI;
   UINT8                       bService;
   UINT16                      iStatus;

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

   /*
   ** Obtain the current Interface Configuration data
   */
   eiu_GetCurrentNetworkConfig();

   /*
   ** Process per the service code.
   */

   switch ( bService )
   {
      case CI_SC_GET_ATTR_ALL:
         iStatus = ei_ProcessGetAttrAllInstance( pTrrbl );
         break;

      case CI_SC_GET_ATTR_SINGLE:
         iStatus = ei_ProcessGetAttrSingleInstance( pTrrbl );
         break;

      /*
      ** If the config settable bit isn't set, then reject the set
      ** attributes requests
      */

#if ( EIU_CONFIG_CAPABILITY & EI_CAPABILITY_SETTABLE_CONFIG )
      case CI_SC_SET_ATTR_SINGLE:
         iStatus = ei_ProcessSetAttrSingleInstance( pTrrbl );
         if ( iStatus == CI_GRC_SUCCESS )
         {
            /*
            ** Store the new Interface data to non-volatile storage.  Apply the
            ** new configuration as needed.
            */

            iStatus = eiu_SetCurrentNetworkConfig();
         }
         break;

      case CI_SC_SET_ATTR_ALL:
         iStatus = ei_ProcessSetAttrAllInstance( pTrrbl );
         if ( iStatus == CI_GRC_SUCCESS )
         {
            /*
            ** Store the new Interface data to non-volatile storage.  Apply the
            ** new configuration as needed.
            */

            iStatus = eiu_SetCurrentNetworkConfig();
         }
         break;
#endif

      default:

         /*
         ** Unsupported request code. Return a bad reply header only.
         */
         iStatus = CI_GRC_BAD_SERVICE;
         break;
   }

   /*
   ** For errors, clear the ComBuf.  Always preprend the Header
   */

   if( iStatus != CI_GRC_SUCCESS )
   {
      CB_ClearComBuf( pTrrbl->pComBuf );
   }

   CI_PrependReplyHeader( pTrrbl->pComBuf, bService, (UINT8)iStatus, 0 );

} /* end of ei_ProcessInstanceRequest() */


/*---------------------------------------------------------------------------
** ei_ProcessSetAttrAllInstance()
**---------------------------------------------------------------------------
*/

UINT16 ei_ProcessSetAttrAllInstance( CD_PacketTrrblType  *pTrrbl )
{
   CB_ComBufType              *pComBuf;
   CI_IoiType                 *pIOI;
   UINT8                       bIOIsize;
   UINT16                      iStatus;
   UINT32                      lConfigControl;
   UINT8                      *pData;

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

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

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

   if ( bIOIsize != 0 )
   {
      return ( CI_GRC_BAD_PATH );
   }

   CI_StripIoiPath( pComBuf, 0 );
   pData = CB_GetDataPtrComBuf( pComBuf );

   /*
   ** unpack valid InterfaceConfig data
   */

   iStatus = ei_SetInterfaceConfig( pComBuf, (EI_LeInterfaceConfig *)pData );
   if( iStatus == CI_GRC_SUCCESS )
   {

      /*
      ** setup pointer to ConfigControl data, then unpack
      */

      pData += (sizeof( EI_LeInterfaceConfig ) +
                ei_s.sInterfaceConfig.iDomainNameSize );
      lConfigControl = *( (UINT32 *)pData);
      iStatus = ei_SetConfigControl( pComBuf, lConfigControl );
   }

   return( iStatus );

} /* end of ei_ProcessSetAttrAllInstance() */


/*---------------------------------------------------------------------------
** ei_ProcessSetAttrSingleInstance()
**---------------------------------------------------------------------------
*/

UINT16 ei_ProcessSetAttrSingleInstance( CD_PacketTrrblType  *pTrrbl )
{
   CB_ComBufType              *pComBuf;
   UINT8                       bSegType;
   UINT16                      iAttribute;
   UINT16                      iStatus;
   UINT32                      lConfigControl;

   pComBuf = pTrrbl->pComBuf;

   /*
   ** Find which attribute to set.
   */

   iStatus = CI_ParseIoiSegment( pComBuf, &bSegType, &iAttribute, TRUE );

   if( iStatus != CI_GRC_SUCCESS )
   {
      return( iStatus );
   }

   if( bSegType != CI_LOGICAL_SEG_ATTRIBUTE )
   {
      return( CI_GRC_BAD_PATH );
   }

   /*
   ** Unpack Settable attributes from the combuf.
   */

   switch( iAttribute )
   {

      case EI_IA_CONFIG_CONTROL:
         CI_StripIoiPath( pComBuf, 0 );
         lConfigControl = *( (UINT32*)CB_GetDataPtrComBuf( pComBuf ) );
         iStatus = ei_SetConfigControl( pComBuf, lConfigControl );
         break;

      case EI_IA_INTERFACE_CONFIG:
         CI_StripIoiPath( pComBuf, 0 );
         iStatus = ei_SetInterfaceConfig( pComBuf, CB_GetDataPtrComBuf( pComBuf ) );
         break;

      case EI_IA_HOST_NAME:
         CI_StripIoiPath( pComBuf, 0 );
         iStatus = ei_SetHostName( pComBuf, CB_GetDataPtrComBuf( pComBuf ) );
         break;

      case EI_IA_INTERFACE_STATUS:
      case EI_IA_CONFIG_CAPABILITY:
      case EI_IA_LINK_PATH:
         iStatus = CI_GRC_ATTR_NOT_SETTABLE;
         break;

      default:
         iStatus = CI_GRC_UNDEFINED_ATTR;
         break;
   }

   return( iStatus );

} /* end of ei_ProcessSetAttrSingleInstance() */



/*---------------------------------------------------------------------------
** ei_SetConfigControl()
**---------------------------------------------------------------------------
*/

UINT16 ei_SetConfigControl( CB_ComBufType *pComBuf, UINT32 lConfigControl )
{
   UINT16                      iStatus;

   iStatus = CI_GRC_SUCCESS;

   lConfigControl = UC_lLeTOl( lConfigControl );

   /*
   ** validate the size and value of the data
   */

   if(CB_GetDataSizeComBuf( pComBuf ) < sizeof( UINT32 ) )
   {
      iStatus = CI_GRC_BAD_ATTR_DATA;
   }
   else
   {
      ei_s.lConfigControl = lConfigControl;
      CB_ShrinkComBuf( pComBuf, sizeof( UINT32 ) );
   }

   return( iStatus );

} /* end of ei_SetConfigControl() */


/*---------------------------------------------------------------------------
** ei_SetHostName()
**---------------------------------------------------------------------------
*/

UINT16 ei_SetHostName( CB_ComBufType *pComBuf, LeUINT16 *piLeAttribute )
{
   UINT16                      iStatus;
   UINT16                      iHostNameSize;

   iStatus = CI_GRC_SUCCESS;

   /*
   ** Validate Host name size, then copy all valid data
   */

   iHostNameSize = UC_iLeTOi( *piLeAttribute );

   if( iHostNameSize > EI_MAX_HOST_LENGTH )
   {
      iStatus = CI_GRC_CONFIG_TOO_BIG;
   }
   else
   {
      /*
      ** Save the Host name size and Host name...
      */
      ei_s.iHostNameSize = iHostNameSize;

      piLeAttribute++;
      UC_CopyMem( &ei_s.achHostName[0], piLeAttribute, iHostNameSize );

      CB_ShrinkComBuf( pComBuf, sizeof( ei_s.iHostNameSize ) + ei_s.iHostNameSize );
   }

   return( iStatus );

} /* end of ei_SetHostName() */


/*---------------------------------------------------------------------------
** ei_SetInterfaceConfig()
**---------------------------------------------------------------------------
*/

UINT16 ei_SetInterfaceConfig( CB_ComBufType *pComBuf, EI_LeInterfaceConfig *psInterfaceConfig )
{
   UINT16                      iStatus;
   UINT16                      iDomainNameSize;

   iStatus = CI_GRC_SUCCESS;

   /*
   ** Perform some BASIC checking on the network addresses.
   */

   if( ( CB_GetDataSizeComBuf( pComBuf ) >= sizeof( EI_LeInterfaceConfig ) ) &&
       ( !( psInterfaceConfig->lLeSubnetMask == 0xFFFFFFFF ||
            psInterfaceConfig->lLeIpAddr == 0x00 ||
            psInterfaceConfig->lLeIpAddr == 0xFFFFFFFF ) ) )
   {
      /*
      ** Validate Domain name size, then copy all valid data
      */

      iDomainNameSize = UC_iLeTOi( psInterfaceConfig->iLeDomainNameSize );

      if( iDomainNameSize > EI_MAX_DOMAIN_LENGTH )
      {
         iStatus = CI_GRC_CONFIG_TOO_BIG;
      }
      else
      {
         /*
         ** Valid so far --> update working copy of packet data.
         */

         ei_s.sInterfaceConfig.lIpAddr         = UC_lLeTOl( psInterfaceConfig->lLeIpAddr );
         ei_s.sInterfaceConfig.lSubnetMask     = UC_lLeTOl( psInterfaceConfig->lLeSubnetMask );
         ei_s.sInterfaceConfig.lGatewayAddr    = UC_lLeTOl( psInterfaceConfig->lLeGatewayAddr );
         ei_s.sInterfaceConfig.lNameServer     = UC_lLeTOl( psInterfaceConfig->lLeNameServer );
         ei_s.sInterfaceConfig.lNameServer_2   = UC_lLeTOl( psInterfaceConfig->lLeNameServer_2 );
         ei_s.sInterfaceConfig.iDomainNameSize = UC_iLeTOi( psInterfaceConfig->iLeDomainNameSize );

         /*
         ** Adjust pointer in incomming packet to start of DomainName and save it
         */

         UC_CopyMem( &ei_s.sInterfaceConfig.achDomainName[0],
                     (UINT8 *)&psInterfaceConfig->iLeDomainNameSize + sizeof( LeUINT16 ),
                     iDomainNameSize );

         CB_ShrinkComBuf( pComBuf, sizeof( EI_LeInterfaceConfig ) + iDomainNameSize );
      }
   }
   else
   {
      /*
      ** invalid Address
      */

      iStatus = CI_GRC_BAD_ATTR_DATA;
   }

   return( iStatus );

} /* end of ei_SetInterfaceConfig() */


#endif  /* #ifdef TCPIP_INTERFACE_OBJECT */

/****************************************************************************
**
** End of EI_OBJ.C
**
*****************************************************************************
*/

⌨️ 快捷键说明

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