123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513 |
- #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=密码;<CR><LF>
- 成功返回:GT+APN:Account=用户名;Password=密码;<CR><LF>
- 失败返回:GT+APN:FAIL[失败原因]<CR><LF>
- */
- 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;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(char *reason){
- QFILE *fd;
- char path[64]="U:/";
- strcat(path, SYSINI_FILE);
- if(sutApp.gtMode==0)
- MSG_INFO(1,"%s save start",SYSINI_FILE);
- //fd=LSAPI_FS_Open(SYSINI_FILE, LSAPI_FS_O_RDWR,0x0);
- fd=ql_fopen(path,"r+");
-
- if(fd==0){
- MSG_ERR(1,"%s open failed",SYSINI_FILE);
- return;
- }
- //保存
- ql_fseek(fd, 0L, 0);
- ql_fwrite((unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF),1,fd);
- //nwy_sdk_fsync(fd);
- ql_fclose(fd);
- if(sutApp.gtMode==0)
- MSG_INFO(1,"%s save done", SYSINI_FILE);
-
- #ifdef ENABLE_DEBUG
- //takeNoteFile(reason);
- #endif
- }
- void setFactoryParam(void);
- void sysIniRead(void){
- QFILE *fd;
- char needsave=0;
- char path[64]="U:/";
- strcat(path, SYSINI_FILE);
-
- fd=ql_fopen(path,"r+");
- if(fd==0){
- MSG_ERR(1,"%s open read failed", SYSINI_FILE);
- return;
- }
- ql_fseek(fd, 0L, 0);
- ql_fread( (unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF),1,fd);
-
- if(newPara.ConfigFlag==0){
- MSG_INFO(1, "First run");
- newPara.itemShowType=0;
- newPara.ConfigFlag=1;
- newPara.gpsTimeIndex=4;//默认30秒
- needsave=1;
- //检测TTS是否是UNICODE,是则将其从BE转换为LE,后面就可以直接播放了
- if(newPara.ttsMessage[0]!=0 && newPara.ttsCodeType==0) ttsToBEStr(newPara.ttsMessage, strlen(newPara.ttsMessage));
- newPara.spkVol=6;
- #ifdef BND_NEW_PLAT
- newPara.newold_plam=1;
- #else
- newPara.newold_plam=0;
- #endif
-
- #ifndef DEVELOP_MODE
- if(newPara.rstPsn!=0){
- newPara.rstPsn=0;
- setFactoryParam();
- }
- #endif
-
- }
-
- if(newPara.serverMenuPass!=NULL) memcpy(menu_key, newPara.serverMenuPass,6);
-
- if(newPara.spkVol>MAX_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<sizeof(SYSINI_HS191X_DEF)){
- MSG_ERR(1, "%s size err:%d,%d", SYS_FILE_BACKUP,pBuf.st_size, sizeof(SYSINI_HS191X_DEF));
- goto END;
- }
- backData=malloc(pBuf.st_size*sizeof(unsigned char));
- if(backData==NULL){
- MSG_ERR(1, "%s malloc failed", SYS_FILE_BACKUP);
- goto END;
- }
- ret=LSAPI_FS_Read(fd_backup, backData,pBuf.st_size);
- if(ret<=0 || ret != pBuf.st_size){
- MSG_ERR(1, "%s read err ret=%d", SYS_FILE_BACKUP,ret);
- goto END;
- }
- LSAPI_FS_Close(fd_backup);
- fd_backup=-1;
- //1、删除sys.status
- fd=LSAPI_FS_Open(SYS_FILE_STATUS, LSAPI_FS_O_RDONLY,0);
- if(fd>=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;
- }
- */
|