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

📄 cm_targt.h

📁 基于EthernetIP协议的应用程序,可以读取AB公司Controllogix系列Ethernetip协议PLC数据. 此软件代码可用于工业控制.
💻 H
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************
*****************************************************************************
**
** File Name
** ---------
**
** CM_TARGT.H
**
*****************************************************************************
*****************************************************************************
**
** Description
** -----------
**
** Private definitions for the target portion of the
** Connection Manager Object.
**
*****************************************************************************
*****************************************************************************
**
** Source Change Indices
** ---------------------
**
** Porting: <none>0----<major>         Customization: <none>0----<major>
**
*****************************************************************************
*****************************************************************************
**
** Services List
** -------------
**
**    cm_BuildFwdErrorReply()    - Build a fwd open/close error reply pkt
**    cm_CloseConnection()       - Close one connection
**    cm_DeleteCR()              - Delete the connection record
**    cm_FindConnection()        - Find an active connection by serial number
**    cm_GenerateAppOpenClose()  - Generate an app open or close tribble
**    cm_IssueAppOpenComplete()  - Issue an app open complete when ready
**    cm_ObjectTask()            - Main processing task for the object
**    cm_ParseFwdOpen()          - Parse the information out of a FO packet
**    cm_ProcessAppCloseResp()   - Process an app close response tribble
**    cm_ProcessAppOpenResp()    - Process an app open response tribble
**    cm_ProcessFwdClose()       - Initial forward close packet processing
**    cm_ProcessFwdOpen()        - Initial forward open packet processing
**    cm_ProcessImAlive()        - Process receipt of an I'm Alive! packet
**    cm_ProcessTimer()          - Process a transport timer expiring
**    cm_ProcessTranDeleteResp() - Process a delete transport response tribble
**    cm_ProcessTranNewResp()    - Process a new transport response tribble
**    cm_SetUpChannel()          - Set up a channel for operation
**    cm_UnpackSchedule()        - Unpack rate and start NUT from sched byte
**    cm_ValidateKey()           - Validate the electronic key in a fwd open
**    cm_WrapUp()                - Wrap up processing after conn open/close
**    cm_ZeroConnRecord()        - Zero a newly allocated conn record
**
*****************************************************************************
*****************************************************************************
**                                                                         **
** 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
** ----------
**
**
*****************************************************************************
*****************************************************************************
*/

#ifndef CM_TARGT_H
#define CM_TARGT_H

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

#ifdef CORE_OBJECTS



/****************************************************************************
**
** Constants
**
*****************************************************************************
*/

/*---------------------------------------------------------------------------
**
** CM_PS_xxx
**
** Connection processing state & steps completed bit masks.
** Used in setting/reading iState & iSteps in connection record.
**
**---------------------------------------------------------------------------
*/

/*
** General processing state.
*/

#define CM_PS_NEW             0x0000
#define CM_PS_OPENING         0x0001
#define CM_PS_OPEN            0x0002
#define CM_PS_CLOSING         0x0004
#define CM_PS_FAULTED         0x0008

/*
** Reserve, start, delete transport processing steps.
*/

#define CM_PS_R_TRAN_ISSUED   0x0001
#define CM_PS_R_TRAN_RETURNED 0x0002
#define CM_PS_S_TRAN_ISSUED   0x0004
#define CM_PS_S_TRAN_RETURNED 0x0008
#define CM_PS_D_TRAN_ISSUED   0x0010
#define CM_PS_D_TRAN_RETURNED 0x0020

/*
** Steps completed in talking to the object being connected to.
*/

#define CM_PS_AO_ISSUED       0x0040
#define CM_PS_AO_RETURNED     0x0080
#define CM_PS_AOC_ISSUED      0x0100
#define CM_PS_AOC_RETURNED    0x0200
#define CM_PS_AC_ISSUED       0x0400
#define CM_PS_AC_RETURNED     0x0800

/*
** Steps completed in talking to the target node (connection originator only).
*/

#define CM_PS_FO_ISSUED       0x1000
#define CM_PS_FO_RETURNED     0x2000
#define CM_PS_FC_ISSUED       0x4000
#define CM_PS_FC_RETURNED     0x8000



/****************************************************************************
**
** Typedefs
**
*****************************************************************************
*/

/*---------------------------------------------------------------------------
**
** cm_ConnectionRecordType
**
** Private portion of the connection record. Information here is for
** use only by the connection manager. The public portion of the
** connection record that applications may snoop at is defined in cm.h
**
**---------------------------------------------------------------------------
*/

typedef struct cm_ConnectionRecordType
{
   /*
   ** Information needed to handle the double linked list of conn records.
   */

   LL_DOUBLE_LINK_HEADER( cm_ConnectionRecordType );

   /*
   ** Public portion of connection record.
   */

   CM_ConnectionRecordType   sPublic;

   /*
   ** Connection processing state and processing steps completed information.
   */

   UINT16                    iState;
   UINT16                    iSteps;

   /*
   ** Hooks to the forward open and close packet tribbles.
   */

   CD_PacketTrrblType       *pTrrblFO;
   CD_PacketTrrblType       *pTrrblFC;

   /*
   ** Hook to the connection open/close request tribbles.
   ** Info needed to build a timeout notification tribble
   ** to the task that requested the connection origination.
   */

   CM_OpenTrrblType         *pTrrblOpen;
   CM_CloseTrrblType        *pTrrblClose;
   void                     *xUserHandle;
   GS_MsgQueueType           xQidOrig;

   /*
   ** Connection path for forward close packet.
   */

   UINT8                     bClosePathSize;
   LeUINT16                 *paiLePath;

   /*
   ** Remaining path size for forward open/close failure reply.
   */

   UINT8                     bRemainingPathSize;
}
cm_ConnectionRecordType;



/*---------------------------------------------------------------------------
**
** cm_DataType
**
** Private data for the connection manager's use.
**
**---------------------------------------------------------------------------
*/

typedef struct cm_DataType
{
   /*
   ** State indicating that we will allow connections or not.
   ** Connections disallowed during flash updates and the like.
   */

   BOOL fAllowConn;

   /*
   ** Dummy head node in connection record list.
   */

   LL_HEAD_NODE( cm_ConnectionRecordType )  sRecordList;

   /*
   ** Details for selecting a connection serial number.
   ** (Unique connection serial number for this node.)
   */

   UINT16 iConnSn;
   BOOL   fConnSnWrapped;
}
cm_DataType;



/*---------------------------------------------------------------------------
**
** cm_upsTrrblType
**
** Union of pointers to all tribble types used by the connection manager.
** Helps to eliminate those unsightly type casts.
**
**---------------------------------------------------------------------------
*/

typedef union cm_upsTrrblType
{
   GS_TrrblType               *Generic;
   CD_PacketTrrblType         *Packet;
   CD_TimeoutTrrblType        *Timeout;
   CD_TransportTrrblType      *Transport;
   CM_AppOpenCloseTrrblType   *AppOpenClose;
   CM_CloseTrrblType          *Close;
   CM_InquireTrrblType        *Inquire;
}
cm_upsTrrblType;



/****************************************************************************
**
** Globals
**
*****************************************************************************
*/

/*---------------------------------------------------------------------------
**
** cm_s
**
** Data structure holding private globals.
**
**---------------------------------------------------------------------------
*/

extern cm_DataType cm_s;



/****************************************************************************
**
** Services
**
*****************************************************************************
*/

/*---------------------------------------------------------------------------
**
** cm_BuildFwdErrorReply()
**
** Build a forward open or close error reply packet.
**
**---------------------------------------------------------------------------
**
** Inputs:
**    pCombuf              - Pointer to combuf to put reply in
**    iLeOrigConnectionSn  - Connection originator connection number
**    iLeOrigVendorId      - Connection originator vendor ID
**    lLeOrigDeviceSn      - Connection originator serial number
**    bPathSize            - Received Message Path size in words
**    bServiceCode         - IOI service code
**    bGRC                 - General status return code
**    iERC                 - Extended status return code (0 if none)
**
** Outputs:
**    None
**
** Usage:
**    cm_BuildFwdErrorReply( pCombuf,
**                           iLeOrigConnectionSn,
**                           iLeOrigVendorId,
**                           lLeOrigDeviceSn,
**                           bPathSize,
**                           bServiceCode,
**                           bGRC,
**                           iERC );
**
**---------------------------------------------------------------------------
*/

EXTFUNC void cm_BuildFwdErrorReply( CB_ComBufType *pCombuf,
                                    LeUINT16       iLeOrigConnectionSn,
                                    LeUINT16       iLeOrigVendorId,
                                    LeUINT32       lLeOrigDeviceSn,
                                    UINT8          bPathSize,
                                    UINT8          bServiceCode,
                                    UINT8          bGRC,
                                    UINT16         iERC );



/*---------------------------------------------------------------------------
**
** cm_CloseConnection()
**
** Close one connection whether we originated it or not.
**
**---------------------------------------------------------------------------
**
** Inputs:
**    pTrrbl            - Pointer to close tribble.
**    fTimeout          - Normal close or close becaue of a timeout.
**
** Outputs:
**    None
**
** Usage:
**    cm_CloseConnection( pTrrbl, TRUE );
**
**---------------------------------------------------------------------------
*/

EXTFUNC void cm_CloseConnection( CM_CloseTrrblType *pTrrbl, BOOL fTimeout );



/*---------------------------------------------------------------------------
**
** cm_ContinueClosing()
** cm_ContinueOpening()
** cm_ContinueProcessing()
**
** Continue the processing of opening or closing a connection.
** cm_ContinueProcessing is called to initiate the next processing step
** and calls either cm_ContinueOpening and cm_ContinueClosing depending
** on the state of the connection.
**
**---------------------------------------------------------------------------
**
** Inputs:
**    psConnRecord      - Pointer to connection record to process
**
** Outputs:
**    None
**
** Usage:
**    cm_ContinueProcessing( psConnRecord );
**
**---------------------------------------------------------------------------
*/

EXTFUNC void cm_ContinueClosing( cm_ConnectionRecordType *psConnRecord );
EXTFUNC void cm_ContinueOpening( cm_ConnectionRecordType *psConnRecord );
EXTFUNC void cm_ContinueProcessing( cm_ConnectionRecordType *psConnRecord );


/*---------------------------------------------------------------------------
**
** cm_DeleteCR()              - Delete the connection record
**
**---------------------------------------------------------------------------
**
** Inputs:
**    psConnRecord      - Pointer to connection record to process
**
** Outputs:
**    None
**
** Usage:
**    cm_DeleteCR( psConnRecord );
**
**---------------------------------------------------------------------------
*/

EXTFUNC void cm_DeleteCR( cm_ConnectionRecordType *psConnRecord );



/*---------------------------------------------------------------------------
**
** cm_FindConnection()
**
** Look for a matching active connection by serial number etc.
** If connection sn != 0, compare to connection serial number.
** If vendor id != 0, compare to vendor id, device sn, connection sn.
** If class != 0, compare to class, instance, connection points.
**
**---------------------------------------------------------------------------
**
** Inputs:
**    iConnectionSn     - Local connection serial number
**    iOrigVendorId     - Vendor ID of connection originator
**    lOrigDeviceSn     - Serial number of connection originator device
**    iOrigConnectionSn - Serial number of connection
**    iPort             - Port accociated with connection ( optional ).
**    iClass            - Object class being connected to
**    iInstance         - Object instance being connected to
**    iProConnPoint     - Producer connection point
**    iConConnPoint     - Consumer connection point
**
** Outputs:
**    Return            - Pointer to matching connection record
**                        NULL if no match found
**
** Usage:
**    pConnRecord = cm_FindConnection( iConnectionSn,
**                                     iOVendorId,
**                                     lODeviceSn,
**                                     iOConnectionSn,
**                                     iConnectionSn,
                                       iPort,
**                                     iClass,
**                                     iInstance,
**                                     iProConnPoint,
**                                     iConConnPoint );
**
**---------------------------------------------------------------------------

⌨️ 快捷键说明

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