/**************************************** ÏûÏ¢¹ÜÀí1.·¢ËÍ£»2½ÓÊÕ£»3.´æ´¢;4.¶ÁÈ¡£» ****************************************/ #include "includes.h" SUT_MESAGE_LIST g_sutMesageList; /***************************************************************** MESAGESysReadIndex 从这里读取短信 ******************************************************************/ void MESAGESysReadIndex(void) { unsigned char *pBuf; int fd; fd=nwy_sdk_fopen(SMS_FILE, NWY_RDONLY); if(fd<0){ MSG_ERR(1,"%s read index but open failed", SMS_FILE); return; } pBuf=(unsigned char *)&g_sutMesageList; nwy_sdk_fread(fd,pBuf, sizeof(SUT_MESAGE_LIST)); //sFlash_Read(pBuf,MESAGE_DATA_ADDR,sizeof(SUT_MESAGE_LIST)); nwy_sdk_fclose(fd); } /****************************************************************** MESAGESysSaveIndex *******************************************************************/ void MESAGESysSaveIndex(void) { unsigned char *pBuf; int fd; fd=nwy_sdk_fopen(SMS_FILE, NWY_RDWR); if(fd<0){ MSG_ERR(1,"[SMS]%s save index but open err",SMS_FILE); return; } pBuf=(unsigned char *)&g_sutMesageList; nwy_sdk_fread(fd,pBuf, sizeof(SUT_MESAGE_LIST)); //sFlash_Write(pBuf,MESAGE_DATA_ADDR,sizeof(SUT_MESAGE_LIST)); nwy_sdk_fclose(fd); } /*************************************************************** 先暂且他不会损坏 ****************************************************************/ /**************************************************************** 获取短信实际长度 *****************************************************************/ 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; if(len<0) return 0; else return len; } /***************************************************************** ¶ÁÈ¡¶ÌÐÅ **********************************************************************/ int ReadMessageData(int MessageIndex,unsigned int startAddr,unsigned int readLen,unsigned char *pData) { int len; unsigned int addr; int fd; 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; fd=nwy_sdk_fopen(SMS_FILE, NWY_RDONLY); if(fd<0){ MSG_ERR(1,"%s read data but open failed", SMS_FILE); return 0; } nwy_sdk_fseek(fd, addr, NWY_SEEK_SET); nwy_sdk_fread(fd,pData, len); //sFlash_Read(pData,addr,len); nwy_sdk_fclose(fd); return len; } #if 1 void MessageEditInit(SUT_MESSAGE_EDIT *p,unsigned short x,unsigned char y,char *def, FONT_MODEENUM fontMode) { p->x=x; p->y=y; p->len=strlen(def); p->item=0; p->font=fontMode; if(fontMode==FONT_MODE_12X12){ p->ylen=12; p->xlen=13;//显示中文时占的宽度 }else{ p->ylen=16; p->xlen=16;//显示中文时占的宽度 } } uint16_t MessageEditShow(SUT_MESSAGE_EDIT *p,char *def) { #if 0 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,guiGetBackColor()); memset(p->buffer1,0,sizeof(p->buffer1)); x=GLCD_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,FONT_MODE_12X12,REVERSED_NO,COLOR_BLACK,guiGetBackColor()); index += item; item=0; if(page>=5) return index; } } p->buffer1[item]=0; guiShowStr(p->x,p->y+page++*16,p->buffer1,FONT_MODE_12X12,REVERSED_NO,COLOR_BLACK,guiGetBackColor()); #else//英文/12中文显示, 动态计算每行显示,尽可能每行显示多内容 遇到0x0a则换行显示 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; int dotLen; int xWidth; int yHeight=p->ylen+3;//字体上下间隔3 int extlen=0;//换行长度 //guiClearArea(p->x,p->y,p->x+p->xlen,p->y+p->ylen,guiGetBackColor()); memset(p->buffer1,0,sizeof(p->buffer1)); x=GLCD_WIDTH-p->x-1; p->item=x;//×î¶àÒ»ÐпÉÒÔÏÔʾ¶àÉÙ¸ö×Ö½Ú page=0; dotLen=x; item = 0; write = 0; while(*temp != 0) { if(*temp > 0x9f) { if(dotLen>=p->xlen) { memcpy(&p->buffer1[0]+item, temp, 2); item += 2; temp += 2; dotLen -= p->xlen; }else write = 1; }else if(*temp==0x0a){ temp ++; write=1; extlen=1; }else { if(dotLen>=8) { p->buffer1[item] = *temp; item ++; temp ++; dotLen -= 8; } else write=1; } if(write) { write=0; p->buffer1[item]=0; guiShowStr(p->x,p->y+page++*yHeight,p->buffer1,p->font,REVERSED_NO,COLOR_BLACK,guiGetBackColor()); index += item+extlen; item=0; extlen=0; dotLen=x; if(p->y+(page+1)*yHeight >=UI_BOTTOM_LINE_Y) return index; if(page>=5) return index; } } p->buffer1[item]=0; guiShowStr(p->x,p->y+page++*yHeight,p->buffer1,p->font,REVERSED_NO,COLOR_BLACK,guiGetBackColor()); #endif 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