/**************************************** ÏûÏ¢¹ÜÀí1.·¢ËÍ£»2½ÓÊÕ£»3.´æ´¢;4.¶ÁÈ¡£» ****************************************/ #include "includes.h" SUT_MESAGE_LIST g_sutMesageList; /***************************************************************** MESAGESysReadIndex 从这里读取短信 ******************************************************************/ void MESAGESysReadIndex(void) { unsigned char *pBuf; int fd; fd=LSAPI_FS_Open(SMS_FILE, LSAPI_FS_O_RDONLY,0); if(fd<0){ MSG_ERR(1,"%s read index but open failed", SMS_FILE); return; } pBuf=(unsigned char *)&g_sutMesageList; LSAPI_FS_Read(fd,pBuf, sizeof(SUT_MESAGE_LIST)); //sFlash_Read(pBuf,MESAGE_DATA_ADDR,sizeof(SUT_MESAGE_LIST)); LSAPI_FS_Close(fd); } /****************************************************************** MESAGESysSaveIndex *******************************************************************/ void MESAGESysSaveIndex(void) { unsigned char *pBuf; int fd; fd=LSAPI_FS_Open(SMS_FILE, LSAPI_FS_O_RDWR,0); if(fd<0){ MSG_ERR(1,"[SMS]%s save index but open err",SMS_FILE); return; } pBuf=(unsigned char *)&g_sutMesageList; LSAPI_FS_Read(fd,pBuf, sizeof(SUT_MESAGE_LIST)); //sFlash_Write(pBuf,MESAGE_DATA_ADDR,sizeof(SUT_MESAGE_LIST)); LSAPI_FS_Close(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=LSAPI_FS_Open(SMS_FILE, LSAPI_FS_O_RDONLY,0); if(fd<0){ MSG_ERR(1,"%s read data but open failed", SMS_FILE); return 0; } LSAPI_FS_Seek(fd, addr, LSAPI_FS_SEEK_SET); LSAPI_FS_Read(fd,pData, len); //sFlash_Read(pData,addr,len); LSAPI_FS_Close(fd); 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,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()); 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