123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345 |
- #include "includes.h"
- static void savePsnNow(ACCOUNT_DEF account);
- 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+SMP")){
- 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);
- len=GetParaFromStr(msg, "Port", buf);
- if(len==0) port=0;
- else if(len>5){
- snprintf(info,sizeof(info),"GT+SMP:FAIL[Port Invalid]");
- needFeedSms=1;
- goto SETTING_END;
- }
- port=atoi(buf);
- 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;Port=%u;PSN=%lu;\r\n",ipAddr,port,psn);
- needFeedSms=1;
- //保存PSN
- if(sutApp.account.psn != psn){
- sutApp.account.psn=psn;
- 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;MEID=%s;CNUM=0000000000;UIMID=0000000000;IP=%s;\r\n",sutApp.account.psn,ohpocGetIMEI(),getPIPAddr());
- needFeedSms=1;
- }else 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+RPID")){
- snprintf(info, sizeof(info), "GT+RPID:PSN=%lu;\r\n", sutApp.account.psn);
- needFeedSms=1;
- }else if(msgCmp(msg, "GT+SPID")){
- len=GetParaFromStr(msg, "PSN",buf);
- if(len<1 || len>10){
- snprintf(info, sizeof(info),"GT+SPID:FAIL[PSN Invalid]\r\n");
- needFeedSms=1;
- goto SETTING_END;
- }
- psn=atol(buf);
- snprintf(info, sizeof(info),"GT+SPID:PSN=%lu;\r\n",psn);
- needFeedSms=1;
- if(sutApp.account.psn != psn){
- sutApp.account.psn=psn;
- saveInfoNow(sutApp.account);
- }
- }else if(msgCmp(msg, "GT+RDOMAIN")){
- snprintf(info,sizeof(info),"GT+RDOMAIN:%s;PSN=%lu;\r\n",newPara.serList.ipFenFa,sutApp.account.psn);
- needFeedSms=1;
- }else if(msgCmp(msg, "GT+SDOMAIN")){
- len=GetParaFromStr(msg, "PSN",buf);
- if(len<1 || len>10){
- snprintf(info, sizeof(info),"GT+SDOMAIN:FAIL[PSN Invalid]\r\n");
- needFeedSms=1;
- goto SETTING_END;
- }
- psn=atol(buf);
-
- len=GetParaFromStr(msg, "SDOMAIN",buf);
- if(len>40){
- snprintf(info, sizeof(info),"GT+SDOMAIN:FAIL[DOMAIN Invalid]\r\n");
- needFeedSms=1;
- goto SETTING_END;
- }
- if(newPara.serList.defaultuse != SERVER_FENFA){
- newPara.serList.defaultuse=SERVER_FENFA;
- needSaveSys=1;
- }
- if(0!=strcmp(newPara.serList.ipFenFa, buf)){
- memset(newPara.serList.ipFenFa,0,sizeof(newPara.serList.ipFenFa));
- snprintf(newPara.serList.ipFenFa,sizeof(newPara.serList.ipFenFa),"%s",buf);
- needSaveSys=1;
- }
- if(sutApp.account.psn != psn){
- sutApp.account.psn=psn;
- saveInfoNow(sutApp.account);
- }
- snprintf(info, sizeof(info),"GT+SDOMAIN=%s;PSN=%lu;\r\n",newPara.serList.ipFenFa,psn);
- needFeedSms=1;
- }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[TNET Invalid]\r\n");
- needFeedSms=1;
- goto SETTING_END;
- }
- psn=atol(buf);
- if(psn !=4 && psn != 5) goto TNET_ERR;
- if(psn != sutApp.account.tnet){
- sutApp.account.tnet=psn;
- saveInfoNow(sutApp.account);
- }
- 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.account.tnet);
- needFeedSms=1;
- }else if(msgCmp(msg, "GT+RPOS")){
- snprintf(info, sizeof(info),"GT+RPOS:VALUE=%d;\r\n", newPara.itemShowType);
- needFeedSms=1;
- }else if(msgCmp(msg, "GT+SPOS")){//GT+SPOS:VALUE=0;
- len=GetParaFromStr(msg, "VALUE",buf);
- if(len!=1){
- SPOS_ERR:
- snprintf(info, sizeof(info),"GT+SPOS:FAIL[VALUE Invalid]\r\n");
- needFeedSms=1;
- goto SETTING_END;
- }
- psn=atol(buf);
- if(psn != 0 && psn != 1) goto SPOS_ERR;
- if(psn != newPara.itemShowType){
- newPara.itemShowType=psn;
- needSaveSys=1;
- }
- snprintf(info, sizeof(info),"GT+SPOS:VALUE=%d;\r\n",psn);
- needFeedSms=1;
- }
- SETTING_END:
- if(needSendAt!=0) msgAtSends(info, strlen(info));
- if(needFeedSms!=0) usbOutPut(info, strlen(info));
- if(needSaveSys!=0) sysIniSave();
- }
- //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;i<len/4;i++){
- tmp[0]=tts[4*i];tmp[1]=tts[4*i+1];
- tts[4*i]=tts[4*i+2];
- tts[4*i+1]=tts[4*i+3];
- tts[4*i+2]=tmp[0];
- tts[4*i+3]=tmp[1];
- }
- }
- void sysIniSave(void){
- int fd;
- MSG_INFO(1,"%s save start",SYSINI_FILE);
- fd=LSAPI_FS_Open(SYSINI_FILE, LSAPI_FS_O_RDWR,0x0);
- if(fd<0){
- MSG_ERR(1,"%s open failed",SYSINI_FILE);
- return;
- }
- //保存
- LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
- LSAPI_FS_Write(fd, (unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF));
- //nwy_sdk_fsync(fd);
- LSAPI_FS_Close(fd);
- MSG_INFO(1,"%s save done", SYSINI_FILE);
- }
- void setFactoryParam(void);
- void sysIniRead(void){
- int fd;
- char needsave=0;
- fd=LSAPI_FS_Open(SYSINI_FILE, LSAPI_FS_O_RDWR,0);
- if(fd<0){
- MSG_ERR(1,"%s open read failed", SYSINI_FILE);
- return;
- }
- LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
- LSAPI_FS_Read(fd, (unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF));
-
- if(newPara.ConfigFlag==0){
- MSG_INFO(1, "First run");
- newPara.itemShowType=0;
- newPara.ConfigFlag=1;
- newPara.lockType=0;//锁正面
- needsave=1;
- //检测TTS是否是UNICODE,是则将其从BE转换为LE,后面就可以直接播放了
- if(newPara.ttsMessage[0]!=0 && newPara.ttsCodeType==0) ttsToBEStr(newPara.ttsMessage, strlen(newPara.ttsMessage));
- newPara.spkVol=6;
- newPara.micGain=MIC_GAIN_DEFAULT;
- newPara.spkGain=SPK_GAIN_DEFAULT;
- #ifndef DEVELOP_MODE
- setFactoryParam();
- #endif
- }
- if(newPara.serverMenuPass!=NULL) memcpy(menu_key, newPara.serverMenuPass,6);
- //测试开始
- //newPara.gpsEnable=0;
- //newPara.bubiaoEnable=0;
- //newPara.KeySound=1;
- //测试结束
-
- if(newPara.spkVol>MAX_SPK_VOL){
- newPara.spkVol=6;
- needsave=1;
- }
-
- if(newPara.gpsEnable!=0){//GPS使能,必需打开布标
- MSG_WARN(1, "gpsEnable, force bubiaoEnable");
- newPara.bubiaoEnable=1;
- needsave=1;
- }
- if(needsave!=0){
- LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
- LSAPI_FS_Write(fd, (unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF));
- //nwy_sdk_fsync(fd);
- }
- LSAPI_FS_Close(fd);
- }
- //保存PSN文件处理
- #define PSN_FILE "m5700_f2"
- void saveInfoNow(ACCOUNT_DEF account){
- int fd;
- MSG_INFO(1,"%s save start:%d,%s",PSN_FILE, account.psn,account.password);
- fd=LSAPI_FS_Open(PSN_FILE, LSAPI_FS_O_RDWR |LSAPI_FS_O_CREAT,0x0);
- if(fd<0){
- MSG_ERR(1,"%s open failed",PSN_FILE);
- return;
- }
- //保存
- LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
- LSAPI_FS_Write(fd, (unsigned char *)&account, sizeof(ACCOUNT_DEF));
- //nwy_sdk_fsync(fd);
- LSAPI_FS_Close(fd);
- MSG_INFO(1,"%s save done", PSN_FILE);
- }
- void readInfoNow(void){
- int fd;
- fd=LSAPI_FS_Open(PSN_FILE, LSAPI_FS_O_RDONLY,0);
- if(fd<0){
- MSG_ERR(1,"%s open read failed", PSN_FILE);
- return;
- }
- LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
- LSAPI_FS_Read(fd, (unsigned char *)&sutApp.account, sizeof(ACCOUNT_DEF));
- if(sutApp.account.tnet != 4 && sutApp.account.tnet != 5){
- sutApp.account.tnet = 4;
- LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
- LSAPI_FS_Write(fd, (unsigned char *)&sutApp, sizeof(ACCOUNT_DEF));
- }
- LSAPI_FS_Close(fd);
- MSG_INFO(1, "%s get info:%d,%s",PSN_FILE, sutApp.account.psn, sutApp.account.password);
- }
- void setFactoryParam(void){
- sutApp.account.psn=newPara.defaultPsn;
- saveInfoNow(sutApp.account);
- MSG_INFO(1, "set factory psn:%d", sutApp.account.psn);
- }
- void setPocPara(){
- unsigned char Databuf[120]={0};
- unsigned char len;
- char *Addr="0.0.0.0";
- snprintf(&Databuf[16], sizeof(Databuf)-16, "addr:%s&user:GPS001&pass:123456", Addr);
- len=strlen(Databuf+16);
- snprintf(Databuf, sizeof(Databuf), "AT+POC=setinfo%02x%s",len, Databuf+16);
- msgAtSend(Databuf);
- MSG_INFO(1,Databuf);
- }
- 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;
- }
|