Source code for /engineering/SERIAL-TEST/SERIAL.HOriginal file SERIAL.H
   1 // --------------------------------------------------------------------------
   2 // --
   3 // -- Serial - Interfacing header.
   4 // --
   5 // --
   6 // --------------------------------------------------------------------------
   7 
   8 // --------------------------------------------------------------------------
   9 // -- Defines
  10 // --------------------------------------------------------------------------
  11 
  12 // ------------------------------------
  13 // -- Enumerate the port data
  14 enum  SS_PORT_T { SS_PORT_1  = 0, SS_PORT_2 = 1 };
  15 enum  SS_BPS_T  { SS_BPS_300 = 0, SS_BPS_2400, SS_BPS_9600,
  16 				  SS_BPS_19200, SS_BPS_38400            };
  17 #define SS_BPS_MIN	    SS_BPS_300
  18 #define SS_BPS_MAX	    SS_BPS_38400
  19 #define SS_BPS_DEFAULT  SS_BPS_19200
  20 
  21 enum  SS_BITS_T   { SS_BITS_5      = 0, SS_BITS_7,     SS_BITS_8      };
  22 #define SS_BITS_MIN	    SS_BITS_5
  23 #define SS_BITS_MAX	    SS_BITS_8
  24 #define SS_BITS_DEFAULT SS_BITS_8
  25 
  26 enum  SS_SBITS_T  { SS_SBITS_1,         SS_SBITS_2     };
  27 #define SS_SBITS_MIN  	  SS_SBITS_1
  28 #define SS_SBITS_MAX  	  SS_SBITS_2
  29 #define SS_SBITS_DEFAULT  SS_SBITS_1
  30 
  31 enum  SS_PARITY_T { SS_PARITY_NONE = 0, SS_PARITY_ODD, SS_PARITY_EVEN };
  32 #define SS_PARITY_MIN  	   SS_PARITY_NONE
  33 #define SS_PARITY_MAX  	   SS_PARITY_EVEN
  34 #define SS_PARITY_DEFAULT  SS_PARITY_NONE
  35 
  36 enum  SS_ERROR_T  { SS_NO_ERROR = 0, SS_ERROR, SS_BAD_PORT };
  37 
  38 #define SS_NO_CHARACTER	-1
  39 
  40 #define SS_BUFFER_SIZE	256
  41 
  42 // --------------------------------------------------------------------------
  43 // -- Class definitions
  44 // --------------------------------------------------------------------------
  45 
  46 // -----------------------------------
  47 // -- Port parameters class
  48 class PortParameters {
  49 
  50    friend   Serial;
  51 
  52    SS_BPS_T		   bps;
  53    SS_BITS_T	   bits;
  54    SS_SBITS_T	   sBits;
  55    SS_PARITY_T	   parity;
  56 
  57  public:
  58 
  59    void bpsNext(   void);
  60    void bitsNext(  void);
  61    void sBitsNext( void);
  62    void parityNext(void);
  63 
  64    unsigned int  bpsIs(   void) { return bps;    };
  65    unsigned int  bitsIs(  void) { return bits;   };
  66    unsigned int  sBitsIs( void) { return sBits;  };
  67    unsigned int  parityIs(void) { return parity; };
  68 
  69    PortParameters(void);
  70 
  71 };
  72 
  73 
  74 // -----------------------------------
  75 // -- Basic serial class.  Each instance will run a port.
  76 class Serial
  77 {
  78 
  79    SS_PORT_T	thisPort;
  80    int  		portbase;
  81 
  82    Boolean  flowControl;
  83 
  84    FBuffer  txFIFO;		// FIFOs for this object
  85    FBuffer  rxFIFO;
  86 
  87    SS_ERROR_T setFraming( SS_PARITY_T parity, SS_BITS_T bits,
  88 						  SS_SBITS_T  stopBit                  );
  89    SS_ERROR_T setSpeed(SS_BPS_T    speed   );
  90    SS_ERROR_T setPort( SS_PORT_T   port    );
  91 
  92  public:
  93 
  94    Boolean  enabled;
  95    Boolean  up;
  96 
  97    Serial(SS_PORT_T port, PortParameters portP,
  98 		  Boolean  hwFlowControl);
  99 
 100    Serial &operator<<( char octet   );
 101    Serial &operator<<( char *string );
 102    Serial &operator>>( unsigned char  &octet  );
 103 
 104    SS_ERROR_T lineUp(  void);
 105    SS_ERROR_T lineDown(void);
 106 
 107    // Exceptions
 108    class XsOUT_OF_MEMORY { };
 109    class XsBAD_PARAM  { };
 110    class XsOVERRUN  { };
 111    
 112    ~Serial();
 113 
 114 };