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

📄 ogsxmit.c

📁 OpenGPSSim是一个gps模拟程序
💻 C
📖 第 1 页 / 共 2 页
字号:
      didx      = HalfChip_Counter[prn];             // now 0,...,2046           didx      = (didx % 2046) / 2;//  C/A code//      assert( didx >= 0 && didx < 1023);//      assert( prn >= 1 && prn < 32);      ca_prompt = CACode[prn][didx];   // didx=0,...,1022//  for (i=1;i<=32;i++)//    for (j=0;j<1023;j++)//    {//      if ( abs( CACode[i][j]) != 1)//        printf("CACode[%d][%d] = %d\n", i,j,CACode[i][j]);//    }    //  getchar();//      if (!( ca_prompt == 1 || ca_prompt == -1))//      {//        printf( "ca_prompt = %d\n", ca_prompt);//        printf("CACode[%d][%d] = %d\n", prn,didx,CACode[prn][didx]);//        getchar();//      }//  C/A code      nidx      = CACode_Counter[prn] / 20;   // 20 C/A periods <-> 1 bit//      assert( nidx >= 0 && nidx < NAVMSGLEN);      navbit    = NavBit[prn][nidx%NAVMSGLEN];   // nidx=0,...,1499//      printf("navbit = %d\n", navbit);//  resolution is 1/1024 cycles      XmtrInfo[prn].carrier_dco_phase = (long)( Carrier_DCO_Cycle[prn] * 1024);        sgn += Carrier_DCO_I[cidx] * ca_prompt * navbit;     //      assert( sgn == 0);//      sgn += Carrier_DCO_I[cidx] * ca_prompt;      #if 0      if ( 0)      {        static int ii;                printf( "cidx = %d", cidx);        printf( " ca = %d", ca_prompt);        printf( " carcyc = %.4f", (double)(Carrier_Cycle[prn]) / (double)(0x1L<<27)); // 24+3!        printf( " CACode1 = %d", CACode[prn][ii]);        printf( " DCO = %d", Carrier_DCO_I[ii%8]);        printf( " sgn = %d\n", sgn);                if (ii > 20)          getchar();        ii += 1;      }#endif//      printf("sgn = %d\n", sgn);//      printf("Carrier_DCO_I = %d, cidx=%d\n", Carrier_DCO_I[cidx], cidx);//      printf("ca_prompt = %d, didx = %d\n", ca_prompt, didx);//      printf("navbit = %d\n", navbit);//      printf("cidx=%d, didx=%d, nidx = %d\n", cidx, didx, nidx);//      getchar();//      nofprn += 1;    }  // --- if ( NavBit[prn]) ---  }  // --- for ( prn=1; prn <= NOFSAT; prn++) ---  // add white noise    if ( Noise_Ampl > 0)  {    sgnflt = (float)( sgn) + Noise_Ampl * randn( 0.0, 1.0);//    printf("sgn=%d, sgnflt=%e (Noise_Ampl=%e)\n", sgn, sgnflt, Noise_Ampl);//    getchar();  //    printf( "noise = %e\n", tmp);//    getchar();//    printf("sgn = %d, noise = %e, sum = %e \n", sgn, tmp, sgnflt);//    printf("sizeof( float) = %d \n", sizeof( float));//    getchar();    }    else      sgnflt = (float)( sgn);// quantize and map to [0,1,2,3]  sgn = ( sgnflt >= 0.0) ? 1 : -1;  if ( fabs( sgnflt) > QuantThresh)    sgn *= 3;// map -3,-1,1,3 to 0,1,2,3  sgn = (sgn+3) / 2;   return (sgn);}////  main function//int main( int argc, char *argv[]){  int j, nof, sgn, ofs;  long i, nofwritten;  unsigned long cntMSB;//  char outfile[] = "ogsraw.dat";   // default output file name//       navfilefmt[] = "navmsg-in-%02d.dat",//       navfile[sizeof(navfilefmt)];      // d <= 2 digits!  char *outpath, *navpath, *ptr, *navfilefmt, *navfile;  float t, dt;  // 30 sec <-> 1500 nav bits  double samplfrq = 40e6 / 7.0;               // sampling frequency  double nofsamples = 0.0;  FILE *Fp, *FpNav;  set_directories( argv[0]);//  process options  getargs( argc, argv);  check_options();//  if ( OutputFileName)//    ptr = OutputFileName;//  else  //    ptr = outfile;  outpath = conmalloc( strlen( OGSDataDir) + strlen( OutputFileName) + 1);  strcpy( outpath, OGSDataDir);  strcat( outpath, OutputFileName);//  welcome  printf("-------------------------------- OpenGPSSim ---------------------------------\n");  printf("ogsxmit   version %s\n", Version);  printf("Copyright (C) 2001-2006 G. Beyerle, A. Tabernero, C. Kelley and others.      \n");  printf("ogsxmit comes with ABSOLUTELY NO WARRANTY; for details see file 'warranty'.\n");  printf("This is free software, and you are welcome to redistribute it under          \n");  printf("certain conditions; see file 'copying' for details.                          \n");  printf("-----------------------------------------------------------------------------\n");//  initialize  init_struct_xmitter();//  read parameter controlling signal transmission  read_xmit_par();  if ( Noise_dB > -1000.0)    Noise_Ampl = pow( 10.0, (double)( Noise_dB)/20.0);  else    Noise_Ampl = 0.0;    srand(1);        // initialize random generator  // calculate C/A-code and store in global CACode[1,...,NOFSATS][1,..,NOFCHIPS]  calc_cacode();  if ( !OverWrite)  {    Fp = fopen( outpath, "rb");    if ( Fp)    {      printf("Data file '%s' already exists.\nPlease remove it and try again.\n",         outpath);      exit(0);    }  }  Fp = fopen( outpath, "wb");  if ( !Fp)  {    printf( "error opening file '%s'\n", outpath);    perror( NULL);    exit(-1);  }//  FILE *TmpFp;//  TmpFp = fopen( "C:/home/Src/osgpsim/data/osgraw-c-chr.dat", "w");//  if ( !TmpFp)//  {//    perror( NULL);//    exit(-1);//  }//  printf( "*** opened C:/home/Src/osgpsim/data/osgraw-c-chr.dat\n");  printf( "\nRead navigation data bits from file(s) ...\n");//  printf( "NavFilePattern = %s\n", NavFilePattern);//  getchar();  ptr = strstr( NavFilePattern, "PRN");  if ( !ptr)  {    printf( "Substring 'PRN' not found in %s.\n", NavFilePattern);    exit(-1);      }    ofs = ptr - NavFilePattern;   navfilefmt = conmalloc( strlen( NavFilePattern) + 4);  navfile    = conmalloc( strlen( NavFilePattern) + 4);    strcpy( navfilefmt, NavFilePattern);  strcpy( navfilefmt + ofs, "%02d");  strcpy( navfilefmt + ofs + 4, ptr + 3);//  printf( "navfilefmt = %s\n", navfilefmt);//  getchar();    navpath = conmalloc( strlen( OGSDataDir) + strlen( navfilefmt) + 1);  for ( i=1; i<=NOFSAT; i++)  {    sprintf( navfile, navfilefmt, i);    strcpy( navpath, OGSDataDir);    strcat( navpath, navfile);    FpNav = fopen( navpath, "rb");    if ( FpNav)    {      printf( " '%s'.\n", navpath);      NavBit[i] = (char*) malloc( NAVMSGLEN);      if ( !NavBit[i])      {        printf( "malloc() failed in %s at line %d\n", __FILE__, __LINE__);        exit(-1);      }      nof = fread( NavBit[i], sizeof( char), NAVMSGLEN, FpNav);      if ( nof < NAVMSGLEN)      {        printf( "read only %d bytes from file '%s'.\n", nof, navpath);        exit(-1);      }//      else//        printf( "read %d bytes from file '%s'.\n", nof, navpath);            fclose( FpNav);      //  re-write: 0 -> -1, 1 -> 1      for ( j=0; j<NAVMSGLEN; j++)        NavBit[i][j] = (NavBit[i][j] > 0) ? 1 : -1;          }  }  int foundone = 0;  for ( i=1; i<=NOFSAT; i++)  {    if ( NavBit[i])      foundone = 1;  }  if ( !foundone)  {    printf("Not a single file found for pattern >%s<.\n", NavFilePattern);    exit(-1);  }//  for (i=1;i<=32;i++)//    for (j=0;j<1023;j++)//    {//      if ( abs( CACode[i][j]) != 1)//        printf("CACode[%d][%d] = %d\n", i,j,CACode[i][j]);//    }    //  TmpFP = fopen( "c:/tmp/testdata.dat", "w");//  if ( !TmpFP)//  {//    printf( "Error opening file 'c:/tmp/testdata.dat'\n");//    perror( NULL);//    exit(-1);//  }  printf( "\n");  printf( "construct GPS signal, add noise, quantize\n");  printf( "and write to file '%s' ...\n", outpath);//  we store 4 times 2 bit (4 level) signal samples into one byte,//  fill XmtrBuf[XMTRBUFLEN] and write to file// 4 samples per byte  dt = XMTRBUFLEN * 4.0 / samplfrq;  for ( t=0; t<MaxTime; t+=dt)    {    cntMSB = 0;    for ( i=0; i<XMTRBUFLEN; i++)    {//      char savsgn[4];            XmtrBuf[i] = 0;      for ( j=0; j<4; j++)      {        sgn = calc_raw_sgn();//        savsgn[j] = sgn;        XmtrBuf[i] |= ((sgn & 0x3) << (3-j)*2);//  magnitude bit should be set in 30% of the samples        if (sgn == 3 || sgn == 0)          cntMSB += 1;      }      }        printf( "%5.2f of %.2f sec (MAG bit: %.2f%%)\n",       t, MaxTime, (100.0 * cntMSB) / (4.0*XMTRBUFLEN));        nofwritten = fwrite( XmtrBuf, sizeof( char), XMTRBUFLEN, Fp);    if ( nofwritten != XMTRBUFLEN)    {      printf( "Could only write %d of %d bytes. Disk full?\n",         nofwritten, XMTRBUFLEN);      fclose( Fp);      exit(-1);            }        nofsamples += 4.0*XMTRBUFLEN;  }  // --- for ( t=0; t<MaxTime; t += dt) ---  fclose( Fp);//  fclose( TmpFp);//  if ( TmpFP) fclose( TmpFP);  printf( "%.0f samples written to %s.\n", nofsamples, outpath);  exit(0);}/* ------------------------------ end of file ----------------------------- */

⌨️ 快捷键说明

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