setting.c 8.7 KB

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