Message.c 19 KB

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