|
1 /* |
|
2 * |
|
3 * Copyright (c) <2010> Comarch S.A. and/or its subsidiary(-ies). |
|
4 * All rights reserved. |
|
5 * This component and the accompanying materials are made available |
|
6 * under the terms of the License "Eclipse Public License v1.0" |
|
7 * which accompanies this distribution, and is available |
|
8 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 * |
|
10 * Original Contributors: |
|
11 * Comarch S.A. - original contribution. |
|
12 * |
|
13 * Contributors: |
|
14 * |
|
15 * Description: |
|
16 * |
|
17 */ |
|
18 #ifndef HSPCOMMAND_H_ |
|
19 #define HSPCOMMAND_H_ |
|
20 |
|
21 #include <e32base.h> |
|
22 |
|
23 /** Helpful constants */ |
|
24 _LIT8(KHsHSPCommandPrefix,"AT"); |
|
25 _LIT8(KHsHSPCommandSuffix,"\r\n"); |
|
26 _LIT8(KHsHSPVGSCommand,"+VGS"); |
|
27 _LIT8(KHsHSPVGMCommand,"+VGM"); |
|
28 _LIT8(KHsHSPCKPDCommand,"+CKPD"); |
|
29 _LIT8(KHsHSPOKCommand,"\r\nOK\r\n"); |
|
30 _LIT8(KHsHSPERRORCommand,"\r\nERROR\r\n"); |
|
31 _LIT8(KHsHSPRINGCommand,"\r\nRING\r\n"); |
|
32 _LIT8(KHsHSPParamsSeparator,","); |
|
33 _LIT8(KHsHSPIndicatorParamsSeparator,"),"); |
|
34 _LIT8(KHsHSPCommandSeparator,"\r\n\r\n"); |
|
35 _LIT8(KHsHSPATTestModeDes,"=?"); |
|
36 _LIT8(KHsHSPATWriteModeDes,"="); |
|
37 _LIT8(KHsHSPATReadModeDes,"?"); |
|
38 _LIT8(KHsHSPATTestModeDesAG,"=?"); |
|
39 _LIT8(KHsHSPATWriteModeDesAG,": "); |
|
40 _LIT8(KHsHSPATReadModeDesAG,"?"); |
|
41 |
|
42 /** Max size of AT command's param */ |
|
43 const TInt KHsHSPMaxATParamSize = 256; |
|
44 |
|
45 /** |
|
46 * @brief TATParam represents singular AT command parameter. |
|
47 */ |
|
48 class TATParam |
|
49 { |
|
50 public: |
|
51 |
|
52 /** |
|
53 * Constructor |
|
54 * |
|
55 * @param aValue 8-bit param descriptor |
|
56 */ |
|
57 TATParam( const TDesC8& aValue ); |
|
58 |
|
59 /** |
|
60 * Returns the parameter as text. |
|
61 * @return the non-modifiable pointer descriptor |
|
62 */ |
|
63 const TDesC8& Des() const; |
|
64 |
|
65 /** |
|
66 * Returns the paramater as integer value (if conversion is possible) |
|
67 * |
|
68 * @return integer value. If conversion is impossible then leave occures |
|
69 */ |
|
70 TInt IntL() const; |
|
71 |
|
72 private: |
|
73 |
|
74 /** Buffer for AT param */ |
|
75 TBuf8 <KHsHSPMaxATParamSize> iValue; |
|
76 }; |
|
77 |
|
78 /** Array of AT params */ |
|
79 typedef RArray <TATParam> RATParamArray; |
|
80 |
|
81 /** HSP's supported commands */ |
|
82 enum THsHSPCommandType |
|
83 { |
|
84 /** <cr><lf> OK <cr><lf> */ |
|
85 EHSPCmdOK, |
|
86 /** <cr><lf> ERROR <cr><lf> */ |
|
87 EHSPCmdERROR, |
|
88 /** <cr><lf> RING <cr><lf> */ |
|
89 EHSPCmdRING, |
|
90 /** +VGS */ |
|
91 EHSPCmdVGS, |
|
92 /** +VGM */ |
|
93 EHSPCmdVGM, |
|
94 /** +CKPD */ |
|
95 EHSPCmdCKPD, |
|
96 /** Other (unsupported) command */ |
|
97 EHSPCmdUnknown |
|
98 }; |
|
99 |
|
100 /** AT command's mode */ |
|
101 enum THsHSPCommandMode |
|
102 { |
|
103 /** = */ |
|
104 ECmdModeWrite, |
|
105 /** ? */ |
|
106 ECmdModeRead, |
|
107 /** =? */ |
|
108 ECmdModeTest, |
|
109 /** empty without params */ |
|
110 ECmdModeNormal, |
|
111 /** empty with params */ |
|
112 ECmdModeOther, |
|
113 |
|
114 ECmdUnknownMode |
|
115 }; |
|
116 |
|
117 /** |
|
118 * @brief AT command representation |
|
119 */ |
|
120 class CHsHSPCommand : public CBase |
|
121 { |
|
122 |
|
123 public: |
|
124 |
|
125 /** |
|
126 * Two-phased constructor. |
|
127 * |
|
128 * @return class instance |
|
129 */ |
|
130 static CHsHSPCommand* NewL(); |
|
131 |
|
132 /** |
|
133 * Two-phased constructor. |
|
134 * |
|
135 * @return class instance |
|
136 */ |
|
137 static CHsHSPCommand* NewLC(); |
|
138 |
|
139 /** |
|
140 * Destructor |
|
141 */ |
|
142 ~CHsHSPCommand(); |
|
143 |
|
144 public: |
|
145 |
|
146 /** Sets command's type |
|
147 * |
|
148 * @param aType type |
|
149 * @return error code |
|
150 */ |
|
151 TInt SetType( const THsHSPCommandType aType ); |
|
152 |
|
153 /** Sets command's mode |
|
154 * |
|
155 * @param aMode mode |
|
156 * @return error code |
|
157 */ |
|
158 TInt SetMode( const THsHSPCommandMode aMode ); |
|
159 |
|
160 /** Sets command's params |
|
161 * |
|
162 * @param aParams array of params |
|
163 * @return error code |
|
164 */ |
|
165 TInt SetParams( const RATParamArray& aParams ); |
|
166 |
|
167 /** Sets command's source |
|
168 * |
|
169 * @param aFromAG denotes if command sent by AG |
|
170 */ |
|
171 void SetSource( const TBool aFromAG ); |
|
172 |
|
173 /** |
|
174 * Returns command as a 8-bit descriptor |
|
175 * |
|
176 * @param aBuf buffer |
|
177 */ |
|
178 void ToDes8( TDes8& aBuf ) const; |
|
179 |
|
180 /** Getter for command's type */ |
|
181 THsHSPCommandType Type() const; |
|
182 |
|
183 /** Getter for command's mode */ |
|
184 THsHSPCommandMode Mode() const; |
|
185 |
|
186 /** Getter for command's source - denotes if sent by AG */ |
|
187 TBool FromAG() const; |
|
188 |
|
189 /** Getter for command's array of params */ |
|
190 const RATParamArray Params() const; |
|
191 |
|
192 /** |
|
193 * Clones CHsHSPCommand object |
|
194 * |
|
195 * @param aCmdFrom source |
|
196 * @param aCmdTo destination |
|
197 */ |
|
198 static void CopyL( const CHsHSPCommand* aCmdFrom, CHsHSPCommand& aCmdTo ); |
|
199 |
|
200 private: |
|
201 /** |
|
202 * Constructor for performing 1st stage construction |
|
203 */ |
|
204 CHsHSPCommand(); |
|
205 |
|
206 /** |
|
207 * Constructor for performing 2nd stage construction |
|
208 */ |
|
209 void ConstructL(); |
|
210 |
|
211 private: |
|
212 |
|
213 /** Param array's granularity */ |
|
214 const TInt KParamArrayGranularity = 3; |
|
215 |
|
216 /** Max length of command's type represented as descriptor */ |
|
217 const TInt KTypeDesMaxLength = 9; |
|
218 |
|
219 /** Max length of command's mode represented as descriptor */ |
|
220 const TInt KModeDesMaxLength = 3; |
|
221 |
|
222 /** Max length of command's params represented as descriptor */ |
|
223 const TInt KParamsDesMaxLength = 200; |
|
224 |
|
225 /** Command's type */ |
|
226 THsHSPCommandType iType; |
|
227 |
|
228 /** Command's mode */ |
|
229 THsHSPCommandMode iMode; |
|
230 |
|
231 /** Command's source. Denotes if command was sent from AG */ |
|
232 TBool iFromAG; |
|
233 |
|
234 /** Command's params */ |
|
235 RATParamArray iParams; |
|
236 |
|
237 /** Command's type as a descriptor */ |
|
238 RBuf8 iTypeDes; |
|
239 |
|
240 /** Command's mode as a descriptor */ |
|
241 RBuf8 iModeDes; |
|
242 |
|
243 /** Command's params as a descriptor */ |
|
244 RBuf8 iParamsDes; |
|
245 }; |
|
246 |
|
247 #endif /* HSPCOMMAND_H_ */ |