|
1 // Copyright (c) 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 // @file testltsysmsatutil.cpp |
|
15 // This contains SmsAtUtil which is util for Sms At command |
|
16 // |
|
17 |
|
18 // user include |
|
19 #include "testltsysmsatutil.h" |
|
20 |
|
21 // --------------------------------------------------------------------------- |
|
22 // SmsAtUtil::ConvertAsciiToBinary |
|
23 // other items were commented in a header |
|
24 // --------------------------------------------------------------------------- |
|
25 TInt SmsAtUtil::ConvertAsciiToBinary(const TDesC8& aAscii,TDes8& aData) |
|
26 { |
|
27 aData.Zero(); |
|
28 TLex8 lex; |
|
29 TUint8 val; |
|
30 TInt ret; |
|
31 const TInt count(aAscii.Length()); |
|
32 for(TInt i = 0;i < count;i = i + 2) |
|
33 { |
|
34 lex = aAscii.Mid(i,2); |
|
35 ret = lex.Val(val,EHex); |
|
36 if(ret != KErrNone) |
|
37 { |
|
38 return ret; |
|
39 } |
|
40 aData.Append(val); |
|
41 } |
|
42 return KErrNone; |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // SmsAtUtil::AppendDataToAscii |
|
47 // other items were commented in a header |
|
48 // --------------------------------------------------------------------------- |
|
49 void SmsAtUtil::AppendDataToAscii(TDes8& aAscii,const TDesC8& aData) |
|
50 { |
|
51 const TInt count(aData.Length()); |
|
52 // __ASSERT_DEBUG((aAscii.MaxLength()-aAscii.MaxLength())<=(count*2),Panic(EATSmsUtilsDescriptorOverflow)); |
|
53 |
|
54 for(TInt i = 0; i < count; ++i) |
|
55 { |
|
56 AppendOctet(aData[i],aAscii); |
|
57 } |
|
58 |
|
59 // __ASSERT_DEBUG(aAscii.Length()%2==0,Panic(EATSmsUtilsOddNumberOfSemiOctets)); |
|
60 } |
|
61 |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // SmsAtUtil::IsAddressChar |
|
65 // other items were commented in a header |
|
66 // --------------------------------------------------------------------------- |
|
67 TBool SmsAtUtil::IsAddressChar(TChar aChar) |
|
68 { |
|
69 if(aChar.IsDigit()) |
|
70 { |
|
71 return ETrue; |
|
72 } |
|
73 if(aChar == TChar('*') || |
|
74 aChar == TChar('#') || |
|
75 aChar == TChar('a') || |
|
76 aChar == TChar('b') || |
|
77 aChar == TChar('c')) |
|
78 { |
|
79 return ETrue; |
|
80 } |
|
81 return EFalse; |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // SmsAtUtil::ConvertNumberingPlan |
|
86 // other items were commented in a header |
|
87 // --------------------------------------------------------------------------- |
|
88 RMobilePhone::TMobileNPI SmsAtUtil::ConvertNumberingPlan(TInt aValue) |
|
89 { |
|
90 switch(aValue) |
|
91 { |
|
92 // The below 'magic numbers' come from the ETSI 03.40 |
|
93 // specification for Address Fields (section 9.1.2.5) |
|
94 case 1: |
|
95 return RMobilePhone::EIsdnNumberPlan; |
|
96 case 3: |
|
97 return RMobilePhone::EDataNumberPlan; |
|
98 case 4: |
|
99 return RMobilePhone::ETelexNumberPlan; |
|
100 case 8: |
|
101 return RMobilePhone::ENationalNumberPlan; |
|
102 case 9: |
|
103 return RMobilePhone::EPrivateNumberPlan; |
|
104 default: |
|
105 return RMobilePhone::EUnknownNumberingPlan; |
|
106 } |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // SmsAtUtil::ConvertTypeOfNumber |
|
111 // other items were commented in a header |
|
112 // --------------------------------------------------------------------------- |
|
113 RMobilePhone::TMobileTON SmsAtUtil::ConvertTypeOfNumber(TInt aValue) |
|
114 { |
|
115 switch(aValue) |
|
116 { |
|
117 // The below 'magic numbers' come from the ETSI 03.40 |
|
118 // specification for Address Fields (section 9.1.2.5) |
|
119 case 0: |
|
120 return RMobilePhone::EUnknownNumber; |
|
121 case 1: |
|
122 return RMobilePhone::EInternationalNumber; |
|
123 case 2: |
|
124 return RMobilePhone::ENationalNumber; |
|
125 case 3: |
|
126 return RMobilePhone::ENetworkSpecificNumber; |
|
127 case 4: |
|
128 return RMobilePhone::ESubscriberNumber; |
|
129 default: |
|
130 return RMobilePhone::EUnknownNumber; |
|
131 } |
|
132 } |
|
133 |
|
134 // --------------------------------------------------------------------------- |
|
135 // SmsAtUtil::AppendOctet |
|
136 // other items were commented in a header |
|
137 // --------------------------------------------------------------------------- |
|
138 void SmsAtUtil::AppendOctet(TInt aOctet,TDes8& aAscii) |
|
139 { |
|
140 // Ensure client has only passed us a octet (ie. low 8 bits only) |
|
141 aOctet = aOctet&0xff; |
|
142 // Append octet |
|
143 // (prefix '0' if the octets value only uses one digit as final |
|
144 // octet coding must use two digits) |
|
145 if(aOctet <= 0x0f) |
|
146 { |
|
147 aAscii.Append(TChar('0')); |
|
148 } |
|
149 |
|
150 aAscii.AppendNum(aOctet,EHex); |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------------------------- |
|
154 // SmsAtUtil::ConvertAddressChar |
|
155 // other items were commented in a header |
|
156 // --------------------------------------------------------------------------- |
|
157 TInt SmsAtUtil::ConvertAddressChar(TChar aChar) |
|
158 { |
|
159 aChar.LowerCase(); |
|
160 if(aChar-TChar('0') <= 9) |
|
161 { |
|
162 // it should be digital number from 0~9 |
|
163 return aChar-TChar('0'); |
|
164 } |
|
165 else if(aChar == TChar('*')) |
|
166 { |
|
167 return 10; |
|
168 } |
|
169 else if(aChar == TChar('#')) |
|
170 { |
|
171 return 11; |
|
172 } |
|
173 else if(aChar == TChar('a')) |
|
174 { |
|
175 return 12; |
|
176 } |
|
177 else if(aChar == TChar('b')) |
|
178 { |
|
179 return 13; |
|
180 } |
|
181 else if(aChar == TChar('c')) |
|
182 { |
|
183 return 14; |
|
184 } |
|
185 return 15; |
|
186 } |
|
187 |
|
188 // --------------------------------------------------------------------------- |
|
189 // SmsAtUtil::ConvertAddressChar |
|
190 // other items were commented in a header |
|
191 // --------------------------------------------------------------------------- |
|
192 TChar SmsAtUtil::ConvertAddressChar(TInt aBinary) |
|
193 { |
|
194 if(aBinary >= 0 && aBinary <= 9) |
|
195 { |
|
196 return TChar(aBinary) + TChar('0'); // Assumes digit characters are one after each other |
|
197 } |
|
198 else if(aBinary == 10) |
|
199 { |
|
200 return TChar('*'); |
|
201 } |
|
202 else if(aBinary == 11) |
|
203 { |
|
204 return TChar('#'); |
|
205 } |
|
206 else if(aBinary == 12) |
|
207 { |
|
208 return TChar('a'); |
|
209 } |
|
210 else if(aBinary == 13) |
|
211 { |
|
212 return TChar('b'); |
|
213 } |
|
214 else if(aBinary == 14) |
|
215 { |
|
216 return TChar('c'); |
|
217 } |
|
218 return TChar(0); // This is the cloest I can find to a NULL char |
|
219 } |
|
220 |
|
221 // End of file |