?? udprot.h
字號:
/* $Header: "%n Ver=%v %f LastEdit=%w Locker=%l" */
/* "UDPROT.H Ver=1 5-Nov-97,14:00:00 LastEdit=JIMV Locker=***_NOBODY_***" */
/***********************************************************************\
* *
* Copyright Wonderware Software Development Corp. 1989-1997 *
* *
* ThisFileName="L:\ww\dde_serv\src\udsample\udprot.h" *
* LastEditDate="1997 Nov 05 14:00:00" *
* *
\***********************************************************************/
#ifndef H__udprot
#define H__udprot
#ifndef LINT_ARGS
#define LINT_ARGS
#endif
#include "protypes.h"
#include "wwheap.h"
#include "ntconv.h"
#include "Utitech.h"
#include "chainmgr.h"
#define DEBUG_CALL_TRAFFIC
extern HHEAP hHeap;
extern BOOL ShowingSend; /* display commands to PLC in logger */
extern BOOL ShowingReceive; /* display replies from PLC in logger */
extern BOOL ShowingErrors; /* display error messages in logger */
extern BOOL ShowingEvents; /* display events in logger */
extern BOOL IndefWriteRetry; /* retry write messages even after loss of connection */
extern BOOL Verbose; /* display program trace messages */
extern BOOL DebugMenu; /* enable debug menu on server window */
extern BOOL WriteConfigInASCII; /* write configuration file as structures */
extern BOOL bDoHelp;
#define DBG_BUF_SIZE 512 /* size of local buffer for trace, debug info */
extern char dbgBuf[]; /* local buffer for trace, debug info */
/** When the comm port is opened, we must specify
the sizes of the transmit and receive buffers. **/
#define INQSIZE 1024
#define OUTQSIZE 1024
/** definitions for communications recovery **/
#define PROT_RETRIES 3
#define TOPIC_RECOVERY_RETRIES 1
#define TOPIC_NORMAL_RETRIES 2
#define TOPIC_CONSEC_FAILURE_LIMIT 2
#define ERRORDELAY 1000 /* One second */
#define SLOW_POLL_MULTIPLIER 15
#define SLOW_POLL_MIN 15000 /* 15 second min on slow poll */
#define SLOW_POLL_MAX 300000 /* 5 minute max on slow poll */
/* Protocol States
Processing of the protocol based on timer tick messages causes the
driver to be organized as a state machine. These are the states:
*/
#define PROT_IDLE 300
#define PROT_WAITRESP 301
#define PROT_PROTERRORDELAY 302
#define PROT_WAITQUIET 303
#define PROT_WAITHDR 304
/**************************************************************\
Assign the correct values for these constants
\**************************************************************/
#define UD_BLOCK_DATA_START 3
#define UD_MAX_WRITE_LENGTH 100 /* max number of bytes in outgoing data */
#define UD_MAX_READ_LENGTH 100 /* max number of bytes in incoming data */
/* Default values for <Your Name> Server Operational Parameters */
#define MIN_DDEBLOCKSIZE 512
#define MAX_DDEBLOCKSIZE 64512
#define DEFAULT_PROTTIMER 50
#define DEFAULT_RQTIMER 1000
#define DEFAULT_DDEBLOCKSIZE 4096
#define DEFAULT_RETRYINDEF FALSE
#define DEFAULT_PATH ""
#define NAME_PROTTIMER GetString(STRUSER+1) /* "ProtocolTimer" */
#define NAME_VDTIMEOUT GetString(STRUSER+2) /* "ValidDataTimeout" */
#define NAME_RQTIMER GetString(STRUSER+4) /* "RequestTimer" */
#define NAME_DDEBLOCKSIZE GetString(STRUSER+6) /* "DDEBlockSize" */
#define NAME_RETRYINDEF GetString(STRUSER+8) /* "WriteRetryIndefinitely" */
#define NAME_PATH GetString(STRUSER+7) /* "ConfigurationFile" */
/***********************************************************************\
* Message Data Structure *
\***********************************************************************/
typedef struct tagUDMSG {
CHAINLINK mmChainLink;
struct tagSTAT FAR* mmTopic;
IDLDEV mmIdLogDev;
WORD mmStartAddr;
WORD mmEndAddr;
WORD mmCount;
unsigned long mmFirstSym;
unsigned long mmLastSym;
BYTE mmMsgType;
BYTE mmDataType;
int mmSize;
long mmScanTimer;
long mmScanReload;
int mmActiveCt;
BYTE mmMbType;
BYTE mmTopicId;
unsigned mmDue : 1;
unsigned mmRead : 1;
unsigned mmDiscrete : 1;
unsigned mmChanged : 1;
unsigned mmMsgInBinary : 1;
BYTE mmOutData[UD_MAX_WRITE_LENGTH];
BYTE mmData[1];
} UDMSG, FAR *LPUDMSG;
/***********************************************************************\
* Symbol Table Data Structure *
\***********************************************************************/
/* The symbol table organization is thus:
Each node (or station or topic) has a single data structure allocated
from the FAR heap (using GlobalAlloc()). It is of type SYMTAB with
the number of entries in the msSym field adjusted dynamically to
handle the symbol table size.
Each entry in the msSym array is of type SYMENT. These array entries
are linked in order of ascending msAlias using the chain manager
structure CHAINLINK. Since the symbol table may grow or shrink by being
reallocated, its location in memory may change. Consequently, the
chains of used symbols and of unused symbols are handled using offsets
and a base address, which is updated whenever the table is reallocated.
The hProt is a handle used in communicating with the outside world.
It identifies a symbol table entry (relative to a node) by being
INDEX+SYM_OFFSET in the msSym array. It could have been the index,
but hProt must use zero to represent an invalid handle, and for
simplicity reserved points such as STATUS are assigned handles below
SYM_OFFSET.
*/
#define HPROT_STATUS 1 /* DB handle for reserved STATUS word */
#define SYM_OFFSET 2 /* handle offset for all other points */
/* A simple symbol table is maintained to permit mapping the protocol-
specific data format into the I/O handler's notation. This constant
controls the symbol granularity.
*/
#define SYMTABQUANTUM 64
#define SYMTABMAXCOUNT 65536L
/******************************************************************\
The SYMENT structure must be a power of two bytes in length.
The define below must be the power of two size of the SYMENT
structure. Adjust the pad[] field of the structure so that
the size of the structure is equal to SIZE_SYMENT.
\******************************************************************/
#define SIZE_SYMENT 32
typedef struct tagSYMENT {
CHAINLINK msChainLink; /* link with list of symbols */
unsigned long msIndex; /* index within symbol array */
HDB msDbHnd; /* handle from toolkit */
int msLockCt;
unsigned msNumBytes : 6;
unsigned msActive : 1;
unsigned msBCD : 1;
unsigned msDdeType : 3;
unsigned msMbType : 3;
unsigned msSigned : 1;
unsigned msBadBCDRead : 1;
WORD msBitPos;
WORD msCount;
struct tagUDMSG FAR* msPollMsg;
/******************************************************************\
The following fields must uniquely define the item names that
are supported by the driver. Add msAddr? fields if more are
required for your driver. Make sure that LogicalAddressCompare
is modified to properly sort these fields in the symbol table.
\******************************************************************/
BYTE msPlcDataType;
BYTE msSubType;
WORD msAddr1;
/******************************************************************\
Add more msAddr? fields as required and change
LogicalAddressCompare.
WORD msAddr2;
WORD msAddr3;
\******************************************************************/
/******************************************************************\
The SYMENT structure must be a power of two bytes in length.
Modify the pad[] field to insure that this requirement is met.
\******************************************************************/
// BYTE pad[16];
} SYMENT, huge * SYMPTR;
/** The ACTIVE_CHECK structure is used for finding a symbol that is
active and is referenced by a particular message **/
typedef struct tagACTIVE_CHECK
{
LPUDMSG lpMsg; /* pointer to message */
unsigned long finalHandle; /* final handle to check */
unsigned long SymHandle; /* symbol handle if match found */
} ACTIVE_CHECK;
/**************************************************************\
Device specific names and identifiers go here
The following example shows point types for an
example server which has two memory ranges:
V memory -- variables, 16 bit cells, address range 1-512
C memory -- counters, 16 bit cells, address range 1-512
\**************************************************************/
/* device point types */
#define PLC_V 1 /* variable memory */
#define PLC_C 2 /* counter memory */
/**************************************************************\
Server-defined subtypes go here
These can be defined to suit the addressing and data methods
you wish to implement: integers, reals, strings, etc.
\**************************************************************/
/* sub-types */
#define PLCS_NONE 0 /* no subtype */
#define PLCS_BIN 1 /* binary */
#define PLCS_BCD 2 /* BCD word */
#define PLCS_WORD 3 /* unsigned word */
#define PLCS_SIGNED 4 /* signed word */
#define PLCS_DWORD 5 /* double word (unsigned) */
#define PLCS_BITP 6 /* bit position within a word */
#define PLCS_REAL 7 /* real, IEEE format */
#define PLCS_DOT 8 /* real, IEEE format */
#define PLCS_IBM 9 /* real, IBM format */
#define PLCS_STRC 10 /* null-terminated (C-style) string */
#define PLCS_STRP 11 /* length-byte-first (PASCAL-style) string */
#define PLCS_STRB 12 /* blank-padded (B-style) string */
#define PLCS_STR_ 13 /* blank-padded (B-style) string */
/***********************************************************************\
* Station Data Structure *
\***********************************************************************/
/* Each node (or station or topic) is represented by a data structure
allocated from the FAR heap (using GlobalAlloc()). It contains all
of the information needed to identify a node and to perform the
protocol.
The station data structure (STAT) is located from the Port data
structure or directly by the handle which is passed as a parameter to
many of the functions called from the outside world.
The station contains handles to the associated symbol table and a
list of messages to be sent to the node.
*/
#define MAX_CONSEC_WRITES 2
typedef struct tagSTAT {
CHAINLINK statChainLink; /* link with station list */
DWORD statUpdatePeriod;
struct tagPORT FAR* statPort;
CHAIN statReadMsgList;
CHAIN statWriteMsgList;
struct tagUDMSG FAR* statCurMsg;
struct tagUDMSG FAR* statCurReadMsg;
EXTARRAY statSymTab; /* symbol table (extensible) */
EXTARRAY statSymInd; /* indexes of used symbols */
CHAIN statSymUsed; /* list of used symbol entries */
CHAIN statSymUnused; /* list of unused symbol entries */
HDB statHdbStatus;
WORD statCoilReadSize;
WORD statRegReadSize;
DWORD statReplyTimeout;
LONG statDelay;
int statRetries;
int statPortRetries;
IDLDEV statIdLogDev;
unsigned statFailed :1;
unsigned statStatusActive:1;
unsigned statStatusDue :1;
unsigned statConsecWrites:3;
BYTE statTopic;
char statTopicName[33];
} STAT, FAR *LPSTAT;
/***********************************************************************\
* Port Data Structure *
\***********************************************************************/
/* Each port is represented by a data structure (of the type PORT) which
contains all of the information needed to control the port in processing
the protocol. It contains a handle to a linked list of nodes. It
also contains the handles of the currently-active node and message.
*/
#define MAX_PORT_NAME_LEN 33
typedef struct tagPORT {
CHAINLINK mbChainLink; /* forward/backward list pointers */
char mbPortName[MAX_PORT_NAME_LEN];
char mbConfigString[20]; /* configuration string */
CHAIN mbTopicList; /* list of topics on this port */
struct tagSTAT FAR* mbCurTopic; /* topic currently being serviced */
struct tagUDMSG FAR* mbCurMsg; /* message currently being serviced */
int mbState; /* communication state */
int mbRetries; /* number of retries */
int mbTimer; /* timer for when to check port */
int mbRspIndex; /* number of characters received */
int mbRspExpLen; /* expected length of response */
int mbReplyTime; /* reply timeout limit (in msec) */
BOOL mbMsgInBinary; /* =TRUE if message is in binary form */
BOOL mbDoingRead; /* =TRUE if doing a read (polling) */
int mbCid; /* COM port ID for serial port */
WORD mbMemSegment; /* MEM segment address for board */
WORD mbIoAddr; /* I/O address for board */
void FAR * mblpBoardMem; /* pointer to board memory buffer */
HANDLE mbhPermission; /* handle for access to board memory */
BYTE mbRspBuffer[ RSP_BUF_SIZE ]; /* response buffer */
} PORT, FAR * LPPORT;
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -