Debian Codegraph @

protolib/include/protoSerial.h

raw
1 #ifndef _PROTO_SERIAL
2 #define _PROTO_SERIAL
3
4 /**
5 * @class ProtoSerial
6 * @brief This class is a generic base class for serial port I/O
7 */
8
9 #include "protoChannel.h"
10
11 class ProtoSerial : public ProtoChannel
12 {
13 public:
14 static ProtoSerial* Create();
15 virtual ~ProtoSerial();
16
17 // Serial port "satus" signal enumeration
18 // The pin assignment listed is for DB9 or DB25, respectively
19
20 enum StatusSignal
21 {
22 DTR = 0x001, // data terminal ready, pin 4/9 or 20/25 (output signal, typically DTR -> DSR)
23 RTS = 0x002, // request-to-send, pin 7/9 or 04/25 (output signal, typically RTS -> CTS)
24 CTS = 0x004, // clear-to-send, pin 8/9 or 05/25 (input signal)
25 DCD = 0x008, // data carrier detect, pin 1/9 or 08/25 (input signal)
26 DSR = 0x010, // data set ready, pin 6/9 or 06/25 (input signal)
27 RNG = 0x020 // ring indicator pin 9/9 or 22/25 (input signal)
28 };
29
30
31 // Device access mode
32 enum AccessMode
33 {
34 RDONLY, // read-only access
35 WRONLY, // write-only access
36 RDWR // read and write access
37 };
38
39 // These MUST be overridden for different implementations
40 // ProtoSerial::Open() should also be called at the _end_ of derived
41 // implementations' Open() method
42 virtual bool Open(const char* deviceName = NULL,
43 AccessMode accessMode = RDWR,
44 bool configure = false)
45 {
46 return ProtoChannel::Open();
47 }
48 virtual bool IsOpen() const
49 {return ProtoChannel::IsOpen();}
50 // ProtoSerial::Close() should also be called at the _beginning_ of
51 // derived implementation's Close() method
52 virtual void Close()
53 {ProtoChannel::Close();}
54
55 // Configuration set/get routines
56 bool SetBaudRate(unsigned int baudRate);
57 bool SetByteSize(unsigned int byteSize);
58 bool SetParity(bool useParity);
59 bool SetReadTimeout(double seconds);
60 bool SetLocalControl(bool status);
61 bool SetEcho(bool status);
62 bool SetLowLatency(bool status);
63
64 unsigned int GetBaudRate() const
65 {return baud_rate;}
66 unsigned int GetByteSize() const
67 {return byte_size;}
68 bool GetParity() const
69 {return use_parity;}
70 double GetReadTimeout() const
71 {return read_timeout;}
72 unsigned int GetLocalControl() const
73 {return local_control;}
74
75 // Status signal set/get methods
76 virtual bool Set(StatusSignal signal) = 0;
77 virtual bool Clear(StatusSignal signal) = 0;
78 virtual bool IsSet(StatusSignal signal) const = 0;
79
80 virtual bool SetStatus(int status) = 0;
81 virtual int GetStatus() const = 0;
82 static bool IsSet(int status, StatusSignal signal)
83 {return (0 != (status & signal));}
84
85 // Recv/Send data ...
86 virtual bool Read(char* buffer, unsigned int& numBytes) = 0;
87 virtual bool Write(const char* buffer, unsigned int& numBytes) = 0;
88
89 protected:
90 ProtoSerial();
91
92 virtual bool SetConfiguration() = 0;
93 virtual bool GetConfiguration() = 0;
94
95 // Serial port device configuration
96 unsigned int baud_rate; // baud rate (default = 9600)
97 unsigned int byte_size; // bits per byte (default = 8)
98 bool use_parity; // parity or no parity (default = no parity)
99 double read_timeout; // read timeout (sec, default = 10 seconds)
100 bool local_control; // ignore modem control lines if true (default = true)
101 bool echo_input;
102 bool low_latency;
103
104 }; // end class ProtoSerial
105
106 #endif // _PROTO_SERIAL