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

📄 l1tm_cust_add.c

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

int read_sim_phb(void)
{
	T_MFW_PHB_STATUS status;

	PcCmdStatus.isPcConect=1;
	//check if the sim cark ok
	if((phb_get_mode()==PHB_LOADING)||(phb_get_mode()==MFW_PHB_FAIL))
		return SIM_NOT_REDAY;
	
	tim		= timCreate(win,   100,         (MfwCb)excute_tim_cb);
	command	=READ_SIM_PHB_CMD;
	timStart(tim);
	PcCmdStatus.SimPhbNum=0;
	PcCmdStatus.NvmPhbNum=0;
	i=0;//sim phb data index in one file[0,19]
	InitPcCmdStatus();

	status.book=PHB_ADN;   
	if (phb_get_status(&status)==MFW_PHB_OK)
		PcCmdStatus.nsimphbmax=status.max_entries;
	
	return CMD_RET_OK;
}


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

 $Function:    	read_sim_phb_cb

 $Description:	This function invokes the operation  for creat the simphb file.
 
 $Returns:		

 $Arguments:	 
*******************************************************************************/
static int read_sim_phb_cb(void)
{
	char	simpath[20];
	int 	j=0;//all phb data index
	int		unreadnum=0;
	T_MFW_PHB_ENTRY  l_phb_Shortentry;
char test[20];

MmiTrace("read_sim_phb_cb");
	Sim_PhbData=SimPhbDefaultData;
	
	memset(&l_phb_Shortentry,0,sizeof(T_MFW_PHB_ENTRY));

	//防止sim正忙时,又有命令进来。
	if(PcCmdStatus.isPcCmdRun)
		return CMD_BUSY;
	
	PcCmdStatus.isPcCmdRun=1;
	
	//check if the sim cark ok
	if((phb_get_mode()==PHB_LOADING)||(phb_get_mode()==MFW_PHB_FAIL))
		return return_info(SIM_NOT_REDAY,NULL,0,NULL,0);
	
	if(SIMLoadingPhbk==FALSE){
		GetSIMData();
		SIMLoadingPhbk=TRUE;
	}
	MmiTrace("simTotal");
	MmiTraceInt(SIMTotal);
	
	PcCmdStatus.NvmPhbNum=NVMTotal;
	PcCmdStatus.SimPhbNum=SIMTotal;
	if (SIMTotal==0)
   		return return_info(NO_SIM_PHB,NULL,0,NULL,0);
	
	
	unreadnum=SIMTotal;
	for (j=0;j<PHBKTotal;j++)
	{
		if (l_phb_index[l_phb_sort_index[j].index].phonebook!=SIM_BOOK_SEL)
			continue;
		if (ReadSIMRecord(l_phb_sort_index[j].index,&l_phb_Shortentry)!=TRUE)
			continue;
		
		memcpy(Sim_PhbData.phbdata[i].Name,l_phb_Shortentry.name.data,21);
		memcpy(Sim_PhbData.phbdata[i].Number,l_phb_Shortentry.number,21); 
		unreadnum--;
		if((i==(MAXSIMPHBNUM-1))||(unreadnum==0)){
			i=-1;//for it will be add to 0 hxl changed 2002-12-12
			k++;
			//creat simphb file in the phone	
			sprintf(simpath,"/mmi/PhSimBf%d",k);
			if(ffs_fwrite(simpath,&Sim_PhbData,sizeof(Sim_PhbData) )<0)
				return return_info(FWRITE_FAIL,NULL,0,NULL,0);
			if(unreadnum==0){
				PcCmdStatus.NvmPhbNum=NVMTotal;
				PcCmdStatus.SimPhbNum=SIMTotal;
				return return_info(CMD_COMPLETE_OK,NULL,0,NULL,0);
			}else
				Sim_PhbData=SimPhbDefaultData;

		}
		i++;	

	}
	

	return return_info(CMD_RET_OK,NULL,0,NULL,0);
}

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

 $Function:    	write_nvm_phb_cb

 $Description:	This function creat the timer and start to  excute.
 
 $Returns:		

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

int write_nvm_phb_cb(void)
{
	int	noldfile=0;
	effs_t	effret=1;
	int	loop=3;
	int	nfile=0;
	MmiTrace("write_nvm_phb_cb");
	
	PcCmdStatus.isPcCmdRun=1;

	//如果原先的号码比现在写入的多,需要将多出来的文件写0
    	noldfile= (NVMTotal%72)? ((NVMTotal/72)+1): NVMTotal/72;
	MmiTraceInt(noldfile);
	MmiTraceInt(PcCmdStatus.NvmPhbNum);
	
	while(noldfile-PcCmdStatus.NvmPhbNum>0){
		nfile=PcCmdStatus.NvmPhbNum++;
	MmiTrace("in");
		while((effret!=EFFS_OK)&&(loop>0)){
			effret=ffs_remove(PBTable[nfile]);
			if(effret!=EFFS_OK){
				Sleep_wait(100);
				loop--;
			}
		}
		ConfigPhbkReset();  
              flash_PBwrite(PBTable[nfile]);
              noldfile--;
	}
	
	NVMLoadingPhbk=FALSE;
	
	InitPcCmdStatus();

	return 1;
}

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

 $Function:    	write_sim_phb

 $Description:	This function creat the timer and start to  excute.
 
 $Returns:		

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

int write_sim_phb(void)
{
	//check if the sim cark ok
	if((phb_get_mode()==PHB_LOADING)||(phb_get_mode()==MFW_PHB_FAIL))
		return SIM_NOT_REDAY;
	
	SIMLoadingPhbk=FALSE; //使按键浏览时显示sim更新后的数据
	
	tim		= timCreate(win,   100,         (MfwCb)excute_tim_cb);
	command	=WRITE_SIM_PHB_CMD;
	timStart(tim);

//	i=MAXSIMPHBNUM-1;//phb index in simphb file(0 19)
       i=MAXSIMPHBNUM;//chenjun changed ,0401,because we use Sim_PhbData.phbdata[i-1]
	
	InitPcCmdStatus();

	return 1;
}


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

 $Function:    	write_sim_phb_cb

 $Description:	This function invokes the operation  for update the simphb file.
 
 $Returns:		

 $Arguments:	 
*******************************************************************************/
int write_sim_phb_cb(void)
{
	UWORD16 nret;
	effs_t ffsret;
	T_MFW mfwret;
	T_MFW_PHB_STATUS status;
	UBYTE	simphbnum;
	fd_t	fdret,fdi;
	char	simpath[20];
	static UBYTE	unwritenum=0;
	T_MFW_PHB_ENTRY entries;
	UBYTE	bookType=0;
	char test[10];
	UBYTE	j=0;
	

//	char buf[50];//chenjun for debug ,0331

	MmiTrace("in write_sim_phb_cb");

		
	//防止sim正忙时,又有命令进来。
	if(PcCmdStatus.isPcCmdRun)
		return CMD_BUSY;
	
	PcCmdStatus.isPcCmdRun=1;

	//第一次执行时,先将sim卡电话本清空
	if(k==0){
		//delete the sim phb all,当sim原为空时,发清空指令,会重启
	  	status.book=PHB_ADN;   
	 	if (phb_get_status(&status)==MFW_PHB_OK)
	  	{
			OldNum=status.used_entries;//chenjun add 0331
	   		if (status.used_entries>0){
    				bookType= bookActiveBook(WRITE);
        			phb_delete_book(bookType);//chenjun add 0408				
	   		}
	 	}else
			return return_info(READ_SIM_PHB_FAIL,NULL,0,NULL,0);
		
		MmiTrace("PcCmdStatus.SimPhbNum");
		MmiTraceInt(PcCmdStatus.SimPhbNum);
        	
		if(PcCmdStatus.SimPhbNum==0)//chenjun del 0331
			{
			if (status.used_entries>0)                   //chenjun 0331 add this conditions
				{
				bookType= bookActiveBook(WRITE);//chenjun 0409
				if(phb_delete_book(bookType)==MFW_PHB_OK)
					{
//					  dspl_TextOut(8, 80, 0, "clear");
				         return CMD_RET_OK;
					}
				else return WRITE_SIM_PHB_FAIL; 
				}
			    //phb_delete_book(bookType);//chenjun 0331 del
			//return return_info(NO_SIM_PHB,NULL,0,NULL,0);//chenjun 0331 del
			}
		
		unwritenum=PcCmdStatus.SimPhbNum;//chenjun 0331,does this right when set it By tell_simphb_num()?

	//	memset(buf,0,50);
	//	sprintf(buf,"num %d",PcCmdStatus.SimPhbNum);
	//	dspl_TextOut(8, 64, 0, buf);
	}
	

#if 0	 //chenjun add 0408
	//若全部执行完,退出
	if(unwritenum==0){
//		dspl_TextOut(8, 64, 0, "uwn=0");
		//删除最后的文件
	/*	if(k>0){
			MmiTrace("chenjun ffs_rm");
			sprintf(simpath,"/mmi/PhSimBf%d",k);
			ffs_remove(simpath);
		}
	*/  //chenjun 0331 move these code to the coming lines 		
		//删除后面的记录
	  	status.book=PHB_ADN;   
	 	if (phb_get_status(&status)==MFW_PHB_OK)
	  	{
		//	if(j=(status.max_entries-20*(k-1)-i-1)){//this is wrong, because i++ lead to j--, but j must ++ here ,chenjun 0331
	   	//	for (j=20*(k-1)+i+1;j<status.max_entries;j++){
	   	       j=(20*(k-1)+i+1);//chenjnu 0331 add
		       if(j<=OldNum/*status.max_entries*/){//chenjun 0331 add
//		              memset(buf,0,50);
//		              sprintf(buf,"j m %d,%d",j,OldNum/*status.max_entries*/);
//		              dspl_TextOut(8, 64, 0, buf);
        			if(phb_delete_entry(status.book, j, &status)!=MFW_PHB_OK)
						return WRITE_SIM_PHB_FAIL;				
				i++; 
				return CMD_RET_OK;//chenjun 0331,after this call, must call SetDelFlag()?    	      
			}
			else
			{
				k=0;
				i=MAXSIMPHBNUM;
//				dspl_TextOut(8, 64, 0, "end");
				MmiTrace("end");
			
				return return_info(CMD_COMPLETE_OK,NULL,0,NULL,0);
			}
	 	}
		else return return_info(READ_SIM_PHB_FAIL,NULL,0,NULL,0);	
//		return return_info(CMD_RET_OK,NULL,0,NULL,0);
		
	}
#endif    //chenjun add 0408

	


	//需要打开并读取新文件
//	if(i==(MAXSIMPHBNUM-1))//chenjun 0401 changed
      if(i==(MAXSIMPHBNUM ))     //chenjun ,i=0,save 1 i=1;...;i=18, save 19 i=19;but there is 20 entries
	{
		//删除已读过的文件
/*		if(k>0)
		{
			sprintf(simpath,"/mmi/PhSimBf%d",k);
			ffs_remove(simpath);
		}
*///chenjun 0331 move these code to the coming lines 		
		//打开新文件
		k++;
		i=0;
		//read file 	
		Sim_PhbData=SimPhbDefaultData;		
		sprintf(simpath,"/mmi/PhSimBf%d",k);
 		if(ffs_fread(simpath,&Sim_PhbData, sizeof(Sim_PhbData))<0)
 			{
 			MmiTrace("Into ffs_fread failed");
			
			//删除已读过的文件
		      if(k>0)
			        {
				     sprintf(simpath,"/mmi/PhSimBf%d",k);
				     ffs_remove(simpath);
			       }
			        return return_info(FREAD_FAIL,NULL,0,NULL,0);//chenjun add
 			}
		      if(k>0)
			        {
//			            sprintf(buf,"into k>0,rmf %d",k);
//			            MmiTrace(buf);
				     sprintf(simpath,"/mmi/PhSimBf%d",k);
				     ffs_remove(simpath);
			       }			        
	}

	
	//将文件中的记录一条条写入sim的20*(k-1)+i 处。
	i++;
	memset(&entries, 0, sizeof(entries));
	entries.book=PHB_ADN;
	entries.index=20*(k-1)+i;//does the index begin from 1?not 0?   
	memcpy(entries.name.data, Sim_PhbData.phbdata[i-1].Name, MAXNAMELEN);
	entries.name.len =wstrlen((char*)entries.name.data);
	memcpy(entries.number, Sim_PhbData.phbdata[i-1].Number, MAXNUMLEN);
	
	MmiTrace(entries.name.data);
	MmiTrace(entries.number);
	MmiTraceInt(entries.index);
	
	
	if(phb_store_entry(PHB_ADN,&entries,&status)!=MFW_PHB_OK)
		return return_info(WRITE_SIM_PHB_FAIL,NULL,0,NULL,0);
	unwritenum--;
//	dspl_TextOut(8, 100, 0, "uwn --");
	
	return CMD_RET_OK;
	
}


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

 $Function:    	tell_simphb_num

 $Description:	This function is pc tell phone,how many phb num need to write into sim card
 
 $Returns:		

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

void tell_simphb_num(UWORD16 value)
{
MmiTrace("tell_simphb_num");
	PcCmdStatus.SimPhbNum=(UWORD8)value;
	MmiTraceInt(PcCmdStatus.SimPhbNum);

}

void tell_nvmphb_num(UWORD16 value)
{
MmiTrace("tell_nvmphb_num");
	PcCmdStatus.NvmPhbNum=(UWORD8)value;
	MmiTraceInt(PcCmdStatus.NvmPhbNum);
	
	InitPcCmdStatus();
	
	tim		= timCreate(win,   100,         (MfwCb)excute_tim_cb);
	command	=WRITE_NVM_PHB_CMD;
	timStart(tim);
}

int read_new_sms(void)
{
       
	MmiTrace("read_new_sms");
	i=0;  //sms需要
	PcCmdStatus.nSimSmsFile=0;

	InitPcCmdStatus();
	
	//check if the sim cark ok
	if (!smsidle_get_ready_state())
		return return_info(SIM_NOT_REDAY,NULL,0,NULL,0);
	//申请空间,并赋初值
	if ( ( psmsidx = (T_MFW_SMS_IDX *) ALLOC_MEMORY(  memory.total*sizeof(T_MFW_SMS_IDX)) ) == NULL )
		return return_info( ALLOC_MEM_FAIL,NULL,0,NULL,0);
	if ( ( pWriteSmsdata = (UBYTE *) ALLOC_MEMORY( 1024) ) == NULL )
		return return_info( ALLOC_MEM_FAIL,psmsidx,  memory.total*sizeof(T_MFW_SMS_IDX),NULL,0);
	memset(psmsidx,0, memory.total*sizeof(T_MFW_SMS_IDX));
	memset(pWriteSmsdata,0,1024);
	
	//读sms的index
	unreadsms=sms_index_list(MFW_SMS_UNREAD,psmsidx,MAX_MESSAGES);
	if(unreadsms==0){
		return return_info( NO_SIM_SMS,psmsidx,  memory.total*sizeof(T_MFW_SMS_IDX),pWriteSmsdata,1024);
	}
	//排序
	//SortSms(unreadsms,psmsidx);//因T_MFW_SMS_MSG空间申请不到,不排序了
		
	tim		= timCreate(win,   100,         (MfwCb)excute_tim_cb);
	command	=READ_NEW_SMS_CMD;
	timStart(tim);


	return CMD_RET_OK;
}

int read_sim_sms(void)
{
       
	MmiTrace("read_sim_sms");
	i=0;  //sms需要
	PcCmdStatus.nSimSmsFile=0;

	PcCmdStatus.isPcConect=1;
	InitPcCmdStatus();
	
	//check if the sim cark ok
	if (!smsidle_get_ready_state())
		return return_info(SIM_NOT_REDAY,NULL,0,NULL,0);
	
MmiTraceInt(memory.total);
	if(memory.total==0)
		return return_info(NO_SIM_SMS,NULL,0,NULL,0);
	
	//申请空间,并赋初值
	if ( ( psmsidx = (T_MFW_SMS_IDX *) ALLOC_MEMORY( memory.total*sizeof(T_MFW_SMS_IDX)) ) == NULL )
		return return_info( ALLOC_MEM_FAIL,NULL,0,NULL,0);
	if ( ( pWriteSmsdata = (UBYTE *) ALLOC_MEMORY( 1024) ) == NULL )
		return return_info( ALLOC_MEM_FAIL,psmsidx,memory.total*sizeof(T_MFW_SMS_IDX),NULL,0);
	memset(psmsidx,0,memory.total*sizeof(T_MFW_SMS_IDX));
	memset(pWriteSmsdata,0,1024);
	
	//读sms的index
	unreadsms=sms_index_list(MFW_SMS_ALL,psmsidx,memory.total);
	if(unreadsms==0){
		return return_info( NO_SIM_SMS,psmsidx,memory.total*sizeof(T_MFW_SMS_IDX),pWriteSmsdata,1024);
	}
	//排序
	//SortSms(unreadsms,psmsidx);//因T_MFW_SMS_MSG空间申请不到,不排序了

	PcCmdStatus.nsimsmsmax=memory.total;
	tim		= timCreate(win,   100,         (MfwCb)excute_tim_cb);
	command	=READ_SIM_SMS_CMD;

⌨️ 快捷键说明

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