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

📄 gbl_var.h

📁 基于USB接口的GPS应用程序
💻 H
字号:
/******************************************************************/
/* File Description:                                              */
/*  Define macro shared by two or more modules                    */
/*  Define all global variables                                   */
/* Author:                                                        */
/*        Yu Lu                                                   */
/*        luyu1974@gmail.com                                      */
/******************************************************************/

#ifndef _GBL_VAR_H
#define _GBL_VAR_H

#include <syncobjs.hpp>

#define ONE_CH_BUFSIZ 56  // 6*8 + 8  , this number is the size of 6 channel's accum data + status word
#define LENG_OF_ONE_FRAME  (ONE_CH_BUFSIZ*4+128) // this num is the size of all channels' data perframe plus one TIC update
#define CH_NUM  6   //I only can implement 6 channel due to hardware limit
#define DUM_NUM (128 - 16*6 - 4)

#define SEARCH_MAX_F  30
#define SEARCH_MIN_F  -30

// set this macro to zero to disable raw data collection
#define GPS_NAV_RAW_DATA  0      // no stored information
//#define GPS_NAV_RAW_DATA  1    // store compensation for 1ms ambiguity
//#define GPS_NAV_RAW_DATA  2    // store debug info for preamble search
//#define GPS_NAV_RAW_DATA  3    // store raw data for tracking loop

// uncomment them if you want debug info output

//#define GPS_NAV_DBG
//#define GPS_FUNC_DBG

//interval between nav info updates , in 100ms unit 
#define NAV_UPDATE_INT  10   // 20 means 2 sec

#define CONFIRM_THRESHOLD 800.

#define START_TIMER  1
#define STOP_TIMER 0

#define  ACQUISITION 0
#define  CONFIRM    1
#define  PULLIN     2
#define  TRACKING   3
extern const char* STATE_MSG[];

#define  PULLIN_CHECK_TIME  150

#define  PI 3.1415926535898E0

// data struct for sending to GP2021
struct gp2021_reg_struct{
  unsigned char addr;
  unsigned char high;
  unsigned char low;
};

typedef struct gp2021_regs_struct{
  unsigned char flag; // 1: need data rebure ; 0: not need reture data
  unsigned char count;
  struct gp2021_reg_struct regs[41];   // must be less than 41 reg one time due to limiation of uC's XRAM
}gp2021_regs, *PT_gp2021_regs;

// data sturct for reading from GP2021 all 8 channels
typedef struct one_channel_correlation_struct{
        unsigned short code_slew;
        unsigned short code_phase;
        unsigned short ca_cycle_low;
        unsigned short ca_dco_phase;
        unsigned short epoch;
        unsigned short cd_dco_phase;
        unsigned short ca_cycle_high;
        unsigned short epoch_check;
        } one_channel_correlation;

typedef struct one_channel_accm_struct{
          short I_track;
          short Q_track;
          short I_prompt;
          short Q_prompt;
        } one_channel_accm;
typedef struct one_channel_corr_accm_struct{
        one_channel_correlation corr;
        one_channel_accm        accm;
        } one_channel_corr_accm;

typedef struct all_channel_struct{
//        one_channel_correlation  ch_cntl[CH_NUM];
        unsigned short accum_status_c;
        unsigned short meas_status_a;
        unsigned short accum_status_a;
        unsigned short accum_status_b;
        one_channel_accm ch_accm[CH_NUM];

        } all_channel;

typedef struct one_frame_data_struct{
        all_channel  all_ch[4];
        one_channel_correlation  ch_cntl[CH_NUM];
        unsigned char timestamp[4];
        unsigned char dummy[DUM_NUM];
        } one_frame_data;

// data struct used for screendisp thread to update display 
typedef struct display_onech_rawdata_struct{
        char ch_num;
        char prn_num;
        unsigned short code_slew;
        unsigned short code_phase;
        unsigned short carrier_cycle_high;
        unsigned short carrier_cycle_low;
        unsigned short carrier_dco_phase;
        unsigned short code_dco_phase;
        unsigned short epoch;
        short i_track;
        short q_track;
        short i_prompt;
        short q_prompt;
        short freq_off;
} onech_rawdata_disp, *PT_onech_rawdata_disp;

typedef struct display_allch_rawdata_struct{
        onech_rawdata_disp allch_rawdata[CH_NUM];
} allch_rawdata_disp, *PT_allch_rawdata_disp;


typedef struct channel_struct{
        char prn;
        char state;
        int TIC_mscount;
        int code_freq, carrier_freq;
        short code,n_freq,del_freq;
        long double tr_time;//, old_tr_time;
        onech_rawdata_disp rawdata;
        unsigned short  epochchk[4];
        unsigned char  epoch_ref;


        // variables required by CONFIRM
        int  n_confirm, mn_confirm;
        // variables required by PULLIN
        unsigned char valid_data_num;
        short old_prompt_q;
        short prompt_iq[4][2];// at most 4 new accum data one frame, each one contains I,Q
        short track_iq[4][2]; // at most 4 new accum data one frame, each one contains I,Q
        double cd_phase0,cd_phase1;      // code phase discriminator
        double old_theta;      // theta of last frame
        double theta[4];      // carrier phase discriminator
        double total_theta;
        double prompt_mag[4], track_mag[4];

        int pullin_time_idx;
        double delta_theta[PULLIN_CHECK_TIME];
        double pullin_prompt_mag[PULLIN_CHECK_TIME];
        double sum_prompt_mag, sum_delta_theta;
        double mean_p, mean_t;
        int pull_time_count;
        
        // variables required by TRACK

        unsigned int tlm_tst,how_tst,nav_msg[302],msg_count;
        int subframe_i, TOW, TLM;
        double ca_old_phase, ca_phase[4];
        double tic_time; // indicate the time instant of TIC happened
        int ms_count, ms_set, sn_mag_count;
        double tr_time_HOW;
        double q_prompt_20,i_prompt_20,q_track_20,i_track_20;
        double trk_cd_freq;
        double SigNoise, sn_mag_avg;
        double pseudorange;
        double ele;
        double azi;

       } channel;


typedef struct highest_accum_struct{
        int  max_accum_value;
        short   freq_offset;
        short   dco_phs_offset;
        } highest_accum, *PT_highest_accum;

typedef struct channel_disp_struct{
        int prn_num;
        char state_info;
        double freq_off;
        double SigNoise;
        double pseudorange;
        int frm_idx;
        int tow;
        int tlm;
        double ele;
        double azi;
        }channel_disp, *PT_channel_disp ;

typedef struct navinfo_disp_struct{
        double ECEFpos[3];
        double NEDpos[3];
        double ECEFvel[3];
        double NEDvel[3];
        double rcv_time;
        double clk_bias;
        double GDOP;
        double HDOP;
        double VDOP;
        double PDOP;
        double TDOP;
        }navinfo_disp, *PT_navinfo_disp;

// struct used to transfer pseudorange, ele, azi from gpsfunc to gpsnav  class        
typedef struct navresult_channel_struct{
        int prn;
        bool valid;
        double pseudorange;
        double ele;
        double azi;
        }navresult_channel, *PT_navresult_channel;
extern navresult_channel  allch_navresult[CH_NUM];

// struct used to transfer msg from GPSNAV to GPSFUNC

typedef struct navmsg_struct{
        bool newdata;
        unsigned char prn;
        unsigned int index;
        unsigned int msg[302];
        }navmsg, *PT_navmsg;

extern navmsg allch_navmsg[CH_NUM];

// struct used to pass prn # and transfer bit time

typedef struct transtime_struct{
        int prn;
        long double tr_time;
        double  dopp_f;
}transtime;
typedef struct allch_transtime_struct{
        int ch_count;
        transtime ch_transtime[CH_NUM];
        }allch_transtime, *PT_allch_transtime;
extern allch_transtime  allchtrtime;        

extern bool newmsg_rdy;
extern bool eph_valid[33];

typedef struct sat_tr_pos_struct{
        long double delta_time;
        double pos[3];
        double vel[3];
        double doppler_freq;
        }sat_tr_pos;

// struct for 5 subframe of nav message, & parity check result for subframe

typedef struct navmsg_par_struct{
        unsigned int msg[5][10];
        unsigned int par[5];
        }navmsg_par, *PT_navmsg_par;

typedef struct  AlmInfo_struct  {	/*  Formatted Almanac data  */
  int	SatId;          /* Satellite number */
  int     WeekNo;       /* Week number for this sat data */
  double  Af1;
  double  Af0;
  double  M0;           /* Mean anomaly at reference time */
                        /* Angle of sat pos from perigee */
  double  Omega;        /* Argument of perigee */
  double  Omega0;       /* Right ascension (precession) at Toa */
  double  SqrtA;        /* A = semi major axis */
  double  OmegaDot;     /* Rate of right ascension */
  double  DeltaI;       /* Correction to standard inclination */
  double  Toa;          /* Reference time of almanac */
  double  E;            /* Eccentricity */
  int    Health;        /* Status of this satellite */
  double ECEF_Pos[3];
  double Ele, Azm, Dopp;
} AlmInfo;

typedef struct EphInfo_struct{        // Precise orbital parameters
 int valid;

 int iode;     /*Issue of Data(Ephemeris)   */
 int iodc;     /*Issue of Clock(Data)       */
 int ura;      /* SV Accuracy */
 int health;   /* SV Health */
 int week;     /* GPS Week */

 double dn;    /*Mean motion difference from computed value */
 double tgd;   /* L1-L2  correction term */
 double toe;   /*Reference time ephemeris */
 double toc;   /* clock data reference time in seconds */
 double omegadot; /*Rrate of right ascension */
 double idot;  /* Rate of inclination angle */
 double cuc,cus,crc,crs,cic,cis;  /* Harmonic correction terms */
 double ma;    /* mean anomaly at reference time */
 double ety;     /* Eccentricity */
 double sqra;  /* square root of the semi-major Axis */
 double w0;    /* Longitude of ascending node of orbit plane at weekly epoch */
 double inc0;  /* Inclination angle at reference time */
 double w;     /* argument of perigee */
 double wm;    /* mean angular velocity of sat, called Mean Motion */
 double af0,af1,af2; /* Apparent SV clock correction terms */
 double bclk;

} EphInfo;

// definition of event to be used between samplign thread and update screen thread
extern HANDLE newdataEvent;
extern HANDLE gpsEvent;
extern HANDLE dispEvent;

//definition of critical section to sync gpsfunc and gpsnav thread

extern CRITICAL_SECTION GpsCriticalSection;

//------------------------------------------------------------------------------
/* Error code definition for GPS_Nav class                                    */
#define GPS_NAV_SUCCESS   0
#define GPS_NAV_FILEOPENERR 1

extern const char* GPS_NAV_MSG[];

/* Error code definition for IoInterface class                                */
#define IOINTERFACE_SUCCESS 0
#define IOINTERFACE_FILEOPENERR 1

extern const char* IOINTERFACE_MSG[];

extern int GpsWeek;
#endif

⌨️ 快捷键说明

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