setting.c 9.1 KB

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