API Documentation
Loading...
Searching...
No Matches
NtpReply.h
Go to the documentation of this file.
1#pragma once
2
3#include <cmath> /* For std::pow. */
4
5#include <QtCore/QDateTime>
6#include <NDEVR/Time.h>
7#include <NDEVR/TimeSpan.h>
8
9/**
10 * NTP reply.
11 */
12namespace NDEVR
13{
14 class NtpReply {
15 public:
16 /**
17 * Default constructor, constructs a null NTP reply.
18 */
20
21 /**
22 * Constructs an NTP reply given an NTP packet and current time.
23 *
24 * @param packet NTP packet.
25 * @param destinationTime Time at the client when the reply arrived from the server.
26 */
28 m_packet(packet),
29 m_destinationTime(destinationTime)
30 {}
31
32 /**
33 * @returns Leap indicator.
34 */
36 return static_cast<NtpLeapIndicator>(m_packet.basic.flags.leapIndicator);
37 }
38
39 /**
40 * @returns NTP version number.
41 */
42 quint8 versionNumber() const {
43 return m_packet.basic.flags.versionNumber;
44 }
45
46 /**
47 * @returns Ntp mode.
48 */
49 NtpMode mode() const {
50 return static_cast<NtpMode>(m_packet.basic.flags.mode);
51 }
52
53 /**
54 * @returns Stratum.
55 */
56 quint8 stratum() const {
57 return m_packet.basic.stratum;
58 }
59
60 /**
61 * @returns Maximum interval between successive messages, in seconds.
62 */
63 qreal pollInterval() const {
64 return std::pow(static_cast<qreal>(2), static_cast<qreal>(m_packet.basic.poll));
65 }
66
67 /**
68 * @returns Clock precision, in seconds.
69 */
70 qreal precision() const {
71 return std::pow(static_cast<qreal>(2), static_cast<qreal>(m_packet.basic.precision));
72 }
73
74 /**
75 * @returns Time when the system clock was last set or corrected.
76 */
78 return m_packet.basic.referenceTimestamp.toTime();
79 }
80
81 /**
82 * @returns Time at the client when the request departed for the server.
83 */
84 Time originTime() const {
85 return m_packet.basic.originateTimestamp.toTime();
86 }
87
88 /**
89 * @returns Time at the server when the request arrived from the client.
90 */
91 Time receiveTime() const {
92 return m_packet.basic.receiveTimestamp.toTime();
93 }
94
95 /**
96 * @returns Time at the server when the response left for the client.
97 */
99 return m_packet.basic.transmitTimestamp.toTime();
100 }
101
102 /**
103 * @returns Time at the client when the reply arrived from the server.
104 */
106 return m_destinationTime;
107 }
108
109 /**
110 * @return Raw NTP reply, for the curious user.
111 */
112 const NtpFullPacket& rawData() const {
113 return m_packet;
114 }
115
116 private:
117 NtpFullPacket m_packet;
118 Time m_destinationTime;
119 };
120}
Definition NtpReply.h:14
Time referenceTime() const
Definition NtpReply.h:77
NtpMode mode() const
Definition NtpReply.h:49
Time transmitTime() const
Definition NtpReply.h:98
NtpLeapIndicator leapIndicator() const
Definition NtpReply.h:35
Time originTime() const
Definition NtpReply.h:84
quint8 stratum() const
Definition NtpReply.h:56
Time receiveTime() const
Definition NtpReply.h:91
quint8 versionNumber() const
Definition NtpReply.h:42
const NtpFullPacket & rawData() const
Definition NtpReply.h:112
Time destinationTime() const
Definition NtpReply.h:105
qreal pollInterval() const
Definition NtpReply.h:63
NtpReply()
Definition NtpReply.h:19
NtpReply(NtpFullPacket packet, Time destinationTime)
Definition NtpReply.h:27
qreal precision() const
Definition NtpReply.h:70
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:54
Definition ACIColor.h:37
NtpLeapIndicator
Definition NtpEnums.h:7
NtpMode
Definition NtpEnums.h:17
Definition NtpPacket.h:80
NtpPacket basic
Definition NtpPacket.h:81
unsigned char leapIndicator
Definition NtpPacket.h:20
unsigned char versionNumber
Definition NtpPacket.h:16
unsigned char mode
Definition NtpPacket.h:13
qint8 poll
Definition NtpPacket.h:37
qint8 precision
Definition NtpPacket.h:40
NtpTimestamp receiveTimestamp
Definition NtpPacket.h:58
NtpTimestamp transmitTimestamp
Definition NtpPacket.h:61
NtpPacketFlags flags
Definition NtpPacket.h:31
NtpTimestamp referenceTimestamp
Definition NtpPacket.h:52
NtpTimestamp originateTimestamp
Definition NtpPacket.h:55
quint8 stratum
Definition NtpPacket.h:34
Time toTime() const
Definition NtpTimestamp.h:41