static char PhoneHandleCall(char *msg) { u8 phonebuff[20]; u8 atcmd[50]; EFILE efile; struct phoneleixing *ph; ph=(struct phoneleixing *)msg; clear_lcd(); phonebuff[0]=EepromFile_Open(file_phonebook,&efile); memset(phonebuff,0,sizeof(phonebuff)); if(ph->leixin==0)EepromFile_Seek(&efile,10+ph->numPhone*98+12,EepromFile_SEEK_SET); else EepromFile_Seek(&efile,10+ph->numPhone*98+12+18,EepromFile_SEEK_SET); EepromFile_read(phonebuff,18,&efile); DrawTitle_to_row_Language2(2,"正在拨号...","Dialing..."); strcpy((char *)atcmd,"ATD"); strcat((char *)atcmd,(const char *)phonebuff); strcat((char *)atcmd,";\r"); send_at_cmd(atcmd); //text_out_to_row_x_Language2(1,25,phonebuff,phonebuff); phonebuff[0]=Waitkey_TillKeyPress(); send_at_cmd("ATH\r"); return phonebuff[0]; }
//buff: 要写的源buff //wLen: 要写的长度 //filename: 文件名 //写成功返回EepromFile_WriteOk, //不成功返回的宏定义有以下: //EepromFile_FileNameToLong---->代表文件名太长 //EepromFile_Error_FilesMax20---->代表已经到了最多存20个文件的上限 //EepromFile_Error_AreaNotEnough---->代表没有足够的空间存放当前的文件 u8 EepromFile_WriteData(const unsigned char *buff,unsigned int wLen,const unsigned char *filename) { unsigned int retval; struct EepromFile efp; retval=EepromFile_Open(filename,&efp); if(retval==EepromFile_FileNameToLong)return retval; if(retval==EepromFile_HaveNotThisFile){ {printf("ERROR-->EepromFile_WriteData-->EepromFile_Open\r\n");} retval=EepromFile_Create(filename,&efp); if(retval!=EepromFile_CreateOK){ {printf("ERROR-->EepromFile_WriteData-->EepromFile_Create\r\n");} return retval; } } //ReadEepromPage(NULL); retval=EepromFile_Write(buff,wLen,&efp); if(retval!=EepromFile_WriteOk){ {printf("ERROR-->EepromFile_WriteData-->EepromFile_Write\r\n");} } return retval; }
// 删除成功返回EepromFile_DeleteOk // 没有这个文件返回EepromFile_HaveNotThisFile u8 EepromFile_Delete(uc8 *Name) { u8 filenumber; u8 TheFirstIdlePosition; u8 retval; struct EepromFile efp; retval=EepromFile_CheckWhetherHaveThisFile(Name,&filenumber,&TheFirstIdlePosition); if(retval==EepromFile_HaveNotThisFile)return retval; EepromFile_Open(Name,&efp); __EepromFile_Delete(&efp); return EepromFile_DeleteOk; }
//参数buff :为要读出文件的缓冲区 //参数rLen:为要读出文件长度 //参数filename: 文件名 //读成功返回EepromFile_ReadOk, //不成功返回的宏定义有以下: //EepromFile_FileNameToLong---->代表文件名太长 //EepromFile_HaveNotThisFile---->代表文件不存在 //EepromFile_Error_NoContext---->代表文件没有内容 u8 EepromFile_ReadData(unsigned char *buff,unsigned int rLen,const unsigned char *filename) { u8 retval; struct EepromFile efp; retval=EepromFile_Open(filename,&efp); if(retval!=EepromFile_OpenOk){ {printf("ERROR-->CheckTamper-->EepromFile_Open\r\n");} return retval; } retval=EepromFile_read(buff,rLen,&efp); if(retval!=EepromFile_ReadOk){ {printf("ERROR-->CheckTamper-->EepromFile_read\r\n");} } return retval; }
/************************************光标在手机处菜单**********************************************/ static char PhoneHandleCall(char *msg) { u8 phonebuff[20]; u8 atcmd[50]; EFILE efile; struct phoneleixing *ph; ph=(struct phoneleixing *)msg; clear_lcd(); /*fp=fopen("PhoneBook","rb"); if(fp!=NULL){ //如果有记录,则先把记录读到phonebuff 。 #ifdef DEBUG_PRINTF printf("open PhoneBook success!!\n"); #endif }else{ #ifdef DEBUG_PRINTF printf("open PhoneBook failure!!\n"); #endif return KEY_ReturnPrevious; }*/ phonebuff[0]=EepromFile_Open(file_phonebook,&efile); memset(phonebuff,0,sizeof(phonebuff)); /*if(ph->leixin==0)fseek(fp,10+ph->numPhone*98+12,SEEK_SET); else fseek(fp,10+ph->numPhone*98+12+18,SEEK_SET); fread(phonebuff,18,1,fp);*/ if(ph->leixin==0)EepromFile_Seek(&efile,10+ph->numPhone*98+12,EepromFile_SEEK_SET); else EepromFile_Seek(&efile,10+ph->numPhone*98+12+18,EepromFile_SEEK_SET); EepromFile_read(phonebuff,18,&efile); DrawTitle_to_row_Language2(2,"正在拨号...","Dialing..."); strcpy((char *)atcmd,"ATD"); strcat((char *)atcmd,(const char *)phonebuff); strcat((char *)atcmd,";\r"); send_at_cmd(atcmd); //text_out_to_row_x_Language2(1,25,phonebuff,phonebuff); phonebuff[0]=Waitkey_TillKeyPress(); send_at_cmd("ATH\r"); return phonebuff[0]; }
//static char PhoneSearch(char *msg) char PhoneSearch(char *msg) { EFILE efile; u8 receive[12]; u8 tempbuff[50]; u8 dispbuff[50]; int i; struct OperateDisplay disp={0,0, 0,0,MaxRowOneScr ,1}; unsigned char retval; unsigned char keyval; retval=GetString_abcABC123PYWuBi_Language2("【输入姓名】","Input name",SRF_PY|SRF_BiHua|SRF_abc|SRF_ABC|SRF_123,SRF_abc,receive,sizeof(receive),0); if(retval!=KEY_Enter)return retval; if(strlen((sc8*)receive)==0)goto tuichu; loop: clear_lcd(); //fp=fopen("PhoneBook","rb"); retval=EepromFile_Open(file_phonebook,&efile); retval=EepromFile_ReadData(tempbuff,10,file_phonebook); if(retval==EepromFile_ReadOk){ //如果有记录,则先把记录读到phonebuff 。 disp.MenuTotal=atoi((sc8*)tempbuff); }else{ DrawTitle_to_row_Language2(2,"没有记录","No record"); goto tuichu; } retval=EepromFile_Open(file_phonebook,&efile); for(i=0;i<disp.MenuTotal;i++){ EepromFile_Seek(&efile,10+i*98,EepromFile_SEEK_SET); EepromFile_read(dispbuff,12,&efile); if(my_FFstrstr((sc8*)dispbuff,(sc8*)receive)==1){ disp.Menucnt=i; if(disp.Menucnt<disp.EndLine-disp.StartLine){ disp.curFlashRow+=disp.Menucnt; }else{ disp.curFlashRow=disp.EndLine-1; } break; } } if(i>=disp.MenuTotal){DrawTitle_to_row_Language2(2,"找不到此记录","Can't find record");goto tuichu;} while(1){ if(disp.flashflag){ disp.flashflag=0; for(i=disp.StartLine;i<disp.EndLine&&i<disp.MenuTotal+disp.StartLine;i++){ //fseek(fp,10+(disp.Menucnt-disp.curFlashRow+i)*98,SEEK_SET); //fread(dispbuff,12,1,fp); EepromFile_Seek(&efile,10+(disp.Menucnt-disp.curFlashRow+i)*98,EepromFile_SEEK_SET); EepromFile_read(dispbuff,12,&efile); steaddraw_pic_to_row_x(PhoneNameIco,0,i,12,12); text_out_to_row_x_fillSpace(i,16,dispbuff); } DispHighLightRow_to_x(16,disp.curFlashRow); //高亮 } keyval=GetKeyValue(); if(keyval == KEY_NONE) continue; KeyEventPost(); switch(keyval){ case KEY_UP: my_OperateDisplay_KEY_UP(&disp); break; case KEY_DOWN: my_OperateDisplay_KEY_DOWN(&disp); break; case KEY_Enter: case KEY_RIGHT: if(HandlePhoneSelection(disp.Menucnt)==KEY_ReturnInitInterface){ //fclose(fp); return KEY_ReturnInitInterface; } disp.flashflag=1; disp.curFlashRow=0; //fclose(fp); goto loop; case KEY_ReturnPrevious: case KEY_ReturnInitInterface: case KEY_WaitTimeout: //fclose(fp); return keyval; } } tuichu: WaitkeyAndAutoExit(10); return 0; }
static char PhoneExplorer(char *msg) { EFILE efile; u8 dispbuff[50]; int i; struct OperateDisplay disp={0,0, 0,0,MaxRowOneScr ,1}; unsigned char keyval; loop: clear_lcd(); keyval=EepromFile_ReadData(dispbuff,10,file_phonebook); if(keyval==EepromFile_ReadOk){ //如果有记录,则先把记录读到phonebuff 。 disp.MenuTotal=atoi((sc8*)dispbuff); if(disp.MenuTotal==0){ text_out_to_row_x_Language2(40,2,"没有记录","No record"); goto tuichu; } }else{ text_out_to_row_x_Language2(2,40,"没有记录","No record"); goto tuichu; } keyval=EepromFile_Open(file_phonebook,&efile); while(1){ if(disp.flashflag){ disp.flashflag=0; for(i=disp.StartLine;i<disp.EndLine&&i<disp.MenuTotal+disp.StartLine;i++){ EepromFile_Seek(&efile,10+(disp.Menucnt-disp.curFlashRow+i)*98,EepromFile_SEEK_SET); EepromFile_read(dispbuff,12,&efile); steaddraw_pic_to_row_x(PhoneNameIco,0,i,12,12); text_out_to_row_x_fillSpace(i,16,dispbuff); } DispHighLightRow_to_x(16,disp.curFlashRow); //高亮 } keyval=GetKeyValue(); if(keyval == KEY_NONE) continue; KeyEventPost(); switch(keyval){ case KEY_UP: my_OperateDisplay_KEY_UP(&disp); break; case KEY_DOWN: my_OperateDisplay_KEY_DOWN(&disp); break; case KEY_Enter: case KEY_RIGHT: if(HandlePhoneSelection(disp.Menucnt)==KEY_ReturnInitInterface){return KEY_ReturnInitInterface;} disp.flashflag=1; //fclose(fp); goto loop; case KEY_ReturnPrevious: case KEY_ReturnInitInterface: case KEY_WaitTimeout: //fclose(fp); return keyval; } } tuichu: return (WaitkeyAndAutoExit(10)); }
/************************************记录详情**********************************************/ static char HandlePhoneSelection(char numPhone) { static u8 PhoneNumber[18],PhoneName[12],PhoneZuoJi[18],PhoneEmail[20],PhoneBeiZhu[30]; EFILE efile; char dispbuff[11]; u8 retval; static struct FunctionMenuAddIco2 Menu[5]={ {PhoneNameIco, PhoneName, PhoneHandleName}, {PhoneNumberIco,PhoneNumber,PhoneHandleNumber}, {PhoneZuoJiIco, PhoneZuoJi, PhoneHandleZuoJi}, {PhoneEmailIco, PhoneEmail, PhoneHandleEmail}, {PhoneBeiZhuIco,PhoneBeiZhu,PhoneHandleBeiZhu}, }; struct OperateAddIco2 MenuOp={Menu,5,0 ,0,0,MaxRowOneScr, 1,0,0}; if(Language[0]==LOCAL_LANGUAGE){ strcpy((char *)PhoneNumber,(const char *)con_Chinese_PhoneNumber); strcpy((char *)PhoneName,(const char *)con_Chinese_PhoneName); strcpy((char *)PhoneZuoJi,(const char *)con_Chinese_PhoneZuoJi); strcpy((char *)PhoneEmail,(const char *)con_Chinese_PhoneEmail); strcpy((char *)PhoneBeiZhu,(const char *)con_Chinese_PhoneBeiZhu); //strcpy((char *)PhoneSave,(const char *)con_Chinese_PhoneSave); } else{ strcpy((char *)PhoneNumber,(const char *)con_English_PhoneNumber); strcpy((char *)PhoneName,(const char *)con_English_PhoneName); strcpy((char *)PhoneZuoJi,(const char *)con_English_PhoneZuoJi); strcpy((char *)PhoneEmail,(const char *)con_English_PhoneEmail); strcpy((char *)PhoneBeiZhu,(const char *)con_English_PhoneBeiZhu); //strcpy((char *)PhoneSave,(const char *)con_English_PhoneSave); } loop: retval=EepromFile_ReadData((unsigned char *)dispbuff,10,file_phonebook); if(retval!=EepromFile_ReadOk){ //如果有记录,则先把记录读到phonebuff 。 clear_lcd(); text_out_to_row_x_Language2(2,40,"没有记录","No record"); return WaitkeyAndAutoExit(10); } retval=EepromFile_Open(file_phonebook,&efile); EepromFile_Seek(&efile,10+numPhone*98,EepromFile_SEEK_SET); EepromFile_read(PhoneName,PhoneNameSize,&efile); EepromFile_read(PhoneNumber,PhoneNumberSize,&efile); EepromFile_read(PhoneZuoJi,PhoneZuoJiSize,&efile); EepromFile_read(PhoneEmail,PhoneEmailSize,&efile); EepromFile_read(PhoneBeiZhu,PhoneBeiZhuSize,&efile); while(1){ MenuHandler_AddIco2(&MenuOp); if(MenuOp.RetVal==KEY_Enter){ MenuOp.FucRetVal=MenuOp.Menu->MenuFuc(&numPhone); if(MenuOp.FucRetVal==KEY_WaitTimeout||MenuOp.FucRetVal==KEY_ReturnInitInterface){CurProc=CurProc_Return;return MenuOp.FucRetVal;} else{ clear_lcd(); MenuOp.flashflag=1; goto loop; } }else{ return MenuOp.RetVal; } } #undef PhoneNumber #undef PhoneName #undef PhoneZuoJi #undef PhoneEmail #undef PhoneBeiZhu //#undef PhoneSave }
/************************************光标在姓名处菜单**********************************************/ static s8 PhoneHandleNameXiuGai(s8 *msg) { static u8 PhoneNumber[18],PhoneName[12],PhoneZuoJi[18],PhoneEmail[20],PhoneBeiZhu[30],PhoneSave[5]; char temp[50]; int numPhone; EFILE efile; static struct FunctionMenuAddIco Menu[6]={ {PhoneNameIco, PhoneName, PhoneNameSize, PhoneAddName}, {PhoneNumberIco,PhoneNumber,PhoneNumberSize,PhoneAddNumber}, {PhoneZuoJiIco, PhoneZuoJi, PhoneZuoJiSize, PhoneAddZuoJi}, {PhoneEmailIco, PhoneEmail, PhoneEmailSize, PhoneAddEmail}, {PhoneBeiZhuIco,PhoneBeiZhu,PhoneBeiZhuSize,PhoneAddBeiZhu}, {PhoneSaveIco, PhoneSave, PhoneSaveSize, PhoneAddSave} }; struct OperateAddIco MenuOp={Menu,6,0,0,0,MaxRowOneScr,1,0}; if(Language[0]==LOCAL_LANGUAGE){ strcpy((char *)PhoneNumber,(const char *)con_Chinese_PhoneNumber); strcpy((char *)PhoneName,(const char *)con_Chinese_PhoneName); strcpy((char *)PhoneZuoJi,(const char *)con_Chinese_PhoneZuoJi); strcpy((char *)PhoneEmail,(const char *)con_Chinese_PhoneEmail); strcpy((char *)PhoneBeiZhu,(const char *)con_Chinese_PhoneBeiZhu); strcpy((char *)PhoneSave,(const char *)con_Chinese_PhoneSave); } else{ strcpy((char *)PhoneNumber,(const char *)con_English_PhoneNumber); strcpy((char *)PhoneName,(const char *)con_English_PhoneName); strcpy((char *)PhoneZuoJi,(const char *)con_English_PhoneZuoJi); strcpy((char *)PhoneEmail,(const char *)con_English_PhoneEmail); strcpy((char *)PhoneBeiZhu,(const char *)con_English_PhoneBeiZhu); strcpy((char *)PhoneSave,(const char *)con_English_PhoneSave); } clear_lcd(); temp[0]=EepromFile_ReadData((unsigned char *)temp,10,file_phonebook); if(temp[0]!=EepromFile_ReadOk){ //如果有记录,则先把记录读到phonebuff 。 clear_lcd(); text_out_to_row_x_Language2(2,40,"没有记录","No record"); return KEY_ReturnPrevious; } EepromFile_Open(file_phonebook,&efile); numPhone=*msg; //如果msg==NULL,则会引起segmentation fault。 EepromFile_Seek(&efile,10+numPhone*98,EepromFile_SEEK_SET); EepromFile_read(PhoneName,PhoneNameSize,&efile); EepromFile_read(PhoneNumber,PhoneNumberSize,&efile); EepromFile_read(PhoneZuoJi,PhoneZuoJiSize,&efile); EepromFile_read(PhoneEmail,PhoneEmailSize,&efile); EepromFile_read(PhoneBeiZhu,PhoneBeiZhuSize,&efile); while(1){ MenuHandler_AddIco(&MenuOp); if(MenuOp.RetVal==KEY_Enter){ if(MenuOp.Menucnt==MenuOp.MenuTotal-1){ if(PhoneDeleteARecord(numPhone)==RIGHT_return){ MenuOp.FucRetVal=MenuOp.Menu->MenuFuc((u8 *)Menu,0); } return MenuOp.FucRetVal; }else{ strcpy(temp,(sc8*)(MenuOp.Menu->MenuStr)); MenuOp.FucRetVal=MenuOp.Menu->MenuFuc(MenuOp.Menu->MenuStr,MenuOp.Menu->size); if(strlen((sc8*)(MenuOp.Menu->MenuStr))==0){ strcpy((s8*)(MenuOp.Menu->MenuStr),temp); } } if(MenuOp.FucRetVal==KEY_WaitTimeout||MenuOp.FucRetVal==KEY_ReturnInitInterface){CurProc=CurProc_Return;return MenuOp.FucRetVal;} else{clear_lcd();MenuOp.flashflag=1;} }else{ return MenuOp.RetVal; } } #undef PhoneNumber #undef PhoneName #undef PhoneZuoJi #undef PhoneEmail #undef PhoneBeiZhu #undef PhoneSave }