|
1 // Copyright (c) 2005-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 |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "EPos_CPosNmeaController.h" |
|
20 #include "EPos_CPosFileHandler.h" |
|
21 #include "EPos_SimPsyConstants.h" |
|
22 |
|
23 |
|
24 // ================= MEMBER FUNCTIONS ======================= |
|
25 |
|
26 // C++ default constructor can NOT contain any code, that |
|
27 // might leave. |
|
28 // |
|
29 CPosNmeaController::CPosNmeaController( |
|
30 TBool aTimeRelativePlayback) : |
|
31 CPosControllerBase(aTimeRelativePlayback), |
|
32 iHasAlreadyReadFirstSentence(EFalse), iState(EIdle) |
|
33 { |
|
34 CActiveScheduler::Add(this); |
|
35 iTimerTrigger.CreateLocal(); |
|
36 } |
|
37 |
|
38 // EPOC default constructor can leave. |
|
39 void CPosNmeaController::ConstructL(const TDesC& aNMEAFile) |
|
40 { |
|
41 iFileHandler = CPosFileHandler::NewL(aNMEAFile); |
|
42 CPosSimulationPositioner::ClearAndSetDefaultPositionData(iPosition); |
|
43 } |
|
44 |
|
45 // Two-phased constructor. |
|
46 CPosNmeaController* CPosNmeaController::NewL( |
|
47 const TDesC& aNMEAFile, |
|
48 TBool aTimeRelativePlayback) |
|
49 { |
|
50 CPosNmeaController* self = new (ELeave) CPosNmeaController(aTimeRelativePlayback); |
|
51 CleanupStack::PushL(self); |
|
52 self->ConstructL(aNMEAFile); |
|
53 CleanupStack::Pop(self); |
|
54 return self; |
|
55 } |
|
56 |
|
57 // Destructor |
|
58 CPosNmeaController::~CPosNmeaController() |
|
59 { |
|
60 iTimerTrigger.Cancel(); |
|
61 iTimerTrigger.Close(); |
|
62 Cancel(); |
|
63 delete iFileHandler; |
|
64 } |
|
65 |
|
66 // ---------------------------------------------------------------------------- |
|
67 // CPosNmeaController::NotifyPositionUpdate |
|
68 // |
|
69 // (other items were commented in a header). |
|
70 // ---------------------------------------------------------------------------- |
|
71 // |
|
72 void CPosNmeaController::NotifyPositionUpdate( |
|
73 TPositionInfoBase& aPosInfo, |
|
74 TRequestStatus& aStatus, |
|
75 CPosSimulationPositioner& aSimPos) |
|
76 { |
|
77 NotifyPositionUpdateBase(aPosInfo, aStatus, aSimPos); |
|
78 |
|
79 if(iState == EIdle && !IsActive()) |
|
80 { |
|
81 iState = EWaiting; |
|
82 if(iTimeRelativePlayback) |
|
83 { |
|
84 iTimerTrigger.After(iStatus, iTimeBetweenReads); |
|
85 } |
|
86 else |
|
87 { |
|
88 TRequestStatus* status = &iStatus; |
|
89 User::RequestComplete(status, KErrNone); |
|
90 } |
|
91 SetActive(); |
|
92 } |
|
93 } |
|
94 |
|
95 // ---------------------------------------------------------------------------- |
|
96 // CPosNmeaController::CompleteRequest |
|
97 // |
|
98 // (other items were commented in a header). |
|
99 // ---------------------------------------------------------------------------- |
|
100 // |
|
101 void CPosNmeaController::CompleteRequest(TInt aErrorCode) |
|
102 { |
|
103 CompleteRequestBase(aErrorCode); |
|
104 iParser.Reset(); |
|
105 if(aErrorCode == KErrNone && iTimeRelativePlayback) |
|
106 { |
|
107 StartTrpDelayTimer(); |
|
108 } |
|
109 else |
|
110 { |
|
111 iState = EIdle; |
|
112 } |
|
113 } |
|
114 |
|
115 // ---------------------------------------------------------------------------- |
|
116 // CPosNmeaController::ReadSentence |
|
117 // |
|
118 // (other items were commented in a header). |
|
119 // ---------------------------------------------------------------------------- |
|
120 // |
|
121 void CPosNmeaController::ReadSentence() |
|
122 { |
|
123 iState = EReadingSentence; |
|
124 TRequestStatus* status = &iStatus; |
|
125 |
|
126 iStatus = iFileHandler->Read(iInputBuffer); |
|
127 User::After(1); |
|
128 User::RequestComplete(status, iStatus.Int()); |
|
129 SetActive(); |
|
130 |
|
131 } |
|
132 |
|
133 // ---------------------------------------------------------------------------- |
|
134 // CPosNmeaController::ParseSentence |
|
135 // |
|
136 // (other items were commented in a header). |
|
137 // ---------------------------------------------------------------------------- |
|
138 // |
|
139 void CPosNmeaController::ParseSentence() |
|
140 { |
|
141 iState = EParsingSentence; |
|
142 TInt err = iParser.ParseSentence(iInputBuffer, iPosition); |
|
143 if(err != KPosErrorAlreadyParsed) |
|
144 { |
|
145 for(TInt i=0; i< iSimulationPositioners.Count(); i++) |
|
146 { |
|
147 //reading same information which were read into iParser |
|
148 //so we can properly process all possible types of position: |
|
149 //HPositionInfo, TPositionInfo, HPositionGenericInfo, TPositionCourseInfo, |
|
150 //TPositionSatelliteInfo, etc. |
|
151 iParser.ParseSentence(iInputBuffer, iSimulationPositioners[i].iPosition, ETrue); |
|
152 } |
|
153 } |
|
154 |
|
155 if (err == KPosErrorAlreadyParsed) |
|
156 { |
|
157 // Make sure this sentence is kept until next request. |
|
158 iHasAlreadyReadFirstSentence = ETrue; |
|
159 CompleteOrRetry(); |
|
160 } |
|
161 else if (err == KErrNone) |
|
162 { |
|
163 ReadSentence(); |
|
164 } |
|
165 else |
|
166 { |
|
167 CompleteRequest(err); |
|
168 } |
|
169 } |
|
170 |
|
171 // ---------------------------------------------------------------------------- |
|
172 // CPosNmeaController::IsPartialPosition |
|
173 // |
|
174 // (other items were commented in a header). |
|
175 // ---------------------------------------------------------------------------- |
|
176 // |
|
177 TBool CPosNmeaController::IsPartialPosition( |
|
178 TPositionInfoBase& aPosInfo) |
|
179 { |
|
180 TPositionInfo& posInfo = static_cast<TPositionInfo&> (aPosInfo); |
|
181 TPosition pos; |
|
182 posInfo.GetPosition(pos); |
|
183 |
|
184 // Check if time is set |
|
185 // Check if longitude is a number |
|
186 // Check if latitude is a number |
|
187 if (pos.Time().Int64() == 0 || |
|
188 Math::IsNaN(TRealX(pos.Longitude())) || |
|
189 Math::IsNaN(TRealX(pos.Latitude()))) |
|
190 { |
|
191 return ETrue; |
|
192 } |
|
193 |
|
194 return EFalse; |
|
195 } |
|
196 |
|
197 // ---------------------------------------------------------------------------- |
|
198 // CPosNmeaController::CompleteOrRetry |
|
199 // |
|
200 // (other items were commented in a header). |
|
201 // ---------------------------------------------------------------------------- |
|
202 // |
|
203 void CPosNmeaController::CompleteOrRetry() |
|
204 { |
|
205 TInt progress = iParser.Progress(); |
|
206 TBool partialPosition = IsPartialPosition(iPosition); |
|
207 |
|
208 if (progress == KPosAllParsed && !partialPosition) |
|
209 { |
|
210 // Full position fix |
|
211 CompleteRequest(KErrNone); |
|
212 return; |
|
213 } |
|
214 |
|
215 if (partialPosition) |
|
216 { |
|
217 // Partial update position fix |
|
218 CompleteRequest(KPositionPartialUpdate); |
|
219 } |
|
220 |
|
221 //check for any outstanding requests |
|
222 for(TInt i = 0; i < iSimulationPositioners.Count(); i++) |
|
223 { |
|
224 CPosSimulationPositioner::ClearAndSetDefaultPositionData(iSimulationPositioners[i].iPosition); |
|
225 } |
|
226 if(iSimulationPositioners.Count()>0) |
|
227 { |
|
228 // Otherwise reset the parser and try again to get a full fix |
|
229 iParser.Reset(); |
|
230 CPosSimulationPositioner::ClearAndSetDefaultPositionData(iPosition); |
|
231 |
|
232 if (iHasAlreadyReadFirstSentence) |
|
233 { |
|
234 ParseSentence(); |
|
235 } |
|
236 else |
|
237 { |
|
238 ReadSentence(); |
|
239 } |
|
240 } |
|
241 else if (iTimeRelativePlayback) |
|
242 { |
|
243 StartTrpDelayTimer(); |
|
244 } |
|
245 } |
|
246 |
|
247 void CPosNmeaController::StartTrpDelayTimer() |
|
248 { |
|
249 iState = EWaiting; |
|
250 __ASSERT_ALWAYS(iTimeRelativePlayback, User::Panic(_L("CPosNmeaController"), KErrTotalLossOfPrecision )); |
|
251 iTimerTrigger.After(iStatus, iTimeBetweenReads); |
|
252 SetActive(); |
|
253 } |
|
254 // ---------------------------------------------------------------------------- |
|
255 // CPosNmeaController::RunL |
|
256 // |
|
257 // (other items were commented in a header). |
|
258 // ---------------------------------------------------------------------------- |
|
259 // |
|
260 void CPosNmeaController::RunL() |
|
261 { |
|
262 switch (iState) |
|
263 { |
|
264 case EIdle: |
|
265 case EWaiting: |
|
266 if(iHasAlreadyReadFirstSentence) |
|
267 { |
|
268 iHasAlreadyReadFirstSentence = EFalse; |
|
269 ParseSentence(); |
|
270 } |
|
271 else |
|
272 { |
|
273 ReadSentence(); |
|
274 } |
|
275 break; |
|
276 case EReadingSentence: |
|
277 if (iStatus == KErrNone) |
|
278 { |
|
279 ParseSentence(); |
|
280 } |
|
281 else if (iStatus == KErrEof) |
|
282 { |
|
283 CompleteOrRetry(); |
|
284 } |
|
285 else |
|
286 { |
|
287 CompleteRequest(iStatus.Int()); |
|
288 } |
|
289 break; |
|
290 case EParsingSentence: |
|
291 default: |
|
292 User::Panic(_L("CPosNmeaController state"), KErrGeneral); |
|
293 } |
|
294 |
|
295 } |
|
296 |
|
297 // ---------------------------------------------------------------------------- |
|
298 // CPosNmeaController::DoCancel |
|
299 // |
|
300 // (other items were commented in a header). |
|
301 // ---------------------------------------------------------------------------- |
|
302 // |
|
303 void CPosNmeaController::DoCancel() |
|
304 { |
|
305 } |
|
306 |
|
307 // End of File |