|
1 /* |
|
2 * Copyright (c) 2005 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: Parses/Encodes AT ccommands. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef AT_CODEC_H |
|
20 #define AT_CODEC_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <e32base.h> |
|
24 |
|
25 enum TATId |
|
26 { |
|
27 EUnknownAT,// 0 Not known AT command |
|
28 EAT, // 1, AT test command |
|
29 EATA, // 2, answer a call |
|
30 EATBINP, // 3, Command used for requesting some specific data input from the AG |
|
31 EATBLDN, // 4, Command used for calling the last phone number dialed |
|
32 EATBRSF, // 5, Bluetooth Retrieve Supported Features |
|
33 EATBVRA, // 6, Bluetooth Voice Recognition Activation |
|
34 EATCCWA, // 7, call waiting notification |
|
35 EATCHLD, // 8, multiparty handling AT command |
|
36 EATCHUP, // 9, Hang-up AT command |
|
37 EATCIND, // 10, standard indicator update AT command (read and test only) |
|
38 EATCKPD, // 11, Command issued by HS to indicate that the button has been pressed |
|
39 EATCLCC, // 12, list of current call |
|
40 EATCLIP, // 13, standard Calling Line Identification notification activation AT command |
|
41 EATCMEE, // 14, Advanced error code activation |
|
42 EATCMER, // 15, Standard event reporting activation AT command |
|
43 EATCNUM, // 16, Subscriber number |
|
44 EATCOPS, // 17, Operator selection |
|
45 EATD1, // 18, place a call |
|
46 EATD2, // 19, speed dial |
|
47 EATNREC, // 20, Noise Reduction and Echo Canceling |
|
48 EATVGM, // 21, Microphone volume |
|
49 EATVGS, // 22, Speaker volume |
|
50 EATVTS, // 23, Standard DTMF generation AT command |
|
51 EATCIEV, // 24, notify call status change |
|
52 EATERROR, // 25, Response Error |
|
53 EATOK, // 26, Response OK |
|
54 EATRING, // 27, RING unsolicited response |
|
55 EATBIA, // 28, Set indicator status |
|
56 EATCREG, // 29, Network registration |
|
57 EATCGSN, // 30, Serial Number |
|
58 EATCSQ, // 31, Signal Strength in dBm |
|
59 EATCIMI, // 32, Mobile subscriber ID |
|
60 EATCGMI, // 33, Manufacturer information |
|
61 EATCGMM, // 34, Model id |
|
62 EATCGMR, // 35, Revision id |
|
63 EATCOLP, // 36, Outgoin call number |
|
64 EMinValidATIdRange = EAT, |
|
65 EMaxValidATIdRange = EATCOLP, |
|
66 }; |
|
67 |
|
68 enum TATType |
|
69 { |
|
70 EATUnkownType = 0, |
|
71 EATReadCmd = 0x001, // 1, Read format "AT+xxxx?" |
|
72 EATWriteCmd = 0x002, // 2, Write format "AT+xxxx=1" |
|
73 EATActionCmd = 0x004, // 4, Action format "AT+xxxx" or "ATx" (e.g. "ATD") |
|
74 EATTestCmd = 0x008, // 8, Test command "AT+xxxx=?" and "AT" |
|
75 EATReadResult = 0x010, // 16, Response to read command |
|
76 EATWriteResult = 0x020, // 32, Response to write command |
|
77 EATActionResult = 0x040, // 64, Response to action command |
|
78 EATTestResult = 0x080, // 128, Response to test command |
|
79 EATUnsolicitedResult = 0x100, // 256, Unsolicited result code |
|
80 EATErrorResult = 0x200 // 512, error result, OK or ERROR |
|
81 }; |
|
82 |
|
83 enum TATParamType |
|
84 { |
|
85 EATNullParam, |
|
86 EATStringParam, |
|
87 EATDQStringParam, |
|
88 EATIntParam |
|
89 }; |
|
90 |
|
91 const TInt KMaxATSize = 512; |
|
92 const TInt KMaxATParamSize = 256; |
|
93 |
|
94 class RReadStream; |
|
95 class RWriteStream; |
|
96 |
|
97 // CLASS DECLARATION |
|
98 /** |
|
99 * TATParam represents one AT command parameter. |
|
100 */ |
|
101 NONSHARABLE_CLASS(TATParam) |
|
102 { |
|
103 public: |
|
104 IMPORT_C TATParam(); |
|
105 |
|
106 IMPORT_C TATParam(const TDesC8& aValue, TATParamType aType = EATStringParam); |
|
107 |
|
108 IMPORT_C TATParam(TInt aValue); |
|
109 |
|
110 /** |
|
111 * Returns the parameter as integer. |
|
112 * @since 3.0 |
|
113 * @return error code. |
|
114 */ |
|
115 IMPORT_C TInt Int(TInt& aValue) const; |
|
116 |
|
117 /** |
|
118 * Returns the parameter as text. |
|
119 * @since 3.0 |
|
120 * @return the non-modifiable pointer descriptor |
|
121 */ |
|
122 IMPORT_C const TDesC8& Des() const; |
|
123 |
|
124 /** |
|
125 * Returns the parameter type. |
|
126 * @since 3.0 |
|
127 * @param None |
|
128 * @return Parameter type. |
|
129 */ |
|
130 IMPORT_C TATParamType Type() const; |
|
131 |
|
132 /** |
|
133 * Sets the parameter value. |
|
134 * @since 3.0 |
|
135 * @param aValue New value. |
|
136 * @return error code |
|
137 */ |
|
138 IMPORT_C TInt SetValue(const TDesC8& aValue, TATParamType aType); |
|
139 |
|
140 /** |
|
141 * Sets the parameter value. |
|
142 * @since 3.0 |
|
143 * @param aValue New value. |
|
144 * @return None |
|
145 */ |
|
146 IMPORT_C void SetInt(TInt aValue); |
|
147 |
|
148 IMPORT_C void ExternalizeL(RWriteStream& aStream) const; |
|
149 |
|
150 IMPORT_C void InternalizeL(RReadStream& aStream); |
|
151 |
|
152 private: |
|
153 void AddDQ(); |
|
154 |
|
155 private: |
|
156 TBuf8<KMaxATParamSize> iValue; |
|
157 TInt iValueInt; |
|
158 TATParamType iType; |
|
159 |
|
160 private: |
|
161 static const TInt32 KStreamVersion1 = 0x00000001; |
|
162 }; |
|
163 |
|
164 typedef RArray<TATParam> RATParamArray; |
|
165 |
|
166 /** |
|
167 * TATCommand is used for parsing Bluetooth AT commands. |
|
168 */ |
|
169 NONSHARABLE_CLASS(CATBase) : public CBase |
|
170 { |
|
171 public: |
|
172 IMPORT_C virtual ~CATBase(); |
|
173 |
|
174 /** |
|
175 * Returns AT command identification. |
|
176 * @since 3.0 |
|
177 * @param None |
|
178 * @return Id number. |
|
179 */ |
|
180 IMPORT_C TATId Id() const; |
|
181 |
|
182 /** |
|
183 * Returns AT command type. |
|
184 * @since 3.0 |
|
185 * @param None |
|
186 * @return Command type. |
|
187 */ |
|
188 IMPORT_C TATType Type() const; |
|
189 |
|
190 /** |
|
191 * Returns the number of command parameters. |
|
192 * @since 3.0 |
|
193 * @param None |
|
194 * @return Number of command paramteres. |
|
195 */ |
|
196 IMPORT_C TInt ParamNum() const; |
|
197 |
|
198 /** |
|
199 * Returns parameter at given index. |
|
200 * @since 3.0 |
|
201 * @param aIndex Index. |
|
202 * @return the parameter. |
|
203 */ |
|
204 IMPORT_C TInt Parameter(TInt aIndex, TATParam& aParam) const; |
|
205 |
|
206 /** |
|
207 * Returns parameters in a string. |
|
208 * @since 3.0 |
|
209 * @return the parameter list. |
|
210 */ |
|
211 IMPORT_C const RATParamArray& Parameters() const; |
|
212 |
|
213 /** |
|
214 * Gets the descriptor of this AT command or response. |
|
215 */ |
|
216 IMPORT_C const TDesC8& Des() const; |
|
217 |
|
218 IMPORT_C void ExternalizeL(RWriteStream& aStream) const; |
|
219 |
|
220 IMPORT_C void InternalizeL(RReadStream& aStream); |
|
221 |
|
222 protected: |
|
223 CATBase(); |
|
224 |
|
225 void Reset(); |
|
226 |
|
227 protected: |
|
228 RBuf8 iText; |
|
229 TATId iId; |
|
230 TATType iType; |
|
231 RATParamArray iParamList; |
|
232 |
|
233 private: |
|
234 static const TInt32 KStreamVersion1 = 0x00000001; |
|
235 }; |
|
236 |
|
237 /** |
|
238 * TATCommand is used for parsing Bluetooth AT commands. |
|
239 */ |
|
240 NONSHARABLE_CLASS(CATCommand) : public CATBase |
|
241 { |
|
242 public: |
|
243 /** |
|
244 * Instantiates an uninitialized AT command. |
|
245 */ |
|
246 IMPORT_C static CATCommand* NewL(); |
|
247 |
|
248 /** |
|
249 * Instantiates an uninitialized AT command and leaves it in cleanupstack. |
|
250 */ |
|
251 IMPORT_C static CATCommand* NewLC(); |
|
252 |
|
253 /** |
|
254 * Instantiates an AT command. |
|
255 * Function leaves if aCmd is not supported or not valid. |
|
256 */ |
|
257 IMPORT_C static CATCommand* NewL(const TDesC8& aCmd); |
|
258 |
|
259 /** |
|
260 * Instantiates an AT command and leaves it in cleanupstack. |
|
261 * Function leaves if aCmd is not supported or not valid. |
|
262 */ |
|
263 IMPORT_C static CATCommand* NewLC(const TDesC8& aCmd); |
|
264 |
|
265 /** |
|
266 * |
|
267 * @since 3.0 |
|
268 * @param aText Command string |
|
269 * @return |
|
270 */ |
|
271 IMPORT_C TInt Set(const TDesC8& aText); |
|
272 |
|
273 private: |
|
274 CATCommand(); |
|
275 |
|
276 TInt Parse(const TDesC8& aText); |
|
277 |
|
278 void ParseCommandType(TPtrC8& aPtrC); |
|
279 |
|
280 TInt ParseParams(TPtrC8& aDes, TUint aParamIndex, TUint aTableIndex); |
|
281 }; |
|
282 |
|
283 /** |
|
284 * TATCommand is used for parsing Bluetooth AT commands. |
|
285 */ |
|
286 NONSHARABLE_CLASS(CATResult) : public CATBase |
|
287 { |
|
288 public: |
|
289 /** |
|
290 * Instantiates an uninitialized AT command. |
|
291 */ |
|
292 IMPORT_C static CATResult* NewL(); |
|
293 |
|
294 /** |
|
295 * Instantiates an uninitialized AT command and leaves it in cleanupstack. |
|
296 */ |
|
297 IMPORT_C static CATResult* NewLC(); |
|
298 |
|
299 IMPORT_C static CATResult* NewL(TATId aId, TATType aType = EATErrorResult, const RATParamArray* aParams = NULL); |
|
300 |
|
301 IMPORT_C static CATResult* NewLC(TATId aId, TATType aType = EATErrorResult, const RATParamArray* aParams = NULL); |
|
302 |
|
303 IMPORT_C static CATResult* NewL(TATId aId, TATType aType, const TATParam aParam); |
|
304 |
|
305 IMPORT_C static CATResult* NewLC(TATId aId, TATType aType, const TATParam aParam); |
|
306 |
|
307 /** |
|
308 * |
|
309 */ |
|
310 IMPORT_C TInt Set(TATId aId, TATType aType = EATErrorResult, const RATParamArray* aParams = NULL); |
|
311 |
|
312 private: |
|
313 CATResult(); |
|
314 |
|
315 TInt Parse(TATId aId, TATType aType, const RATParamArray* aParams); |
|
316 |
|
317 /** |
|
318 * Adds carriage return and line feed characters at |
|
319 * the beginning and the end of the string. |
|
320 * @since 3.0 |
|
321 * @param aText String to be modified. |
|
322 * @return None |
|
323 */ |
|
324 static TInt AddCRLF(TDes8& aText); |
|
325 }; |
|
326 |
|
327 typedef RPointerArray<CATResult> RATResultPtrArray; |
|
328 |
|
329 IMPORT_C void ATObjArrayCleanupResetAndDestroyPushL(RATResultPtrArray& aArray); |
|
330 |
|
331 #endif // AT_CODEC_H |
|
332 |
|
333 // End of File |