Subversion Repositories factorylink.valmet

Rev

Rev 18 | Blame | Compare with Previous | Last modification | View Log | Download

/*
 ******************************************************************************
 *  Copyright 1995 DeltaLink bv. All Rights Reserved.
 ******************************************************************************
 *
 * DeltaLink Decoder Header file
 *
 * File: val_pd.h
 *
 * Contains definitions for the DeltaLink Valmet Protocol driver task
 */
#ifndef _VAL_PD_DEFS_INCLUDED /* { */
#define _VAL_PD_DEFS_INCLUDED 1

#include "val_ct.h"

#ifndef HPUX
#pragma pack(1)
#else
#pragma HP_ALIGN HPUX_WORD PUSH
#endif

/* defines for read/write array */

#define COM_READ   0
#define COM_WRITE  1

#define READBUF_SIZE    4096
#define WRITEBUF_SIZE   4096

/*
 * This is the maximum address table length
 */
#define MAX_ADDRESS_TABLE_LEN 300
 
/* define the different conversions */
#define C_BIT             1           /* BIT conversion */
#define C_BYTE_R          2           /* RIGHT byte conversion */
#define C_BYTE_L          3           /* LEFT byte conversion */
#define C_WORD            4           /* WORD conversion */
#define C_LONG            5           /* LONG conversion */
#define C_IEEE_DOUBLE     6           /* DOUBLE precision float conversion */
#define C_MSG             7           /* message conversion */
#define C_IEEE_FLT        8           /* IEEE single presicion float conversion */
#define C_BCD             10          /* Binary Coded Decimal conversion */
#define C_BYTE            11          /* BYTE conversion */

#define C_SIE_FLT         9           /* SIEMENS float conversion */

#define C_IBG             12          /* Interbus-S Gain for analog in/out */
#define C_IBAU            13          /* Interbus-S Analog Input/Output 12 bits Unsigned */
#define C_IBAS            14          /* Interbus-S Analog Input/Output 12 bits two's complement */

#define C_R_LONG          15          /* reversed long conversion */
#define C_R_FLT           16          /* reversed float conversion */



/*
 *-----------------------------------------------------------------------------
 *  Definition of relevant structures and related types
 *-----------------------------------------------------------------------------
 */

/* definition of a valmet word. Note that as Valmet is also little endian as is Intel
 * The valmet word and the Intel word are alike
*/
typedef unsigned char UBYTE;
//typedef unsigned int UWORD;

typedef struct {

  UBYTE lsb;
  UBYTE msb;

} INTEL_WORD;

typedef struct {

  UBYTE lsb;
  UBYTE msb;

} VALMET_WORD;

/* definition of the possible message types, as far as we use them  */

typedef enum {

  UPDATING_SEQUENTIAL = 0x1A,
  QUERY_SEQUENTIAL = 0x18,
  ANSWER_SEQUENTIAL = 0x19,
  UPDATING_RANDOM = 0x1E,
  QUERY_RANDOM = 0x1C,
  ANSWER_RANDOM = 0x1D,
  UNKNOWN     = 0

} MESSAGE_TYPE;

/* definition of the maximum number of words that the datapart of a message can contain */
#define MAX_WORDS_IN_MESSAGE 0x40

/* the definition of the relevant parts of the Valmet message as far as they
 * are not related to message delimiters, BCC and so on 
 */
typedef struct {

  /* the type of the message (for example query/random) */

  UBYTE     Type;

  /* the length information as defined by Valmet. Note that this length 'byte' does not
   * have any relation with the length in bytes or in words. It is a logical indication
   * of the number of logical entities in the message
   */

  UBYTE     Length;

  /* the number of words in the message. This has 'no' relation with the length field */

  unsigned int  NrWords;

  /* the words in the message */

  VALMET_WORD   Words[ MAX_WORDS_IN_MESSAGE ];

} VALMET_BASIC_MSG;

/* definition of the maximum message that could be sent or received over the COM-port, including
 * STX, transparancy bytes, BCC
*/
#define  VALMET_MSG_BUFFER_SIZE (1+ /*STX*/ + 1 /*Type*/ + 1 /*Length*/ + \
      (2 * /* all bytes duplicated */ 2 * /*bytes in word*/ MAX_WORDS_IN_MESSAGE) \
      + 1 /*ETX*/ + 1 /*BCC */ ) 
typedef UBYTE VALMET_MSG_BUFFER[VALMET_MSG_BUFFER_SIZE];
typedef struct {
  UWORD BufferLength;
  VALMET_MSG_BUFFER Buffer;
} VALMET_MSG;


/*
 *-----------------------------------------------------------------------------
 *  Definition of how to access the Valmet device (sequential or random)
 *-----------------------------------------------------------------------------
 */

// comment out line below to use random access to Valmet
#define USE_SEQUENTIAL 1

#ifdef USE_SEQUENTIAL
  #define BuildDefineDatasetCmd BuildSequentialDefineDatasetCmd
  #define BuildReadDatasetCmd   BuildSequentialReadDatasetCmd
  #define ExpectedAnswerType    ANSWER_SEQUENTIAL
#else
  #define BuildDefineDatasetCmd BuildRandomDefineDatasetCmd
  #define BuildReadDatasetCmd   BuildRandomReadDatasetCmd
  #define ExpectedAnswerType    ANSWER_RANDOM
#endif

/*
 *-----------------------------------------------------------------------------
 *  Definition of relevant error codes in status tag 
 *-----------------------------------------------------------------------------
 */
#define ERROR_SERIAL              300
#define ERROR_BASE                350
#define ERROR_FACTORYLINK         400
#define ERR_READ_DISABLED         (ERROR_BASE)
#define ERR_WRITE_DISABLED        (ERROR_BASE+ 1)
#define ERR_COM_PORT_NOT_OPENED   (ERROR_BASE+ 2)
#define ERR_INVALID_BCC           (ERROR_BASE+ 3)
#define ERR_INVALID_ANSWER_TYPE   (ERROR_BASE+ 4)
#define ERR_INVALID_LENGTH        (ERROR_BASE+ 5)
#define ERR_INVALID_NR_WORDS      (ERROR_BASE+ 6)
#define ERR_TIMEOUT               (ERROR_BASE+ 7)
#define ERR_EXTRA_CHARS           (ERROR_BASE+ 8)
#define ERR_MSG_COMPOSITION       (ERROR_BASE+ 9)
#define ERR_DEVICE_DISABLED       (ERROR_BASE+10)
#define ERR_TCPCONN_DISABLED      (ERROR_BASE+11)
#define ERR_MAX_WORDS_FOR_SET     (ERROR_BASE+12)
#define ERR_TIMEOUT_ACK           (ERROR_BASE+13)
#define ERR_MCI_UNSUPPORTED       (ERROR_BASE+14)
#define ERR_INTERNAL              (ERROR_BASE+15)


/*
 *-----------------------------------------------------------------------------
 *  Definition of relevant prototypes
 *-----------------------------------------------------------------------------
 */

/* general DeltaLink required functions */

int   main( void);
int   mci_event( MCI_DEVICE * mt_dev, int function );
int   read_write(MCI_DEVICE * dev, MCIDS * ds, char func );
void  complete_tags( VAL_DEVICE * dev, MCIDS * ds, int error );
int   check_decoder( VAL_DEVICE * dev, MCIDS * ds);
void  complete( VAL_DEVICE * dev, MCIDS * ds, char func);
void  complete_error( VAL_DEVICE * dev, MCIDS * ds, char func, uint error );
int   pd_error(VAL_DEVICE * dev, char func);
int   event_read_disable( void * d, VAL v);
int   event_write_disable( void * d, VAL v);
int   event_redefine( void * d, VAL v);
int   event_tcp_connect( void * d, VAL v);
int   event_driver_disable( void * d, VAL v);
short DC_get_max_msg( TAG dec);


/* Valmet specific functions */
void  InitBasicMessage(VALMET_BASIC_MSG * BasicMsg);
void  FillMessageType(VALMET_BASIC_MSG * BasicMsg, MESSAGE_TYPE Type);
void  FillMessageLength(VALMET_BASIC_MSG * BasicMsg, UBYTE Length);
void  AddWordToMessage(VALMET_BASIC_MSG * BasicMsg, UWORD Word);
void  Add2BytesToMessage(VALMET_BASIC_MSG * BasicMsg, UBYTE Byte1, UBYTE Byte2);
UBYTE BCCFromMessage(VALMET_BASIC_MSG * BasicMsg);
void  InitMessageBuffer(VALMET_MSG * Msg);
void  AddByteToBufferMsg(VALMET_MSG * Msg, UBYTE UByte);
void  AddByteWithTransparancyToBufferMsg(VALMET_MSG * Msg, UBYTE UByte);
void  ConstructBufferMessage(VALMET_BASIC_MSG * BasicMsg, VALMET_MSG * Msg);
UBYTE Make_b1(u16 datatype, u16 datadir);
UBYTE Make_b2(u16 signalb);
UBYTE Make_b3(u16 signalp, u16 signalg, u16 blockmes);
UBYTE Make_b4( u16 statnum, u16 busnum, u16 bustype);

int   DoRead( VAL_DEVICE * dev, MCIDS * ds, VAL_DATASET * ds_info);
int   ReadDataset( VAL_DEVICE * dev, MCIDS * ds, VAL_DATASET * ds_info);
int   DefineDataset(VAL_DEVICE * dev, VAL_DATASET * ds_info, int * DatasetDefined);
int   SendDefineDatasetCmd(VAL_DEVICE * dev, VAL_DATASET * ds_info);
int   SendReadDatasetCmd(VAL_DEVICE * dev, VAL_DATASET * ds_info);
int   BuildRandomDefineDatasetCmd(VAL_DEVICE * dev,VALMET_BASIC_MSG * BasicMsg, VAL_DATASET * ds_info);
int   BuildSequentialDefineDatasetCmd(VAL_DEVICE * dev,VALMET_BASIC_MSG * BasicMsg, VAL_DATASET * ds_info);
int   BuildRandomReadDatasetCmd(VAL_DEVICE * dev,VALMET_BASIC_MSG * BasicMsg, VAL_DATASET * ds_info);
void  BuildSequentialReadDatasetCmd(VAL_DEVICE * dev,VALMET_BASIC_MSG * BasicMsg, VAL_DATASET * ds_info);
void  AddEntryToSequentialDefineCmd(VALMET_BASIC_MSG * BasicMsg, CT_SET CurrentSet);
int   DeviceReturnedACK(VAL_DEVICE * dev, int *ack_found);
int   ReadBufferMessageUntilETXBCC(VAL_DEVICE * dev, VALMET_MSG * Msg);
int   AnalyzeBufferMessage(VALMET_MSG * Msg, VALMET_BASIC_MSG * BasicMsg, UBYTE * ExtractedBcc);
void  StartTimeoutCounting(int Timeout);
BOOL  HaveTimeout(void);


/*
 * global variables
 */
extern TASK_ID      Task;
//extern TASK_ID      *Task_ptr;
extern MCISYSTEM    Mcisys;
extern VAL_DECODER *Decoders;
extern uint         No_decoders;

extern VAL_DEVICE   **Devices;
extern uint         No_devices;

#ifndef HPUX
#pragma pack()
#else
#pragma HP_ALIGN POP
#endif

#endif /* _VAL_PD_DEFS_INCLUDED */