Debian Codegraph @

gobi-api/Gobi_2012-06-18-1054/Core/Comm.h

raw
1 /*===========================================================================
2 FILE:
3 Comm.h
4
5 DESCRIPTION:
6 Declaration of cComm class
7
8 PUBLIC CLASSES AND METHODS:
9 cComm
10 This class wraps low level port communications
11
12 Copyright (c) 2012, Code Aurora Forum. All rights reserved.
13
14 Redistribution and use in source and binary forms, with or without
15 modification, are permitted provided that the following conditions are met:
16 * Redistributions of source code must retain the above copyright
17 notice, this list of conditions and the following disclaimer.
18 * Redistributions in binary form must reproduce the above copyright
19 notice, this list of conditions and the following disclaimer in the
20 documentation and/or other materials provided with the distribution.
21 * Neither the name of Code Aurora Forum nor
22 the names of its contributors may be used to endorse or promote
23 products derived from this software without specific prior written
24 permission.
25
26
27 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 POSSIBILITY OF SUCH DAMAGE.
38 ===========================================================================*/
39
40 //---------------------------------------------------------------------------
41 // Include Files
42 //---------------------------------------------------------------------------
43 #include "Event.h"
44 #include "Connection.h"
45
46 //---------------------------------------------------------------------------
47 // Pragmas
48 //---------------------------------------------------------------------------
49 #pragma once
50
51 /*=========================================================================*/
52 // Class cComm
53 /*=========================================================================*/
54 class cComm : public cConnection
55 {
56 public:
57 // Constructor
58 cComm();
59
60 // Destructor
61 ~cComm();
62
63 // Is this object valid?
64 bool IsValid();
65
66 // Connect to the specified port
67 bool Connect( LPCSTR pPort );
68
69 // Run an IOCTL on the open file handle
70 int SendCtl(
71 UINT ioctlReq,
72 void * pData );
73
74 // Disconnect from the current port
75 bool Disconnect();
76
77 // Configure the port with the passed in parameters
78 bool ConfigureSettings( termios * pSettings );
79
80 // Return the current port settings
81 bool GetSettings( termios * pSettings );
82
83 // Cancel any in-progress I/O
84 bool CancelIO();
85
86 // Cancel any in-progress receive operation
87 bool CancelRx();
88
89 // Cancel any in-progress transmit operation
90 bool CancelTx();
91
92 // Receive data
93 bool RxData(
94 BYTE * pBuf,
95 ULONG bufSz,
96 cIOCallback * pCallback );
97
98 // Transmit data
99 bool TxData(
100 const BYTE * pBuf,
101 ULONG bufSz );
102
103 // (Inline) Return current port name
104 std::string GetPortName() const
105 {
106 return mPortName;
107 };
108
109 // Are we currently connected to a port?
110 bool IsConnected()
111 {
112 return (mPort != INVALID_HANDLE_VALUE);
113 };
114
115 protected:
116 /* Name of current port */
117 std::string mPortName;
118
119 /* Handle to COM port */
120 int mPort;
121
122 // Cancel the write request?
123 bool mbCancelWrite;
124
125 /* Buffer */
126 BYTE * mpBuffer;
127
128 /* Buffer size */
129 ULONG mBuffSz;
130
131 /* Pipe for comunication with thread */
132 int mCommandPipe[2];
133
134 /* Thread ID of Rx Thread. */
135 pthread_t mRxThreadID;
136
137 // Rx thread is allowed complete access
138 friend void * RxThread( void * pData );
139 };