Update contrib.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
18 #include "T_RBusDevCommData.h"
19 #include "T_TCommCapsV01Data.h"
20 #include "T_TCommConfigV01Data.h"
25 _LIT(KCmdConstructor, "new");
26 _LIT(KCmdDestructor, "~");
27 _LIT(KCmdBreak, "Break");
28 _LIT(KCmdBreakCancel, "BreakCancel");
29 _LIT(KCmdCaps, "Caps");
30 _LIT(KCmdConfig, "Config");
31 _LIT(KCmdMinTurnaroundTime, "MinTurnaroundTime");
32 _LIT(KCmdNotifyReceiveDataAvailable, "NotifyReceiveDataAvailable");
33 _LIT(KCmdNotifyReceiveDataAvailableCancel, "NotifyReceiveDataAvailableCancel");
34 _LIT(KCmdNotifySignalChange, "NotifySignalChange");
35 _LIT(KCmdNotifySignalChangeCancel, "NotifySignalChangeCancel");
36 _LIT(KCmdOpen, "Open");
37 _LIT(KCmdQueryReceiveBuffer, "QueryReceiveBuffer");
38 _LIT(KCmdRead, "Read");
39 _LIT(KCmdReadCancel, "ReadCancel");
40 _LIT(KCmdReadOneOrMore, "ReadOneOrMore");
41 _LIT(KCmdReceiveBufferLength, "ReceiveBufferLength");
42 _LIT(KCmdResetBuffers, "ResetBuffers");
43 _LIT(KCmdSetConfig, "SetConfig");
44 _LIT(KCmdSetMinTurnaroundTime, "SetMinTurnaroundTime");
45 _LIT(KCmdSetReceiveBufferLength, "SetReceiveBufferLength");
46 _LIT(KCmdSetSignals, "SetSignals");
47 _LIT(KCmdSignals, "Signals");
48 _LIT(KCmdVersionRequired, "VersionRequired");
49 _LIT(KCmdWrite, "Write");
50 _LIT(KCmdWriteCancel, "WriteCancel");
52 _LIT(KFldBufferLength, "bufferlength");
53 _LIT(KFldCaps, "caps");
54 _LIT(KFldClearMask, "clearmask");
55 _LIT(KFldConfig, "config");
56 _LIT(KFldData, "data");
57 _LIT(KFldExpected, "expected");
58 _LIT(KFldExpectedFile, "expected_file");
59 _LIT(KFldFile, "file");
60 _LIT(KFldIsEmpty, "is_empty");
61 _LIT(KFldMask, "mask");
62 _LIT(KFldPortPDD, "portpdd");
63 _LIT(KFldPortLDD, "portldd");
64 _LIT(KFldRepeat, "repeat");
65 _LIT(KFldSave, "save");
66 _LIT(KFldSetMask, "setmask");
67 _LIT(KFldTime, "time");
68 _LIT(KFldTimeOut, "timeout");
69 _LIT(KFldUnit, "unit");
70 _LIT(KFldUseLength, "uselength");
71 _LIT(KFldValue, "value");
72 _LIT(KFldVersionName, "version_name");
73 _LIT(KFldVersionBuild, "version_build");
74 _LIT(KFldVersionMajor, "version_major");
75 _LIT(KFldVersionMinor, "version_minor");
77 _LIT(KLogError, "Error=%d");
78 _LIT(KLogErrorBufferLength, "Buffer Length %d must be greater than 0");
79 _LIT(KLogErrorExpectedValue, "Expected Value does not match actual");
80 _LIT(KLogErrorExpectedSignal, "Expected Signal %d does not match actual %d");
81 _LIT(KLogMissingParameter, "Missing parameter '%S'");
82 _LIT(KLogNullCapsData, "Caps Data - '%S' is NULL");
83 _LIT(KLogNullConfigData, "Config Data - '%S' is NULL");
84 _LIT(KLogLoadPhysicalDeviceError, "Load Physical Device '%S' error=%d");
85 _LIT(KLogLoadLogicalDeviceError, "Load Logical Device '%S' error=%d");
88 _LIT(KStrKSignalCTS, "KSignalCTS");
89 _LIT(KStrKSignalDSR, "KSignalDSR");
90 _LIT(KStrKSignalDCD, "KSignalDCD");
91 _LIT(KStrKSignalRNG, "KSignalRNG");
92 _LIT(KStrKSignalRTS, "KSignalRTS");
93 _LIT(KStrKSignalDTR, "KSignalDTR");
94 _LIT(KStrKSignalBreak, "KSignalBreak");
95 const CDataWrapperBase::TEnumEntryTable CT_RBusDevCommData::iEnumTableSignals[] =
97 // Enum as a descriptor Enum
98 KStrKSignalCTS, KSignalCTS,
99 KStrKSignalDSR, KSignalDSR,
100 KStrKSignalDCD, KSignalDCD,
101 KStrKSignalRNG, KSignalRNG,
102 KStrKSignalRTS, KSignalRTS,
103 KStrKSignalDTR, KSignalDTR,
104 KStrKSignalBreak, KSignalBreak,
108 //////////////////////////////////////////////////////////////////////
109 // Construction/Destruction
110 //////////////////////////////////////////////////////////////////////
112 CT_RBusDevCommData* CT_RBusDevCommData::NewL()
114 CT_RBusDevCommData* ret=new (ELeave) CT_RBusDevCommData();
115 CleanupStack::PushL(ret);
117 CleanupStack::Pop(ret);
121 CT_RBusDevCommData::CT_RBusDevCommData()
122 : CT_RBusLogicalChannelData()
125 , iBufferReadPtr(NULL, 0)
126 , iBufferReadOneOrMorePtr(NULL, 0)
127 , iReadOneOrMoreLeft(0)
128 , iHasReadExpected(EFalse)
130 , iMinTurnaroundTime(0)
131 , iReceiveBufferLength(0)
134 , iHasNotifySignalsExpected(EFalse)
135 , iNotifySignalsExpected(0)
136 , iCallbackBreak(NULL)
137 , iCallbackNotifyReceiveDataAvailable(NULL)
138 , iCallbackNotifySignalChange(NULL)
139 , iCallbackRead(NULL)
140 , iCallbackReadOneOrMore(NULL)
141 , iCallbackWrite(NULL)
145 CT_RBusDevCommData::~CT_RBusDevCommData()
155 delete iCallbackWrite;
158 delete iCallbackReadOneOrMore;
159 iCallbackReadOneOrMore=NULL;
161 delete iCallbackRead;
164 delete iCallbackNotifySignalChange;
165 iCallbackNotifySignalChange=NULL;
167 delete iCallbackNotifyReceiveDataAvailable;
168 iCallbackNotifyReceiveDataAvailable=NULL;
170 delete iCallbackBreak;
174 void CT_RBusDevCommData::ConstructL()
176 iCallbackBreak =CActiveCallbackBase::NewL(*this);
177 iCallbackNotifyReceiveDataAvailable =CActiveCallbackBase::NewL(*this);
178 iCallbackNotifySignalChange =CActiveCallbackBase::NewL(*this);
179 iCallbackRead =CT_ActiveCallbackIO::NewL(*this);
180 iCallbackReadOneOrMore =CT_ActiveCallbackIO::NewL(*this);
181 iCallbackWrite =CT_ActiveCallbackIO::NewL(*this);
184 void CT_RBusDevCommData::DestroyData()
190 TAny* CT_RBusDevCommData::GetObject()
192 * Return a pointer to the object that the data wraps
194 * @return pointer to the object that the data wraps
200 RHandleBase* CT_RBusDevCommData::GetHandleBase()
205 RBusLogicalChannel* CT_RBusDevCommData::GetBusLogicalChannel()
210 void CT_RBusDevCommData::PrepareReadExpectedBufferLengthL(CT_ActiveCallbackIO& aCallback, const TDesC& aSection)
213 GetIntFromConfig(aSection, KFldRepeat, repeat);
216 iHasReadExpected=GetStringFromConfig(aSection, KFldExpected, readExpected);
217 if ( iHasReadExpected )
219 aCallback.PrepareFromStringL(repeat, readExpected);
220 iBufferLength=aCallback.BufferLength();
224 iHasReadExpected=GetStringFromConfig(aSection, KFldExpectedFile, readExpected);
225 if ( iHasReadExpected )
227 aCallback.PrepareFromFileL(repeat, readExpected);
231 if ( iHasReadExpected )
233 iBufferLength=aCallback.BufferLength();
236 GetIntFromConfig(aSection, KFldBufferLength, iBufferLength);
237 if ( iBufferLength <= 0 )
239 ERR_PRINTF2(KLogErrorBufferLength, iBufferLength);
240 SetBlockResult(EFail);
244 TBool CT_RBusDevCommData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
246 * Process a command read from the ini file
248 * @param aCommand The command to process
249 * @param aSection The section in the ini containing data for the command
250 * @param aAsyncErrorIndex Command index for async calls to return errors to
252 * @return ETrue if the command is processed
254 * @leave System wide error
260 if ( aCommand==KCmdConstructor )
262 err=DoCmdConstructor();
264 else if ( aCommand==KCmdDestructor )
268 else if ( aCommand==KCmdBreak )
270 DoCmdBreak(aSection, aAsyncErrorIndex);
272 else if ( aCommand==KCmdBreakCancel )
276 else if ( aCommand==KCmdCaps )
278 DoCmdCapsL(aSection);
280 else if ( aCommand==KCmdConfig )
282 DoCmdConfigL(aSection);
284 else if ( aCommand==KCmdMinTurnaroundTime )
286 DoCmdMinTurnaroundTime(aSection);
288 else if ( aCommand==KCmdNotifyReceiveDataAvailable )
290 DoCmdNotifyReceiveDataAvailable(aSection, aAsyncErrorIndex);
292 else if ( aCommand==KCmdNotifyReceiveDataAvailableCancel )
294 DoCmdNotifyReceiveDataAvailableCancel();
296 else if ( aCommand==KCmdNotifySignalChange )
298 DoCmdNotifySignalChange(aSection, aAsyncErrorIndex);
300 else if ( aCommand==KCmdNotifySignalChangeCancel )
302 DoCmdNotifySignalChangeCancel();
304 else if ( aCommand==KCmdOpen )
306 err=DoCmdOpen(aSection);
308 else if ( aCommand==KCmdQueryReceiveBuffer )
310 err=DoCmdQueryReceiveBuffer(aSection);
312 else if ( aCommand==KCmdRead )
314 DoCmdReadL(aSection, aAsyncErrorIndex);
316 else if ( aCommand==KCmdReadCancel )
320 else if ( aCommand==KCmdReadOneOrMore )
322 DoCmdReadOneOrMoreL(aSection, aAsyncErrorIndex);
324 else if ( aCommand==KCmdReceiveBufferLength )
326 DoCmdReceiveBufferLength(aSection);
328 else if ( aCommand==KCmdResetBuffers )
332 else if ( aCommand==KCmdSetConfig )
334 err=DoCmdSetConfigL(aSection);
336 else if ( aCommand==KCmdSetMinTurnaroundTime )
338 err=DoCmdSetMinTurnaroundTime(aSection);
340 else if ( aCommand==KCmdSetReceiveBufferLength )
342 err=DoCmdSetReceiveBufferLength(aSection);
344 else if ( aCommand==KCmdSetSignals )
346 DoCmdSetSignals(aSection);
348 else if ( aCommand==KCmdSignals )
350 DoCmdSignals(aSection);
352 else if ( aCommand==KCmdVersionRequired )
354 DoCmdVersionRequired(aSection);
356 else if ( aCommand==KCmdWrite )
358 DoCmdWriteL(aSection, aAsyncErrorIndex);
360 else if ( aCommand==KCmdWriteCancel )
366 ret=CT_RBusLogicalChannelData::DoCommandL(aCommand, aSection, aAsyncErrorIndex);
371 ERR_PRINTF2(KLogError, err);
378 TInt CT_RBusDevCommData::DoCmdConstructor()
381 TRAPD(err, iBusDevComm=new (ELeave) RBusDevComm());
385 void CT_RBusDevCommData::DoCmdDestructor()
390 void CT_RBusDevCommData::DoCmdBreak(const TDesC& aSection, const TInt aAsyncErrorIndex)
393 GetIntFromConfig(aSection, KFldTimeOut, timeOut);
396 if ( !GetIntFromConfig(aSection, KFldTime, time) )
398 ERR_PRINTF2(KLogMissingParameter, &KFldTime());
399 SetBlockResult(EFail);
403 INFO_PRINTF1(_L("Break"));
404 iBusDevComm->Break(iCallbackBreak->iStatus, time);
405 iCallbackBreak->Activate(aAsyncErrorIndex, timeOut);
410 void CT_RBusDevCommData::DoCmdBreakCancel()
412 INFO_PRINTF1(_L("BreakCancel"));
413 iBusDevComm->BreakCancel();
416 void CT_RBusDevCommData::DoCmdCapsL(const TDesC& aSection)
419 if ( GetStringFromConfig(aSection, KFldCaps, dataName) )
421 CT_TCommCapsV01Data* wrapper=static_cast<CT_TCommCapsV01Data*>(GetDataWrapperL(dataName));
422 TDes8* data=wrapper->Descriptor();
425 INFO_PRINTF1(_L("Caps"));
426 iBusDevComm->Caps(*data);
430 ERR_PRINTF2(KLogNullCapsData, &dataName);
431 SetBlockResult(EFail);
436 ERR_PRINTF2(KLogMissingParameter, &KFldCaps());
437 SetBlockResult(EFail);
441 void CT_RBusDevCommData::DoCmdConfigL(const TDesC& aSection)
444 if ( GetStringFromConfig(aSection, KFldConfig, dataName) )
446 CT_TCommConfigV01Data* wrapper=static_cast<CT_TCommConfigV01Data*>(GetDataWrapperL(dataName));
447 TDes8* data=wrapper->Descriptor();
450 INFO_PRINTF1(_L("Config"));
451 iBusDevComm->Config(*data);
455 ERR_PRINTF2(KLogNullConfigData, &dataName);
456 SetBlockResult(EFail);
461 ERR_PRINTF2(KLogMissingParameter, &KFldConfig());
462 SetBlockResult(EFail);
466 void CT_RBusDevCommData::DoCmdMinTurnaroundTime(const TDesC& aSection)
468 TUint actual=iBusDevComm->MinTurnaroundTime();
469 INFO_PRINTF2(_L("MinTurnaroundTime : %d"), actual);
472 if ( GetUintFromConfig(aSection, KFldExpected(), expected) )
474 if ( expected!=actual )
476 ERR_PRINTF1(KLogErrorExpectedValue);
477 SetBlockResult(EFail);
482 GetBoolFromConfig(aSection, KFldSave(), save);
485 iMinTurnaroundTime=actual;
489 void CT_RBusDevCommData::DoCmdNotifyReceiveDataAvailable(const TDesC& aSection, const TInt aAsyncErrorIndex)
492 GetIntFromConfig(aSection, KFldTimeOut, timeOut);
494 INFO_PRINTF1(_L("NotifyReceiveDataAvailable"));
495 iBusDevComm->NotifyReceiveDataAvailable(iCallbackNotifyReceiveDataAvailable->iStatus);
496 iCallbackNotifyReceiveDataAvailable->Activate(aAsyncErrorIndex, timeOut);
500 void CT_RBusDevCommData::DoCmdNotifyReceiveDataAvailableCancel()
502 INFO_PRINTF1(_L("NotifyReceiveDataAvailableCancel"));
503 iBusDevComm->NotifyReceiveDataAvailableCancel();
506 void CT_RBusDevCommData::DoCmdNotifySignalChange(const TDesC& aSection, const TInt aAsyncErrorIndex)
509 GetIntFromConfig(aSection, KFldTimeOut, timeOut);
511 iHasNotifySignalsExpected=GetOrFromConfig(aSection, KFldExpected(), iEnumTableSignals, iNotifySignalsExpected);
514 if ( GetOrFromConfig(aSection, KFldMask(), iEnumTableSignals, mask) )
516 INFO_PRINTF1(_L("NotifySignalChange with mask"));
517 iBusDevComm->NotifySignalChange(iCallbackNotifySignalChange->iStatus, iNotifySignals, mask);
521 INFO_PRINTF1(_L("NotifySignalChange without mask"));
522 iBusDevComm->NotifySignalChange(iCallbackNotifySignalChange->iStatus, iNotifySignals);
524 iCallbackNotifySignalChange->Activate(aAsyncErrorIndex, timeOut);
528 void CT_RBusDevCommData::DoCmdNotifySignalChangeCancel()
530 INFO_PRINTF1(_L("NotifySignalChangeCancel"));
531 iBusDevComm->NotifySignalChangeCancel();
534 TInt CT_RBusDevCommData::DoCmdOpen(const TDesC& aSection)
539 if ( GetStringFromConfig(aSection, KFldPortPDD, pdd) && pdd.Length()!=0 )
541 TInt errLoad=User::LoadPhysicalDevice(pdd);
542 if ( (errLoad!=KErrNone) && (errLoad!=KErrAlreadyExists) )
545 ERR_PRINTF3(KLogLoadPhysicalDeviceError, &pdd, errLoad);
546 SetBlockResult(EFail);
551 if ( GetStringFromConfig(aSection, KFldPortLDD, ldd) && ldd.Length()!=0 )
553 TInt errLoad=User::LoadLogicalDevice(ldd);
554 if ( (errLoad!=KErrNone) && (errLoad!=KErrAlreadyExists) )
557 ERR_PRINTF3(KLogLoadLogicalDeviceError, &ldd, errLoad);
558 SetBlockResult(EFail);
563 if ( !GetIntFromConfig(aSection, KFldUnit, unit) )
566 ERR_PRINTF2(KLogMissingParameter, &KFldUnit());
567 SetBlockResult(EFail);
573 INFO_PRINTF1(_L("Open"));
574 err=iBusDevComm->Open(unit);
580 TInt CT_RBusDevCommData::DoCmdQueryReceiveBuffer(const TDesC& aSection)
582 INFO_PRINTF1(_L("QueryReceiveBuffer"));
583 TInt actual=iBusDevComm->QueryReceiveBuffer();
592 if ( GetIntFromConfig(aSection, KFldExpected(), expected) )
594 if ( expected!=actual )
596 ERR_PRINTF1(KLogErrorExpectedValue);
597 SetBlockResult(EFail);
602 if ( GetBoolFromConfig(aSection, KFldIsEmpty(), isEmpty) )
608 ERR_PRINTF1(KLogErrorExpectedValue);
609 SetBlockResult(EFail);
616 ERR_PRINTF1(KLogErrorExpectedValue);
617 SetBlockResult(EFail);
623 GetBoolFromConfig(aSection, KFldSave(), save);
626 iBufferLength=actual;
633 void CT_RBusDevCommData::DoCmdReadL(const TDesC& aSection, const TInt aAsyncErrorIndex)
636 GetIntFromConfig(aSection, KFldTimeOut, timeOut);
638 TBool useLength=EFalse;
639 GetBoolFromConfig(aSection, KFldUseLength(), useLength);
641 PrepareReadExpectedBufferLengthL(*iCallbackRead, aSection);
642 if ( iBufferLength>0 )
645 iBufferRead=HBufC8::New(iBufferLength);
647 iBufferReadPtr.Set(iBufferRead->Des());
650 INFO_PRINTF2(_L("Read with length %d"), iBufferLength);
651 iBusDevComm->Read(iCallbackRead->iStatus, iBufferReadPtr, iBufferLength);
655 INFO_PRINTF1(_L("Read without length"));
656 iBusDevComm->Read(iCallbackRead->iStatus, iBufferReadPtr);
658 iCallbackRead->Activate(aAsyncErrorIndex, timeOut);
663 void CT_RBusDevCommData::DoCmdReadCancel()
665 INFO_PRINTF1(_L("ReadCancel"));
666 iBusDevComm->ReadCancel();
669 void CT_RBusDevCommData::DoCmdReadOneOrMoreL(const TDesC& aSection, const TInt aAsyncErrorIndex)
672 GetIntFromConfig(aSection, KFldTimeOut, timeOut);
674 PrepareReadExpectedBufferLengthL(*iCallbackReadOneOrMore, aSection);
675 if ( iBufferLength>0 )
678 iBufferRead=HBufC8::New(iBufferLength);
680 iBufferReadPtr.Set(iBufferRead->Des());
681 iBufferReadPtr.SetLength(iBufferLength);
682 iBufferReadOneOrMorePtr.Set(iBufferRead->Des());
683 iBufferReadOneOrMorePtr.SetLength(iBufferLength);
684 iReadOneOrMoreLeft=iBufferLength;
685 INFO_PRINTF2(_L("iBufferLength=%d"), iBufferLength);
686 INFO_PRINTF2(_L("iBufferRead->MaxLength=%d"), iBufferRead->Des().MaxLength());
687 INFO_PRINTF2(_L("iBufferReadPtr.Length=%d"), iBufferReadPtr.Length());
688 INFO_PRINTF2(_L("iBufferReadPtr.MaxLength=%d"), iBufferReadPtr.MaxLength());
689 INFO_PRINTF1(_L("ReadOneOrMore"));
690 iBusDevComm->ReadOneOrMore(iCallbackReadOneOrMore->iStatus, iBufferReadPtr);
691 iCallbackReadOneOrMore->Activate(aAsyncErrorIndex, timeOut);
696 void CT_RBusDevCommData::DoCmdReceiveBufferLength(const TDesC& aSection)
698 TInt actual=iBusDevComm->ReceiveBufferLength();
699 INFO_PRINTF2(_L("ReceiveBufferLength : %d"), actual);
702 if ( GetIntFromConfig(aSection, KFldExpected(), expected) )
704 if ( expected!=actual )
706 ERR_PRINTF1(KLogErrorExpectedValue);
707 SetBlockResult(EFail);
712 GetBoolFromConfig(aSection, KFldSave(), save);
715 iReceiveBufferLength=actual;
719 void CT_RBusDevCommData::DoCmdResetBuffers()
721 INFO_PRINTF1(_L("ResetBuffers"));
722 iBusDevComm->ResetBuffers();
725 TInt CT_RBusDevCommData::DoCmdSetConfigL(const TDesC& aSection)
730 if ( GetStringFromConfig(aSection, KFldConfig, dataName) )
732 CT_TCommConfigV01Data* wrapper=static_cast<CT_TCommConfigV01Data*>(GetDataWrapperL(dataName));
733 TDes8* data=wrapper->Descriptor();
736 INFO_PRINTF1(_L("SetConfig"));
737 ret=iBusDevComm->SetConfig(*data);
741 ERR_PRINTF2(KLogNullConfigData, &dataName);
742 SetBlockResult(EFail);
747 ERR_PRINTF2(KLogMissingParameter, &KFldConfig());
748 SetBlockResult(EFail);
754 TInt CT_RBusDevCommData::DoCmdSetMinTurnaroundTime(const TDesC& aSection)
756 TUint value=iMinTurnaroundTime;
757 GetUintFromConfig(aSection, KFldValue(), value);
759 INFO_PRINTF1(_L("SetMinTurnaroundTime"));
760 return iBusDevComm->SetMinTurnaroundTime(value);
763 TInt CT_RBusDevCommData::DoCmdSetReceiveBufferLength(const TDesC& aSection)
765 TInt value=iReceiveBufferLength;
766 GetIntFromConfig(aSection, KFldValue(), value);
768 INFO_PRINTF1(_L("SetReceiveBufferLength"));
769 return iBusDevComm->SetReceiveBufferLength(value);
772 void CT_RBusDevCommData::DoCmdSetSignals(const TDesC& aSection)
774 TUint setMask=iSignals;
775 GetOrFromConfig(aSection, KFldSetMask(), iEnumTableSignals, setMask);
777 TUint clearMask=~setMask;
778 GetOrFromConfig(aSection, KFldClearMask(), iEnumTableSignals, clearMask);
780 INFO_PRINTF1(_L("SetSignals"));
781 iBusDevComm->SetSignals(setMask, clearMask);
784 void CT_RBusDevCommData::DoCmdSignals(const TDesC& aSection)
786 TUint actual=iBusDevComm->Signals();
787 INFO_PRINTF2(_L("Signals:0x%x"), actual);
790 if ( GetOrFromConfig(aSection, KFldExpected(), iEnumTableSignals, expected) )
792 if ( expected!=actual )
794 ERR_PRINTF1(KLogErrorExpectedValue);
795 SetBlockResult(EFail);
800 GetBoolFromConfig(aSection, KFldSave(), save);
807 void CT_RBusDevCommData::DoCmdVersionRequired(const TDesC& aSection)
809 TVersion version=iBusDevComm->VersionRequired();
810 TBuf<KMaxVersionName> versionName(version.Name());
812 INFO_PRINTF2(_L("Version name : %S"), &versionName);
813 INFO_PRINTF2(_L("Version build : %d"), (TInt)version.iBuild);
814 INFO_PRINTF2(_L("Version major : %d"), (TInt)version.iMajor);
815 INFO_PRINTF2(_L("Version minor : %d"), (TInt)version.iMinor);
817 TPtrC expectedVersionName;
818 if( GetStringFromConfig(aSection, KFldVersionName(), expectedVersionName) )
820 if( version.Name() != expectedVersionName )
822 ERR_PRINTF3(_L("Expected Version Name (%S) != Actual Version Name (%S)"), &expectedVersionName, &versionName);
823 SetBlockResult(EFail);
828 if( GetIntFromConfig(aSection, KFldVersionBuild(), intTemp) )
830 if( version.iBuild != intTemp )
832 ERR_PRINTF3(_L("Expected Version Build (%d) != Actual Version Build (%d)"), intTemp, version.iBuild);
833 SetBlockResult(EFail);
837 if( GetIntFromConfig(aSection, KFldVersionMajor(), intTemp) )
839 if( version.iMajor != intTemp )
841 ERR_PRINTF3(_L("Expected Version Major (%d) != Actual Version Major (%d)"), intTemp, version.iMajor);
842 SetBlockResult(EFail);
846 if( GetIntFromConfig(aSection, KFldVersionMinor(), intTemp) )
848 if( version.iMinor != intTemp )
850 ERR_PRINTF3(_L("Expected Version Minor (%d) != Actual Version Minor (%d)"), intTemp, version.iMinor);
851 SetBlockResult(EFail);
855 if (version.Name() == _L("") && version.iBuild == 0 && version.iMajor == 0 && version.iMinor == 0)
857 ERR_PRINTF1(_L("Some version fields are not set!"));
858 SetBlockResult(EFail);
862 void CT_RBusDevCommData::DoCmdWriteL(const TDesC& aSection, const TInt aAsyncErrorIndex)
865 TBool useLength=EFalse;
866 GetBoolFromConfig(aSection, KFldUseLength(), useLength);
869 GetIntFromConfig(aSection, KFldTimeOut, timeOut);
872 GetIntFromConfig(aSection, KFldRepeat, repeat);
875 if ( GetStringFromConfig(aSection, KFldData, data) )
877 iCallbackWrite->PrepareFromStringL(repeat, data);
881 if ( GetStringFromConfig(aSection, KFldFile, data) )
883 iCallbackWrite->PrepareFromFileL(repeat, data);
888 ERR_PRINTF2(KLogMissingParameter, &KFldData);
889 ERR_PRINTF2(KLogMissingParameter, &KFldFile);
890 SetBlockResult(EFail);
896 iBufferLength=iCallbackWrite->BufferLength();
900 INFO_PRINTF2(_L("Write with length %d"), iBufferLength);
901 iBusDevComm->Write(iCallbackWrite->iStatus, iCallbackWrite->Buffer(), iBufferLength);
905 INFO_PRINTF1(_L("Write without length"));
906 iBusDevComm->Write(iCallbackWrite->iStatus, iCallbackWrite->Buffer());
908 iCallbackWrite->Activate(aAsyncErrorIndex, timeOut);
913 void CT_RBusDevCommData::DoCmdWriteCancel()
915 INFO_PRINTF1(_L("WriteCancel"));
916 iBusDevComm->WriteCancel();
919 void CT_RBusDevCommData::RunL(CActive* aActive, TInt aIndex)
921 Virtual RunL - Called on completion of an asynchronous command
923 @see MTPActiveCallback
924 @param aActive Active Object that RunL has been called on
927 @leave system wide error code
930 TBool activeOk=ETrue;
935 err=aActive->iStatus.Int();
938 if ( aActive==iCallbackRead )
940 iCallbackRead->KillTimer();
941 INFO_PRINTF1(_L("RunL: Read()"));
945 TInt length=iBufferReadPtr.Length();
946 HBufC* bufferRead=HBufC::NewLC(length);
947 bufferRead->Des().Copy(iBufferReadPtr);
948 INFO_PRINTF2(_L("Received Data Length:%d"), length);
949 if ( iHasReadExpected )
951 const TDesC8& expectedBuffer=iCallbackRead->Buffer();
952 if ( expectedBuffer.Match(iBufferReadPtr)!=0 )
954 for ( TInt index=0; index<length; ++index )
956 const TUint8& actual=(*iBufferRead)[index];
957 const TUint8& expected=expectedBuffer[index];
958 if ( actual!=expected )
960 ERR_PRINTF4(_L("Index:%d Read:%d Expected:%d"), index, (TInt)actual, (TInt)expected);
961 SetBlockResult(EFail);
966 CleanupStack::PopAndDestroy(bufferRead);
969 else if ( aActive==iCallbackReadOneOrMore )
971 INFO_PRINTF1(_L("RunL: ReadOneOrMore()"));
975 TInt length=iBufferReadPtr.Length();
976 if ( iReadOneOrMoreLeft!=length )
978 iBufferReadPtr.SetLength(iReadOneOrMoreLeft);
979 iReadOneOrMoreLeft-=length;
980 INFO_PRINTF2(_L("iReadOneOrMoreLeft:%d"), iReadOneOrMoreLeft);
981 iBufferReadPtr.Set(iBufferReadPtr.RightTPtr(iReadOneOrMoreLeft));
982 iBufferReadPtr.SetLength(iReadOneOrMoreLeft);
983 INFO_PRINTF1(_L("ReadOneOrMore"));
984 iBusDevComm->ReadOneOrMore(iCallbackReadOneOrMore->iStatus, iBufferReadPtr);
985 iCallbackReadOneOrMore->Activate(aIndex);
990 iCallbackReadOneOrMore->KillTimer();
991 HBufC* bufferRead=HBufC::NewLC(iBufferLength);
992 bufferRead->Des().Copy(iBufferReadOneOrMorePtr);
993 if ( iHasReadExpected )
995 const TDesC8& expectedBuffer=iCallbackReadOneOrMore->Buffer();
996 if ( expectedBuffer.Match(iBufferReadOneOrMorePtr)!=0 )
998 for ( TInt index=0; index<iBufferLength; ++index )
1000 const TUint8& actual=(*iBufferRead)[index];
1001 const TUint8& expected=expectedBuffer[index];
1002 if ( actual!=expected )
1004 ERR_PRINTF4(_L("Index:%d Read:%d Expected:%d"), index, (TInt)actual, (TInt)expected);
1008 ERR_PRINTF1(KLogErrorExpectedValue);
1009 SetBlockResult(EFail);
1012 CleanupStack::PopAndDestroy(bufferRead);
1016 else if ( aActive==iCallbackBreak )
1018 iCallbackBreak->KillTimer();
1019 INFO_PRINTF1(_L("RunL: Break()"));
1021 else if ( aActive==iCallbackNotifySignalChange )
1023 iCallbackNotifySignalChange->KillTimer();
1024 INFO_PRINTF1(_L("RunL: NotifySignalChange()"));
1026 if ( err==KErrNone )
1028 INFO_PRINTF2(_L("Signals Changed=0x%x"), iNotifySignals);
1029 if ( iHasNotifySignalsExpected )
1031 if ( iNotifySignals!=iNotifySignalsExpected )
1033 ERR_PRINTF3(KLogErrorExpectedSignal, iNotifySignals, iNotifySignalsExpected);
1034 SetBlockResult(EFail);
1039 else if ( aActive==iCallbackWrite )
1041 iCallbackWrite->KillTimer();
1042 INFO_PRINTF1(_L("RunL: Write()"));
1044 else if ( aActive==iCallbackNotifyReceiveDataAvailable )
1046 iCallbackNotifyReceiveDataAvailable->KillTimer();
1047 INFO_PRINTF1(_L("RunL: NotifyReceiveDataAvailable()"));
1051 CT_RBusLogicalChannelData::RunL(aActive, aIndex);
1060 if ( err!=KErrNone )
1062 ERR_PRINTF2(_L("RunL Error %d"), err);
1063 SetAsyncError(aIndex, err);
1067 void CT_RBusDevCommData::DoCancel(CActive* aActive, TInt aIndex)
1069 Virtual DoCancel - Request to cancel the asynchronous command
1071 @see - MTPActiveCallback
1072 @param aActive Active Object that DoCancel has been called on
1075 @leave system wide error code
1078 TBool activeOk=ETrue;
1079 SetBlockResult(EFail);
1081 if ( aActive==iCallbackRead )
1083 ERR_PRINTF1(_L("ReadCancel Called"));
1084 iBusDevComm->ReadCancel();
1086 else if ( aActive==iCallbackReadOneOrMore )
1088 ERR_PRINTF1(_L("ReadCancel Called"));
1089 iBusDevComm->ReadCancel();
1091 else if ( aActive==iCallbackBreak )
1093 ERR_PRINTF1(_L("BreakCancel Called"));
1094 iBusDevComm->BreakCancel();
1096 else if ( aActive==iCallbackNotifySignalChange )
1098 ERR_PRINTF1(_L("NotifySignalChangeCancel Called"));
1099 iBusDevComm->NotifySignalChangeCancel();
1101 else if ( aActive==iCallbackWrite )
1103 ERR_PRINTF1(_L("WriteCancel Called"));
1104 iBusDevComm->WriteCancel();
1106 else if ( aActive==iCallbackNotifyReceiveDataAvailable )
1108 ERR_PRINTF1(_L("NotifyReceiveDataAvailableCancel Called"));
1109 iBusDevComm->NotifyReceiveDataAvailableCancel();
1114 CT_RBusLogicalChannelData::DoCancel(aActive, aIndex);