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

📄 ogr2rnx.c

📁 The OpenGPSRec receiver software runs on the real time operating system RTAI-Linux. It compiles with
💻 C
📖 第 1 页 / 共 5 页
字号:
      dif[0] = (float) dt / 256.0;      dif[1] = (float) rec[k].delta_f - last.doppler;      DIF = fabs (dif[0]) + fabs (dif[1]);      if (DIF < dif_min)      {        dif_min = DIF;        best = rec[k];      }    }  }  return best;}intverify_c511 (type_rec0x38 allrec[], int N, double last_tow, ULONG next_c511){  int k, j, nsat, nmax;  int n_511, nn[40], test;  ULONG c511[40], cc, c511_ok;  float dif;  n_511 = 0;  for (j = 0; j < 40; j++)    nn[j] = 0;  for (k = 0; k < N; k++)  {    cc = allrec[k].c511;    test = 0;    for (j = 0; j < n_511; j++)      if (cc == c511[j])      {        nn[j]++;        test = 1;        break;      }    if (test == 0)    {      c511[n_511] = cc;      nn[n_511] = 1;      n_511++;    }  }  nmax = 0;  for (k = 0; k < n_511; k++)    if (nn[k] > nmax)    {      c511_ok = c511[k];      nmax = nn[k];    }  if (nmax == 0)    return 0;  dif = (float) next_c511 - (float) c511_ok;  if (last_tow != -1)    if (abs (dif) > 20)      return 0;  nsat = 0;  for (k = 0; k < N; k++)    if (allrec[k].c511 == c511_ok)      allrec[nsat++] = allrec[k];//  printf("Verifying c511: %2d records: Expecting %12u\n",N,next_c511);//  for(k=0;k<n_511;k++) //    printf("C511 %16u -> %2d veces\n",c511[k],nn[k]);// printf("Chosen %16u con %2d veces Dif %.0f\n",c511_ok,nmax,dif);//  getchar();  return nsat;}intremove_duplicates (type_rec0x38 allrec[], int N, rinex_obs epoch[]){  int k, j, nsat, sv, used[32], nn;  type_rec0x38 rec[20];  double tow, phase;  tow = allrec[0].tow;  // Find SVs in sight and possibly duplicated records  for (k = 0; k < 32; k++)    used[k] = 0;  for (k = 0; k < N; k++)    used[allrec[k].sv]++;  // printf("Remove: Tow %14.6f -> ",tow);  // printf("NREC %2d :: ",N); for(k=0;k<N;k++) printf("%2d  // ",allrec[k].sv+1);   // printf("\n");   nsat = 0;  for (k = 0; k < N; k++)  {    nn = 0;    rec[nn++] = allrec[k];    sv = rec[0].sv;    if (used[sv] < 0)      continue;                 // This sv has already been processed     if (used[sv] > 1)    {      for (j = k + 1; j < N; j++)      {        if (allrec[j].sv == sv)          rec[nn++] = allrec[j];        if (nn == used[sv])          break;      }      used[sv] = -1;    }    allrec[nsat++] = choose (rec, nn, epoch[sv]);  }  return nsat;  // printf("N SV %2d :: ",nsat); for(k=0;k<nsat;k++) printf("%2d  // ",allrec[k].sv+1);  // printf("\n");  for (k = 0; k < nsat; k++)  {    if ((allrec[k].sv + 1) != 21)      continue;    phase = allrec[k].int_phase + (allrec[k].c_phase & 2047) / 2048.0;    printf      ("0x38 ----------------------------------------------------------------\n");    printf ("PRN %02d: Sgn Q %5d ", allrec[k].sv + 1, allrec[k].db);    printf ("TRACKED %08x -> %8d\n", allrec[k].tracked,            (int) allrec[k].tracked);    printf ("\tTOW %12.5f (Counter 0.5 Mhz = %u).\n", allrec[k].tow,            allrec[k].c511);    printf ("\tPseudoRange  %14.3f  Integrated Phase %14.3f\n",            allrec[k].pr, phase);    printf ("\tDoppler(Hz): %5d \n", allrec[k].delta_f);  }  return nsat;}voidadd_0x16_to_epoch (rinex_obs epoch[], type_rec0x16 rec){  BYTE sv = rec.sv;  // printf("%d %14.3f %14.3f  // %f\n",sv,epoch[sv].prange,rec.pr,epoch[sv].prange-rec.pr);  if (epoch[sv].prange == rec.pr)    epoch[sv].doppler = rec.delta_pr / lambda;}voidadd_0x38_to_epoch (rinex_obs epoch[], type_rec0x38 rec){  BYTE sv;  int action;  BYTE check;  long dtracked;  sv = rec.sv;//  if ( !(sv == 0 || sv == 3))//    printf("sv = %d\n", sv);  //  if ( rec.tracked == 0xff)//  {//    rec.tracked = 1;//    printf("set rec.tracked to 1!\n");//  }//  else//  {//    printf("rec.tracked = %d\n", rec.tracked);//  }  check = rec.tracked & 0xff;  if (epoch[sv].used == NEVER_USED)  {    action = (check == 0) ? NO_DUMP : DUMP;//    if ( action == NO_DUMP)//      printf("rec.tracked = %d\n", rec.tracked);  }  else  {    dtracked = (epoch[sv].tracked - rec.tracked);    action = (abs (dtracked) < 256) ? DUMP : NO_DUMP;//    if ( action == NO_DUMP)//      printf("dtracked = %d\n", dtracked);  }  // Check if there have been a recent 0x36 record for that sat//  if ((rec.tow > (epoch[sv].last36 + 2.0)) && (action == DUMP))//    action = (OPT1) ? DUMP_PHASE_ONLY : NO_DUMP;  // printf("SV %2d -> %08x %08x :  // ",sv+1,epoch[sv].tracked,rec.tracked,dtracked);  // printf("dTracked %8d :",dtracked);  // printf("check %02x action %d\n",check,action);#if 0  // Check for meaningless values  if ((rec.pr <= 10.0) || (rec.pr >= 1e9))    return;  // if (rec.db>15000) return; #endif  // epoch[sv].doppler=rec.delta_f;   epoch[sv].prange = rec.pr;  epoch[sv].phase = (double) rec.int_phase + (rec.c_phase & 2047) / 2048.0;  epoch[sv].db = rec.db;  epoch[sv].tracked = rec.tracked;  epoch[sv].c511 = rec.c511;  if (RELAX)    action = DUMP;//  action = DUMP;  epoch[sv].used = action;  return;}intprocess_tow (type_rec0x38 *rec, int N, type_rec0x16 *rec16, int N16,   rinex_obs *epoch, double last_tow)//     type_rec0x38 *rec;//     int N;//     type_rec0x16 *rec16;//     int N16;//     rinex_obs *epoch;//     double last_tow;{  double current_tow = rec[0].tow;  int n_sat;  int k;  // Check for current_tow < last_tow (problems during week rollover)  // if (current_tow<last_tow) return 0;   // Check for tow=0.000000  if (current_tow == 0.0)    return 0;  // Eliminates duplicated records   n_sat = remove_duplicates (rec, N, epoch);  // printf("Tow %14.6f -> %2d records -> %2d  // sats\n",current_tow,N,n_sat);   // Add (or not) records to rinex obs.  for (k = 0; k < n_sat; k++)    add_0x38_to_epoch (epoch, rec[k]);  // Add doppler data  for (k = 0; k < N16; k++)    add_0x16_to_epoch (epoch, rec16[k]);  return n_sat;}voidgenerate_rinex (FILE * org){  BYTE id, L, record[256], sv;  int k, n_records, nr, n_16;  type_rec0x16 r16, rec16[48];  type_rec0x38 rec, allrec[48];  type_rec0x36 rec36;  // type_rec0x1a chan[12];  double current_tow, last_tow;  ULONG next_c511, last_c511 = 0;  rinex_obs epoch[32];  ULONG week_days, week_secs;  double aprox_xyz[3];  char description[256];  UINT prod_number;  long itow, dtow;  float version;  BOOLEAN found = 0;  long fptr;  FILE *dest;  char name[128];  static int FirstWarn = 1;  get_prod_id (org, description, &prod_number, &version);  get_aprox_location_and_wdays_and_tow (org, aprox_xyz, &week_days,                                        &week_secs);  if (RINEX_FILE)  {    get_rinex_file_name (location, week_days, week_secs, name, 'O');    dest = fopen (name, "w");    if (!dest)    {      printf( "OGR2RNX: error opening file %s\n", name);      exit(-1);    }    printf( "OGR2RNX: write RINEX file %s\n", name);  }  else    dest = stdout;  // printf("Week days %d TOW %d -> File  // %s\n",week_days,week_secs,name);   // printf("Aprox location %f %f  // %f\n",aprox_llh[0],aprox_llh[1],aprox_llh[2]);  // printf("Aprox XYZ %f %f  // %f\n",aprox_xyz[0],aprox_xyz[1],aprox_xyz[2]);  // printf("ID %d.\n Desc: %s .\n Soft  // %.2f\n",prod_number,description,version);  // exit(0);  rewind (org);  n_records = 0;  n_16 = 0;  last_tow = -1;  reset_epoch (epoch);  for (k = 0; k < 32; k++)  {    epoch[k].used = NEVER_USED;    epoch[k].last36 = -1.0;  }//  printf( "*** start ***\n", id);  do  {    fptr = ftell (org);    fread (&id, 1, 1, org);    fread (&L, 1, 1, org);    fread (record, 1, L, org);    fptr -= ftell (org);//    printf( "%x\n", id);    switch (id)    {    case 0x1a:      break;    case 0x16://      printf( "*** id = %x ***\n", id);      r16 = process_0x16 (record);      sv = r16.sv;      if (sv >= 32)        break;// Option A: keep all of them and discard them later      if (n_16 < 48)        rec16[n_16++] = r16;      // if (n_16>=12) {printf("N16 %d Tow      // %.0f\n",n_16,current_tow); getchar();}      // OPtion B: check to see if there is already a 0x16 record      // for that sv      // found=0; for (k=0;k<n_16;k++) if (sv==rec16[k].sv)      // {found=1; break;}      // if (found==0) rec16[n_16++]=r16;      // else { printf("Repeated 0x16 for SV %d, tow %.0f. Not      // added\n",sv,current_tow);}      break;    case 0x36:      rec36 = process_0x36 (record);      sv = rec36.sv;      if (sv >= 32)        break;      epoch[sv].last36 = (float) rec36.c50 / 50.0;      break;    case 0x38:      rec = process_0x38 (record);      sv = rec.sv;      if (sv >= 32)        break;//      printf("SV = %3d, TOW = %.2f\n", rec.sv, rec.tow);      if ( n_records == 0)        current_tow = rec.tow;//      if ( rec.tow != current_tow)//        printf("rec.tow = %e, current_tow = %e\n", rec.tow, current_tow);      if ( rec.tow == current_tow)        allrec[n_records++] = rec;      else                      // End of epoch detected      {        fseek (org, fptr, SEEK_CUR);    // Reset file pointer for        // next epoch        nr = n_records;        n_records = 0;        // printf("End TOW: 0x38 records: %d ",nr);         // Check that tow is within limits        itow = (long) floor (current_tow + 0.5);        if (START == -1)          START = itow;        dtow = itow - START;        if ((itow < START) || (itow > LAST) || (dtow > ELAPSED))        {          n_16 = 0;//          printf("itow = %d, dtow = %d\n", itow, dtow); //          getchar();          break;        }// Verifies c511 fields//        printf("%10.3f (%2d) ->\n ",current_tow,nr);         next_c511 = last_c511 +          (ULONG) floor ((current_tow - last_tow) * 511500.0 + 0.5);//        nr = verify_c511 (allrec, nr, last_tow, next_c511);        if ( FirstWarn)        {           FirstWarn = 0;           printf("OGR2RNX: *** skip 511 kHz counter test ***\n");         }        if (nr == 0)        {          n_16 = 0;//          printf("n_16 = %d\n", n_16); //          getchar();          break;        }//        printf("After c511 check = %2d. 0x16 records %d\n",nr,n_16); //        printf("Before %2d: ",nr); //        for(k=0;k<nr;k++) printf("%02d ",allrec[k].sv+1);//        printf("\n");         nr = process_tow (allrec, nr, rec16, n_16, epoch, last_tow);//        printf("Final %2d: ",nr); //        for(k=0;k<nr;k++) printf("%02d ",allrec[k].sv+1);//        printf("\n");         if (nr == 0)        {          n_16 = 0;          break;        }        // If first epoch, creates header         if (last_tow == -1)          generate_rinex_header (aprox_xyz, week_days,                                 current_tow, prod_number,                                 version, description, dest);// If multiple of interval, dump to rinex file //        printf("INTERVAL = %d itow =%d\n", INTERVAL, itow);         if ((INTERVAL == 1) || (itow % INTERVAL) == 0)          print_rinex_info (week_days, current_tow, epoch, dest);        else          printf("INTERVAL = %d \n", INTERVAL);//        for(k=0;k<n_16;k++) //          printf("%02d %14.3f\n",rec16[k].sv+1,rec16[k].pr); //        getchar();        n_16 = 0;               // Reset number of 0x16 records per epoch        last_c511 = allrec[0].c511;        // printf("Expected c511 %u -> seen        // %u\n",next_c511,last_c511);        last_tow = current_tow;        reset_epoch (epoch);      }      break;    default:      break;    }  }  while (feof (org) == 0);//  printf( "*** stop ***\n", id);  if (STDIN == 0)    fclose (org);  if (RINEX_FILE)    fclose (dest);  exit (0);}voidparse_records (FILE * org){  BYTE record[256], id, L;  fread (&id, 1, 1, org);  fread (&L, 1, 1, org);  fread (record, 1, L, org);  if (!found_in_list (SELECTED_RECORDS, id))    return;  switch (id)  {  case 0x12:    process_0x12_gps38 (record);    break;  case 0x0e:    process_0x0e (record);    break;  case 0x11:    process_0x11 (record);    break;  case 0x14:    process_0x14 (record);    break;  case 0x16:    process_0x16 (record);    break;  case 0x1a:    process_0x1a (record);    break;  case 0x33:    process_0x33 (record);    break;  case 0x36:    process_0x36 (record);    break;  case 0x37:    process_0x37 (record);    break;  case 0x38:    process_0x38 (record);    break;  case 0x39:    process_0x39 (record);    break;  default:    printf ("Record %02x ------------------------------------------\n", id);    check (record, L, AS_BYTE);    getchar ();    break;  }}voidoriginal_parsing (FILE * fd){  do    parse_records (fd);  while (feof (fd) == 0);  if (DIF_RECORDS)  {

⌨️ 快捷键说明

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