PhoneNum.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. /*****************************************************************************
  2. PhoneNum.c
  3. *****************************************************************************/
  4. #include "includes.h"
  5. //SUT_FILE_LIST g_sutFilesList;
  6. int g_iPhoneNumFileIndex;
  7. int g_PhoneNumToUse=0;
  8. unsigned char g_ucCallPhonePro = 0;
  9. SUT_NUM_EDIT sutNumEdit;
  10. //在MainTask里面设置一次 不改变
  11. int SetPhoneNumFile(const char *filename)
  12. {
  13. int FileLen;
  14. g_iPhoneNumFileIndex=GetFileIndex(filename);
  15. FileLen=GetFileLen(g_iPhoneNumFileIndex);
  16. if(FileLen==0)
  17. {
  18. g_iPhoneNumFileIndex=-1;
  19. }
  20. return g_iPhoneNumFileIndex;
  21. }
  22. /********************************************************
  23. 统计电话本内电话的个数
  24. ********************************************************/
  25. int GetPhoneNumCount(void)
  26. {
  27. int i;
  28. char number[12];
  29. g_PhoneNumToUse = 0;
  30. for(i=0;i<PHONE_NUM_MAX;i++){//100个电话号码
  31. ReadFileData(g_iPhoneNumFileIndex,i*13,11,(u8 *)number); //先读取到电话号码 11位
  32. number[11]=0;
  33. if(0!=strcmp(number,"00000000000")){
  34. g_PhoneNumToUse++;
  35. }
  36. }
  37. return g_PhoneNumToUse;
  38. }
  39. /*******************************************************
  40. 检查电话本中是否有某电话号码,如有责返回其位置索引(从0开始),否则返回-1
  41. ******************************************************/
  42. int CheckPhoneNum(char *num)
  43. {
  44. int i;
  45. char number[12];
  46. for(i=0;i<PHONE_NUM_MAX;i++){//100个电话号码
  47. ReadFileData(g_iPhoneNumFileIndex,i*13,11,(u8 *)number); //先读取到电话号码 11位
  48. number[11]=0;
  49. if(0==strcmp(num,number)){
  50. return i;
  51. }
  52. }
  53. return -1;
  54. }
  55. /******************************************************
  56. //思路:获取文件 根据索引找到所要删除的电话号码
  57. 把所要删除的号码全部置为0,并且隐藏,统计时不做统计索引要减一 所以要
  58. 有一个*oldFile *newFile 来替换
  59. *********************************************************/
  60. int DeltePhoneNum(char *num)
  61. {
  62. int flag;
  63. int index;
  64. char number[12];
  65. if(-1==g_iPhoneNumFileIndex)return 0;
  66. index=CheckPhoneNum(num);
  67. if(-1==index)return 0;
  68. // ModifyFileData(g_iPhoneNumFileIndex,index*13,11,"00000000000");
  69. //将后续的电话号码往前移
  70. number[11]=0;
  71. while(index<(PHONE_NUM_MAX-1)){
  72. ////////////////////////////////////
  73. if((index % 5) ==0) IWDG_ReloadCounter();
  74. ////////////////////////////////////
  75. ReadFileData(g_iPhoneNumFileIndex,(index+1)*13,11,(u8 *)number); //先读取到电话号码 11位
  76. // ModifyFileData(g_iPhoneNumFileIndex,index*13,11,(u8 *)number);
  77. index++;
  78. if(0==strcmp(number,"00000000000")){
  79. break;
  80. }
  81. }
  82. return 1;
  83. }
  84. /******************************************************
  85. //思路:获取文件 把找到的最近的00号码变为数字号码
  86. 先要找到位置为0的索引,然后把他复制到索引位置上去。
  87. *********************************************************/
  88. int AddPhoneNum(char *num)
  89. {
  90. int i;
  91. int index;
  92. char number[12];
  93. if(-1==g_iPhoneNumFileIndex)return 0;
  94. GetPhoneNumCount();
  95. // index=CheckPhoneNum(num);
  96. index = g_PhoneNumToUse;
  97. // if(-1!=index)return 0;
  98. if((index+1)<(PHONE_NUM_MAX-1)){
  99. //找到空位置,并将其设置为期待的电话号码
  100. // ModifyFileData(g_iPhoneNumFileIndex,(index+1)*13,11,(u8 *)num);
  101. }else{
  102. //ShowMessageBox("您的号码超过100个,请删除不常用号码再添新号");
  103. ShowMessageBox("电话容量不足");
  104. uTimerHardDly(50);
  105. UISetNextStatus(UIS_MENU_MAIN);
  106. }
  107. return 1;
  108. }
  109. /******************************************************
  110. //思路:获取文件 先去找到要修改的号码索引号 所以要
  111. 有一个*oldFile *newFile 来替换
  112. *********************************************************/
  113. int ChangePhoneNum(char *oldNum,char *newNum)
  114. {
  115. int i,w,l;
  116. int index;
  117. if(-1==g_iPhoneNumFileIndex)return 0;//找不到文件,直接返回不处理
  118. index=CheckPhoneNum(oldNum);
  119. if(-1==index)return 0;
  120. // ModifyFileData(g_iPhoneNumFileIndex,index*13,11,(u8 *)newNum);
  121. return 1;
  122. }
  123. /***********************************************************************
  124. 按下OK键 操作打电话
  125. //ATD34394036;
  126. ************************************************************************/
  127. int CallPhoneNum(char *num)
  128. {
  129. char AT[30];
  130. ModemSendAt("AT+ZVCF=2\r");
  131. snprintf(AT, sizeof(AT),"ATD%s;\r",num);
  132. ModemSendAt(AT);
  133. SlwTrace(INF,AT,0);
  134. MicEnable();
  135. sutPocStatus.Mic=1;
  136. sutPocStatus.TTS=1;
  137. SpeakerEnable();
  138. // sprintf(buf,"AT+POC=0A0000%s\r",num);
  139. return 1;
  140. }
  141. /******************************************************
  142. NumList格式:
  143. 总长度必须为:12*PHONE_NUM_MAX 字节
  144. 每一个号码占: 12字节 时间为11个数字加1个结束符/0
  145. *******************************************************/
  146. void CallPhoneGetAllNum(char *NumList)
  147. {
  148. int i,j;
  149. int index;
  150. char *num;
  151. GetPhoneNumCount();
  152. index = g_PhoneNumToUse;
  153. if(-1==g_iPhoneNumFileIndex)return;//找不到文件,直接返回不处理
  154. j=0;
  155. for(i=0;i<PHONE_NUM_MAX;i++){
  156. num=NumList+12*j;
  157. ReadFileData(g_iPhoneNumFileIndex,i*13,11,(u8 *)num);
  158. num[11]=0;
  159. if(0!=strcmp(num,"00000000000"))j++;
  160. }
  161. memset(num,0,12);
  162. }
  163. /*****************************************************
  164. 电话管理
  165. *****************************************************/
  166. void CallPhoneShow(int update)
  167. {
  168. #if 0
  169. static unsigned short susCt=0;
  170. int i;
  171. static const char *accIconFileName[]={
  172. "Phone.bmp",
  173. ""
  174. };
  175. //号码提出去 为全局变量
  176. static char PhonesName[PHONE_NUM_MAX][12];
  177. static char *pPhonesName[PHONE_NUM_MAX];
  178. static char PhonesFeatures[PHONE_NUM_MAX];//这里不能少
  179. static char *ascMsg[]={
  180. "110",
  181. "120",
  182. "119",
  183. ""
  184. };
  185. u16 x,y;
  186. // GetPhoneNumCount();
  187. // PhoneNum.PhonesNUM = PhonesName;
  188. if(update){
  189. susCt=0;
  190. GuiClearAll();
  191. ShowCaption("电话管理",1); //0
  192. //GuiDrawHLine(0,159,20,1);
  193. //----------------------------
  194. CallPhoneGetAllNum(&PhonesName[0][0]);
  195. for(i=0;i<PHONE_NUM_MAX;i++)pPhonesName[i]=PhonesName[i];
  196. if(g_PhoneNumToUse>1){//g_PhoneNumToUse
  197. ListBoxInit(&sutListBox,pPhonesName,0,accIconFileName,PhonesFeatures);
  198. }else{
  199. ListBoxInit(&sutListBox,ascMsg,0,accIconFileName,PhonesFeatures);
  200. }
  201. //----------------------------
  202. GuiDrawHLine(0,159,110,1);
  203. GuiShowStr(0,SUBSCRIPT_LOCATION," [M]呼叫 [S]选项 ",0x01,0);
  204. return;
  205. }
  206. // //按键提示
  207. // if(susCt==0){
  208. // GuiShowStr(0,110," [OK]呼叫 [S]选项 ",0x01);
  209. // }else if(susCt==200){
  210. // GuiShowStr(0,110," [P2]修改 [P3]删除",0x01);
  211. // }
  212. // if(++susCt>=400)susCt=0;
  213. #endif
  214. }
  215. //DeltePhoneNum(sutNumEdit.buffer);
  216. //AddPhoneNum(sutNumEdit.buffer);
  217. //ChangePhoneNum(sutNumEdit.buffer,"12345678902");
  218. void CallPhoneResponse(void)
  219. {
  220. #if 0
  221. unsigned long key;
  222. key=ListBoxResponse(&sutListBox);
  223. switch(key)
  224. {
  225. case KEY_PANEL_EXIT:
  226. UISetNextStatus(UIS_MENU_MAIN);
  227. break;
  228. // case KEY_PANEL_MENU:
  229. // UISetNextStatus(UIS_MENU_MAIN);
  230. // break;
  231. case KEY_PANEL_MENU:
  232. //打电话
  233. //获取电话号码 sutListBox.item[sutListBox.handle];
  234. UISetNextStatus(UIS_CALL_TO_PHONE);
  235. break;
  236. case KEY_OPTION://选项
  237. UISetNextStatus(UIS_CALL_PHONE_OPTION);
  238. break;
  239. default:
  240. break;
  241. }
  242. #endif
  243. }
  244. void CallPhoneOptionShow(int update)
  245. {
  246. static const char *apcMenuSysSetup[]=
  247. {
  248. "新增","编辑","删除",""
  249. };
  250. if(update)
  251. {
  252. GuiClearAll();
  253. ShowCaption("电话选项",1); //0
  254. //GuiDrawHLine(0,159,20,1);
  255. GuiDrawHLine(0,159,110,1);
  256. MenuInit(&sutMenuSysSetup,apcMenuSysSetup);
  257. GuiDrawHLine(0,159,110,1);
  258. GuiShowStr(0,SUBSCRIPT_LOCATION,"[M]确定 [EXIT]退出",0x01,0);
  259. }
  260. }
  261. void CallPhoneOptionResponse(void)
  262. {
  263. #if 0
  264. char buf[30];
  265. unsigned long key;
  266. key=MenuResponse(&sutMenuSysSetup);
  267. if(KEY_PANEL_MENU==key)
  268. {
  269. switch(sutMenuSysSetup.handle)
  270. {
  271. case 0:UISetNextStatus(UIS_CALL_PHONE_INPUT);break;
  272. case 1:UISetNextStatus(UIS_CALL_PHONE_MODIFY);break;
  273. case 2:UISetNextStatus(UIS_CALL_PHONE_DELETE);break;
  274. }
  275. }
  276. else if(KEY_PANEL_EXIT==g_ulKeyValue) UISetNextStatus(sutUIstatus.LastStatus);
  277. //else if(KEY_PANEL_MENU==g_ulKeyValue) UISetNextStatus(UIS_MENU_MAIN);
  278. #endif
  279. }
  280. //LCD_WIDTH 160
  281. //LCD_HEIGHT 128
  282. void CallPhoneInputNumShow(int update)
  283. {
  284. static unsigned short susCt=0;
  285. if(update){
  286. GuiClearAll();//clear
  287. ShowCaption("新增号码",1); //0
  288. //GuiDrawHLine(0,159,20,1);
  289. NumEditInit(&sutNumEdit,38,48,"11111111111");
  290. NumEditShow(&sutNumEdit);
  291. GuiDrawHLine(0,159,110,1);
  292. susCt=0;
  293. GuiShowStr(0,SUBSCRIPT_LOCATION," [上]改值 [下]右移 ",0x01,0);
  294. }
  295. // //按键提示
  296. // if(susCt==0){
  297. // GuiShowStr(0,110," [上]加 [下]减 ",0x01);//[OK]确定
  298. // }else if(susCt==200){
  299. // GuiShowStr(0,110," [P2]左移 [P3]右移 ",0x01);
  300. //
  301. // }
  302. // if(++susCt>=400)susCt=0;
  303. }
  304. //sutListBox.item[sutListBox.handle] 显示光标选中的电话号码
  305. void CallPhoneInputNewNumShow(int update)
  306. {
  307. //static unsigned short susCt=0;
  308. if(update){
  309. GuiClearAll();//clear
  310. ShowCaption("修改号码",1);//0
  311. //GuiDrawHLine(0,159,20,1);
  312. NumEditInit(&sutNumEdit,38,48,sutListBox.item[sutListBox.handle]);
  313. NumEditShow(&sutNumEdit);
  314. GuiDrawHLine(0,159,110,1);
  315. // susCt=0;
  316. GuiShowStr(0,SUBSCRIPT_LOCATION," [上]改值 [下]右移 ",0x01,0);
  317. }
  318. // //按键提示
  319. // if(susCt==0){
  320. // GuiShowStr(0,110," [上]加 [下]减 ",0x01);//[OK]确定
  321. // }else if(susCt==200){
  322. // GuiShowStr(0,110," [P2]左移 [P3]右移 ",0x01);
  323. // }
  324. // if(++susCt>=400)susCt=0;
  325. }
  326. void CallPhoneDeleteNumShow(int update)
  327. {
  328. if(update){
  329. GuiClearAll();//clear
  330. ShowCaption("删除号码",1);//0
  331. //GuiDrawHLine(0,159,20,1);
  332. NumEditInit(&sutNumEdit,38,48,sutListBox.item[sutListBox.handle]);
  333. //NumEditShow(&sutNumEdit);
  334. NumEditShowNORect(&sutNumEdit);
  335. GuiDrawHLine(0,159,110,1);
  336. GuiShowStr(0,SUBSCRIPT_LOCATION,"[M]确定 [EXIT]退出",0x01,0);
  337. }
  338. }
  339. void CallPhoneInputNumResponse(void)
  340. {
  341. #if 0
  342. unsigned long key;
  343. NumEditResponse(&sutNumEdit);
  344. if(KEY_PANEL_MENU==g_ulKeyValue){
  345. //g_sutNumEdit.buffer
  346. // sutListBox.item[sutListBox.handle]=sutNumEdit.buffer;
  347. UISetNextStatus(UIS_CALL_PHONE);
  348. AddPhoneNum(sutNumEdit.buffer);
  349. }
  350. if(KEY_PANEL_EXIT==g_ulKeyValue)UISetNextStatus(UIS_CALL_PHONE);
  351. //else if(KEY_PANEL_MENU==g_ulKeyValue)UISetNextStatus(UIS_MENU_MAIN);
  352. #endif
  353. }
  354. void CallPhoneInputNewNumResponse(void)
  355. {
  356. #if 0
  357. unsigned long key;
  358. NumEditResponse(&sutNumEdit);
  359. if(KEY_PANEL_MENU==g_ulKeyValue){
  360. // sutListBox.item[sutListBox.handle]=sutNumEdit.buffer;
  361. ChangePhoneNum(sutListBox.item[sutListBox.handle],sutNumEdit.buffer);//sutListBox.item[sutListBox.handle],sutNumEdit.buffer
  362. UISetNextStatus(UIS_CALL_PHONE);
  363. }
  364. if(KEY_PANEL_EXIT==g_ulKeyValue)UISetNextStatus(UIS_CALL_PHONE);
  365. //else if(KEY_PANEL_MENU==g_ulKeyValue)UISetNextStatus(UIS_MENU_MAIN);
  366. #endif
  367. }
  368. void CallPhoneInputDeleNumResponse(void)
  369. {
  370. #if 0
  371. unsigned long key;
  372. // NumEditResponse(&sutNumEdit);
  373. if(KEY_PANEL_MENU==g_ulKeyValue){
  374. // sutListBox.item[sutListBox.handle]="00000000000";
  375. ShowMessageBox("请稍候...");
  376. DeltePhoneNum(sutNumEdit.buffer);
  377. UISetNextStatus(UIS_CALL_PHONE);
  378. }
  379. if(KEY_PANEL_EXIT==g_ulKeyValue)UISetNextStatus(UIS_CALL_PHONE);
  380. //else if(KEY_PANEL_MENU==g_ulKeyValue)UISetNextStatus(UIS_MENU_MAIN);
  381. #endif
  382. }
  383. void CallToPhoneNum(int update)
  384. {
  385. #if 0
  386. if(update){
  387. GuiClearAll();//clear
  388. ShowCaption("拨打电话",1); //0
  389. //GuiDrawHLine(0,159,20,1);
  390. NumEditInit(&sutNumEdit,38,48,sutListBox.item[sutListBox.handle]);
  391. //NumEditShow(&sutNumEdit);
  392. NumEditShowNORect(&sutNumEdit);
  393. GuiDrawHLine(0,159,110,1);
  394. GuiShowStr(0,SUBSCRIPT_LOCATION,"[M]拨打 [EXIT]挂断",0x01,0);
  395. }
  396. if(g_ucCallPhonePro == 2)
  397. {
  398. ModemSendAt("ATH\r"); //挂断电话
  399. UISetNextStatus(UIS_CALL_PHONE);
  400. g_ucCallPhonePro = 0;
  401. //////////////////
  402. MicDisable();
  403. sutPocStatus.Mic=0;
  404. sutPocStatus.TTS=0;
  405. SpeakerDisable();
  406. //////////////////
  407. }
  408. #endif
  409. }
  410. void CallToPhoneNumResponse(void)
  411. {
  412. #if 0
  413. char buf[30];
  414. static int siCt;
  415. // NumEditResponse(&sutNumEdit);
  416. #if 0//暂时不支持或未做
  417. if(KEY_PANEL_MENU==g_ulKeyValue){
  418. g_ucCallPhonePro = 1;
  419. ModemSendAt("AT+VGT=1\r"); //输入增益控制
  420. CallPhoneNum(sutListBox.item[sutListBox.handle]);//sutNumEdit.buffer sutListBox.item[sutListBox.handle]
  421. os_dly_wait(30);
  422. GuiClearRect(0,38,159,38+59);
  423. GuiShowBmp(40+12,40,"Pickup.bmp");
  424. }
  425. #else
  426. ShowMessageBox("暂不支持");
  427. IWDG_ReloadCounter();
  428. uTimerHardDly(100);
  429. UISetNextStatus(UIS_CALL_PHONE);
  430. #endif
  431. if(KEY_PANEL_EXIT==g_ulKeyValue){
  432. // UISetNextStatus(UIS_STANDBY);
  433. ModemSendAt("ATH\r"); //挂断电话
  434. UISetNextStatus(UIS_CALL_PHONE);
  435. g_ucCallPhonePro = 0;
  436. //////////////////
  437. MicDisable();
  438. sutPocStatus.Mic=0;
  439. sutPocStatus.TTS=0;
  440. SpeakerDisable();
  441. //////////////////
  442. }
  443. //else if(KEY_PANEL_MENU==g_ulKeyValue)UISetNextStatus(UIS_MENU_MAIN);
  444. #endif
  445. }