kodi
NptSerialPort.h
1 /*****************************************************************
2 |
3 | Neptune - Serial Ports
4 |
5 | Copyright (c) 2002-2008, Axiomatic Systems, LLC.
6 | All rights reserved.
7 |
8 | Redistribution and use in source and binary forms, with or without
9 | modification, are permitted provided that the following conditions are met:
10 | * Redistributions of source code must retain the above copyright
11 | notice, this list of conditions and the following disclaimer.
12 | * Redistributions in binary form must reproduce the above copyright
13 | notice, this list of conditions and the following disclaimer in the
14 | documentation and/or other materials provided with the distribution.
15 | * Neither the name of Axiomatic Systems nor the
16 | names of its contributors may be used to endorse or promote products
17 | derived from this software without specific prior written permission.
18 |
19 | THIS SOFTWARE IS PROVIDED BY AXIOMATIC SYSTEMS ''AS IS'' AND ANY
20 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL AXIOMATIC SYSTEMS BE LIABLE FOR ANY
23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
30  ****************************************************************/
31 
32 #ifndef _NPT_SERIAL_PORT_H_
33 #define _NPT_SERIAL_PORT_H_
34 
35 /*----------------------------------------------------------------------
36 | includes
37 +---------------------------------------------------------------------*/
38 #include "NptTypes.h"
39 #include "NptStreams.h"
40 
41 /*----------------------------------------------------------------------
42 | constants
43 +---------------------------------------------------------------------*/
44 const int NPT_ERROR_NO_SUCH_SERIAL_PORT = NPT_ERROR_BASE_SERIAL_PORT - 0;
45 const int NPT_ERROR_SERIAL_PORT_NOT_OPEN = NPT_ERROR_BASE_SERIAL_PORT - 1;
46 const int NPT_ERROR_SERIAL_PORT_ALREADY_OPEN = NPT_ERROR_BASE_SERIAL_PORT - 2;
47 const int NPT_ERROR_SERIAL_PORT_BUSY = NPT_ERROR_BASE_SERIAL_PORT - 3;
48 
49 typedef enum {
50  NPT_SERIAL_PORT_PARITY_NONE,
51  NPT_SERIAL_PORT_PARITY_EVEN,
52  NPT_SERIAL_PORT_PARITY_ODD,
53  NPT_SERIAL_PORT_PARITY_MARK
54 } NPT_SerialPortParity;
55 
56 typedef enum {
57  NPT_SERIAL_PORT_STOP_BITS_1,
58  NPT_SERIAL_PORT_STOP_BITS_1_5,
59  NPT_SERIAL_PORT_STOP_BITS_2
60 } NPT_SerialPortStopBits;
61 
62 typedef enum {
63  NPT_SERIAL_PORT_FLOW_CONTROL_NONE,
64  NPT_SERIAL_PORT_FLOW_CONTROL_HARDWARE,
65  NPT_SERIAL_PORT_FLOW_CONTROL_XON_XOFF
66 } NPT_SerialPortFlowControl;
67 
68 /*----------------------------------------------------------------------
69 | NPT_SerialPortInterface
70 +---------------------------------------------------------------------*/
72 {
73 public:
74  // constructors and destructor
75  virtual ~NPT_SerialPortInterface() {}
76 
77  // methods
78  virtual NPT_Result Open(unsigned int speed,
79  NPT_SerialPortStopBits stop_bits,
80  NPT_SerialPortFlowControl flow_control,
81  NPT_SerialPortParity parity) = 0;
82  virtual NPT_Result Close() = 0;
83  virtual NPT_Result GetInputStream(NPT_InputStreamReference& stream) = 0;
84  virtual NPT_Result GetOutputStream(NPT_OutputStreamReference& stream) = 0;
85 };
86 
87 /*----------------------------------------------------------------------
88 | NPT_SerialPort
89 +---------------------------------------------------------------------*/
91 {
92 public:
93  // constructors and destructor
94  NPT_SerialPort(const char* name);
95  ~NPT_SerialPort() override { delete m_Delegate; }
96 
97  // NPT_SerialPortInterface methods
98  NPT_Result Open(unsigned int speed,
99  NPT_SerialPortStopBits stop_bits = NPT_SERIAL_PORT_STOP_BITS_1,
100  NPT_SerialPortFlowControl flow_control = NPT_SERIAL_PORT_FLOW_CONTROL_NONE,
101  NPT_SerialPortParity parity = NPT_SERIAL_PORT_PARITY_NONE) override {
102  return m_Delegate->Open(speed, stop_bits, flow_control, parity);
103  }
104  NPT_Result Close() override {
105  return m_Delegate->Close();
106  }
107  NPT_Result GetInputStream(NPT_InputStreamReference& stream) override {
108  return m_Delegate->GetInputStream(stream);
109  }
110  NPT_Result GetOutputStream(NPT_OutputStreamReference& stream) override {
111  return m_Delegate->GetOutputStream(stream);
112  }
113 
114 protected:
115  // members
116  NPT_SerialPortInterface* m_Delegate;
117 };
118 
119 #endif // _NPT_SERIAL_PORT_H_
Definition: NptSerialPort.h:71
Definition: NptSerialPort.h:90