前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >nmealib解析-----(3)---

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

作者头像
py3study
发布2020-01-08 14:47:58
6900
发布2020-01-08 14:47:58
举报
文章被收录于专栏:python3python3
代码语言:javascript
复制
/*
 *
 * 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

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-09-13 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档