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

📄 ntptime.h

📁 基于SNTP协议的时间同步客户端的c代码。其中计算传输时间偏移和同步误差都在客户端实现。可顺利移植到DSP上
💻 H
字号:

#ifndef  _NTP_TIME
#define  _NTP_TIME 

#include <windows.h>
#include <assert.h>
#include "datatype.h"

static double NTP_FRACTIONAL_TO_MS = (((double)1000.0)/0xFFFFFFFF); ;
static double NTP_TO_SECOND = (((double)1.0)/0xFFFFFFFF);
static long JAN_1ST_1900 = 2415021;
ulong  m_dwTimeout;
ulong m_Ms2NTP[1000];
//Representation of an NTP timestamp

typedef struct 
{
	ulong m_dwInteger;
	ulong m_dwFractional;  // 2 packets of 32bit,one is integer part,the other is frantional part 
}CNtpTimePacket;

//General functions

SYSTEMTIME CNtpTimePacket2Systemtime(CNtpTimePacket pNtpTime);
double CNtpTimePacket2Double(CNtpTimePacket pNtpTime);
CNtpTimePacket Double2CNtpTimePacket(double f);
CNtpTimePacket Systemtime2CNtpTimePacket(SYSTEMTIME st);

ulong Ms2NtpFraction(u16_t wMilliSeconds);
u16_t NtpFraction2Ms(ulong dwFraction);
double NtpFraction2Second(ulong dwFraction);
long GetJulianDay(u16_t Year, u16_t Month, u16_t Day);

CNtpTimePacket myGetCurrentTime();

CNtpTimePacket host2network(CNtpTimePacket ntp);
CNtpTimePacket network2host(CNtpTimePacket packet);


int Create();
int Connect(const SOCKADDR* lpSockAddr, int nSockAddrLen);
int Send(LPCSTR pszBuf, int nBuf);
int IsReadible(int bReadible, ulong dwTimeout);
int Receive(LPSTR pszBuf, int nBuf);
void Close();
int  SetClientTime(newTime);

 
#endif 

⌨️ 快捷键说明

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