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

📄 clock.c

📁 GPS导航定位程序
💻 C
字号:
#include "includes.h"

/****************************************************************************    
* Function: void SetClockModel(void)
*
* Sets up the clock model at the start of the program based on the PC date
* and time.
*
* Input: None.
*
* Output: None.
*
* Return Value: None.
****************************************************************************/
void SetClockModel(void)
{
    int year,month,day,hour,minute,second;

    long time_now;
    
    unsigned long current_TIC;

    int gps_week;
    double gps_second;

    struct tm *tm_now;

    /* Obtain the program start time from the PC. */

    time(&time_now);
    CurrentTIC(&current_TIC);
    tm_now = localtime(&time_now);
    year = tm_now->tm_year + 1900;
    month = tm_now->tm_mon + 1;
    day = tm_now->tm_mday;
    hour = tm_now->tm_hour;
    minute = tm_now->tm_min;
    second = tm_now->tm_sec;

    /* Convert Gregorian y/m/d hh:mm:ss to GPS week and seconds. */

    GregorianDateToGpsTime(year,month,day,hour,minute,second,
                           &gps_week,&gps_second);

    /* Estimate GPS time at TIC=0 and initialize the current clock model. */

    CurClkModel.Zwk = gps_week;
    CurClkModel.Zsec = gps_second
                       - SECONDS_IN_HOUR*TimeZone
                       - current_TIC*TIC_PERIOD;

    while(CurClkModel.Zsec<0.0)
    {
        CurClkModel.Zwk--;
        CurClkModel.Zsec += SECONDS_IN_WEEK;
    }
    while(CurClkModel.Zsec>=SECONDS_IN_WEEK)
    {
        CurClkModel.Zwk++;
        CurClkModel.Zsec -= SECONDS_IN_WEEK;
    }
}

/****************************************************************************    
* Function: void OscillatorAccuracy(void)
*
* Updates the current estimate of the oscillator error.
*
* Input: None.
*
* Output: None.
*
* Return Value: None.
****************************************************************************/
void OscillatorAccuracy(void)
{
    unsigned long ctic;
    double dt;
    clockmodelstruc CLK;

    /* Obtain an updated local copy of the current clock model. */

    PROTECT++;
    CLK = CurClkModel;
    PROTECT--;

    /* Estimate current oscillator accuracy as three times the RMS clock
       error determined from navigation plus the maximum error buildup rate
       times the number of seconds since the last navigation solution.  Peg
       this at the user-specified maximum oscillator error. */

    CurrentTIC(&ctic);
    dt = labs(ctic-CLK.RCOtic) * TIC_PERIOD;
    if(CLK.VARClkError>1.0E-6)
        OscAcc = 3.0*sqrt(CLK.VARClkError) + dt*OscFreqChgRate;
    else
        OscAcc = dt*OscFreqChgRate;
    if(OscAcc > InitOscAcc)
        OscAcc = InitOscAcc;
}

⌨️ 快捷键说明

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