setting(6649).c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. #include "includes.h"
  2. static void savePsnNow(ACCOUNT_DEF account);
  3. void cmdSetting(char *msg){
  4. char info[100],buf[50],ipAddr[40];
  5. char needSendAt=0;
  6. char needFeedSms=0;
  7. char needSaveSys=0;
  8. int len,port;
  9. unsigned long psn;
  10. if(sutApp.gtMode==0) return;
  11. if(sutApp.gtTMode!=0){
  12. msgAtSends(msg, strlen(msg));
  13. return;
  14. }
  15. //GT模式下指令处理
  16. if(msgCmp(msg, "GT+SMP")){
  17. len=GetParaFromStr(msg, "IP",buf);
  18. if(len<1 || len>=40){
  19. snprintf(info, sizeof(info),"GT+SMP:FAIL[IP Invalid]\r\n");
  20. needFeedSms=1;
  21. goto SETTING_END;
  22. }
  23. strcpy(ipAddr, buf);
  24. len=GetParaFromStr(msg, "Port", buf);
  25. if(len==0) port=0;
  26. else if(len>5){
  27. snprintf(info,sizeof(info),"GT+SMP:FAIL[Port Invalid]");
  28. needFeedSms=1;
  29. goto SETTING_END;
  30. }
  31. port=atoi(buf);
  32. len=GetParaFromStr(msg, "PSN",buf);
  33. if(len<1 || len>10){
  34. snprintf(info, sizeof(info),"GT+SMP:FAIL[PSN Invalid]\r\n");
  35. needFeedSms=1;
  36. goto SETTING_END;
  37. }
  38. psn=atol(buf);
  39. snprintf(info, sizeof(info),"GT+SMP:IP=%s;Port=%u;PSN=%lu;\r\n",ipAddr,port,psn);
  40. needFeedSms=1;
  41. //保存PSN
  42. if(sutApp.account.psn != psn){
  43. sutApp.account.psn=psn;
  44. saveInfoNow(sutApp.account);
  45. }
  46. //保存IP到sys.ini中的用户定义段
  47. if(strcmp(newPara.serList.ur.pip,ipAddr) || newPara.serList.defaultuse!=SERVER_UR){
  48. //不相等
  49. newPara.serList.defaultuse=SERVER_UR;
  50. strcpy(newPara.serList.ur.pip, ipAddr);
  51. sysIniSave();
  52. }
  53. }else if(msgCmp(msg, "GT+RMP")){
  54. snprintf(info, sizeof(info),"GT+RMP:PSN=%lu;MEID=%s;CNUM=0000000000;UIMID=0000000000;IP=%s;\r\n",sutApp.account.psn,ohpocGetIMEI(),getPIPAddr());
  55. needFeedSms=1;
  56. }else if(msgCmp(msg, "GT+TM")){
  57. snprintf(info, sizeof(info), "TM Mode:OK\r\n");
  58. needFeedSms=1;
  59. sutApp.gtTMode=1;
  60. }else if(msgCmp(msg, "GT+PWM=")){
  61. // if(msg[7]>='0' && msg[7]<='9') beepStart(atoi(msg+7));
  62. }else if(msgCmp(msg, "GT+RPID")){
  63. snprintf(info, sizeof(info), "GT+RPID:PSN=%lu;\r\n", sutApp.account.psn);
  64. needFeedSms=1;
  65. }else if(msgCmp(msg, "GT+SPID")){
  66. len=GetParaFromStr(msg, "PSN",buf);
  67. if(len<1 || len>10){
  68. snprintf(info, sizeof(info),"GT+SPID:FAIL[PSN Invalid]\r\n");
  69. needFeedSms=1;
  70. goto SETTING_END;
  71. }
  72. psn=atol(buf);
  73. snprintf(info, sizeof(info),"GT+SPID:PSN=%lu;\r\n",psn);
  74. needFeedSms=1;
  75. if(sutApp.account.psn != psn){
  76. sutApp.account.psn=psn;
  77. saveInfoNow(sutApp.account);
  78. }
  79. }else if(msgCmp(msg, "GT+RDOMAIN")){
  80. snprintf(info,sizeof(info),"GT+RDOMAIN:%s;PSN=%lu;\r\n",newPara.serList.ipFenFa,sutApp.account.psn);
  81. needFeedSms=1;
  82. }else if(msgCmp(msg, "GT+SDOMAIN")){
  83. len=GetParaFromStr(msg, "PSN",buf);
  84. if(len<1 || len>10){
  85. snprintf(info, sizeof(info),"GT+SDOMAIN:FAIL[PSN Invalid]\r\n");
  86. needFeedSms=1;
  87. goto SETTING_END;
  88. }
  89. psn=atol(buf);
  90. len=GetParaFromStr(msg, "SDOMAIN",buf);
  91. if(len>40){
  92. snprintf(info, sizeof(info),"GT+SDOMAIN:FAIL[DOMAIN Invalid]\r\n");
  93. needFeedSms=1;
  94. goto SETTING_END;
  95. }
  96. if(newPara.serList.defaultuse != SERVER_FENFA){
  97. newPara.serList.defaultuse=SERVER_FENFA;
  98. needSaveSys=1;
  99. }
  100. if(0!=strcmp(newPara.serList.ipFenFa, buf)){
  101. memset(newPara.serList.ipFenFa,0,sizeof(newPara.serList.ipFenFa));
  102. snprintf(newPara.serList.ipFenFa,sizeof(newPara.serList.ipFenFa),"%s",buf);
  103. needSaveSys=1;
  104. }
  105. if(sutApp.account.psn != psn){
  106. sutApp.account.psn=psn;
  107. saveInfoNow(sutApp.account);
  108. }
  109. snprintf(info, sizeof(info),"GT+SDOMAIN=%s;PSN=%lu;\r\n",newPara.serList.ipFenFa,psn);
  110. needFeedSms=1;
  111. }else if(msgCmp(msg, "GT+SNET")){//GT+SNET:TNET=4;GT+SNET:TNET=5;
  112. len=GetParaFromStr(msg, "TNET",buf);
  113. if(len!=1){
  114. TNET_ERR:
  115. snprintf(info, sizeof(info),"GT+SNET:FAIL[TNET Invalid]\r\n");
  116. needFeedSms=1;
  117. goto SETTING_END;
  118. }
  119. psn=atol(buf);
  120. if(psn !=4 && psn != 5) goto TNET_ERR;
  121. if(psn != sutApp.account.tnet){
  122. sutApp.account.tnet=psn;
  123. saveInfoNow(sutApp.account);
  124. }
  125. snprintf(info, sizeof(info),"GT+SNET:TNET=%d\r\n",psn);
  126. needFeedSms=1;
  127. }else if(msgCmp(msg, "GT+RNET")){
  128. snprintf(info,sizeof(info),"GT+RNET:TNET=%d;\r\n",sutApp.account.tnet);
  129. needFeedSms=1;
  130. }else if(msgCmp(msg, "GT+RPOS")){
  131. snprintf(info, sizeof(info),"GT+RPOS:VALUE=%d;\r\n", newPara.itemShowType);
  132. needFeedSms=1;
  133. }else if(msgCmp(msg, "GT+SPOS")){//GT+SPOS:VALUE=0;
  134. len=GetParaFromStr(msg, "VALUE",buf);
  135. if(len!=1){
  136. SPOS_ERR:
  137. snprintf(info, sizeof(info),"GT+SPOS:FAIL[VALUE Invalid]\r\n");
  138. needFeedSms=1;
  139. goto SETTING_END;
  140. }
  141. psn=atol(buf);
  142. if(psn != 0 && psn != 1) goto SPOS_ERR;
  143. if(psn != newPara.itemShowType){
  144. newPara.itemShowType=psn;
  145. needSaveSys=1;
  146. }
  147. snprintf(info, sizeof(info),"GT+SPOS:VALUE=%d;\r\n",psn);
  148. needFeedSms=1;
  149. }
  150. SETTING_END:
  151. if(needSendAt!=0) msgAtSends(info, strlen(info));
  152. if(needFeedSms!=0) usbOutPut(info, strlen(info));
  153. if(needSaveSys!=0) sysIniSave();
  154. }
  155. //sysini文件处理
  156. #define SYSINI_FILE "sys.ini"
  157. SYSINI_HS191X_DEF newPara;
  158. char menu_key[6]="502800";//如果资源文件中没有定义服务器菜单密码,则默认使用此密码
  159. char *getMenuKey(void){return menu_key;}
  160. static void ttsToBEStr(char *tts, int len){
  161. int i;
  162. char tmp[2];
  163. if(len % 4) return;
  164. for(i=0;i<len/4;i++){
  165. tmp[0]=tts[4*i];tmp[1]=tts[4*i+1];
  166. tts[4*i]=tts[4*i+2];
  167. tts[4*i+1]=tts[4*i+3];
  168. tts[4*i+2]=tmp[0];
  169. tts[4*i+3]=tmp[1];
  170. }
  171. }
  172. void sysIniSave(void){
  173. int fd;
  174. MSG_INFO(1,"%s save start",SYSINI_FILE);
  175. fd=LSAPI_FS_Open(SYSINI_FILE, LSAPI_FS_O_RDWR,0x0);
  176. if(fd<0){
  177. MSG_ERR(1,"%s open failed",SYSINI_FILE);
  178. return;
  179. }
  180. //保存
  181. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  182. LSAPI_FS_Write(fd, (unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF));
  183. //nwy_sdk_fsync(fd);
  184. LSAPI_FS_Close(fd);
  185. MSG_INFO(1,"%s save done", SYSINI_FILE);
  186. }
  187. void setFactoryParam(void);
  188. void sysIniRead(void){
  189. int fd;
  190. char needsave=0;
  191. fd=LSAPI_FS_Open(SYSINI_FILE, LSAPI_FS_O_RDWR,0);
  192. if(fd<0){
  193. MSG_ERR(1,"%s open read failed", SYSINI_FILE);
  194. return;
  195. }
  196. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  197. LSAPI_FS_Read(fd, (unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF));
  198. if(newPara.ConfigFlag==0){
  199. MSG_INFO(1, "First run");
  200. newPara.itemShowType=0;
  201. newPara.ConfigFlag=1;
  202. newPara.lockType=0;//锁正面
  203. needsave=1;
  204. //检测TTS是否是UNICODE,是则将其从BE转换为LE,后面就可以直接播放了
  205. if(newPara.ttsMessage[0]!=0 && newPara.ttsCodeType==0) ttsToBEStr(newPara.ttsMessage, strlen(newPara.ttsMessage));
  206. newPara.spkVol=6;
  207. newPara.micGain=MIC_GAIN_DEFAULT;
  208. newPara.spkGain=SPK_GAIN_DEFAULT;
  209. #ifndef DEVELOP_MODE
  210. setFactoryParam();
  211. #endif
  212. }
  213. if(newPara.serverMenuPass!=NULL) memcpy(menu_key, newPara.serverMenuPass,6);
  214. //测试开始
  215. //newPara.gpsEnable=0;
  216. //newPara.bubiaoEnable=0;
  217. //newPara.KeySound=1;
  218. //测试结束
  219. if(newPara.spkVol>MAX_SPK_VOL){
  220. newPara.spkVol=6;
  221. needsave=1;
  222. }
  223. if(newPara.gpsEnable!=0){//GPS使能,必需打开布标
  224. MSG_WARN(1, "gpsEnable, force bubiaoEnable");
  225. newPara.bubiaoEnable=1;
  226. needsave=1;
  227. }
  228. if(needsave!=0){
  229. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  230. LSAPI_FS_Write(fd, (unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF));
  231. //nwy_sdk_fsync(fd);
  232. }
  233. LSAPI_FS_Close(fd);
  234. }
  235. //保存PSN文件处理
  236. #define PSN_FILE "m5700_f2"
  237. void saveInfoNow(ACCOUNT_DEF account){
  238. int fd;
  239. MSG_INFO(1,"%s save start:%d,%s",PSN_FILE, account.psn,account.password);
  240. fd=LSAPI_FS_Open(PSN_FILE, LSAPI_FS_O_RDWR |LSAPI_FS_O_CREAT,0x0);
  241. if(fd<0){
  242. MSG_ERR(1,"%s open failed",PSN_FILE);
  243. return;
  244. }
  245. //保存
  246. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  247. LSAPI_FS_Write(fd, (unsigned char *)&account, sizeof(ACCOUNT_DEF));
  248. //nwy_sdk_fsync(fd);
  249. LSAPI_FS_Close(fd);
  250. MSG_INFO(1,"%s save done", PSN_FILE);
  251. }
  252. void readInfoNow(void){
  253. int fd;
  254. fd=LSAPI_FS_Open(PSN_FILE, LSAPI_FS_O_RDONLY,0);
  255. if(fd<0){
  256. MSG_ERR(1,"%s open read failed", PSN_FILE);
  257. return;
  258. }
  259. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  260. LSAPI_FS_Read(fd, (unsigned char *)&sutApp.account, sizeof(ACCOUNT_DEF));
  261. if(sutApp.account.tnet != 4 && sutApp.account.tnet != 5){
  262. sutApp.account.tnet = 4;
  263. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  264. LSAPI_FS_Write(fd, (unsigned char *)&sutApp, sizeof(ACCOUNT_DEF));
  265. }
  266. LSAPI_FS_Close(fd);
  267. MSG_INFO(1, "%s get info:%d,%s",PSN_FILE, sutApp.account.psn, sutApp.account.password);
  268. }
  269. void setFactoryParam(void){
  270. sutApp.account.psn=newPara.defaultPsn;
  271. saveInfoNow(sutApp.account);
  272. MSG_INFO(1, "set factory psn:%d", sutApp.account.psn);
  273. }
  274. void setPocPara(char *pocPara, int len){
  275. int k;
  276. char buf[40];
  277. char buf1[100];
  278. char pwd[40];
  279. char idFlag=0,domainFlag=0,ipFlag=0;
  280. char gapFlag=0,gportFlag=0;
  281. char pwdFlag=0;
  282. char enableChangeIp=1;
  283. if(0!=restoreDataFormatByHex(pocPara,len)){//库接口提便
  284. MSG_ERR(1, "setPocPara get error");
  285. return;
  286. }
  287. k=len/2;
  288. pocPara[k]=0;
  289. //找pwd
  290. GetParaFromStr(pocPara, "pwd", pwd);
  291. if(0!=strcmp(sutApp.account.password, pwd)) pwdFlag=1;
  292. //找id
  293. GetParaFromStr(pocPara, "id", buf);
  294. snprintf(buf1, sizeof(buf1), "%lu", sutApp.account.psn);
  295. if(0!=strcmp(buf1, buf)) idFlag=1;
  296. //找domain
  297. switch(newPara.serList.defaultuse){
  298. case SERVER_HZ:
  299. case SERVER_SD:
  300. case SERVER_UR:break;
  301. case SERVER_FENFA:
  302. case SERVER_JIQUN:
  303. if(newPara.serList.defaultuse==SERVER_FENFA) snprintf(buf1, sizeof(buf1), "%s", newPara.serList.ipFenFa);
  304. else if(newPara.serList.defaultuse==SERVER_JIQUN) snprintf(buf1, sizeof(buf1), "%s", newPara.serList.jiqun);
  305. GetParaFromStr(pocPara, "domain", buf);
  306. if(0!=strcmp(buf1, buf)) domainFlag=1;
  307. enableChangeIp=0;
  308. break;
  309. }
  310. if(enableChangeIp!=0){
  311. GetParaFromStr(pocPara, "ip", buf);
  312. snprintf(buf1, sizeof(buf1), "%s", getPIPAddr());
  313. if(0!=strcmp(buf1, buf)) ipFlag=1;
  314. }
  315. //找gap
  316. if(newPara.serList.defaultuse!=SERVER_FENFA && newPara.serList.defaultuse!=SERVER_JIQUN){//分发/集群时不需要比对GPS,因为POC已保存了
  317. GetParaFromStr(pocPara, "gap", buf);
  318. snprintf(buf1, sizeof(buf1), "%s", getGIPAddr());
  319. if(0!=strcmp(buf1, buf)) gapFlag=1;
  320. }
  321. //找gport
  322. GetParaFromStr(pocPara, "gport", buf);
  323. snprintf(buf1, sizeof(buf1), "%d", newPara.gpsPort);
  324. if(0!=strcmp(buf1, buf)) gportFlag=1;
  325. //MSG_INFO(1, "-->%d,%d,%d,%d,%d",idFlag,ipFlag,domainFlag,gapFlag,gportFlag);
  326. if(idFlag==0 && ipFlag==0 && domainFlag==0 && gapFlag==0 && gportFlag==0 && pwdFlag==0){
  327. MSG_INFO(1, "POC still");
  328. sutApp.pocParaDone=2;
  329. return;
  330. }
  331. msgAtSend("AT+POC=010000");
  332. //更新pwd
  333. if(pwdFlag!=0){
  334. snprintf(buf, sizeof(buf), "pwd=%s;", sutApp.account.password);
  335. AscStrTurnHexStr(buf, buf1);
  336. msgAtSend(buf1);
  337. }
  338. //更新id
  339. if(idFlag!=0){
  340. snprintf(buf, sizeof(buf), "id=%lu;", sutApp.account.psn);
  341. AscStrTurnHexStr(buf, buf1);
  342. msgAtSend(buf1);
  343. }
  344. //更新ip
  345. if(enableChangeIp!=0){
  346. snprintf(buf, sizeof(buf), "ip=%s;", getPIPAddr());
  347. AscStrTurnHexStr(buf, buf1);
  348. msgAtSend(buf1);
  349. }
  350. //更新domian
  351. if(newPara.serList.defaultuse==SERVER_FENFA) snprintf(buf, sizeof(buf), "domain=%s;",newPara.serList.ipFenFa);
  352. else if(newPara.serList.defaultuse==SERVER_JIQUN)snprintf(buf, sizeof(buf), "domain=%s;",newPara.serList.jiqun);
  353. else snprintf(buf, sizeof(buf), "domain=;");
  354. AscStrTurnHexStr(buf, buf1);
  355. msgAtSend(buf1);
  356. //更新gap
  357. if(gapFlag!=0){
  358. snprintf(buf, sizeof(buf), "gap=%s;", getGIPAddr());
  359. AscStrTurnHexStr(buf, buf1);
  360. msgAtSend(buf1);
  361. }
  362. //更新gport
  363. if(gportFlag!=0){
  364. snprintf(buf, sizeof(buf), "gport=%d;", newPara.gpsPort);
  365. AscStrTurnHexStr(buf, buf1);
  366. msgAtSend(buf1);
  367. }
  368. msgAtSend("\r\n");
  369. MSG_INFO(1, "POC reset");
  370. sutApp.pocParaDone=1;
  371. }
  372. char showPIP[40];
  373. char showGIP[40];
  374. const char invalidIp[]="1.1.1.1";
  375. char *getPIPAddr(void){
  376. char *retAddr=NULL;
  377. switch(newPara.serList.defaultuse){
  378. case SERVER_HZ: retAddr=newPara.serList.zh.pip;break;
  379. case SERVER_SD: retAddr=newPara.serList.sd.pip;break;
  380. case SERVER_FENFA:retAddr=(char *)invalidIp;break;
  381. case SERVER_JIQUN:retAddr=(char *)invalidIp;break;
  382. case SERVER_UR: retAddr=newPara.serList.ur.pip;break;
  383. }
  384. memset(showPIP, 0, sizeof(showPIP));
  385. strcpy(showPIP, retAddr);
  386. return retAddr;
  387. }
  388. char *getGIPAddr(void){
  389. char *retAddr=NULL;
  390. switch(newPara.serList.defaultuse){
  391. case SERVER_HZ: retAddr=newPara.serList.zh.gip;break;
  392. case SERVER_SD: retAddr=newPara.serList.sd.gip;break;
  393. case SERVER_FENFA: break;
  394. case SERVER_JIQUN: break;
  395. case SERVER_UR: retAddr=newPara.serList.ur.gip;break;
  396. }
  397. if(retAddr==NULL) showGIP[0]=0;
  398. else strcpy(showGIP, retAddr);
  399. return retAddr;
  400. }
  401. char *getDOMAINAddr(void)
  402. {
  403. char *retAddr=NULL;
  404. switch(newPara.serList.defaultuse){
  405. case SERVER_HZ:break;
  406. case SERVER_SD:break;
  407. case SERVER_FENFA:retAddr=newPara.serList.ipFenFa;break;
  408. case SERVER_JIQUN:retAddr=newPara.serList.jiqun;break;
  409. case SERVER_UR:break;
  410. }
  411. return retAddr;
  412. }