Class: Net::NTP::Response
- Inherits:
-
Object
- Object
- Net::NTP::Response
- Defined in:
- lib/net/ntp/ntp.rb
Instance Attribute Summary collapse
-
#client_time_receive ⇒ Object
readonly
Returns the value of attribute client_time_receive.
Instance Method Summary collapse
-
#initialize(raw_data, client_time_receive) ⇒ Response
constructor
A new instance of Response.
- #leap_indicator ⇒ Object
- #leap_indicator_text ⇒ Object
- #mode ⇒ Object
- #mode_text ⇒ Object
-
#offset ⇒ Object
As described in tools.ietf.org/html/rfc958.
- #originate_timestamp ⇒ Object
- #poll_interval ⇒ Object
- #precision ⇒ Object
- #receive_timestamp ⇒ Object
- #reference_clock_identifier ⇒ Object
- #reference_clock_identifier_text ⇒ Object
- #reference_timestamp ⇒ Object
- #root_delay ⇒ Object
- #root_dispersion ⇒ Object
- #stratum ⇒ Object
- #stratum_text ⇒ Object
- #time ⇒ Object
- #transmit_timestamp ⇒ Object
- #version_number ⇒ Object
Constructor Details
#initialize(raw_data, client_time_receive) ⇒ Response
Returns a new instance of Response.
107 108 109 110 111 |
# File 'lib/net/ntp/ntp.rb', line 107 def initialize(raw_data, client_time_receive) @raw_data = raw_data @client_time_receive = client_time_receive @packet_data_by_field = nil end |
Instance Attribute Details
#client_time_receive ⇒ Object (readonly)
Returns the value of attribute client_time_receive.
105 106 107 |
# File 'lib/net/ntp/ntp.rb', line 105 def client_time_receive @client_time_receive end |
Instance Method Details
#leap_indicator ⇒ Object
113 114 115 |
# File 'lib/net/ntp/ntp.rb', line 113 def leap_indicator @leap_indicator ||= (packet_data_by_field[:byte1].bytes.first & 0xC0) >> 6 end |
#leap_indicator_text ⇒ Object
117 118 119 |
# File 'lib/net/ntp/ntp.rb', line 117 def leap_indicator_text @leap_indicator_text ||= LEAP_INDICATOR[leap_indicator] end |
#mode ⇒ Object
125 126 127 |
# File 'lib/net/ntp/ntp.rb', line 125 def mode @mode ||= (packet_data_by_field[:byte1].bytes.first & 0x07) end |
#mode_text ⇒ Object
129 130 131 |
# File 'lib/net/ntp/ntp.rb', line 129 def mode_text @mode_text ||= MODE[mode] end |
#offset ⇒ Object
As described in tools.ietf.org/html/rfc958
186 187 188 |
# File 'lib/net/ntp/ntp.rb', line 186 def offset @offset ||= ( - + - client_time_receive) / 2.0 end |
#originate_timestamp ⇒ Object
169 170 171 |
# File 'lib/net/ntp/ntp.rb', line 169 def @originate_timestamp ||= (packet_data_by_field[:org_time] + bin2frac(packet_data_by_field[:org_time_fb])) end |
#poll_interval ⇒ Object
141 142 143 |
# File 'lib/net/ntp/ntp.rb', line 141 def poll_interval @poll_interval ||= packet_data_by_field[:poll] end |
#precision ⇒ Object
145 146 147 |
# File 'lib/net/ntp/ntp.rb', line 145 def precision @precision ||= packet_data_by_field[:precision] - 255 end |
#receive_timestamp ⇒ Object
173 174 175 |
# File 'lib/net/ntp/ntp.rb', line 173 def @receive_timestamp ||= ((packet_data_by_field[:recv_time] + bin2frac(packet_data_by_field[:recv_time_fb])) - NTP_ADJ) end |
#reference_clock_identifier ⇒ Object
157 158 159 |
# File 'lib/net/ntp/ntp.rb', line 157 def reference_clock_identifier @reference_clock_identifier ||= unpack_ip(packet_data_by_field[:stratum], packet_data_by_field[:ident]) end |
#reference_clock_identifier_text ⇒ Object
161 162 163 |
# File 'lib/net/ntp/ntp.rb', line 161 def reference_clock_identifier_text @reference_clock_identifier_text ||= REFERENCE_CLOCK_IDENTIFIER[reference_clock_identifier] end |
#reference_timestamp ⇒ Object
165 166 167 |
# File 'lib/net/ntp/ntp.rb', line 165 def @reference_timestamp ||= ((packet_data_by_field[:ref_time] + bin2frac(packet_data_by_field[:ref_time_fb])) - NTP_ADJ) end |
#root_delay ⇒ Object
149 150 151 |
# File 'lib/net/ntp/ntp.rb', line 149 def root_delay @root_delay ||= bin2frac(packet_data_by_field[:delay_fb]) end |
#root_dispersion ⇒ Object
153 154 155 |
# File 'lib/net/ntp/ntp.rb', line 153 def root_dispersion @root_dispersion ||= packet_data_by_field[:disp] end |
#stratum ⇒ Object
133 134 135 |
# File 'lib/net/ntp/ntp.rb', line 133 def stratum @stratum ||= packet_data_by_field[:stratum] end |
#stratum_text ⇒ Object
137 138 139 |
# File 'lib/net/ntp/ntp.rb', line 137 def stratum_text @stratum_text ||= STRATUM[stratum] end |
#time ⇒ Object
181 182 183 |
# File 'lib/net/ntp/ntp.rb', line 181 def time @time ||= Time.at() end |
#transmit_timestamp ⇒ Object
177 178 179 |
# File 'lib/net/ntp/ntp.rb', line 177 def @transmit_timestamp ||= ((packet_data_by_field[:trans_time] + bin2frac(packet_data_by_field[:trans_time_fb])) - NTP_ADJ) end |
#version_number ⇒ Object
121 122 123 |
# File 'lib/net/ntp/ntp.rb', line 121 def version_number @version_number ||= (packet_data_by_field[:byte1].bytes.first & 0x38) >> 3 end |