#include "includes.h" #define APP_LOG_MAX_SIZE (3*1024) #define APP_LOG "applog.txt" void takeNoteOfSerType(void){ sutApp.serverDef=newPara.serList.defaultuse; MSG_INFO(1, "pri server option:%d\n", sutApp.serverDef); } typedef struct{ int fd; MY_CLOCK myclock; LSAPI_FS_Stat_info_t pbuf; char info[20+20+10]; }LOG_PARADEF; LOG_PARADEF logPara={0}; void takeNoteFile(char *reason){ int offset,i,j,k; int extneedsize; if(sutApp.serverDef==newPara.serList.defaultuse) return; ohpocGetClock(&logPara.myclock); snprintf(logPara.info, sizeof(logPara.info),"*[%04d-%02d-%02d,%02d:%02d:%02d,%d,%d,%s]\n", logPara.myclock.year, logPara.myclock.month, logPara.myclock.day, logPara.myclock.hour, logPara.myclock.min, logPara.myclock.sec, sutApp.serverDef,newPara.serList.defaultuse, reason); MSG_WARN(1, logPara.info); logPara.fd=LSAPI_FS_Open(APP_LOG, LSAPI_FS_O_RDWR|LSAPI_FS_O_CREAT,0x0); if(logPara.fd<0){ MSG_ERR(1,"%s open failed",APP_LOG); return; } LSAPI_FS_Fstat(logPara.fd, &logPara.pbuf); //检测是否够写,如果不够写,则将第一条删除 if((logPara.pbuf.st_size+strlen(logPara.info))>APP_LOG_MAX_SIZE){ extneedsize=strlen(logPara.info)-(APP_LOG_MAX_SIZE-logPara.pbuf.st_size);//至少还需要这么多 unsigned char *ptr=(unsigned char *)malloc(logPara.pbuf.st_size*sizeof(unsigned char)); if(ptr==NULL){//如果申请失败,那这一条信息就直接覆盖第一条好了 MSG_WARN(1, "malloc failed, save to 0"); offset=0; }else{//将文件所有数据先读出来 LSAPI_FS_Read(logPara.fd, ptr, logPara.pbuf.st_size); //然后删除数据直到够存本条信息 j=0; for(i=0;i=extneedsize) break;//够数据了 } } //整体数据移动j for(i=j;i(APP_LOG_MAX_SIZE-30)) reachFull=1;//基础每一条长度30左右,提示已慢,提示可删除 unsigned char *ptr=(unsigned char *)malloc(pbuf.st_size*sizeof(unsigned char)+1); if(ptr==NULL){ MSG_WARN(1, "%s malloc err", APP_LOG); LSAPI_FS_Close(fd); goto FAILED; } if(pbuf.st_size){ len=LSAPI_FS_Read(fd, ptr, pbuf.st_size); }else len=0; LSAPI_FS_Close(fd); if(len<0) len=0; *msglen=len; ptr[len]=0; return ptr; FAILED: *msglen=0; return NULL; } unsigned char *debugmsg=NULL; int debugmsglen=0; void uiShowDebug(char update){ if(update){ guiClearAll(guiGetBackColor()); guiShowCaption(0,"更改记录",UI_STATUS_ITEM_Y+1,guiGetBackColor(),guiGetForeColor(),FONT_MODE_16X16); debugmsg=takeNoteRead(&debugmsglen); if(debugmsglen>0 && debugmsg!=NULL) newMessageInit(FONT_MODE_16X16, debugmsg, NULL, NULL); uiMenuShowBottomLine(); if(reachFull==0) uiMenuShowBottomIndacitor(NULL, "返回"); else uiMenuShowBottomIndacitor("格式化", "返回"); return; } } void uiShowDebugResponse(void){ unsigned short key=getKeyValue(); if(MKEY_VALUE_ESC==key){ if(debugmsg != NULL) free(debugmsg); debugmsg=NULL; uISetNextStatus(UIS_STANDBY); } else if(MKEY_VALUE_DOWN==key){ if(debugmsglen>0 && debugmsg!=NULL) newMessageShow(SHOW_DOWN); }else if(MKEY_VALUE_MENU==key){ if(reachFull!=0){ char buf[50]; snprintf(buf, sizeof(buf), "AT+FSDELFILE=\"applog.txt\"\r\n",APP_LOG); msgAtSend(buf); uISetNextStatus(UIS_STANDBY); } } }