cbsref/telephonyrefplugins/atltsy/atcommand/sms/src/atsmssend.cpp
branchRCL_3
changeset 20 07a122eea281
parent 19 630d2f34d719
child 21 4814c5a49428
equal deleted inserted replaced
19:630d2f34d719 20:07a122eea281
     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 atsmssend.cpp
       
    15 // This contains CAtSmsSend which is used to send sms message
       
    16 // 
       
    17 
       
    18 //system include
       
    19 #include <etelmm.h>
       
    20 #include <ctsy/ltsy/cctsydispatchercallback.h>
       
    21 
       
    22 // user include
       
    23 #include "atsmssend.h"
       
    24 #include "mslogger.h"
       
    25 #include "ltsycommondefine.h"
       
    26 #include "atmanager.h"
       
    27 #include "commengine.h"
       
    28 #include "smsatutil.h"
       
    29 
       
    30 //Constants
       
    31 _LIT8(KSmsSendCommandPdu,"AT+CMGS=%d\r");
       
    32 _LIT8(KCMGSResponseString,"+CMGS:");
       
    33 _LIT8(KDefaultSCA,"00");
       
    34 _LIT8(KSmsEnterPduResponse,">");
       
    35 _LIT8(KSendExpectedString,"+CMGS:*");
       
    36 const TInt KLtsyOnePause = 100000;
       
    37 const TInt KLtsySendSmsWriteTimeOut = 20;
       
    38 const TInt KLtsySendSmsReadTimeOut = 30;
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // CAtSmsSend::CAtSmsSend
       
    42 // other items were commented in a header
       
    43 // ---------------------------------------------------------------------------
       
    44 CAtSmsSend::CAtSmsSend(CGlobalPhonemanager& aGloblePhone, 
       
    45                        CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    46                        :CAtCommandBase(aGloblePhone,aCtsyDispatcherCallback)                  
       
    47  	{
       
    48 	LOGTEXT(_L8("CAtSmsSend::CAtSmsSend called"));
       
    49 	iWriteTimeOut = KLtsySendSmsWriteTimeOut;
       
    50 	iReadTimeOut = KLtsySendSmsReadTimeOut;
       
    51 	}
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // CAtSmsSend::~CAtSmsSend
       
    55 // other items were commented in a header
       
    56 // ---------------------------------------------------------------------------
       
    57 CAtSmsSend::~CAtSmsSend()
       
    58 	{
       
    59 	LOGTEXT(_L8("CAtSmsSend::~CAtSmsSend called"));
       
    60 	delete iCallbackTimer;
       
    61 	iCallbackTimer = NULL;
       
    62 	}
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // CAtSmsSend::NewLC
       
    66 // other items were commented in a header
       
    67 // ---------------------------------------------------------------------------
       
    68 CAtSmsSend* CAtSmsSend::NewLC(CGlobalPhonemanager& aGloblePhone, 
       
    69                               CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    70 	{
       
    71 	CAtSmsSend* self = new (ELeave)CAtSmsSend(aGloblePhone,
       
    72 			                                  aCtsyDispatcherCallback);
       
    73 	CleanupStack::PushL(self);
       
    74 	self->ConstructL();
       
    75 	return self;
       
    76 	}
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // CAtSmsSend::NewL
       
    80 // other items were commented in a header
       
    81 // ---------------------------------------------------------------------------
       
    82 CAtSmsSend* CAtSmsSend::NewL(CGlobalPhonemanager& aGloblePhone, 
       
    83                              CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    84 	{
       
    85 	CAtSmsSend* self=CAtSmsSend::NewLC(aGloblePhone,aCtsyDispatcherCallback);
       
    86 	CleanupStack::Pop(self);
       
    87 	return self;
       
    88 	}
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // CAtSmsSend::ConstructL
       
    92 // other items were commented in a header
       
    93 // ---------------------------------------------------------------------------
       
    94 void CAtSmsSend::ConstructL()
       
    95 	{
       
    96 	CAtCommandBase::ConstructL();
       
    97 	//Create Timer
       
    98 	iCallbackTimer = CCallbackTimer::NewL(*this);
       
    99 	//set writing timeout
       
   100 	iWriteTimeOut = KLtsyDefaultWriteTimeOut;
       
   101 	AddExpectStringL(KSmsEnterPduResponse);
       
   102 	AddExpectStringL(KSendExpectedString);
       
   103 	}
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // CAtSmsSend::StartRequest
       
   107 // other items were commented in a header
       
   108 // ---------------------------------------------------------------------------
       
   109 void CAtSmsSend::StartRequest()
       
   110 	{
       
   111 	ExecuteCommand();
       
   112 	}
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // CAtSmsSend::ExecuteCommand
       
   116 // other items were commented in a header
       
   117 // ---------------------------------------------------------------------------
       
   118 void CAtSmsSend::ExecuteCommand()
       
   119 	{
       
   120 	LOGTEXT(_L8("CAtSmsSend::ExecuteCommand called"));
       
   121 	LOGTEXT(_L8("SendPDUMessage..."));
       
   122 	
       
   123 	iMsgDataAscii.Zero();
       
   124 	TInt ret = ConfirmSca();
       
   125 	if(ret == KErrNone)
       
   126 		{
       
   127 		//Here is a SCA
       
   128 		ret = SmsAtUtil::AppendAddressToAscii(iMsgDataAscii,iSmsSendParam.iGsmServiceCentre);
       
   129 		if( ret!=KErrNone )
       
   130 			{
       
   131 			BeginTimer();
       
   132 			iCallbackVal = ret;
       
   133 			return;
       
   134 			}
       
   135 		}
       
   136 	else 
       
   137 		{
       
   138 		//Here is no SCA,usign default SCA
       
   139 		iMsgDataAscii.Append(KDefaultSCA);
       
   140 		}
       
   141 	const TInt msgDataAsciiLen(iMsgDataAscii.Length());
       
   142 	// Convert PDU to ASCII
       
   143 	SmsAtUtil::AppendDataToAscii(iMsgDataAscii,iSmsSendParam.iSmsTpdu);
       
   144 	iState = ESetPDULengthComplete;
       
   145 	StartWritingPduLength();
       
   146 	}
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // CAtSmsSend::StartWritingPduLength
       
   150 // other items were commented in a header
       
   151 // ---------------------------------------------------------------------------
       
   152 void CAtSmsSend::StartWritingPduLength()
       
   153 	{
       
   154 	LOGTEXT(_L8("CAtSmsSend::StartWritingPduLength called"));
       
   155 	TInt pduLen = iSmsSendParam.iSmsTpdu.Length();
       
   156 	iTxBuffer.Zero();
       
   157 	iTxBuffer.Format(KSmsSendCommandPdu,pduLen);
       
   158 	ClearBuffer();
       
   159 	iPhoneGlobals.iAtManager->SetSolicitedAtCommand(this);
       
   160 	iPhoneGlobals.iCommEngine->CommWrite(iTxBuffer);	
       
   161 	StartTimer(iWriteTimeOut);
       
   162 	}
       
   163 
       
   164 // ---------------------------------------------------------------------------
       
   165 // CAtSmsSend::StartWritingPdu
       
   166 // other items were commented in a header
       
   167 // ---------------------------------------------------------------------------
       
   168 void CAtSmsSend::StartWritingPdu()
       
   169 	{
       
   170 	LOGTEXT(_L8("CAtSmsSend::StartWritingPdu called"));
       
   171 	iTxBuffer.Zero();
       
   172 	iTxBuffer.Append(iMsgDataAscii);
       
   173 	iTxBuffer.Append(KLtsyCtrlZChar);
       
   174 	ClearBuffer();
       
   175 	iPhoneGlobals.iAtManager->SetSolicitedAtCommand(this);
       
   176 	iPhoneGlobals.iCommEngine->CommWrite(iTxBuffer);	
       
   177 	StartTimer(iWriteTimeOut);
       
   178 	}
       
   179 
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 // CAtSmsSend::SetMessageParam
       
   183 // other items were commented in a header
       
   184 // ---------------------------------------------------------------------------
       
   185 void CAtSmsSend::SetMessageParam(TSmsSendParam aMsgParam)
       
   186 	{
       
   187 	iSmsSendParam = aMsgParam;
       
   188 	}
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // CAtSmsSend::EventSignal
       
   192 // other items were commented in a header
       
   193 // ---------------------------------------------------------------------------
       
   194 void CAtSmsSend::EventSignal(TAtEventSource aEventSource, TInt aStatus)
       
   195 	{
       
   196 	LOGTEXT3(_L8("CAtSmsSend::EventSignal aStatus=%D iSource=%D"),aStatus,aEventSource);
       
   197     if(aStatus == KErrNone)
       
   198 		{
       
   199 		if(aEventSource == EWriteCompletion)
       
   200 			{
       
   201 			LOGTEXT(_L8("CAtSmsSend::EventSignal,EWriteCompletion!"));
       
   202 			return;
       
   203 			}
       
   204 		else
       
   205 			{
       
   206 			if( iState == ESetPDULengthComplete )
       
   207 				{
       
   208 	            if(iError==KErrNone)
       
   209 	            	{
       
   210 			    	iState = ESendPDUComplete;
       
   211 			    	Complete();
       
   212 			       	StartWritingPdu();
       
   213 			    	return;     
       
   214 	            	}
       
   215 				}
       
   216 			}
       
   217 		aStatus = iError;
       
   218 		}
       
   219     Complete();
       
   220    	iPhoneGlobals.iEventSignalActive = EFalse;
       
   221     iCtsyDispatcherCallback.CallbackSmsSendSmsMessageComp(aStatus,iSmsSendResponse.iValRef,
       
   222     		                                              iSmsSendResponse.iSubmitReport);
       
   223 	}
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // CAtSmsSend::ParseResponseL
       
   227 // other items were commented in a header
       
   228 // ---------------------------------------------------------------------------
       
   229 void CAtSmsSend::ParseResponseL(const TDesC8& /*aResponseBuf*/)
       
   230     {
       
   231     LOGTEXT(_L8("CAtSmsSend::ParseResponseL called!"));
       
   232     if(iState == ESetPDULengthComplete) 
       
   233 	    {
       
   234    	    if(CurrentLine().MatchF(KSmsEnterPduResponse) != KErrNotFound)
       
   235 	    	{
       
   236 	    	iError = KErrNone;
       
   237 	    	}
       
   238 	    else
       
   239 	    	{
       
   240 	    	iError = KErrNotFound;
       
   241 	    	}
       
   242 	    }
       
   243     else
       
   244 		{
       
   245 		iError = KErrNone;
       
   246 		TPtrC8 responseBuf;
       
   247 		responseBuf.Set(Buffer());
       
   248 		TInt pos = responseBuf.FindF(KCMGSResponseString);
       
   249 		if (pos == KErrNotFound)
       
   250 			{
       
   251 			LOGTEXT(_L8("CAtSmsSend::ParseCMGSResponse \"+CMGS:\" not found"));
       
   252 			iError = KErrNotFound;
       
   253 			return;
       
   254 			}
       
   255 	
       
   256 		// Locate the message reference number
       
   257 		// (ie. read in all digits form the first found to the end of the string)
       
   258 		const TInt bufLength=responseBuf.Length();
       
   259 		pos += KCMGSResponseString().Length();
       
   260 		while(pos<bufLength && !(TChar(responseBuf[pos]).IsDigit()))
       
   261 				++pos;
       
   262 		if(pos == bufLength)
       
   263 			{
       
   264 			LOGTEXT(_L8("CAtSmsSend::ParseCMGSResponse cannot find any digits after \"+CMS:\" "));
       
   265 			iError = KErrNotFound;
       
   266 			return;
       
   267 			}
       
   268 	
       
   269 		// Read message number and store in clients data structure
       
   270 		TPtrC8 ptr = responseBuf.Mid(pos);	
       
   271 		TLex8 lex(ptr);
       
   272 		TUint16 val;
       
   273 		TInt ret = lex.Val(val,EDecimal);
       
   274 		if(ret != KErrNone)
       
   275 			{
       
   276 			LOGTEXT(_L8("CAtSmsSend::ParseCMGSResponse cannot read Message Reference Number"));
       
   277 			iError = ret;
       
   278 			return;
       
   279 			}
       
   280 		iSmsSendResponse.iValRef = val;
       
   281 		LOGTEXT2(_L8("CAtSmsSend  Message reference number %d"),val);
       
   282 	    }
       
   283 	}
       
   284 
       
   285 // ---------------------------------------------------------------------------
       
   286 // CAtSmsSend::ConfirmSca
       
   287 // other items were commented in a header
       
   288 // ---------------------------------------------------------------------------
       
   289 TInt CAtSmsSend::ConfirmSca()
       
   290 	{
       
   291 	if(iSmsSendParam.iGsmServiceCentre.iTelNumber.Length() == 0)
       
   292 		{
       
   293 		return KErrNotFound;
       
   294 		}
       
   295 	if(!(iSmsSendParam.iGsmServiceCentre.iNumberPlan == RMobilePhone::EIsdnNumberPlan &&
       
   296 		(iSmsSendParam.iGsmServiceCentre.iTypeOfNumber == RMobilePhone::EInternationalNumber ||
       
   297 		iSmsSendParam.iGsmServiceCentre.iTypeOfNumber == RMobilePhone::EUnknownNumber)))
       
   298 		{
       
   299 		return KErrCorrupt;
       
   300 		}
       
   301 	return KErrNone;
       
   302 	}
       
   303 
       
   304 // ---------------------------------------------------------------------------
       
   305 // CAtSmsSend::BeginTimer
       
   306 // other items were commented in a header
       
   307 // ---------------------------------------------------------------------------
       
   308 void CAtSmsSend::BeginTimer()
       
   309 	{
       
   310 	LOGTEXT(_L8("CAtSmsSend::BeginTimer() called"));	
       
   311 	
       
   312     if (iCallbackTimer->IsActive())
       
   313     	{
       
   314     	iCallbackTimer->Cancel();
       
   315     	}
       
   316 	iCallbackTimer->After(KLtsyOnePause);	
       
   317 	}
       
   318 
       
   319 // ---------------------------------------------------------------------------
       
   320 // CAtSmsSend::TimerRun
       
   321 // other items were commented in a header
       
   322 // ---------------------------------------------------------------------------
       
   323 void CAtSmsSend::TimerRun(TInt aError)
       
   324 	{
       
   325 	LOGTEXT(_L8("CAtSmsSend::TimerRun() called"));
       
   326 	if(aError == KErrNone)
       
   327 		{
       
   328 		Complete();
       
   329 		iPhoneGlobals.iEventSignalActive = EFalse;
       
   330 		iCtsyDispatcherCallback.CallbackSmsSendSmsMessageComp(iCallbackVal,iSmsSendResponse.iValRef,
       
   331 				                                              iSmsSendResponse.iSubmitReport);
       
   332 		}
       
   333 	}
       
   334 
       
   335 //End of file