📄 gpsfunc.h
字号:
/******************************************************************/
/* File Description: */
/* Header file for Gps_func class */
/* Processing nav message and pseudorange, position calculation etc. */
/* Author: */
/* Yu Lu */
/* luyu1974@gmail.com */
/******************************************************************/
#ifndef _GPSFUNC_H
#define _GPSFUNC_H
#include <fstream.h>
#include <ostream>
#include <time.h>
#include <stdio.h>
#include "gbl_var.h"
#include "GpsThrd.h"
// here is some background info
/*
Definition of a Yuma Almanac
----------------------------
ID: PRN of the SVN
Health: 000=usable
Eccentricity: This shows the amount of the orbit deviation
from circular (orbit). It is the distance between the
foci divided by the length of the semi-major axis
(our orbits are very circular).
Time of Applicability: The number of seconds in the orbit
when the almanac was generated. Kind of a time tag.
Orbital Inclination: The angle to which the SV orbit meets
the equator (GPS is at approx. 55 degrees). Roughly, the
SV's orbit will not rise above approx. 55 degrees latitude.
The number is part of an equation: #= degrees/180 = the
true inclination.
Rate of Right Ascension: Rate of change in the measurement
of the angle of right ascension as defined in the Right
Ascension mnemonic.
SQRT(A) Square Root of Semi-Major Axis: This is defined
as the measurement from the center of the orbit to either
the point of apogee or the point of perigee.
Right Ascension at Time of Almanac (TOA): Right Ascensions
an angular measurement from the vernal equinox.
Argument of Perigee: An angular measurement along the
orbital path measured from the ascending node to the
point of perigee, measured in the direction of the SV's
motion.
Mean Anomaly: Angle (arc) traveled past the longitude of
ascending node (value= 0-180 degrees or 0-negative 180
degrees). If the value exceeds 180 degrees, subtract
360 degrees to find the mean anomaly. When the SV has
passed perigee and heading towards apogee, the mean
anomaly is positive. After the point of apogee, the
mean anomaly value will be negative to the point of perigee.
Af(0): SV clock bias in seconds
Af(1): SV clock Drift in seconds per seconds
week: GPS week (0-1024), every 7 days since 6 Jan 1980/0000z
*/
class GPS_Func{
private:
#ifdef GPS_FUNC_DBG
ofstream debugfile;
#endif
// binary constants for nav message decoding
//
static const double c_2p12;// = 4096;
static const double c_2p4;// = 16;
static const double c_2m5;// = 0.03125;
static const double c_2m11;// = 4.8828125e-4;
static const double c_2m19;// = 1.9073486328125e-6;
static const double c_2m20;// = 9.5367431640625e-7;
static const double c_2m21;// = 4.76837158203125e-7;
static const double c_2m23;// = 1.19209289550781e-7;
static const double c_2m24;// = 5.96046447753906e-8;
static const double c_2m27;// = 7.45058059692383e-9;
static const double c_2m29;// = 1.86264514923096e-9;
static const double c_2m30;// = 9.31322574615479e-10;
static const double c_2m31;// = 4.65661287307739e-10;
static const double c_2m33;// = 1.16415321826935E-10;
static const double c_2m38;// = 3.63797880709171e-12;
static const double c_2m43;// = 1.13686837721616e-13;
static const double c_2m50;// = 8.881784197e-16;
static const double c_2m55;// = 2.77555756156289e-17;
static const double lambda; //=.1902936728; // L1 wavelength in meters
//for parity check calculation use
static const int pb1=0x3b1f3480,pb2=0x1d8f9a40,pb3=0x2ec7cd00;
static const int pb4=0x1763e680,pb5=0x2bb1f340,pb6=0x0b7a89c0;
static const int SatMax = 32;
static const char* const ALM_ID_STR;// ="ID:";
static const char* const ALM_HEALTH_STR;//="Health:";
static const char* const ALM_ECCEN_STR;//="Eccentricity:";
static const char* const ALM_TIME_STR;//="Time of Applicability(s):";
static const char* const ALM_ORB_STR;//="Orbital Inclination(rad):";
static const char* const ALM_RRA_STR;//="Rate of Right Ascen(r/s):";
static const char* const ALM_SQRTA_STR;//="SQRT(A) (m 1/2):";
static const char* const ALM_RAAW_STR;//="Right Ascen at Week(rad):";
static const char* const ALM_AOP_STR;//="Argument of Perigee(rad):";
static const char* const ALM_MA_STR;//="Mean Anom(rad):";
static const char* const ALM_AF0_STR;//="Af0(s):";
static const char* const ALM_AF1_STR;//="Af1(s/s):";
static const char* const ALM_WK_STR;//="week:";
static const int SecPerHour=3600;
static const int SecPerDay=86400;
static const int SecPerWeek=604800;
static const double SemiMajorAxis,
EccentrSquared,
OneMinusEccentrSquared,
OmegaDotEarth,
SpeedOfLight;
double ECEFuserpos[3], NEDuserpos[3]; // this is the result form GPS navigation algorithm
double ECEFvel[3];
double clk_bias;
double AccurateTime; // user's time when last TIC happensed
double pdop,tdop,hdop,vdop,gdop; // dops definition
unsigned int nav_msg[CH_NUM][10], p_error[CH_NUM];
unsigned char ch_prn[CH_NUM]; // indicate prn allocation
navmsg_par navmsgparity[CH_NUM];
int prev_bit[2];
AlmInfo Almanac[SatMax+1];
EphInfo Ephemeris[SatMax+1];
GpsThrd* gpsthrd;
bool thrdtermed;
double UserPos[3];
/* Parameters for the transformation to the local tangent plane */
double PlaneCE, PlaneET1, PlaneET2, PlaneNT1, PlaneNT2;
double PlaneUTx, PlaneUTy, PlaneUTz;
void SelectPrn(int*);
void readOneChMsg(int);
void parity_check(int);
void read_allsubframe(int);
void resolve_PVT(void);
public:
GPS_Func();
~GPS_Func();
void SetUserPos( double*);
void ConvertToECEF( double *, double *);
void ConvertToLongLatAlt( double *, double *);
long double CalcJulianDay(int , int ,int ,int ,int, int);
long double CalcJulianDay(struct tm *);
int CalcGpsWeek(long double );
int CalcToW( long double );
void SatPosECEFAlminfo(AlmInfo *, double, int, double *);
void SatPosECEFEphinfo(EphInfo *, double, int, double *);
void GetSatPos( int , double);
void SatElevAndAzimuth( int, double *, double, int);
void process_allsat(double, int);
int CalcPrnSetting( int *, struct tm*, FILE*, double* );
void read_almparam(AlmInfo *, FILE *);
void ReadAlm(FILE *);
void get_gpsweek(void);
void processMsg(void);
void get_navinfo( PT_navinfo_disp);
void CreateGpsThrd(void);
void TerminateThrd(void);
void SetThrdStatus(bool);
bool NavThrdIsTermed();
};
const double GPS_Func::SemiMajorAxis=6378137.0L;
const double GPS_Func::EccentrSquared=0.00669437999L;
const double GPS_Func::OneMinusEccentrSquared=0.993305620010000L;
const double GPS_Func::OmegaDotEarth=7.292115146E-5L;
const double GPS_Func::SpeedOfLight = 2.99792458e8;
const char* const GPS_Func::ALM_ID_STR ="ID:";
const char* const GPS_Func::ALM_HEALTH_STR="Health:";
const char* const GPS_Func::ALM_ECCEN_STR="Eccentricity:";
const char* const GPS_Func::ALM_TIME_STR="Time of Applicability(s):";
const char* const GPS_Func::ALM_ORB_STR="Orbital Inclination(rad):";
const char* const GPS_Func::ALM_RRA_STR="Rate of Right Ascen(r/s):";
const char* const GPS_Func::ALM_SQRTA_STR="SQRT(A) (m 1/2):";
const char* const GPS_Func::ALM_RAAW_STR="Right Ascen at Week(rad):";
const char* const GPS_Func::ALM_AOP_STR="Argument of Perigee(rad):";
const char* const GPS_Func::ALM_MA_STR="Mean Anom(rad):";
const char* const GPS_Func::ALM_AF0_STR="Af0(s):";
const char* const GPS_Func::ALM_AF1_STR="Af1(s/s):";
const char* const GPS_Func::ALM_WK_STR="week:" ;
// binary constants for nav message decoding
const double GPS_Func::c_2p12 = 4096;
const double GPS_Func::c_2p4 = 16;
const double GPS_Func::c_2m5 = 0.03125;
const double GPS_Func::c_2m11 = 4.8828125e-4;
const double GPS_Func::c_2m19 = 1.9073486328125e-6;
const double GPS_Func::c_2m20 = 9.5367431640625e-7;
const double GPS_Func::c_2m21 = 4.76837158203125e-7;
const double GPS_Func::c_2m23 = 1.19209289550781e-7;
const double GPS_Func::c_2m24 = 5.96046447753906e-8;
const double GPS_Func::c_2m27 = 7.45058059692383e-9;
const double GPS_Func::c_2m29 = 1.86264514923096e-9;
const double GPS_Func::c_2m30 = 9.31322574615479e-10;
const double GPS_Func::c_2m31 = 4.65661287307739e-10;
const double GPS_Func::c_2m33 = 1.16415321826935E-10;
const double GPS_Func::c_2m38 = 3.63797880709171e-12;
const double GPS_Func::c_2m43 = 1.13686837721616e-13;
const double GPS_Func::c_2m50 = 8.881784197e-16;
const double GPS_Func::c_2m55 = 2.77555756156289e-17;
const double GPS_Func::lambda =.1902936728;
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -