⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmihomezone.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*******************************************************************************

					CONDAT (UK)

********************************************************************************                                                                              

 This software product is the property of Condat (UK) Ltd and may not be
 disclosed to any third party without the express permission of the owner.                                 
                                                                              
********************************************************************************

 $Project name:	Basic MMI                                                      
 $Project code:	BMI                                                            
 $Module:		
 $File:		    MmiHomezone.c
 $Revision:		1.0                                                       
                                                                              
 $Author:		Condat(UK)                                                         
 $Date:		    15/02/02                                                      
                                                                               
********************************************************************************
                                                                              
 Description: Homezone functionality in MMI
 
   
                        
********************************************************************************

 $History: MmiHomezone.c

	15/02/02			Original Condat(UK) BMI version.
	28/05/02			Latest Condat(UK) BMI version
	   
 $End

*******************************************************************************/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#if defined (NEW_FRAME)

#include "typedefs.h"
#include "vsi.h"
#include "pei.h"
#include "custom.h"
#include "gsm.h"

#else

#include "stddefs.h"
#include "custom.h"
#include "gsm.h"
#include "vsi.h"

#endif
#include "p_sim.h"


#include "mfw_sys.h"

#include "mfw_mfw.h"
#include "mfw_win.h"
#include "mfw_kbd.h"
#include "mfw_edt.h"
#include "mfw_lng.h"
#include "mfw_icn.h"
#include "mfw_phb.h"
#include "mfw_sim.h"
#include "mfw_nm.h"
#include "ksd.h"
#include "psa.h"
#include "mfw_sms.h"
#include "mfw_smsi.h"
#include "mfw_mnu.h"
#include "mfw_sat.h"
#include "mfw_tim.h"
#include "mfw_cphs.h"

#include "MmiMmi.h"
#include "MmiDummy.h"
#include "MmiDialogs.h"
#include "MmiLists.h"

#include "MmiMain.h"
#include "MmiStart.h"
#include "MmiPins.h"
#include "MmiMenu.h"
#include "MmiSoftKeys.h"
#include "MmiSounds.h"
#include "MmiCall.h"

#include "MmiBookController.h"

#include "MmiIdle.h"
#include "MmiIcons.h"
#include "MmiNetwork.h"
#include "MmiSmsBroadcast.h"
#include "MmiHomezone.h"

#include "cus_aci.h"
#include "p_sim.h"
#include "pcm.h"

#undef	TRACE_MMIHOMEZONE

T_homezone_data		homezoneData;
extern T_SMSCB_DATASTORE g_smscb_data; /* storage for Cell Broadcast lists */


/*******************************************************************************

LOCALLY REFERENCED FUNCTIONS

*******************************************************************************/

void		homezoneReadParams();
void		homezoneLocate();
static U32	calculateDecimal( char *string, int length );
static U32	readHexFromSimfile( UBYTE *simFile, int length );
static void	writeHexToSimfile( UBYTE *simFile, U32 value, int length );

/*******************************************************************************

 $Function:    	homezoneInit

 $Description:	Initialise homezone data structure.  Reset the recent cache.
 
 $Returns:		

 $Arguments:
*******************************************************************************/

void homezoneInit()
{
	T_homezone_data	*data			= &homezoneData;
	USHORT cacheIndex;
	
	TRACE_FUNCTION("homezoneInit()");

	/* Set all data to 0 */

	memset((UBYTE *)data, 0, sizeof(T_homezone_data));

	data->current_zone = HZ_NOT_IN_ZONE;									// 0xFF = not in a homezone
	data->recent_cell_index = HZ_RECENT_MAX-1;								// Next entry will loop round & be at start of cache

	/* Set up recent cell cache */
	
	for (cacheIndex = 0; cacheIndex<HZ_RECENT_MAX; cacheIndex++)
	{
		data->recent_cell[cacheIndex] = 0;
		data->recent_cell_zone[cacheIndex] = HZ_NOT_IN_ZONE;
	}

	data->new_cell_res = FALSE;
	
	return;
}

			
/*******************************************************************************

 $Function:    	homezoneReadSim

 $Description:	Read homezone data in from SIM.  Checks to see if conditions (SIM,
 				network) are correct for homezone; switches it off if not.
 
 $Returns:		None.

 $Arguments:	read_again	- if this is HZ_READ_ONCE_ONLY, then SIM fields will not
 					be read in again if they have already been read in once.
 					If this is HZ_READ_SIM_AGAIN, they will be read in anyway.
 					
*******************************************************************************/

void homezoneReadSim(UBYTE read_again)
{
	T_homezone_data		*data = &homezoneData;
	char IMSI[17];
	char MNC_MCC[6];
	T_ACI_RETURN result;
	USHORT				networkIndex;
	UBYTE				networkOK;
	USHORT				tries;

	/* Check if homezone is switched off */
	
	if (data->received == HZ_RECEIVED_HZ_OFF)
		return;

	/* SPR877 - If read_again specifies that SIM data should not be re-read, exit from function
	 * provided we have read it once. */
	 
	if (read_again == HZ_READ_ONCE_ONLY && data->received & HZ_RECEIVED_SIMDATA)
		return;
	
	TRACE_FUNCTION("homezoneReadSim()");

	/* Check if network operator is in list */

	networkOK = FALSE;

	tries = 0;
	
	while ((result = qAT_PlusCIMI(CMD_SRC_LCL, IMSI)) != AT_CMPL  && tries < 5)
	{
		tries++;
	}
		
	strncpy(MNC_MCC, IMSI, 5);
	MNC_MCC[5] =0;	//terminate string

#ifdef TRACE_MMIHOMEZONE
	TRACE_EVENT_P1("MNC_MCC: %s", (char *)MNC_MCC);
#endif

	for (networkIndex=0; networkIndex<HZ_PERMITTED_NETWORKS; networkIndex++)
	{
		if (!strncmp((char *)MNC_MCC, homezoneMNC_MCC[networkIndex],5))
		{
#ifdef TRACE_MMIHOMEZONE
			TRACE_EVENT_P1("Matches entry %d", networkIndex);
#endif
			networkOK = TRUE;
		}
	}

	/* Attempt to read first sim field */

	if (networkOK)
	{
		if (!Read_Sim(HZ_SIM_PARAMETERS, 0, HZ_SIM_PARAMETERS_SIZE, data->buffer))
		{
			TRACE_EVENT("SIM read error 1: Homezone OFF");	/* SIM field not present, switch off homezone */
			data->received = HZ_RECEIVED_HZ_OFF;
		}
	}
	else
	{
		TRACE_EVENT("Wrong network: Homezone OFF");		/* Network not in list, switch off homezone */
		data->received = HZ_RECEIVED_HZ_OFF;
	}
	
	return;
}


/*******************************************************************************

 $Function:    	homezoneReadSimCb

 $Description:	Callback, called when read sim has occurred.  Fills up the homezone
 				data structure with the appropriate values retrieved from SIM.
 
 $Returns:		None.

 $Arguments: 	field - the SIM field that was just read
 				record - the record in the SIM field that was read
 				result - the result code returned - 0 for successful.
*******************************************************************************/

void homezoneReadSimCb(USHORT field, USHORT record, USHORT result)
{
	T_homezone_data	*data				= &homezoneData;
	T_homezone		*homezone			= data->homezone;
	UBYTE			*simFile;
	USHORT			fileIndex;
	USHORT			hzIndex;
	UBYTE			keepLooking;

	TRACE_FUNCTION("homezoneReadSimCb()");
	
#ifdef TRACE_MMIHOMEZONE
	TRACE_EVENT_P2("Have just read SIM file: %x record %d", field, record);
#endif

	/* Read in general homezone data.  If reading first SIM field fails, switch homezone off */

	if (field==HZ_SIM_PARAMETERS)
	{	
		if (result)
		{
			TRACE_EVENT("SIM read error 2: Homezone OFF");
			data->received = HZ_RECEIVED_HZ_OFF;
			return;
		}
		homezoneReadParams();
		/*homezoneActivateCB();*/				/* Switch on cell broadcast */
		/* SH - this is already done at startup */
		record = HZ_CACHE_MAX;
	}
	
	/* Read in records for each homezone cache */

	if (field>HZ_SIM_PARAMETERS && !result)
	{
		hzIndex = field - HZ_SIM_CELL_CACHE;
		simFile = data->buffer2;
		fileIndex = 0;
		
		homezone[hzIndex].lac[record-1] = readHexFromSimfile(&simFile[fileIndex],2);
		fileIndex+=2;
		homezone[hzIndex].cid[record-1] = readHexFromSimfile(&simFile[fileIndex],2);

#ifdef TRACE_MMIHOMEZONE
		TRACE_EVENT_P2("read lac = %x, cid = %x", homezone[hzIndex].lac[record-1], homezone[hzIndex].cid[record-1]);
#endif
	}

	/* Read in the next record */

	keepLooking = TRUE;
	
	while (keepLooking)
	{
		if (record==HZ_CACHE_MAX || result)
		{
			field++;												// Look at next field
			record = 1;
		}
		else
			record++;

		hzIndex = field-HZ_SIM_CELL_CACHE;

		if (hzIndex==HZ_ZONES_MAX)
		{
			keepLooking = FALSE;
			/* Have read all sim data, set flag so icon etc will be updated */
			data->received |= HZ_RECEIVED_SIMDATA;
		}
		else if (homezone[hzIndex].active)
		{
			keepLooking = FALSE;
			
#ifdef TRACE_MMIHOMEZONE
	//TRACE_EVENT_P3("HZ READ HZ %d field %X record %d", hzIndex, field, record);
#endif
			if (!Read_Sim_Record(field, record, HZ_SIM_CELL_CACHE_SIZE, data->buffer2))
			{
				TRACE_EVENT("SIM reading error!");
			}
		}
	}
	
	return;
}


/*******************************************************************************

 $Function:    	homezoneReadParams

 $Description:	Decode the homezone parameters from the first SIM field
 
 $Returns:		None.

 $Arguments:	None.
*******************************************************************************/

void homezoneReadParams()
{
	T_homezone_data	*data				= &homezoneData;
	T_homezone		*homezone			= data->homezone;
	UBYTE			*simFile;
	USHORT			fileIndex;
	USHORT			tagIndex;
	USHORT			hzIndex;
	char			character;

	TRACE_FUNCTION("homezoneReadParams()");
	
	simFile = data->buffer;
	fileIndex = HZ_SIM_FIRST_ZONE;										// Point to the first homezone data

	for (hzIndex=0; hzIndex<HZ_ZONES_MAX; hzIndex++)					// For each homezone...
	{
		homezone[hzIndex].zoneID = simFile[fileIndex];				// Read in the various parameters
		fileIndex++;
		
		homezone[hzIndex].X = readHexFromSimfile(&simFile[fileIndex],4);
		fileIndex += 4;
		homezone[hzIndex].Y = readHexFromSimfile(&simFile[fileIndex],4);
		fileIndex += 4;
		homezone[hzIndex].Rsquared = readHexFromSimfile(&simFile[fileIndex],4);
		fileIndex += 4;
		
		homezone[hzIndex].active = (BOOL) (simFile[fileIndex] & HZ_ACTIVE_FLAG)/HZ_ACTIVE_FLAG;
		homezone[hzIndex].cityzone = (BOOL) (simFile[fileIndex] & HZ_CITYZONE_FLAG)/HZ_CITYZONE_FLAG;
		fileIndex++;
					
		/* Read in the 12-character tag name */
		
		for (tagIndex = 0; tagIndex<HZ_NAME_LENGTH; tagIndex++)					
		{
			character = (char) simFile[fileIndex];
			fileIndex++;
			if (character<32 || character>127)
				character = 0;
			homezone[hzIndex].Tag[tagIndex] = character;
		}
		homezone[hzIndex].Tag[HZ_NAME_LENGTH] = 0;								// Make sure tag is null-terminated

#ifdef TRACE_MMIHOMEZONE
			TRACE_EVENT_P1("Homezone %d:", hzIndex);
			TRACE_EVENT_P1("ID: %d", homezone[hzIndex].zoneID);
			TRACE_EVENT_P1("Active: %d", (UBYTE)homezone[hzIndex].active);
			TRACE_EVENT_P1("Cityzone: %d", (UBYTE)homezone[hzIndex].cityzone);
			TRACE_EVENT_P1("X: %X", homezone[hzIndex].X);
			TRACE_EVENT_P1("Y: %X", homezone[hzIndex].Y);
			TRACE_EVENT_P1("Rsquared: %X", homezone[hzIndex].Rsquared);
		TRACE_EVENT_P1("Homezone name: %s", homezone[hzIndex].Tag);
#endif

	}

	return;
}


/*******************************************************************************

 $Function:    	homezoneWriteSim

 $Description:	Write homezone data to the SIM
				SPR 877 - SH - now just writes a single record
 
 $Returns:		None.

 $Arguments:	cache, record
********************************************************************************/

void homezoneWriteSim(USHORT field, USHORT record)
{
	T_homezone_data	*data				= &homezoneData;
	USHORT hzIndex;
	UBYTE *simFile;
	USHORT fileIndex;

	/* Check if homezone is already switched off */

	if (data->received==HZ_RECEIVED_HZ_OFF)
		return;
	
	TRACE_FUNCTION("homezoneWriteSim()");

	hzIndex = field-HZ_SIM_CELL_CACHE;
	
#ifdef TRACE_MMIHOMEZONE
	TRACE_EVENT_P4("HZ WRITE field: %X record %d lac %X cid %X", field, record, data->homezone[hzIndex].lac[record-1], data->homezone[hzIndex].cid[record-1]);
#endif

	if (data->homezone[hzIndex].active)
	{	
		simFile = data->buffer2;
		fileIndex = 0;
		writeHexToSimfile(&simFile[fileIndex], data->homezone[hzIndex].lac[record-1], 2 );
		fileIndex += 2;
		writeHexToSimfile(&simFile[fileIndex], data->homezone[hzIndex].cid[record-1], 2 );
	}

	if (!Write_Sim_Record(field, record, HZ_SIM_CELL_CACHE_SIZE, data->buffer2))
	{
		TRACE_EVENT("SIM writing error!");
	}
	return;
}


/*******************************************************************************

 $Function:    	homezoneWriteSimCb

 $Description:	Write homezone data to the SIM.  This function is called after a previous
 				SIM write (or, in the initial case, by homezoneWriteSim above).
				SPR877 - SH - Previous functionality no longer required here.
 
 $Returns:		None.

 $Arguments:	field - the SIM field that is to be written
 				record - the SIM record that is to be written
 				result - the result of the last write attempt
*******************************************************************************/

void homezoneWriteSimCb(USHORT field, USHORT record, USHORT result)
{
	T_homezone_data	*data				= &homezoneData;
	T_homezone		*homezone			= data->homezone;
	USHORT			hzIndex;
	UBYTE			*simFile;
	USHORT			fileIndex;
	UBYTE			keepLooking;

	TRACE_FUNCTION("homezoneWriteSimCb()");

#ifdef TRACE_MMIHOMEZONE
	TRACE_EVENT_P1("RESULT: %d", result);
#endif

	return;
}


/*******************************************************************************

 $Function:    	homezoneCBData

 $Description:	Make sure correct homezone CB channel is set up and activate CB
 
 $Returns:		None.

 $Arguments:	message		- The text of the cell broadcast message
*******************************************************************************/

void homezoneActivateCB(void)
{
	T_homezone_data	*data				= &homezoneData;
	USHORT index;
	UBYTE stopSearch;
	USHORT emptyID;

	/* Check if homezone is already switched off */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -