Message.c 20 KB

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