setting.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. #include "includes.h"
  2. void cmdSetting(char *msg){
  3. char info[100],buf[50],ipAddr[40];
  4. char needSendAt=0;
  5. char needFeedSms=0;
  6. int len,port;
  7. unsigned long psn;
  8. if(sutApp.gtMode==0) return;
  9. if(sutApp.gtTMode!=0){
  10. if(msgCmp(msg, "AT+POC=poccmd1")){
  11. msgAtSends("AT+POC=poccmd1", strlen("AT+POC=poccmd1"));
  12. }else msgAtSends(msg, strlen(msg));
  13. return;
  14. }
  15. else if(msgCmp(msg, "GT+TM")){
  16. snprintf(info, sizeof(info), "TM Mode:OK\r\n");
  17. needFeedSms=1;
  18. sutApp.gtTMode=1;
  19. }else if(msgCmp(msg, "GT+PWM=")){
  20. // if(msg[7]>='0' && msg[7]<='9') beepStart(atoi(msg+7));
  21. }else if(msgCmp(msg, "GT+SNET")){ //GT+SNET:TNET=4;GT+SNET:TNET=5;
  22. len=GetParaFromStr(msg, "TNET", buf);
  23. if(len!=1){
  24. TNET_ERR:
  25. snprintf(info, sizeof(info),"GT+SNET:FAIL[PSN Invalid]\r\n");
  26. needFeedSms=1;
  27. goto SETTING_END;
  28. }
  29. psn=atoi(buf);
  30. if(psn!=4&&psn!=5) goto TNET_ERR;
  31. MSG_INFO(1,"psn=====%d",psn);
  32. if(psn!=sutApp.UserInfo.tnet){
  33. sutApp.UserInfo.tnet=psn;
  34. saveInfoNow(&sutApp.UserInfo);
  35. }
  36. snprintf(info,sizeof(info),"GT+SNET:TNET=%d\r\n",psn);
  37. needFeedSms=1;
  38. }else if(msgCmp(msg, "GT+RNET")){
  39. snprintf(info, sizeof(info),"GT+RNET:TNET=%d;\r\n",sutApp.UserInfo.tnet);
  40. needFeedSms=1;
  41. }else if(msgCmp(msg, "GT+SZZD")){
  42. len=GetParaFromStr(msg,"ID",buf);
  43. if(len<1 || len>15){
  44. snprintf(info, sizeof(info),"GT+SZZD:FAIL[ID Invalid]\r\n");
  45. needFeedSms=1;
  46. goto SETTING_END;
  47. }
  48. strcpy(sutApp.UserInfo.OtherId,buf);
  49. if(len<1 || len>19){
  50. snprintf(info, sizeof(info),"GT+SZZD:FAIL[PWD Invalid]\r\n");
  51. needFeedSms=1;
  52. goto SETTING_END;
  53. }
  54. len=GetParaFromStr(msg,"PWD",buf);
  55. strcpy(sutApp.UserInfo.OtherPassWord,buf);
  56. snprintf(info, sizeof(info),"GT+SZZD:ID=%s;PWD=%s;\r\n",sutApp.UserInfo.OtherId,sutApp.UserInfo.OtherPassWord);
  57. needFeedSms=1;
  58. saveInfoNow(&sutApp.UserInfo);
  59. }
  60. else if(msgCmp(msg, "GT+RZZD")){
  61. snprintf(info, sizeof(info),"GT+RZZD:Id=%s;Pwd=%s;\r\n",sutApp.UserInfo.OtherId,sutApp.UserInfo.OtherPassWord);
  62. needFeedSms=1;
  63. goto SETTING_END;
  64. }
  65. //unsigned char platform[20];
  66. //unsigned char pFormatMark[20];
  67. else if(msgCmp(msg, "GT+SDOMAIN")){
  68. len=GetParaFromStr(msg,"PLAT",buf);
  69. if(len<1 || len>15){
  70. snprintf(info, sizeof(info),"GT+SDOMAIN:FAIL[ID Invalid]\r\n");
  71. needFeedSms=1;
  72. goto SETTING_END;
  73. }
  74. strcpy(sutApp.UserInfo.platform,buf);
  75. if(len<1 || len>19){
  76. snprintf(info, sizeof(info),"GT+SDOMAIN:FAIL[PWD Invalid]\r\n");
  77. needFeedSms=1;
  78. goto SETTING_END;
  79. }
  80. len=GetParaFromStr(msg,"MARK",buf);
  81. strcpy(sutApp.UserInfo.pFormatMark,buf);
  82. snprintf(info, sizeof(info),"GT+SDOMAIN:PLAT=%s;MARK=%s;\r\n",sutApp.UserInfo.platform,sutApp.UserInfo.pFormatMark);
  83. needFeedSms=1;
  84. saveInfoNow(&sutApp.UserInfo);
  85. }
  86. else if(msgCmp(msg, "GT+RDOMAIN")){
  87. snprintf(info, sizeof(info),"GT+RDOMAIN:PLAT=%s;MARK=%s;\r\n",sutApp.UserInfo.platform,sutApp.UserInfo.pFormatMark);
  88. needFeedSms=1;
  89. goto SETTING_END;
  90. }
  91. SETTING_END:
  92. if(needSendAt!=0) msgAtSends(info, strlen(info));
  93. if(needFeedSms!=0) usbOutPut(info, strlen(info));
  94. }
  95. //sysini鏂囦欢澶勭悊
  96. #define SYSINI_FILE "sys.ini"
  97. SYSINI_HS191X_DEF newPara;
  98. char menu_key[6]="502800";//濡傛灉璧勬簮鏂囦欢涓�病鏈夊畾涔夋湇鍔″櫒鑿滃崟瀵嗙爜锛屽垯榛樿�浣跨敤姝ゅ瘑鐮?
  99. char *getMenuKey(void){return menu_key;}
  100. static void ttsToBEStr(char *tts, int len){
  101. int i;
  102. char tmp[2];
  103. if(len % 4) return;
  104. for(i=0;i<len/4;i++){
  105. tmp[0]=tts[4*i];tmp[1]=tts[4*i+1];
  106. tts[4*i]=tts[4*i+2];
  107. tts[4*i+1]=tts[4*i+3];
  108. tts[4*i+2]=tmp[0];
  109. tts[4*i+3]=tmp[1];
  110. }
  111. }
  112. void sysIniSave(void){
  113. int fd;
  114. MSG_INFO(1,"%s save start",SYSINI_FILE);
  115. fd=LSAPI_FS_Open(SYSINI_FILE, LSAPI_FS_O_RDWR,0x0);
  116. if(fd<0){
  117. MSG_ERR(1,"%s open failed",SYSINI_FILE);
  118. return;
  119. }
  120. //淇濆瓨
  121. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  122. LSAPI_FS_Write(fd, (unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF));
  123. //nwy_sdk_fsync(fd);
  124. LSAPI_FS_Close(fd);
  125. MSG_INFO(1,"%s save done", SYSINI_FILE);
  126. }
  127. void sysIniRead(void){
  128. int fd;
  129. char needsave=0;
  130. fd=LSAPI_FS_Open(SYSINI_FILE, LSAPI_FS_O_RDWR,0);
  131. if(fd<0){
  132. MSG_ERR(1,"%s open read failed", SYSINI_FILE);
  133. return;
  134. }
  135. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  136. LSAPI_FS_Read(fd, (unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF));
  137. if(newPara.ConfigFlag==0){
  138. MSG_INFO(1, "First run");
  139. newPara.ConfigFlag=1;
  140. needsave=1;
  141. //妫€娴婽TS鏄�惁鏄疷NICODE锛屾槸鍒欏皢鍏朵粠BE杞�崲涓篖E锛屽悗闈㈠氨鍙�互鐩存帴鎾�斁浜?
  142. if(newPara.ttsMessage[0]!=0 && newPara.ttsCodeType==0) ttsToBEStr(newPara.ttsMessage, strlen(newPara.ttsMessage));
  143. newPara.spkVol=6;
  144. newPara.VolMicLvCu=4;
  145. newPara.VolMicLvXi=10;
  146. newPara.pwrMode=1;//智能模式
  147. newPara.voiceSel=0;//标准音质
  148. }
  149. if(newPara.serverMenuPass!=NULL) memcpy(menu_key, newPara.serverMenuPass,6);
  150. //娴嬭瘯寮€濮?
  151. //newPara.gpsEnable=0;
  152. //newPara.bubiaoEnable=0;
  153. //newPara.KeySound=1;
  154. //娴嬭瘯缁撴潫
  155. if(newPara.spkVol>MAX_SPK_VOL){
  156. newPara.spkVol=6;
  157. needsave=1;
  158. }
  159. if(newPara.gpsEnable!=0){//GPS浣胯兘锛屽繀闇€鎵撳紑甯冩爣
  160. MSG_WARN(1, "gpsEnable, force bubiaoEnable");
  161. newPara.bubiaoEnable=1;
  162. needsave=1;
  163. }
  164. if(needsave!=0){
  165. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  166. LSAPI_FS_Write(fd, (unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF));
  167. //nwy_sdk_fsync(fd);
  168. }
  169. LSAPI_FS_Close(fd);
  170. }
  171. //淇濆瓨PSN鏂囦欢澶勭悊
  172. #define PSN_FILE "m5700_f2"
  173. void saveInfoNow(USER_STOR_INFO *info){
  174. int fd;
  175. MSG_INFO(1,"%s save start:",PSN_FILE);
  176. fd=LSAPI_FS_Open(PSN_FILE, LSAPI_FS_O_RDWR |LSAPI_FS_O_CREAT,0x0);
  177. if(fd<0){
  178. MSG_ERR(1,"%s open failed",PSN_FILE);
  179. return;
  180. }
  181. if(info->tnet!=4&&info->tnet!=5){
  182. info->tnet=4;
  183. }
  184. //淇濆瓨
  185. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  186. LSAPI_FS_Write(fd, (unsigned char *)&sutApp.UserInfo, sizeof(USER_STOR_INFO));
  187. //nwy_sdk_fsync(fd);
  188. LSAPI_FS_Close(fd);
  189. MSG_INFO(1,"%s save done", PSN_FILE);
  190. }
  191. void readInfoNow(void){
  192. int fd;
  193. fd=LSAPI_FS_Open(PSN_FILE, LSAPI_FS_O_RDONLY,0);
  194. if(fd<0){
  195. MSG_ERR(1,"%s open read failed", PSN_FILE);
  196. return;
  197. }
  198. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  199. LSAPI_FS_Read(fd, (unsigned char *)&sutApp.UserInfo, sizeof(USER_STOR_INFO));
  200. LSAPI_FS_Close(fd);
  201. MSG_INFO(1, "%s get info:%s,%s",PSN_FILE, sutApp.UserInfo.OtherId, sutApp.UserInfo.OtherPassWord);
  202. }
  203. void setPocPara(char *pocPara, int len){
  204. int k;
  205. char buf[40];
  206. char buf1[100];
  207. char idFlag=0,domainFlag=0,ipFlag=0;
  208. char gapFlag=0,gportFlag=0;
  209. char enableChangeIp=1;
  210. //msgAtSend("AT+POC=0100007077643D3131313131313B00\r\n");
  211. if(0!=restoreDataFormatByHex(pocPara,len)){
  212. MSG_ERR(1, "setPocPara get error");
  213. return;
  214. }
  215. k=len/2;
  216. pocPara[k]=0;
  217. GetParaFromStr(pocPara, "id", buf);
  218. if(0!=strcmp(sutApp.UserInfo.OtherId, buf)) idFlag=1;
  219. if(idFlag==0 && ipFlag==0 && domainFlag==0 && gapFlag==0 && gportFlag==0){
  220. MSG_INFO(1, "POC still");
  221. sutApp.pocParaDone=1;
  222. return;
  223. }
  224. idFlag=1;
  225. if(idFlag!=0){
  226. snprintf(buf1, sizeof(buf1), "AT+POC=010000");
  227. snprintf(buf, sizeof(buf), "id=%s;pwd=%s",sutApp.UserInfo.OtherId,sutApp.UserInfo.OtherPassWord);
  228. AscStrTurnHexStr(buf, buf1+strlen(buf1));
  229. strcat(buf1, "00\r\n");
  230. msgAtSend(buf1);
  231. MSG_INFO(1, "POC reset");
  232. sutApp.pocParaDone=1;
  233. }
  234. return;
  235. msgAtSend("AT+POC=010000");
  236. MSG_INFO(1, "POC reset");
  237. sutApp.pocParaDone=1;
  238. }
  239. char showPIP[40];
  240. char showGIP[40];
  241. const char invalidIp[]="1.1.1.1";
  242. char *getPIPAddr(void){
  243. char *retAddr=NULL;
  244. switch(newPara.serList.defaultuse){
  245. case SERVER_HZ: retAddr=newPara.serList.zh.pip;break;
  246. case SERVER_SD: retAddr=newPara.serList.sd.pip;break;
  247. case SERVER_FENFA:retAddr=(char *)invalidIp;break;
  248. case SERVER_JIQUN:retAddr=(char *)invalidIp;break;
  249. case SERVER_UR: retAddr=newPara.serList.ur.pip;break;
  250. }
  251. memset(showPIP, 0, sizeof(showPIP));
  252. strcpy(showPIP, retAddr);
  253. return retAddr;
  254. }
  255. char *getGIPAddr(void){
  256. char *retAddr=NULL;
  257. switch(newPara.serList.defaultuse){
  258. case SERVER_HZ: retAddr=newPara.serList.zh.gip;break;
  259. case SERVER_SD: retAddr=newPara.serList.sd.gip;break;
  260. case SERVER_FENFA: break;
  261. case SERVER_JIQUN: break;
  262. case SERVER_UR: retAddr=newPara.serList.ur.gip;break;
  263. }
  264. if(retAddr==NULL) showGIP[0]=0;
  265. else strcpy(showGIP, retAddr);
  266. return retAddr;
  267. }
  268. char *getDOMAINAddr(void)
  269. {
  270. char *retAddr=NULL;
  271. switch(newPara.serList.defaultuse){
  272. case SERVER_HZ:break;
  273. case SERVER_SD:break;
  274. case SERVER_FENFA:retAddr=newPara.serList.ipFenFa;break;
  275. case SERVER_JIQUN:retAddr=newPara.serList.jiqun;break;
  276. case SERVER_UR:break;
  277. }
  278. return retAddr;
  279. }