nmealib解析-----(3)---

发布时间:2019-09-13 09:31:32编辑:auto阅读(2220)

    /*
     *
     * NMEA library
     * URL: http://nmea.sourceforge.net
     * Author: Tim (xtimor@gmail.com)
     * Licence: http://www.gnu.org/licenses/lgpl.html
     * $Id: time.h 4 2007-08-27 13:11:03Z xtimor $
     *
     */
    /*! \file */
    //该函数主要是对于nmea时间的处理
    #ifndef __NMEA_TIME_H__
    #define __NMEA_TIME_H__
    #include "config.h"
    #ifdef  __cplusplus
    extern "C" {
    #endif
    /**
     * Date and time data
     * @see nmea_time_now
     */
    typedef struct _nmeaTIME
    {
        int     year;       /**< Years since 1900 */
        int     mon;        /**< Months since January - [0,11] */  //这里竟然是0-11,而不是1-12
        int     day;        /**< Day of the month - [1,31] */
        int     hour;       /**< Hours since midnight - [0,23] */
        int     min;        /**< Minutes after the hour - [0,59] */
        int     sec;        /**< Seconds after the minute - [0,59] */
        int     hsec;       /**< Hundredth part of second - [0,99] */
    } nmeaTIME;
    /**
     * \brief Get time now to nmeaTIME structure
     */
    void nmea_time_now(nmeaTIME *t);  //获得这个格式的时间
    #ifdef  __cplusplus
    }
    #endif
    #endif /* __NMEA_TIME_H__ */
     
     
     
    /*
     *
     * NMEA library
     * URL: http://nmea.sourceforge.net
     * Author: Tim (xtimor@gmail.com)
     * Licence: http://www.gnu.org/licenses/lgpl.html
     * $Id: time.c 4 2007-08-27 13:11:03Z xtimor $
     *
     */
    /*! \file time.h */
    #include "nmea/time.h"
    #ifdef NMEA_WIN
    #   pragma warning(disable: 4201)   //对于这个用法不熟的可参考http://no001.blog.51cto.com/1142339/354181
    #   pragma warning(disable: 4214)
    #   pragma warning(disable: 4115)
    #   include <windows.h>
    #   pragma warning(default: 4201)
    #   pragma warning(default: 4214)
    #   pragma warning(default: 4115)
    #else
    #   include <time.h>
    #endif
    #ifdef NMEA_WIN              //充分利用宏定义。对于window.h函数库不熟,这个不是标准的c函数库,是widows的库
    void nmea_time_now(nmeaTIME *stm)
    {
        SYSTEMTIME st;
        GetSystemTime(&st);
        stm->year = st.wYear - 1900;
        stm->mon = st.wMonth - 1;   //月份-1,,,0-11
        stm->day = st.wDay;
        stm->hour = st.wHour;
        stm->min = st.wMinute;
        stm->sec = st.wSecond;
        stm->hsec = st.wMilliseconds / 10;
    }
    #else /* NMEA_WIN */    //这个地方,直接都使用<time.h>不就行了吗?既然time是标准的c函数,那个windows中肯定也有,那么为什么还要再单独调用window.h呢?
    void nmea_time_now(nmeaTIME *stm)
    {
        time_t lt;
        struct tm *tt;
        time(&lt);
        tt = gmtime(&lt);
        stm->year = tt->tm_year;
        stm->mon = tt->tm_mon;
        stm->day = tt->tm_mday;
        stm->hour = tt->tm_hour;
        stm->min = tt->tm_min;
        stm->sec = tt->tm_sec;
        stm->hsec = 0;
    }
    #endif

关键字