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

📄 ei_obj.c

📁 基于EthernetIP协议的应用程序,可以读取AB公司Controllogix系列Ethernetip协议PLC数据. 此软件代码可用于工业控制.
💻 C
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************
*****************************************************************************
**
** File Name
** ---------
**
** EI_OBJ.C
**
*****************************************************************************
*****************************************************************************
**
** Description
** -----------
**
** This source module implements the TCP/IP Interface Object.
**
*****************************************************************************
*****************************************************************************
**
** Source Change Indices
** ---------------------
**
** Porting: <none>0----<major>         Customization: <none>0----<major>
**
*****************************************************************************
*****************************************************************************
**                                                                         **
** ETHERNET/IP EXAMPLE CODE                                                **
** COPYRIGHT (c) 2000-2005 ODVA (Open DeviceNet Vendor Association)		   **
**						   & ControlNet International Ltd.                 **
**                                                                         **
** All rights reserved, except as specifically licensed in writing.        **
** Use of the Ethernet/IP Example Protocol Software is subject to          **
** ODVA's and ControlNet International's Terms of Use Agreement.           **
** The following work constitutes example program code and is intended     **
** merely to illustrate useful programming techniques.  The user is        **
** responsible for applying the code correctly.  The code is provided      **
** AS IS without warranty and is in no way guaranteed to be error-free.    **
**                                                                         **
*****************************************************************************
*****************************************************************************
*/

/****************************************************************************
*****************************************************************************
**
** Change Log
** ----------
**
**
*****************************************************************************
*****************************************************************************
*/

/*
** See if this object is to be included.
*/

#include "ab.h"

#ifdef TCPIP_INTERFACE_OBJECT

#include "cd.h"         /* Communications Device public interfaces         */
#include "mr.h"         /* Message Router public interfaces                */
#include "ei.h"         /* TCP/IP Interface Object public interfaces       */
#include "ei_obj.h"     /* TCP/IP Interface Object private interfaces      */

/****************************************************************************
**
** Public Globals
**
*****************************************************************************
*/

ei_DataType      ei_s;
GS_MsgQueueType  EI_xQid;

/****************************************************************************
**
** Public Services
**
*****************************************************************************
*/

/*---------------------------------------------------------------------------
** EI_Init()
**---------------------------------------------------------------------------
*/

StatusType EI_Init( UINT16 iOptions )
{
   GS_TaskSeedType            sSeed;
   MR_RegistrationTrrblType  *pMrTrrbl;
   UINT8 abLinkPath[] = EIU_LINK_PATH_SEGMENT;

   /*
   ** Allocate/Create all resources (except for tasks).
   */

   if( iOptions & AB_CREATE_RESOURCE )
   {
      /*
      ** Create the task's request queue.
      */

      EI_xQid = GS_NewMsgQueue();
   }

   /*
   ** Initialize all internal data structures.
   */

   if( iOptions & AB_INIT_RESOURCE )
   {

      /*
      ** Default Configuration Capability and Configuration Control
      ** are user configurable.
      */

      ei_s.lConfigCapability = EIU_CONFIG_CAPABILITY;
      ei_s.lConfigControl    = EIU_CONFIG_CONTROL;

      /*
      ** Setup the User Link Path
      */

      ei_s.iLinkObjPathSize = EIU_LINK_PATH_LENGTH / 2;
      UC_CopyMem( &ei_s.achLinkObjPath[0], &abLinkPath[0], EIU_LINK_PATH_LENGTH );

   }

   /*
   ** Create the task & associate it with the message queue created earlier.
   */

   if( iOptions & AB_CREATE_TASK )
   {
      sSeed.pRoutine   = EI_ObjectTask;
      sSeed.pParameter = NULL;
      sSeed.pStack     = NULL;
      sSeed.iStackSize = EI_STACK_SIZE;
      sSeed.nPrio      = EI_TASK_PRIO;
      sSeed.pTaskName  = "EI  ";

      GS_AssociateTaskAndQueues( GS_NewTask( &sSeed ), EI_xQid, GS_NO_QUEUE );
   }

   /*
   ** Final initialization after tasks are running.
   */

   if( iOptions & AB_INIT_TASK )
   {
      /*
      ** Register ourselves with the message router.
      */

      pMrTrrbl = GS_NewTrrbl( MR_RegistrationTrrblType );
      pMrTrrbl->eRequest  = TREQ_REGISTER_OBJECT;
      pMrTrrbl->iClass    = EI_CLASS_NUMBER;
      pMrTrrbl->iInstance = MR_CLASS_AND_INSTANCE_1;
      pMrTrrbl->iPort     = MR_ALL_PORTS;
      pMrTrrbl->xQ        = EI_xQid;

      GS_PutTrrbl( MR_xQid, pMrTrrbl );
   }

   return( SUCCESS );

} /* end of EI_Init() */



/*---------------------------------------------------------------------------
** EI_ObjectTask()
**---------------------------------------------------------------------------
*/

TASKRETURN EI_ObjectTask( TASKPARAM )
{
   CB_ComBufType   *pComBuf;
   CI_IoiType      *pIOI;
   UINT8            bService;
   ei_upsTrrblType  upsTrrbl;

   /*
   ** Process request tribbles one at a time (in an endless task loop).
   */

   while ( 1 )
   {
      /*
      ** Process tribbles one at a time.
      ** Make sure we've gotten an expected tribble.
      */

      upsTrrbl.Generic = GS_TakeTrrbl( EI_xQid );

      switch ( upsTrrbl.Generic->eRequest )
      {
         case TREQ_APP_OPEN:

            /*
            ** App open (initial connection request notification).
            */

            ei_ProcessAppOpen( upsTrrbl.AppOpenClose );
            continue;


         case TREQ_RX_UNSCHEDULED_PACKET:

            /*
            ** Unscheduled packet received. Just fall through to the
            ** packet processing code.
            */

            break ;


         default:

            GS_LogEvent( UNKNOWN_TRRBL_REQUEST, upsTrrbl.Generic->eRequest, upsTrrbl.Generic, FATAL );
            break;

      } /* end of switch( pTrrbl->eRequest ) */


      /*
      ** We've received a request packet.
      ** Is this a class or instance request, or something invalid.
      */

      switch ( upsTrrbl.Packet->iInstance )
      {
         case 0:

            ei_ProcessClassRequest( upsTrrbl.Packet );
            GS_ReturnTrrbl( upsTrrbl.Packet );
            break;


         case 1:

            ei_ProcessInstanceRequest( upsTrrbl.Packet );
            GS_ReturnTrrbl( upsTrrbl.Packet );
            break ;


         default:

            pComBuf  = upsTrrbl.Packet->pComBuf;
            pIOI     = CB_GetDataPtrComBuf( pComBuf );
            bService = pIOI->bService;
            CB_ClearComBuf( pComBuf );
            CI_PrependReplyHeader( pComBuf, bService, CI_GRC_BAD_CLASS_INSTANCE, 0 );
            GS_ReturnTrrbl( upsTrrbl.Packet );
            break;
      }

   } /* end of while( 1 ) */

} /* end of EI_ObjectTask() */



/****************************************************************************
**
** Private Services
**
*****************************************************************************
*/


/*---------------------------------------------------------------------------
** ei_GetInterfaceConfigAttribute()
**---------------------------------------------------------------------------
*/

void ei_GetInterfaceConfigAttribute( CB_ComBufType  *pComBuf )
{

   EI_LeInterfaceConfig  *psLeInterfaceConfig;
   UINT16 iNameSize;
   UINT8 bPad = 0;

   /*
   ** Since variable length string is at the end of this structure, first need to
   ** prepend this data.  Pad w/ zero to even number of characters, but don't include
   ** the pad in the Size field.
   */

   iNameSize = ei_s.sInterfaceConfig.iDomainNameSize;
   if( iNameSize & 1 )
   {
      CB_PrependComBuf( pComBuf, &bPad, 1 );
   }
   CB_PrependComBuf( pComBuf, &ei_s.sInterfaceConfig.achDomainName[0], iNameSize );

   /*
   ** Next add the "fixed" length EI_LeInterfaceConfig attributes.
   */

   CB_ExpandComBuf( pComBuf, sizeof( EI_LeInterfaceConfig ) );
   psLeInterfaceConfig = CB_GetDataPtrComBuf( pComBuf );

   psLeInterfaceConfig->lLeIpAddr          = UC_lTOlLe( ei_s.sInterfaceConfig.lIpAddr );
   psLeInterfaceConfig->lLeSubnetMask      = UC_lTOlLe( ei_s.sInterfaceConfig.lSubnetMask );
   psLeInterfaceConfig->lLeGatewayAddr     = UC_lTOlLe( ei_s.sInterfaceConfig.lGatewayAddr );
   psLeInterfaceConfig->lLeNameServer      = UC_lTOlLe( ei_s.sInterfaceConfig.lNameServer );
   psLeInterfaceConfig->lLeNameServer_2    = UC_lTOlLe( ei_s.sInterfaceConfig.lNameServer_2 );
   psLeInterfaceConfig->iLeDomainNameSize  = UC_iTOiLe( ei_s.sInterfaceConfig.iDomainNameSize );

} /* end of ei_GetInterfaceConfigAttribute() */



/*---------------------------------------------------------------------------
** ei_ProcessAppOpen()
**---------------------------------------------------------------------------
*/

void ei_ProcessAppOpen( CM_AppOpenCloseTrrblType *psTrrbl )
{
   CM_ConnectionRecordType *psConnRecord;

   /*
   ** Grab all of the interesting information from the tribble.
   */

   psConnRecord = psTrrbl->psConnRecord;

   if( CM_IsConnectionTypeNull( psConnRecord ) )
   {
      /*
      ** Just say YES, if Connection Type is NULL!
      */

      psTrrbl->eStatus = SUCCESS;
   }
   else
   {
      /*
      ** Somebody's trying to connect to us. Just say NO,
      ** if Connection Type is not NULL!
      */

      psTrrbl->eStatus = CM_UNCONNECTABLE_OBJECT;
   }

   GS_ReturnTrrbl( psTrrbl );

} /* end of ei_ProcessAppOpen() */



/*---------------------------------------------------------------------------
** ei_ProcessClassRequest()
**---------------------------------------------------------------------------
*/

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

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

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

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

   switch ( bService )
   {

      case CI_SC_GET_ATTR_ALL:
         iStatus = ei_ProcessGetAttrAllClass( pTrrbl );
         break;

⌨️ 快捷键说明

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