ManageMessage.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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=nwy_sdk_fopen(SMS_FILE, NWY_RDONLY);
  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. nwy_sdk_fread(fd,pBuf, sizeof(SUT_MESAGE_LIST));
  21. //sFlash_Read(pBuf,MESAGE_DATA_ADDR,sizeof(SUT_MESAGE_LIST));
  22. nwy_sdk_fclose(fd);
  23. }
  24. /******************************************************************
  25. MESAGESysSaveIndex
  26. *******************************************************************/
  27. void MESAGESysSaveIndex(void)
  28. {
  29. unsigned char *pBuf;
  30. int fd;
  31. fd=nwy_sdk_fopen(SMS_FILE, NWY_RDWR);
  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. nwy_sdk_fread(fd,pBuf, sizeof(SUT_MESAGE_LIST));
  38. //sFlash_Write(pBuf,MESAGE_DATA_ADDR,sizeof(SUT_MESAGE_LIST));
  39. nwy_sdk_fclose(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=nwy_sdk_fopen(SMS_FILE, NWY_RDONLY);
  73. if(fd<0){
  74. MSG_ERR(1,"%s read data but open failed", SMS_FILE);
  75. return 0;
  76. }
  77. nwy_sdk_fseek(fd, addr, NWY_SEEK_SET);
  78. nwy_sdk_fread(fd,pData, len);
  79. //sFlash_Read(pData,addr,len);
  80. nwy_sdk_fclose(fd);
  81. return len;
  82. }
  83. #if 1
  84. void MessageEditInit(SUT_MESSAGE_EDIT *p,unsigned short x,unsigned char y,char *def, FONT_MODEENUM fontMode)
  85. {
  86. p->x=x;
  87. p->y=y;
  88. p->len=strlen(def);
  89. p->item=0;
  90. p->font=fontMode;
  91. if(fontMode==FONT_MODE_12X12){
  92. p->ylen=12;
  93. p->xlen=13;//显示中文时占的宽度
  94. }else{
  95. p->ylen=16;
  96. p->xlen=16;//显示中文时占的宽度
  97. }
  98. }
  99. uint16_t MessageEditShow(SUT_MESSAGE_EDIT *p,char *def)
  100. {
  101. #if 0
  102. uint16_t index=0;
  103. unsigned short x;
  104. char *temp =def;
  105. char buf[62];
  106. char buf1[4];
  107. uint8_t i;
  108. uint8_t item,page;
  109. uint8_t write;
  110. guiClearArea(p->x,p->y,p->x+p->xlen,p->y+p->ylen,guiGetBackColor());
  111. memset(p->buffer1,0,sizeof(p->buffer1));
  112. x=GLCD_WIDTH-p->x-1;
  113. p->item=x/8;//×î¶àÒ»ÐпÉÒÔÏÔʾ¶àÉÙ¸ö×Ö½Ú
  114. page=0;
  115. item = 0;
  116. write = 0;
  117. while(*temp != 0)
  118. {
  119. if(*temp > 0x9f)
  120. {
  121. if(p->item-item >=2)
  122. {
  123. memcpy(&p->buffer1[0]+item, temp, 2);
  124. item += 2;
  125. temp += 2;
  126. }else
  127. write = 1;
  128. }
  129. else
  130. {
  131. if(p->item-item >= 1)
  132. {
  133. p->buffer1[item] = *temp;
  134. item ++;
  135. temp ++;
  136. }
  137. else
  138. write=1;
  139. }
  140. if(write)
  141. {
  142. write=0;
  143. p->buffer1[item]=0;
  144. guiShowStr(p->x,p->y+page++*16,p->buffer1,FONT_MODE_12X12,REVERSED_NO,COLOR_BLACK,guiGetBackColor());
  145. index += item;
  146. item=0;
  147. if(page>=5) return index;
  148. }
  149. }
  150. p->buffer1[item]=0;
  151. guiShowStr(p->x,p->y+page++*16,p->buffer1,FONT_MODE_12X12,REVERSED_NO,COLOR_BLACK,guiGetBackColor());
  152. #else//英文/12中文显示, 动态计算每行显示,尽可能每行显示多内容 遇到0x0a则换行显示
  153. uint16_t index=0;
  154. unsigned short x;
  155. char *temp =def;
  156. char buf[62];
  157. char buf1[4];
  158. uint8_t i;
  159. uint8_t item,page;
  160. uint8_t write;
  161. int dotLen;
  162. int xWidth;
  163. int yHeight=p->ylen+3;//字体上下间隔3
  164. int extlen=0;//换行长度
  165. //guiClearArea(p->x,p->y,p->x+p->xlen,p->y+p->ylen,guiGetBackColor());
  166. memset(p->buffer1,0,sizeof(p->buffer1));
  167. x=GLCD_WIDTH-p->x-1;
  168. p->item=x;//×î¶àÒ»ÐпÉÒÔÏÔʾ¶àÉÙ¸ö×Ö½Ú
  169. page=0;
  170. dotLen=x;
  171. item = 0;
  172. write = 0;
  173. while(*temp != 0)
  174. {
  175. if(*temp > 0x9f)
  176. {
  177. if(dotLen>=p->xlen)
  178. {
  179. memcpy(&p->buffer1[0]+item, temp, 2);
  180. item += 2;
  181. temp += 2;
  182. dotLen -= p->xlen;
  183. }else
  184. write = 1;
  185. }else if(*temp==0x0a){
  186. temp ++;
  187. write=1;
  188. extlen=1;
  189. }else
  190. {
  191. if(dotLen>=8)
  192. {
  193. p->buffer1[item] = *temp;
  194. item ++;
  195. temp ++;
  196. dotLen -= 8;
  197. }
  198. else
  199. write=1;
  200. }
  201. if(write)
  202. {
  203. write=0;
  204. p->buffer1[item]=0;
  205. guiShowStr(p->x,p->y+page++*yHeight,p->buffer1,p->font,REVERSED_NO,COLOR_BLACK,guiGetBackColor());
  206. index += item+extlen;
  207. item=0;
  208. extlen=0;
  209. dotLen=x;
  210. if(p->y+(page+1)*yHeight >=UI_BOTTOM_LINE_Y) return index;
  211. if(page>=5) return index;
  212. }
  213. }
  214. p->buffer1[item]=0;
  215. guiShowStr(p->x,p->y+page++*yHeight,p->buffer1,p->font,REVERSED_NO,COLOR_BLACK,guiGetBackColor());
  216. #endif
  217. return 0;
  218. }
  219. #else
  220. void MessageEditInit(SUT_MESSAGE_EDIT *p,unsigned short x,unsigned char y,char *def)
  221. {
  222. p->x=x;
  223. p->y=y;
  224. strncpy(p->buffer,def,NUM_EDIT_BUFFER_LEN_MAX);
  225. p->len=strlen(p->buffer);
  226. p->xlen=p->len*8;
  227. p->ylen=16;
  228. p->item=0;
  229. }
  230. void MessageEditShow(SUT_MESSAGE_EDIT *p,char *def)
  231. {
  232. unsigned short x,w,j=0;
  233. char *temp =def;
  234. char buf[3];
  235. GuiClearArea(p->x,p->y,p->x+p->xlen,p->y+p->ylen);
  236. x=p->item*8;
  237. p->len=strlen(def);//¶à´ËÒ»¾Ù
  238. snprintf(buf, sizeof(buf),"%d",p->len);
  239. SlwTrace(INF,buf);
  240. memset(p->buffer1,0,sizeof(p->buffer1));
  241. IWDG_ReloadCounter();
  242. // if(((int)p->len)<100&&(g_ucMessageFlag==0)){
  243. while(j<(int)(p->len)/18+1){
  244. strncpy(p->buffer1,temp+j*18,18);//0-17//p->buffer
  245. p->buffer[18]=0;
  246. GuiShowStr(p->x,p->y+j*16,p->buffer1,0x01);
  247. if((j)*18>p->len)break;
  248. j++;
  249. }
  250. }
  251. #endif