Class: CodinRep::SetTime

Inherits:
Command show all
Defined in:
lib/codin_rep/set_time.rb

Constant Summary collapse

COMMAND_CODE =
"016A".freeze
EXPECTED_HEADER =
'REP008A'.freeze

Constants inherited from Command

Command::COMMAND_PREFIX

Instance Method Summary collapse

Methods inherited from Command

#execute, #generate_header, #get_max_attempts, #get_timeout_time, #should_close_connection?

Constructor Details

#initialize(time, *args) ⇒ SetTime

Returns a new instance of SetTime.



28
29
30
31
# File 'lib/codin_rep/set_time.rb', line 28

def initialize(time, *args)
  super(*args)
  @time = time
end

Instance Method Details

#check_response_headerObject



41
42
43
44
45
# File 'lib/codin_rep/set_time.rb', line 41

def check_response_header
  unless @response.match(/^#{EXPECTED_HEADER}/)
    raise UnknownHeader.new @response[0..6], 'set time', EXPECTED_HEADER
  end
end

#generate_command_payloadObject



33
34
35
# File 'lib/codin_rep/set_time.rb', line 33

def generate_command_payload
  CodinRep::TimeUtil.pack @time
end

#get_data_from_response_payloadObject



51
52
53
54
55
56
57
58
59
# File 'lib/codin_rep/set_time.rb', line 51

def get_data_from_response_payload
  new_time = nil
  begin
    new_time = CodinRep::TimeUtil.unpack @response_payload
  rescue ArgumentError
    raise MalformedResponsePayload.new 'set time'
  end
  return new_time
end

#get_expected_response_sizeObject



37
38
39
# File 'lib/codin_rep/set_time.rb', line 37

def get_expected_response_size
  14
end

#get_response_payloadObject



47
48
49
# File 'lib/codin_rep/set_time.rb', line 47

def get_response_payload
  @response_payload = @response[7..-1]
end