setting.c 9.1 KB

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