PhoneNum.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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. OsDelayTime(200);
  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. static unsigned short susCt=0;
  169. int i;
  170. static const char *accIconFileName[]={
  171. "Phone.bmp",
  172. ""
  173. };
  174. //号码提出去 为全局变量
  175. static char PhonesName[PHONE_NUM_MAX][12];
  176. static char *pPhonesName[PHONE_NUM_MAX];
  177. static char PhonesFeatures[PHONE_NUM_MAX];//这里不能少
  178. static char *ascMsg[]={
  179. "110",
  180. "120",
  181. "119",
  182. ""
  183. };
  184. u16 x,y;
  185. // GetPhoneNumCount();
  186. // PhoneNum.PhonesNUM = PhonesName;
  187. if(update){
  188. susCt=0;
  189. GuiClearAll();
  190. ShowCaption("电话管理",1); //0
  191. GuiDrawHLine(0,159,20,1);
  192. //----------------------------
  193. CallPhoneGetAllNum(&PhonesName[0][0]);
  194. for(i=0;i<PHONE_NUM_MAX;i++)pPhonesName[i]=PhonesName[i];
  195. if(g_PhoneNumToUse>1){//g_PhoneNumToUse
  196. ListBoxInit(&sutListBox,pPhonesName,0,accIconFileName,PhonesFeatures);
  197. }else{
  198. ListBoxInit(&sutListBox,ascMsg,0,accIconFileName,PhonesFeatures);
  199. }
  200. //----------------------------
  201. GuiDrawHLine(0,159,104,1);
  202. GuiShowStr(0,110," [M]呼叫 [S]选项 ",0x01);
  203. return;
  204. }
  205. // //按键提示
  206. // if(susCt==0){
  207. // GuiShowStr(0,110," [OK]呼叫 [S]选项 ",0x01);
  208. // }else if(susCt==200){
  209. // GuiShowStr(0,110," [P2]修改 [P3]删除",0x01);
  210. // }
  211. // if(++susCt>=400)susCt=0;
  212. }
  213. //DeltePhoneNum(sutNumEdit.buffer);
  214. //AddPhoneNum(sutNumEdit.buffer);
  215. //ChangePhoneNum(sutNumEdit.buffer,"12345678902");
  216. void CallPhoneResponse(void)
  217. {
  218. unsigned long key;
  219. key=ListBoxResponse(&sutListBox);
  220. switch(key)
  221. {
  222. case KEY_PANEL_EXIT:
  223. UISetNextStatus(UIS_MENU_MAIN);
  224. break;
  225. // case KEY_PANEL_MENU:
  226. // UISetNextStatus(UIS_MENU_MAIN);
  227. // break;
  228. case KEY_PANEL_MENU:
  229. //打电话
  230. //获取电话号码 sutListBox.item[sutListBox.handle];
  231. UISetNextStatus(UIS_CALL_TO_PHONE);
  232. break;
  233. case KEY_OPTION://选项
  234. UISetNextStatus(UIS_CALL_PHONE_OPTION);
  235. break;
  236. default:
  237. break;
  238. }
  239. }
  240. void CallPhoneOptionShow(int update)
  241. {
  242. static const char *apcMenuSysSetup[]=
  243. {
  244. "新增","编辑","删除",""
  245. };
  246. if(update)
  247. {
  248. GuiClearAll();
  249. ShowCaption("电话选项",1); //0
  250. GuiDrawHLine(0,159,20,1);
  251. GuiDrawHLine(0,159,104,1);
  252. MenuInit(&sutMenuSysSetup,apcMenuSysSetup);
  253. GuiDrawHLine(0,159,104,1);
  254. GuiShowStr(0,110,"[M]确定 [EXIT]退出",0x01);
  255. }
  256. }
  257. void CallPhoneOptionResponse(void)
  258. {
  259. char buf[30];
  260. unsigned long key;
  261. key=MenuResponse(&sutMenuSysSetup);
  262. if(KEY_PANEL_MENU==key)
  263. {
  264. switch(sutMenuSysSetup.handle)
  265. {
  266. case 0:UISetNextStatus(UIS_CALL_PHONE_INPUT);break;
  267. case 1:UISetNextStatus(UIS_CALL_PHONE_MODIFY);break;
  268. case 2:UISetNextStatus(UIS_CALL_PHONE_DELETE);break;
  269. }
  270. }
  271. else if(KEY_PANEL_EXIT==g_ulKeyValue) UISetNextStatus(sutUIstatus.LastStatus);
  272. //else if(KEY_PANEL_MENU==g_ulKeyValue) UISetNextStatus(UIS_MENU_MAIN);
  273. }
  274. //LCD_WIDTH 160
  275. //LCD_HEIGHT 128
  276. void CallPhoneInputNumShow(int update)
  277. {
  278. static unsigned short susCt=0;
  279. if(update){
  280. GuiClearAll();//clear
  281. ShowCaption("新增号码",1); //0
  282. GuiDrawHLine(0,159,20,1);
  283. NumEditInit(&sutNumEdit,38,48,"11111111111");
  284. NumEditShow(&sutNumEdit);
  285. GuiDrawHLine(0,159,104,1);
  286. susCt=0;
  287. GuiShowStr(0,110," [上]改值 [下]右移 ",0x01);
  288. }
  289. // //按键提示
  290. // if(susCt==0){
  291. // GuiShowStr(0,110," [上]加 [下]减 ",0x01);//[OK]确定
  292. // }else if(susCt==200){
  293. // GuiShowStr(0,110," [P2]左移 [P3]右移 ",0x01);
  294. //
  295. // }
  296. // if(++susCt>=400)susCt=0;
  297. }
  298. //sutListBox.item[sutListBox.handle] 显示光标选中的电话号码
  299. void CallPhoneInputNewNumShow(int update)
  300. {
  301. //static unsigned short susCt=0;
  302. if(update){
  303. GuiClearAll();//clear
  304. ShowCaption("修改号码",1);//0
  305. GuiDrawHLine(0,159,20,1);
  306. NumEditInit(&sutNumEdit,38,48,sutListBox.item[sutListBox.handle]);
  307. NumEditShow(&sutNumEdit);
  308. GuiDrawHLine(0,159,104,1);
  309. // susCt=0;
  310. GuiShowStr(0,110," [上]改值 [下]右移 ",0x01);
  311. }
  312. // //按键提示
  313. // if(susCt==0){
  314. // GuiShowStr(0,110," [上]加 [下]减 ",0x01);//[OK]确定
  315. // }else if(susCt==200){
  316. // GuiShowStr(0,110," [P2]左移 [P3]右移 ",0x01);
  317. // }
  318. // if(++susCt>=400)susCt=0;
  319. }
  320. void CallPhoneDeleteNumShow(int update)
  321. {
  322. if(update){
  323. GuiClearAll();//clear
  324. ShowCaption("删除号码",1);//0
  325. GuiDrawHLine(0,159,20,1);
  326. NumEditInit(&sutNumEdit,38,48,sutListBox.item[sutListBox.handle]);
  327. //NumEditShow(&sutNumEdit);
  328. NumEditShowNORect(&sutNumEdit);
  329. GuiDrawHLine(0,159,104,1);
  330. GuiShowStr(0,110,"[M]确定 [EXIT]退出",0x01);
  331. }
  332. }
  333. void CallPhoneInputNumResponse(void)
  334. {
  335. unsigned long key;
  336. NumEditResponse(&sutNumEdit);
  337. if(KEY_PANEL_MENU==g_ulKeyValue){
  338. //g_sutNumEdit.buffer
  339. // sutListBox.item[sutListBox.handle]=sutNumEdit.buffer;
  340. UISetNextStatus(UIS_CALL_PHONE);
  341. AddPhoneNum(sutNumEdit.buffer);
  342. }
  343. if(KEY_PANEL_EXIT==g_ulKeyValue)UISetNextStatus(UIS_CALL_PHONE);
  344. //else if(KEY_PANEL_MENU==g_ulKeyValue)UISetNextStatus(UIS_MENU_MAIN);
  345. }
  346. void CallPhoneInputNewNumResponse(void)
  347. {
  348. unsigned long key;
  349. NumEditResponse(&sutNumEdit);
  350. if(KEY_PANEL_MENU==g_ulKeyValue){
  351. // sutListBox.item[sutListBox.handle]=sutNumEdit.buffer;
  352. ChangePhoneNum(sutListBox.item[sutListBox.handle],sutNumEdit.buffer);//sutListBox.item[sutListBox.handle],sutNumEdit.buffer
  353. UISetNextStatus(UIS_CALL_PHONE);
  354. }
  355. if(KEY_PANEL_EXIT==g_ulKeyValue)UISetNextStatus(UIS_CALL_PHONE);
  356. //else if(KEY_PANEL_MENU==g_ulKeyValue)UISetNextStatus(UIS_MENU_MAIN);
  357. }
  358. void CallPhoneInputDeleNumResponse(void)
  359. {
  360. unsigned long key;
  361. // NumEditResponse(&sutNumEdit);
  362. if(KEY_PANEL_MENU==g_ulKeyValue){
  363. // sutListBox.item[sutListBox.handle]="00000000000";
  364. ShowMessageBox("请稍候...");
  365. DeltePhoneNum(sutNumEdit.buffer);
  366. UISetNextStatus(UIS_CALL_PHONE);
  367. }
  368. if(KEY_PANEL_EXIT==g_ulKeyValue)UISetNextStatus(UIS_CALL_PHONE);
  369. //else if(KEY_PANEL_MENU==g_ulKeyValue)UISetNextStatus(UIS_MENU_MAIN);
  370. }
  371. void CallToPhoneNum(int update)
  372. {
  373. if(update){
  374. GuiClearAll();//clear
  375. ShowCaption("拨打电话",1); //0
  376. GuiDrawHLine(0,159,20,1);
  377. NumEditInit(&sutNumEdit,38,48,sutListBox.item[sutListBox.handle]);
  378. //NumEditShow(&sutNumEdit);
  379. NumEditShowNORect(&sutNumEdit);
  380. GuiDrawHLine(0,159,104,1);
  381. GuiShowStr(0,110,"[M]拨打 [EXIT]挂断",0x01);
  382. }
  383. if(g_ucCallPhonePro == 2)
  384. {
  385. ModemSendAT("ATH\r"); //挂断电话
  386. UISetNextStatus(UIS_CALL_PHONE);
  387. g_ucCallPhonePro = 0;
  388. //////////////////
  389. MicDisable();
  390. sutPocStatus.Mic=0;
  391. sutPocStatus.TTS=0;
  392. SpeakerDisable();
  393. //////////////////
  394. }
  395. }
  396. void CallToPhoneNumResponse(void)
  397. {
  398. char buf[30];
  399. static int siCt;
  400. // NumEditResponse(&sutNumEdit);
  401. #if 0//暂时不支持或未做
  402. if(KEY_PANEL_MENU==g_ulKeyValue){
  403. g_ucCallPhonePro = 1;
  404. ModemSendAT("AT+VGT=1\r"); //输入增益控制
  405. CallPhoneNum(sutListBox.item[sutListBox.handle]);//sutNumEdit.buffer sutListBox.item[sutListBox.handle]
  406. os_dly_wait(30);
  407. GuiClearRect(0,38,159,38+59);
  408. GuiShowBmp(40+12,40,"Pickup.bmp");
  409. }
  410. #else
  411. ShowMessageBox("暂不支持");
  412. IWDG_ReloadCounter();
  413. os_dly_wait(100);
  414. UISetNextStatus(UIS_CALL_PHONE);
  415. #endif
  416. if(KEY_PANEL_EXIT==g_ulKeyValue){
  417. // UISetNextStatus(UIS_STANDBY);
  418. ModemSendAT("ATH\r"); //挂断电话
  419. UISetNextStatus(UIS_CALL_PHONE);
  420. g_ucCallPhonePro = 0;
  421. //////////////////
  422. MicDisable();
  423. sutPocStatus.Mic=0;
  424. sutPocStatus.TTS=0;
  425. SpeakerDisable();
  426. //////////////////
  427. }
  428. //else if(KEY_PANEL_MENU==g_ulKeyValue)UISetNextStatus(UIS_MENU_MAIN);
  429. }