setting(2122).c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. #include "includes.h"
  2. static void savePsnNow(ACCOUNT_DEF account);
  3. void cmdSetting(char *msg){
  4. char info[100],buf[50],ipAddr[40];
  5. char needSendAt=0;
  6. char needFeedSms=0;
  7. char needSaveSys=0;
  8. int len,port;
  9. unsigned long psn;
  10. if(sutApp.gtMode==0) return;
  11. if(sutApp.gtTMode!=0){
  12. msgAtSends(msg, strlen(msg));
  13. return;
  14. }
  15. //GT模式下指令处理
  16. if(msgCmp(msg, "GT+SMP")){
  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. len=GetParaFromStr(msg, "Port", buf);
  25. if(len==0) port=0;
  26. else if(len>5){
  27. snprintf(info,sizeof(info),"GT+SMP:FAIL[Port Invalid]");
  28. needFeedSms=1;
  29. goto SETTING_END;
  30. }
  31. 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. psn=atol(buf);
  39. snprintf(info, sizeof(info),"GT+SMP:IP=%s;Port=%u;PSN=%lu;\r\n",ipAddr,port,psn);
  40. needFeedSms=1;
  41. //保存PSN
  42. if(sutApp.account.psn != psn){
  43. sutApp.account.psn=psn;
  44. saveInfoNow(sutApp.account);
  45. }
  46. //保存IP到sys.ini中的用户定义段
  47. if(strcmp(newPara.serList.ur.pip,ipAddr) || newPara.serList.defaultuse!=SERVER_UR){
  48. //不相等
  49. newPara.serList.defaultuse=SERVER_UR;
  50. strcpy(newPara.serList.ur.pip, ipAddr);
  51. sysIniSave();
  52. }
  53. }else if(msgCmp(msg, "GT+RMP")){
  54. snprintf(info, sizeof(info),"GT+RMP:PSN=%lu;MEID=%s;CNUM=0000000000;UIMID=0000000000;IP=%s;\r\n",sutApp.account.psn,ohpocGetIMEI(),getPIPAddr());
  55. needFeedSms=1;
  56. }else if(msgCmp(msg, "GT+TM")){
  57. snprintf(info, sizeof(info), "TM Mode:OK\r\n");
  58. needFeedSms=1;
  59. sutApp.gtTMode=1;
  60. }else if(msgCmp(msg, "GT+PWM=")){
  61. // if(msg[7]>='0' && msg[7]<='9') beepStart(atoi(msg+7));
  62. }else if(msgCmp(msg, "GT+RPID")){
  63. snprintf(info, sizeof(info), "GT+RPID:PSN=%lu;\r\n", sutApp.account.psn);
  64. needFeedSms=1;
  65. }else if(msgCmp(msg, "GT+SPID")){
  66. len=GetParaFromStr(msg, "PSN",buf);
  67. if(len<1 || len>10){
  68. snprintf(info, sizeof(info),"GT+SPID:FAIL[PSN Invalid]\r\n");
  69. needFeedSms=1;
  70. goto SETTING_END;
  71. }
  72. psn=atol(buf);
  73. snprintf(info, sizeof(info),"GT+SPID:PSN=%lu;\r\n",psn);
  74. needFeedSms=1;
  75. if(sutApp.account.psn != psn){
  76. sutApp.account.psn=psn;
  77. saveInfoNow(sutApp.account);
  78. }
  79. }else if(msgCmp(msg, "GT+RDOMAIN")){
  80. snprintf(info,sizeof(info),"GT+RDOMAIN:%s;PSN=%lu;\r\n",newPara.serList.ipFenFa,sutApp.account.psn);
  81. needFeedSms=1;
  82. }else if(msgCmp(msg, "GT+SDOMAIN")){
  83. len=GetParaFromStr(msg, "PSN",buf);
  84. if(len<1 || len>10){
  85. snprintf(info, sizeof(info),"GT+SDOMAIN:FAIL[PSN Invalid]\r\n");
  86. needFeedSms=1;
  87. goto SETTING_END;
  88. }
  89. psn=atol(buf);
  90. len=GetParaFromStr(msg, "SDOMAIN",buf);
  91. if(len>40){
  92. snprintf(info, sizeof(info),"GT+SDOMAIN:FAIL[DOMAIN Invalid]\r\n");
  93. needFeedSms=1;
  94. goto SETTING_END;
  95. }
  96. if(newPara.serList.defaultuse != SERVER_FENFA){
  97. newPara.serList.defaultuse=SERVER_FENFA;
  98. needSaveSys=1;
  99. }
  100. if(0!=strcmp(newPara.serList.ipFenFa, buf)){
  101. memset(newPara.serList.ipFenFa,0,sizeof(newPara.serList.ipFenFa));
  102. snprintf(newPara.serList.ipFenFa,sizeof(newPara.serList.ipFenFa),"%s",buf);
  103. needSaveSys=1;
  104. }
  105. if(sutApp.account.psn != psn){
  106. sutApp.account.psn=psn;
  107. saveInfoNow(sutApp.account);
  108. }
  109. snprintf(info, sizeof(info),"GT+SDOMAIN=%s;PSN=%lu;\r\n",newPara.serList.ipFenFa,psn);
  110. needFeedSms=1;
  111. }else if(msgCmp(msg, "GT+SNET")){//GT+SNET:TNET=4;GT+SNET:TNET=5;
  112. len=GetParaFromStr(msg, "TNET",buf);
  113. if(len!=1){
  114. TNET_ERR:
  115. snprintf(info, sizeof(info),"GT+SNET:FAIL[TNET Invalid]\r\n");
  116. needFeedSms=1;
  117. goto SETTING_END;
  118. }
  119. psn=atol(buf);
  120. if(psn !=4 && psn != 5) goto TNET_ERR;
  121. if(psn != sutApp.account.tnet){
  122. sutApp.account.tnet=psn;
  123. saveInfoNow(sutApp.account);
  124. }
  125. snprintf(info, sizeof(info),"GT+SNET:TNET=%d\r\n",psn);
  126. needFeedSms=1;
  127. }else if(msgCmp(msg, "GT+RNET")){
  128. snprintf(info,sizeof(info),"GT+RNET:TNET=%d;\r\n",sutApp.account.tnet);
  129. needFeedSms=1;
  130. }else if(msgCmp(msg, "GT+RPOS")){
  131. snprintf(info, sizeof(info),"GT+RPOS:VALUE=%d;\r\n", newPara.itemShowType);
  132. needFeedSms=1;
  133. }else if(msgCmp(msg, "GT+SPOS")){//GT+SPOS:VALUE=0;
  134. len=GetParaFromStr(msg, "VALUE",buf);
  135. if(len!=1){
  136. SPOS_ERR:
  137. snprintf(info, sizeof(info),"GT+SPOS:FAIL[VALUE Invalid]\r\n");
  138. needFeedSms=1;
  139. goto SETTING_END;
  140. }
  141. psn=atol(buf);
  142. if(psn != 0 && psn != 1) goto SPOS_ERR;
  143. if(psn != newPara.itemShowType){
  144. newPara.itemShowType=psn;
  145. needSaveSys=1;
  146. }
  147. snprintf(info, sizeof(info),"GT+SPOS:VALUE=%d;\r\n",psn);
  148. needFeedSms=1;
  149. }
  150. SETTING_END:
  151. if(needSendAt!=0) msgAtSends(info, strlen(info));
  152. if(needFeedSms!=0) usbOutPut(info, strlen(info));
  153. if(needSaveSys!=0) sysIniSave();
  154. }
  155. //sysini文件处理
  156. #define SYSINI_FILE "sys.ini"
  157. SYSINI_HS191X_DEF newPara;
  158. char menu_key[6]="502800";//如果资源文件中没有定义服务器菜单密码,则默认使用此密码
  159. char *getMenuKey(void){return menu_key;}
  160. static void ttsToBEStr(char *tts, int len){
  161. int i;
  162. char tmp[2];
  163. if(len % 4) return;
  164. for(i=0;i<len/4;i++){
  165. tmp[0]=tts[4*i];tmp[1]=tts[4*i+1];
  166. tts[4*i]=tts[4*i+2];
  167. tts[4*i+1]=tts[4*i+3];
  168. tts[4*i+2]=tmp[0];
  169. tts[4*i+3]=tmp[1];
  170. }
  171. }
  172. void sysIniSave(void){
  173. int fd;
  174. MSG_INFO(1,"%s save start",SYSINI_FILE);
  175. fd=LSAPI_FS_Open(SYSINI_FILE, LSAPI_FS_O_RDWR,0x0);
  176. if(fd<0){
  177. MSG_ERR(1,"%s open failed",SYSINI_FILE);
  178. return;
  179. }
  180. //保存
  181. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  182. LSAPI_FS_Write(fd, (unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF));
  183. //nwy_sdk_fsync(fd);
  184. LSAPI_FS_Close(fd);
  185. MSG_INFO(1,"%s save done", SYSINI_FILE);
  186. }
  187. void setFactoryParam(void);
  188. void sysIniRead(void){
  189. int fd;
  190. char needsave=0;
  191. fd=LSAPI_FS_Open(SYSINI_FILE, LSAPI_FS_O_RDWR,0);
  192. if(fd<0){
  193. MSG_ERR(1,"%s open read failed", SYSINI_FILE);
  194. return;
  195. }
  196. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  197. LSAPI_FS_Read(fd, (unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF));
  198. if(newPara.ConfigFlag==0){
  199. MSG_INFO(1, "First run");
  200. newPara.itemShowType=0;
  201. newPara.ConfigFlag=1;
  202. newPara.lockType=0;//锁正面
  203. needsave=1;
  204. //检测TTS是否是UNICODE,是则将其从BE转换为LE,后面就可以直接播放了
  205. if(newPara.ttsMessage[0]!=0 && newPara.ttsCodeType==0) ttsToBEStr(newPara.ttsMessage, strlen(newPara.ttsMessage));
  206. newPara.spkVol=6;
  207. newPara.micGain=MIC_GAIN_DEFAULT;
  208. newPara.spkGain=SPK_GAIN_DEFAULT;
  209. #ifndef DEVELOP_MODE
  210. setFactoryParam();
  211. #endif
  212. }
  213. if(newPara.serverMenuPass!=NULL) memcpy(menu_key, newPara.serverMenuPass,6);
  214. //测试开始
  215. //newPara.gpsEnable=0;
  216. //newPara.bubiaoEnable=0;
  217. //newPara.KeySound=1;
  218. //测试结束
  219. if(newPara.spkVol>MAX_SPK_VOL){
  220. newPara.spkVol=6;
  221. needsave=1;
  222. }
  223. if(newPara.gpsEnable!=0){//GPS使能,必需打开布标
  224. MSG_WARN(1, "gpsEnable, force bubiaoEnable");
  225. newPara.bubiaoEnable=1;
  226. needsave=1;
  227. }
  228. if(needsave!=0){
  229. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  230. LSAPI_FS_Write(fd, (unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF));
  231. //nwy_sdk_fsync(fd);
  232. }
  233. LSAPI_FS_Close(fd);
  234. }
  235. //保存PSN文件处理
  236. #define PSN_FILE "m5700_f2"
  237. void saveInfoNow(ACCOUNT_DEF account){
  238. int fd;
  239. MSG_INFO(1,"%s save start:%d,%s",PSN_FILE, account.psn,account.password);
  240. fd=LSAPI_FS_Open(PSN_FILE, LSAPI_FS_O_RDWR |LSAPI_FS_O_CREAT,0x0);
  241. if(fd<0){
  242. MSG_ERR(1,"%s open failed",PSN_FILE);
  243. return;
  244. }
  245. //保存
  246. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  247. LSAPI_FS_Write(fd, (unsigned char *)&account, sizeof(ACCOUNT_DEF));
  248. //nwy_sdk_fsync(fd);
  249. LSAPI_FS_Close(fd);
  250. MSG_INFO(1,"%s save done", PSN_FILE);
  251. }
  252. void readInfoNow(void){
  253. int fd;
  254. fd=LSAPI_FS_Open(PSN_FILE, LSAPI_FS_O_RDONLY,0);
  255. if(fd<0){
  256. MSG_ERR(1,"%s open read failed", PSN_FILE);
  257. return;
  258. }
  259. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  260. LSAPI_FS_Read(fd, (unsigned char *)&sutApp.account, sizeof(ACCOUNT_DEF));
  261. if(sutApp.account.tnet != 4 && sutApp.account.tnet != 5){
  262. sutApp.account.tnet = 4;
  263. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  264. LSAPI_FS_Write(fd, (unsigned char *)&sutApp, sizeof(ACCOUNT_DEF));
  265. }
  266. LSAPI_FS_Close(fd);
  267. MSG_INFO(1, "%s get info:%d,%s",PSN_FILE, sutApp.account.psn, sutApp.account.password);
  268. }
  269. void setFactoryParam(void){
  270. sutApp.account.psn=newPara.defaultPsn;
  271. saveInfoNow(sutApp.account);
  272. MSG_INFO(1, "set factory psn:%d", sutApp.account.psn);
  273. }
  274. void setPocPara(){
  275. unsigned char Databuf[120]={0};
  276. unsigned char len;
  277. char *Addr="0.0.0.0";
  278. snprintf(&Databuf[16], sizeof(Databuf)-16, "addr:%s&user:GPS001&pass:123456", Addr);
  279. len=strlen(Databuf+16);
  280. snprintf(Databuf, sizeof(Databuf), "AT+POC=setinfo%02x%s",len, Databuf+16);
  281. msgAtSend(Databuf);
  282. MSG_INFO(1,Databuf);
  283. }
  284. char showPIP[40];
  285. char showGIP[40];
  286. const char invalidIp[]="1.1.1.1";
  287. char *getPIPAddr(void){
  288. char *retAddr=NULL;
  289. switch(newPara.serList.defaultuse){
  290. case SERVER_HZ: retAddr=newPara.serList.zh.pip;break;
  291. case SERVER_SD: retAddr=newPara.serList.sd.pip;break;
  292. case SERVER_FENFA:retAddr=(char *)invalidIp;break;
  293. case SERVER_JIQUN:retAddr=(char *)invalidIp;break;
  294. case SERVER_UR: retAddr=newPara.serList.ur.pip;break;
  295. }
  296. memset(showPIP, 0, sizeof(showPIP));
  297. strcpy(showPIP, retAddr);
  298. return retAddr;
  299. }
  300. char *getGIPAddr(void){
  301. char *retAddr=NULL;
  302. switch(newPara.serList.defaultuse){
  303. case SERVER_HZ: retAddr=newPara.serList.zh.gip;break;
  304. case SERVER_SD: retAddr=newPara.serList.sd.gip;break;
  305. case SERVER_FENFA: break;
  306. case SERVER_JIQUN: break;
  307. case SERVER_UR: retAddr=newPara.serList.ur.gip;break;
  308. }
  309. if(retAddr==NULL) showGIP[0]=0;
  310. else strcpy(showGIP, retAddr);
  311. return retAddr;
  312. }
  313. char *getDOMAINAddr(void)
  314. {
  315. char *retAddr=NULL;
  316. switch(newPara.serList.defaultuse){
  317. case SERVER_HZ:break;
  318. case SERVER_SD:break;
  319. case SERVER_FENFA:retAddr=newPara.serList.ipFenFa;break;
  320. case SERVER_JIQUN:retAddr=newPara.serList.jiqun;break;
  321. case SERVER_UR:break;
  322. }
  323. return retAddr;
  324. }