setting.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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. newPara.paCnt=2;//FM
  119. }
  120. if(newPara.serverMenuPass!=NULL) memcpy(menu_key, newPara.serverMenuPass,6);
  121. //测试开?
  122. //newPara.gpsEnable=0;
  123. //newPara.bubiaoEnable=0;
  124. //newPara.KeySound=1;
  125. //测试结束
  126. if(newPara.spkVol>10){
  127. newPara.spkVol=6;
  128. needsave=1;
  129. }
  130. if(newPara.gpsEnable!=0){//GPS使能,必需打开布标
  131. MSG_WARN(1, "gpsEnable, force bubiaoEnable");
  132. newPara.bubiaoEnable=1;
  133. needsave=1;
  134. }
  135. if(needsave!=0){
  136. nwy_sdk_fseek(fd, 0L, NWY_SEEK_SET);
  137. nwy_sdk_fwrite(fd, (unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF));
  138. nwy_sdk_fsync(fd);
  139. }
  140. nwy_sdk_fclose(fd);
  141. }
  142. //保存PSN文件处理
  143. #define PSN_FILE "n58_f2"
  144. static void saveInfoNow(ACCOUNT_DEF account){
  145. int fd;
  146. MSG_INFO(1,"%s save start:%d,%s",PSN_FILE, account.psn,account.password);
  147. fd=nwy_sdk_fopen(PSN_FILE, NWY_RDWR | NWY_CREAT);
  148. if(fd<0){
  149. MSG_ERR(1,"%s open failed",PSN_FILE);
  150. return;
  151. }
  152. //保存
  153. nwy_sdk_fseek(fd, 0L, NWY_SEEK_SET);
  154. nwy_sdk_fwrite(fd, (unsigned char *)&account, sizeof(ACCOUNT_DEF));
  155. nwy_sdk_fsync(fd);
  156. nwy_sdk_fclose(fd);
  157. MSG_INFO(1,"%s save done", PSN_FILE);
  158. }
  159. void readInfoNow(void){
  160. int fd;
  161. fd=nwy_sdk_fopen(PSN_FILE, NWY_RDONLY);
  162. if(fd<0){
  163. MSG_ERR(1,"%s open read failed", PSN_FILE);
  164. return;
  165. }
  166. nwy_sdk_fseek(fd, 0L, NWY_SEEK_SET);
  167. nwy_sdk_fread(fd, (unsigned char *)&sutApp.account, sizeof(ACCOUNT_DEF));
  168. nwy_sdk_fclose(fd);
  169. MSG_INFO(1, "%s get info:%d,%s",PSN_FILE, sutApp.account.psn, sutApp.account.password);
  170. }
  171. void setPocPara(char *pocPara, int len){
  172. int k;
  173. char buf[40];
  174. char buf1[100];
  175. char pwd[40];
  176. char idFlag=0,domainFlag=0,ipFlag=0;
  177. char gapFlag=0,gportFlag=0;
  178. char pwdFlag=0;
  179. char enableChangeIp=1;
  180. if(0!=restoreDataFormatByHex(pocPara,len)){//库接口提?
  181. MSG_ERR(1, "setPocPara get error");
  182. return;
  183. }
  184. k=len/2;
  185. pocPara[k]=0;
  186. //找pwd
  187. GetParaFromStr(pocPara, "pwd", pwd);
  188. if(0!=strcmp(sutApp.account.password, pwd)) pwdFlag=1;
  189. //找id
  190. GetParaFromStr(pocPara, "id", buf);
  191. snprintf(buf1, sizeof(buf1), "%lu", sutApp.account.psn);
  192. if(0!=strcmp(buf1, buf)) idFlag=1;
  193. //找domain
  194. switch(newPara.serList.defaultuse){
  195. case SERVER_HZ:
  196. case SERVER_SD:
  197. case SERVER_UR:break;
  198. case SERVER_FENFA:
  199. case SERVER_JIQUN:
  200. if(newPara.serList.defaultuse==SERVER_FENFA) snprintf(buf1, sizeof(buf1), "%s", newPara.serList.ipFenFa);
  201. else if(newPara.serList.defaultuse==SERVER_JIQUN) snprintf(buf1, sizeof(buf1), "%s", newPara.serList.jiqun);
  202. GetParaFromStr(pocPara, "domain", buf);
  203. if(0!=strcmp(buf1, buf)) domainFlag=1;
  204. enableChangeIp=0;
  205. break;
  206. }
  207. if(enableChangeIp!=0){
  208. GetParaFromStr(pocPara, "ip", buf);
  209. snprintf(buf1, sizeof(buf1), "%s", getPIPAddr());
  210. if(0!=strcmp(buf1, buf)) ipFlag=1;
  211. }
  212. //找gap
  213. if(newPara.serList.defaultuse!=SERVER_FENFA && newPara.serList.defaultuse!=SERVER_JIQUN){//分发/集群时不需要比对GPS,因为POC已保存了
  214. GetParaFromStr(pocPara, "gap", buf);
  215. snprintf(buf1, sizeof(buf1), "%s", getGIPAddr());
  216. if(0!=strcmp(buf1, buf)) gapFlag=1;
  217. }
  218. //找gport
  219. GetParaFromStr(pocPara, "gport", buf);
  220. snprintf(buf1, sizeof(buf1), "%d", newPara.gpsPort);
  221. if(0!=strcmp(buf1, buf)) gportFlag=1;
  222. //MSG_INFO(1, "-->%d,%d,%d,%d,%d",idFlag,ipFlag,domainFlag,gapFlag,gportFlag);
  223. if(idFlag==0 && ipFlag==0 && domainFlag==0 && gapFlag==0 && gportFlag==0 && pwdFlag==0){
  224. MSG_INFO(1, "POC still");
  225. sutApp.pocParaDone=1;
  226. return;
  227. }
  228. msgAtSend("AT+POC=010000");
  229. //更新pwd
  230. if(pwdFlag!=0){
  231. snprintf(buf, sizeof(buf), "pwd=%s;", sutApp.account.password);
  232. AscStrTurnHexStr(buf, buf1);
  233. msgAtSend(buf1);
  234. }
  235. //更新id
  236. if(idFlag!=0){
  237. snprintf(buf, sizeof(buf), "id=%lu;", sutApp.account.psn);
  238. AscStrTurnHexStr(buf, buf1);
  239. msgAtSend(buf1);
  240. }
  241. //更新ip
  242. if(enableChangeIp!=0){
  243. snprintf(buf, sizeof(buf), "ip=%s;", getPIPAddr());
  244. AscStrTurnHexStr(buf, buf1);
  245. msgAtSend(buf1);
  246. }
  247. //更新domian
  248. if(newPara.serList.defaultuse==SERVER_FENFA) snprintf(buf, sizeof(buf), "domain=%s;",newPara.serList.ipFenFa);
  249. else if(newPara.serList.defaultuse==SERVER_JIQUN)snprintf(buf, sizeof(buf), "domain=%s;",newPara.serList.jiqun);
  250. else snprintf(buf, sizeof(buf), "domain=;");
  251. AscStrTurnHexStr(buf, buf1);
  252. msgAtSend(buf1);
  253. //更新gap
  254. if(gapFlag!=0){
  255. snprintf(buf, sizeof(buf), "gap=%s;", getGIPAddr());
  256. AscStrTurnHexStr(buf, buf1);
  257. msgAtSend(buf1);
  258. }
  259. //更新gport
  260. if(gportFlag!=0){
  261. snprintf(buf, sizeof(buf), "gport=%d;", newPara.gpsPort);
  262. AscStrTurnHexStr(buf, buf1);
  263. msgAtSend(buf1);
  264. }
  265. msgAtSend("\r\n");
  266. MSG_INFO(1, "POC reset");
  267. sutApp.pocParaDone=1;
  268. }
  269. char showPIP[40];
  270. char showGIP[40];
  271. const char invalidIp[]="1.1.1.1";
  272. char *getPIPAddr(void){
  273. char *retAddr=NULL;
  274. switch(newPara.serList.defaultuse){
  275. case SERVER_HZ: retAddr=newPara.serList.zh.pip;break;
  276. case SERVER_SD: retAddr=newPara.serList.sd.pip;break;
  277. case SERVER_FENFA:retAddr=(char *)invalidIp;break;
  278. case SERVER_JIQUN:retAddr=(char *)invalidIp;break;
  279. case SERVER_UR: retAddr=newPara.serList.ur.pip;break;
  280. }
  281. memset(showPIP, 0, sizeof(showPIP));
  282. strcpy(showPIP, retAddr);
  283. return retAddr;
  284. }
  285. char *getGIPAddr(void){
  286. char *retAddr=NULL;
  287. switch(newPara.serList.defaultuse){
  288. case SERVER_HZ: retAddr=newPara.serList.zh.gip;break;
  289. case SERVER_SD: retAddr=newPara.serList.sd.gip;break;
  290. case SERVER_FENFA: break;
  291. case SERVER_JIQUN: break;
  292. case SERVER_UR: retAddr=newPara.serList.ur.gip;break;
  293. }
  294. if(retAddr==NULL) showGIP[0]=0;
  295. else strcpy(showGIP, retAddr);
  296. return retAddr;
  297. }
  298. char *getDOMAINAddr(void)
  299. {
  300. char *retAddr=NULL;
  301. switch(newPara.serList.defaultuse){
  302. case SERVER_HZ:break;
  303. case SERVER_SD:break;
  304. case SERVER_FENFA:retAddr=newPara.serList.ipFenFa;break;
  305. case SERVER_JIQUN:retAddr=newPara.serList.jiqun;break;
  306. case SERVER_UR:break;
  307. }
  308. return retAddr;
  309. }