⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pseudorange.cpp

📁 该程序是对GPS接收机输出的原始数据(indata.log文件)进行分析计算
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <math.h>
#include <stdio.h>
#pragma hdrstop
#define N 7
//---------------------------------------------------------------------------

#pragma argsused


get_header_23(FILE *fp)
{ int x=0;
  while(1)
    {fread(&x,1,1,fp);
     if(x==1)
       {fread(&x,1,1,fp);
        if(x==23)
          {fread(&x,1,1,fp);
           if(x==232) return 0;
          }
       }
     else if(feof(fp)) break;
    }
    return 0;
}

int get_id( FILE *fp)
{ int y=0;
  fread(&y,1,1,fp);
  y=y&63;
  y++;
  if(y==N) return 1;
  else
    {fseek(fp,10L,1);
     return 0;
    }
}

int main(int argc, char* argv[])
{double gps_time=0.0,p=0.0,p_range=0.0;
 int x=0,m=11;
 int data_len=0,num_block=0,true_id=0;
 unsigned long int code_ph=0;
 float cn=0.0;
 FILE *infp,*outfp1,*outfp2,*outfp3;

 if((infp=fopen("indata.log","rb"))==NULL)
 {printf("can't open file indata \n");
 }
 if((outfp1=fopen("Pseudorange.txt","wb"))==NULL)
 {printf("can't open file Pseudorange \n");
 }
 if((outfp2=fopen("CN.txt","wb"))==NULL)
 {printf("can't open file CN\n");
 }
 if((outfp3=fopen("figure.txt","wb"))==NULL) //用于作图的数据文件
 {printf("can't open file figure \n");
 }

 while(1)
    {
     get_header_23(infp);
     if(feof(infp)) goto aa;


     fread(&data_len,1,1,infp);//信息数据长度
     fread(&x,1,1,infp); //第五个字节,“time slew value”,单位175ns
     fread(&x,1,1,infp); //第六个字节,0-2位是time status,3-7位保留
     fread(&num_block,1,1,infp);//数据块数
     fread(&gps_time,8,1,infp);

     true_id=0;
     m=11;
     while(!true_id)
      {
       true_id=get_id(infp);
       m=m+11;
       if(m>=data_len) break;
      }

    if(true_id==1)
      {fread(&x,1,1,infp);
       cn=x*0.25;    //载波噪声比,float型
       fread(&code_ph,4,1,infp);//码相位
       p=(gps_time-floor(gps_time))-code_ph/2095104000.0;
       if(p<0) p=p+1;
       p_range=p*299792458;  //p_range为Ulong型
       if(!feof(infp))
         {
          printf("%12.3f ",p_range);
          fprintf(outfp1,"%12.3f\n",p_range);
          printf("%5.2f ",cn);
          fprintf(outfp2,"%5.2f ",cn);

          fprintf(outfp3,"%12.3f ",p_range);
          fprintf(outfp3,"%5.2f",cn);
          fprintf(outfp3,"\n");
         }
       }

    }

aa: printf("\n\n    Processing is end,press ENTER to exit!");
    fclose(infp);
    fclose(outfp1);
    fclose(outfp2);
    getchar();

        return 0;
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -