|
1 // Copyright (c) 1997-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 // |
|
15 |
|
16 #ifndef DUMMY_H__ |
|
17 #define DUMMY_H__ |
|
18 |
|
19 /** @file |
|
20 * |
|
21 * Dummy CSY for testing. |
|
22 */ |
|
23 |
|
24 #include <cs_port.h> |
|
25 #include <comms-infras/commsdebugutility.h> |
|
26 |
|
27 const TInt KDummyCompleteDelayFast = 600000L; |
|
28 const TInt KDummyCompleteDelaySlow = 1200000L; |
|
29 |
|
30 const TInt KDummy12ReadWait=28000000; |
|
31 |
|
32 class CDummyPort; |
|
33 class CDummyCompleter; |
|
34 |
|
35 _LIT8(KC32LoggingName,"C32SerComms"); |
|
36 |
|
37 /* |
|
38 * Macros are defined in respective mmp files for different csys |
|
39 */ |
|
40 |
|
41 #if defined(DUMMYCSY1) |
|
42 #define SERIAL_DESCRIPTION _L("DummyCsy1 3 wire raw") //< CSY description |
|
43 #define SERIAL_NAME _S("DummyCsy1") //< name of prefix for each com port |
|
44 _LIT8(KCSYLoggingName,"DummyCsy1"); |
|
45 #elif defined(DUMMYCSY2) |
|
46 #define SERIAL_DESCRIPTION _L("DummyCsy2 3 wire raw") |
|
47 #define SERIAL_NAME _S("DummyCsy2") |
|
48 _LIT8(KCSYLoggingName,"DummyCsy2"); |
|
49 #elif defined(DUMMYCSY3) |
|
50 #define SERIAL_DESCRIPTION _L("DummyCsy3 3 wire raw") |
|
51 #define SERIAL_NAME _S("DummyCsy3") |
|
52 _LIT8(KCSYLoggingName,"DummyCsy3"); |
|
53 #elif defined(DUMMYCSY4) |
|
54 #define SERIAL_DESCRIPTION _L("DummyCsy4 3 wire raw") |
|
55 #define SERIAL_NAME _S("DummyCsy4") |
|
56 _LIT8(KCSYLoggingName,"DummyCsy4"); |
|
57 #elif defined(DUMMYCSY5) |
|
58 #define SERIAL_DESCRIPTION _L("DummyCsy5 3 wire raw") |
|
59 #define SERIAL_NAME _S("DummyCsy5") |
|
60 _LIT8(KCSYLoggingName,"DummyCsy5"); |
|
61 #elif defined(DUMMYCSY6) |
|
62 #define SERIAL_DESCRIPTION _L("DummyCsy6 3 wire raw") |
|
63 #define SERIAL_NAME _S("DummyCsy6") |
|
64 _LIT8(KCSYLoggingName,"DummyCsy6"); |
|
65 #elif defined(DUMMYCSY7) |
|
66 #define SERIAL_DESCRIPTION _L("DummyCsy7 3 wire raw") |
|
67 #define SERIAL_NAME _S("DummyCsy7") |
|
68 _LIT8(KCSYLoggingName,"DummyCsy7"); |
|
69 #elif defined(DUMMYCSY8) |
|
70 #define SERIAL_DESCRIPTION _L("DummyCsy8 3 wire raw") |
|
71 #define SERIAL_NAME _S("DummyCsy8") |
|
72 _LIT8(KCSYLoggingName,"DummyCsy8"); |
|
73 #elif defined(DUMMYCSY9) |
|
74 #define SERIAL_DESCRIPTION _L("DummyCsy9 3 wire raw") |
|
75 #define SERIAL_NAME _S("DummyCsy9") |
|
76 _LIT8(KCSYLoggingName,"DummyCsy9"); |
|
77 #elif defined(DUMMYCSY10) |
|
78 #define SERIAL_DESCRIPTION _L("DummyCsy10 3 wire raw") |
|
79 #define SERIAL_NAME _S("DummyCsy10") |
|
80 _LIT8(KCSYLoggingName,"DummyCsy10"); |
|
81 #elif defined(DUMMYCSY12) |
|
82 #define SERIAL_DESCRIPTION _L("DummyCsy12 3 wire raw") |
|
83 #define SERIAL_NAME _S("DummyCsy12") |
|
84 _LIT8(KCSYLoggingName,"DummyCsy12"); |
|
85 /* |
|
86 KMaxBlockingTestWrites = 4; |
|
87 attempt to perform four read/write operation in loopback while waiting for blocking dummy12, |
|
88 4 being enough to simulate quite a bit of "work". |
|
89 |
|
90 KMicroSecWaitBetnLoopbackWrites = 1000000; |
|
91 1 sec is reasonable time to wait between loopback writes |
|
92 to ensure processing interference is miniscule |
|
93 |
|
94 KMaxExpectedLoopbackWriteTime = |
|
95 KMicroSecWaitBetnLoopbackWrites * KMaxBlockingTestWrites; |
|
96 1000000 * 4 = 4000000 |
|
97 |
|
98 KDummy12ReadWaitContingency = 2 * KMicroSecWaitBetnLoopbackWrites; |
|
99 allow 2 extra wait times for loopback writes to complete before releasing dummy12 to compensate for any processing time |
|
100 2 * 1000000 = 2000000 |
|
101 |
|
102 //KDummy12ReadWait = KMaxExpectedLoopbackWriteTime + KDummy12ReadWaitContingency; |
|
103 // dummy12 waits about 6 seconds |
|
104 // 4000000 + 2000000 = 6000000 |
|
105 const TInt KDummyCompleteDelayFast = 600000L; |
|
106 const TInt KDummyCompleteDelaySlow = 1200000L; |
|
107 |
|
108 KDummy12ReadWait=(KDummyCompleteDelayFast * KMaxBlockingTestWrites) |
|
109 + (KDummy12ReadWaitContingency * 2); |
|
110 |
|
111 600000 * 4 + (200000 * 2) = 2800000 |
|
112 */ |
|
113 |
|
114 #elif defined(DUMMYCSY15) |
|
115 #define SERIAL_DESCRIPTION _L("DummyCsy15 3 wire raw") |
|
116 #define SERIAL_NAME _S("DummyCsy15") |
|
117 _LIT8(KCSYLoggingName,"DummyCsy15"); |
|
118 #elif defined(DUMMYCSY16) |
|
119 #define SERIAL_DESCRIPTION _L("DummyCsy16 3 wire raw") |
|
120 #define SERIAL_NAME_SMALL _S("DummyCsy16") |
|
121 #define SERIAL_NAME _S("DummyCsy16LongPortNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee") |
|
122 _LIT8(KCSYLoggingName,"DummyCsy16"); |
|
123 #elif defined(DUMMYCSY17) |
|
124 #define SERIAL_DESCRIPTION _L("DummyCsy17 3 wire raw") |
|
125 #define SERIAL_NAME _S("DummyCsy17") |
|
126 _LIT8(KCSYLoggingName,"DummyCsy17"); |
|
127 #else |
|
128 #define SERIAL_DESCRIPTION _L("Dummy 3 wire raw") // default c32 dummy csy |
|
129 #define SERIAL_NAME _S("Dummy") |
|
130 _LIT8(KCSYLoggingName,"Dummy"); |
|
131 #endif |
|
132 |
|
133 _LIT8(testbufRead, "0123456789abcdefghijklmnopqrstuvxyxABCDEFGHIJKLMNOPQRSTUVXYZ[]\r\n"); |
|
134 _LIT8(testbufWrite, "This string has to be exactly like this othervice write returns KErrCommsLineFail."); |
|
135 |
|
136 const TInt PORT_0_NOCAPS = 0; |
|
137 const TInt PORT_1_NETWORKSERVICES = 1; |
|
138 const TInt PORT_2_NOTSUPPORT = 2; |
|
139 const TInt PORT_3_ALLCAPS = 3; |
|
140 const TInt PORT_6_NOCAPS = 6; |
|
141 |
|
142 /** |
|
143 unique numbers used for message passing between |
|
144 client and C32 comms server. |
|
145 @internalAll |
|
146 */ |
|
147 enum TCommMess |
|
148 { |
|
149 ECommLoadCommModule, //< 0 Load a CSY comms module |
|
150 ECommCloseCommModule, //< 1 Unload a CSY comms module |
|
151 ECommPortInfo, |
|
152 ECommPortInfoByName, //< 3 Get information on serial ports by name |
|
153 ECommPortInfoByNumber, //< 4 Get information on serial ports by number |
|
154 ECommNumPorts, //< 5 Get how many CSY's are loaded |
|
155 ECommStartServerThread, //< 6 Start another thread in the C32 process |
|
156 ECommOpen, //< 7 Open a comm port |
|
157 ECommRead, //< 8 Read from the comm port |
|
158 ECommReadCancel, //< 9 Cancel an outstanding read |
|
159 ECommQueryReceiveBuffer, //< 10 Get number of bytes in received buffer |
|
160 |
|
161 ECommResetBuffers, //< 11 Reset the serial port buffers |
|
162 ECommWrite, //< 12 Write to the comm port |
|
163 ECommWriteCancel, //< 13 Cancel an outstanding write |
|
164 ECommBreak, //< 14 Send a break |
|
165 ECommBreakCancel, //< 15 Cancel sending of break |
|
166 ECommCancel, //< 16 Cancel any outstanding reads or writes |
|
167 ECommConfig, //< 17 Get comm port configuration |
|
168 ECommSetConfig, //< 18 Set comm port configuration |
|
169 ECommCaps, //< 19 Get the capabilities of the comm port |
|
170 ECommSetMode, //< 20 Set server buffering mode |
|
171 |
|
172 ECommGetMode, //< 21 Get server buffering mode |
|
173 ECommSignals, //< 22 Read serial port control lines |
|
174 ECommSetSignalsToMark, //< 23 Set control lines high (1) |
|
175 ECommSetSignalsToSpace, //< 24 Set control line low (0) |
|
176 ECommReceiveBufferLength, //< 25 Get the size of the receive buffer |
|
177 ECommSetReceiveBufferLength, //< 26 Set the size of the receive buffer |
|
178 ECommClose, //< 27 Close the comm port |
|
179 ECommDbgMarkHeap, //< 28 Set a heap mark in the Comms server |
|
180 ECommDbgCheckHeap, //< 29 Check the heap mark in the Comms server |
|
181 ECommDbgMarkEnd, //< 30 Set the heap mark end in the Comms server |
|
182 |
|
183 ECommDbgFailNext, //< 31 Emulate fail next heap allocation in the comm server |
|
184 ECommDbgSetDebugPrintMask, //< 32 Set the debug print mask |
|
185 ECommDbgDoDumpDebugInfo, //< 33 Dump debug info |
|
186 |
|
187 // Here starts version 02 extensions |
|
188 ECommGetRole, //< 34 Get the current role |
|
189 ECommNotifySignals, //< 35 Notify when signals change |
|
190 ECommNotifySignalsCancel, //< 36 Cancel an outstanding signals notify |
|
191 ECommNotifyFlowControl, //< 37 Notify when flow control changes |
|
192 ECommNotifyFlowControlCancel, //< 38 Cancel an outstanding flow control notify |
|
193 ECommGetFlowControl, //< 39 Get the current status of flow control |
|
194 ECommNotifyConfigChange, //< 40 Notify when config change |
|
195 |
|
196 ECommNotifyConfigChangeCancel, //< 41 Cancel an outstanding config notify |
|
197 ECommNotifyBreak, //< 42 Send break |
|
198 ECommNotifyBreakCancel, //< 43 Cancel an outstanding sending of break |
|
199 ECommNotifyDataAvailable, //< 44 Notify when data available in Rx buffer |
|
200 ECommNotifyDataAvailableCancel, //< 45 Cancel an outstanding notify data available |
|
201 ECommNotifyOutputEmpty, //< 46 Notify when Tx buffer is empty |
|
202 ECommNotifyOutputEmptyCancel, //< 47 Cancel an outstanding output empty notify |
|
203 // Here ends version 02 extensions |
|
204 |
|
205 ECommSetAccess, //< 48 Set the access mode defined by TCommAccess |
|
206 ECommDebugState, //< 49 Get the debug state |
|
207 ECommOpenWhenAvailable //< 50 Open port when it is available |
|
208 }; |
|
209 |
|
210 |
|
211 /** |
|
212 * a dummy class for completing asynchronour requests |
|
213 */ |
|
214 class CDummyCompleter : public CActive |
|
215 { |
|
216 public: |
|
217 // construction |
|
218 CDummyCompleter(CDummyPort& aPort); |
|
219 |
|
220 // destruction |
|
221 ~CDummyCompleter(); |
|
222 |
|
223 // Completes async call |
|
224 void Complete(TCommMess aMess, TTimeIntervalMicroSeconds32 anInterval, TInt aReason, TUint aValue = 0); |
|
225 void Complete(TCommMess aMess, TTimeIntervalMicroSeconds32 anInterval, TInt aReason, const TDesC8& aDescriptor); |
|
226 void CancelComplete(); |
|
227 |
|
228 private: |
|
229 void DoCancel(); /* stop object activity */ |
|
230 void RunL(); /* active object callback */ |
|
231 |
|
232 private: |
|
233 TCommMess iMess; |
|
234 RTimer iTimer; |
|
235 CDummyPort& iPort; |
|
236 TInt iReason; |
|
237 TUint iValue; |
|
238 TCommNotificationV01 iPeerConfig; |
|
239 |
|
240 }; |
|
241 |
|
242 |
|
243 /** |
|
244 * "Entry point object" makes the objects which do the work |
|
245 */ |
|
246 class CDummyPortFactory : public CSerial |
|
247 { |
|
248 enum {KMajorVersion=1,KMinorVersion=0,KBuild=92}; |
|
249 public: |
|
250 static CDummyPortFactory* NewL(); |
|
251 virtual CPort * NewPortL(const TUint aUnit); |
|
252 virtual void Info(TSerialInfo &aSerialInfo); |
|
253 #ifdef DUMMYCSY10 |
|
254 void LoadAnotherCSY(); |
|
255 #endif |
|
256 #ifdef DUMMYCSY17 |
|
257 void LoadAnotherCSYNoClose(); |
|
258 #endif |
|
259 |
|
260 public: //CSerial |
|
261 TSecurityPolicy PortPlatSecCapability(TUint aPort) const; |
|
262 private: |
|
263 void ConstructL(); |
|
264 CDummyPortFactory(); |
|
265 }; |
|
266 |
|
267 |
|
268 /** |
|
269 * CPort is the object which interfaces to the commserver |
|
270 */ |
|
271 class CDummyPort : public CPort |
|
272 { |
|
273 public: |
|
274 static CDummyPort * NewL(TUint aUint); |
|
275 public: |
|
276 virtual void StartRead(const TAny *aClientBuffer,TInt aLength); |
|
277 virtual void ReadCancel(); |
|
278 virtual TInt QueryReceiveBuffer(TInt& aLength) const; |
|
279 virtual void ResetBuffers(TUint aFlags); |
|
280 virtual void StartWrite(const TAny *aClientBuffer,TInt aLength); |
|
281 virtual void WriteCancel(); |
|
282 virtual void Break(TInt aTime); |
|
283 virtual void BreakCancel(); |
|
284 virtual TInt GetConfig(TDes8& aPackage) const; |
|
285 virtual TInt SetConfig(const TDesC8& aPackage); |
|
286 virtual TInt SetServerConfig(const TDesC8& aPackage); |
|
287 virtual TInt GetServerConfig(TDes8& aPackage); |
|
288 virtual TInt GetCaps(TDes8& aPackage); |
|
289 virtual TInt GetSignals(TUint& aSignals); |
|
290 virtual TInt SetSignalsToMark(TUint aSignals); |
|
291 virtual TInt SetSignalsToSpace(TUint aSignals); |
|
292 virtual TInt GetReceiveBufferLength(TInt& aLength) const; |
|
293 virtual TInt SetReceiveBufferLength(TInt aLength); |
|
294 virtual ~CDummyPort(); |
|
295 |
|
296 // Version 02 additions to IrCOMM starts from here |
|
297 virtual void NotifySignalChange(TUint aSignalMask); |
|
298 virtual void NotifySignalChangeCancel(); |
|
299 virtual void NotifyConfigChange(); |
|
300 virtual void NotifyConfigChangeCancel(); |
|
301 virtual void NotifyFlowControlChange(); |
|
302 virtual void NotifyFlowControlChangeCancel(); |
|
303 virtual void NotifyBreak(); |
|
304 virtual void NotifyBreakCancel(); |
|
305 virtual void NotifyDataAvailable(); |
|
306 virtual void NotifyDataAvailableCancel(); |
|
307 virtual void NotifyOutputEmpty(); |
|
308 virtual void NotifyOutputEmptyCancel(); |
|
309 virtual TInt GetFlowControlStatus(TFlowControl& aFlowControl); |
|
310 virtual TInt GetRole(TCommRole& aRole); |
|
311 virtual TInt SetRole(TCommRole aRole); |
|
312 // Version 02 additions to IrCOMM ends to here |
|
313 |
|
314 void Destruct(); |
|
315 |
|
316 private: |
|
317 CDummyPort(); |
|
318 void ConstructL(TUint aUint); |
|
319 |
|
320 private: |
|
321 |
|
322 TUint iBufFlags; //< buffer flags |
|
323 TInt iBufSize; //< buffer size |
|
324 |
|
325 TInt iBreakDelay; //< time of break delay |
|
326 |
|
327 TUint8* iDataIn; //< pointer to data in buffer |
|
328 TPtr8 iPtrDataIn; //< descriptor pointer to data in buffer |
|
329 |
|
330 TUint8* iDataOut; //< pointer to data out buffer |
|
331 TPtr8 iPtrDataOut; //< descriptor pointer to data out buffer |
|
332 |
|
333 TUint8* iCompData; //< pointer to compare data |
|
334 TPtr8 iPtrCompData; //< descriptor pointer to compare data |
|
335 |
|
336 TAny* iClientPtr; //< pointer to client buffer |
|
337 TInt iClientLength; //< length of client buffer |
|
338 TInt iLength; //< length count of client buffer |
|
339 TUint iSignals; //< RS232 signals |
|
340 TCommConfigV01 iConfig; //< port configuration |
|
341 TDeltaTimerEntry iBreakTimer; //< break timer entry |
|
342 TCommRole iRole; //< current role, DTE or DCE |
|
343 TUint iNotifySignalMask; //< signals notification mask |
|
344 TFlowControl iFlowControl; //< flow control settings |
|
345 TPckg<TCommCapsV02> *iCapsPtr; //< pointer to capabilities package |
|
346 TCommNotificationV01 iPeerConfig; //< peer configuration |
|
347 CDummyCompleter *iCompleteSigPtr; //< pointer to signal completer |
|
348 CDummyCompleter *iCompleteFlowPtr; //< pointer to flow control completer |
|
349 CDummyCompleter *iCompleteConfPtr; //< pointer to configuration completer |
|
350 CDummyCompleter *iCompleteCapsPtr; //< pointer to capabilities completer |
|
351 CDummyCompleter *iCompleteReadPtr; //< pointer to data read completer |
|
352 CDummyCompleter *iCompleteWritePtr; //< pointer to data write completer |
|
353 CDummyCompleter *iCompleteSetBreakPtr; //< pointer to set break completer |
|
354 CDummyCompleter *iCompleteBreakPtr; //< pointer to break completer |
|
355 CDummyCompleter *iCompleteDataAvailablePtr; //< pointer to data available completer |
|
356 CDummyCompleter *iCompleteOutputEmptyPtr; //< pointer to output empty completer |
|
357 CDummyCompleter *iCompleteClosePtr; //< pointer to close completer |
|
358 |
|
359 TTimeIntervalMicroSeconds32 iDummyCompleteDelayFast; //< fast complete delay |
|
360 TTimeIntervalMicroSeconds32 iDummyCompleteDelaySlow; //< slow complete delay |
|
361 }; |
|
362 |
|
363 /** |
|
364 * faults in the CSY |
|
365 */ |
|
366 enum TCSYFaults |
|
367 { |
|
368 E_ParametersCorrupted, //< wrong parameter |
|
369 E_UnknownAsynchronousCall //< not used |
|
370 }; |
|
371 |
|
372 |
|
373 #endif // DUMMY_H__ |
|
374 |