cbsref/telephonyrefplugins/atltsy/atcommand/phone/src/atgetbatteryinfo.cpp
branchRCL_3
changeset 65 630d2f34d719
equal deleted inserted replaced
61:17af172ffa5f 65:630d2f34d719
       
     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 // Queries the ME battery. Retrieves charge level and battery status
       
    15 
       
    16 #include "atgetbatteryinfo.h"
       
    17 #include "mslogger.h"
       
    18 #include "requestbase.h"
       
    19 
       
    20 
       
    21 _LIT8(KGetBatteryCommand,"AT+CIND?\r");
       
    22 _LIT8(KGetBatteryCmdRepondStr,"+CIND:");
       
    23 // Class CATGetBattery
       
    24 // ---------------------------------------------------------------------------
       
    25 // CATGetBattery::NewL
       
    26 // other items were commented in a header
       
    27 // ---------------------------------------------------------------------------
       
    28 CATGetBattery* CATGetBattery::NewL(CGlobalPhonemanager& aGloblePhone, 
       
    29 	                               CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    30 	{
       
    31 	CATGetBattery* self = new(ELeave) CATGetBattery(aGloblePhone,
       
    32 			                                        aCtsyDispatcherCallback);
       
    33 	CleanupStack::PushL(self );
       
    34 	self->ConstructL();
       
    35 	CleanupStack::Pop(self );
       
    36 	return self ;
       
    37 	}
       
    38 // ---------------------------------------------------------------------------
       
    39 // CATGetBattery::CATGetBattery
       
    40 // other items were commented in a header
       
    41 // ---------------------------------------------------------------------------
       
    42 CATGetBattery::CATGetBattery(CGlobalPhonemanager& aGloblePhone, 
       
    43 	                         CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    44 		:CAtCommandBase(aGloblePhone,aCtsyDispatcherCallback)
       
    45 	{
       
    46 	}
       
    47 // ---------------------------------------------------------------------------
       
    48 // CATGetBattery::ConstructL
       
    49 // other items were commented in a header
       
    50 // ---------------------------------------------------------------------------
       
    51 void CATGetBattery::ConstructL()
       
    52 	{
       
    53 	CAtCommandBase::ConstructL();
       
    54 	iAtType = ELtsyAT_Phone_GetBattery;
       
    55 	}
       
    56 // ---------------------------------------------------------------------------
       
    57 // CATGetBattery::~CATGetBattery
       
    58 // other items were commented in a header
       
    59 // ---------------------------------------------------------------------------
       
    60 CATGetBattery::~CATGetBattery()
       
    61 	{
       
    62 	}
       
    63 // ---------------------------------------------------------------------------
       
    64 // CATGetBattery::StartRequestL
       
    65 // other items were commented in a header
       
    66 // ---------------------------------------------------------------------------
       
    67 void CATGetBattery::StartRequest()
       
    68 	{
       
    69 	ExecuteCommand();
       
    70 	}
       
    71 // ---------------------------------------------------------------------------
       
    72 // CATGetBattery::ExecuteCommand
       
    73 // other items were commented in a header
       
    74 // ---------------------------------------------------------------------------
       
    75 void CATGetBattery::ExecuteCommand()
       
    76 	{
       
    77 	iTxBuffer.Copy(KGetBatteryCommand);
       
    78 	Write();
       
    79 	}
       
    80 // ---------------------------------------------------------------------------
       
    81 // CATGetBattery::CATGetBattery
       
    82 // other items were commented in a header
       
    83 // ---------------------------------------------------------------------------
       
    84 RMobilePhone::TMobilePhoneBatteryInfoV1 CATGetBattery::GetBatteryinfo()
       
    85 	{
       
    86 	return iBatteryInfo;
       
    87 	}
       
    88 // ---------------------------------------------------------------------------
       
    89 // CATGetBattery::CATGetBattery
       
    90 // other items were commented in a header
       
    91 // ---------------------------------------------------------------------------
       
    92 TRfStateInfo CATGetBattery::GetRfStateInfo()
       
    93 	{
       
    94 	return iRfStateInfo;
       
    95 	}
       
    96 // ---------------------------------------------------------------------------
       
    97 // CATGetBattery::GetErrorValue
       
    98 // other items were commented in a header
       
    99 // ---------------------------------------------------------------------------
       
   100 TInt CATGetBattery::GetErrorValue()
       
   101 	{
       
   102 	return iError;
       
   103 	}
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // CATGetBattery::ParseResponseL
       
   107 // This method parses the modems response to the 'AT+CIND?' command.
       
   108 // +CIND: <ind>[,<ind>[,...]]
       
   109 // An example response is '+CIND: 3,3,1,1,1,1,1,1,1' where first value 
       
   110 // denotes the current battery charge level.
       
   111 // "battchg" battery charge level (0-5)
       
   112 // "signal" signal quality (0-5)
       
   113 // "service" service availability (0-1)
       
   114 // "sounder" sounder activity (0-1)
       
   115 // "message" message received (0-1)
       
   116 // "call" call in progress (0-1)
       
   117 // "vox" transmit activated by voice activity (0-1)
       
   118 // "roam" roaming indicator (0-1)
       
   119 // "smsfull" a short message memory storage in the MT has become full (1), or memory locations are available (0);
       
   120 // i.e. the range is (0-1)
       
   121 // other items were commented in a header
       
   122 // ---------------------------------------------------------------------------
       
   123 void CATGetBattery::ParseResponseL(const TDesC8& /*aResponseBuf*/)
       
   124 	{
       
   125 	if (CurrentLine().Match(KLtsyOkString) != 0)
       
   126 		{
       
   127 		iError = KErrGeneral;
       
   128 		return ;
       
   129 		}
       
   130 	RArray<TPtrC8> array;
       
   131 	CleanupClosePushL(array);
       
   132 	iParser->ParseRespondedBuffer(array,PrecedingLine());
       
   133 	TInt Count = array.Count();
       
   134 	if (Count < 1)
       
   135 		{
       
   136 		CleanupStack::PopAndDestroy();
       
   137 		iError = KErrNotFound;
       
   138 		return;
       
   139 		}
       
   140 	if( array[0].MatchF(KGetBatteryCmdRepondStr)==KErrNotFound)
       
   141 		{
       
   142 		CleanupStack::PopAndDestroy();
       
   143 		iError = KErrNotFound;
       
   144 		return ;
       
   145 		}
       
   146 	TInt val = 0;
       
   147 	TLex8 lex(array[1]);
       
   148 	lex.Val(val);
       
   149 	if (val < 0) 
       
   150 		{
       
   151 		iBatteryInfo.iStatus = RMobilePhone::EPowerStatusUnknown;
       
   152 		iBatteryInfo.iChargeLevel = 0;
       
   153 		}
       
   154 	else	
       
   155 		{
       
   156 		iBatteryInfo.iStatus = RMobilePhone::EPoweredByBattery;
       
   157 		iBatteryInfo.iChargeLevel = val;
       
   158 		}
       
   159 	TLex8 lexRf(array[3]);
       
   160 	lexRf.Val(val);
       
   161 	if(val == 1)
       
   162 		{
       
   163 		iRfStateInfo = ERfsStateInfoNormal;
       
   164 		}
       
   165 	else
       
   166 		{
       
   167 		iRfStateInfo = ERfsStateInfoInactive;
       
   168 		}
       
   169 	
       
   170 	CleanupStack::PopAndDestroy(&array);
       
   171 	iError = KErrNone;
       
   172 	}
       
   173 // ---------------------------------------------------------------------------
       
   174 // CATGetBattery::EventSignal
       
   175 // other items were commented in a header
       
   176 // ---------------------------------------------------------------------------
       
   177 void CATGetBattery::EventSignal(TAtEventSource aEventSource, TInt aStatus)
       
   178 	{
       
   179 	if(KErrNone ==aStatus)
       
   180 		{
       
   181 		if(aEventSource == EReadCompletion)
       
   182 			{
       
   183 			aStatus = iError;
       
   184 			}
       
   185 		else
       
   186 			return;
       
   187 		}
       
   188 	CAtCommandBase::Complete();
       
   189 	iPhoneGlobals.iEventSignalActive = EFalse;
       
   190 	iCtsyDispatcherCallback.CallbackPhoneGetBatteryInfoComp(aStatus,iBatteryInfo);
       
   191 	}
       
   192 //
       
   193 // End of file