ManageMessage.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /****************************************
  2. ÏûÏ¢¹ÜÀí1.·¢ËÍ£»2½ÓÊÕ£»3.´æ´¢;4.¶ÁÈ¡£»
  3. ****************************************/
  4. #include "includes.h"
  5. SUT_MESAGE_LIST g_sutMesageList;
  6. /*****************************************************************
  7. MESAGESysReadIndex
  8. 从这里读取短信
  9. ******************************************************************/
  10. void MESAGESysReadIndex(void)
  11. {
  12. unsigned char *pBuf;
  13. int fd;
  14. fd=LSAPI_FS_Open(SMS_FILE, LSAPI_FS_O_RDONLY,0);
  15. if(fd<0){
  16. MSG_ERR(1,"%s read index but open failed", SMS_FILE);
  17. return;
  18. }
  19. pBuf=(unsigned char *)&g_sutMesageList;
  20. LSAPI_FS_Read(fd,pBuf, sizeof(SUT_MESAGE_LIST));
  21. //sFlash_Read(pBuf,MESAGE_DATA_ADDR,sizeof(SUT_MESAGE_LIST));
  22. LSAPI_FS_Close(fd);
  23. }
  24. /******************************************************************
  25. MESAGESysSaveIndex
  26. *******************************************************************/
  27. void MESAGESysSaveIndex(void)
  28. {
  29. unsigned char *pBuf;
  30. int fd;
  31. fd=LSAPI_FS_Open(SMS_FILE, LSAPI_FS_O_RDWR,0);
  32. if(fd<0){
  33. MSG_ERR(1,"[SMS]%s save index but open err",SMS_FILE);
  34. return;
  35. }
  36. pBuf=(unsigned char *)&g_sutMesageList;
  37. LSAPI_FS_Read(fd,pBuf, sizeof(SUT_MESAGE_LIST));
  38. //sFlash_Write(pBuf,MESAGE_DATA_ADDR,sizeof(SUT_MESAGE_LIST));
  39. LSAPI_FS_Close(fd);
  40. }
  41. /***************************************************************
  42. 先暂且他不会损坏
  43. ****************************************************************/
  44. /****************************************************************
  45. 获取短信实际长度
  46. *****************************************************************/
  47. int GetMessageLen(int MessageIndex)
  48. {
  49. int len;
  50. if(MessageIndex<0)return 0;
  51. len=g_sutMesageList.MESAGEInfo[MessageIndex].MESAGELen;
  52. //if(len<0 || len>(MESAGE_DATA_ADDR_END-MESAGE_DATA_ADDR))return 0;
  53. if(len<0) return 0;
  54. else return len;
  55. }
  56. /*****************************************************************
  57. ¶ÁÈ¡¶ÌÐÅ
  58. **********************************************************************/
  59. int ReadMessageData(int MessageIndex,unsigned int startAddr,unsigned int readLen,unsigned char *pData)
  60. {
  61. int len;
  62. unsigned int addr;
  63. int fd;
  64. if(MessageIndex<0)return 0;
  65. if(MessageIndex>=g_sutMesageList.MESAGECount)return 0;
  66. if((startAddr+readLen)>g_sutMesageList.MESAGEInfo[MessageIndex].MESAGELen){
  67. len=g_sutMesageList.MESAGEInfo[MessageIndex].MESAGELen-startAddr;
  68. }else{
  69. len=readLen;
  70. }
  71. addr=g_sutMesageList.MESAGEInfo[MessageIndex].MESAGEAddr + startAddr;
  72. fd=LSAPI_FS_Open(SMS_FILE, LSAPI_FS_O_RDONLY,0);
  73. if(fd<0){
  74. MSG_ERR(1,"%s read data but open failed", SMS_FILE);
  75. return 0;
  76. }
  77. LSAPI_FS_Seek(fd, addr, LSAPI_FS_SEEK_SET);
  78. LSAPI_FS_Read(fd,pData, len);
  79. //sFlash_Read(pData,addr,len);
  80. LSAPI_FS_Close(fd);
  81. return len;
  82. }
  83. #if 1
  84. void MessageEditInit(SUT_MESSAGE_EDIT *p,unsigned short x,unsigned char y,char *def)
  85. {
  86. p->x=x;
  87. p->y=y;
  88. p->len=strlen(def);
  89. p->ylen=16;
  90. p->item=0;
  91. }
  92. uint16_t MessageEditShow(SUT_MESSAGE_EDIT *p,char *def)
  93. {
  94. uint16_t index=0;
  95. unsigned short x;
  96. char *temp =def;
  97. char buf[62];
  98. char buf1[4];
  99. uint8_t i;
  100. uint8_t item,page;
  101. uint8_t write;
  102. guiClearArea(p->x,p->y,p->x+p->xlen,p->y+p->ylen,guiGetBackColor());
  103. memset(p->buffer1,0,sizeof(p->buffer1));
  104. x=GLCD_WIDTH-p->x-1;
  105. p->item=x/8;//×î¶àÒ»ÐпÉÒÔÏÔʾ¶àÉÙ¸ö×Ö½Ú
  106. page=0;
  107. item = 0;
  108. write = 0;
  109. while(*temp != 0)
  110. {
  111. if(*temp > 0x9f)
  112. {
  113. if(p->item-item >=2)
  114. {
  115. memcpy(&p->buffer1[0]+item, temp, 2);
  116. item += 2;
  117. temp += 2;
  118. }else
  119. write = 1;
  120. }
  121. else
  122. {
  123. if(p->item-item >= 1)
  124. {
  125. p->buffer1[item] = *temp;
  126. item ++;
  127. temp ++;
  128. }
  129. else
  130. write=1;
  131. }
  132. if(write)
  133. {
  134. write=0;
  135. p->buffer1[item]=0;
  136. guiShowStr(p->x,p->y+page++*16,p->buffer1,FONT_MODE_12X12,REVERSED_NO,COLOR_BLACK,guiGetBackColor());
  137. index += item;
  138. item=0;
  139. if(page>=5) return index;
  140. }
  141. }
  142. p->buffer1[item]=0;
  143. guiShowStr(p->x,p->y+page++*16,p->buffer1,FONT_MODE_12X12,REVERSED_NO,COLOR_BLACK,guiGetBackColor());
  144. return 0;
  145. }
  146. #else
  147. void MessageEditInit(SUT_MESSAGE_EDIT *p,unsigned short x,unsigned char y,char *def)
  148. {
  149. p->x=x;
  150. p->y=y;
  151. strncpy(p->buffer,def,NUM_EDIT_BUFFER_LEN_MAX);
  152. p->len=strlen(p->buffer);
  153. p->xlen=p->len*8;
  154. p->ylen=16;
  155. p->item=0;
  156. }
  157. void MessageEditShow(SUT_MESSAGE_EDIT *p,char *def)
  158. {
  159. unsigned short x,w,j=0;
  160. char *temp =def;
  161. char buf[3];
  162. GuiClearArea(p->x,p->y,p->x+p->xlen,p->y+p->ylen);
  163. x=p->item*8;
  164. p->len=strlen(def);//¶à´ËÒ»¾Ù
  165. snprintf(buf, sizeof(buf),"%d",p->len);
  166. SlwTrace(INF,buf);
  167. memset(p->buffer1,0,sizeof(p->buffer1));
  168. IWDG_ReloadCounter();
  169. // if(((int)p->len)<100&&(g_ucMessageFlag==0)){
  170. while(j<(int)(p->len)/18+1){
  171. strncpy(p->buffer1,temp+j*18,18);//0-17//p->buffer
  172. p->buffer[18]=0;
  173. GuiShowStr(p->x,p->y+j*16,p->buffer1,0x01);
  174. if((j)*18>p->len)break;
  175. j++;
  176. }
  177. }
  178. #endif