/**************************************** 消息管理1.发送;2接收;3.存储;4.读取; ****************************************/ #include "includes.h" SUT_MESAGE_LIST g_sutMesageList; /***************************************************************** MESAGESysReadIndex 从这里读取短信 ******************************************************************/ void MESAGESysReadIndex(void) { u8 *pBuf; pBuf=(u8 *)&g_sutMesageList; sFlash_Read(pBuf,MESAGE_DATA_ADDR,sizeof(SUT_MESAGE_LIST)); } /****************************************************************** MESAGESysSaveIndex *******************************************************************/ void MESAGESysSaveIndex(void) { u8 *pBuf; pBuf=(u8 *)&g_sutMesageList; sFlash_Write(pBuf,MESAGE_DATA_ADDR,sizeof(SUT_MESAGE_LIST)); } /*************************************************************** 先暂且他不会损坏 ****************************************************************/ /**************************************************************** 获取短信实际长度 *****************************************************************/ int GetMessageLen(int MessageIndex) { int len; if(MessageIndex<0)return 0; len=g_sutMesageList.MESAGEInfo[MessageIndex].MESAGELen; if(len<0 || len>(MESAGE_DATA_ADDR_END-MESAGE_DATA_ADDR))return 0; else return len; } /***************************************************************** 读取短信 **********************************************************************/ int ReadMessageData(int MessageIndex,u32 startAddr,u32 readLen,unsigned char *pData) { int len; u32 addr; if(MessageIndex<0)return 0; if(MessageIndex>=g_sutMesageList.MESAGECount)return 0; if((startAddr+readLen)>g_sutMesageList.MESAGEInfo[MessageIndex].MESAGELen){ len=g_sutMesageList.MESAGEInfo[MessageIndex].MESAGELen-startAddr; }else{ len=readLen; } addr=g_sutMesageList.MESAGEInfo[MessageIndex].MESAGEAddr + startAddr; sFlash_Read(pData,addr,len); return len; } #if 1 void MessageEditInit(SUT_MESSAGE_EDIT *p,unsigned short x,unsigned char y,char *def) { p->x=x; p->y=y; p->len=strlen(def); p->ylen=16; p->item=0; } uint16_t MessageEditShow(SUT_MESSAGE_EDIT *p,char *def) { uint16_t index=0; unsigned short x; char *temp =def; char buf[62]; char buf1[4]; uint8_t i; uint8_t item,page; uint8_t write; GuiClearArea(p->x,p->y,p->x+p->xlen,p->y+p->ylen); memset(p->buffer1,0,sizeof(p->buffer1)); x=LCD_WIDTH-p->x-1; p->item=x/8;//最多一行可以显示多少个字节 page=0; item = 0; write = 0; while(*temp != 0) { if(*temp > 0x9f) { if(p->item-item >=2) { memcpy(&p->buffer1[0]+item, temp, 2); item += 2; temp += 2; }else write = 1; } else { if(p->item-item >= 1) { p->buffer1[item] = *temp; item ++; temp ++; } else write=1; } if(write) { write=0; p->buffer1[item]=0; GuiShowStr(p->x,p->y+page++*16,p->buffer1,0x10,0); index += item; item=0; if(page>=5) return index; } } p->buffer1[item]=0; GuiShowStr(p->x,p->y+page++*16,p->buffer1,0x10,0); return 0; } #else void MessageEditInit(SUT_MESSAGE_EDIT *p,unsigned short x,unsigned char y,char *def) { p->x=x; p->y=y; strncpy(p->buffer,def,NUM_EDIT_BUFFER_LEN_MAX); p->len=strlen(p->buffer); p->xlen=p->len*8; p->ylen=16; p->item=0; } void MessageEditShow(SUT_MESSAGE_EDIT *p,char *def) { unsigned short x,w,j=0; char *temp =def; char buf[3]; GuiClearArea(p->x,p->y,p->x+p->xlen,p->y+p->ylen); x=p->item*8; p->len=strlen(def);//多此一举 snprintf(buf, sizeof(buf),"%d",p->len); SlwTrace(INF,buf); memset(p->buffer1,0,sizeof(p->buffer1)); IWDG_ReloadCounter(); // if(((int)p->len)<100&&(g_ucMessageFlag==0)){ while(j<(int)(p->len)/18+1){ strncpy(p->buffer1,temp+j*18,18);//0-17//p->buffer p->buffer[18]=0; GuiShowStr(p->x,p->y+j*16,p->buffer1,0x01); if((j)*18>p->len)break; j++; } } #endif