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

📄 gpsrcvr.bak

📁 OpenSource GPS is software for x86 PCs that allows you to acquire, track and demodulate signals from
💻 BAK
📖 第 1 页 / 共 3 页
字号:
								chan[ch].avg/1395.*25.*1.7777);
           }
           else chan[ch].CNo=0.0;
			  if (chan[ch].CNo<25.0)
			  {
	// calculate carrier clock and doppler correction
			 chan[ch].carrier_corr=(-xyz[chan[ch].prn].doppler-
										  clock_offset*1575.42)/42.57475e-3;
	// calculate code clock and doppler correction
			 code_corr=clock_offset*24.+xyz[chan[ch].prn].doppler/65.5;
			 chan[ch].code_freq=code_ref+code_corr;
			 ch_code(ch,chan[ch].code_freq);            // 1.023 MHz chipping rate
			 chan[ch].state=acquisition;
			 chan[ch].t_count=0;
			 chan[ch].n_frame=0;
			 chan[ch].codes=0;
          chan[ch].bit_counter=0;
          chan[ch].frame_bit=0;
			 chan[ch].n_freq=search_min_f;
          chan[ch].tow_sync=0;
			 chan[ch].del_freq=1;
			 chan[ch].carrier_freq=carrier_ref+chan[ch].carrier_corr+
										  d_freq*chan[ch].n_freq;     // set carrier
			 ch_carrier(ch,chan[ch].carrier_freq);             // select carrier
			  }
		   }
	   }

    }
    ext_bit_count=-1;
    for (ch=0;ch<12;ch++)
    {
      if (chan[ch].frame_bit> ext_bit_count ) ext_bit_count= chan[ch].frame_bit;
    }
    if (n_track>0)
    {
      sync_set=1;
      for (ch=0;ch<12;ch++)
      {
        if (chan[ch].state==track && ( ext_bit_count<5 || ext_bit_count>6 ))
        {
          sync_set=0;
          break;
        }
      }
      if (sync_set==1 && out_data) write_data_1();
      sync_set=1;
      for (ch=0;ch<12;ch++)
      {
        if (chan[ch].state==track && ( ext_bit_count<1505 || ext_bit_count>1506))
        {
          sync_set=0;
          break;
        }
      }
      if (sync_set==1  && out_data) write_data_0();
    }
//    nav fix once every X seconds
    if (nav_flag==1)
    {
      nav_fix();
      nav_flag=0;
    }
//    channel allocation once every minute
    if (min_flag==1)
    {
		 if ( status != cold_start ) chan_allocate();
       else if (status==cold_start ) cold_allocate();
       min_flag=0;
#ifdef BCPP
       clrscr();
#endif
#ifdef VCPP
       _clearscreen( _GCLEARSCREEN); // PGB MS
#endif
    }
	 display();
	 if (key =='p' || key=='P')
	 {
		display_page++;
		display_page=display_page % 5;
#ifdef BCPP
               clrscr();
#endif
#ifdef VCPP
       _clearscreen( _GCLEARSCREEN); // PGB MS
#endif
    }
  } while (key != 'x' && key != 'X');/*Stay in loop until 'X' key is pressed.*/

#ifdef VCPP  // PGB

    //
	// There may be a better way????
	//

	struct tm* TempTime;
	TempTime = localtime( &thetime );

	//
	// Update system time.
	//
	gDosTime.hour	= TempTime->tm_hour;   
	gDosTime.minute	= TempTime->tm_min; 
	gDosTime.second = TempTime->tm_sec;

	gDosDate.month  = TempTime->tm_mon + 1;
	gDosDate.day    = TempTime->tm_mday;
	//
	// tm_year is the current year - 1900
	//
	gDosDate.year   = 1900 + TempTime->tm_year;

	gDosDate.dayofweek = TempTime->tm_wday;

	_dos_settime( &gDosTime ); //  TODO 
	_dos_setdate( &gDosDate ); //  TODO 
  
#endif  
   
  
  //
// Remove our interrupt and restore the old one
//
  Interrupt_Remove();
#ifndef DJGPP
  close_com(); // NMEA
#endif
// Update the Almanac Data file
  write_almanac();
//  Update the Ephemeris Data file
  write_ephemeris();
//  Update the ionospheric model and UTC parameters
  write_ion_utc();
//    Update the curloc file for the next run
  if ( status==navigating )
  {
    out=fopen("curloc.dat","w+");
	 fprintf(out,"latitude  %f\n",rec_pos_llh.lat*r_to_d);
	 fprintf(out,"longitude %f\n",rec_pos_llh.lon*r_to_d);
	 fprintf(out,"hae       %f\n",rec_pos_llh.hae);
    fclose(out);
  }

/*  out=fopen("debug.dat","w+");
  fprintf(out,"carrier=%ld, code=%ld\n",store_carrier,store_code);
  for (ch=0;ch<6;ch++)
  {
    fprintf(out," ch=%d  offset=%d  \n",ch,chan[ch].offset);
    for ((int)i=0;i<1500;i++)
    {
		 fprintf(out," %d %d, %ld, %ld, %ld, %ld\n",
		 ch, i,qdither[ch][i],qprompt[ch][i],idither[ch][i],iprompt[ch][i]);
    }
  }  
  for (i=0;i<30000;i++)
  {
		 fprintf(out," %d, %d, %d, %d, %d\n",
		 i,qdither0[i],qprompt0[i],idither0[i],iprompt0[i]);
  }
*/
//  fcloseall();
}

/*******************************************************************************
FUNCTION display()
RETURNS  None.

PARAMETERS None.

PURPOSE
	This function displays the current status of the receiver on the
	computer screen.  It is called when there is nothing else to do

WRITTEN BY
	Clifford Kelley

*******************************************************************************/
void display(void)
{
  char ch;
#ifdef VCPP
  _settextposition(1,1);
#endif
#ifdef BCPP
  gotoxy(1,1);
#endif
  printf("                   OpenSource GPS Software Version 1.18%s  %s\n",KFtxt,IOtxt);
  printf("%s",ctime(&thetime));
  printf("TOW  %6ld\n",clock_tow);
  printf("meas time %f  error %f  delta %f\n",m_time[1],m_error,delta_m_time);
  cur_lat.deg=rec_pos_llh.lat*r_to_d;
  cur_lat.min=(rec_pos_llh.lat*r_to_d-cur_lat.deg)*60;
  cur_lat.sec=(rec_pos_llh.lat*r_to_d-cur_lat.deg-cur_lat.min/60.)*3600.;
  cur_long.deg=rec_pos_llh.lon*r_to_d;
  cur_long.min=(rec_pos_llh.lon*r_to_d-cur_long.deg)*60;
  cur_long.sec=(rec_pos_llh.lon*r_to_d-cur_long.deg-cur_long.min/60.)*3600.;
  printf("   latitude    longitude          HAE      clock error (ppm)\n");
  printf("  %4d:%2d:%5.2f  %4d:%2d:%5.2f  %10.2f  %f\n",
  cur_lat.deg,abs(cur_lat.min),fabs(cur_lat.sec),cur_long.deg,abs(cur_long.min),
  fabs(cur_long.sec),rec_pos_llh.hae,clock_offset);
  printf(" Speed     Heading      TIC_dt\n");
  printf(" %lf   %lf   %lf\n",speed,heading*r_to_d,TIC_dt);
  printf("   \n");
  printf("tracking %2d status %1d almanac valid %1d gps week %4d alm_page %2d\n",
  n_track,status,almanac_valid,gps_week%1024,alm_page);
  if (display_page==0)
  {
	 printf(
" ch prn state n_freq az el doppler t_count n_frame sfid ura page missed CNo\n");
	 for (ch=0;ch<N_channels;ch++)
	 {
		printf(
" %2d %2d  %2d  %3d   %4.0f  %3.0f   %6.0f   %4d  %4d  %2d  %3d  %3d%5d   %4.1f\n",
		ch,chan[ch].prn,chan[ch].state,chan[ch].n_freq,
		xyz[chan[ch].prn].azimuth*57.3,xyz[chan[ch].prn].elevation*57.3,
		xyz[chan[ch].prn].doppler,chan[ch].frame_bit%1500,chan[ch].n_frame,chan[ch].sfid,
		gps_eph[chan[ch].prn].ura,chan[ch].page5,chan[ch].missed,chan[ch].CNo);
	 }
  printf(" GDOP=%6.3f  HDOP=%6.3f  VDOP=%6.3f  TDOP=%6.3f\n",gdop,hdop,vdop,tdop);  }
  else if (display_page==1)
  {
	 printf(  " ch prn state TLM      TOW  Health  Valid  TOW_sync offset\n");
	 for (ch=0;ch<N_channels;ch++)
	 {
		printf(" %2d %2d  %2d  %6ld   %6ld   %2d     %2d     %2d   %4d\n",
		ch, chan[ch].prn, chan[ch].state, chan[ch].TLM, chan[ch].TOW,
		gps_eph[chan[ch].prn].health,gps_eph[chan[ch].prn].valid,chan[ch].tow_sync,
		chan[ch].offset);
	 }
  }
  else if (display_page==2)
  {
	 printf(" ch prn state n_freq az  el        tropo        iono\n");
	 for (ch=0;ch<N_channels;ch++)
	 {
		printf(" %2d %2d  %2d  %3d   %4.0f  %3.0f   %10.4lf   %10.4lf\n",
		ch, chan[ch].prn, chan[ch].state, chan[ch].n_freq,
		xyz[chan[ch].prn].azimuth*57.3, xyz[chan[ch].prn].elevation*57.3,
		chan[ch].Tropo*c, chan[ch].Iono*c);
	 }
  }
  else if (display_page==3)
  {
	 printf(" ch prn state      Pseudorange     delta Pseudorange\n");
	 for (ch=0;ch<N_channels;ch++)
	 {
		printf(" %2d %2d  %2d  %20.10lf   %15.10lf\n",
		ch, chan[ch].prn, chan[ch].state, chan[ch].Pr, chan[ch].dPr);
	 }
  }
  else if (display_page==4)// can be used for debugging purposes
  {
	 printf(" ch prn state sfid page SF1  SF2  SF3  SF4  SF5\n");
	 for (ch=0;ch<N_channels;ch++)
	 {
		printf(" %2d %2d   %2d   %2d  %2d  %3x  %3x  %3x  %3x  %3x\n",
		ch, chan[ch].prn, chan[ch].state,chan[ch].sfid,chan[ch].page5,
      chan[ch].word_error[0],chan[ch].word_error[1],chan[ch].word_error[2],
      chan[ch].word_error[3],chan[ch].word_error[4]);
	 }
  }

}

/*******************************************************************************
FUNCTION Interrupt_Install()
RETURNS  None.

PARAMETERS None.

PURPOSE
	This function replaces the current IRQ0 Interrupt service routine with
	our own custom function. The old vector is stored in a global variable
	and will be reinstalled at the end of program execution. IRQ0 is
	enabled by altering the interrupt mask stored by the 8259 interrupt
	handler.

*******************************************************************************/
#ifdef BCPP  
void Interrupt_Install()
{
  unsigned char     int_mask,i_high,i_low;
  i_high=interr_int>>8;
  i_low=interr_int&0xff;
  Old_Interrupt = getvect(8 + IRQLEVEL);
  disable();
  setvect(8 + IRQLEVEL,GPS_Interrupt);
  int_mask = inportb(0x21);     // get hardware interrupt mask
  int_mask = int_mask & ~(1 << IRQLEVEL);
  outportb(0x21,int_mask);      // send new mask to 8259
  enable();
// modify the timer to divide by interr_int
  outportb(0x43,0x34);
  outportb(0x40,i_low);
  outportb(0x40,i_high);
  outportb(0x20,0x20); // Clear PIC

}
#endif
#ifdef VCPP  // MS
void Interrupt_Install()
{
	unsigned char     int_mask, i_high, i_low;
	i_high = interr_int >> 8;
	i_low  = interr_int & 0xff;
	Old_Interrupt = _dos_getvect( 8 + IRQLEVEL);
	_disable();
	_dos_setvect( 8 + IRQLEVEL, GPS_Interrupt);
	int_mask = _inp(0x21);     // Get hardware interrupt mask

	int_mask = int_mask & ~(1 << IRQLEVEL);

	_outp( 0x21, int_mask );

	_enable();

	// Modify the timer to divide by interr_int
	_outp(0x43,0x34 );

	_outp( 0x40,i_low );

	_outp( 0x40,i_high );

	_outp( 0x20,0x20 ); // Clear the PIC

}

#endif

#ifdef DJGPP  // DJGPP compiler
void Interrupt_Install()
{
	unsigned char     i_high, i_low;
        int int_handler;
        
	i_high = interr_int >> 8;
	i_low  = interr_int & 0xff;

   GPS_Interrupt.pm_offset = int_handler;
   GPS_Interrupt.pm_selector = _go32_my_cs();
   _go32_dpmi_get_protected_mode_interrupt_vector(0x08, &Old_Interrupt);
   _go32_dpmi_allocate_iret_wrapper(&GPS_Interrupt);
   _go32_dpmi_set_protected_mode_interrupt_vector(0x08, &GPS_Interrupt);

	// Modify the timer to divide by interr_int
	outportb(0x43,0x34 );

	outportb( 0x40,i_low );

	outportb( 0x40,i_high );

⌨️ 快捷键说明

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