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

📄 el_obj.c

📁 基于EthernetIP协议的应用程序,可以读取AB公司Controllogix系列Ethernetip协议PLC数据. 此软件代码可用于工业控制.
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************
*****************************************************************************
**
** File Name
** ---------
**
** EL_OBJ.C
**
*****************************************************************************
*****************************************************************************
**
** Description
** -----------
**
** This source module implements the Ethernet Link 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 ETHERNET_LINK_OBJECT

#include "cd.h"         /* Communications Device public interfaces         */
#include "mr.h"         /* Message Router public interfaces                */
#include "el.h"         /* Ethernet Link Object public interfaces          */
#include "el_obj.h"     /* Ethernet Link Object private interfaces         */

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

el_DataType      el_s;
GS_MsgQueueType  EL_xQid;

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

/*---------------------------------------------------------------------------
** EL_Init()
**---------------------------------------------------------------------------
*/

StatusType EL_Init( UINT16 iOptions )
{
   GS_TaskSeedType            sSeed;
   MR_RegistrationTrrblType  *pMrTrrbl;

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

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

      EL_xQid = GS_NewMsgQueue();
   }

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

   if( iOptions & AB_INIT_RESOURCE )
   {
      UC_SetMem( &el_s, 0, sizeof( el_s ) );
   }

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

   if( iOptions & AB_CREATE_TASK )
   {
      sSeed.pRoutine   = EL_ObjectTask;
      sSeed.pParameter = NULL;
      sSeed.pStack     = NULL;
      sSeed.iStackSize = EL_STACK_SIZE;
      sSeed.nPrio      = EL_TASK_PRIO;
      sSeed.pTaskName  = "EL  ";

      GS_AssociateTaskAndQueues( GS_NewTask( &sSeed ), EL_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    = EL_CLASS_NUMBER;
      pMrTrrbl->iInstance = MR_CLASS_AND_INSTANCE_1;
      pMrTrrbl->iPort     = MR_ALL_PORTS;
      pMrTrrbl->xQ        = EL_xQid;

      GS_PutTrrbl( MR_xQid, pMrTrrbl );
   }

   return( SUCCESS );

} /* end of EL_Init() */



/*---------------------------------------------------------------------------
** EL_ObjectTask()
**---------------------------------------------------------------------------
*/

TASKRETURN EL_ObjectTask( TASKPARAM )
{
   CB_ComBufType   *pComBuf;
   CI_IoiType      *pIOI;
   UINT8            bService;
   el_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( EL_xQid );

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

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

            el_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:

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


         case 1:

            el_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 EL_ObjectTask() */



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

/*---------------------------------------------------------------------------
** el_ProcessAppOpen()
**---------------------------------------------------------------------------
*/

void el_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 el_ProcessAppOpen() */



/*---------------------------------------------------------------------------
** el_ProcessClassRequest()
**---------------------------------------------------------------------------
*/

void el_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 = el_ProcessGetAttrAllClass( pTrrbl );
         break;

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

      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 el_ProcessClassRequest() */


/*---------------------------------------------------------------------------
** el_ProcessGetAttrAllClass()
**---------------------------------------------------------------------------
*/

UINT16 el_ProcessGetAttrAllClass( CD_PacketTrrblType  *pTrrbl )
{
   CB_ComBufType              *pComBuf;
   CI_IoiType                 *pIOI;
   UINT8                       bIOIsize;

⌨️ 快捷键说明

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