📄 gpsrcvr.cpp
字号:
}
#endif
/*******************************************************************************
FUNCTION Interrupt_Remove()
RETURNS None.
PARAMETERS None.
PURPOSE
This function removes the custom interrupt vector from the vector
table and restores the previous vector.
*******************************************************************************/
#ifdef BCPP
void Interrupt_Remove()
{
unsigned char int_mask;
outportb(0x20,0x20); // clear interrupt and allow next one
int_mask = inportb(0x21); // get hardware interrupt mask
int_mask = int_mask | (1 << IRQLEVEL);
disable();
//outportb(0x21,int_mask); // send new mask to 8259
setvect(8 + IRQLEVEL,Old_Interrupt);
enable(); // allow hardware interrupts
outportb(0x20,0x20); // clear interrupt and allow next one
outportb(0x43,0x34); // reset clock
outportb(0x40,0xff);
outportb(0x40,0xff);
}
#endif
#ifdef VCPP
void Interrupt_Remove()
{
unsigned char int_mask;
_outp( 0x20,0x20);
// PGB outportb(0x20,0x20); // clear interrupt and allow next one
int_mask = inp(0x21);
// PGB int_mask = inportb(0x21); // get hardware interrupt mask
int_mask = int_mask | (1 << IRQLEVEL);
_disable();
//outportb(0x21,int_mask); // send new mask to 8259
_dos_setvect(8 + IRQLEVEL,Old_Interrupt);
_enable(); // allow hardware interrupts
_outp(0x20,0x20); // clear interrupt and allow next one
_outp(0x43,0x34); // reset clock
_outp(0x40,0xff);
_outp(0x40,0xff);
}
#endif
#ifdef DJGPP
void Interrupt_Remove()
{
_go32_dpmi_set_protected_mode_interrupt_vector(0x08, &Old_Interrupt);
_go32_dpmi_free_iret_wrapper(&GPS_Interrupt);
outportb(0x43,0x34); // reset clock
outportb(0x40,0xff);
outportb(0x40,0xff);
}
#endif
/*******************************************************************************
FUNCTION chan_allocate()
RETURNS None.
PARAMETERS None.
PURPOSE
This function allocates the channels with PRN numbers
WRITTEN BY
Clifford Kelley
*******************************************************************************/
void chan_allocate()
{
char ch,prnn,alloc;
int i;
// almanac_valid=1;
for (prnn=1;prnn<=32;prnn++)
{
xyz[prnn]=satfind(prnn);
if (gps_alm[prnn].inc>0.0 && gps_alm[prnn].week!=gps_week%1024)
{
almanac_valid=0;
}
}
if (al0==0.0 && b0==0.0)almanac_valid=0;
for (ch=0;ch<N_channels;ch++) // if the sat has dropped below mask angle
// turn the channel off
{
if (xyz[chan[ch].prn].elevation < mask_angle ||
gps_alm[chan[ch].prn].ety == 0.0)
{
chan[ch].state=off;
chan[ch].tow_sync=0;
chan[ch].prn=chan[ch].offset=0;
chan[ch].bit_counter=0;
chan[ch].frame_bit=0;
chan[ch].CNo=0.0;
chan[ch].n_freq=chan[ch].t_count=chan[ch].n_frame=chan[ch].sfid=0;
chan[ch].Pr=chan[ch].dPr=chan[ch].Tropo=chan[ch].Iono=0.0;
chan[ch].TOW=chan[ch].TLM=0;
for (i=0;i<5;i++)chan[ch].word_error[i]=0;
for (i=0;i<1500;i++) chan[ch].message[i]=0;
}
}
for (prnn=1;prnn<=32;prnn++)
{
if (xyz[prnn].elevation > mask_angle && gps_alm[prnn].health==0 &&
gps_alm[prnn].ety != 0.00)
{
alloc=0;
for (ch=0;ch<N_channels;ch++)
{
if (chan[ch].prn==prnn)
{
alloc=1;// satellite already allocated a channel
break;
}
}
if (alloc==0) // if not allocated find an empty channel
{
for (ch=0;ch<N_channels;ch++)
{
reset_cntl(0x1fff);
if (chan[ch].state==off)
{
// calculate carrier clock and doppler correction
chan[ch].carrier_corr=(-xyz[prnn].doppler-
clock_offset*1575.42)/42.57475e-3;
// calculate code clock and doppler correction
code_corr=clock_offset*24.+xyz[prnn].doppler/65.5;
chan[ch].code_freq=code_ref+code_corr;
ch_code(ch,chan[ch].code_freq); // 1.023 MHz chipping rate
ch_cntl(ch,prn_code[prnn]|0xa000); // select satellite
chan[ch].prn=prnn;
// ch_on(ch);
chan[ch].state=acquisition;
chan[ch].codes=0;
chan[ch].bit_counter=0;
chan[ch].frame_bit=0;
chan[ch].n_freq=search_min_f;
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
break;
}
}
}
}
}
}
/*******************************************************************************
FUNCTION cold_allocate()
RETURNS None.
PARAMETERS None.
PURPOSE To allocate the PRNs to channels for a cold start, start by searching
for PRN 1 through 12 and cycling through all PRN numbers skipping channels
that are tracking
WRITTEN BY
Clifford Kelley
*******************************************************************************/
void cold_allocate()
{
satvis dummy;
char ch,i,alloc;
// d_freq=4698; // search 200 Hz intervals
search_max_f=50; // widen the search for a cold start
dummy=satfind(0);
// almanac_valid=1;
reset_cntl(0x1fff);
for (i=1;i<=32;i++)
{
if (gps_alm[i].inc>0.0 && gps_alm[i].week!=gps_week%1024) almanac_valid=0;
}
if (al0==0.0 && b0==0.0)almanac_valid=0;
for (ch=0;ch<N_channels;ch++) // if no satellite is being tracked
// turn the channel off
{
if ( chan[ch].CNo<30.0 )// if C/No is too low turn the channel off
{
chan[ch].state=off;
chan[ch].prn=0;
}
}
for (i=0;i<=chmax;i++)
{
alloc=0;
for (ch=0;ch<N_channels;ch++)
{
if (chan[ch].prn==cold_prn)
{
alloc=1;// satellite is already allocated a channel
break;
}
}
if (alloc==0) // if not allocated find an empty channel
{
for (ch=0;ch<N_channels;ch++)
{
if (chan[ch].state==off)
{
chan[ch].carrier_corr=-clock_offset*1575.42/42.57475e-3;
chan[ch].carrier_freq=carrier_ref+chan[ch].carrier_corr; // set carrier
ch_carrier(ch,chan[ch].carrier_freq); // select carrier
chan[ch].code_freq=code_ref;
ch_code(ch,chan[ch].code_freq); // 1.023 MHz chipping rate
ch_cntl(ch,prn_code[cold_prn]|0xa000);// 0xa000 for late select satellite
chan[ch].prn=cold_prn;
chan[ch].bit_counter=0;
chan[ch].frame_bit=0;
ch_on(ch);
chan[ch].state=acquisition;
chan[ch].codes=0;
chan[ch].n_freq=search_min_f;
chan[ch].del_freq=1;
cold_prn=cold_prn%32+1;
break;
}
}
}
}
}
/*******************************************************************************
FUNCTION read_rcvr_par(void)
RETURNS None.
PARAMETERS None.
PURPOSE To read in from the rcvr_par file the receiver parameters that control
acquisition, tracking etc.
WRITTEN BY
Clifford Kelley
*******************************************************************************/
void read_rcvr_par(void)
{
char intext[40];
if ((in = fopen("rcvr_par.dat", "rt")) == NULL)
{
printf("Cannot open rcvr_par.dat file.\n");
exit(0);
}
else
{
fscanf(in,"%s %s",intext,tzstr);
fscanf(in,"%s %f",intext,&mask_angle);
mask_angle=mask_angle/r_to_d;
fscanf(in,"%s %f",intext,&clock_offset);
fscanf(in,"%s %d",intext,&interr_int);
fscanf(in,"%s %d",intext,&acq_thresh);
fscanf(in,"%s %d",intext,&search_min_f);
fscanf(in,"%s %d",intext,&cold_prn);
fscanf(in,"%s %d",intext,&ICP_CTL);
fscanf(in,"%s %d",intext,&pull_code_k);
fscanf(in,"%s %d",intext,&pull_code_d);
fscanf(in,"%s %d",intext,&pull_carr_k);
fscanf(in,"%s %d",intext,&pull_carr_d);
fscanf(in,"%s %d",intext,&trk_code_k);
fscanf(in,"%s %d",intext,&trk_code_d);
fscanf(in,"%s %d",intext,&trk_carr_k);
fscanf(in,"%s %d",intext,&trk_carr_d);
fscanf(in,"%s %f",intext,&nav_up);
fscanf(in,"%s %d",intext,&pull_in_time);
fscanf(in,"%s %d",intext,&phase_test);
fscanf(in,"%s %d",intext,&d_freq);
fscanf(in,"%s %d",intext,&trk_div);
fscanf(in,"%s %d",intext,&n_of_m_thresh);
fscanf(in,"%s %d",intext,&confirm_m);
fscanf(in,"%s %d",intext,&out_pos);
fscanf(in,"%s %d",intext,&out_vel);
fscanf(in,"%s %d",intext,&out_time);
fscanf(in,"%s %d",intext,&out_kalman);
fscanf(in,"%s %d",intext,&out_debug);
fscanf(in,"%s %d",intext,&out_data);
fscanf(in,"%s %d",intext,&m_tropo);
fscanf(in,"%s %d",intext,&m_iono);
fscanf(in,"%s %d",intext,&align_t);
fscanf(in,"%s %u",intext,&Com0Baud); // NMEA
fscanf(in,"%s %u",intext,&Com1Baud); // NMEA
fscanf(in,"%s %u",intext,&GPGGA); // NMEA
fscanf(in,"%s %u",intext,&GPGSV); // NMEA
fscanf(in,"%s %u",intext,&GPGSA); // NMEA
fscanf(in,"%s %u",intext,&GPVTG); // NMEA
fscanf(in,"%s %u",intext,&GPRMC); // NMEA
fscanf(in,"%s %u",intext,&GPZDA); // NMEA
}
fclose(in);
}
//
// This routine writes out buffer 0 of data bits from each channel
// to file data_bits.dat
//
void write_data_0(void)
{
int i;
if (abs(clock_tow-last_tow)>20)
{
fprintf(data_bits,"%6ld ",clock_tow);
for (i=0;i<12;i++) fprintf(data_bits,"%d,",chan[i].prn);
fprintf(kalm," 0\n");
for (i=0;i<1500;i++)
{
fprintf(data_bits,"%x\n",data_0[i]);
data_0[i]=0;
}
last_tow=clock_tow;
}
}
//
// This routine writes out buffer 1 of data bits from each channel
// to file data_bits.dat
//
void write_data_1(void)
{
int i;
if (abs(clock_tow-last_tow)>20)
{
fprintf(data_bits,"%6ld ",clock_tow);
for (i=0;i<12;i++) fprintf(data_bits,"%d,",chan[i].prn);
fprintf(kalm," 1\n");
for (i=0;i<1500;i++)
{
fprintf(data_bits,"%x\n",data_1[i]);
data_1[i]=0;
}
last_tow=clock_tow;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -