message.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. #include "includes.h"
  2. SUT_SMS_DEFINE sutSms;
  3. SUT_MESSAGE_EDIT sutMEdit;
  4. static void SmsScan(unsigned char ret);
  5. void ShowMessageFlag(uint8_t show)
  6. {
  7. static uint8_t smsUnReadBackup;
  8. uint8_t showFlag;
  9. showFlag=0;
  10. if(show)
  11. {
  12. if(sutSms.haveUnRead)
  13. showFlag=1;
  14. }else
  15. {
  16. if(smsUnReadBackup == sutSms.haveUnRead) return;
  17. smsUnReadBackup = sutSms.haveUnRead;
  18. if(sutSms.haveUnRead)
  19. showFlag=1;
  20. }
  21. switch(showFlag)
  22. {
  23. case 0:GuiShowStr(106,1," ",0x01,0);break;
  24. case 1:GuiShowBmp(106,1,"Mail1.bmp");break;
  25. //case 2:GuiShowStr(60,3," ",0x01,0);break;
  26. default:break;
  27. }
  28. }
  29. //读取所有信息的前15字节内容
  30. //返回消息总数目
  31. uint8_t GetPagePreMessage(struct SUT_LIST_BOX *p,uint8_t firstRead, char up_down)
  32. {
  33. uint8_t i,*ptr,buf[16],ptrTem[8];
  34. uint32_t readAddr;
  35. uint16_t totalnum,retNum;
  36. struct SUT_SMS_INFO_HEADER info;
  37. uint8_t downFindFirst;//向下查找时第一次找到消息-此时要记录向上查找记录upToBeRead
  38. uint8_t upFindFirst;
  39. uint8_t reCtPerTime;
  40. //以下用于交换用
  41. struct SUT_LIST_BOX_SMS_INFO boxinfo;
  42. uint8_t temp,*Cptr1,*Cptr2;
  43. // char buf1[30];
  44. //1从最新消息,即sutSms.newestAddr开始读出最多5项
  45. if(sutSms.smsTotalNum >= LIST_ROW)
  46. reCtPerTime=LIST_ROW;
  47. else
  48. reCtPerTime = sutSms.smsTotalNum;
  49. downFindFirst=0;
  50. upFindFirst=0;
  51. totalnum = SMS_TOTAL_NUM;
  52. ptr=(uint8_t *)&info;
  53. if(firstRead == 1)
  54. {
  55. //SmsScan(1);
  56. sutSms.downToBeRead = sutSms.newestAddr;
  57. sFlash_Read(ptr, sutSms.newestAddr, sizeof(struct SUT_SMS_INFO_HEADER));
  58. sutSms.upToBeRead = info.upperAddr;
  59. firstRead=0;
  60. }
  61. i=0;
  62. if(up_down == 'd')
  63. {//向下读
  64. while(1)
  65. {
  66. readAddr = sutSms.downToBeRead;
  67. //1.1读出年月日(16/06/01 = 8字节)+内容7字节
  68. sFlash_Read(ptr, readAddr, sizeof(struct SUT_SMS_INFO_HEADER));
  69. sFlash_Read(ptrTem, readAddr+SMS_INFO_DETAIL_OFFSET, 8);//8字节内容
  70. if(1==info.flag)
  71. {
  72. if(!downFindFirst)
  73. {
  74. downFindFirst++;
  75. sutSms.upToBeRead = info.upperAddr;
  76. }
  77. sprintf(p->boxinfo[i].item,"%02d/%02d/%02d ", (info.recTime>>26)&0x3F,(info.recTime>>22)&0x0F,(info.recTime>>17)&0x1F);
  78. strcat(p->boxinfo[i].item, (char *)ptrTem);
  79. if(1==info.read)
  80. p->boxinfo[i].features = 0;
  81. else p->boxinfo[i].features = 1;
  82. sutSms.downToBeRead = info.nextAddr;
  83. sutSms.ReadAddr[i] = readAddr;
  84. i++;
  85. if(i>=reCtPerTime)
  86. {
  87. retNum=i;
  88. break;
  89. }
  90. }else
  91. {//读完了,转到一开始
  92. sutSms.downToBeRead = sutSms.newestAddr;
  93. //sutSms.downToBeRead = info.nextAddr;
  94. continue;
  95. }
  96. totalnum--;
  97. if(!totalnum)
  98. {
  99. //error
  100. SlwTrace(INF, "[SMS]err1",1);
  101. retNum=i;
  102. break;
  103. }
  104. }
  105. p->handle=0;
  106. }else
  107. {//向上读
  108. while(1)
  109. {
  110. readAddr = sutSms.upToBeRead;
  111. //1.1读出年月日(16/06/01 = 8字节)+内容7字节
  112. sFlash_Read(ptr, readAddr, sizeof(struct SUT_SMS_INFO_HEADER));
  113. sFlash_Read(ptrTem, readAddr+SMS_INFO_DETAIL_OFFSET, 8);//8字节内容
  114. if(1==info.flag)
  115. {
  116. if(!upFindFirst)
  117. {
  118. upFindFirst++;
  119. sutSms.downToBeRead = info.nextAddr;
  120. }
  121. sprintf(p->boxinfo[i].item,"%d/%d/%d ", (info.recTime>>26)&0x3F,(info.recTime>>22)&0x0F,(info.recTime>>17)&0x1F);
  122. strcat(p->boxinfo[i].item, (char *)ptrTem);
  123. if(1==info.read)
  124. p->boxinfo[i].features = 0;
  125. else p->boxinfo[i].features = 1;
  126. sutSms.upToBeRead = info.upperAddr;
  127. sutSms.ReadAddr[i] = readAddr;
  128. i++;
  129. if(i>=reCtPerTime)
  130. {
  131. retNum=i;
  132. break;
  133. }
  134. }else
  135. {//读完了,转到最后一条
  136. //sutSms.upToBeRead = sutSms.newestAddr+(sutSms.smsTotalNum-1)*SMS_SIZE_PER;
  137. //sutSms.upToBeRead = SMS_START_ADDRESS+(sutSms.smsTotalNum-1)*SMS_SIZE_PER;
  138. sutSms.upToBeRead = info.upperAddr;
  139. continue;
  140. }
  141. totalnum--;
  142. if(!totalnum)
  143. {
  144. //error
  145. SlwTrace(INF, "[SMS]err2",1);
  146. retNum=i;
  147. break;
  148. }
  149. }
  150. //switch
  151. ptr=(uint8_t *)&boxinfo;//copy
  152. temp = retNum/2;
  153. for(i=0;i<temp;i++)
  154. {
  155. Cptr1=(uint8_t *)&p->boxinfo[i];
  156. Cptr2=(uint8_t *)&p->boxinfo[retNum-1-i];
  157. memcpy(ptr, Cptr1, LIST_ITEM_TEXT_LEN_MAX+1);
  158. memcpy(Cptr1, Cptr2, LIST_ITEM_TEXT_LEN_MAX+1);
  159. memcpy(Cptr2, ptr, LIST_ITEM_TEXT_LEN_MAX+1);
  160. readAddr=sutSms.ReadAddr[i];
  161. sutSms.ReadAddr[i] = sutSms.ReadAddr[retNum-1-i];
  162. sutSms.ReadAddr[retNum-1-i] = readAddr;
  163. }
  164. p->handle=reCtPerTime-1;
  165. }
  166. p->itemnum=retNum;
  167. p->pageChange=0;
  168. ListBoxItemNumShowSMS(p->notehandle,p->totalnum);
  169. ListBoxShowSMS(p);
  170. }
  171. void SetGotNewMessage(void)
  172. {
  173. unsigned char type,encode,def1,def2;
  174. type = sutMess.GBKMess1[0];
  175. encode=sutMess.GBKMess1[1];
  176. def1 = sutMess.GBKMess1[2];
  177. def2 = sutMess.GBKMess1[3];
  178. //处理分析消息类型
  179. if(type == 0x30 &&
  180. encode == 0x30 &&
  181. def1 == 0x32 &&
  182. def2 == 0x30)
  183. {//一键报警
  184. sutMess.len -= 4;
  185. sutMess.Update=1;//收到一条消息标记
  186. sutMess.startCntFlag=1;
  187. sutMess.skipCnt=0;//从此时开始计数
  188. sutMess.forcePullGroupOn=0;
  189. SlwTrace(INF,"AlarmStart",1);
  190. sutMess.codeType=2;//unicode
  191. //sutSms.smsUpdate=1;//need to store
  192. }else
  193. if(type == 0x01 &&
  194. encode == 0x02)
  195. {//纯TTS播报
  196. sutMess.len -= 4;
  197. sutMess.Update=2;
  198. sutMess.codeType=2;//unicode
  199. sutSms.smsUpdate=1;//need to store
  200. SlwTrace(INF,"Pure TTS",1);
  201. }else
  202. if(type == 0x20 &&
  203. encode == 0x20 &&
  204. def1 == 0x20 &&
  205. def2 == 0x20)
  206. {//全文本
  207. sutMess.len -= 4;
  208. sutMess.Update=0;
  209. sutMess.codeType=1;//gb2312
  210. sutSms.smsUpdate=1;//need to store
  211. SlwTrace(INF,"Pure TXT",1);
  212. }
  213. sutFeed.result=0;
  214. sutFeed.feedBackStart=1;
  215. }
  216. //扫描消息 ret值:
  217. //0、重置过的
  218. //1、获得消息总数以及未读数目
  219. //2、往上查找当前最新消息位置上一条空地址
  220. static void SmsScan(unsigned char ret)
  221. {
  222. uint8_t *ptr;
  223. uint16_t i;
  224. struct SUT_SMS_INFO_HEADER smsinfo,*info;
  225. uint32_t readAddr;
  226. if(ret > 2) return;//出错不扫描
  227. if(0 == ret)
  228. {//已reset过
  229. }else if(1 == ret)
  230. {//查找消息总数和未读数
  231. sutSms.smsTotalNum=0;
  232. sutSms.smsUnReadNum=0;
  233. ptr = (unsigned char *)&smsinfo;
  234. readAddr = sutSms.newestAddr;
  235. info=&smsinfo;
  236. i=SMS_TOTAL_NUM;
  237. while(1)
  238. {
  239. sFlash_Read(ptr, readAddr, sizeof(struct SUT_SMS_INFO_HEADER));
  240. if(1==smsinfo.flag)
  241. {
  242. sutSms.smsTotalNum ++;
  243. if(1==smsinfo.read)
  244. {
  245. sutSms.smsUnReadNum ++;
  246. sutSms.haveUnRead = 1;
  247. }
  248. }
  249. i--;
  250. if(!i) break;
  251. readAddr = info->nextAddr;
  252. }
  253. }else if(2 == ret)
  254. {//向上查找空地址
  255. ptr = (unsigned char *)&smsinfo;
  256. readAddr = sutSms.newestAddr;
  257. info=&smsinfo;
  258. i=SMS_TOTAL_NUM;
  259. while(1)
  260. {
  261. sFlash_Read(ptr, readAddr, sizeof(struct SUT_SMS_INFO_HEADER));
  262. if(0==smsinfo.flag)
  263. {//找到
  264. sutSms.emptyAddr = readAddr;
  265. break;
  266. }
  267. i--;
  268. if(!i)
  269. {
  270. sutSms.poolFull = 1;
  271. SlwTrace(INF, "[SMS]Full",1);
  272. SpeakerEnable();
  273. ModemSendAt("AT+LSHTTS=1,\"CFFBCFA2D2D1C2FA\"\r\n");
  274. break;
  275. }
  276. readAddr = smsinfo.upperAddr;
  277. }
  278. }
  279. }
  280. ///////////////////////////////////////////////////////////
  281. //uint8_t defaultSMS[] = "0我们都是好朋友";
  282. //重置设置
  283. //返回值0到2用实际用处
  284. unsigned char ResetSMSConfi(void)
  285. {
  286. int endAddress,temp1,i;
  287. unsigned char *ptr,process=0;
  288. struct SUT_SMS_INFO_HEADER smsinfo;
  289. // struct SUT_SMS_CONF_HEADER conf;
  290. unsigned short sectorNum,startSector,k;
  291. unsigned int totalBytes;
  292. #if 0
  293. //1,得到HGS.sms文件内容
  294. g_iMessageFileIndex=GetFileIndex("HGS.sms");
  295. if(g_iMessageFileIndex == -1)
  296. {
  297. sutSms.smsEnable = 0;
  298. SlwTrace(INF, "[SMS]RErr1",1);
  299. return 3;
  300. }
  301. temp1=GetFileLen(g_iMessageFileIndex);
  302. if(!temp1)
  303. {
  304. sutSms.smsEnable = 0;
  305. SlwTrace(INF, "[SMS]RErr2",1);
  306. return 4;
  307. }
  308. ptr=(uint8_t *)&conf;
  309. ReadFileData(g_iMessageFileIndex,0,5,ptr);
  310. #else
  311. #endif
  312. switch(newPara.messageResetFlag)
  313. {
  314. case 'N'://不用重置
  315. sutSms.smsEnable = 1;
  316. //读出最新消息地址
  317. sutSms.newestAddr = newPara.messageNewAddr;
  318. return 1;
  319. break;
  320. case 'R'://重置
  321. SlwTrace(INF, "[SMS]Reset",1);
  322. break;
  323. default://文件内容错误
  324. SlwTrace(INF, "[SMS]RErr3",1);
  325. sutSms.smsEnable = 0;
  326. return 5;
  327. break;
  328. }
  329. //2,根据短信格式初始化消息内存
  330. GuiShowStr(26,13,"消息内存配置1/2",0x01,0);
  331. GuiDrawRect(29,50+50,128,66+50,1);
  332. //还是得将1M的消息空间擦除掉
  333. //扇区大小4K
  334. //算出扇区地址
  335. //SMS_START_ADDRESS一定要设置成整4K的
  336. startSector = SMS_START_ADDRESS/4096;//消息位置的开始sector数
  337. totalBytes = SMS_TOTAL_NUM*SMS_SIZE_PER;
  338. sectorNum = totalBytes/4096;
  339. if(totalBytes%4096) sectorNum ++;
  340. for(k=0;k<sectorNum;k++)
  341. {
  342. sFlash_Erase_Sector(startSector+k);
  343. if(k%10) IWDG_ReloadCounter();
  344. process = k*100/sectorNum;
  345. GuiFillRect(29,50+51+1,29+process,66+49-1,COLOR_BLUE);
  346. }
  347. GuiShowStr(26,13,"消息内存配置2/2",0x01,0);
  348. GuiClearRect(30,50+51,127,66+49);
  349. ////////////////////////////////////////////////////
  350. ptr = (unsigned char *)&smsinfo;
  351. for(i=0;i<SMS_TOTAL_NUM;i++)
  352. {
  353. smsinfo.flag = 0;
  354. smsinfo.read = 0;
  355. smsinfo.len = 0;
  356. smsinfo.recTime = 0;
  357. if(0==i)
  358. {//第一条
  359. smsinfo.upperAddr = SMS_START_ADDRESS+(SMS_TOTAL_NUM-1)*SMS_SIZE_PER;//连接最后一条地址
  360. smsinfo.nextAddr = SMS_START_ADDRESS+SMS_SIZE_PER;//指向下一条地址
  361. sutSms.emptyAddr = smsinfo.upperAddr;//空地址为上一条
  362. //sFlash_Write(defaultSMS, SMS_START_ADDRESS+SMS_INFO_DETAIL_OFFSET, sizeof(defaultSMS));
  363. }else if(i == (SMS_TOTAL_NUM-1))
  364. {//最后一条
  365. smsinfo.upperAddr = SMS_START_ADDRESS+(SMS_TOTAL_NUM-2)*SMS_SIZE_PER;//倒数第二条地址
  366. smsinfo.nextAddr = SMS_START_ADDRESS;//第一条地址
  367. //sFlash_Write(defaultSMS, SMS_START_ADDRESS+i*SMS_SIZE_PER+SMS_INFO_DETAIL_OFFSET, sizeof(defaultSMS));
  368. }
  369. else
  370. {
  371. smsinfo.upperAddr = SMS_START_ADDRESS+(i-1)*SMS_SIZE_PER;
  372. smsinfo.nextAddr = SMS_START_ADDRESS+(i+1)*SMS_SIZE_PER;
  373. //sFlash_Write(defaultSMS, SMS_START_ADDRESS+i*SMS_SIZE_PER+SMS_INFO_DETAIL_OFFSET, sizeof(defaultSMS));
  374. }
  375. sFlash_Write(ptr, SMS_START_ADDRESS+i*SMS_SIZE_PER, sizeof(struct SUT_SMS_INFO_HEADER));
  376. if(i%20)
  377. IWDG_ReloadCounter();
  378. if(i%10==0)
  379. {
  380. process = i*100/SMS_TOTAL_NUM;
  381. GuiDrawVLine(52+50,64+50,29+process,1,COLOR_DEFAULT_BLUE);
  382. }
  383. }
  384. newPara.messageResetFlag = 'N';
  385. newPara.messageNewAddr = SMS_START_ADDRESS;
  386. //save sys
  387. ModifyConfigureFile(0);
  388. //3,初始化参数
  389. sutSms.newestAddr = SMS_START_ADDRESS;
  390. sutSms.smsTotalNum=0;
  391. sutSms.smsUnReadNum=0;
  392. sutSms.haveUnRead = 0;
  393. sutSms.smsUpdate = 0;
  394. sutSms.poolFull = 0;
  395. sutSms.smsEnable = 1;
  396. SmsScan(1);
  397. sFlash_Read(ptr, SMS_START_ADDRESS, sizeof(struct SUT_SMS_INFO_HEADER));
  398. return 0;
  399. }
  400. void SetMessageConfi(void)
  401. {
  402. SmsScan(ResetSMSConfi());
  403. SlwTrace(INF, "[SMS]Ok",1);
  404. }
  405. void MessageResponse(void)
  406. {
  407. if(sutSms.smsTotalNum)
  408. ListBoxResponseSMS(&sutListBox);
  409. switch(g_ulKeyValue)
  410. {
  411. case KEY_PANEL_EXIT:
  412. UISetNextStatus(UIS_MENU_MAIN);
  413. break;
  414. // case KEY_PANEL_MENU:
  415. // UISetNextStatus(UIS_MENU_MAIN);
  416. // break;
  417. case KEY_PANEL_P1:
  418. if(sutSms.smsTotalNum)
  419. UISetNextStatus(UIS_MESSAGE_READ);
  420. break;
  421. case KEY_PANEL_P2:
  422. UISetNextStatus(UIS_MESSAGE_OPTION);
  423. break;
  424. default:
  425. break;
  426. }
  427. }
  428. void MessageDeletShow(int update)
  429. {
  430. if(update)
  431. {
  432. GuiClearAll();//clear
  433. ShowCaption("消息删除",1);//0
  434. //GuiDrawHLine(0,159,20,1);
  435. ShowMessageBox("确定删除?");
  436. GuiDrawHLine(0,159,110,1);
  437. GuiShowStr(0,SUBSCRIPT_LOCATION,"[M]确定 [EXIT]取消",0x01,0);
  438. }
  439. }
  440. void MessageFormatShow(int update)
  441. {
  442. if(update)
  443. {
  444. GuiClearAll();//clear
  445. ShowCaption("消息格式化",1);//0
  446. //GuiDrawHLine(0,159,20,1);
  447. ShowMessageBox("确定删除所有?");
  448. GuiDrawHLine(0,159,110,1);
  449. GuiShowStr(0,SUBSCRIPT_LOCATION,"[M]确定 [EXIT]取消",0x01,0);
  450. }
  451. }
  452. const char *accIconFileName[]={
  453. "Mail1.bmp",
  454. "Mail2.bmp",
  455. ""
  456. };
  457. /******************************************************
  458. UIShowMailBox
  459. 信箱
  460. *******************************************************/
  461. void UIShowMailBox(int update)
  462. {
  463. uint8_t SmsNumTemp;
  464. if(update)
  465. {
  466. GuiClearAll();
  467. GuiShowStr(0,STATUS_BAR_HEIGH," 文本消息",0x01,0);
  468. //GuiDrawHLine(0,159,20,1);
  469. if(sutSms.smsTotalNum>=1)
  470. ListBoxInitSMS(&sutListBox,sutSms.smsTotalNum,accIconFileName,0);
  471. else
  472. ListBoxItemNumShowSMS(0,0);
  473. GuiShowStr(0,SUBSCRIPT_LOCATION,"[P1]查阅 [P2]选项",0x01,0);
  474. GuiDrawHLine(0,159,110,1);
  475. }
  476. }
  477. void DeleteSpecificSMS(void)
  478. {
  479. struct SUT_SMS_INFO_HEADER smsinfo,smsinfoTem,*info;
  480. uint8_t *ptr,*ptrTem,temp;
  481. uint32_t curAddr;
  482. ptr=(uint8_t *)&smsinfo;
  483. info=&smsinfo;
  484. //curAddr=SMS_START_ADDRESS+index*SMS_SIZE_PER;//要删除的消息地址
  485. curAddr=sutSms.ReadAddr[sutListBox.handle];
  486. sFlash_Read(ptr, curAddr, sizeof(struct SUT_SMS_INFO_HEADER));
  487. //0 更新数目
  488. if(1==smsinfo.read)
  489. {
  490. if(sutSms.smsUnReadNum)
  491. {
  492. sutSms.smsUnReadNum --;
  493. if(0==sutSms.smsUnReadNum)
  494. sutSms.haveUnRead =0;
  495. }
  496. }
  497. if(sutSms.smsTotalNum)
  498. sutSms.smsTotalNum --;
  499. if(sutSms.poolFull)
  500. sutSms.poolFull--;
  501. if(curAddr != sutSms.newestAddr){
  502. //1将当前要删除的消息的上下消息接连起来
  503. //1.1设置上一条消息的nextAddr
  504. ptrTem=(uint8_t *)&smsinfo.nextAddr;
  505. sFlash_Write(ptrTem, smsinfo.upperAddr+SMS_INFO_REAL_LEN+4, 4);
  506. //1.2设置下一条消息的upperAddr
  507. ptrTem=(uint8_t *)&smsinfo.upperAddr;
  508. sFlash_Write(ptrTem, smsinfo.nextAddr+SMS_INFO_REAL_LEN, 4);
  509. }
  510. //2设置要删除的消息的标志位
  511. temp=0;
  512. sFlash_Write(&temp, curAddr, 1);
  513. if(curAddr != sutSms.newestAddr)
  514. {
  515. //3把空的消息插到最新的那条消息的上面去,它的下面都会是连续的新消息,不要往下插
  516. sFlash_Read(ptr, sutSms.newestAddr, sizeof(struct SUT_SMS_INFO_HEADER));
  517. //3.1设置最新的消息的upperAddr
  518. sFlash_Write((uint8_t *)&curAddr, sutSms.newestAddr+SMS_INFO_REAL_LEN, 4);
  519. //3.2设置最新消息原来的上一条消息的nextAddr
  520. sFlash_Write((uint8_t *)&curAddr, smsinfo.upperAddr+SMS_INFO_REAL_LEN+4, 4);
  521. //4设置被删除的消息的upperAddr and nextAddr
  522. //4.1设置upperAddr
  523. sFlash_Write((uint8_t *)&smsinfo.upperAddr, curAddr+SMS_INFO_REAL_LEN, 4);
  524. //4.2设置nextAddr
  525. sFlash_Write((uint8_t *)&sutSms.newestAddr, curAddr+SMS_INFO_REAL_LEN+4, 4);
  526. }else
  527. {
  528. //如果是删除最新的那条消息,不用更改位置,只要将更改最新消息的地址即可
  529. sutSms.newestAddr = smsinfo.nextAddr;
  530. }
  531. }
  532. void MessageDeletResponse(void)
  533. {
  534. if(KEY_PANEL_MENU==g_ulKeyValue)
  535. {
  536. if(sutSms.smsTotalNum>=1)
  537. DeleteSpecificSMS();
  538. UISetNextStatus(UIS_MAIL_BOX);
  539. }
  540. if(KEY_PANEL_EXIT==g_ulKeyValue)UISetNextStatus(UIS_MAIL_BOX);
  541. //else if(KEY_PANEL_MENU==g_ulKeyValue)UISetNextStatus(UIS_MENU_MAIN);
  542. }
  543. void FormatSMS(void)
  544. {
  545. uint16_t i;
  546. uint8_t *ptr;
  547. struct SUT_SMS_INFO_HEADER info;
  548. uint32_t readAddr;
  549. uint8_t process;
  550. GuiClearRect(0,44,159,84);
  551. GuiDrawRect(29,50,128,66,1);
  552. process=0;
  553. readAddr = sutSms.newestAddr;
  554. ptr=(uint8_t *)&info;
  555. for(i=0;i<SMS_TOTAL_NUM;i++)
  556. {
  557. sFlash_Read(ptr, readAddr, sizeof(struct SUT_SMS_INFO_HEADER));
  558. if(info.flag == 1)
  559. {
  560. info.flag=0;
  561. sFlash_Write(ptr, readAddr, 1);
  562. }
  563. readAddr = info.nextAddr;
  564. if(i%10== 0)
  565. IWDG_ReloadCounter();
  566. if(i%10==0)
  567. {
  568. GuiDrawVLine(52,64,29+process,1,COLOR_DEFAULT_BLUE);
  569. process++;
  570. }
  571. }
  572. sutSms.smsTotalNum = 0;
  573. sutSms.smsUnReadNum = 0;
  574. sutSms.haveUnRead = 0;
  575. }
  576. void MessageFormatResponse(void)
  577. {
  578. if(KEY_PANEL_MENU==g_ulKeyValue)
  579. {
  580. FormatSMS();
  581. UISetNextStatus(UIS_MAIL_BOX);
  582. }
  583. if(KEY_PANEL_EXIT==g_ulKeyValue)UISetNextStatus(UIS_MAIL_BOX);
  584. //else if(KEY_PANEL_MENU==g_ulKeyValue)UISetNextStatus(UIS_MENU_MAIN);
  585. }
  586. void MessageOptionResponse(void)
  587. {
  588. char buf[30];
  589. unsigned long key;
  590. key=MenuResponse(&sutMenuSysSetup);
  591. if(KEY_PANEL_MENU==key)
  592. {
  593. switch(sutMenuSysSetup.handle)
  594. {
  595. case 0:UISetNextStatus(UIS_MESSAGE_DELE);break;
  596. case 1:UISetNextStatus(UIS_MESSAGE_FORMAT);break;
  597. }
  598. }
  599. else if(KEY_PANEL_EXIT==g_ulKeyValue) UISetNextStatus(sutUIstatus.LastStatus);
  600. //else if(KEY_PANEL_MENU==g_ulKeyValue) UISetNextStatus(UIS_MENU_MAIN);
  601. }
  602. void MessageOptionShow(int update)
  603. {
  604. static const char *apcMenuSysSetup[]=
  605. {"删除","格式化",""};
  606. if(update)
  607. {
  608. GuiClearAll();
  609. ShowCaption("文本选项",1); //0
  610. //GuiDrawHLine(0,159,20,1);
  611. GuiDrawHLine(0,159,110,1);
  612. MenuInit(&sutMenuSysSetup,apcMenuSysSetup);
  613. GuiDrawHLine(0,159,110,1);
  614. GuiShowStr(0,SUBSCRIPT_LOCATION,"[M]确定 [EXIT]退出",0x01,0);
  615. }
  616. }
  617. //读取index短信全部内容到bufPt
  618. static void ReadSpecificSms(uint8_t *bufPt)
  619. {
  620. struct SUT_SMS_INFO_HEADER info;
  621. uint8_t *ptr;
  622. ptr=(uint8_t *)&info;
  623. sFlash_Read(bufPt, sutSms.ReadAddr[sutListBox.handle]+SMS_INFO_DETAIL_OFFSET, SMS_SIGNAL_LEN);
  624. sFlash_Read(ptr, sutSms.ReadAddr[sutListBox.handle],2);
  625. info.read = 0;
  626. sFlash_Write(ptr, sutSms.ReadAddr[sutListBox.handle], 2);
  627. if(sutSms.smsUnReadNum)
  628. {
  629. sutSms.smsUnReadNum--;
  630. if(sutSms.smsUnReadNum==0)
  631. sutSms.haveUnRead = 0;
  632. }
  633. }
  634. static uint16_t lastShowIndex=0;
  635. uint8_t smsDetail[SMS_SIGNAL_LEN];
  636. void MessageReadShow(int update)
  637. {
  638. if(update)
  639. {
  640. lastShowIndex=0;
  641. memset(smsDetail,0,sizeof(smsDetail));
  642. GuiClearAll();
  643. ShowCaption("消息阅读",1);
  644. //GuiDrawHLine(0,159,20,1);
  645. ReadSpecificSms(smsDetail);
  646. MessageEditInit(&sutMEdit,8,STATUS_ITEM_HEIGH, (char *)smsDetail);
  647. lastShowIndex=MessageEditShow(&sutMEdit,(char *)smsDetail+lastShowIndex);
  648. GuiDrawHLine(0,159,110,1);
  649. #ifdef REPORT_SMS_VOICE
  650. GuiShowStr(0,SUBSCRIPT_LOCATION,"[P1]播放 [EXIT]返回",0x01);
  651. #else
  652. GuiShowStr(0,SUBSCRIPT_LOCATION,"[下]翻页 [EXIT]返回",0x01,0);
  653. #endif
  654. return;
  655. }
  656. }
  657. void MessageReadResponse(void)
  658. {
  659. unsigned short len;
  660. if(KEY_PANEL_EXIT==g_ulKeyValue)UISetNextStatus(UIS_MAIL_BOX);
  661. else if(KEY_PANEL_MENU == g_ulKeyValue)
  662. {
  663. #ifdef REPORT_SMS_VOICE
  664. // ReadSpecificSms(smsDetail);
  665. // AnsiToStrUnicode(unicodeSms,sizeof(unicodeSms),(char *)smsDetail);
  666. // ModemSendAt("AT+ZTTS=1,\"");
  667. // ModemSendAt((char *)unicodeSms);
  668. // ModemSendAt("\"\r");
  669. #endif
  670. }else if(KEY_PANEL_DOWN==g_ulKeyValue)
  671. {
  672. //printf("len:%d,%d\r\n",lastShowIndex,strlen(smsDetail));
  673. if(lastShowIndex<strlen(smsDetail))
  674. {
  675. GuiClearRect(0,24,LCD_WIDTH-1,106);
  676. MessageEditInit(&sutMEdit,8,STATUS_ITEM_HEIGH, (char *)smsDetail);
  677. len=MessageEditShow(&sutMEdit,(char *)smsDetail+lastShowIndex);
  678. if(len !=0) lastShowIndex+=len;
  679. else lastShowIndex=0;
  680. }
  681. }
  682. }
  683. void SwitchSMS_ToGB2312(void)
  684. {
  685. uint8_t *ptr;
  686. unsigned char tempSMS[SMS_SIGNAL_LEN+1];
  687. ptr = sutMess.GBKMess1+4;
  688. //source data:sutMess.GBKMess1+4;
  689. //data len:sutMess.len
  690. switch(sutMess.codeType)
  691. {
  692. case 2://unicode to gb2312
  693. memcpy(tempSMS, ptr, SMS_SIGNAL_LEN+1-4);
  694. StrUnicodeToAnsi(ptr, sutMess.len, (const char *)tempSMS);//
  695. //len no change
  696. break;
  697. default:
  698. break;
  699. }
  700. }
  701. //向上存方式
  702. void IncomingSMS(void)
  703. {
  704. struct SUT_SMS_INFO_HEADER infosms;
  705. uint8_t *ptr,i;
  706. static uint8_t showCt;
  707. unsigned char *smsPtr;
  708. unsigned char tempyear;
  709. USER_RTC_DEF time;
  710. RTC_UserGetTime(&time);
  711. if(0 == sutSms.smsEnable)
  712. {
  713. if(showCt++ == 0)
  714. SlwTrace(INF, "[SMS]Invalid",1);
  715. return;
  716. }
  717. //if(0 != sutMess.Update) return;//消息播报处理完毕
  718. if(0 == sutSms.smsUpdate) return;//没有可存储处理
  719. //sutSms.smsUpdate = 0;
  720. SlwTrace(INF, "[SMS]Store SMS",1);
  721. SmsScan(2);
  722. if(sutSms.poolFull)
  723. return;
  724. SwitchSMS_ToGB2312();
  725. // SpeakerEnable();
  726. // ModemSendAt("AT+ZTTS=1,\"36653052B065886D6F60\"\r");
  727. //1.1
  728. ptr = (uint8_t*)&infosms;
  729. infosms.flag=1;
  730. infosms.read=1;
  731. tempyear=time.year%2000;
  732. infosms.recTime = (uint32_t)tempyear<<26 |
  733. (uint32_t)time.month<<22 |
  734. (uint32_t)time.day<<17 |
  735. (uint32_t)time.hour<<12 |
  736. (uint32_t)time.min<<6 |
  737. (uint32_t)time.second<<0;
  738. infosms.len = sutMess.len;
  739. //保存头信息
  740. sFlash_Write(ptr, sutSms.emptyAddr, SMS_INFO_REAL_LEN);
  741. //保存内容
  742. smsPtr = sutMess.GBKMess1+4;
  743. //sFlash_Write((uint8_t *)sutMess.GBKMess1, sutSms.emptyAddr+SMS_INFO_DETAIL_OFFSET, SMS_SIGNAL_LEN);
  744. sFlash_Write(smsPtr, sutSms.emptyAddr+SMS_INFO_DETAIL_OFFSET, SMS_SIGNAL_LEN);
  745. sutSms.haveUnRead=1;
  746. sutSms.smsTotalNum ++;
  747. sutSms.smsUnReadNum ++;
  748. sutSms.newestAddr = sutSms.emptyAddr;
  749. //保存
  750. newPara.messageNewAddr=sutSms.newestAddr;
  751. //save sys
  752. ModifyConfigureFile(0);
  753. sutSms.smsUpdate = 0;
  754. }
  755. void SMSHandle(void)
  756. {
  757. unsigned char temp1,temp2;
  758. unsigned short i;
  759. char buf[30];
  760. static unsigned int cnt=0;
  761. unsigned char *p;
  762. if(sutMess.startCntFlag)
  763. {
  764. // if(os_time_get() > cnt)
  765. // {//秒粗计数器
  766. // cnt=os_time_get()+100;
  767. // if(++sutMess.skipCnt>20)
  768. // {//时间到了
  769. // sutMess.startCntFlag=0;
  770. // SlwTrace(INF,"Timeout",1);
  771. // }
  772. // }
  773. }
  774. if(sutSms.smsUpdate !=0) return; //未存完不处理
  775. if(sutMess.Update == 1 || sutMess.Update == 2)
  776. {
  777. printf("TTS_LEN:%d\r\n",sutMess.len);
  778. p = sutMess.GBKMess1+4;
  779. // for(i=0;i<sutMess.len;i+=4)
  780. // {
  781. // temp1 = p[i+2];
  782. // temp2 = p[i+3];
  783. // p[i+2] = p[i];
  784. // p[i+3] = p[i+1];
  785. // p[i] = temp1;
  786. // p[i+1]=temp2;
  787. // }
  788. // p[sutMess.len]=0;
  789. //MeSpeak(ENCODE_UNICODEBigend, (char *)p);
  790. MeSpeak(ENCODE_ASCII, (char *)p);
  791. sutMess.Update=0;
  792. }
  793. }