setting.c 10 KB

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