setting.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. #include "includes.h"
  2. void saveInfoNow(USER_STOR_INFO *info);
  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.TbMode!=0){
  12. Ble_SendAT(msg,strlen(msg)-2);
  13. return;
  14. }
  15. if(sutApp.gtTMode!=0){
  16. msgAtSends(msg, strlen(msg));
  17. return;
  18. }
  19. //GT模式下指令处理
  20. if(msgCmp(msg, "GT+TM")){
  21. snprintf(info, sizeof(info), "TM Mode:OK\r\n");
  22. needFeedSms=1;
  23. sutApp.gtTMode=1;
  24. }else if(msgCmp(msg, "GT+TB")){
  25. sutApp.gtMode=1;
  26. }
  27. else if(msgCmp(msg, "GT+PWM=")){
  28. // if(msg[7]>='0' && msg[7]<='9') beepStart(atoi(msg+7));
  29. }else if(msgCmp(msg, "GT+RPID")){
  30. snprintf(info, sizeof(info), "GT+RPID:PSN=%lu;\r\n", sutApp.UserInfo.psn);
  31. needFeedSms=1;
  32. }else if(msgCmp(msg, "GT+SPID")){
  33. len=GetParaFromStr(msg, "PSN",buf);
  34. if(len<1 || len>10){
  35. snprintf(info, sizeof(info),"GT+SPID:FAIL[PSN Invalid]\r\n");
  36. needFeedSms=1;
  37. goto SETTING_END;
  38. }
  39. psn=atol(buf);
  40. snprintf(info, sizeof(info),"GT+SPID:PSN=%lu;\r\n",psn);
  41. needFeedSms=1;
  42. if(sutApp.UserInfo.psn != psn){
  43. sutApp.UserInfo.psn=psn;
  44. saveInfoNow(&sutApp.UserInfo);
  45. }
  46. }else if(msgCmp(msg, "GT+SNET")){ //GT+SNET:TNET=4;GT+SNET:TNET=5;
  47. len=GetParaFromStr(msg, "TNET", buf);
  48. if(len!=1){
  49. TNET_ERR:
  50. snprintf(info, sizeof(info),"GT+SNET:FAIL[PSN Invalid]\r\n");
  51. needFeedSms=1;
  52. goto SETTING_END;
  53. }
  54. psn=atoi(buf);
  55. if(psn!=4&&psn!=5) goto TNET_ERR;
  56. MSG_INFO(1,"psn=====%d",psn);
  57. if(psn!=sutApp.UserInfo.tnet){
  58. sutApp.UserInfo.tnet=psn;
  59. saveInfoNow(&sutApp.UserInfo);
  60. }
  61. snprintf(info,sizeof(info),"GT+SNET:TNET=%d\r\n",psn);
  62. needFeedSms=1;
  63. }else if(msgCmp(msg, "GT+RNET")){
  64. snprintf(info, sizeof(info),"GT+RNET:TNET=%d;\r\n",sutApp.UserInfo.tnet);
  65. needFeedSms=1;
  66. }else if(msgCmp(msg, "GT+SZZD")){
  67. len=GetParaFromStr(msg,"ID",buf);
  68. if(len<1 || len>15){
  69. snprintf(info, sizeof(info),"GT+SZZD:FAIL[ID Invalid]\r\n");
  70. needFeedSms=1;
  71. goto SETTING_END;
  72. }
  73. strcpy(sutApp.UserInfo.OtherId,buf);
  74. if(len<1 || len>19){
  75. snprintf(info, sizeof(info),"GT+SZZD:FAIL[PWD Invalid]\r\n");
  76. needFeedSms=1;
  77. goto SETTING_END;
  78. }
  79. len=GetParaFromStr(msg,"PWD",buf);
  80. strcpy(sutApp.UserInfo.OtherPassWord,buf);
  81. snprintf(info, sizeof(info),"GT+SZZD:ID=%s;PWD=%s;\r\n",sutApp.UserInfo.OtherId,sutApp.UserInfo.OtherPassWord);
  82. needFeedSms=1;
  83. saveInfoNow(&sutApp.UserInfo);
  84. }
  85. else if(msgCmp(msg, "GT+RZZD")){
  86. snprintf(info, sizeof(info),"GT+RZZD:Id=%s;Pwd=%s;\r\n",sutApp.UserInfo.OtherId,sutApp.UserInfo.OtherPassWord);
  87. needFeedSms=1;
  88. goto SETTING_END;
  89. }
  90. SETTING_END:
  91. if(needSendAt!=0) msgAtSends(info, strlen(info));
  92. if(needFeedSms!=0) usbOutPut(info, strlen(info));
  93. if(needSaveSys!=0){
  94. snprintf(info, sizeof(info), "cmd:%d",needSaveSys);
  95. sysIniSave(info);
  96. }
  97. }
  98. //sysini文件处理
  99. #define SYSINI_FILE "/ext/prepack/sys.ini"
  100. SYSINI_HS191X_DEF newPara;
  101. char menu_key[6]="502800";//如果资源文件中没有定义服务器菜单密码,则默认使用此密码
  102. char *getMenuKey(void){return menu_key;}
  103. static void ttsToBEStr(char *tts, int len){
  104. int i;
  105. char tmp[2];
  106. if(len % 4) return;
  107. for(i=0;i<len/4;i++){
  108. tmp[0]=tts[4*i];tmp[1]=tts[4*i+1];
  109. tts[4*i]=tts[4*i+2];
  110. tts[4*i+1]=tts[4*i+3];
  111. tts[4*i+2]=tmp[0];
  112. tts[4*i+3]=tmp[1];
  113. }
  114. }
  115. void sysIniSave(char *reason){
  116. int fd;
  117. MSG_INFO(1,"%s save start",SYSINI_FILE);
  118. fd=LSAPI_FS_Open(SYSINI_FILE, LSAPI_FS_O_RDWR,0x0);
  119. if(fd<0){
  120. MSG_ERR(1,"%s open failed",SYSINI_FILE);
  121. return;
  122. }
  123. //保存
  124. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  125. LSAPI_FS_Write(fd, (unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF));
  126. //nwy_sdk_fsync(fd);
  127. LSAPI_FS_Close(fd);
  128. MSG_INFO(1,"%s save done", SYSINI_FILE);
  129. #ifdef ENABLE_DEBUG
  130. takeNoteFile(reason);
  131. #endif
  132. }
  133. void setFactoryParam(void);
  134. void sysIniRead(void){
  135. int fd;
  136. char needsave=0;
  137. fd=LSAPI_FS_Open(SYSINI_FILE, LSAPI_FS_O_RDWR,0);
  138. if(fd<0){
  139. MSG_ERR(1,"%s open read failed", SYSINI_FILE);
  140. return;
  141. }
  142. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  143. LSAPI_FS_Read(fd, (unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF));
  144. if(newPara.ConfigFlag==0){
  145. MSG_INFO(1, "First run");
  146. newPara.itemShowType=0;
  147. newPara.ConfigFlag=1;
  148. newPara.lockType=0;//锁正面
  149. needsave=1;
  150. //检测TTS是否是UNICODE,是则将其从BE转换为LE,后面就可以直接播放了
  151. if(newPara.ttsMessage[0]!=0 && newPara.ttsCodeType==0) ttsToBEStr(newPara.ttsMessage, strlen(newPara.ttsMessage));
  152. newPara.spkVol=7;
  153. newPara.micGain=MIC_GAIN_DEFAULT;
  154. newPara.spkGain=SPK_GAIN_DEFAULT;
  155. //lc
  156. newPara.sidekey02_func=1;
  157. newPara.Xinbiao_LiveUpdate=1;
  158. newPara.Xinbiao_station=1;
  159. newPara.Xinbiao_IpEnable=1;
  160. newPara.BleEnable=1;
  161. newPara.BleSpkLv=8;
  162. newPara.BleMicLv=9;
  163. #ifndef DEVELOP_MODE
  164. setFactoryParam();
  165. #endif
  166. }
  167. if(newPara.serverMenuPass!=NULL) memcpy(menu_key, newPara.serverMenuPass,6);
  168. if(newPara.spkVol>MAX_SPK_VOL){
  169. newPara.spkVol=7;
  170. needsave=1;
  171. }
  172. if(newPara.gpsEnable!=0){//GPS使能,必需打开布标
  173. MSG_WARN(1, "gpsEnable, force bubiaoEnable");
  174. newPara.bubiaoEnable=1;
  175. needsave=1;
  176. }
  177. if(needsave!=0){
  178. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  179. LSAPI_FS_Write(fd, (unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF));
  180. //nwy_sdk_fsync(fd);
  181. }
  182. LSAPI_FS_Close(fd);
  183. }
  184. //保存PSN文件处理
  185. #define PSN_FILE "m5700_f2"
  186. void saveInfoNow(USER_STOR_INFO *info){
  187. int fd;
  188. MSG_INFO(1,"%s save start:",PSN_FILE);
  189. fd=LSAPI_FS_Open(PSN_FILE, LSAPI_FS_O_RDWR |LSAPI_FS_O_CREAT,0x0);
  190. if(fd<0){
  191. MSG_ERR(1,"%s open failed",PSN_FILE);
  192. return;
  193. }
  194. if(info->tnet!=4&&info->tnet!=5){
  195. info->tnet=4;
  196. }
  197. //淇濆瓨
  198. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  199. LSAPI_FS_Write(fd, (unsigned char *)&sutApp.UserInfo, sizeof(USER_STOR_INFO));
  200. //nwy_sdk_fsync(fd);
  201. LSAPI_FS_Close(fd);
  202. MSG_INFO(1,"%s save done", PSN_FILE);
  203. }
  204. void readInfoNow(void){
  205. int fd;
  206. fd=LSAPI_FS_Open(PSN_FILE, LSAPI_FS_O_RDONLY,0);
  207. if(fd<0){
  208. MSG_ERR(1,"%s open read failed", PSN_FILE);
  209. return;
  210. }
  211. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  212. LSAPI_FS_Read(fd, (unsigned char *)&sutApp.UserInfo, sizeof(USER_STOR_INFO));
  213. LSAPI_FS_Close(fd);
  214. MSG_INFO(1, "%s get info:%s,%s",PSN_FILE, sutApp.UserInfo.OtherId, sutApp.UserInfo.OtherPassWord);
  215. }
  216. void setFactoryParam(void){
  217. sutApp.UserInfo.psn=newPara.defaultPsn;
  218. saveInfoNow(&sutApp.UserInfo);
  219. MSG_INFO(1, "set factory psn:%d", sutApp.UserInfo.psn);
  220. }
  221. void setPocPara(char *pocPara, int len){
  222. int k;
  223. char buf[40];
  224. char buf1[100];
  225. char idFlag=0,domainFlag=0,ipFlag=0;
  226. char gapFlag=0,gportFlag=0;
  227. char enableChangeIp=1;
  228. char tmpdata[100];
  229. sutApp.pocParaDone=1;
  230. return; //直接返回不处理
  231. }
  232. //CY 登录很快直接设置参数
  233. void ModemSetZZDPocPara()
  234. {
  235. char buf[40];
  236. char buf1[100];
  237. msgAtSend("AT+POC=010000");
  238. snprintf(buf, sizeof(buf),"ip=%s;",ZZD_IP);
  239. AscStrTurnHexStr(buf,buf1);
  240. ModemSendAt(buf1);
  241. MSG_INFO(1,buf1 );
  242. snprintf(buf, sizeof(buf),"id=%s;",sutApp.UserInfo.OtherId);
  243. AscStrTurnHexStr(buf,buf1);
  244. ModemSendAt(buf1);
  245. MSG_INFO(1,buf1 );
  246. snprintf(buf, sizeof(buf),"pwd=%s;",sutApp.UserInfo.OtherPassWord);
  247. AscStrTurnHexStr(buf,buf1);
  248. ModemSendAt(buf1);
  249. ModemSendAt("\r\n");
  250. MSG_INFO(1,buf1 );
  251. //ModemSendAt("AT+POC=000000010100\r\n");
  252. MSG_INFO(1,"Set-ZZDpara--");
  253. }
  254. char showPIP[40];
  255. char showGIP[40];
  256. const char invalidIp[]="1.1.1.1";
  257. char *getPIPAddr(void){
  258. char *retAddr=NULL;
  259. switch(newPara.serList.defaultuse){
  260. case SERVER_HZ: retAddr=newPara.serList.zh.pip;break;
  261. case SERVER_SD: retAddr=newPara.serList.sd.pip;break;
  262. case SERVER_FENFA:retAddr=(char *)invalidIp;break;
  263. case SERVER_JIQUN:retAddr=(char *)invalidIp;break;
  264. case SERVER_UR: retAddr=newPara.serList.ur.pip;break;
  265. }
  266. memset(showPIP, 0, sizeof(showPIP));
  267. strcpy(showPIP, retAddr);
  268. return retAddr;
  269. }
  270. char *getGIPAddr(void){
  271. char *retAddr=NULL;
  272. switch(newPara.serList.defaultuse){
  273. case SERVER_HZ: retAddr=newPara.serList.zh.gip;break;
  274. case SERVER_SD: retAddr=newPara.serList.sd.gip;break;
  275. case SERVER_FENFA: break;
  276. case SERVER_JIQUN: break;
  277. case SERVER_UR: retAddr=newPara.serList.ur.gip;break;
  278. }
  279. if(retAddr==NULL) showGIP[0]=0;
  280. else strcpy(showGIP, retAddr);
  281. return retAddr;
  282. }
  283. char *getDOMAINAddr(void)
  284. {
  285. char *retAddr=NULL;
  286. switch(newPara.serList.defaultuse){
  287. case SERVER_HZ:break;
  288. case SERVER_SD:break;
  289. case SERVER_FENFA:retAddr=newPara.serList.ipFenFa;break;
  290. case SERVER_JIQUN:retAddr=newPara.serList.jiqun;break;
  291. case SERVER_UR:break;
  292. }
  293. return retAddr;
  294. }