sysIni.c 4.5 KB

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