setting_band.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:19k
- /*****************************************************************************
- * Copyright Statement:
- * --------------------
- * This software is protected by Copyright and the information contained
- * herein is confidential. The software may not be copied and the information
- * contained herein may not be used or disclosed except with the written
- * permission of MediaTek Inc. (C) 2005
- *
- * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
- * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
- * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
- * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
- * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
- * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
- * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
- * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
- * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
- *
- * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
- * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
- * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
- * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
- * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
- *
- * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
- * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
- * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
- * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
- * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
- *
- *****************************************************************************/
- /*****************************************************************************
- *
- * Filename:
- * ---------
- * setting_band.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * band setting source
- *
- * Author:
- * -------
- * Andy Ueng (mtk00490)
- *
- *============================================================================
- * HISTORY
- * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *------------------------------------------------------------------------------
- * $Revision$
- * $Modtime$
- * $Log$
- *
- *------------------------------------------------------------------------------
- * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *============================================================================
- ****************************************************************************/
- #include <IniFiles.hpp>
- #pragma hdrstop
- #include "setting_band.h"
- #include "man_active.h"
- #include "man_fdm.h"
- //===========================================================================
- static CSETTINGBAND* setting_band_ptr;
- static bool g_bIsRunning;
- //===========================================================================
- static void CNF_ReadFromNVRAM( void )
- {
- setting_band_ptr->CNF_ReadFromNVRAM( );
- }
- //---------------------------------------------------------------------------
- static void CNF_WriteToNVRAM(void)
- {
- setting_band_ptr->CNF_WriteToNVRAM();
- }
- //-------------------------------------------------------------------------
- static void CNF_ResetNVRAMData( void )
- {
- setting_band_ptr->CNF_ResetNVRAMData( );
- }
- //===========================================================================
- CSETTINGBAND::CSETTINGBAND( void )
- {
- g_bIsRunning = false;
- ConfirmCallback = 0;
-
- }
- //---------------------------------------------------------------------------
- CSETTINGBAND::~CSETTINGBAND( )
- {
-
- }
- //---------------------------------------------------------------------------
- void CSETTINGBAND::Confirm(E_METAAPP_RESULT_T confirm_state)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- g_bIsRunning = false;
- if (NULL == ConfirmCallback)
- {
- return;
- }
- m_eConfirmState = confirm_state;
- ActiveMan->SetActiveFunction(ConfirmCallback);
- }
- //===========================================================================
- bool CSETTINGBAND::Decompose_SettingBand(void)
- {
- META_RESULT MetaResult;
- // band
- //MetaResult = META_NVRAM_GetRecFieldValue( "NVRAM_EF_RAC_PREFERENCE_LID",
- // "band",
- // m_cBuf,
- // m_iBufSize,
- // &m_sNvramEfRacPreference.band,
- // sizeof(m_sNvramEfRacPreference.band)
- // );
- //if(MetaResult!=META_SUCCESS) return false;
- // uc_arg1
- MetaResult = META_NVRAM_GetRecFieldValue("NVRAM_EF_RAC_PREFERENCE_LID",
- "arg1",
- m_cBuf,
- m_iBufSize,
- &m_sNvramEfRacPreference.uc_arg1,
- sizeof(m_sNvramEfRacPreference.uc_arg1)
- );
- if (MetaResult != META_SUCCESS)
- {
- return false;
- }
- return true;
- }
- //---------------------------------------------------------------------------
- bool CSETTINGBAND::Compose_SettingBand(void)
- {
- META_RESULT MetaResult;
- // band
- // MetaResult = META_NVRAM_SetRecFieldValue( "NVRAM_EF_RAC_PREFERENCE_LID",
- // "band",
- // m_cBuf,
- // m_iBufSize,
- // &m_sNvramEfRacPreference.band,
- // sizeof(m_sNvramEfRacPreference.band) );
- //
- // if(MetaResult!=META_SUCCESS) return(false);
- // uc_arg1
- MetaResult = META_NVRAM_SetRecFieldValue( "NVRAM_EF_RAC_PREFERENCE_LID",
- "arg1",
- m_cBuf,
- m_iBufSize,
- &m_sNvramEfRacPreference.uc_arg1,
- sizeof(m_sNvramEfRacPreference.uc_arg1) );
- if (MetaResult != META_SUCCESS)
- {
- return false;
- }
- return true;
- }
- //===========================================================================
- void CSETTINGBAND::REQ_Read_From_NVRAM_Start(void)
- {
- setting_band_ptr = this;
- g_bIsRunning = true;
- m_bDownloadTrigger = false;
- REQ_Read_From_NVRAM();
- }
- //---------------------------------------------------------------------------
- void CSETTINGBAND::REQ_Read_From_NVRAM(void)
- {
- if (NULL == m_cBuf)
- {
- META_RESULT MetaResult = META_NVRAM_GetRecLen("NVRAM_EF_RAC_PREFERENCE_LID",
- &m_iBufSize );
- if (MetaResult != META_SUCCESS)
- {
- Confirm( METAAPP_FAIL );
- return;
- }
- m_cBuf = new char[m_iBufSize];
- }
- NVRAMMan->ConfirmCallback = ::CNF_ReadFromNVRAM;
- NVRAMMan->REQ_ReadNVRAM_Start("NVRAM_EF_RAC_PREFERENCE_LID",
- 1,
- m_iBufSize,
- m_cBuf );
- }
- //-------------------------------------
- void CSETTINGBAND::CNF_ReadFromNVRAM(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
- if (METAAPP_SUCCESS == state)
- {
- if (m_bDownloadTrigger)
- {
- REQ_Write_To_NVRAM();
- }
- else
- {
- if (!Decompose_SettingBand())
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- Confirm(METAAPP_SUCCESS);
- }
- }
- else
- {
- Confirm(state);
- }
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void CSETTINGBAND::REQ_Write_To_NVRAM_Start(void)
- {
- setting_band_ptr = this;
- g_bIsRunning = true;
- m_bDownloadTrigger = true;
- REQ_Read_From_NVRAM();
- }
- //------------------------------------------------------------------------------
- void CSETTINGBAND::REQ_Write_To_NVRAM(void)
- {
- if (NULL == m_cBuf)
- {
- META_RESULT MetaResult = META_NVRAM_GetRecLen("NVRAM_EF_RAC_PREFERENCE_LID",
- &m_iBufSize);
- if (MetaResult != META_SUCCESS)
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- m_cBuf = new char[m_iBufSize];
- }
- if (!Compose_SettingBand())
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- NVRAMMan->ConfirmCallback = ::CNF_WriteToNVRAM;
- NVRAMMan->REQ_WriteNVRAM_Start("NVRAM_EF_RAC_PREFERENCE_LID",
- 1,
- m_iBufSize,
- m_cBuf );
- }
- //-------------------------------------
- void CSETTINGBAND::CNF_WriteToNVRAM(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
- Confirm(state);
- }
- //===========================================================================
- bool CSETTINGBAND::REQ_Read_From_File(char *filename)
- {
- TIniFile *ini_file;
- AnsiString as_str;
- ini_file = new TIniFile(filename);
- if (NULL == ini_file)
- {
- return false;
- }
- //as_str = ini_file->ReadString( "RAC preference setting",
- // "band",
- // "GSM 900" );
- //m_sNvramEfRacPreference.band = Get_SettingBand( as_str );
- as_str = ini_file->ReadString( "RAC preference setting",
- "PLMN selection",
- "Automatic" );
- m_sNvramEfRacPreference.uc_arg1 = (m_sNvramEfRacPreference.uc_arg1 & (0xFF ^ MASK_ARG1_PLMN_SELECTION)) | Get_SettingPlmnSelection( as_str );
- as_str = ini_file->ReadString( "RAC preference setting",
- "Mobile class",
- "Class B(GSM)" );
- m_sNvramEfRacPreference.uc_arg1 = (m_sNvramEfRacPreference.uc_arg1 & (0xFF ^ MASK_ARG1_MOBILE_CLASS)) | Get_SettingMsClass( as_str );
- as_str = ini_file->ReadString( "RAC preference setting",
- "GPRS attach mode",
- "Auto" );
- m_sNvramEfRacPreference.uc_arg1 = (m_sNvramEfRacPreference.uc_arg1 & (0xFF ^ MASK_ARG1_GPRS_ATTACH)) | Get_SettingGprsAttachMode( as_str );
- delete ini_file;
- return true;
- }
- //------------------------------------------------------------------------
- bool CSETTINGBAND::REQ_Write_To_File( char *filename )
- {
- TIniFile *ini_file;
- AnsiString as_band;
- AnsiString as_PlmnSelection;
- AnsiString as_MsClass;
- AnsiString as_GprsAttachMode;
-
- //unsigned char band = m_sNvramEfRacPreference.band;
- unsigned char plmn_sel = m_sNvramEfRacPreference.uc_arg1 & MASK_ARG1_PLMN_SELECTION;
- unsigned char ms_class = m_sNvramEfRacPreference.uc_arg1 & MASK_ARG1_MOBILE_CLASS;
- unsigned char gprs_attach = m_sNvramEfRacPreference.uc_arg1 & MASK_ARG1_GPRS_ATTACH;
- ini_file = new TIniFile(filename );
- if (NULL == ini_file)
- {
- return false;
- }
-
- //Set_SettingBand( band, as_band );
- //ini_file->WriteString( "RAC preference setting",
- // "band",
- // as_band
- // );
- Set_SettingPlmnSelection( plmn_sel, as_PlmnSelection );
- ini_file->WriteString( "RAC preference setting",
- "PLMN selection",
- as_PlmnSelection
- );
- Set_SettingMsClass( ms_class, as_MsClass );
- ini_file->WriteString( "RAC preference setting",
- "Mobile class",
- as_MsClass
- );
- Set_SettingGprsAttachMode( gprs_attach, as_GprsAttachMode );
- ini_file->WriteString( "RAC preference setting",
- "GPRS attach mode",
- as_GprsAttachMode
- );
- delete ini_file;
- return true;
- }
- //==============================================================================
- int CSETTINGBAND::Get_SettingBand( AnsiString as_str )
- {
- int band = BAND_MODE_GSM900;
- if( as_str.AnsiCompareIC( "GSM 900" ) == 0 )
- {
- band = BAND_MODE_GSM900;
- }
- else if( as_str.AnsiCompareIC( "DCS 1800" ) == 0 )
- {
- band = BAND_MODE_DCS1800;
- }
- else if( as_str.AnsiCompareIC( "PCS 1900" ) == 0 )
- {
- band = BAND_MODE_PCS1900;
- }
- else if( as_str.AnsiCompareIC( "GSM 850" ) == 0 )
- {
- band = BAND_MODE_GSM850;
- }
- else if( as_str.AnsiCompareIC( "Dual band (GSM 900 and DCS 1800)" ) == 0 )
- {
- band = DUAL_BAND_MODE;
- }
- else if( as_str.AnsiCompareIC( "Dual band (GSM 850 and PCS 1900)" ) == 0 )
- {
- band = DUAL_BAND_MODE_850_1900;
- }
- return band;
- }
- //---------------------------------------------------------------------------
- bool CSETTINGBAND::Set_SettingBand(unsigned char band, AnsiString &as_str )
- {
- switch( band )
- {
- case BAND_MODE_GSM900:
- as_str = "GSM 900";
- break;
- case BAND_MODE_DCS1800:
- as_str = "DCS 1800";
- break;
- case BAND_MODE_PCS1900:
- as_str = "PCS 1900";
- break;
- case BAND_MODE_GSM850:
- as_str = "GSM 850";
- break;
- case DUAL_BAND_MODE:
- as_str = "Dual band (GSM 900 and DCS 1800)";
- break;
- case DUAL_BAND_MODE_850_1900:
- as_str = "Dual band (GSM 850 and PCS 1900)";
- break;
- default:
- return false;
- }
- return true;
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- int CSETTINGBAND::Get_SettingPlmnSelection( AnsiString as_str )
- {
- int plmn_sel;
- if( as_str.AnsiCompareIC( "Manual" ) == 0 )
- {
- plmn_sel = ARG1_PLMN_SELECTION_MANUAL;
- }
- else if( as_str.AnsiCompareIC( "Automatic" ) == 0 )
- {
- plmn_sel = ARG1_PLMN_SELECTION_AUTO;
- }
- return plmn_sel;
- }
- //---------------------------------------------------------------------------
- bool CSETTINGBAND::Set_SettingPlmnSelection(unsigned char plmn_sel, AnsiString &as_str )
- {
- switch( plmn_sel )
- {
- case ARG1_PLMN_SELECTION_MANUAL:
- as_str = "Manual";
- break;
- case ARG1_PLMN_SELECTION_AUTO:
- as_str = "Automatic";
- break;
- default:
- return false;
- }
- return true;
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- int CSETTINGBAND::Get_SettingMsClass( AnsiString as_str )
- {
- int ms_class;
- if( as_str.AnsiCompareIC( "Class CC" ) == 0 )
- {
- ms_class = ARG1_MOBILE_CLASS_CC;
- }
- else if( as_str.AnsiCompareIC( "Class CG" ) == 0 )
- {
- ms_class = ARG1_MOBILE_CLASS_CG;
- }
- else if( as_str.AnsiCompareIC( "Class B(GSM)" ) == 0 )
- {
- ms_class = ARG1_MOBILE_CLASS_BGSM;
- }
- else if( as_str.AnsiCompareIC( "Class B(GPRS)" ) == 0 )
- {
- ms_class = ARG1_MOBILE_CLASS_BGPRS;
- }
- return ms_class;
- }
- //---------------------------------------------------------------------------
- bool CSETTINGBAND::Set_SettingMsClass( unsigned char ms_class, AnsiString &as_str )
- {
- switch( ms_class )
- {
- case ARG1_MOBILE_CLASS_CC:
- as_str = "Class CC";
- break;
- case ARG1_MOBILE_CLASS_CG:
- as_str = "Class CG";
- break;
- case ARG1_MOBILE_CLASS_BGSM:
- as_str = "Class B(GSM)";
- break;
- case ARG1_MOBILE_CLASS_BGPRS:
- as_str = "Class B(GPRS)";
- break;
- default:
- return false;
- }
- return true;
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- int CSETTINGBAND::Get_SettingGprsAttachMode( AnsiString as_str )
- {
- int gprs_attach_mode;
- if( as_str.AnsiCompareIC( "Auto" ) == 0 )
- {
- gprs_attach_mode = ARG1_GPRS_ATTACH_AUTO;
- }
- else if( as_str.AnsiCompareIC( "Not auto" ) == 0 )
- {
- gprs_attach_mode = ARG1_GPRS_ATTACH_NOTAUTO;
- }
- return gprs_attach_mode;
- }
- //---------------------------------------------------------------------------
- bool CSETTINGBAND::Set_SettingGprsAttachMode( unsigned char gprs_attach_mode, AnsiString &as_str )
- {
- switch( gprs_attach_mode )
- {
- case ARG1_GPRS_ATTACH_AUTO:
- as_str = "Auto";
- break;
- case ARG1_GPRS_ATTACH_NOTAUTO:
- as_str = "Not auto";
- break;
- default:
- return false;
- }
- return true;
- }
- //===========================================================================
- void CSETTINGBAND::REQ_Reset_NVRAM_Data( void )
- {
- setting_band_ptr = this;
- g_bIsRunning = true;
- NVRAMMan->ConfirmCallback = ::CNF_ResetNVRAMData;
- NVRAMMan->REQ_ResetNVRAMData_Start("NVRAM_EF_RAC_PREFERENCE_LID");
- }
- //-------------------------------------
- void CSETTINGBAND::CNF_ResetNVRAMData( void )
- {
- if (!g_bIsRunning)
- {
- return;
- }
- E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
- Confirm(state);
- }
- //===========================================================================
- ///////////////////////// Global information //////////////////////////////
- //===========================================================================
- E_METAAPP_RESULT_T CSETTINGBAND::Get_ConfirmState(void)
- {
- return m_eConfirmState;
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void CSETTINGBAND::Get_RacPreference(S_NVRAM_EF_RAC_PREFERENCE_T &rac_preference)
- {
- rac_preference = m_sNvramEfRacPreference;
- }
- //----------------------------------------------------------------------------
- void CSETTINGBAND::Set_RacPreference(S_NVRAM_EF_RAC_PREFERENCE_T rac_preference)
- {
- m_sNvramEfRacPreference = rac_preference;
- }