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

📄 secs1.h

📁 SECS I, SECS II协议通讯源码
💻 H
字号:
/*
 * Header defining things useful in the SECS-1 part of the SEMI protocol
 */
#ifndef SECS1_H
#define SECS1_H

#include "utype.h"

/* Define various characters supported in SECS-1 */
#ifndef EOT
#define EOT 4
#define ENQ	5
#define ACK	6
#define NAK	21
#endif //EOT
/*
 * Modify the following to allocate data buffers
 * Note that send buffer and expected list are circular queues,
 * the expected list points to a linked list of receive buffers
 * Buffers are allocated statically to avoid costly ( in terms of time)
 * dynamic memory management functions.
 *
 */
#define NUMBER_RECEIVE_BLOCKS   32
#define NUMBER_SEND_BLOCKS    32
#define NUMBER_EXPECTED_BLOCKS  20

/*
 * SECS-1 block constant
 */
#define MAX_BLOCK_LEN	244
#define SECS1_HEADLEN 10

/*
 * MRA and BTP erros
 */
#define BTP_NO_DATA -1
#define BTP_NO_FIRST -1
#define BTP_ALLOC_ERR -1
#define MRA_ALLOC_ERR -1
#define MRA_NO_BLOCK -1

/*
 * Default values for SECS-1, these must be modifiable per the spec.
 * Timeout values are in tenths of seconds
 */
#define DF_BAUD		9600
#define DF_DEVID		1
#define TO_INTERCHAR	5
#define TO_PROTOCOL		100
#define TO_REPLY		450
#define TO_INTERBLOCK	450
#define DF_RETRY		3

/*
 * Communications parameters
 */
#define EVEN_PARITY 1
#define ODD_PARITY 0
#define STOP_2 1
#define STOP_1 0
/*
 * Macro returns true if is primary message
 */
#define IS_PRIMARY(xx) (xx.h.Lmessage & 1)

/*
 * Communication line characteristics
 */
typedef struct {
  int BaudRate;         // Use this baud rate
  int MultiDropAddress; // Current multidrop address
  int StopBits:4;       // Number of stop bits
  int DataBits:3;       // Number of data bits
  int ParitySense:1;    // Parity sense, TRUE = even
  int ParityOn:1;       // Parity enable
  int XonXoff:1;        // xon/xoff usage
} COMMSTATES;

/*
 * Structure for timers
 * SECS_TIMER_MAX is the tick rollover for timing purposes
 * SECS_TIMER_MUL and SECS_TIMER_DIV convert from the equipment clock to tenths
 * of seconds
 */
typedef struct {
	uint length;    /* Timer interval, in deci-seconds */
  uint startval;  /* Started timing at this tick */
	uint TickLength; /* Timer interval, ticks */
  BOOL timing;    /* True if timing */
} SECS_TIMER;
/*
 * The SECS-1 header structure.  Notice the implicit assumption, that the
 * compiler will allocate bit fields in the required order.
 * If the compiler does allocate bits starting with bit 0,
 * the SECS1 protocol will fail
 */
typedef struct {
  BYTE Udevice : 7;  /* Upper device */
  BYTE R : 1;    /* Direction bit- 0= to equipment */
  BYTE Ldevice;    /* Lower device */
  BYTE Umessage : 7; /* Upper message (Stream ) */
  BYTE W : 1;    /* Set if waiting for a reply */
  BYTE Lmessage;   /* Lower message (Function) */
  BYTE Ublock : 7; /* Upper block # */
  BYTE E : 1;    /* Set if is last block */
  BYTE Lblock;   /* Lower block number */
  BYTE system1;  /* System 1 */
  BYTE system2;  /* System 2 */
  BYTE system3;  /* System 3 */
  BYTE system4;  /* System 4 */
} SECS1_HEADER;
/*
 * A SECS-1 data block
 */
typedef struct {
  uint nextblock; /* Chain to next block */
  BYTE ready_to_send; /* Ready to send flag */
  BYTE length;   /* Length of data,
                   * Note the SECS1 code uses it to locate the header and thus
                   * the length, header, data order must be preserved
                   */
	SECS1_HEADER h;	/* Header data */
  BYTE data[MAX_BLOCK_LEN];  /* Block data */
} SECS1_BLOCK;

/* Message Resource allocation status constants
 * Used to flag expected blocks status
 * A FREE block is usable, a COMPLETE block is done being received,
 * an ABORTED block has been aborted and must be deallocated by the
 * SECS2 protocol when convenient
 */
#define MRA_FREE 0
#define MRA_COMPLETE  1
#define MRA_ABORT        2

/* MRA timing status constants
 * MRA timers may be off or may be used either while awaiting a reply
 * or waiting for another block in a multiblock message
 */
#define MRA_NOTIMING		0
#define MRA_REPLY_TIME		1
#define MRA_INTERBLOCK_TIME	2

/*
 * each item in Expected list holds pointer to a linked list of receive
 * data buffers, the last buffer currently allocated, and enough information
 * to uniquely identify the header of associated blocks.  Note that by
 * SECS1 standards the system bytes are enough to specify uniqueness, however
 * there are some subtle bugs that can sneak in if the stream and function
 * are not used as well.  Such as, we post the expectation of a reply
 * (secondary block) but a primary block comes in with the expected system
 * bytes for whatever reason.  Bad news for the way the MRA routines are coded.
 */
typedef struct {
  BYTE status;  /* Status of this receive */
  BYTE timing;  /* Status of timer */
  int nextblock; /* Last block which has been alloated */
	int firstblock; /* First block in linked list */
	int blocknum;	/* SECS-1 block number */
  SECS1_HEADER h; /* SECS-1 HEADER, in case of timeout during expectation */
  SECS_TIMER timer;  /* T3 or T4 Timer (REPLY or INTERBLOCK) */
} EXPECTED;

// Load SECS-1 prototypes
#include "secs1.p"

#endif /* SECS1_H */

⌨️ 快捷键说明

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