|
1 /* |
|
2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32test.h> |
|
19 #include <e32twin.h> |
|
20 #include <c32comm.h> |
|
21 #include <d32comm.h> |
|
22 #include <usbman.h> |
|
23 |
|
24 TCommNotificationPckg TheSerialConfigBuf; |
|
25 TCommNotificationPckg TheUsbConfigBuf; |
|
26 |
|
27 TCommNotificationV01 &TheSerialConfig=TheSerialConfigBuf(); |
|
28 TCommNotificationV01 &TheUsbConfig=TheUsbConfigBuf(); |
|
29 TInt TheLastError=KErrNone; |
|
30 |
|
31 static const TInt KMaxBufSize = 4096; |
|
32 const TInt KMaxDumpLength=0x100; |
|
33 |
|
34 enum TTermPanic |
|
35 { |
|
36 EStraySignal, |
|
37 ELoadPhysicalDeviceErr, |
|
38 ELoadLogicalDeviceErr, |
|
39 EOpenErr, |
|
40 EConnectFsErr, |
|
41 ECaptureFileOpen, |
|
42 EOpenUploadFile, |
|
43 }; |
|
44 |
|
45 enum TRxMode |
|
46 { |
|
47 ENormal=0, |
|
48 ELoopBack=1, |
|
49 ECountChars=2, |
|
50 ERxOff=3, |
|
51 ECapture=128, |
|
52 }; |
|
53 |
|
54 NONSHARABLE_STRUCT(SSettings) |
|
55 { |
|
56 TBool iNotFinished; |
|
57 TBool iLocalEcho; |
|
58 TInt iAddLF; |
|
59 TBool iDump; |
|
60 TInt iDumpRepeat; |
|
61 TBuf8<KMaxDumpLength> iDumpData; |
|
62 TRxMode iRxMode; |
|
63 TInt iCharCount; |
|
64 TInt iMaxInOne; |
|
65 TInt iInfraRed; |
|
66 TBool iWaitAfterWrite; |
|
67 // Fifo |
|
68 // Brk |
|
69 }; |
|
70 |
|
71 LOCAL_D SSettings TheSettings; |
|
72 LOCAL_D RUsb TheUsbServer; |
|
73 LOCAL_D RCommServ TheCommServer; |
|
74 LOCAL_D RComm TheUsbPort; |
|
75 LOCAL_D RComm TheSerialPort; |
|
76 LOCAL_D RConsole TheWindow; |
|
77 |
|
78 |
|
79 #define USBCSY_NAME _L("ECACM") |
|
80 #define USBPORT_NAME _L("ACM::0") |
|
81 #define SERIALCSY_NAME _L("ECUART") |
|
82 #define SERIALPORT_NAME _L("COMM::0") // second comm port |
|
83 |
|
84 #define SERIALPDD_NAME _L("EUART1") |
|
85 #define SERIALLDD_NAME _L("ECOMM") |
|
86 #define USBLDD_NAME _L("EUSBC") |
|
87 |
|
88 class CDuplex; |
|
89 //Base class for simplex transfer activity |
|
90 class MTransferNotifier |
|
91 { |
|
92 public: |
|
93 virtual void NotifyRead(TInt aErr,TInt aSize, TDes8& aBuf)=0; |
|
94 virtual void NotifyWrite(TInt aErr)=0; |
|
95 }; |
|
96 |
|
97 class CSimplex: public CActive |
|
98 { |
|
99 public: |
|
100 void SetTotalAmount(TUint aTotalAmount){iTotalAmount = aTotalAmount;} |
|
101 virtual ~CSimplex(){Cancel();} |
|
102 protected: |
|
103 CSimplex(CDuplex& aDuplex): |
|
104 CActive(CActive::EPriorityStandard),iDuplex(aDuplex){} |
|
105 |
|
106 protected: |
|
107 TBuf8<KMaxBufSize> iBuffer; |
|
108 CDuplex& iDuplex; |
|
109 TInt iTotalAmount; |
|
110 }; |
|
111 |
|
112 class CSimplexRead: public CSimplex |
|
113 { |
|
114 public: |
|
115 static CSimplexRead* NewL(CDuplex& aDuplex); |
|
116 virtual ~CSimplexRead(){} |
|
117 void SetPort(RComm* aPort){iCommPort = aPort;} |
|
118 void StartL(); |
|
119 protected: |
|
120 CSimplexRead(CDuplex& aDuplex): |
|
121 CSimplex(aDuplex){} |
|
122 virtual void DoCancel(void); |
|
123 void ConstructL(); |
|
124 virtual void RunL(); |
|
125 private: |
|
126 TBuf8<KMaxBufSize> iBuffer; |
|
127 TBool iPortType; |
|
128 RComm* iCommPort; |
|
129 }; |
|
130 |
|
131 class CSimplexWrite: public CSimplex |
|
132 { |
|
133 public: |
|
134 static CSimplexWrite* NewL(CDuplex& aDuplex); |
|
135 virtual ~CSimplexWrite(){} |
|
136 void SetPort(RComm* aPort){iCommPort = aPort;} |
|
137 void StartL(TDes8& abuf); |
|
138 protected: |
|
139 CSimplexWrite(CDuplex& aDuplex): |
|
140 CSimplex(aDuplex){} |
|
141 virtual void DoCancel(void); |
|
142 void ConstructL(); |
|
143 virtual void RunL(); |
|
144 private: |
|
145 TBool iPortType; |
|
146 RComm* iCommPort; |
|
147 }; |
|
148 |
|
149 class CDuplex : public MTransferNotifier, CBase |
|
150 { |
|
151 public: |
|
152 // Construction |
|
153 static CDuplex* NewL(); |
|
154 // Destruction |
|
155 void StartL(); |
|
156 void Cancel(); |
|
157 void NotifyRead(TInt aErr,TInt aSize, TDes8& aBuf); |
|
158 void NotifyWrite(TInt aErr); |
|
159 void SetTxPort(RComm* aPort){iSimplexWrite->SetPort(aPort);} |
|
160 void SetRxPort(RComm* aPort){iSimplexRead->SetPort(aPort);} |
|
161 void SetTotalAmount(TInt aTotalAmount){iSimplexWrite->SetTotalAmount(aTotalAmount); |
|
162 iSimplexRead->SetTotalAmount(aTotalAmount);} |
|
163 virtual ~CDuplex(); |
|
164 protected: |
|
165 // Construction |
|
166 CDuplex(){}; |
|
167 void ConstructL(); |
|
168 private: |
|
169 CSimplexRead* iSimplexRead; |
|
170 CSimplexWrite* iSimplexWrite; |
|
171 }; |
|
172 |
|
173 class CConfigChangeNotifier: public CActive |
|
174 { |
|
175 public: |
|
176 static CConfigChangeNotifier* NewL(); |
|
177 ~CConfigChangeNotifier(){}; |
|
178 |
|
179 // Issue request |
|
180 void StartL(); |
|
181 private: |
|
182 CConfigChangeNotifier(); |
|
183 virtual void DoCancel(); |
|
184 virtual void RunL(); |
|
185 }; |
|
186 |
|
187 class CSignalChangeNotifier: public CActive |
|
188 { |
|
189 public: |
|
190 static CSignalChangeNotifier* NewL(TBool aIsusbPort); |
|
191 ~CSignalChangeNotifier(){}; |
|
192 |
|
193 // Issue request |
|
194 void StartL(); |
|
195 private: |
|
196 CSignalChangeNotifier(TBool aIsusbPort); |
|
197 virtual void DoCancel(); |
|
198 virtual void RunL(); |
|
199 const TBool iIsUsbPort; |
|
200 TUint iInSignals; |
|
201 }; |
|
202 |
|
203 class CFControlChangeNotifier: public CActive |
|
204 { |
|
205 public: |
|
206 static CFControlChangeNotifier* NewL(); |
|
207 ~CFControlChangeNotifier(){}; |
|
208 |
|
209 // Issue request |
|
210 void StartL(); |
|
211 private: |
|
212 CFControlChangeNotifier(); |
|
213 virtual void DoCancel(); |
|
214 virtual void RunL(); |
|
215 TFlowControl iFlowControl; |
|
216 }; |
|
217 |
|
218 |
|
219 class CActiveConsole : public CActive |
|
220 //----------------------------------- |
|
221 { |
|
222 public: |
|
223 // Construction |
|
224 static CActiveConsole* NewLC(); |
|
225 static CActiveConsole* NewL(); |
|
226 void ConstructL(); |
|
227 |
|
228 // Destruction |
|
229 ~CActiveConsole(); |
|
230 |
|
231 // Issue request |
|
232 void WaitForKeyPress(); |
|
233 |
|
234 private: |
|
235 // Construction |
|
236 CActiveConsole(); |
|
237 |
|
238 // Cancel request. |
|
239 // Defined as pure virtual by CActive; |
|
240 // implementation provided by this class. |
|
241 virtual void DoCancel(); |
|
242 |
|
243 // Service completed request. |
|
244 // Defined as pure virtual by CActive; |
|
245 // implementation provided by this class, |
|
246 virtual void RunL(); |
|
247 |
|
248 void Start(); |
|
249 void ProcessKeyPressL(); |
|
250 |
|
251 private: |
|
252 TBool iIsRunning; |
|
253 TConsoleKey iKeypress; |
|
254 TRequestStatus iBreakRequest; |
|
255 // Data members defined by this class |
|
256 CDuplex* iUsbToSerial; |
|
257 CDuplex* iSerialToUsb; |
|
258 CSignalChangeNotifier* iUsbSignalChangeNotifier; |
|
259 CSignalChangeNotifier* iSerialSignalChangeNotifier; |
|
260 CFControlChangeNotifier* iUsbFControlNotifier; |
|
261 CConfigChangeNotifier* iUsbConfigChangeNotifier; |
|
262 }; |
|
263 |
|
264 |