message.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932
  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. static unsigned int timer;
  468. static char machine=0;
  469. if(update){
  470. guiClearAll(guiGetBackColor());
  471. guiShowCaption(40,"文本消息",UI_STATUS_ITEM_Y+1,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
  472. uiMenuShowBottomLine();
  473. machine=1;
  474. uiMenuShowBottomIndacitor(NULL, "返回");
  475. guiShowMessageBox("版本不支持");
  476. uTimerStart(&timer, 1000);
  477. return;
  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. if(machine==1){
  487. if(uTimerExpired(&timer)){
  488. machine=0;
  489. uISetNextStatus(UIS_MENU_MAIN);
  490. }
  491. }
  492. }
  493. void DeleteSpecificSMS(void)
  494. {
  495. SUT_SMS_INFO_HEADER smsinfo,smsinfoTem,*info;
  496. unsigned char *ptr,*ptrTem,temp;
  497. unsigned int curAddr;
  498. int fd;
  499. fd=LSAPI_FS_Open(SMS_FILE, LSAPI_FS_O_RDWR,0);
  500. if(fd<0){
  501. MSG_ERR(1,"%s del open but failed", SMS_FILE);
  502. return;
  503. }
  504. ptr=(unsigned char *)&smsinfo;
  505. info=&smsinfo;
  506. //curAddr=SMS_START_ADDRESS+index*SMS_SIZE_PER;//要删除的消息地址
  507. curAddr=sutSms.ReadAddr[sutListBox.handle];
  508. LSAPI_FS_Seek(fd, curAddr,LSAPI_FS_SEEK_SET);
  509. LSAPI_FS_Read(fd, ptr, sizeof( SUT_SMS_INFO_HEADER));
  510. //sFlash_Read(ptr, curAddr, sizeof(struct SUT_SMS_INFO_HEADER));
  511. //0 更新数目
  512. if(1==smsinfo.read)
  513. {
  514. if(sutSms.smsUnReadNum)
  515. {
  516. sutSms.smsUnReadNum --;
  517. if(0==sutSms.smsUnReadNum)
  518. sutSms.haveUnRead =0;
  519. }
  520. }
  521. if(sutSms.smsTotalNum)
  522. sutSms.smsTotalNum --;
  523. if(sutSms.poolFull)
  524. sutSms.poolFull--;
  525. if(curAddr != sutSms.newestAddr){
  526. //1将当前要删除的消息的上下消息接连起来
  527. //1.1设置上一条消息的nextAddr
  528. ptrTem=(unsigned char *)&smsinfo.nextAddr;
  529. LSAPI_FS_Seek(fd,smsinfo.upperAddr+SMS_INFO_REAL_LEN+4,LSAPI_FS_SEEK_SET );
  530. LSAPI_FS_Write(fd, ptrTem, 4);
  531. //sFlash_Write(ptrTem, smsinfo.upperAddr+SMS_INFO_REAL_LEN+4, 4);
  532. //1.2设置下一条消息的upperAddr
  533. ptrTem=(unsigned char *)&smsinfo.upperAddr;
  534. LSAPI_FS_Seek(fd,smsinfo.nextAddr+SMS_INFO_REAL_LEN,LSAPI_FS_SEEK_SET );
  535. LSAPI_FS_Write(fd, ptrTem, 4);
  536. //sFlash_Write(ptrTem, smsinfo.nextAddr+SMS_INFO_REAL_LEN, 4);
  537. }
  538. //2设置要删除的消息的标志位
  539. temp=0;
  540. LSAPI_FS_Seek(fd,curAddr,LSAPI_FS_SEEK_SET );
  541. LSAPI_FS_Write(fd, &temp, 1);
  542. //sFlash_Write(&temp, curAddr, 1);
  543. if(curAddr != sutSms.newestAddr)
  544. {
  545. //3把空的消息插到最新的那条消息的上面去,它的下面都会是连续的新消息,不要往下插
  546. LSAPI_FS_Seek(fd, sutSms.newestAddr, LSAPI_FS_SEEK_SET);
  547. LSAPI_FS_Read(fd, ptr, sizeof( SUT_SMS_INFO_HEADER));
  548. //sFlash_Read(ptr, sutSms.newestAddr, sizeof(struct SUT_SMS_INFO_HEADER));
  549. //3.1设置最新的消息的upperAddr
  550. LSAPI_FS_Seek(fd, sutSms.newestAddr+SMS_INFO_REAL_LEN, LSAPI_FS_SEEK_SET);
  551. LSAPI_FS_Write(fd, (unsigned char *)&curAddr, 4);
  552. //sFlash_Write((uint8_t *)&curAddr, sutSms.newestAddr+SMS_INFO_REAL_LEN, 4);
  553. //3.2设置最新消息原来的上一条消息的nextAddr
  554. LSAPI_FS_Seek(fd, smsinfo.upperAddr+SMS_INFO_REAL_LEN+4, LSAPI_FS_SEEK_SET);
  555. LSAPI_FS_Write(fd, (unsigned char *)&curAddr, 4);
  556. //sFlash_Write((uint8_t *)&curAddr, smsinfo.upperAddr+SMS_INFO_REAL_LEN+4, 4);
  557. //4设置被删除的消息的upperAddr and nextAddr
  558. //4.1设置upperAddr
  559. LSAPI_FS_Seek(fd, curAddr+SMS_INFO_REAL_LEN, LSAPI_FS_SEEK_SET);
  560. LSAPI_FS_Write(fd, (unsigned char *)&smsinfo.upperAddr, 4);
  561. //sFlash_Write((uint8_t *)&smsinfo.upperAddr, curAddr+SMS_INFO_REAL_LEN, 4);
  562. //4.2设置nextAddr
  563. LSAPI_FS_Seek(fd, curAddr+SMS_INFO_REAL_LEN+4, LSAPI_FS_SEEK_SET);
  564. LSAPI_FS_Write(fd, (unsigned char *)&sutSms.newestAddr, 4);
  565. //sFlash_Write((uint8_t *)&sutSms.newestAddr, curAddr+SMS_INFO_REAL_LEN+4, 4);
  566. }else
  567. {
  568. //如果是删除最新的那条消息,不用更改位置,只要将更改最新消息的地址即可
  569. sutSms.newestAddr = smsinfo.nextAddr;
  570. }
  571. if(fd>0) LSAPI_FS_Close(fd);
  572. }
  573. void MessageDeletResponse(void)
  574. {
  575. unsigned short key=getKeyValue();
  576. if(MKEY_VALUE_MENU==key)
  577. {
  578. if(sutSms.smsTotalNum>=1)
  579. DeleteSpecificSMS();
  580. uISetNextStatus(UIS_MENU_MAIL_SEL);
  581. }
  582. if(MKEY_VALUE_ESC==key)uISetNextStatus(UIS_MENU_MAIL_SEL);
  583. }
  584. void FormatSMS(void)
  585. {
  586. unsigned short i;
  587. unsigned char *ptr;
  588. SUT_SMS_INFO_HEADER info;
  589. unsigned int readAddr;
  590. unsigned char process;
  591. int fd;
  592. fd=LSAPI_FS_Open(SMS_FILE, LSAPI_FS_O_RDWR,0);
  593. if(fd<0){
  594. MSG_ERR(1,"%s format but open failed", SMS_FILE);
  595. return;
  596. }
  597. guiClearRect(0,44,GLCD_WIDTH,84,guiGetBackColor());
  598. guiDrawRect(29,50,128,66,1,guiGetForeColor());
  599. process=0;
  600. readAddr = sutSms.newestAddr;
  601. ptr=(unsigned char *)&info;
  602. for(i=0;i<SMS_TOTAL_NUM;i++)
  603. {
  604. LSAPI_FS_Seek(fd, readAddr,LSAPI_FS_SEEK_SET);
  605. LSAPI_FS_Read(fd, ptr, sizeof(SUT_SMS_INFO_HEADER));
  606. //sFlash_Read(ptr, readAddr, sizeof(struct SUT_SMS_INFO_HEADER));
  607. if(info.flag == 1)
  608. {
  609. info.flag=0;
  610. LSAPI_FS_Seek(fd, readAddr,LSAPI_FS_SEEK_SET);
  611. LSAPI_FS_Write(fd, ptr, 1);
  612. //sFlash_Write(ptr, readAddr, 1);
  613. }
  614. readAddr = info.nextAddr;
  615. if(i%10==0)
  616. {
  617. guiDrawVLine(52,64,29+process,1,guiGetForeColor());
  618. process++;
  619. }
  620. }
  621. if(fd>0) LSAPI_FS_Close(fd);
  622. sutSms.smsTotalNum = 0;
  623. sutSms.smsUnReadNum = 0;
  624. sutSms.haveUnRead = 0;
  625. }
  626. void MessageFormatResponse(void)
  627. {
  628. unsigned short key=getKeyValue();
  629. if(MKEY_VALUE_MENU==key)
  630. {
  631. FormatSMS();
  632. uISetNextStatus(UIS_MENU_MAIL_SEL);
  633. }
  634. if(MKEY_VALUE_ESC==key)uISetNextStatus(UIS_MENU_MAIL_SEL);
  635. }
  636. void MessageOptionResponse(void)
  637. {
  638. char buf[30];
  639. unsigned short key;
  640. key=uiMenuResponse(&sutMenuSysSetup);
  641. if(MKEY_VALUE_MENU==key)
  642. {
  643. switch(sutMenuSysSetup.handle)
  644. {
  645. case 0:uISetNextStatus(UIS_MENU_MAIL_DEL);break;
  646. case 1:uISetNextStatus(UIS_MENU_MAIL_FORMAT);break;
  647. }
  648. }
  649. else if(MKEY_VALUE_ESC==key) uISetNextStatus(sutUIstatus.LastStatus);
  650. }
  651. void MessageOptionShow(char update)
  652. {
  653. static const char *apcMenuSysSetup[]=
  654. {"删除","格式化",""};
  655. if(update)
  656. {
  657. guiClearAll(guiGetBackColor());
  658. guiShowCaption(0,"文本选项",UI_STATUS_ITEM_Y+1,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
  659. uiMenuShowBottomLine();
  660. uiMenuInit(&sutMenuSysSetup,apcMenuSysSetup, FONT_MODE_12X12);
  661. uiMenuShowBottomIndacitor("确定", "返回");
  662. }
  663. }
  664. //读取index短信全部内容到bufPt
  665. static void ReadSpecificSms(unsigned char *bufPt)
  666. {
  667. SUT_SMS_INFO_HEADER info;
  668. unsigned char *ptr;
  669. int fd;
  670. fd=LSAPI_FS_Open(SMS_FILE, LSAPI_FS_O_RDWR,0);
  671. if(fd<0){
  672. MSG_ERR(1,"%s read sms but open failed", SMS_FILE);
  673. return;
  674. }
  675. ptr=(unsigned char *)&info;
  676. LSAPI_FS_Seek(fd, sutSms.ReadAddr[sutListBox.handle]+SMS_INFO_DETAIL_OFFSET, LSAPI_FS_SEEK_SET);
  677. LSAPI_FS_Read(fd,bufPt, SMS_SIGNAL_LEN);
  678. //sFlash_Read(bufPt, sutSms.ReadAddr[sutListBox.handle]+SMS_INFO_DETAIL_OFFSET, SMS_SIGNAL_LEN);
  679. LSAPI_FS_Seek(fd, sutSms.ReadAddr[sutListBox.handle], LSAPI_FS_SEEK_SET);
  680. LSAPI_FS_Read(fd,ptr, 2);
  681. //sFlash_Read(ptr, sutSms.ReadAddr[sutListBox.handle],2);
  682. info.read = 0;
  683. LSAPI_FS_Seek(fd, sutSms.ReadAddr[sutListBox.handle], LSAPI_FS_SEEK_SET);
  684. LSAPI_FS_Write(fd,ptr, 2);
  685. //sFlash_Write(ptr, sutSms.ReadAddr[sutListBox.handle], 2);
  686. if(sutSms.smsUnReadNum)
  687. {
  688. sutSms.smsUnReadNum--;
  689. if(sutSms.smsUnReadNum==0)
  690. sutSms.haveUnRead = 0;
  691. }
  692. if(fd>0) LSAPI_FS_Close(fd);
  693. }
  694. static unsigned short lastShowIndex=0;
  695. unsigned char smsDetail[SMS_SIGNAL_LEN];
  696. void MessageReadShow(char update)
  697. {
  698. if(update)
  699. {
  700. lastShowIndex=0;
  701. memset(smsDetail,0,sizeof(smsDetail));
  702. guiClearAll(guiGetBackColor());
  703. guiShowCaption(0,"消息阅读",UI_STATUS_ITEM_Y+1,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
  704. ReadSpecificSms(smsDetail);
  705. MessageEditInit(&sutMEdit,8,UI_CONTENT_SHOW_Y+5, (char *)smsDetail);
  706. lastShowIndex=MessageEditShow(&sutMEdit,(char *)smsDetail+lastShowIndex);
  707. uiMenuShowBottomLine();
  708. #ifdef REPORT_SMS_VOICE
  709. uiMenuShowBottomIndacitor("播放", "返回");
  710. #else
  711. uiMenuShowBottomIndacitor(NULL, "返回");
  712. #endif
  713. return;
  714. }
  715. }
  716. void MessageReadResponse(void)
  717. {
  718. unsigned short len;
  719. unsigned short key=getKeyValue();
  720. if(MKEY_VALUE_ESC==getKeyValue())uISetNextStatus(UIS_MENU_MAIL_SEL);
  721. else if(MKEY_VALUE_MENU == key)
  722. {
  723. #ifdef REPORT_SMS_VOICE
  724. // ReadSpecificSms(smsDetail);
  725. // AnsiToStrUnicode(unicodeSms,sizeof(unicodeSms),(char *)smsDetail);
  726. // ModemSendAt("AT+ZTTS=1,\"");
  727. // ModemSendAt((char *)unicodeSms);
  728. // ModemSendAt("\"\r");
  729. #endif
  730. }else if(MKEY_VALUE_DOWN==key)
  731. {
  732. //printf("len:%d,%d\r\n",lastShowIndex,strlen(smsDetail));
  733. if(lastShowIndex<strlen(smsDetail))
  734. {
  735. guiClearRect(0,UI_CONTENT_SHOW_Y+5,GLCD_WIDTH-1,UI_BOTTOM_LINE_Y-2,guiGetBackColor());
  736. MessageEditInit(&sutMEdit,8,UI_CONTENT_SHOW_Y+5, (char *)smsDetail);
  737. len=MessageEditShow(&sutMEdit,(char *)smsDetail+lastShowIndex);
  738. if(len !=0) lastShowIndex+=len;
  739. else lastShowIndex=0;
  740. }
  741. }
  742. }
  743. void SwitchSMS_ToGB2312(void)
  744. {
  745. unsigned char *ptr;
  746. unsigned char tempSMS[SMS_SIGNAL_LEN+1];
  747. ptr = sutMess.GBKMess1+4;
  748. //source data:sutMess.GBKMess1+4;
  749. //data len:sutMess.len
  750. switch(sutMess.codeType)
  751. {
  752. case 2://unicode to gb2312
  753. memcpy(tempSMS, ptr, SMS_SIGNAL_LEN+1-4);
  754. //StrUnicodeToAnsi(ptr, sutMess.len, (const char *)tempSMS);//
  755. unicodeToGbk(tempSMS, ptr, &sutMess.len);
  756. //len no change
  757. break;
  758. default:
  759. break;
  760. }
  761. }
  762. //向上存方式
  763. void IncomingSMS(void)
  764. {
  765. SUT_SMS_INFO_HEADER infosms;
  766. unsigned char *ptr,i;
  767. static unsigned short showCt;
  768. unsigned char *smsPtr;
  769. unsigned char tempyear;
  770. MY_CLOCK time;
  771. /*获取系统时间*/
  772. getMyClock(&time);
  773. if(0 == sutSms.smsEnable)
  774. {
  775. if(++showCt >= 500){
  776. showCt=0;
  777. MSG_ERR(1,"[SMS]Invalid");
  778. }
  779. return;
  780. }
  781. if(0 != sutMess.Update) return;//消息播报处理完毕
  782. if(0 == sutSms.smsUpdate) return;//没有可存储处理
  783. sutSms.smsUpdate = 0;
  784. MSG_INFO(1,"[SMS]Store SMS");
  785. SmsScan(2);
  786. if(sutSms.poolFull)
  787. return;
  788. int fd;
  789. fd=LSAPI_FS_Open(SMS_FILE, LSAPI_FS_O_RDWR,0);
  790. if(fd<0){
  791. MSG_ERR(1,"%s open to save but failed",SMS_FILE);
  792. return;
  793. }
  794. SwitchSMS_ToGB2312();
  795. // SpeakerEnable();
  796. // ModemSendAt("AT+ZTTS=1,\"36653052B065886D6F60\"\r");
  797. //1.1
  798. ptr = (unsigned char*)&infosms;
  799. infosms.flag=1;
  800. infosms.read=1;
  801. tempyear=time.year%2000;
  802. infosms.recTime = (unsigned int)tempyear<<26 |
  803. (unsigned int)time.month<<22 |
  804. (unsigned int)time.day<<17 |
  805. (unsigned int)time.hour<<12 |
  806. (unsigned int)time.min<<6 |
  807. (unsigned int)time.sec<<0;
  808. infosms.len = sutMess.len;
  809. //保存头信息
  810. LSAPI_FS_Seek(fd, sutSms.emptyAddr, LSAPI_FS_SEEK_SET);
  811. LSAPI_FS_Write(fd, ptr, SMS_INFO_REAL_LEN);
  812. //保存内容
  813. smsPtr = sutMess.GBKMess1+4;
  814. LSAPI_FS_Seek(fd, sutSms.emptyAddr+SMS_INFO_DETAIL_OFFSET,LSAPI_FS_SEEK_SET);
  815. LSAPI_FS_Write(fd, smsPtr, SMS_SIGNAL_LEN);
  816. LSAPI_FS_Close(fd);
  817. sutSms.haveUnRead=1;
  818. sutSms.smsTotalNum ++;
  819. sutSms.smsUnReadNum ++;
  820. sutSms.newestAddr = sutSms.emptyAddr;
  821. //保存
  822. newPara.messageNewAddr=sutSms.newestAddr;
  823. //save sys
  824. sysIniSave();
  825. }
  826. void SMSHandle(void)
  827. {
  828. unsigned char temp1,temp2;
  829. unsigned short i;
  830. char buf[30];
  831. static unsigned int cnt=0;
  832. unsigned char *p;
  833. if(sutMess.startCntFlag)
  834. {
  835. // if(os_time_get() > cnt)
  836. // {//秒粗计数器
  837. // cnt=os_time_get()+100;
  838. // if(++sutMess.skipCnt>20)
  839. // {//时间到了
  840. // sutMess.startCntFlag=0;
  841. // SlwTrace(INF,"Timeout",1);
  842. // }
  843. // }
  844. }
  845. if(sutMess.Update == 1 || sutMess.Update == 2)
  846. {
  847. MSG_INFO(1,"TTS_LEN:%d",sutMess.len);
  848. p = sutMess.GBKMess1+4;
  849. // for(i=0;i<sutMess.len;i+=4)
  850. // {
  851. // temp1 = p[i+2];
  852. // temp2 = p[i+3];
  853. // p[i+2] = p[i];
  854. // p[i+3] = p[i+1];
  855. // p[i] = temp1;
  856. // p[i+1]=temp2;
  857. // }
  858. //p[sutMess.len]=0;
  859. ttsPlay(ENCODE_USER_UNICODE_BE, (char *)p);
  860. sutMess.Update=0;
  861. }
  862. }