#include "includes.h" void applist_dir(const char *path) { QDIR * dp = NULL; struct lfs_info info = {0}; int ret; dp = ql_opendir(path); if(dp == NULL) { MSG_INFO(1,"[FS] *** dir open fail: %s ***\r\n", path); return; } MSG_INFO(1,"[FS] dir opened: %s\r\n", path); MSG_INFO(1,"[FS] ----- start dir list -----\r\n"); MSG_INFO(1,"[FS] type\tsize\tname\r\n"); while(1) { ret = ql_readdir(dp, &info); if(ret < 0) { MSG_INFO(1,"[FS] *** dir read fail: %s ***\r\n", path); break; } else if(ret == 0) { MSG_INFO(1,"[FS] ----- end of dir list -----\r\n"); break; } else { MSG_INFO(1,"[FS] %-4d\t%-4d\t%s\r\n", info.type, info.size, info.name); } } if(dp) { ql_closedir(dp); MSG_INFO(1,"[FS] dir closed: %s\r\n", path); } } static void savePsnNow(USER_STOR_INFO *info); void cmdSetting(char *msg){ char info[100],buf[50],ipAddr[40]; char needSendAt=0; char needFeedSms=0; char needSaveSys=0; int len,port; unsigned long psn; if(sutApp.gtMode==0) return; if(sutApp.gtTMode!=0){ msgAtSends(msg, strlen(msg)); return; } //GT模式下指令处理 if(msgCmp(msg, "GT+TM")){ snprintf(info, sizeof(info), "TM Mode:OK\r\n"); needFeedSms=1; sutApp.gtTMode=1; }else if(msgCmp(msg, "GT+PWM=")){ // if(msg[7]>='0' && msg[7]<='9') beepStart(atoi(msg+7)); }else if(msgCmp(msg, "GT+SZZD")){ len=GetParaFromStr(msg,"ID",buf); if(len<1 || len>15){ snprintf(info, sizeof(info),"GT+SZZD:FAIL[ID Invalid]\r\n"); needFeedSms=1; goto SETTING_END; } strcpy(sutApp.UserInfo.OtherId,buf); if(len<1 || len>19){ snprintf(info, sizeof(info),"GT+SZZD:FAIL[PWD Invalid]\r\n"); needFeedSms=1; goto SETTING_END; } len=GetParaFromStr(msg,"PWD",buf); strcpy(sutApp.UserInfo.OtherPassWord,buf); snprintf(info, sizeof(info),"GT+SZZD:ID=%s;PWD=%s;\r\n",sutApp.UserInfo.OtherId,sutApp.UserInfo.OtherPassWord); needFeedSms=1; saveInfoNow(&sutApp.UserInfo); } else if(msgCmp(msg, "GT+RZZD")){ snprintf(info, sizeof(info),"GT+RZZD:Id=%s;Pwd=%s;\r\n",sutApp.UserInfo.OtherId,sutApp.UserInfo.OtherPassWord); needFeedSms=1; goto SETTING_END; }else if(msgCmp(msg, "GT+SDOMAIN")){ len=GetParaFromStr(msg,"PLAT",buf); if(len<1 || len>15){ snprintf(info, sizeof(info),"GT+SDOMAIN:FAIL[ID Invalid]\r\n"); needFeedSms=1; goto SETTING_END; } strcpy(sutApp.UserInfo.platform,buf); if(len<1 || len>19){ snprintf(info, sizeof(info),"GT+SDOMAIN:FAIL[PWD Invalid]\r\n"); needFeedSms=1; goto SETTING_END; } len=GetParaFromStr(msg,"MARK",buf); strcpy(sutApp.UserInfo.pFormatMark,buf); snprintf(info, sizeof(info),"GT+SDOMAIN:PLAT=%s;MARK=%s;\r\n",sutApp.UserInfo.platform,sutApp.UserInfo.pFormatMark); needFeedSms=1; saveInfoNow(&sutApp.UserInfo); }else if(msgCmp(msg, "GT+SNET")){ //GT+SNET:TNET=4;GT+SNET:TNET=5; len=GetParaFromStr(msg, "TNET", buf); if(len!=1){ TNET_ERR: snprintf(info, sizeof(info),"GT+SNET:FAIL[PSN Invalid]\r\n"); needFeedSms=1; goto SETTING_END; } psn=atoi(buf); if(psn!=4&&psn!=5) goto TNET_ERR; MSG_INFO(1,"psn=====%d",psn); if(psn!=sutApp.UserInfo.tnet){ sutApp.UserInfo.tnet=psn; saveInfoNow(&sutApp.UserInfo); } snprintf(info,sizeof(info),"GT+SNET:TNET=%d\r\n",psn); needFeedSms=1; }else if(msgCmp(msg, "GT+RNET")){ snprintf(info, sizeof(info),"GT+RNET:TNET=%d;\r\n",sutApp.UserInfo.tnet); needFeedSms=1; } else if(msgCmp(msg, "GT+RDOMAIN")){ snprintf(info, sizeof(info),"GT+RDOMAIN:PLAT=%s;MARK=%s;\r\n",sutApp.UserInfo.platform,sutApp.UserInfo.pFormatMark); needFeedSms=1; goto SETTING_END; }else if(msgCmp(msg, "GT+TG")){ snprintf(info, sizeof(info), "TG Mode:OK\r\n"); needFeedSms=1; sutApp.gtTMode=1; msgAtSend("AT+POC=050000\r\n"); msgAtSend("AT+SGPS=1\r\n"); msgAtSend("AT+BUBIAO=0\r\n"); msgAtSend("AT+TG\r\n"); gpsAntCtl(1); }else if(msgCmp(msg, "GT+APN")){ /* 设置格式:GT+APN=Account=用户名;Password=密码; 成功返回:GT+APN:Account=用户名;Password=密码; 失败返回:GT+APN:FAIL[失败原因] */ len=GetParaFromStr(msg,"Account",buf); if(len<1 || len > 30){ snprintf(info, sizeof(info),"GT+APN:FAIL[Account Invalid]\r\n"); needFeedSms=1; goto SETTING_END; } strcpy(ipAddr,buf); len=GetParaFromStr(msg,"Password",buf); if(len<1 || len > 30){ snprintf(info, sizeof(info),"GT+APN:FAIL[Password Invalid]"); needFeedSms=1; goto SETTING_END; } snprintf(info, sizeof(info),"GT+APN:Account=%s;Password=%s;\r\n",ipAddr,buf);//****** needFeedSms=1; if(0!=strcmp(ipAddr, newPara.apnList.apnList[3].account) || 0!=strcmp(buf, newPara.apnList.apnList[3].pass)){ strcpy(newPara.apnList.apnList[3].account, ipAddr); strcpy(newPara.apnList.apnList[3].pass, buf); newPara.apnList.defaultuse=3; needSaveSys=7; } }else if(msgCmp(msg, "GT+RAPN")){ snprintf(info,sizeof(info),"GT+RAPN:Account=%s;Password=%s;\r\n",newPara.apnList.apnList[3].account,newPara.apnList.apnList[3].pass); //*********** needFeedSms=1; }else if(msgCmp(msg, "GT+SACC")){ len=GetParaFromStr(msg,"Accessp",buf); if(len<0 || len > (APN_SEGMENT_MAX_LEN-1)){ snprintf(info, sizeof(info),"GT+SACC:FAIL[Accessp Invalid]\r\n"); needFeedSms=1; goto SETTING_END; } if(len ==0) newPara.apnList.APN_Name[0]=0; else strcpy(newPara.apnList.APN_Name,buf); snprintf(info, sizeof(info),"GT+SACC:Accessp=%s;\r\n",newPara.apnList.APN_Name); //********** needFeedSms=1; needSaveSys=8; }else if(msgCmp(msg, "GT+RACC")){ snprintf(info, sizeof(info),"GT+RACC:Accessp=%s;\r\n",newPara.apnList.APN_Name); needFeedSms=1; } SETTING_END: if(needSendAt!=0) msgAtSends(info, strlen(info)); if(needFeedSms!=0) ql_uart_write(QL_USB_CDC_PORT, info, strlen(info)); if(needSaveSys!=0){ snprintf(info, sizeof(info), "cmd:%d",needSaveSys); sysIniSave(info); } } //sysini文件处理 #define SYSINI_FILE "sys.ini" SYSINI_HS191X_DEF newPara; char menu_key[6]="502800";//如果资源文件中没有定义服务器菜单密码,则默认使用此密码 char *getMenuKey(void){return menu_key;} static void ttsToBEStr(char *tts, int len){ int i; char tmp[2]; if(len % 4) return; for(i=0;iMAX_SPK_VOL){ newPara.spkVol=6; needsave=1; } /* if(false==isNeedShutGps()){//GPS使能,必需打开布标 MSG_WARN(1, "gpsEnable, force bubiaoEnable"); newPara.bubiaoEnable=1; needsave=1; } */ if(needsave!=0){ ql_fseek(fd, 0L, 0); ql_fwrite((unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF),1,fd); //nwy_sdk_fsync(fd); } ql_fclose(fd); } //保存PSN文件处理 #define PSN_FILE "EC600M_f2" void saveInfoNow(USER_STOR_INFO *info){ QFILE * fd; char path[64]="U:/"; strcat(path, PSN_FILE); MSG_INFO(1,"%s save start:%d,%s",PSN_FILE, info->OtherId,info->OtherPassWord); fd=ql_fopen(path,"wb+"); if(fd==NULL){ MSG_ERR(1,"%s open failed",PSN_FILE); return; } //保存 ql_fseek(fd, 0L, 0); ql_fwrite((unsigned char *)&sutApp.UserInfo, sizeof(USER_STOR_INFO),1,fd); ql_fclose(fd); MSG_INFO(1,"%s save done", PSN_FILE); } void readInfoNow(void){ QFILE * fd; char path[64]="U:/"; strcat(path, PSN_FILE); fd=ql_fopen(path, "r+"); if(fd==NULL){ MSG_ERR(1,"%s open read failed", PSN_FILE); return; } MSG_ERR(1,"%s open read ok", PSN_FILE); ql_fseek(fd, 0L, 0); ql_fread( (unsigned char *)&sutApp.UserInfo, sizeof(USER_STOR_INFO),1,fd); if(sutApp.UserInfo.tnet != 4 && sutApp.UserInfo.tnet != 5){ sutApp.UserInfo.tnet = 4; ql_fseek(fd, 0L, 0); ql_fwrite( (unsigned char *)&sutApp.UserInfo, sizeof(USER_STOR_INFO),1,fd); } ql_fclose(fd); MSG_INFO(1, "%s get info:%d,%s",PSN_FILE, sutApp.UserInfo.OtherId, sutApp.UserInfo.OtherPassWord); } void setFactoryParam(void){ sutApp.UserInfo.psn=newPara.defaultPsn; saveInfoNow(&sutApp.UserInfo); MSG_INFO(1, "set factory psn:%d", sutApp.UserInfo.psn); } void setPocPara(char *pocPara, int len){ sutApp.pocParaDone=1; } char showPIP[40]; char showGIP[40]; const char invalidIp[]="1.1.1.1"; char *getPIPAddr(void){ char *retAddr=NULL; switch(newPara.serList.defaultuse){ case SERVER_HZ: retAddr=newPara.serList.zh.pip;break; case SERVER_SD: retAddr=newPara.serList.sd.pip;break; case SERVER_FENFA:retAddr=(char *)invalidIp;break; case SERVER_JIQUN:retAddr=(char *)invalidIp;break; case SERVER_UR: retAddr=newPara.serList.ur.pip;break; } memset(showPIP, 0, sizeof(showPIP)); strcpy(showPIP, retAddr); return retAddr; } char *getGIPAddr(void){ char *retAddr=NULL; switch(newPara.serList.defaultuse){ case SERVER_HZ: retAddr=newPara.serList.zh.gip;break; case SERVER_SD: retAddr=newPara.serList.sd.gip;break; case SERVER_FENFA: break; case SERVER_JIQUN: break; case SERVER_UR: retAddr=newPara.serList.ur.gip;break; } if(retAddr==NULL) showGIP[0]=0; else strcpy(showGIP, retAddr); return retAddr; } char *getDOMAINAddr(void) { char *retAddr=NULL; switch(newPara.serList.defaultuse){ case SERVER_HZ:break; case SERVER_SD:break; case SERVER_FENFA:retAddr=newPara.serList.ipFenFa;break; case SERVER_JIQUN:retAddr=newPara.serList.jiqun;break; case SERVER_UR:break; } return retAddr; } /* #define SYS_FILE_STATUS "hfiles/sys.status" #define SYS_FILE_BACKUP "hfiles/sys.bak" void checkNeedRecoverFile(void){ int fd=LSAPI_FS_Open(SYS_FILE_STATUS, LSAPI_FS_O_RDONLY,0); if(fd<0){ MSG_WARN(1, "'%s' lost, recover %s", SYS_FILE_STATUS,true==recoverOperation()?"ok":"failed"); }else LSAPI_FS_Close(fd); } bool recoverOperation(void){ bool returnValue=false; int ret,fd,fd_backup=-1,fd_ini=-1; unsigned char *backData=NULL; //0、读sys.bak内容出来 fd_backup=LSAPI_FS_Open(SYS_FILE_BACKUP, LSAPI_FS_O_RDONLY,0); if(fd_backup<0){ MSG_ERR(1,"%s open read failed", SYS_FILE_BACKUP); goto END; } LSAPI_FS_Stat_info_t pBuf; memset(&pBuf,0,sizeof(pBuf)); ret=LSAPI_FS_Fstat(fd_backup,&pBuf); if(ret!=0){ MSG_ERR(1,"%s get size failed, ret=%d", SYS_FILE_BACKUP, ret); goto END; } if(pBuf.st_size=0){//存在,则删除之 LSAPI_FS_Close(fd); ret=LSAPI_FS_Unlink(SYS_FILE_STATUS); if(ret!=0){ MSG_INFO(1, "Del '%s' failed ret=%d", SYS_FILE_STATUS, ret); goto END; } } //2、复制到sys.ini fd_ini=LSAPI_FS_Open(SYSINI_FILE, LSAPI_FS_O_RDWR,0); if(fd_ini<0){ MSG_ERR(1,"%s open failed", SYSINI_FILE); goto END; } ret=LSAPI_FS_Ftruncate(fd_ini,pBuf.st_size); if(ret!=0){ MSG_ERR(1, "%s truncate failed:%d", SYSINI_FILE,ret); goto END; } ret=LSAPI_FS_Write(fd_ini, backData, pBuf.st_size); if(ret!=pBuf.st_size){ MSG_ERR(1, "%s write failed:%d", SYSINI_FILE,ret); goto END; } LSAPI_FS_Close(fd_ini); fd_ini=-1; //3、恢复sys.status fd=LSAPI_FS_Open(SYS_FILE_STATUS, LSAPI_FS_O_RDWR|LSAPI_FS_O_CREAT,0); if(fd<0){ MSG_ERR(1,"%s create failed:%d", SYS_FILE_STATUS,fd); goto END; } MSG_INFO(1, "CREATE DONE"); LSAPI_FS_Close(fd); returnValue=true; END: if(fd_backup) LSAPI_FS_Close(fd_backup); if(fd_ini) LSAPI_FS_Close(fd_ini); if(backData!=NULL) free(backData); return returnValue; } */