setting.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. #include "includes.h"
  2. void applist_dir(const char *path)
  3. {
  4. QDIR * dp = NULL;
  5. struct lfs_info info = {0};
  6. int ret;
  7. dp = ql_opendir(path);
  8. if(dp == NULL)
  9. {
  10. MSG_INFO(1,"[FS] *** dir open fail: %s ***\r\n", path);
  11. return;
  12. }
  13. MSG_INFO(1,"[FS] dir opened: %s\r\n", path);
  14. MSG_INFO(1,"[FS] ----- start dir list -----\r\n");
  15. MSG_INFO(1,"[FS] type\tsize\tname\r\n");
  16. while(1)
  17. {
  18. ret = ql_readdir(dp, &info);
  19. if(ret < 0)
  20. {
  21. MSG_INFO(1,"[FS] *** dir read fail: %s ***\r\n", path);
  22. break;
  23. }
  24. else if(ret == 0)
  25. {
  26. MSG_INFO(1,"[FS] ----- end of dir list -----\r\n");
  27. break;
  28. }
  29. else
  30. {
  31. MSG_INFO(1,"[FS] %-4d\t%-4d\t%s\r\n", info.type, info.size, info.name);
  32. }
  33. }
  34. if(dp)
  35. {
  36. ql_closedir(dp);
  37. MSG_INFO(1,"[FS] dir closed: %s\r\n", path);
  38. }
  39. }
  40. static void savePsnNow(USER_STOR_INFO *info);
  41. void cmdSetting(char *msg){
  42. char info[100],buf[50],ipAddr[40];
  43. char needSendAt=0;
  44. char needFeedSms=0;
  45. char needSaveSys=0;
  46. int len,port;
  47. unsigned long psn;
  48. if(sutApp.gtMode==0) return;
  49. if(sutApp.gtTMode!=0){
  50. msgAtSends(msg, strlen(msg));
  51. return;
  52. }
  53. //GT模式下指令处理
  54. if(msgCmp(msg, "GT+TM")){
  55. snprintf(info, sizeof(info), "TM Mode:OK\r\n");
  56. needFeedSms=1;
  57. sutApp.gtTMode=1;
  58. }else if(msgCmp(msg, "GT+PWM=")){
  59. // if(msg[7]>='0' && msg[7]<='9') beepStart(atoi(msg+7));
  60. }else if(msgCmp(msg, "GT+SZZD")){
  61. len=GetParaFromStr(msg,"ID",buf);
  62. if(len<1 || len>15){
  63. snprintf(info, sizeof(info),"GT+SZZD:FAIL[ID Invalid]\r\n");
  64. needFeedSms=1;
  65. goto SETTING_END;
  66. }
  67. strcpy(sutApp.UserInfo.OtherId,buf);
  68. if(len<1 || len>19){
  69. snprintf(info, sizeof(info),"GT+SZZD:FAIL[PWD Invalid]\r\n");
  70. needFeedSms=1;
  71. goto SETTING_END;
  72. }
  73. len=GetParaFromStr(msg,"PWD",buf);
  74. strcpy(sutApp.UserInfo.OtherPassWord,buf);
  75. snprintf(info, sizeof(info),"GT+SZZD:ID=%s;PWD=%s;\r\n",sutApp.UserInfo.OtherId,sutApp.UserInfo.OtherPassWord);
  76. needFeedSms=1;
  77. saveInfoNow(&sutApp.UserInfo);
  78. }
  79. else if(msgCmp(msg, "GT+RZZD")){
  80. snprintf(info, sizeof(info),"GT+RZZD:Id=%s;Pwd=%s;\r\n",sutApp.UserInfo.OtherId,sutApp.UserInfo.OtherPassWord);
  81. needFeedSms=1;
  82. goto SETTING_END;
  83. }else if(msgCmp(msg, "GT+SDOMAIN")){
  84. len=GetParaFromStr(msg,"PLAT",buf);
  85. if(len<1 || len>15){
  86. snprintf(info, sizeof(info),"GT+SDOMAIN:FAIL[ID Invalid]\r\n");
  87. needFeedSms=1;
  88. goto SETTING_END;
  89. }
  90. strcpy(sutApp.UserInfo.platform,buf);
  91. if(len<1 || len>19){
  92. snprintf(info, sizeof(info),"GT+SDOMAIN:FAIL[PWD Invalid]\r\n");
  93. needFeedSms=1;
  94. goto SETTING_END;
  95. }
  96. len=GetParaFromStr(msg,"MARK",buf);
  97. strcpy(sutApp.UserInfo.pFormatMark,buf);
  98. snprintf(info, sizeof(info),"GT+SDOMAIN:PLAT=%s;MARK=%s;\r\n",sutApp.UserInfo.platform,sutApp.UserInfo.pFormatMark);
  99. needFeedSms=1;
  100. saveInfoNow(&sutApp.UserInfo);
  101. }else if(msgCmp(msg, "GT+SNET")){ //GT+SNET:TNET=4;GT+SNET:TNET=5;
  102. len=GetParaFromStr(msg, "TNET", buf);
  103. if(len!=1){
  104. TNET_ERR:
  105. snprintf(info, sizeof(info),"GT+SNET:FAIL[PSN Invalid]\r\n");
  106. needFeedSms=1;
  107. goto SETTING_END;
  108. }
  109. psn=atoi(buf);
  110. if(psn!=4&&psn!=5) goto TNET_ERR;
  111. MSG_INFO(1,"psn=====%d",psn);
  112. if(psn!=sutApp.UserInfo.tnet){
  113. sutApp.UserInfo.tnet=psn;
  114. saveInfoNow(&sutApp.UserInfo);
  115. }
  116. snprintf(info,sizeof(info),"GT+SNET:TNET=%d\r\n",psn);
  117. needFeedSms=1;
  118. }else if(msgCmp(msg, "GT+RNET")){
  119. snprintf(info, sizeof(info),"GT+RNET:TNET=%d;\r\n",sutApp.UserInfo.tnet);
  120. needFeedSms=1;
  121. }
  122. else if(msgCmp(msg, "GT+RDOMAIN")){
  123. snprintf(info, sizeof(info),"GT+RDOMAIN:PLAT=%s;MARK=%s;\r\n",sutApp.UserInfo.platform,sutApp.UserInfo.pFormatMark);
  124. needFeedSms=1;
  125. goto SETTING_END;
  126. }else if(msgCmp(msg, "GT+TG")){
  127. snprintf(info, sizeof(info), "TG Mode:OK\r\n");
  128. needFeedSms=1;
  129. sutApp.gtTMode=1;
  130. msgAtSend("AT+POC=050000\r\n");
  131. msgAtSend("AT+SGPS=1\r\n");
  132. msgAtSend("AT+BUBIAO=0\r\n");
  133. msgAtSend("AT+TG\r\n");
  134. gpsAntCtl(1);
  135. }else if(msgCmp(msg, "GT+APN")){
  136. /*
  137. 设置格式:GT+APN=Account=用户名;Password=密码;<CR><LF>
  138. 成功返回:GT+APN:Account=用户名;Password=密码;<CR><LF>
  139. 失败返回:GT+APN:FAIL[失败原因]<CR><LF>
  140. */
  141. len=GetParaFromStr(msg,"Account",buf);
  142. if(len<1 || len > 30){
  143. snprintf(info, sizeof(info),"GT+APN:FAIL[Account Invalid]\r\n");
  144. needFeedSms=1;
  145. goto SETTING_END;
  146. }
  147. strcpy(ipAddr,buf);
  148. len=GetParaFromStr(msg,"Password",buf);
  149. if(len<1 || len > 30){
  150. snprintf(info, sizeof(info),"GT+APN:FAIL[Password Invalid]");
  151. needFeedSms=1;
  152. goto SETTING_END;
  153. }
  154. snprintf(info, sizeof(info),"GT+APN:Account=%s;Password=%s;\r\n",ipAddr,buf);//******
  155. needFeedSms=1;
  156. if(0!=strcmp(ipAddr, newPara.apnList.apnList[3].account) ||
  157. 0!=strcmp(buf, newPara.apnList.apnList[3].pass)){
  158. strcpy(newPara.apnList.apnList[3].account, ipAddr);
  159. strcpy(newPara.apnList.apnList[3].pass, buf);
  160. newPara.apnList.defaultuse=3;
  161. needSaveSys=7;
  162. }
  163. }else if(msgCmp(msg, "GT+RAPN")){
  164. snprintf(info,sizeof(info),"GT+RAPN:Account=%s;Password=%s;\r\n",newPara.apnList.apnList[3].account,newPara.apnList.apnList[3].pass); //***********
  165. needFeedSms=1;
  166. }else if(msgCmp(msg, "GT+SACC")){
  167. len=GetParaFromStr(msg,"Accessp",buf);
  168. if(len<0 || len > (APN_SEGMENT_MAX_LEN-1)){
  169. snprintf(info, sizeof(info),"GT+SACC:FAIL[Accessp Invalid]\r\n");
  170. needFeedSms=1;
  171. goto SETTING_END;
  172. }
  173. if(len ==0) newPara.apnList.APN_Name[0]=0;
  174. else strcpy(newPara.apnList.APN_Name,buf);
  175. snprintf(info, sizeof(info),"GT+SACC:Accessp=%s;\r\n",newPara.apnList.APN_Name); //**********
  176. needFeedSms=1;
  177. needSaveSys=8;
  178. }else if(msgCmp(msg, "GT+RACC")){
  179. snprintf(info, sizeof(info),"GT+RACC:Accessp=%s;\r\n",newPara.apnList.APN_Name);
  180. needFeedSms=1;
  181. }
  182. SETTING_END:
  183. if(needSendAt!=0) msgAtSends(info, strlen(info));
  184. if(needFeedSms!=0) ql_uart_write(QL_USB_CDC_PORT, info, strlen(info));
  185. if(needSaveSys!=0){
  186. snprintf(info, sizeof(info), "cmd:%d",needSaveSys);
  187. sysIniSave(info);
  188. }
  189. }
  190. //sysini文件处理
  191. #define SYSINI_FILE "sys.ini"
  192. SYSINI_HS191X_DEF newPara;
  193. char menu_key[6]="502800";//如果资源文件中没有定义服务器菜单密码,则默认使用此密码
  194. char *getMenuKey(void){return menu_key;}
  195. static void ttsToBEStr(char *tts, int len){
  196. int i;
  197. char tmp[2];
  198. if(len % 4) return;
  199. for(i=0;i<len/4;i++){
  200. tmp[0]=tts[4*i];tmp[1]=tts[4*i+1];
  201. tts[4*i]=tts[4*i+2];
  202. tts[4*i+1]=tts[4*i+3];
  203. tts[4*i+2]=tmp[0];
  204. tts[4*i+3]=tmp[1];
  205. }
  206. }
  207. void sysIniSave(char *reason){
  208. QFILE *fd;
  209. char path[64]="U:/";
  210. strcat(path, SYSINI_FILE);
  211. if(sutApp.gtMode==0)
  212. MSG_INFO(1,"%s save start",SYSINI_FILE);
  213. //fd=LSAPI_FS_Open(SYSINI_FILE, LSAPI_FS_O_RDWR,0x0);
  214. fd=ql_fopen(path,"r+");
  215. if(fd==0){
  216. MSG_ERR(1,"%s open failed",SYSINI_FILE);
  217. return;
  218. }
  219. //保存
  220. ql_fseek(fd, 0L, 0);
  221. ql_fwrite((unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF),1,fd);
  222. //nwy_sdk_fsync(fd);
  223. ql_fclose(fd);
  224. if(sutApp.gtMode==0)
  225. MSG_INFO(1,"%s save done", SYSINI_FILE);
  226. #ifdef ENABLE_DEBUG
  227. //takeNoteFile(reason);
  228. #endif
  229. }
  230. void setFactoryParam(void);
  231. void sysIniRead(void){
  232. QFILE *fd;
  233. char needsave=0;
  234. char path[64]="U:/";
  235. strcat(path, SYSINI_FILE);
  236. fd=ql_fopen(path,"r+");
  237. if(fd==0){
  238. MSG_ERR(1,"%s open read failed", SYSINI_FILE);
  239. return;
  240. }
  241. ql_fseek(fd, 0L, 0);
  242. ql_fread( (unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF),1,fd);
  243. if(newPara.ConfigFlag==0){
  244. MSG_INFO(1, "First run");
  245. newPara.itemShowType=0;
  246. newPara.ConfigFlag=1;
  247. newPara.gpsTimeIndex=4;//默认30秒
  248. needsave=1;
  249. //检测TTS是否是UNICODE,是则将其从BE转换为LE,后面就可以直接播放了
  250. if(newPara.ttsMessage[0]!=0 && newPara.ttsCodeType==0) ttsToBEStr(newPara.ttsMessage, strlen(newPara.ttsMessage));
  251. newPara.spkVol=6;
  252. #ifdef BND_NEW_PLAT
  253. newPara.newold_plam=1;
  254. #else
  255. newPara.newold_plam=0;
  256. #endif
  257. #ifndef DEVELOP_MODE
  258. if(newPara.rstPsn!=0){
  259. newPara.rstPsn=0;
  260. setFactoryParam();
  261. }
  262. #endif
  263. }
  264. if(newPara.serverMenuPass!=NULL) memcpy(menu_key, newPara.serverMenuPass,6);
  265. if(newPara.spkVol>MAX_SPK_VOL){
  266. newPara.spkVol=6;
  267. needsave=1;
  268. }
  269. /*
  270. if(false==isNeedShutGps()){//GPS使能,必需打开布标
  271. MSG_WARN(1, "gpsEnable, force bubiaoEnable");
  272. newPara.bubiaoEnable=1;
  273. needsave=1;
  274. }
  275. */
  276. if(needsave!=0){
  277. ql_fseek(fd, 0L, 0);
  278. ql_fwrite((unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF),1,fd);
  279. //nwy_sdk_fsync(fd);
  280. }
  281. ql_fclose(fd);
  282. }
  283. //保存PSN文件处理
  284. #define PSN_FILE "EC600M_f2"
  285. void saveInfoNow(USER_STOR_INFO *info){
  286. QFILE * fd;
  287. char path[64]="U:/";
  288. strcat(path, PSN_FILE);
  289. MSG_INFO(1,"%s save start:%d,%s",PSN_FILE, info->OtherId,info->OtherPassWord);
  290. fd=ql_fopen(path,"wb+");
  291. if(fd==NULL){
  292. MSG_ERR(1,"%s open failed",PSN_FILE);
  293. return;
  294. }
  295. //保存
  296. ql_fseek(fd, 0L, 0);
  297. ql_fwrite((unsigned char *)&sutApp.UserInfo, sizeof(USER_STOR_INFO),1,fd);
  298. ql_fclose(fd);
  299. MSG_INFO(1,"%s save done", PSN_FILE);
  300. }
  301. void readInfoNow(void){
  302. QFILE * fd;
  303. char path[64]="U:/";
  304. strcat(path, PSN_FILE);
  305. fd=ql_fopen(path, "r+");
  306. if(fd==NULL){
  307. MSG_ERR(1,"%s open read failed", PSN_FILE);
  308. return;
  309. }
  310. MSG_ERR(1,"%s open read ok", PSN_FILE);
  311. ql_fseek(fd, 0L, 0);
  312. ql_fread( (unsigned char *)&sutApp.UserInfo, sizeof(USER_STOR_INFO),1,fd);
  313. if(sutApp.UserInfo.tnet != 4 && sutApp.UserInfo.tnet != 5){
  314. sutApp.UserInfo.tnet = 4;
  315. ql_fseek(fd, 0L, 0);
  316. ql_fwrite( (unsigned char *)&sutApp.UserInfo, sizeof(USER_STOR_INFO),1,fd);
  317. }
  318. ql_fclose(fd);
  319. MSG_INFO(1, "%s get info:%d,%s",PSN_FILE, sutApp.UserInfo.OtherId, sutApp.UserInfo.OtherPassWord);
  320. }
  321. void setFactoryParam(void){
  322. sutApp.UserInfo.psn=newPara.defaultPsn;
  323. saveInfoNow(&sutApp.UserInfo);
  324. MSG_INFO(1, "set factory psn:%d", sutApp.UserInfo.psn);
  325. }
  326. void setPocPara(char *pocPara, int len){
  327. sutApp.pocParaDone=1;
  328. }
  329. char showPIP[40];
  330. char showGIP[40];
  331. const char invalidIp[]="1.1.1.1";
  332. char *getPIPAddr(void){
  333. char *retAddr=NULL;
  334. switch(newPara.serList.defaultuse){
  335. case SERVER_HZ: retAddr=newPara.serList.zh.pip;break;
  336. case SERVER_SD: retAddr=newPara.serList.sd.pip;break;
  337. case SERVER_FENFA:retAddr=(char *)invalidIp;break;
  338. case SERVER_JIQUN:retAddr=(char *)invalidIp;break;
  339. case SERVER_UR: retAddr=newPara.serList.ur.pip;break;
  340. }
  341. memset(showPIP, 0, sizeof(showPIP));
  342. strcpy(showPIP, retAddr);
  343. return retAddr;
  344. }
  345. char *getGIPAddr(void){
  346. char *retAddr=NULL;
  347. switch(newPara.serList.defaultuse){
  348. case SERVER_HZ: retAddr=newPara.serList.zh.gip;break;
  349. case SERVER_SD: retAddr=newPara.serList.sd.gip;break;
  350. case SERVER_FENFA: break;
  351. case SERVER_JIQUN: break;
  352. case SERVER_UR: retAddr=newPara.serList.ur.gip;break;
  353. }
  354. if(retAddr==NULL) showGIP[0]=0;
  355. else strcpy(showGIP, retAddr);
  356. return retAddr;
  357. }
  358. char *getDOMAINAddr(void)
  359. {
  360. char *retAddr=NULL;
  361. switch(newPara.serList.defaultuse){
  362. case SERVER_HZ:break;
  363. case SERVER_SD:break;
  364. case SERVER_FENFA:retAddr=newPara.serList.ipFenFa;break;
  365. case SERVER_JIQUN:retAddr=newPara.serList.jiqun;break;
  366. case SERVER_UR:break;
  367. }
  368. return retAddr;
  369. }
  370. /*
  371. #define SYS_FILE_STATUS "hfiles/sys.status"
  372. #define SYS_FILE_BACKUP "hfiles/sys.bak"
  373. void checkNeedRecoverFile(void){
  374. int fd=LSAPI_FS_Open(SYS_FILE_STATUS, LSAPI_FS_O_RDONLY,0);
  375. if(fd<0){
  376. MSG_WARN(1, "'%s' lost, recover %s", SYS_FILE_STATUS,true==recoverOperation()?"ok":"failed");
  377. }else LSAPI_FS_Close(fd);
  378. }
  379. bool recoverOperation(void){
  380. bool returnValue=false;
  381. int ret,fd,fd_backup=-1,fd_ini=-1;
  382. unsigned char *backData=NULL;
  383. //0、读sys.bak内容出来
  384. fd_backup=LSAPI_FS_Open(SYS_FILE_BACKUP, LSAPI_FS_O_RDONLY,0);
  385. if(fd_backup<0){
  386. MSG_ERR(1,"%s open read failed", SYS_FILE_BACKUP);
  387. goto END;
  388. }
  389. LSAPI_FS_Stat_info_t pBuf;
  390. memset(&pBuf,0,sizeof(pBuf));
  391. ret=LSAPI_FS_Fstat(fd_backup,&pBuf);
  392. if(ret!=0){
  393. MSG_ERR(1,"%s get size failed, ret=%d", SYS_FILE_BACKUP, ret);
  394. goto END;
  395. }
  396. if(pBuf.st_size<sizeof(SYSINI_HS191X_DEF)){
  397. MSG_ERR(1, "%s size err:%d,%d", SYS_FILE_BACKUP,pBuf.st_size, sizeof(SYSINI_HS191X_DEF));
  398. goto END;
  399. }
  400. backData=malloc(pBuf.st_size*sizeof(unsigned char));
  401. if(backData==NULL){
  402. MSG_ERR(1, "%s malloc failed", SYS_FILE_BACKUP);
  403. goto END;
  404. }
  405. ret=LSAPI_FS_Read(fd_backup, backData,pBuf.st_size);
  406. if(ret<=0 || ret != pBuf.st_size){
  407. MSG_ERR(1, "%s read err ret=%d", SYS_FILE_BACKUP,ret);
  408. goto END;
  409. }
  410. LSAPI_FS_Close(fd_backup);
  411. fd_backup=-1;
  412. //1、删除sys.status
  413. fd=LSAPI_FS_Open(SYS_FILE_STATUS, LSAPI_FS_O_RDONLY,0);
  414. if(fd>=0){//存在,则删除之
  415. LSAPI_FS_Close(fd);
  416. ret=LSAPI_FS_Unlink(SYS_FILE_STATUS);
  417. if(ret!=0){
  418. MSG_INFO(1, "Del '%s' failed ret=%d", SYS_FILE_STATUS, ret);
  419. goto END;
  420. }
  421. }
  422. //2、复制到sys.ini
  423. fd_ini=LSAPI_FS_Open(SYSINI_FILE, LSAPI_FS_O_RDWR,0);
  424. if(fd_ini<0){
  425. MSG_ERR(1,"%s open failed", SYSINI_FILE);
  426. goto END;
  427. }
  428. ret=LSAPI_FS_Ftruncate(fd_ini,pBuf.st_size);
  429. if(ret!=0){
  430. MSG_ERR(1, "%s truncate failed:%d", SYSINI_FILE,ret);
  431. goto END;
  432. }
  433. ret=LSAPI_FS_Write(fd_ini, backData, pBuf.st_size);
  434. if(ret!=pBuf.st_size){
  435. MSG_ERR(1, "%s write failed:%d", SYSINI_FILE,ret);
  436. goto END;
  437. }
  438. LSAPI_FS_Close(fd_ini);
  439. fd_ini=-1;
  440. //3、恢复sys.status
  441. fd=LSAPI_FS_Open(SYS_FILE_STATUS, LSAPI_FS_O_RDWR|LSAPI_FS_O_CREAT,0);
  442. if(fd<0){
  443. MSG_ERR(1,"%s create failed:%d", SYS_FILE_STATUS,fd);
  444. goto END;
  445. }
  446. MSG_INFO(1, "CREATE DONE");
  447. LSAPI_FS_Close(fd);
  448. returnValue=true;
  449. END:
  450. if(fd_backup) LSAPI_FS_Close(fd_backup);
  451. if(fd_ini) LSAPI_FS_Close(fd_ini);
  452. if(backData!=NULL) free(backData);
  453. return returnValue;
  454. }
  455. */