message.c 24 KB

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