ManageMessage.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. u8 *pBuf;
  13. pBuf=(u8 *)&g_sutMesageList;
  14. sFlash_Read(pBuf,MESAGE_DATA_ADDR,sizeof(SUT_MESAGE_LIST));
  15. }
  16. /******************************************************************
  17. MESAGESysSaveIndex
  18. *******************************************************************/
  19. void MESAGESysSaveIndex(void)
  20. {
  21. u8 *pBuf;
  22. pBuf=(u8 *)&g_sutMesageList;
  23. sFlash_Write(pBuf,MESAGE_DATA_ADDR,sizeof(SUT_MESAGE_LIST));
  24. }
  25. /***************************************************************
  26. 先暂且他不会损坏
  27. ****************************************************************/
  28. /****************************************************************
  29. 获取短信实际长度
  30. *****************************************************************/
  31. int GetMessageLen(int MessageIndex)
  32. {
  33. int len;
  34. if(MessageIndex<0)return 0;
  35. len=g_sutMesageList.MESAGEInfo[MessageIndex].MESAGELen;
  36. if(len<0 || len>(MESAGE_DATA_ADDR_END-MESAGE_DATA_ADDR))return 0;
  37. else return len;
  38. }
  39. /*****************************************************************
  40. 读取短信
  41. **********************************************************************/
  42. int ReadMessageData(int MessageIndex,u32 startAddr,u32 readLen,unsigned char *pData)
  43. {
  44. int len;
  45. u32 addr;
  46. if(MessageIndex<0)return 0;
  47. if(MessageIndex>=g_sutMesageList.MESAGECount)return 0;
  48. if((startAddr+readLen)>g_sutMesageList.MESAGEInfo[MessageIndex].MESAGELen){
  49. len=g_sutMesageList.MESAGEInfo[MessageIndex].MESAGELen-startAddr;
  50. }else{
  51. len=readLen;
  52. }
  53. addr=g_sutMesageList.MESAGEInfo[MessageIndex].MESAGEAddr + startAddr;
  54. sFlash_Read(pData,addr,len);
  55. return len;
  56. }
  57. #if 1
  58. void MessageEditInit(SUT_MESSAGE_EDIT *p,unsigned short x,unsigned char y,char *def)
  59. {
  60. p->x=x;
  61. p->y=y;
  62. p->len=strlen(def);
  63. p->ylen=16;
  64. p->item=0;
  65. }
  66. uint16_t MessageEditShow(SUT_MESSAGE_EDIT *p,char *def)
  67. {
  68. uint16_t index=0;
  69. unsigned short x;
  70. char *temp =def;
  71. char buf[62];
  72. char buf1[4];
  73. uint8_t i;
  74. uint8_t item,page;
  75. uint8_t write;
  76. GuiClearArea(p->x,p->y,p->x+p->xlen,p->y+p->ylen);
  77. memset(p->buffer1,0,sizeof(p->buffer1));
  78. x=LCD_WIDTH-p->x-1;
  79. p->item=x/8;//最多一行可以显示多少个字节
  80. page=0;
  81. item = 0;
  82. write = 0;
  83. while(*temp != 0)
  84. {
  85. if(*temp > 0x9f)
  86. {
  87. if(p->item-item >=2)
  88. {
  89. memcpy(&p->buffer1[0]+item, temp, 2);
  90. item += 2;
  91. temp += 2;
  92. }else
  93. write = 1;
  94. }
  95. else
  96. {
  97. if(p->item-item >= 1)
  98. {
  99. p->buffer1[item] = *temp;
  100. item ++;
  101. temp ++;
  102. }
  103. else
  104. write=1;
  105. }
  106. if(write)
  107. {
  108. write=0;
  109. p->buffer1[item]=0;
  110. GuiShowStr(p->x,p->y+page++*16,p->buffer1,0x01);
  111. index += item;
  112. item=0;
  113. if(page>=5) return index;
  114. }
  115. }
  116. p->buffer1[item]=0;
  117. GuiShowStr(p->x,p->y+page++*16,p->buffer1,0x01);
  118. return 0;
  119. }
  120. #else
  121. void MessageEditInit(SUT_MESSAGE_EDIT *p,unsigned short x,unsigned char y,char *def)
  122. {
  123. p->x=x;
  124. p->y=y;
  125. strncpy(p->buffer,def,NUM_EDIT_BUFFER_LEN_MAX);
  126. p->len=strlen(p->buffer);
  127. p->xlen=p->len*8;
  128. p->ylen=16;
  129. p->item=0;
  130. }
  131. void MessageEditShow(SUT_MESSAGE_EDIT *p,char *def)
  132. {
  133. unsigned short x,w,j=0;
  134. char *temp =def;
  135. char buf[3];
  136. GuiClearArea(p->x,p->y,p->x+p->xlen,p->y+p->ylen);
  137. x=p->item*8;
  138. p->len=strlen(def);//多此一举
  139. snprintf(buf, sizeof(buf),"%d",p->len);
  140. SlwTrace(INF,buf);
  141. memset(p->buffer1,0,sizeof(p->buffer1));
  142. IWDG_ReloadCounter();
  143. // if(((int)p->len)<100&&(g_ucMessageFlag==0)){
  144. while(j<(int)(p->len)/18+1){
  145. strncpy(p->buffer1,temp+j*18,18);//0-17//p->buffer
  146. p->buffer[18]=0;
  147. GuiShowStr(p->x,p->y+j*16,p->buffer1,0x01);
  148. if((j)*18>p->len)break;
  149. j++;
  150. }
  151. }
  152. #endif