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

📄 atbpbgi.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 2 页
字号:
#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 <stdio.h>
#include <string.h>

#include "mfw_mfw.h"
#include "mfw_sys.h"
#include "mfw_phb.h"
#include "mfw_cm.h"
#include "mfw_ss.h"

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

#include "ATBPb.h"
#include "ATBPbGI.h"


/*******************************************************************************
 * LOCAL FUNCTION PROTOTYPES
 *
 ******************************************************************************/

void GI_alpha_AlphaToAscii(T_MFW_PHB_TEXT *ascii, T_PB_ALPHA *alpha, SHORT max_len);
void GI_alpha_AsciiToAlpha(T_PB_ALPHA *alpha, T_MFW_PHB_TEXT *ascii, SHORT max_len);
T_PB_INDEX GI_index_Convert(UBYTE mode);


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

 $Function:    	GI_pb_GetPhonebook
 
 $Description:	Checks to see which file system is selected

 $Returns:		MFW_PHB_OK			Action completed OK.
				MFW_PHB_FAIL		File write encountered an error

 $Arguments:	intphonebook		Place to store type of phonebook selected
 									(TRUE for FFS)
 
*******************************************************************************/

T_MFW	GI_pb_GetPhonebook(UBYTE *intphonebook)
{
	PB_RET result;
	T_MFW ret;
	T_PB_TYPE current_type;

	result = ATB_pb_GetPhonebook(PB_BOOK_DEFAULT, &current_type);

	if (current_type==PB_TYPE_FFS)
		*intphonebook = TRUE;
	else
		*intphonebook = FALSE;
	
	if (result==PB_OK)
		ret = MFW_PHB_OK;
	else
		ret = MFW_PHB_FAIL;

	return ret;
}


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

 $Function:    	GI_pb_SetPhonebook
 
 $Description:	Selects file system
 
 $Returns:		MFW_PHB_OK			Action completed OK.
				MFW_PHB_FAIL		File write encountered an error

 $Arguments:	intphonebook		TRUE if FFS is to be used
 
*******************************************************************************/

T_MFW	GI_pb_SetPhonebook(UBYTE intphonebook)
{
	PB_RET result;
	T_MFW ret;
	T_PB_TYPE current_type;

	if (intphonebook)
		current_type = PB_TYPE_FFS;
	else
		current_type = PB_TYPE_SIM;
	
	result = ATB_pb_SetPhonebook(PB_BOOK_DEFAULT, current_type);
	
	if (result==PB_OK)
		ret = MFW_PHB_OK;
	else
		ret = MFW_PHB_FAIL;

	return ret;
}


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

 $Function:    	GI_pb_Initialise
 
 $Description:	Initialise an instance of phonebook.  Dynamically allocates a record
 				cache in RAM.  Creates the necessary file(s) if they do not already exist.
 				Sorts the phonebook by name and by number, creating the appropriate
 				index tables.
 				
 $Returns:		MFW_PHB_OK
 				MFW_PHB_FAIL

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

T_MFW	GI_pb_Initialise(void)
{
	PB_RET result;
	T_MFW ret;

	tracefunction("GI_pb_Initialise");

	result = ATB_pb_Initialise(PB_BOOK_DEFAULT, PB_TYPE_FFS, PB_RECORDS_MAX,
		PB_CACHE_MAX, PB_ALPHATAG_MAX, PB_NUMBER_MAX, PB_EXT_MAX);

	switch(result)
	{
		case PB_OK:
			ret = MFW_PHB_OK;
			break;
		case PB_EXCT:
			ret = MFW_PHB_OK;
			break;
		case PB_BOOKALREADYEXISTS:
			ret = MFW_PHB_FAIL;
			break;
	}

	return ret;
}


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

 $Function:    	GI_pb_Exit
 
 $Description:	Frees memory associated with phonebook.  To be called when the
 				phonebook is no longer required, or at shutdown.

 $Returns:		MFW_PB_OK		Action completed OK.

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

T_MFW	GI_pb_Exit(void)
{
	tracefunction("GI_pb_Exit");

	ATB_pb_Exit(PB_BOOK_DEFAULT);
	return MFW_PHB_OK;
}


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

 $Function:    	GI_pb_Info
 
 $Description:	Returns information about the phonebook, which will be returned
 				in the data structure pointed to by status.  The caller must
 				allocate the T_MFW_PHB_STATUS structure.

 $Returns:		MFW_PB_OK		Action completed OK.

 $Arguments:	status			Data structure to contain phonebook info
 
*******************************************************************************/

void GI_pb_Info(T_MFW_PHB_STATUS *status)
{
	T_PB_INFO info;

	tracefunction("GI_pb_Info");

	ATB_pb_Info(PB_BOOK_DEFAULT, &info);
	
	status->book = PHB_IPB;
	status->max_entries = (UBYTE)info.records_max;
	status->used_entries = (UBYTE)info.records_used;
	status->avail_entries = (UBYTE)info.records_free;
	status->tag_len = PHB_MAX_LEN;

	return;
}


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

 $Function:    	GI_pb_Status
 
 $Description:	Returns whether or not the phonebook is busy.  If so, stat will contain
 				PHB_BUSY, otherwise PHB_READY.

 $Returns:		None

 $Arguments:	stat			UBYTE to contain status information
 
*******************************************************************************/

void GI_pb_Status(UBYTE *stat)
{
	PB_RET result;
	
	tracefunction("GI_pb_Status");

	result = ATB_pb_Status(PB_BOOK_DEFAULT);
	
	return;
}



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

 $Function:    	GI_pb_WriteRec
 
 $Description:	Writes a record to the physical position index.  If the index is
 				0, a new record is added, otherwise the previous
 				record at that position is overwritten.

 $Returns:		MFW_PHB_OK
 				MFW_PHB_FAIL
 				MFW_PHB_FULL

 $Arguments:	entry	The phonebook entry to write
 
*******************************************************************************/

T_MFW	GI_pb_WriteRec(T_MFW_PHB_ENTRY *entry)
{
	T_MFW ret;
	PB_RET result;
	SHORT	index;
	T_PB_RECORD *record;
	UBYTE *number;

	tracefunction("GI_pb_WriteRec");

	/* Allocate memory for record */

	record = ATB_pb_AllocRec(PB_BOOK_DEFAULT);
	
	/* If the provided index is 0, we must add new record */
	
	if (entry->index==0)
		index = PB_NEW_RECORD;
	else
		index = (SHORT)(entry->index-1);	/* MFW/ACI indices start at 1, ATB indices start at 0 */

	/* Convert name to unicode*/
	
	record->alpha.dcs = entry->name.dcs;
	record->alpha.length = (UBYTE)entry->name.len;
	GI_alpha_AsciiToAlpha(&record->alpha, &entry->name, PHB_MAX_LEN);

	/* Convert number to BCD */

	record->ton_npi = entry->npi & 0x0F;
	record->ton_npi |= (entry->ton<<4);
	
	number = entry->number;

	if (number[0]=='+')
	{
		record->ton_npi &= 0xF0;
		record->ton_npi |= (MFW_TON_INTERNATIONAL<<4);
		number++;
	}

	TRACE_EVENT_P1("ton_npi: %X", record->ton_npi);
  
	ATB_pb_CharToBCD(record->number, (char *)number, PB_NUMBER_MAX);

	/* Write the record */
	
	result = ATB_pb_WriteRec(PB_BOOK_DEFAULT, INDEX_PHYSICAL, index, record);

	/* Free allocated record */

	ATB_pb_FreeRec(PB_BOOK_DEFAULT, record);
	
	switch(result)
	{
		case PB_OK:
			ret = MFW_PHB_OK;
			break;
		case PB_BOOKFULL:
			ret = MFW_PHB_FULL;
			break;
		default:
			ret = MFW_PHB_FAIL;
			break;
	}

	return ret;
}


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

 $Function:    	GI_pb_DeleteRec
 
 $Description:	Deletes a record at a physical position index.

 $Returns:		MFW_PHB_OK
 				MFW_PHB_FAIL
 
 $Arguments:	index		Physical index of the record to delete

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

T_MFW	GI_pb_DeleteRec(UBYTE index)
{
	T_MFW ret;
	PB_RET result;

	tracefunction("GI_pb_DeleteRec");

	/* MFW/ACI indices start at 1, ATB indices start at 0 */

	index--;

	/* Delete record */
	
	result = ATB_pb_DeleteRec(PB_BOOK_DEFAULT, INDEX_PHYSICAL, (SHORT)index);

	switch(result)
	{
		case PB_OK:
			ret = MFW_PHB_OK;
			break;
		default:
			ret = MFW_PHB_FAIL;
			break;
	}

	return ret;	
}


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

 $Function:    	GI_pb_Find
 
 $Description:	Find the nearest match to the supplied record. 

 $Returns:		MFW_PHB_OK
 				MFW_PHB_FAIL

 $Arguments:	mode 			Specifies the sorting for the index list
				index			Place to store the index of the matching record
				num_recs		Number of records to read in
				search_pattern	The string or number to match
				entries			Place to store the resulting list of entries
 
*******************************************************************************/

T_MFW GI_pb_Find(UBYTE mode, UBYTE *index, UBYTE num_recs,  T_MFW_PHB_TEXT *search_pattern, T_MFW_PHB_LIST *entries)
{
	PB_RET result;
	T_MFW ret;
	T_PB_INDEX index_type = GI_index_Convert(mode);
	T_PB_RECORD *record;
	SHORT recs_count;
	SHORT rec_index;
	UBYTE *number;

	tracefunction("GI_pb_Find");

	/* Allocate memory for record */

	record = ATB_pb_AllocRec(PB_BOOK_DEFAULT);

	/* Convert name to unicode, or number to BCD */
		
	if(index_type==INDEX_NAME)
	{
		GI_alpha_AsciiToAlpha(&record->alpha, search_pattern, PB_ALPHATAG_MAX);
	}
    else
    {
    	/* Convert number to BCD */

		number = search_pattern->data;
		
		if (number[0]=='+')
		{
			number++;
		}
      	ATB_pb_CharToBCD(record->number, (char *)number, PB_NUMBER_MAX);
	}

	result = ATB_pb_Find(PB_BOOK_DEFAULT, index_type, record, &rec_index, NULL);
	
	if (result==PB_OK)
	{
		*index = rec_index+1;	/* MFW/ACI indices start at 1, ATB indices start at 0 */
		result = GI_pb_ReadRecList(mode, (UBYTE)(*index), num_recs, entries);
	}

	/* Free allocated record */

	ATB_pb_FreeRec(PB_BOOK_DEFAULT, record);

	
	switch(result)
	{
		case PB_OK:
			ret = MFW_PHB_OK;
			break;
		default:
			ret = MFW_PHB_FAIL;
			break;
	}
	
	return ret;
}

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

 $Function:    	GI_pb_ReadRecList
 
 $Description:	Read in a list of entries.

 $Returns:		MFW_PHB_OK
 				MFW_PHB_FAIL

 $Arguments:	mode 			Specifies the sorting for the index list
				index			Place to store the index of the matching record
				num_recs		Number of records to read in
				entries			Place to store the resulting list of entries
 

⌨️ 快捷键说明

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