1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // @file commengine.h |
|
15 // This contains CCommEngine which manage access to serial port. |
|
16 // |
|
17 |
|
18 #ifndef __CCOMMENGINE_H__ |
|
19 #define __CCOMMENGINE_H__ |
|
20 |
|
21 // system include |
|
22 #include <c32comm.h> |
|
23 #include <callbacktimer.h> |
|
24 |
|
25 // use include |
|
26 #include "mcommobserver.h" |
|
27 #include "globalphonemanager.h" |
|
28 |
|
29 // const defination |
|
30 const TInt KCommRxBufSize = 200; |
|
31 |
|
32 //Class forward |
|
33 class CCommWriter; |
|
34 class CCommReader; |
|
35 class CStringParser; |
|
36 |
|
37 /** |
|
38 * The class provide the functionalities to access the serials port, write and read to or from |
|
39 * serial port. It also provide the function to find one line of string and notify its observer. |
|
40 * |
|
41 */ |
|
42 class CCommEngine : public CBase, |
|
43 public MTimerObserver |
|
44 |
|
45 { |
|
46 friend class CCommWriter; |
|
47 friend class CCommReader; |
|
48 public: |
|
49 /** |
|
50 * Factory function |
|
51 * |
|
52 * @param aBufferSize |
|
53 * @param aReadPriority |
|
54 * @param aWritePriority |
|
55 * @param aPortAccess |
|
56 */ |
|
57 static CCommEngine* NewL(TInt aBufferSize, |
|
58 TInt aReadPriority, |
|
59 TInt aWritePriority, |
|
60 TPortAccess& aPortAccess); |
|
61 |
|
62 /** |
|
63 * Factory function |
|
64 * |
|
65 * @param aBufferSize |
|
66 * @param aReadPriority |
|
67 * @param aWritePriority |
|
68 * @param aPortAccess |
|
69 */ |
|
70 static CCommEngine* NewLC(TInt aBufferSize, |
|
71 TInt aReadPriority, |
|
72 TInt aWritePriority, |
|
73 TPortAccess& aPortAccess); |
|
74 |
|
75 /** |
|
76 * Destructor |
|
77 * |
|
78 */ |
|
79 virtual ~CCommEngine(); |
|
80 |
|
81 public: |
|
82 /** |
|
83 * Configure the serial port |
|
84 * |
|
85 */ |
|
86 TInt ConfigurePort(TCommConfig aConfiguration); |
|
87 |
|
88 /** |
|
89 * Open the serial port |
|
90 * |
|
91 * @param aDll |
|
92 * @param aName |
|
93 * @param aAccess |
|
94 */ |
|
95 TInt CommOpen(const TDesC& aDll, const TDesC& aName, TCommAccess aAccess); |
|
96 |
|
97 /** |
|
98 * Close the serial port |
|
99 * |
|
100 */ |
|
101 void CommClose(); |
|
102 |
|
103 /** |
|
104 * Cancel comm serail IO opeation |
|
105 * |
|
106 */ |
|
107 void CommCancel(); |
|
108 |
|
109 /** |
|
110 * Start serail IO writing |
|
111 * |
|
112 */ |
|
113 void CommWrite(const TDesC8& aDes); |
|
114 |
|
115 /** |
|
116 * Serial port writing is ready |
|
117 * |
|
118 */ |
|
119 void CommWriteReady(); |
|
120 |
|
121 /** |
|
122 * Cancel serial writing |
|
123 * |
|
124 */ |
|
125 void CommWriteCancel(); |
|
126 |
|
127 /** |
|
128 * Start serail IO reading |
|
129 * |
|
130 */ |
|
131 void CommRead(); |
|
132 |
|
133 /** |
|
134 * Start to read |
|
135 * |
|
136 */ |
|
137 void Read(); |
|
138 |
|
139 /** |
|
140 * The read will return whatever the data have been received |
|
141 * |
|
142 */ |
|
143 void CommReadOneOrMore(); |
|
144 |
|
145 /** |
|
146 * Cancel reading |
|
147 */ |
|
148 void CommReadCancel(); |
|
149 |
|
150 /** |
|
151 * Disconnect it from modem |
|
152 */ |
|
153 void Disconnect(); |
|
154 |
|
155 /** |
|
156 * Drop the DTR |
|
157 */ |
|
158 void DropDtr(); |
|
159 |
|
160 /** |
|
161 * Raise the DTR-- Data Terminal Ready |
|
162 */ |
|
163 void RaiseDTR(); |
|
164 |
|
165 /** |
|
166 * Drop the RTS signal-- Request to send |
|
167 */ |
|
168 void DropRTS(); |
|
169 |
|
170 /** |
|
171 * Raise the RTS signal |
|
172 */ |
|
173 void RaiseRTS(); |
|
174 |
|
175 /** |
|
176 * Clean all the buffers |
|
177 */ |
|
178 void ResetBuffers(); |
|
179 |
|
180 /** |
|
181 * Get the singnals |
|
182 */ |
|
183 TUint Signals(); |
|
184 |
|
185 /** |
|
186 * Start the timer |
|
187 */ |
|
188 void StartTimer(TInt aSecond); |
|
189 |
|
190 /** |
|
191 * Stop the timer |
|
192 */ |
|
193 void StopTimer(); |
|
194 |
|
195 /** |
|
196 * Reset all the buffers |
|
197 */ |
|
198 void ResetReadAndWriteBuffers(); |
|
199 |
|
200 /** |
|
201 * Get the port shutdown timeout |
|
202 */ |
|
203 TInt GetPortShutdownTimeout(); |
|
204 |
|
205 /** |
|
206 * Set the port shut down timeout |
|
207 */ |
|
208 TInt SetPortShutdownTimeout(TInt aTimeout); |
|
209 |
|
210 /** |
|
211 * Get the string parser |
|
212 */ |
|
213 CStringParser* GetStringParse() const; |
|
214 public: |
|
215 /** |
|
216 * Set the notifier for get the notificaiton when one line of string was found |
|
217 */ |
|
218 void SetCommReadLineNotify(MCommReadLineNotifier *aReadLineNotify); |
|
219 |
|
220 /** |
|
221 * Set the comm engine observer |
|
222 */ |
|
223 void SetCommEngineObserver(MCommEngineObserver *aEngineObserver); |
|
224 public: |
|
225 /** |
|
226 * Handle read complete event |
|
227 */ |
|
228 virtual void CommReadComplete(TInt aStatus); |
|
229 |
|
230 /** |
|
231 * Handle write complete event |
|
232 */ |
|
233 virtual void CommWriteComplete(TInt aStatus); |
|
234 protected: |
|
235 /** |
|
236 * Constructor |
|
237 */ |
|
238 CCommEngine(TPortAccess& aPortAccess); |
|
239 |
|
240 /** |
|
241 * 2nd constructor |
|
242 */ |
|
243 void ConstructL(TInt aBufferSize, TInt aReadPriority, TInt aWritePriority); |
|
244 private: |
|
245 /** |
|
246 * From MTimerObserver |
|
247 */ |
|
248 virtual void TimerRun(TInt aError); |
|
249 |
|
250 /** |
|
251 * Get the size of received buffer |
|
252 */ |
|
253 TInt GetSizeOfRxBuffer(); |
|
254 private: |
|
255 /** |
|
256 * The comm server reference |
|
257 */ |
|
258 RCommServ iCommServer; |
|
259 |
|
260 /** |
|
261 * The comm port object |
|
262 */ |
|
263 RComm iCommPort; |
|
264 |
|
265 /** |
|
266 * The active object for reading data from Baseband |
|
267 */ |
|
268 CCommReader *iCommReader; |
|
269 |
|
270 /** |
|
271 * The active object for writing AT command |
|
272 */ |
|
273 CCommWriter *iCommWriter; |
|
274 |
|
275 /** |
|
276 * The string parser |
|
277 */ |
|
278 CStringParser *iStringParse; |
|
279 |
|
280 /** |
|
281 * The engine observer |
|
282 */ |
|
283 MCommEngineObserver *iEngineObserver; |
|
284 |
|
285 /** |
|
286 * The received data |
|
287 */ |
|
288 TBuf8<KCommRxBufSize> iRxBuf; |
|
289 |
|
290 /** |
|
291 * The port specification |
|
292 */ |
|
293 TPortAccess& iPortAccess; |
|
294 |
|
295 /** |
|
296 * The timer active object. Used to record the time after a writing request is triggered. |
|
297 */ |
|
298 CCallbackTimer* iCallbackTimer; |
|
299 |
|
300 /** |
|
301 * Check if the comm has been canceled. |
|
302 */ |
|
303 TBool iCommCancel; |
|
304 }; |
|
305 #endif |
|