sysIni.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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.ConfigFlag==0){//程序更新过了
  50. // sutGpsCtl.reTryAuthTimes=1;
  51. // sutGpsCtl.reTryPerSeconds=1;
  52. newPara.ConfigFlag=1;
  53. newPara.netMode=4;//强制默认为4G
  54. needsave=1;
  55. }else{
  56. // sutGpsCtl.reTryAuthTimes=3;
  57. // sutGpsCtl.reTryPerSeconds=15;
  58. }
  59. getGIPAddr();
  60. getPIPAddr();
  61. if(newPara.serverMenuPass!=NULL) memcpy(menu_key, newPara.serverMenuPass,6);
  62. if(needsave != 0) ModifyConfigureFile(0);
  63. #else
  64. testing();
  65. #endif
  66. }
  67. void ShowDetail(void)
  68. {
  69. char buf[30];
  70. int len;
  71. int i;
  72. printf("Len=%d,%d\r\n",len,sizeof(SYSINI_HS191X_DEF));
  73. printf("CFlag:%d,Mode:%d,ttsType:%d,ttsMess:%s\r\n",newPara.ConfigFlag,newPara.Mode,newPara.ttsCodeType,newPara.ttsMessage);
  74. memcpy(buf, newPara.serverMenuPass,6);buf[6]=0;
  75. 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);
  76. printf("zh pip:%s,gip:%s\r\n", newPara.serList.zh.pip, newPara.serList.zh.gip);
  77. printf("sd pip:%s,gip:%s\r\n", newPara.serList.sd.pip, newPara.serList.sd.gip);
  78. printf("ur pip:%s,gip:%s\r\n", newPara.serList.ur.pip, newPara.serList.ur.gip);
  79. printf("ipfa:%s\r\n", newPara.serList.ipFenFa);
  80. printf("jiqun:%s\r\n", newPara.serList.jiqun);
  81. printf("server use:%d\r\n", newPara.serList.defaultuse);
  82. for(i=0;i<4;i++){
  83. printf("APN%d acc:%s, pass:%s\r\n", i,newPara.apnList.apnList[i].account, newPara.apnList.apnList[i].pass);
  84. }
  85. printf("APN def=%d, showflag=%d\r\n", newPara.apnList.defaultuse, newPara.apnList.apnShowFlag);
  86. printf("netMode:%d\r\n",newPara.netMode);
  87. }
  88. void tryToModifyData(void)
  89. {
  90. #if 1
  91. // newPara.lcdParaList[0]=77;
  92. // newPara.lcdParaList[1]=88;
  93. // newPara.lcdParaList[2]=99;
  94. // ModifyConfigureFile();
  95. SUT_FILE_PAGE_HEAD pageinfo;
  96. pageinfo.mark=FILE_HEAD_END;
  97. sFlash_Write((unsigned char *)&pageinfo, g_sutFilesList.FileInfo[g_sutFilesList.FileCount-1].FileAddr, sizeof(SUT_FILE_PAGE_HEAD));
  98. #endif
  99. }
  100. void testing(void)
  101. {
  102. #if 0
  103. ShowDetail();
  104. //tryToModifyData();
  105. while(1){
  106. IWDG_ReloadCounter();
  107. DelayMs(500);
  108. printf("tick\r\n");
  109. }
  110. #endif
  111. }
  112. char *getPIPAddr(void)
  113. {
  114. char *retAddr=NULL;
  115. switch(newPara.serList.defaultuse){
  116. case SER_HZ:retAddr=newPara.serList.zh.pip;break;
  117. case SER_SD:retAddr=newPara.serList.sd.pip;break;
  118. case SER_IP:retAddr=(char *)invalidIp;break;
  119. case SER_JIQUN:retAddr=(char *)invalidIp;break;
  120. case SER_US:retAddr=newPara.serList.ur.pip;break;
  121. }
  122. memset(showPIP, 0,sizeof(showPIP));
  123. strcpy(showPIP, retAddr);
  124. return retAddr;
  125. }
  126. char buBiaoAddrChange=0;
  127. char *getGIPAddr(void)
  128. {
  129. char *retAddr=NULL;
  130. switch(newPara.serList.defaultuse){
  131. case SER_HZ:retAddr=newPara.serList.zh.gip;break;
  132. case SER_SD:retAddr=newPara.serList.sd.gip;break;
  133. case SER_IP:break; //IP分发和集群情况时,GPS地址使用集群或IP分发解析后输出的,这里直接返回NULL
  134. case SER_JIQUN:break;//IP分发和集群情况时,GPS地址使用集群或IP分发解析后输出的,这里直接返回NULL
  135. case SER_US:retAddr=newPara.serList.ur.gip;break;
  136. }
  137. if(retAddr==NULL) showGIP[0]=0;
  138. else strcpy(showGIP, retAddr);
  139. buBiaoAddrChange=1;
  140. return retAddr;
  141. }
  142. char *getDOMAINAddr(void)
  143. {
  144. char *retAddr=NULL;
  145. switch(newPara.serList.defaultuse){
  146. case SER_HZ:break;
  147. case SER_SD:break;
  148. case SER_IP:retAddr=newPara.serList.ipFenFa;break;
  149. case SER_JIQUN:retAddr=newPara.serList.jiqun;break;
  150. case SER_US:break;
  151. }
  152. return retAddr;
  153. }