#define WORK_BUF_SIZE 64 /**************************************************************************/ /* CHARS_PER_SEC */ /* FIXED_TIMEOUT_TIME */ /* Controls time out time in both transmitting and receiving messages */ /* */ /* Very precise time out control is allowed by setting these values. */ /* FIXED_TIMEOUT_TIME is also used as the time out time for receiving the */ /* lead character and the length of a message when time out is enabled */ /* for receiving a message. After the length of the message is received, */ /* a new time out time (used for receiving the rest of the message) is */ /* computed based on CHARS_PER_SEC. */ /* */ /* Conservative estimates for CHARS_PER_SEC for different baud rates: */ /* 1200 baud 100 */ /* 9600 baud 800 */ /**************************************************************************/ #define CHARS_PER_SEC 800 #define FIXED_TIMEOUT_TIME 1000 /* Special station values are 0x6000 - 0x603f. */ #define ANY_STAT 0x603f #define NO_STAT 0x603e #define DEST_STAT 20 #define HAND_MAX 4 #define O_RAW O_BINARY /* This macro translates the C 2.0 name */ /* used to force binary mode for files. */ /* Message types : */ #define ACK 1 #define NAK 2 #define GETD 10 /* Get discrete values. */ #define GETB 11 /* Get bytes of discrete values. */ #define GETA 12 /* Get analog values. */ #define PUTB 15 /* Put bytes of discrete values. */ #define PUTA 16 /* Send analog values. */ #define SETD 17 /* Turn on all discrete values specified. */ #define CLRD 18 /* Turn off all discrete values specified. */ /* I/O Types: */ #define DEF_IN 0 #define DEF_OUT 1 #define FLT_IN 22 #define FLT_OUT 23 /* Special value for time out computations in Microsoft C. */ #define TICKS_PER_SEC (18.2) #define IS_SPECIAL 0x0001 #define LEAD_CHAR 0x0002 #define GET_LEAD_CHAR 0x0001 #define GET_SPECIAL 0x0002 typedef unsigned char uchar; typedef signed char schar; typedef unsigned short ushort; typedef unsigned long ulong; typedef volatile short aio_t; typedef struct { short stat; /* Station number being talked to. */ schar m_in; /* Ptr to next free byte in m_buf. */ schar m_out; /* Ptr to 1st byte to send in m_buf. */ schar m_cnt; /* Number of bytes in m_buf. (128 max) */ schar s_in; /* Ptr to next free byte in s_buf. */ schar s_out; /* Ptr to 1st byte to send in s_buf. */ schar s_cnt; /* Number of bytes in s_buf. (128 max) */ uchar s_buf[128]; /* Buffer for characters going to slave port */ uchar m_buf[128]; /* Buffer for characters going to master port. */ } PT_CONT; /* Control block for Universal Driver has all neccessary information. */ /* - control block is to be declared as a local variable. */ /* - control block is passed to all Universal Driver functions. */ /* - no global variables exist for the Universal Driver. */ /* With all of these conditions met, the Universal Driver is reentrant */ /* which means that multiple copies of any of its' functions or tasks */ /* can be executed concurrently. */ typedef struct { uchar wbuf[WORK_BUF_SIZE]; /* Commands are written here and */ /* responses are received here. */ int buf_i; /* Index into wbuf. */ int num_read; /* Number of chars read, used by 'rv' only. */ short form; /* Format BIN or HEX. */ short len; /* Total message length (not including len byte). */ short hlen; /* Length of header info. */ short dlen; /* Length of data. */ short stat; /* Receiving station number. */ short orig; /* Sending stations station number. */ short sess; /* Session number. */ short cmd; /* Type of command. */ short timo; /* Time out enable. */ ushort to_time; /* Time out time, used if timo is enabled. This is */ /* computed by: CHARS_PER_SEC / FIXED_TIMEOUT_TIME */ ushort s_time; /* Start time. */ short start; /* This is used in time control. */ ushort crc; /* Working value of crc. */ uchar id; /* Byte sequence number is echoed by this driver. */ } MSG_CONT; typedef struct { int control; /* Control word to flag various info: */ MSG_CONT tx; /* Transmit message control structure. */ MSG_CONT rv; /* Receive message control structure. */ } UD_CONT; /* Lowest Level Functions */ int udgetchar( UD_CONT *ct, ushort *inchar); int get_mess_char(UD_CONT *ct,ushort *inchar, ushort control ); short set_transmit_timo(UD_CONT *ct, ushort mess_len); short write_cmd_buf(UD_CONT *ct, ushort outval, ushort control ); short flush_cmd_buf(UD_CONT *ct); int num_bytes_avail(UD_CONT *ct); int free_buf_space(UD_CONT *ct); /* Middle Level Functions */ int transmit_mess(UD_CONT *ct,uchar *hbuff, uchar *dbuff); int receive_mess(UD_CONT *ct,uchar *buff); int init_udr_ct(UD_CONT *ct);