summaryrefslogtreecommitdiff
path: root/FreeRTOS-Labs/Demo/Common/Demo_IP_Protocols/include/NTPClient.h
blob: 813539e6e7e84876959d8a75759aa2ea50b3a3f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
//	ntpClient.h
//

#ifndef	__NTPCLIENT_H__

#define __NTPCLIENT_H__

#define NTP_PORT	123

typedef uint32_t quint32;
typedef int32_t qint32;
typedef uint8_t quint8;
typedef int8_t qint8;

typedef union _SNtpFlags  SNtpFlags;

/**
 * 64-bit NTP timestamp.
 */
struct __attribute__ ((__packed__)) _SNtpTimestamp {
  /** Number of seconds passed since Jan 1 1900, in big-endian format. */
  quint32 seconds;

  /** Fractional time part, in <tt>1/0xFFFFFFFF</tt>s of a second. */
  quint32 fraction;
};

typedef struct _SNtpTimestamp SNtpTimestamp;
/**
 * Mandatory part of an NTP packet
 */
struct SNtpPacket {
  /** Flags. */
  unsigned char flags;  // value 0xDB : mode 3 (client), version 3, leap indicator unknown 3

  /** Stratum of the clock. */
  quint8 stratum;  // value 0 : unspecified

  /** Maximum interval between successive messages, in log2 seconds. Note that the value is signed. */
  qint8 poll;  // 10 means 1 << 10 = 1024 seconds

  /** Precision of the clock, in log2 seconds. Note that the value is signed. */
  qint8 precision; // 0xFA = 250 = 0.015625 seconds

  /** Round trip time to the primary reference source, in NTP short format. */
  qint32 rootDelay; // 0x5D2E = 23854 or (23854/65535)= 0.3640 sec

  /** Nominal error relative to the primary reference source. */
  qint32 rootDispersion; // 0x0008 CAC8 = 8.7912  seconds

  /** Reference identifier (either a 4 character string or an IP address). */
  qint8 referenceID[4]; // or just 0000

  /** The time at which the clock was last set or corrected. */
  SNtpTimestamp referenceTimestamp; // Current time

  /** The time at which the request departed the client for the server. */
  SNtpTimestamp originateTimestamp; // Keep 0

  /** The time at which the request arrived at the server. */
  SNtpTimestamp receiveTimestamp; // Keep 0

  /** The time at which the reply departed the server for client. */
  SNtpTimestamp transmitTimestamp;
};

/* Add this number to get secs since 1-1-1900 */
#define TIME1970 2208988800UL

#endif // __NTPCLIENT_H__