123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482 |
- /*****************************************************************************
- PhoneNum.c
- *****************************************************************************/
- #include "includes.h"
- //SUT_FILE_LIST g_sutFilesList;
- int g_iPhoneNumFileIndex;
- int g_PhoneNumToUse=0;
- unsigned char g_ucCallPhonePro = 0;
- SUT_NUM_EDIT sutNumEdit;
- //在MainTask里面设置一次 不改变
- int SetPhoneNumFile(const char *filename)
- {
- int FileLen;
- g_iPhoneNumFileIndex=GetFileIndex(filename);
- FileLen=GetFileLen(g_iPhoneNumFileIndex);
- if(FileLen==0)
- {
- g_iPhoneNumFileIndex=-1;
- }
- return g_iPhoneNumFileIndex;
- }
- /********************************************************
- 统计电话本内电话的个数
- ********************************************************/
- int GetPhoneNumCount(void)
- {
- int i;
- char number[12];
- g_PhoneNumToUse = 0;
-
- for(i=0;i<PHONE_NUM_MAX;i++){//100个电话号码
- ReadFileData(g_iPhoneNumFileIndex,i*13,11,(u8 *)number); //先读取到电话号码 11位
- number[11]=0;
- if(0!=strcmp(number,"00000000000")){
- g_PhoneNumToUse++;
- }
- }
-
- return g_PhoneNumToUse;
- }
- /*******************************************************
- 检查电话本中是否有某电话号码,如有责返回其位置索引(从0开始),否则返回-1
- ******************************************************/
- int CheckPhoneNum(char *num)
- {
- int i;
- char number[12];
- for(i=0;i<PHONE_NUM_MAX;i++){//100个电话号码
- ReadFileData(g_iPhoneNumFileIndex,i*13,11,(u8 *)number); //先读取到电话号码 11位
- number[11]=0;
- if(0==strcmp(num,number)){
- return i;
- }
- }
- return -1;
- }
- /******************************************************
- //思路:获取文件 根据索引找到所要删除的电话号码
- 把所要删除的号码全部置为0,并且隐藏,统计时不做统计索引要减一 所以要
- 有一个*oldFile *newFile 来替换
- *********************************************************/
- int DeltePhoneNum(char *num)
- {
- int flag;
- int index;
- char number[12];
-
- if(-1==g_iPhoneNumFileIndex)return 0;
- index=CheckPhoneNum(num);
- if(-1==index)return 0;
- // ModifyFileData(g_iPhoneNumFileIndex,index*13,11,"00000000000");
- //将后续的电话号码往前移
- number[11]=0;
- while(index<(PHONE_NUM_MAX-1)){
- ////////////////////////////////////
- if((index % 5) ==0) IWDG_ReloadCounter();
- ////////////////////////////////////
- ReadFileData(g_iPhoneNumFileIndex,(index+1)*13,11,(u8 *)number); //先读取到电话号码 11位
- // ModifyFileData(g_iPhoneNumFileIndex,index*13,11,(u8 *)number);
- index++;
- if(0==strcmp(number,"00000000000")){
- break;
- }
- }
- return 1;
- }
- /******************************************************
- //思路:获取文件 把找到的最近的00号码变为数字号码
- 先要找到位置为0的索引,然后把他复制到索引位置上去。
- *********************************************************/
- int AddPhoneNum(char *num)
- {
- int i;
- int index;
- char number[12];
- if(-1==g_iPhoneNumFileIndex)return 0;
- GetPhoneNumCount();
- // index=CheckPhoneNum(num);
- index = g_PhoneNumToUse;
- // if(-1!=index)return 0;
- if((index+1)<(PHONE_NUM_MAX-1)){
- //找到空位置,并将其设置为期待的电话号码
- // ModifyFileData(g_iPhoneNumFileIndex,(index+1)*13,11,(u8 *)num);
- }else{
- //ShowMessageBox("您的号码超过100个,请删除不常用号码再添新号");
- ShowMessageBox("电话容量不足");
- uTimerHardDly(50);
- UISetNextStatus(UIS_MENU_MAIN);
- }
- return 1;
- }
- /******************************************************
- //思路:获取文件 先去找到要修改的号码索引号 所以要
- 有一个*oldFile *newFile 来替换
- *********************************************************/
- int ChangePhoneNum(char *oldNum,char *newNum)
- {
- int i,w,l;
- int index;
-
- if(-1==g_iPhoneNumFileIndex)return 0;//找不到文件,直接返回不处理
- index=CheckPhoneNum(oldNum);
- if(-1==index)return 0;
- // ModifyFileData(g_iPhoneNumFileIndex,index*13,11,(u8 *)newNum);
- return 1;
- }
- /***********************************************************************
- 按下OK键 操作打电话
- //ATD34394036;
- ************************************************************************/
- int CallPhoneNum(char *num)
- {
- char AT[30];
-
- ModemSendAt("AT+ZVCF=2\r");
-
- snprintf(AT, sizeof(AT),"ATD%s;\r",num);
- ModemSendAt(AT);
- SlwTrace(INF,AT,0);
- MicEnable();
- sutPocStatus.Mic=1;
- sutPocStatus.TTS=1;
- SpeakerEnable();
- // sprintf(buf,"AT+POC=0A0000%s\r",num);
- return 1;
- }
- /******************************************************
- NumList格式:
- 总长度必须为:12*PHONE_NUM_MAX 字节
- 每一个号码占: 12字节 时间为11个数字加1个结束符/0
-
- *******************************************************/
- void CallPhoneGetAllNum(char *NumList)
- {
- int i,j;
- int index;
- char *num;
- GetPhoneNumCount();
- index = g_PhoneNumToUse;
- if(-1==g_iPhoneNumFileIndex)return;//找不到文件,直接返回不处理
- j=0;
- for(i=0;i<PHONE_NUM_MAX;i++){
- num=NumList+12*j;
- ReadFileData(g_iPhoneNumFileIndex,i*13,11,(u8 *)num);
- num[11]=0;
- if(0!=strcmp(num,"00000000000"))j++;
- }
- memset(num,0,12);
- }
- /*****************************************************
- 电话管理
- *****************************************************/
- void CallPhoneShow(int update)
- {
- #if 0
- static unsigned short susCt=0;
- int i;
- static const char *accIconFileName[]={
- "Phone.bmp",
- ""
- };
-
- //号码提出去 为全局变量
- static char PhonesName[PHONE_NUM_MAX][12];
- static char *pPhonesName[PHONE_NUM_MAX];
- static char PhonesFeatures[PHONE_NUM_MAX];//这里不能少
- static char *ascMsg[]={
- "110",
- "120",
- "119",
- ""
- };
- u16 x,y;
- // GetPhoneNumCount();
- // PhoneNum.PhonesNUM = PhonesName;
- if(update){
- susCt=0;
- GuiClearAll();
- ShowCaption("电话管理",1); //0
- //GuiDrawHLine(0,159,20,1);
- //----------------------------
- CallPhoneGetAllNum(&PhonesName[0][0]);
- for(i=0;i<PHONE_NUM_MAX;i++)pPhonesName[i]=PhonesName[i];
-
- if(g_PhoneNumToUse>1){//g_PhoneNumToUse
- ListBoxInit(&sutListBox,pPhonesName,0,accIconFileName,PhonesFeatures);
- }else{
- ListBoxInit(&sutListBox,ascMsg,0,accIconFileName,PhonesFeatures);
- }
- //----------------------------
- GuiDrawHLine(0,159,110,1);
- GuiShowStr(0,SUBSCRIPT_LOCATION," [M]呼叫 [S]选项 ",0x01,0);
- return;
- }
-
- // //按键提示
- // if(susCt==0){
- // GuiShowStr(0,110," [OK]呼叫 [S]选项 ",0x01);
- // }else if(susCt==200){
- // GuiShowStr(0,110," [P2]修改 [P3]删除",0x01);
- // }
- // if(++susCt>=400)susCt=0;
- #endif
- }
- //DeltePhoneNum(sutNumEdit.buffer);
- //AddPhoneNum(sutNumEdit.buffer);
- //ChangePhoneNum(sutNumEdit.buffer,"12345678902");
- void CallPhoneResponse(void)
- {
- #if 0
- unsigned long key;
- key=ListBoxResponse(&sutListBox);
-
- switch(key)
- {
- case KEY_PANEL_EXIT:
- UISetNextStatus(UIS_MENU_MAIN);
- break;
- // case KEY_PANEL_MENU:
- // UISetNextStatus(UIS_MENU_MAIN);
- // break;
- case KEY_PANEL_MENU:
- //打电话
- //获取电话号码 sutListBox.item[sutListBox.handle];
- UISetNextStatus(UIS_CALL_TO_PHONE);
- break;
- case KEY_OPTION://选项
- UISetNextStatus(UIS_CALL_PHONE_OPTION);
- break;
- default:
- break;
- }
- #endif
- }
- void CallPhoneOptionShow(int update)
- {
- static const char *apcMenuSysSetup[]=
- {
- "新增","编辑","删除",""
- };
- if(update)
- {
- GuiClearAll();
- ShowCaption("电话选项",1); //0
- //GuiDrawHLine(0,159,20,1);
- GuiDrawHLine(0,159,110,1);
- MenuInit(&sutMenuSysSetup,apcMenuSysSetup);
- GuiDrawHLine(0,159,110,1);
- GuiShowStr(0,SUBSCRIPT_LOCATION,"[M]确定 [EXIT]退出",0x01,0);
- }
- }
- void CallPhoneOptionResponse(void)
- {
- #if 0
- char buf[30];
- unsigned long key;
- key=MenuResponse(&sutMenuSysSetup);
- if(KEY_PANEL_MENU==key)
- {
- switch(sutMenuSysSetup.handle)
- {
- case 0:UISetNextStatus(UIS_CALL_PHONE_INPUT);break;
- case 1:UISetNextStatus(UIS_CALL_PHONE_MODIFY);break;
- case 2:UISetNextStatus(UIS_CALL_PHONE_DELETE);break;
- }
- }
- else if(KEY_PANEL_EXIT==g_ulKeyValue) UISetNextStatus(sutUIstatus.LastStatus);
- //else if(KEY_PANEL_MENU==g_ulKeyValue) UISetNextStatus(UIS_MENU_MAIN);
- #endif
- }
- //LCD_WIDTH 160
- //LCD_HEIGHT 128
- void CallPhoneInputNumShow(int update)
- {
- static unsigned short susCt=0;
- if(update){
- GuiClearAll();//clear
- ShowCaption("新增号码",1); //0
- //GuiDrawHLine(0,159,20,1);
- NumEditInit(&sutNumEdit,38,48,"11111111111");
- NumEditShow(&sutNumEdit);
- GuiDrawHLine(0,159,110,1);
- susCt=0;
-
- GuiShowStr(0,SUBSCRIPT_LOCATION," [上]改值 [下]右移 ",0x01,0);
- }
- // //按键提示
- // if(susCt==0){
- // GuiShowStr(0,110," [上]加 [下]减 ",0x01);//[OK]确定
- // }else if(susCt==200){
- // GuiShowStr(0,110," [P2]左移 [P3]右移 ",0x01);
- //
- // }
- // if(++susCt>=400)susCt=0;
- }
- //sutListBox.item[sutListBox.handle] 显示光标选中的电话号码
- void CallPhoneInputNewNumShow(int update)
- {
- //static unsigned short susCt=0;
- if(update){
- GuiClearAll();//clear
- ShowCaption("修改号码",1);//0
- //GuiDrawHLine(0,159,20,1);
- NumEditInit(&sutNumEdit,38,48,sutListBox.item[sutListBox.handle]);
- NumEditShow(&sutNumEdit);
- GuiDrawHLine(0,159,110,1);
- // susCt=0;
-
- GuiShowStr(0,SUBSCRIPT_LOCATION," [上]改值 [下]右移 ",0x01,0);
- }
- // //按键提示
- // if(susCt==0){
- // GuiShowStr(0,110," [上]加 [下]减 ",0x01);//[OK]确定
- // }else if(susCt==200){
- // GuiShowStr(0,110," [P2]左移 [P3]右移 ",0x01);
- // }
- // if(++susCt>=400)susCt=0;
- }
- void CallPhoneDeleteNumShow(int update)
- {
- if(update){
- GuiClearAll();//clear
- ShowCaption("删除号码",1);//0
- //GuiDrawHLine(0,159,20,1);
- NumEditInit(&sutNumEdit,38,48,sutListBox.item[sutListBox.handle]);
- //NumEditShow(&sutNumEdit);
- NumEditShowNORect(&sutNumEdit);
- GuiDrawHLine(0,159,110,1);
- GuiShowStr(0,SUBSCRIPT_LOCATION,"[M]确定 [EXIT]退出",0x01,0);
- }
- }
- void CallPhoneInputNumResponse(void)
- {
- #if 0
- unsigned long key;
- NumEditResponse(&sutNumEdit);
- if(KEY_PANEL_MENU==g_ulKeyValue){
- //g_sutNumEdit.buffer
- // sutListBox.item[sutListBox.handle]=sutNumEdit.buffer;
- UISetNextStatus(UIS_CALL_PHONE);
- AddPhoneNum(sutNumEdit.buffer);
- }
-
- if(KEY_PANEL_EXIT==g_ulKeyValue)UISetNextStatus(UIS_CALL_PHONE);
- //else if(KEY_PANEL_MENU==g_ulKeyValue)UISetNextStatus(UIS_MENU_MAIN);
- #endif
- }
- void CallPhoneInputNewNumResponse(void)
- {
- #if 0
- unsigned long key;
- NumEditResponse(&sutNumEdit);
- if(KEY_PANEL_MENU==g_ulKeyValue){
- // sutListBox.item[sutListBox.handle]=sutNumEdit.buffer;
- ChangePhoneNum(sutListBox.item[sutListBox.handle],sutNumEdit.buffer);//sutListBox.item[sutListBox.handle],sutNumEdit.buffer
- UISetNextStatus(UIS_CALL_PHONE);
- }
- if(KEY_PANEL_EXIT==g_ulKeyValue)UISetNextStatus(UIS_CALL_PHONE);
- //else if(KEY_PANEL_MENU==g_ulKeyValue)UISetNextStatus(UIS_MENU_MAIN);
- #endif
- }
- void CallPhoneInputDeleNumResponse(void)
- {
- #if 0
- unsigned long key;
- // NumEditResponse(&sutNumEdit);
- if(KEY_PANEL_MENU==g_ulKeyValue){
- // sutListBox.item[sutListBox.handle]="00000000000";
- ShowMessageBox("请稍候...");
- DeltePhoneNum(sutNumEdit.buffer);
- UISetNextStatus(UIS_CALL_PHONE);
- }
- if(KEY_PANEL_EXIT==g_ulKeyValue)UISetNextStatus(UIS_CALL_PHONE);
- //else if(KEY_PANEL_MENU==g_ulKeyValue)UISetNextStatus(UIS_MENU_MAIN);
- #endif
- }
- void CallToPhoneNum(int update)
- {
- #if 0
- if(update){
- GuiClearAll();//clear
- ShowCaption("拨打电话",1); //0
- //GuiDrawHLine(0,159,20,1);
- NumEditInit(&sutNumEdit,38,48,sutListBox.item[sutListBox.handle]);
- //NumEditShow(&sutNumEdit);
- NumEditShowNORect(&sutNumEdit);
- GuiDrawHLine(0,159,110,1);
- GuiShowStr(0,SUBSCRIPT_LOCATION,"[M]拨打 [EXIT]挂断",0x01,0);
- }
-
- if(g_ucCallPhonePro == 2)
- {
- ModemSendAt("ATH\r"); //挂断电话
- UISetNextStatus(UIS_CALL_PHONE);
- g_ucCallPhonePro = 0;
- //////////////////
- MicDisable();
- sutPocStatus.Mic=0;
- sutPocStatus.TTS=0;
- SpeakerDisable();
- //////////////////
- }
- #endif
- }
- void CallToPhoneNumResponse(void)
- {
- #if 0
- char buf[30];
- static int siCt;
- // NumEditResponse(&sutNumEdit);
- #if 0//暂时不支持或未做
- if(KEY_PANEL_MENU==g_ulKeyValue){
- g_ucCallPhonePro = 1;
- ModemSendAt("AT+VGT=1\r"); //输入增益控制
-
- CallPhoneNum(sutListBox.item[sutListBox.handle]);//sutNumEdit.buffer sutListBox.item[sutListBox.handle]
- os_dly_wait(30);
- GuiClearRect(0,38,159,38+59);
- GuiShowBmp(40+12,40,"Pickup.bmp");
- }
- #else
- ShowMessageBox("暂不支持");
- IWDG_ReloadCounter();
- uTimerHardDly(100);
- UISetNextStatus(UIS_CALL_PHONE);
- #endif
- if(KEY_PANEL_EXIT==g_ulKeyValue){
- // UISetNextStatus(UIS_STANDBY);
- ModemSendAt("ATH\r"); //挂断电话
- UISetNextStatus(UIS_CALL_PHONE);
- g_ucCallPhonePro = 0;
- //////////////////
- MicDisable();
- sutPocStatus.Mic=0;
- sutPocStatus.TTS=0;
- SpeakerDisable();
- //////////////////
- }
- //else if(KEY_PANEL_MENU==g_ulKeyValue)UISetNextStatus(UIS_MENU_MAIN);
- #endif
- }
|