|
1 /* |
|
2 * Copyright (c) 2007-2008 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 the License "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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // Include Files |
|
21 #include "cmmdatautility.h" |
|
22 #include "cmmdataporthandler.h" |
|
23 #include "tsylogger.h" |
|
24 |
|
25 #include "osttracedefinitions.h" |
|
26 #ifdef OST_TRACE_COMPILER_IN_USE |
|
27 #include "cmmdatautilitytraces.h" |
|
28 #endif |
|
29 // EXTERNAL DATA STRUCTURES |
|
30 //None |
|
31 |
|
32 // EXTERNAL FUNCTION PROTOTYPES |
|
33 //None |
|
34 |
|
35 // CONSTANTS |
|
36 //None |
|
37 |
|
38 // MACROS |
|
39 //None |
|
40 |
|
41 // LOCAL CONSTANTS AND MACROS |
|
42 //None |
|
43 |
|
44 // MODULE DATA STRUCTURES |
|
45 //None |
|
46 |
|
47 // LOCAL FUNCTION PROTOTYPES |
|
48 //None |
|
49 |
|
50 // FORWARD DECLARATIONS |
|
51 //None |
|
52 |
|
53 // ==================== LOCAL FUNCTIONS ======================================= |
|
54 |
|
55 //None |
|
56 |
|
57 // ================= MEMBER FUNCTIONS ========================================= |
|
58 |
|
59 // ---------------------------------------------------------------------------- |
|
60 // CDataPortWriter::NewL |
|
61 // Two-phased constructor. |
|
62 // ---------------------------------------------------------------------------- |
|
63 // |
|
64 CDataPortWriter* CDataPortWriter::NewL( |
|
65 CMmDataPortHandler* aMmDataPortHandler, |
|
66 const RComm& aDataPort ) |
|
67 { |
|
68 |
|
69 TFLOGSTRING("TSY: CDataPortWriter::NewL"); |
|
70 OstTrace0( TRACE_NORMAL, CDATAPORTWRITER_NEWL, "CDataPortWriter::NewL" ); |
|
71 |
|
72 CDataPortWriter* writer = new ( ELeave ) CDataPortWriter(); |
|
73 CleanupStack::PushL( writer ); |
|
74 |
|
75 writer->iDataPortHandler = aMmDataPortHandler; |
|
76 writer->iDataPort = aDataPort; |
|
77 writer->ConstructL(); |
|
78 |
|
79 CActiveScheduler::Add( writer ); |
|
80 |
|
81 CleanupStack::Pop( writer ); |
|
82 |
|
83 return writer; |
|
84 } |
|
85 |
|
86 // ---------------------------------------------------------------------------- |
|
87 // CDataPortWriter::CDataPortWriter |
|
88 // C++ default constructor can NOT contain any code, that |
|
89 // might leave. |
|
90 // ---------------------------------------------------------------------------- |
|
91 // |
|
92 CDataPortWriter::CDataPortWriter() |
|
93 : CActive( EPriorityStandard ), iDataToDpPtr( NULL, 0 ) |
|
94 { |
|
95 //None |
|
96 TFLOGSTRING("TSY: CDataPortWriter::CDataPortWriter"); |
|
97 OstTrace0( TRACE_NORMAL, CDATAPORTWRITER_CDATAPORTWRITER, "CDataPortWriter::CDataPortWriter" ); |
|
98 |
|
99 } |
|
100 |
|
101 // ---------------------------------------------------------------------------- |
|
102 // CDataPortWriter::ConstructL |
|
103 // Symbian 2nd phase constructor can leave. |
|
104 // ---------------------------------------------------------------------------- |
|
105 // |
|
106 void CDataPortWriter::ConstructL() |
|
107 { |
|
108 |
|
109 TFLOGSTRING("TSY: CDataPortWriter::ConstructL"); |
|
110 OstTrace0( TRACE_NORMAL, CDATAPORTWRITER_CONSTRUCTL, "CDataPortWriter::ConstructL" ); |
|
111 |
|
112 // initialisation of menber variables |
|
113 iWriteCompleted = ETrue; |
|
114 iContinueWrite = ETrue; |
|
115 iWriteBuffer = new ( ELeave ) CArrayPtrSeg<HBufC8>( |
|
116 KSentAtCommandLimit ); |
|
117 iAtCommandBuffer = new (ELeave) CArrayFixFlat<TUint>( |
|
118 KSentAtCommandLimit ); |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CDataPortWriter::~CDataPortWriter |
|
123 // Destructor, deletes all allocated resources. |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 CDataPortWriter::~CDataPortWriter() |
|
127 { |
|
128 |
|
129 TFLOGSTRING("TSY: CDataPortWriter::~CDataPortWriter"); |
|
130 OstTrace0( TRACE_NORMAL, DUP1_CDATAPORTWRITER_CDATAPORTWRITER, "CDataPortWriter::~CDataPortWriter" ); |
|
131 |
|
132 Cancel(); |
|
133 |
|
134 if ( iWriteBuffer ) |
|
135 { |
|
136 iWriteBuffer->ResetAndDestroy(); |
|
137 delete iWriteBuffer; |
|
138 } |
|
139 //no else |
|
140 |
|
141 if ( iAtCommandBuffer ) |
|
142 { |
|
143 iAtCommandBuffer->Reset(); |
|
144 delete iAtCommandBuffer; |
|
145 } |
|
146 //no else |
|
147 } |
|
148 |
|
149 // ---------------------------------------------------------------------------- |
|
150 // CDataPortWriter::Init |
|
151 // This method sends TSY init strings to modem. |
|
152 // (other items were commented in a header). |
|
153 // ---------------------------------------------------------------------------- |
|
154 // |
|
155 void CDataPortWriter::Init() |
|
156 { |
|
157 |
|
158 TFLOGSTRING("TSY: CDataPortWriter::Init Modem initialisation"); |
|
159 OstTrace0( TRACE_NORMAL, CDATAPORTWRITER_INIT, "CDataPortWriter::Init" ); |
|
160 |
|
161 // Initalise modem |
|
162 TBuf8<KDataBufLength> ATString; |
|
163 |
|
164 // Common Initialisations |
|
165 ATString.Copy( KModemInitString ); |
|
166 ATString.Append( KReturn ); |
|
167 Write( ATString, EModemInit ); |
|
168 // VT initialisation |
|
169 ATString.Copy( KHscsdMultimedia_64000 ); |
|
170 Write( ATString, EModemInit ); |
|
171 } |
|
172 |
|
173 // ---------------------------------------------------------------------------- |
|
174 // CDataPortWriter::AppendCommandL |
|
175 // This method appends enum for AT command to be sent into iAtCommandBuffer. |
|
176 // (other items were commented in a header). |
|
177 // ---------------------------------------------------------------------------- |
|
178 // |
|
179 void CDataPortWriter::AppendCommandL( |
|
180 TLastAtCommandSent aCommand ) |
|
181 { |
|
182 |
|
183 TFLOGSTRING("TSY: CDataPortWriter::AppendCommandL"); |
|
184 OstTrace0( TRACE_NORMAL, CDATAPORTWRITER_APPENDCOMMANDL, "CDataPortWriter::AppendCommandL" ); |
|
185 |
|
186 iAtCommandBuffer->AppendL( aCommand ); |
|
187 } |
|
188 |
|
189 // ---------------------------------------------------------------------------- |
|
190 // CDataPortWriter::GetAtBuffer |
|
191 // Returns iAtCommandBuffer. |
|
192 // (other items were commented in a header). |
|
193 // ---------------------------------------------------------------------------- |
|
194 // |
|
195 CArrayFixFlat<TUint>* CDataPortWriter::GetAtBuffer() |
|
196 { |
|
197 |
|
198 TFLOGSTRING("TSY: CDataPortWriter::GetAtBuffer"); |
|
199 OstTrace0( TRACE_NORMAL, CDATAPORTWRITER_GETATBUFFER, "CDataPortWriter::GetAtBuffer" ); |
|
200 |
|
201 return iAtCommandBuffer; |
|
202 } |
|
203 |
|
204 // ---------------------------------------------------------------------------- |
|
205 // CDataPortWriter::Write |
|
206 // Writes data into dataport. |
|
207 // (other items were commented in a header). |
|
208 // ---------------------------------------------------------------------------- |
|
209 // |
|
210 void CDataPortWriter::Write( |
|
211 const TDesC8& aData, |
|
212 TLastAtCommandSent aCommand ) |
|
213 { |
|
214 |
|
215 TFLOGSTRING("TSY: CDataPortWriter::Write"); |
|
216 OstTrace0( TRACE_NORMAL, CDATAPORTWRITER_WRITE, "CDataPortWriter::Write" ); |
|
217 |
|
218 // We are writing data so set the flag to ETrue. |
|
219 iContinueWrite = ETrue; |
|
220 |
|
221 #ifdef TF_LOGGING_ENABLED |
|
222 // If aData is longer than KDataBufLength, copy only KDataBufLength |
|
223 TBuf< KDataBufLength > data16bit; |
|
224 if ( KDataBufLength < aData.Length() ) |
|
225 { |
|
226 data16bit.Copy( aData.Left( KDataBufLength ) ); |
|
227 } |
|
228 else |
|
229 { |
|
230 data16bit.Copy( aData.Left( aData.Length() ) ); |
|
231 } |
|
232 |
|
233 TFLOGSTRING2("TSY: CDataPortWriter::Write - Stored into FIFO buffer: %S", &data16bit ); |
|
234 |
|
235 OstTraceExt1( TRACE_NORMAL, DUP1_CDATAPORTWRITER_WRITE, "CDataPortWriter::Write;Stored into FIFO buffer=%S", data16bit ); |
|
236 #endif // TF_LOGGING_ENABLED |
|
237 |
|
238 HBufC8* tmp = NULL; |
|
239 TInt commandError( KErrNone ); |
|
240 |
|
241 // Trap possible leave in AppendLs and AllocL. |
|
242 TRAPD( trapError, |
|
243 // Create tmp ptr for data, allocate heap and copy the aData parameter. |
|
244 tmp = aData.AllocL(); |
|
245 // Append the ptr into buffer |
|
246 iWriteBuffer->AppendL( tmp ); |
|
247 // Append AT command enum into buffer so that we know |
|
248 // what is the AT command. |
|
249 AppendCommandL( aCommand ) ); |
|
250 |
|
251 // Check if allocation and appends were succesful. |
|
252 if ( ( KErrNone == trapError ) && ( KErrNone == commandError ) ) |
|
253 { |
|
254 // If already sent data and pending for completition, continue to wait. |
|
255 // If the last write thas been already completed, write new data. |
|
256 if ( iWriteCompleted ) |
|
257 { |
|
258 // Write the data. |
|
259 iStatus = KRequestPending; |
|
260 iWriteCompleted = EFalse; |
|
261 |
|
262 // As iWriteBuffer->AppendL() can reorganise the iWriteBuffer, |
|
263 // we need to use a separate iDataToDPPtr with Write. |
|
264 // Otherwise it is possible that the data written before |
|
265 // new CDataPortWriter::Write is called has wrong address. |
|
266 iDataToDpPtr.Set( iWriteBuffer->At( 0 )->Left( |
|
267 iWriteBuffer->At( 0 )->Length() ) ); |
|
268 // Write the data to modem |
|
269 iDataPort.Write( iStatus, iDataToDpPtr ); |
|
270 // DO NOT DELETE ALLOCATED DATA FROM HEAP AS IT IS DONE IN RUNL |
|
271 |
|
272 #ifdef TF_LOGGING_ENABLED |
|
273 // If aData is longer than KDataBufLength, copy only KDataBufLength |
|
274 if ( KDataBufLength < aData.Length() ) |
|
275 { |
|
276 data16bit.Copy( iDataToDpPtr.Left( iDataToDpPtr.Length() ) ); |
|
277 } |
|
278 else |
|
279 { |
|
280 data16bit.Copy( aData.Left( aData.Length() ) ); |
|
281 } |
|
282 |
|
283 TFLOGSTRING2("TSY: CDataPortWriter::Write - From FIFO buffer: %S", &data16bit); |
|
284 |
|
285 OstTraceExt1( TRACE_NORMAL, DUP2_CDATAPORTWRITER_WRITE, "CDataPortWriter::Write;From FIFO buffer=%S", data16bit ); |
|
286 #endif // TF_LOGGING_ENABLED |
|
287 |
|
288 if ( !IsActive() ) |
|
289 { |
|
290 SetActive(); |
|
291 } |
|
292 //no else |
|
293 } |
|
294 //no else |
|
295 } |
|
296 |
|
297 // If TRAP caught error, call line to handle the error. |
|
298 else |
|
299 { |
|
300 // If AllocL or AppendL left for the actual data string, |
|
301 // delete tmp if it exists. |
|
302 if ( NULL != tmp ) |
|
303 { |
|
304 delete tmp; |
|
305 } |
|
306 |
|
307 // If AllocL or AppendL left, handle corresponding error. |
|
308 iDataPortHandler->HandleDataPortError( trapError ); |
|
309 } |
|
310 } |
|
311 |
|
312 // ---------------------------------------------------------------------------- |
|
313 // CDataPortWriter::RunL |
|
314 // Activates active object when request is completed. |
|
315 // (other items were commented in a header). |
|
316 // ---------------------------------------------------------------------------- |
|
317 // |
|
318 void CDataPortWriter::RunL() |
|
319 { |
|
320 |
|
321 TFLOGSTRING("TSY: CDataPortWriter::RunL"); |
|
322 OstTrace0( TRACE_NORMAL, CDATAPORTWRITER_RUNL, "CDataPortWriter::RunL" ); |
|
323 |
|
324 #ifdef TF_LOGGING_ENABLED |
|
325 |
|
326 TBuf< KDataBufLength > data16bit; |
|
327 data16bit.AppendNum( iStatus.Int() ); |
|
328 |
|
329 TFLOGSTRING2("TSY: CDataPortWriter::RunL - iStatus: %S", &data16bit); |
|
330 OstTrace1( TRACE_NORMAL, DUP2_CDATAPORTWRITER_RUNL, "CDataPortWriter::RunL;iStatus: %d", iStatus.Int() ); |
|
331 #endif // TF_LOGGING_ENABLED |
|
332 |
|
333 if ( KRequestPending != iStatus.Int() ) |
|
334 { |
|
335 // If write buffer has data, delete first element. |
|
336 if ( 0 < iWriteBuffer->Count() ) |
|
337 { |
|
338 |
|
339 #ifdef TF_LOGGING_ENABLED |
|
340 // If write buffer entry length is longer than KDataBufLength, |
|
341 // log only KDataBufLength bytes of data |
|
342 if ( KDataBufLength < iWriteBuffer->At( 0 )->Length() ) |
|
343 { |
|
344 data16bit.Copy( iWriteBuffer->At( 0 )-> |
|
345 Left( KDataBufLength ) ); |
|
346 } |
|
347 // Else log the whole buffer |
|
348 else |
|
349 { |
|
350 data16bit.Copy( iWriteBuffer->At( 0 )->Left( |
|
351 iWriteBuffer->At( 0 )->Length() ) ); |
|
352 } |
|
353 |
|
354 TFLOGSTRING2("TSY: CDataPortWriter::RunL - AT command deleted from FIFO buffer: %S", &data16bit); |
|
355 OstTraceExt1( TRACE_NORMAL, DUP1_CDATAPORTWRITER_RUNL, "CDataPortWriter::RunL;AT command deleted from FIFO buffer=%S", data16bit ); |
|
356 #endif // TF_LOGGING_ENABLED |
|
357 |
|
358 if ( iWriteBuffer->At( 0 ) ) |
|
359 { |
|
360 // Delete the data from heap |
|
361 delete iWriteBuffer->At( 0 ); |
|
362 iWriteBuffer->At( 0 ) = NULL; |
|
363 } |
|
364 //no else |
|
365 |
|
366 // Delete and compress the buffer |
|
367 iWriteBuffer->Delete( 0 ); |
|
368 iWriteBuffer->Compress(); |
|
369 // Leave if error, will fall back to RunError. |
|
370 User::LeaveIfError( iStatus.Int() ); |
|
371 } |
|
372 //no else |
|
373 } |
|
374 //no else |
|
375 } |
|
376 |
|
377 // ---------------------------------------------------------------------------- |
|
378 // CDataPortWriter::RunError |
|
379 // Called when RunL leaves. |
|
380 // (other items were commented in a header). |
|
381 // ---------------------------------------------------------------------------- |
|
382 // |
|
383 TInt CDataPortWriter::RunError( |
|
384 TInt aError ) |
|
385 { |
|
386 |
|
387 TFLOGSTRING2("TSY: CDataPortWriter::RunError %d", aError); |
|
388 OstTrace1( TRACE_NORMAL, CDATAPORTWRITER_RUNERROR, "CDataPortWriter::RunError;aError=%d", aError ); |
|
389 |
|
390 // Line object completes client requests in case of an error. |
|
391 iDataPortHandler->HandleDataPortError( aError ); |
|
392 // Cancel writes if active. |
|
393 Cancel(); |
|
394 // If write buffer has data, delete it. |
|
395 TInt count( iWriteBuffer->Count() ); |
|
396 |
|
397 if ( 0 < count ) |
|
398 { |
|
399 // Loop through each element and delete data from heap. |
|
400 for ( TInt i = 0; i < count; i++ ) |
|
401 { |
|
402 if ( iWriteBuffer->At( 0 ) ) |
|
403 { |
|
404 delete iWriteBuffer->At( 0 ); |
|
405 iWriteBuffer->At( 0 ) = NULL; |
|
406 } |
|
407 //no else |
|
408 } |
|
409 } |
|
410 //no else |
|
411 |
|
412 // Delete elements and compress buffer. |
|
413 iWriteBuffer->Delete( 0, iWriteBuffer->Count() ); |
|
414 iWriteBuffer->Compress(); |
|
415 |
|
416 return KErrNone; |
|
417 } |
|
418 |
|
419 // ---------------------------------------------------------------------------- |
|
420 // CDataPortWriter::WriteNextL |
|
421 // Writes next AT command from iWriteBuffer. |
|
422 // (other items were commented in a header). |
|
423 // ---------------------------------------------------------------------------- |
|
424 // |
|
425 void CDataPortWriter::WriteNextL() |
|
426 { |
|
427 |
|
428 TFLOGSTRING("TSY: CDataPortWriter::WriteNextL - Write next command from FIFO"); |
|
429 OstTrace0( TRACE_NORMAL, CDATAPORTWRITER_WRITENEXTL, "CDataPortWriter::WriteNextL, Write next command from FIFO" ); |
|
430 |
|
431 if ( !IsActive() ) |
|
432 { |
|
433 iWriteCompleted = ETrue; |
|
434 User::LeaveIfError( iStatus.Int() ); |
|
435 |
|
436 // Check if we have AT commands waiting in the buffer and if we are |
|
437 // still supposed to write commands |
|
438 if ( ( 0 < iWriteBuffer->Count() ) && |
|
439 ( EFalse != iContinueWrite ) ) |
|
440 { |
|
441 iWriteCompleted = EFalse; |
|
442 // As iWriteBuffer->AppendL() can reorganise the iWriteBuffer, |
|
443 // we need to use a separate iDataToDPPtr with Write. |
|
444 // Otherwise it is possible that the data written before |
|
445 // new CDataPortWriter::Write is called has wrong address |
|
446 // because of the AppendL(). |
|
447 iDataToDpPtr.Set( iWriteBuffer->At( 0 )->Left( |
|
448 iWriteBuffer->At( 0 )->Length() ) ); |
|
449 iDataPort.Write( iStatus, iDataToDpPtr ); |
|
450 |
|
451 #ifdef TF_LOGGING_ENABLED |
|
452 |
|
453 TBuf<KDataBufLength> data16bit; |
|
454 // If write buffer entry length is longer than KDataBufLength, |
|
455 // log only KDataBufLength bytes of data |
|
456 if ( KDataBufLength < iDataToDpPtr.Length() ) |
|
457 { |
|
458 data16bit.Copy( iDataToDpPtr.Left( KDataBufLength ) ); |
|
459 } |
|
460 else |
|
461 { |
|
462 data16bit.Copy( iDataToDpPtr.Left( iDataToDpPtr.Length() ) ); |
|
463 } |
|
464 |
|
465 TFLOGSTRING2("TSY: CDataPortWriter::WriteNextL - AT command: %S", &data16bit); |
|
466 |
|
467 OstTraceExt1( TRACE_NORMAL, DUP1_CDATAPORTWRITER_WRITENEXTL, "CDataPortWriter::WriteNextL;AT command=%S", data16bit ); |
|
468 #endif //TF_LOGGING_ENABLED |
|
469 |
|
470 // Set active as write is pending |
|
471 if ( !IsActive() ) |
|
472 { |
|
473 SetActive(); |
|
474 } |
|
475 //no else |
|
476 } |
|
477 //no else |
|
478 } |
|
479 //no else |
|
480 } |
|
481 |
|
482 // ---------------------------------------------------------------------------- |
|
483 // CDataPortWriter::DoCancel |
|
484 // Cancels active object request. |
|
485 // (other items were commented in a header). |
|
486 // ---------------------------------------------------------------------------- |
|
487 // |
|
488 void CDataPortWriter::DoCancel() |
|
489 { |
|
490 |
|
491 TFLOGSTRING("CDataPortWriter::DoCancel"); |
|
492 OstTrace0( TRACE_NORMAL, CDATAPORTWRITER_DOCANCEL, "CDataPortWriter::DoCancel" ); |
|
493 |
|
494 // Stop writing into DP |
|
495 iContinueWrite = EFalse; |
|
496 iDataPort.WriteCancel(); |
|
497 iWriteCompleted = ETrue; |
|
498 } |
|
499 |
|
500 // ---------------------------------------------------------------------------- |
|
501 // CDataPortWriter::BlockWrite |
|
502 // Blocks writing to dataport |
|
503 // (other items were commented in a header). |
|
504 // ---------------------------------------------------------------------------- |
|
505 // |
|
506 void CDataPortWriter::BlockWrite() |
|
507 { |
|
508 |
|
509 TFLOGSTRING("TSY: CDataPortWriter::BlockWrite - Blocking writes to DP"); |
|
510 OstTrace0( TRACE_NORMAL, CDATAPORTWRITER_BLOCKWRITE, "CDataPortWriter::BlockWrite" ); |
|
511 |
|
512 // Stop writing into DP until DP reader has flushed RX buffer |
|
513 iContinueWrite = EFalse; |
|
514 iWriteCompleted = EFalse; |
|
515 } |
|
516 |
|
517 // ---------------------------------------------------------------------------- |
|
518 // CDataPortReader::NewL |
|
519 // Two-phased constructor. |
|
520 // (other items were commented in a header). |
|
521 // ---------------------------------------------------------------------------- |
|
522 // |
|
523 CDataPortReader* CDataPortReader::NewL( |
|
524 CMmDataPortHandler* aDataPortHandler, |
|
525 const RComm& aDataPort, |
|
526 CDataPortWriter* aDataPortWriter ) |
|
527 { |
|
528 |
|
529 TFLOGSTRING("TSY: CDataPortReader::NewL"); |
|
530 OstTrace0( TRACE_NORMAL, CDATAPORTREADER_NEWL, "CDataPortReader::NewL" ); |
|
531 |
|
532 CDataPortReader* reader = new ( ELeave ) CDataPortReader(); |
|
533 CleanupStack::PushL( reader ); |
|
534 |
|
535 reader->iDataPortHandler = aDataPortHandler; |
|
536 reader->iDataPort = aDataPort; |
|
537 reader->iDataPortWriter = aDataPortWriter; |
|
538 |
|
539 CActiveScheduler::Add( reader ); |
|
540 |
|
541 CleanupStack::Pop( reader ); |
|
542 |
|
543 return reader; |
|
544 } |
|
545 |
|
546 // ---------------------------------------------------------------------------- |
|
547 // CDataPortReader::CDataPortReader |
|
548 // Dataport reader default constructor. |
|
549 // (other items were commented in a header). |
|
550 // ---------------------------------------------------------------------------- |
|
551 // |
|
552 CDataPortReader::CDataPortReader() |
|
553 : CActive( EPriorityStandard ) |
|
554 { |
|
555 |
|
556 TFLOGSTRING("TSY: CDataPortReader::CDataPortReader"); |
|
557 OstTrace0( TRACE_NORMAL, CDATAPORTREADER_CDATAPORTREADER, "CDataPortReader::CDataPortReader" ); |
|
558 |
|
559 // initialisation of meneber variables |
|
560 iModemInitComplete = EFalse; |
|
561 iContinueRead = ETrue; |
|
562 iReaAllComplete = ETrue; |
|
563 } |
|
564 |
|
565 // ----------------------------------------------------------------------------- |
|
566 // CDataPortReader::~CDataPortReader |
|
567 // Destructor, deletes all allocated resources. |
|
568 // ----------------------------------------------------------------------------- |
|
569 // |
|
570 CDataPortReader::~CDataPortReader() |
|
571 { |
|
572 |
|
573 TFLOGSTRING("TSY: CDataPortReader::~CDataPortReader"); |
|
574 OstTrace0( TRACE_NORMAL, DUP1_CDATAPORTREADER_CDATAPORTREADER, "CDataPortReader::~CDataPortReader" ); |
|
575 |
|
576 Cancel(); |
|
577 } |
|
578 |
|
579 // ---------------------------------------------------------------------------- |
|
580 // CDataPortReader::DoCancel |
|
581 // Cancels active object request. |
|
582 // (other items were commented in a header). |
|
583 // ---------------------------------------------------------------------------- |
|
584 // |
|
585 void CDataPortReader::DoCancel() |
|
586 { |
|
587 |
|
588 TFLOGSTRING("CDataPortReader::DoCancel"); |
|
589 OstTrace0( TRACE_NORMAL, CDATAPORTREADER_DOCANCEL, "CDataPortReader::DoCancel" ); |
|
590 |
|
591 // Stop reading from DP |
|
592 iContinueRead = EFalse; |
|
593 iDataPort.ReadCancel(); |
|
594 } |
|
595 |
|
596 // ---------------------------------------------------------------------------- |
|
597 // CDataPortReader::Read |
|
598 // Reads data from dataport. |
|
599 // (other items were commented in a header). |
|
600 // ---------------------------------------------------------------------------- |
|
601 // |
|
602 void CDataPortReader::Read() |
|
603 { |
|
604 |
|
605 TFLOGSTRING("TSY: CDataPortReader::Read Start reading"); |
|
606 OstTrace0( TRACE_NORMAL, CDATAPORTREADER_READ, "CDataPortReader::Read" ); |
|
607 |
|
608 iContinueRead = ETrue; |
|
609 // If already active, don't make a new request |
|
610 if ( !IsActive() ) |
|
611 { |
|
612 iResp.SetLength( 0 ); |
|
613 |
|
614 iDataPort.Read( iStatus, iResp ); |
|
615 SetActive(); |
|
616 } |
|
617 //no else |
|
618 } |
|
619 |
|
620 // ---------------------------------------------------------------------------- |
|
621 // CDataPortReader::ReadAll |
|
622 // Reads all data from dataport (flushing). |
|
623 // (other items were commented in a header). |
|
624 // ---------------------------------------------------------------------------- |
|
625 // |
|
626 void CDataPortReader::ReadAll() |
|
627 { |
|
628 |
|
629 TFLOGSTRING("TSY: CDataPortReader::ReadAll - Read all data from DP"); |
|
630 OstTrace0( TRACE_NORMAL, CDATAPORTREADER_READALL, "CDataPortReader::ReadAll, Read all data from DP" ); |
|
631 |
|
632 iContinueRead = ETrue; |
|
633 |
|
634 // First get remaining data length in DP |
|
635 TInt dataLen = iDataPort.QueryReceiveBuffer(); |
|
636 // If there is data remaining in RX buffer, read it all first. |
|
637 // If modem init is not yet done, then do not empty RX buffer |
|
638 // as line object is doing initialisations before first dial. |
|
639 if ( ( 0 < dataLen ) && ( EFalse != iModemInitComplete ) ) |
|
640 { |
|
641 |
|
642 TFLOGSTRING2("TSY: CDataPortReader::ReadAll - Data remaining: %d", |
|
643 dataLen ); |
|
644 OstTrace1( TRACE_NORMAL, DUP1_CDATAPORTREADER_READALL, "CDataPortReader::ReadAll;Data remaining=%d", dataLen ); |
|
645 // Block DP writer, so that it does not generate more |
|
646 // responses from modem. Continue when RX buffer is empty. |
|
647 iDataPortWriter->BlockWrite(); |
|
648 // Set read all complete flag to false |
|
649 iReaAllComplete = EFalse; |
|
650 // If already active, don't make a new request. Wait for RunL |
|
651 if ( !IsActive() ) |
|
652 { |
|
653 |
|
654 TFLOGSTRING("TSY: CDataPortReader::ReadAll - Starting to read remaining data (flushing)"); |
|
655 OstTrace0( TRACE_NORMAL, DUP2_CDATAPORTREADER_READALL, "CDataPortReader::ReadAll, Starting to read remaining data (flushing)" ); |
|
656 |
|
657 iResp.SetLength( 0 ); |
|
658 iDataPort.Read( iStatus, iResp ); |
|
659 SetActive(); |
|
660 } |
|
661 else |
|
662 { |
|
663 |
|
664 TFLOGSTRING("TSY: CDataPortReader::ReadAll - Read still pending!"); |
|
665 OstTrace0( TRACE_NORMAL, DUP3_CDATAPORTREADER_READALL, "CDataPortReader::ReadAll, Read still pending!" ); |
|
666 } |
|
667 } |
|
668 else |
|
669 { |
|
670 |
|
671 TFLOGSTRING("TSY: CDataPortReader::ReadAll - Init going or no data in RX"); |
|
672 OstTrace0( TRACE_NORMAL, DUP4_CDATAPORTREADER_READALL, "CDataPortReader::ReadAll, Init going or no data in RX" ); |
|
673 if ( 0 >= dataLen ) |
|
674 { |
|
675 // Set read all complete flag to true, there is no data waiting |
|
676 iReaAllComplete = ETrue; |
|
677 } |
|
678 //no else |
|
679 |
|
680 // Read data if not already |
|
681 if ( !IsActive() ) |
|
682 { |
|
683 |
|
684 TFLOGSTRING("TSY: CDataPortReader::ReadAll - Start normal reading"); |
|
685 OstTrace0( TRACE_NORMAL, DUP5_CDATAPORTREADER_READALL, "CDataPortReader::ReadAll, Start normal reading" ); |
|
686 |
|
687 iResp.SetLength( 0 ); |
|
688 iDataPort.Read( iStatus, iResp ); |
|
689 SetActive(); |
|
690 } |
|
691 //no else |
|
692 } |
|
693 } |
|
694 |
|
695 // ---------------------------------------------------------------------------- |
|
696 // CDataPortReader::ReadCancel |
|
697 // Cancels reading. |
|
698 // (other items were commented in a header). |
|
699 // ---------------------------------------------------------------------------- |
|
700 // |
|
701 void CDataPortReader::ReadCancel() |
|
702 { |
|
703 |
|
704 TFLOGSTRING("TSY: CDataPortReader::ReadCancel"); |
|
705 OstTrace0( TRACE_NORMAL, CDATAPORTREADER_READCANCEL, "CDataPortReader::ReadCancel" ); |
|
706 |
|
707 // Stop reading from DP |
|
708 iContinueRead = EFalse; |
|
709 iDataPort.ReadCancel(); |
|
710 } |
|
711 |
|
712 // ---------------------------------------------------------------------------- |
|
713 // CDataPortReader::ModemInitComplete |
|
714 // Called by line to inform DP reader that modem initialisation is completed. |
|
715 // (other items were commented in a header). |
|
716 // ---------------------------------------------------------------------------- |
|
717 // |
|
718 void CDataPortReader::ModemInitComplete() |
|
719 { |
|
720 |
|
721 TFLOGSTRING("TSY: CDataPortReader::ModemInitComplete"); |
|
722 OstTrace0( TRACE_NORMAL, CDATAPORTREADER_MODEMINITCOMPLETE, "CDataPortReader::ModemInitComplete" ); |
|
723 |
|
724 iModemInitComplete = ETrue; |
|
725 } |
|
726 |
|
727 // ---------------------------------------------------------------------------- |
|
728 // CDataPortReader::RunL |
|
729 // Activates active object when request is completed. |
|
730 // (other items were commented in a header). |
|
731 // ---------------------------------------------------------------------------- |
|
732 // |
|
733 void CDataPortReader::RunL() |
|
734 { |
|
735 |
|
736 TFLOGSTRING("TSY: CDataPortReader::RunL"); |
|
737 OstTrace0( TRACE_NORMAL, CDATAPORTREADER_RUNL, "CDataPortReader::RunL" ); |
|
738 |
|
739 #ifdef TF_LOGGING_ENABLED |
|
740 |
|
741 TBuf< KDataBufLength > data16bit; |
|
742 data16bit.AppendNum( iStatus.Int() ); |
|
743 |
|
744 TFLOGSTRING2("TSY: CDataPortReader::RunL - iStatus:%S", &data16bit); |
|
745 OstTrace1( TRACE_NORMAL, DUP1_CDATAPORTREADER_RUNL, "CDataPortReader::RunL;iStatus=%d", iStatus.Int() ); |
|
746 #endif // TF_LOGGING_ENABLED |
|
747 |
|
748 // KErrNone and KErrCancel are ok, others mean real error |
|
749 TInt ret( iStatus.Int() ); |
|
750 if ( KErrNone == ret || KErrCancel == ret ) |
|
751 { |
|
752 |
|
753 #ifdef TF_LOGGING_ENABLED |
|
754 data16bit.SetLength( 0 ); |
|
755 // If iResp lenght is more than KDataBufLength, |
|
756 // log only KDataBufLength bytes |
|
757 if ( KDataBufLength < iResp.Length() ) |
|
758 { |
|
759 data16bit.Copy( iResp.Left( KDataBufLength ) ); |
|
760 } |
|
761 else |
|
762 { |
|
763 data16bit.Copy( iResp.Left( iResp.Length() ) ); |
|
764 } |
|
765 const TDesC16 help = data16bit; |
|
766 TFLOGSTRING2("TSY: CDataPortReader::Read Data: %S", &data16bit); |
|
767 OstTraceExt1( TRACE_NORMAL, DUP2_CDATAPORTREADER_RUNL, "CDataPortReader::RunL;data16bit=%S", help ); |
|
768 #endif // TF_LOGGING_ENABLED |
|
769 |
|
770 // If flushing the dataport and modem from last connection, |
|
771 // continue until RX buffer is empty |
|
772 if ( EFalse == iReaAllComplete ) |
|
773 { |
|
774 // To ensure that NO CARRIER and +CRING (in case of waiting call) |
|
775 // responces are not missed. |
|
776 if ( 0 == iResp.MatchF( KModemNoCarrier ) || |
|
777 0 == iResp.MatchF( KModemCRing ) ) |
|
778 { |
|
779 iDataPortHandler->ReadResponseFromDataport( iResp ); |
|
780 } |
|
781 //no else |
|
782 |
|
783 TInt dataLen( iDataPort.QueryReceiveBuffer() ); |
|
784 // If there is data remaining in RX buffer, read it all first |
|
785 if ( 0 < dataLen ) |
|
786 { |
|
787 |
|
788 TFLOGSTRING2("TSY: CDataPortReader::RunL - Data remaining: %d", dataLen ); |
|
789 |
|
790 OstTrace1( TRACE_NORMAL, DUP3_CDATAPORTREADER_RUNL, "CDataPortReader::RunL;Data remaining=%d", dataLen ); |
|
791 } |
|
792 else |
|
793 { |
|
794 |
|
795 TFLOGSTRING("TSY: CDataPortReader::RunL - RX buffer empty, normal read continuing"); |
|
796 OstTrace0( TRACE_NORMAL, DUP4_CDATAPORTREADER_RUNL, "CDataPortReader::RunL, RX buffer empty, normal read continuing" ); |
|
797 |
|
798 iReaAllComplete = ETrue; |
|
799 // Request next write from iDataPortWriter |
|
800 iDataPortWriter->WriteNextL(); |
|
801 } |
|
802 // Set length to zero |
|
803 iResp.SetLength( 0 ); |
|
804 // Make the reader read again... |
|
805 iStatus = KRequestPending; |
|
806 iDataPort.Read( iStatus, iResp ); |
|
807 SetActive(); |
|
808 } |
|
809 // Normal read prosessing, forward data to line or call object |
|
810 else |
|
811 { |
|
812 // Check what is received from modem |
|
813 if ( 0 < iResp.Length() ) |
|
814 { |
|
815 // Skip over line changes and unnecessary data. |
|
816 // CR is in byte 0 and LF is in byte 1. |
|
817 if ( ( KMinModemRespLength < iResp.Length() ) && |
|
818 ( KCarriageReturn != iResp[0] ) && |
|
819 ( KLineFeed != iResp[1] ) ) |
|
820 { |
|
821 iDataPortHandler->ReadResponseFromDataport( iResp ); |
|
822 // If not echo data, send new commands. |
|
823 // Otherwise skip over |
|
824 if ( ( 0 > iResp.MatchF( KInitEcho ) ) ) |
|
825 { |
|
826 // Request next write from iDataPortWriter |
|
827 iDataPortWriter->WriteNextL(); |
|
828 } |
|
829 //no else |
|
830 } |
|
831 //no else |
|
832 |
|
833 // Set length to zero |
|
834 iResp.SetLength( 0 ); |
|
835 |
|
836 if ( EFalse == iContinueRead ) |
|
837 { |
|
838 |
|
839 TFLOGSTRING("TSY: CDataPortReader::RunL - Cancel reading"); |
|
840 OstTrace0( TRACE_NORMAL, DUP5_CDATAPORTREADER_RUNL, "CDataPortReader::RunL, Cancel reading" ); |
|
841 |
|
842 iDataPort.ReadCancel(); |
|
843 } |
|
844 else if ( !IsActive() ) |
|
845 { |
|
846 |
|
847 TFLOGSTRING("TSY: CDataPortReader::RunL - Continue reading"); |
|
848 OstTrace0( TRACE_NORMAL, DUP6_CDATAPORTREADER_RUNL, "CDataPortReader::RunL, Continue reading" ); |
|
849 // Make the reader read again... |
|
850 iStatus = KRequestPending; |
|
851 iDataPort.Read( iStatus, iResp ); |
|
852 SetActive(); |
|
853 } |
|
854 } |
|
855 else if ( !IsActive() && iContinueRead ) |
|
856 { |
|
857 |
|
858 TFLOGSTRING("TSY: CDataPortReader::RunL - Continue reading"); |
|
859 OstTrace0( TRACE_NORMAL, DUP7_CDATAPORTREADER_RUNL, "CDataPortReader::RunL, Continue reading" ); |
|
860 // Make the reader read again... |
|
861 iStatus = KRequestPending; |
|
862 iDataPort.Read( iStatus, iResp ); |
|
863 SetActive(); |
|
864 } |
|
865 } |
|
866 } |
|
867 // If in use, do no do anything but wait for others to |
|
868 // end using dataport. |
|
869 else if ( KErrInUse == ret ) |
|
870 { |
|
871 |
|
872 TFLOGSTRING("TSY: CDataPortReader::RunL - Dataport used by other client"); |
|
873 OstTrace0( TRACE_NORMAL, DUP8_CDATAPORTREADER_RUNL, "CDataPortReader::RunL, Dataport used by other client" ); |
|
874 } |
|
875 // These will make the next call object creation fail in |
|
876 // CMmLineTsy::OpenNewObjectL as we can't handle these errors in TSY. |
|
877 else |
|
878 { |
|
879 User::LeaveIfError( ret ); |
|
880 } |
|
881 } |
|
882 |
|
883 // ---------------------------------------------------------------------------- |
|
884 // CDataPortReader::RunError |
|
885 // Called when RunL leaves. |
|
886 // (other items were commented in a header). |
|
887 // ---------------------------------------------------------------------------- |
|
888 // |
|
889 TInt CDataPortReader::RunError( |
|
890 TInt aError ) |
|
891 { |
|
892 |
|
893 TFLOGSTRING2("TSY: CDataPortReader::RunError %d", aError); |
|
894 OstTrace1( TRACE_NORMAL, CDATAPORTREADER_RUNERROR, "CDataPortReader::RunError;aError=%d", aError ); |
|
895 |
|
896 iDataPortHandler->HandleDataPortError( aError ); |
|
897 |
|
898 return KErrNone; |
|
899 } |
|
900 |
|
901 //============================================================================= |
|
902 |
|
903 // OTHER EXPORTED FUNCTIONS |
|
904 //none |
|
905 |
|
906 // End of File |