|
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 #include "rasdef.h" |
|
17 |
|
18 TInt Util::GetCommaSepToken(TLex& aLex, TPtrC& aPtr) |
|
19 { |
|
20 aPtr.Set(NULL,0); |
|
21 |
|
22 TChar ch; |
|
23 while(!aLex.Eos() && (ch = aLex.Peek(), ch==',')) |
|
24 aLex.Inc(); |
|
25 |
|
26 if(aLex.Eos()) |
|
27 return KErrNone; |
|
28 |
|
29 aLex.Mark(); |
|
30 while (!aLex.Eos() && (ch = aLex.Peek(), ch!=',')) |
|
31 aLex.Inc(); |
|
32 aPtr.Set(aLex.MarkedToken()); |
|
33 return KErrNone; |
|
34 } |
|
35 |
|
36 TInt Util::GetCommHandshake(const TDesC& aDes, TUint& aHandshake) |
|
37 { |
|
38 TLex lex(aDes); |
|
39 TPtrC des; |
|
40 TUint hs = 0; |
|
41 for (;;) |
|
42 { |
|
43 TInt ret = GetCommaSepToken(lex, des); |
|
44 if (ret!=KErrNone) |
|
45 return ret; |
|
46 if (des.Length()>0) |
|
47 { |
|
48 _LIT(KXonXoff, "XON/XOFF"); |
|
49 _LIT(KRtsCts, "RTS/CTS"); |
|
50 _LIT(KDtrDsr, "DTR/DSR"); |
|
51 _LIT(KDcd, "DCD"); |
|
52 |
|
53 if (!des.CompareF(KXonXoff)) |
|
54 hs |= (KConfigObeyXoff | KConfigSendXoff); |
|
55 else if (!des.CompareF(KRtsCts)) |
|
56 hs |= (KConfigObeyCTS); |
|
57 else if (!des.CompareF(KDtrDsr)) |
|
58 hs |= (KConfigObeyDSR | KConfigFailDSR); |
|
59 else if (!des.CompareF(KDcd)) |
|
60 hs |= (KConfigObeyDCD); |
|
61 else |
|
62 return KErrArgument; |
|
63 } |
|
64 else |
|
65 break; |
|
66 } |
|
67 aHandshake = hs; |
|
68 return KErrNone; |
|
69 } |
|
70 |
|
71 TInt Util::GetCommFormat(const TDesC& aDes, TDataBits& aDataBits, TStopBits& aStopBits, TParity& aParity) |
|
72 { |
|
73 switch (aDes[0]) |
|
74 { |
|
75 case '5': |
|
76 aDataBits = EData5; |
|
77 break; |
|
78 case '6': |
|
79 aDataBits = EData6; |
|
80 break; |
|
81 case '7': |
|
82 aDataBits = EData7; |
|
83 break; |
|
84 case '8': |
|
85 aDataBits = EData8; |
|
86 break; |
|
87 default: |
|
88 return KErrArgument; |
|
89 } |
|
90 switch (aDes[1]) |
|
91 { |
|
92 case 'N': |
|
93 aParity = EParityNone; |
|
94 break; |
|
95 case 'E': |
|
96 aParity = EParityEven; |
|
97 break; |
|
98 case 'O': |
|
99 aParity = EParityOdd; |
|
100 break; |
|
101 case 'M': |
|
102 aParity = EParityMark; |
|
103 break; |
|
104 case 'S': |
|
105 aParity = EParitySpace; |
|
106 break; |
|
107 default: |
|
108 return KErrArgument; |
|
109 } |
|
110 switch (aDes[2]) |
|
111 { |
|
112 case '1': |
|
113 aStopBits = EStop1; |
|
114 break; |
|
115 case '2': |
|
116 aStopBits = EStop2; |
|
117 break; |
|
118 default: |
|
119 return KErrArgument; |
|
120 } |
|
121 return KErrNone; |
|
122 } |
|
123 |
|
124 |
|
125 TInt Util::GetCommSpeed(TInt aSpeed, TBps& aBps) |
|
126 { |
|
127 switch (aSpeed) |
|
128 { |
|
129 case 50: |
|
130 aBps = EBps50; |
|
131 break; |
|
132 case 75: |
|
133 aBps = EBps75; |
|
134 break; |
|
135 case 110: |
|
136 aBps = EBps110; |
|
137 break; |
|
138 case 134: |
|
139 aBps = EBps134; |
|
140 break; |
|
141 case 150: |
|
142 aBps = EBps150; |
|
143 break; |
|
144 case 300: |
|
145 aBps = EBps300; |
|
146 break; |
|
147 case 600: |
|
148 aBps = EBps600; |
|
149 break; |
|
150 case 1200: |
|
151 aBps = EBps1200; |
|
152 break; |
|
153 case 1800: |
|
154 aBps = EBps1800; |
|
155 break; |
|
156 case 2000: |
|
157 aBps = EBps2000; |
|
158 break; |
|
159 case 2400: |
|
160 aBps = EBps2400; |
|
161 break; |
|
162 case 3600: |
|
163 aBps = EBps3600; |
|
164 break; |
|
165 case 4800: |
|
166 aBps = EBps4800; |
|
167 break; |
|
168 case 7200: |
|
169 aBps = EBps7200; |
|
170 break; |
|
171 case 9600: |
|
172 aBps = EBps9600; |
|
173 break; |
|
174 case 19200: |
|
175 aBps = EBps19200; |
|
176 break; |
|
177 case 38400: |
|
178 aBps = EBps38400; |
|
179 break; |
|
180 case 57600: |
|
181 aBps = EBps57600; |
|
182 break; |
|
183 case 115200: |
|
184 aBps = EBps115200; |
|
185 break; |
|
186 default: |
|
187 return KErrArgument; |
|
188 } |
|
189 return KErrNone; |
|
190 } |
|
191 |
|
192 #if defined (__WINS__) |
|
193 _LIT(PDD_NAME,"ECDRV"); |
|
194 _LIT(LDD_NAME,"ECOMM"); |
|
195 #else |
|
196 _LIT(PDD_NAME,"EUART1"); |
|
197 _LIT(PDD2_NAME,"EUART2"); |
|
198 _LIT(LDD_NAME,"ECOMM"); |
|
199 #endif |
|
200 |
|
201 void Util::CommInit() |
|
202 { |
|
203 |
|
204 User::LoadPhysicalDevice(PDD_NAME); |
|
205 #ifdef PDD2_NAME |
|
206 User::LoadPhysicalDevice(PDD2_NAME); |
|
207 #endif |
|
208 User::LoadLogicalDevice(LDD_NAME); |
|
209 // When bootstrapping C32 we have to avoid the PhBkSyncServer being started, since |
|
210 // it needs a different CommDB |
|
211 _LIT(KPhbkSyncCMI, "phbsync.cmi"); |
|
212 StartC32WithCMISuppressions(KPhbkSyncCMI); |
|
213 } |