#include "includes.h" static void saveInfoNow(ACCOUNT_DEF account); void cmdSetting(char *msg){ char info[100],buf[50],ipAddr[40],pwd[30]; char needSendAt=0; char needFeedSms=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+SMP")){//GT+SMP:PSN=1509000030;IP=183.131.13.10;PWD=xxxxxxxxx; //IP len=GetParaFromStr(msg, "IP",buf); if(len<1 || len>=40){ snprintf(info, sizeof(info),"GT+SMP:FAIL[IP Invalid]\r\n"); needFeedSms=1; goto SETTING_END; } strcpy(ipAddr, buf); //PWD len=GetParaFromStr(msg, "PWD", buf); if(len<0 || len>=40){ snprintf(info, sizeof(info),"GT+SMP:FAIL[PWD Invalid]\r\n"); needFeedSms=1; goto SETTING_END; } snprintf(pwd, sizeof(pwd), "%s", buf); //PSN len=GetParaFromStr(msg, "PSN",buf); if(len<1 || len>10){ snprintf(info, sizeof(info),"GT+SMP:FAIL[PSN Invalid]\r\n"); needFeedSms=1; goto SETTING_END; } psn=atol(buf); snprintf(info, sizeof(info),"GT+SMP:IP=%s;PWD=%s;PSN=%lu;\r\n",ipAddr,pwd,psn); needFeedSms=1; //保存PSN,PASSWORK if(sutApp.account.psn != psn || strcmp(sutApp.account.password, pwd)){ sutApp.account.psn=psn; snprintf(sutApp.account.password,sizeof(sutApp.account.password), "%s", pwd); saveInfoNow(sutApp.account); } //保存IP到sys.ini中的用户定义? if(strcmp(newPara.serList.ur.pip,ipAddr) || newPara.serList.defaultuse!=SERVER_UR){ //不相? newPara.serList.defaultuse=SERVER_UR; strcpy(newPara.serList.ur.pip, ipAddr); sysIniSave(); } }else if(msgCmp(msg, "GT+RMP")){ snprintf(info, sizeof(info),"GT+RMP:PSN=%lu;PWD=%s;IP=%s;\r\n",sutApp.account.psn,sutApp.account.password,getPIPAddr()); needFeedSms=1; }else if(msgCmp(msg, "GT+TM")){ snprintf(info, sizeof(info), "TM Mode:OK\r\n"); needFeedSms=1; sutApp.gtTMode=1; guiShowMessageBox("TMģʽ"); } SETTING_END: if(needSendAt!=0) msgAtSends(info, strlen(info)); if(needFeedSms!=0) nwy_usb_serial_send(info, strlen(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;i10){ newPara.spkVol=6; needsave=1; } if(newPara.gpsEnable!=0){//GPS使能,必需打开布标 MSG_WARN(1, "gpsEnable, force bubiaoEnable"); newPara.bubiaoEnable=1; needsave=1; } if(needsave!=0){ nwy_sdk_fseek(fd, 0L, NWY_SEEK_SET); nwy_sdk_fwrite(fd, (unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF)); nwy_sdk_fsync(fd); } nwy_sdk_fclose(fd); } //保存PSN文件处理 #define PSN_FILE "n58_f2" static void saveInfoNow(ACCOUNT_DEF account){ int fd; MSG_INFO(1,"%s save start:%d,%s",PSN_FILE, account.psn,account.password); fd=nwy_sdk_fopen(PSN_FILE, NWY_RDWR | NWY_CREAT); if(fd<0){ MSG_ERR(1,"%s open failed",PSN_FILE); return; } //保存 nwy_sdk_fseek(fd, 0L, NWY_SEEK_SET); nwy_sdk_fwrite(fd, (unsigned char *)&account, sizeof(ACCOUNT_DEF)); nwy_sdk_fsync(fd); nwy_sdk_fclose(fd); MSG_INFO(1,"%s save done", PSN_FILE); } void readInfoNow(void){ int fd; fd=nwy_sdk_fopen(PSN_FILE, NWY_RDONLY); if(fd<0){ MSG_ERR(1,"%s open read failed", PSN_FILE); return; } nwy_sdk_fseek(fd, 0L, NWY_SEEK_SET); nwy_sdk_fread(fd, (unsigned char *)&sutApp.account, sizeof(ACCOUNT_DEF)); nwy_sdk_fclose(fd); MSG_INFO(1, "%s get info:%d,%s",PSN_FILE, sutApp.account.psn, sutApp.account.password); } void setPocPara(char *pocPara, int len){ int k; char buf[40]; char buf1[100]; char pwd[40]; char idFlag=0,domainFlag=0,ipFlag=0; char gapFlag=0,gportFlag=0; char pwdFlag=0; char enableChangeIp=1; if(0!=restoreDataFormatByHex(pocPara,len)){//库接口提? MSG_ERR(1, "setPocPara get error"); return; } k=len/2; pocPara[k]=0; //找pwd GetParaFromStr(pocPara, "pwd", pwd); if(0!=strcmp(sutApp.account.password, pwd)) pwdFlag=1; //找id GetParaFromStr(pocPara, "id", buf); snprintf(buf1, sizeof(buf1), "%lu", sutApp.account.psn); if(0!=strcmp(buf1, buf)) idFlag=1; //找domain switch(newPara.serList.defaultuse){ case SERVER_HZ: case SERVER_SD: case SERVER_UR:break; case SERVER_FENFA: case SERVER_JIQUN: if(newPara.serList.defaultuse==SERVER_FENFA) snprintf(buf1, sizeof(buf1), "%s", newPara.serList.ipFenFa); else if(newPara.serList.defaultuse==SERVER_JIQUN) snprintf(buf1, sizeof(buf1), "%s", newPara.serList.jiqun); GetParaFromStr(pocPara, "domain", buf); if(0!=strcmp(buf1, buf)) domainFlag=1; enableChangeIp=0; break; } if(enableChangeIp!=0){ GetParaFromStr(pocPara, "ip", buf); snprintf(buf1, sizeof(buf1), "%s", getPIPAddr()); if(0!=strcmp(buf1, buf)) ipFlag=1; } //找gap if(newPara.serList.defaultuse!=SERVER_FENFA && newPara.serList.defaultuse!=SERVER_JIQUN){//分发/集群时不需要比对GPS,因为POC已保存了 GetParaFromStr(pocPara, "gap", buf); snprintf(buf1, sizeof(buf1), "%s", getGIPAddr()); if(0!=strcmp(buf1, buf)) gapFlag=1; } //找gport GetParaFromStr(pocPara, "gport", buf); snprintf(buf1, sizeof(buf1), "%d", newPara.gpsPort); if(0!=strcmp(buf1, buf)) gportFlag=1; //MSG_INFO(1, "-->%d,%d,%d,%d,%d",idFlag,ipFlag,domainFlag,gapFlag,gportFlag); if(idFlag==0 && ipFlag==0 && domainFlag==0 && gapFlag==0 && gportFlag==0 && pwdFlag==0){ MSG_INFO(1, "POC still"); sutApp.pocParaDone=1; return; } msgAtSend("AT+POC=010000"); //更新pwd if(pwdFlag!=0){ snprintf(buf, sizeof(buf), "pwd=%s;", sutApp.account.password); AscStrTurnHexStr(buf, buf1); msgAtSend(buf1); } //更新id if(idFlag!=0){ snprintf(buf, sizeof(buf), "id=%lu;", sutApp.account.psn); AscStrTurnHexStr(buf, buf1); msgAtSend(buf1); } //更新ip if(enableChangeIp!=0){ snprintf(buf, sizeof(buf), "ip=%s;", getPIPAddr()); AscStrTurnHexStr(buf, buf1); msgAtSend(buf1); } //更新domian if(newPara.serList.defaultuse==SERVER_FENFA) snprintf(buf, sizeof(buf), "domain=%s;",newPara.serList.ipFenFa); else if(newPara.serList.defaultuse==SERVER_JIQUN)snprintf(buf, sizeof(buf), "domain=%s;",newPara.serList.jiqun); else snprintf(buf, sizeof(buf), "domain=;"); AscStrTurnHexStr(buf, buf1); msgAtSend(buf1); //更新gap if(gapFlag!=0){ snprintf(buf, sizeof(buf), "gap=%s;", getGIPAddr()); AscStrTurnHexStr(buf, buf1); msgAtSend(buf1); } //更新gport if(gportFlag!=0){ snprintf(buf, sizeof(buf), "gport=%d;", newPara.gpsPort); AscStrTurnHexStr(buf, buf1); msgAtSend(buf1); } msgAtSend("\r\n"); MSG_INFO(1, "POC reset"); 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; }