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

📄 secs2.h

📁 SECS I, SECS II协议通讯源码
💻 H
字号:
/*
 * Definitions for the SECS2 portion of the SEMI protocol
 */
#ifndef SECS2_H
#define SECS2_H

/* Most constants in this file are specified in the SEMI standards */
#include "secs1.h"

/* Number of pauses required to lose a message from the status box */
#define NUM_TERM_PAUSES 20

/* Maximum data length for host terminal transfers */
#define HostTermLen 80

/* Number of enquiries which a SECS-2 function like SR_SELDATA can do` at once */
#define NUMBER_ENQUIRIES		512

/* Max number errors which can be queued at once */
#define NUMBER_SECS2_ERRORS	20

/* Length of ASCII string reception buffer */
#define MAX_RECEIVE_BUF		256

/* LoopBack Buffer Length */
#define MAX_LOOPBACK	1024

/* Used to flag a message as completely read */
#define RECEIVE_COMPLETE -1

/* And to flag that there is no message to read */
#define NO_RECEIVE_MESSAGE -1

/* Default Values, timers are in tenths of seconds */
// Used during communications establishing
#define TO_ESTABLISH	100

// Length of model & revision
#define SECS2_MODLEN 6
#define SECS2_SOFTLEN 6

// Length of Service Program ID
#define PPID_LENGTH 16
#define SPID_LENGTH 6

/* Stream values */

#define ST_ACTUALS		1
#define ST_PRESETS		2
#define ST_ALARMS		5
#define ST_PROCPROG 7
#define ST_ERRORS   9
#define ST_TERMINAL		10

/* Function values, stream 1 */
/* Status requests */
#define SR_AREYOUTHERE	1
#define SR_SELDATA		3
#define SR_FORMDATA		5
#define SR_FORMSPEC		7
#define SR_SELSPEC		11
#define SR_CR			13
#define SR_CRA			14

/* Function values, stream 2 */
/* Preset requests and misc controls */
#define PR_PROG_ENQ 1
#define PR_PROG_SEND 3
#define PR_PROG_LOAD 5
#define PR_PROG_RUN 7
#define PR_SELDATA		13
#define PR_SELCHANGE	15
#define PR_GETDATE		17
#define PR_RESET		19
#define PR_REMCMD		21
#define PR_LOOPBACK		25
#define PR_SELSPEC		29
#define PR_SETDATE		31

/* Function values, stream 5 */
/* Alarm functionality */
#define SA_REPORT   1
#define SA_ALMACK   2
#define SA_ENABLE   3
#define SA_REQUEST    5
#define SA_LISTENABLED  7

/* Function values, stream 8 */
/* Process Program functionality */
#define PP_INQUIRE 1
#define PP_SEND 3
#define PP_LOAD 5

/* Function values, stream 9 */
/* Secs Errors */
#define ER_UNRECDEV 1
#define ER_UNRECSTR	3
#define ER_UNRECFUN	5
#define ER_BADDATA	7
#define ER_TIMEOUT	9
#define ER_2MUCHDAT	11

/* Function values, stream 10 */
#define TR_DISPLAYLINE	3
#define TR_MULTIBLOCK 5
#define TR_NOMULTIBLOCK 7
#define TR_BROADCAST 9

/* SECS2 Item Format constants,
 * Note the lower two bits will tell how many length bytes there are,
 * the length bytes give the total length of the data in bytes, NOT
 * the number of items of the given format
 * With the exception of FM_LIST, of course
 */
#define FM_LIST	 0
#define FM_BINARY	 0x20
#define FM_BOOL	 0x24
#define FM_ASCII	 0x40
#define FM_BYTE	 0x64
#define FM_WORD	 0x68
#define FM_INT		 0x70
#define FM_DFLOAT	 0x80
#define FM_FLOAT	 0x90
#define FM_UBYTE   0xa4
#define FM_UWORD   0xa8
#define FM_UINT	 0xb0

/*
 * Alarm Code (ALCD) personality values, each alarm has it's own
 * personality
 */
#define AC_PERSONAL 1
#define AC_EQUIP	2
#define AC_PARMWARN	3
#define AC_PARMERR	4
#define AC_UNRECOV	5
#define AC_STATUS	6
#define AC_ATTEN	7
#define AC_DATINTEG	8

/*
 * ALED bit mask meaning enable alarm
 */
#define ALED_ENABLE 0x80

// ACKC5 alarm acknowledge values
#define ACKC5_ACCEPTED 0
#define ACKC5_UNACCEPTED 64

// ACKC10 terminal acknowledge values
#define ACKC10_OK 0
#define ACKC10_NOTACCEPTED 1
#define ACKC10_NOTERMINAL 2

/* Errors for command response (CMDA) */
#define CMD_ACK		0
#define CMD_BADCMD		1
#define CMD_BUSY		2

/* Errors for timeset response (TIACK)*/
#define TIME_ACK		0
#define TIME_BUSY		1

/* Errors for process Program send respose (PPGNT) , (ACKC7) */
#define PPGNT_OK 0
#define PPGNT_NOSPACE 2
#define PPGNT_BADPPID 3
#define ACKC7_OK 0
#define ACKC7_NOT_GRANTED 1
#define ACKC7_BADLENGTH 2
#define ACKC7_BADPPID 4
#define ACKC7_BADFORMAT 64

/* Errors for Program send respose (GRANT) (SPAACK) (CSAACK) */
#define SPAACK_OK 0
#define SPAACK_BADFORMAT 1
#define SPAACK_NOGRANT 64
#define SPAACK_BADLENGTH 65
#define CSAACK_OK 0
#define CSAACK_BADSPID 2
#define CSAACK_BADDATA 3
#define CSAACK_CANTRUN 64
#define GRANT_OK 0
#define GRANT_NOSPACE 2
#define GRANT_BADSPID 64

/* SPL function handler codes, not defined in SECS standards */
#define SPL_LOAD 0
#define SPL_SEND 1
#define SPL_RUN 2

/* PPL function handler codes, not defined in SECS standards */
#define PPL_REQUEST 0
#define PPL_SEND 1

/* Errors for preset response (EAC) */
#define EAC_ACK		0
#define EAC_BADCONST	1
#define EAC_BUSY		2
#define EAC_BADRANGE	3

/* Error codes for reset command (RAC) */
#define RAC_OK 0
#define RAC_DENIED 1

// Process Program Load functions for programs look like this
typedef BYTE (*PLFUNC)();  // Load function
typedef BOOL (*PVFUNC)();  // Validate function

/* Shorthand Macros to send format constants out to the buffer */
#define IF_LIST(len) Secs2Format(FM_LIST,len)
#define IF_BINARY(len) Secs2Format(FM_BINARY,len)
#define IF_BOOL(len) Secs2Format(FM_BOOL, len)
#define IF_ASCII(len) Secs2Format(FM_ASCII,len)
#define IF_BYTE(len) Secs2Format(FM_BYTE,len)
#define IF_WORD(len) Secs2Format(FM_WORD,len<<1)
#define IF_INT(len) Secs2Format(FM_INT,len<<2)
#define IF_DFLOAT(len) Secs2Format(FM_DFLOAT,len<<3)
#define IF_FLOAT(len) Secs2Format(FM_FLOAT,len<<2)
#define IF_UBYTE(len) Secs2Format(FM_UBYTE,len)
#define IF_UWORD(len) Secs2Format(FM_UWORD,len<<1)
#define IF_UINT(len) Secs2Format(FM_UINT,len<<2)

#define FV(x) Secs2bFormatValidate(x)

#define RB Secs2bReceiveByte
#define RW Secs2bReceiveWord
#define RI Secs2bReceiveInt
#define RA(x) Secs2bReceiveAscii(x);
#define RF Secs2bReceiveFloat
#define RD Secs2bReceiveDfloat
#define SB(x) Secs2bSendByte(x)
#define SW(x) Secs2bSendWord(x)
#define SI(x) Secs2bSendInt(x)
#define SA(x,y) Secs2bSendAscii(x,y)
#define SF(x) Secs2bSendFloat(x)
#define SD(x) Secs2bSenddFloat(x)

/* Error entry structure */
typedef struct {
   int stream;  /* Stream of error to report */
   int func;  /* Function of error to report */
   SECS1_HEADER h;	/* Header which caused error */
} SECS2_ERROR;

/* SECS2-Function id to actual function translation structure*/
typedef struct {
   int val; /* SECS2 id */
   FUNC func;	/* Function to call */
} PASSFUNC;

// data structure for SPL/PPL validates
typedef struct {
  PVFUNC validate; // Validate function
  PLFUNC exec;  //Load function
} PROGFUNC;

/*
 * Alarm structure, defines each individual alarm
 * the SECS2 alarm ID is given by the indice into a table of such structures
 */
typedef struct {
  PTEXT *text;    /* Pointer to name */
  BOOL *value;		/* Pointer to value */
  BYTE alcd; /* ALCD */
  BYTE alstate;  /* ON or OFF */
  BYTE clearable;/* True if clearable */
  BYTE enabled;  /* True if enabled for send */
} SA_STRUC ;

/* Status structure, defines each individual status (actual) value
 * the SECS2 status ID is given by the indice into a table
 */
typedef struct {
  PTEXT *text;    /* name */
  void *value;    /* pointer to value, usage depends on UNITS */
  int units;    /* Units */
} SR_STRUC;

/* Preset structure, defines each individual preset value
 * the SECS2 preset ID is given by the indice into a table
 */
typedef struct {
  PTEXT *text;      /* Text */
  void *value;      /* Pointer to value, usage depends on UNITS */
  int units;      /* Units */
} PR_STRUC;


/* SECS2 prototypes */
#include "secs2.p"

#endif /* SECS2_H */

⌨️ 快捷键说明

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