Symbian OS
read last symbian news on www.newlc.com read last symbian reviews on www.newlc.com
read last symbian tutorial on www.newlc.com read last symbian download on www.newlc.com
18 Apr 2007 - 23:07
Keywords :

The CNetworkCellMonitor class shown in this code snippet monitors the network and cell a mobile device is registered on. It will report the Mobile Country Code, the Mobile Network Code and the CellId to an observer class.

// NetworkCellMonitor.h

#ifndef __NETWORKCELLMONITOR_H__
#define __NETWORKCELLMONITOR_H__

#include <e32base.h>
#include <Etel3rdParty.h>
 
/**
* The network and cell id callback interface. 
*/ 
class MNetworkCellObserver
{
public:
  virtual void NetworkCellNotifyL(TUint aMCC, TUint aMNC, TUint aCellId) = 0;
};
    
/**
* The network and cell id monitor
*/
class CNetworkCellMonitor : public CActive
{ 
public:
  static CNetworkCellMonitor* NewL(MNetworkCellObserver& aObserver,
    TTimeIntervalMicroSeconds32 aPollingInterval);
  ~CNetworkCellMonitor();
  
private:  /// from CActive
  void RunL();
  void DoCancel();
    
private: /// Construction
  CNetworkCellMonitor(MNetworkCellObserver& aObserver,
    TTimeIntervalMicroSeconds32 aPollingInterval);
  void ConstructL();
    
private:

  enum TMonitoringMode
  {
    EMonitoring,
    EWaiting
  };
  
  MNetworkCellObserver&          iObserver;
  TTimeIntervalMicroSeconds32    iPollingInterval;
  RTimer                         iTimer;
  TMonitoringMode                iMode;
  
  CTelephony*                    iTelephony;
  CTelephony::TNetworkInfoV1     iNetworkInfo;    
  CTelephony::TNetworkInfoV1Pckg iNetworkInfoPckg;
  
  TUint                          iPreviousCellId;
};

#endif

And the implementation of the CNetworkCellMonitor class:

// NetworkCellMonitor.cpp

#include "NetworkCellMonitor.h"

CNetworkCellMonitor* CNetworkCellMonitor::NewL(MCellIdObserver& aObserver,
    TTimeIntervalMicroSeconds32 aPollingInterval)
{
  CNetworkCellMonitor* self=new(ELeave)CNetworkCellMonitor(aObserver,aPollingInterval);
  CleanupStack::PushL(self);
  self->ConstructL();
  CleanupStack::Pop(self);
  return(self);
}
  
CNetworkCellMonitor::CNetworkCellMonitor(MCellIdObserver& aObserver,
    TTimeIntervalMicroSeconds32 aPollingInterval)
: CActive(EPriorityNormal),
  iObserver(aObserver),
  iPollingInterval(aPollingInterval),
  iNetworkInfoPckg(iNetworkInfo)
{
}

CNetworkCellMonitor::~CNetworkCellMonitor()
{
  Cancel();
  delete iTelephony;
  iTimer.Close();
}
 
void CNetworkCellMonitor::ConstructL()
{
  iTelephony = CTelephony::NewL();
  iTimer.CreateLocal();
  CActiveScheduler::Add(this);
  
  iMode=EMonitoring;
  iTelephony->GetCurrentNetworkInfo(iStatus,iNetworkInfoPckg);
  SetActive();
}
 
void CNetworkCellMonitor::RunL()
{
  if(iStatus==KErrNone)
  {
    switch(iMode)
    {
      case EMonitoring:
      {   
        if(iPreviousCellId!=iNetworkInfo.iCellId)
        {
          // Convert the MCC/MNC in numerical values and notify the observer
          TLex lex(iNetworkInfo.iCountryCode);
          TUint mcc=0,mnc=0,cellId=0;
          lex.Val(mcc);
          lex.Assign(iNetworkInfo.iNetworkId);
          lex.Val(mnc);
          iObserver.NetworkCellNotifyL(mcc,mnc,iNetworkInfo.iCellId);
          
          iPreviousCellId=iNetworkInfo.iCellId;
        }
        
        // Now wait before getting values again
        iMode=EWaiting;
        iTimer.After(iStatus,iPollingInterval);
        SetActive();
        break;
      }
      
      case EWaiting:
      {
        // Continue the monitoring
        iMode=EMonitoring;
        iTelephony->GetCurrentNetworkInfo(iStatus,iNetworkInfoPckg); 
        SetActive();
        break;
      }
    }
  }   
 
}
 
void CNetworkCellMonitor::DoCancel()
{
  if(iMode==EWaiting)
    iTimer.Cancel()
  else
    iTelephony->CancelAsync(CTelephony::EGetCurrentNetworkInfoCancel);
}

Note: If you just need to read these information and not to monitor them, you may want to take a look at the following page: http://www.newlc.com/Retrieving-IMEI-IMSI-Network-Info.html

Tutorial posted April 18th, 2007 by eric

Submitted by Luca on Fri, 2007-04-20 09:06.

Hi,
I'm using Nokia3250 and with GetCurrentNetworkInfo() and I can retrive all network info (mcc, mnc, cellid, ...) except the network type (GSM - UMTS).

iMode = iNetworkInfoV1.iMode; ....... iMode = ENetworkModeUnknown
iAccess = iNetworkInfoV1.iAccess; ....... iAccess = ENetworkAccessUnknown

I' m not in flight mode and I use required capabilities (ReadDeviceData and Location). SDK says that ENetworkAccessUnknown " is used when there is no network activity and therefore no RAT active", anyway I can receive and make phone calls, so there's network activity....

What could be the problem in your opinion?

Thanks in advance, Luca.



Submitted by jje on Wed, 2007-04-25 14:06.

Hi Luca,

I don't know what's wrong with your setup, but I tell my experience just in case there is some useful info to you:

I also get ENetworkAccessUnknown (0) with iNetworkInfoV1.iAccess
but iNetworkInfoV1.iMode returns ENetworkModeGsm (2) or ENetworkModeWcdma (6).

I am using Nokia N73 and Nokia 5500d and the following APIs: CTelephony::GetCurrentNetworkInfo and CTelephony::NotifyChange( iStatus, CTelephony::ECurrentNetworkInfoChange, *iPkg );

Jyrki



copyright 2003-2009 NewLC SARL