sysIni.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #include "includes.h"
  2. const char invalidIp[]="1.1.1.1";
  3. SYSINI_HS191X_DEF newPara;
  4. unsigned char UniToGBKIndex;
  5. char menu_key[6]="502800";//如果资源文件没有定义密码,则默认密码为此
  6. int newSysiniIndex=-1;
  7. void testing(void);
  8. void ShowDetail(void);
  9. void newSysIniRead(void)
  10. {
  11. int len;
  12. char needsave=0;
  13. newSysiniIndex=GetFileIndex(SYS_CONFIG);
  14. if(newSysiniIndex<0){
  15. printf("%s not found\r\n",SYS_CONFIG);
  16. return;
  17. }
  18. len=GetFileLen(newSysiniIndex);
  19. if(len<sizeof(SYSINI_HS191X_DEF)){
  20. printf("%s SYS_CONFIG len err\r\n",SYS_CONFIG);
  21. printf("len is %d\r\n",sizeof(SYSINI_HS191X_DEF));
  22. return;
  23. }
  24. ReadFileData(newSysiniIndex, 0, sizeof(SYSINI_HS191X_DEF), (unsigned char *)&newPara);
  25. #if 1
  26. //ShowDetail();
  27. validApnNum = 4;
  28. //要对应有有参数的合法性作判断
  29. if(newPara.serList.defaultuse>SER_US){
  30. newPara.serList.defaultuse=SER_HZ;
  31. needsave=1;
  32. }
  33. if(newPara.apnList.defaultuse>APN_APN4){
  34. newPara.apnList.defaultuse=APN_APN1;
  35. needsave=1;
  36. }
  37. if(newPara.lcdParaDefaultIndex>=5){
  38. newPara.lcdParaDefaultIndex=0;
  39. needsave=1;
  40. }
  41. if(newPara.gpsTimeIndex>=GPS_TABLE_NUM){
  42. newPara.gpsTimeIndex=0;
  43. needsave=1;
  44. }
  45. if(newPara.pwrMode>=PWR_MODE_NUM){
  46. newPara.pwrMode=0;
  47. needsave=1;
  48. }
  49. if(newPara.PF1Status>1){
  50. newPara.PF1Status=0;
  51. needsave=1;
  52. }
  53. if(newPara.ConfigFlag==0){//程序更新过了
  54. // sutGpsCtl.reTryAuthTimes=1;
  55. // sutGpsCtl.reTryPerSeconds=1;
  56. newPara.ConfigFlag=1;
  57. newPara.netMode=4;//强制默认为4G
  58. needsave=1;
  59. }else{
  60. // sutGpsCtl.reTryAuthTimes=3;
  61. // sutGpsCtl.reTryPerSeconds=15;
  62. }
  63. getGIPAddr();
  64. getPIPAddr();
  65. if(newPara.serverMenuPass!=NULL) memcpy(menu_key, newPara.serverMenuPass,6);
  66. if(needsave != 0) ModifyConfigureFile(0);
  67. #else
  68. testing();
  69. #endif
  70. }
  71. void ShowDetail(void)
  72. {
  73. char buf[30];
  74. int len;
  75. int i;
  76. printf("Len=%d,%d\r\n",len,sizeof(SYSINI_HS191X_DEF));
  77. printf("CFlag:%d,Mode:%d,ttsType:%d,ttsMess:%s\r\n",newPara.ConfigFlag,newPara.Mode,newPara.ttsCodeType,newPara.ttsMessage);
  78. memcpy(buf, newPara.serverMenuPass,6);buf[6]=0;
  79. printf("pass:%s,SmsFlag=%c,SmdAddr:%x,lcd:%d,%d,%d,%d,%d,useLcd=%d,auth:%d\r\n", buf, newPara.messageResetFlag,newPara.messageNewAddr,newPara.lcdParaList[0],newPara.lcdParaList[1],newPara.lcdParaList[2],newPara.lcdParaList[3],newPara.lcdParaList[4],newPara.lcdParaDefaultIndex,newPara.authType);
  80. printf("zh pip:%s,gip:%s\r\n", newPara.serList.zh.pip, newPara.serList.zh.gip);
  81. printf("sd pip:%s,gip:%s\r\n", newPara.serList.sd.pip, newPara.serList.sd.gip);
  82. printf("ur pip:%s,gip:%s\r\n", newPara.serList.ur.pip, newPara.serList.ur.gip);
  83. printf("ipfa:%s\r\n", newPara.serList.ipFenFa);
  84. printf("jiqun:%s\r\n", newPara.serList.jiqun);
  85. printf("server use:%d\r\n", newPara.serList.defaultuse);
  86. for(i=0;i<4;i++){
  87. printf("APN%d acc:%s, pass:%s\r\n", i,newPara.apnList.apnList[i].account, newPara.apnList.apnList[i].pass);
  88. }
  89. printf("APN def=%d, showflag=%d\r\n", newPara.apnList.defaultuse, newPara.apnList.apnShowFlag);
  90. printf("netMode:%d\r\n",newPara.netMode);
  91. }
  92. void tryToModifyData(void)
  93. {
  94. #if 1
  95. // newPara.lcdParaList[0]=77;
  96. // newPara.lcdParaList[1]=88;
  97. // newPara.lcdParaList[2]=99;
  98. // ModifyConfigureFile();
  99. SUT_FILE_PAGE_HEAD pageinfo;
  100. pageinfo.mark=FILE_HEAD_END;
  101. sFlash_Write((unsigned char *)&pageinfo, g_sutFilesList.FileInfo[g_sutFilesList.FileCount-1].FileAddr, sizeof(SUT_FILE_PAGE_HEAD));
  102. #endif
  103. }
  104. void testing(void)
  105. {
  106. #if 0
  107. ShowDetail();
  108. //tryToModifyData();
  109. while(1){
  110. IWDG_ReloadCounter();
  111. DelayMs(500);
  112. printf("tick\r\n");
  113. }
  114. #endif
  115. }
  116. char *getPIPAddr(void)
  117. {
  118. char *retAddr=NULL;
  119. switch(newPara.serList.defaultuse){
  120. case SER_HZ:retAddr=newPara.serList.zh.pip;break;
  121. case SER_SD:retAddr=newPara.serList.sd.pip;break;
  122. case SER_IP:retAddr=(char *)invalidIp;break;
  123. case SER_JIQUN:retAddr=(char *)invalidIp;break;
  124. case SER_US:retAddr=newPara.serList.ur.pip;break;
  125. }
  126. memset(showPIP, 0,sizeof(showPIP));
  127. strcpy(showPIP, retAddr);
  128. return retAddr;
  129. }
  130. char buBiaoAddrChange=0;
  131. char *getGIPAddr(void)
  132. {
  133. char *retAddr=NULL;
  134. switch(newPara.serList.defaultuse){
  135. case SER_HZ:retAddr=newPara.serList.zh.gip;break;
  136. case SER_SD:retAddr=newPara.serList.sd.gip;break;
  137. case SER_IP:break; //IP分发和集群情况时,GPS地址使用集群或IP分发解析后输出的,这里直接返回NULL
  138. case SER_JIQUN:break;//IP分发和集群情况时,GPS地址使用集群或IP分发解析后输出的,这里直接返回NULL
  139. case SER_US:retAddr=newPara.serList.ur.gip;break;
  140. }
  141. if(retAddr==NULL) showGIP[0]=0;
  142. else strcpy(showGIP, retAddr);
  143. buBiaoAddrChange=1;
  144. return retAddr;
  145. }
  146. char *getDOMAINAddr(void)
  147. {
  148. char *retAddr=NULL;
  149. switch(newPara.serList.defaultuse){
  150. case SER_HZ:break;
  151. case SER_SD:break;
  152. case SER_IP:retAddr=newPara.serList.ipFenFa;break;
  153. case SER_JIQUN:retAddr=newPara.serList.jiqun;break;
  154. case SER_US:break;
  155. }
  156. return retAddr;
  157. }