Class: BWA::Messages::SetTime

Inherits:
BWA::Message show all
Defined in:
lib/bwa/messages/set_time.rb

Constant Summary collapse

MESSAGE_TYPE =
"\xbf\x21".b
MESSAGE_LENGTH =
2

Instance Attribute Summary collapse

Attributes inherited from BWA::Message

#raw_data, #src

Instance Method Summary collapse

Methods inherited from BWA::Message

format_duration, format_time, inherited, #log?, parse

Constructor Details

#initialize(hour = nil, minute = nil, twenty_four_hour_time = nil) ⇒ SetTime

Returns a new instance of SetTime.



11
12
13
14
# File 'lib/bwa/messages/set_time.rb', line 11

def initialize(hour = nil, minute = nil, twenty_four_hour_time = nil)
  super()
  self.hour, self.minute, self.twenty_four_hour_time = hour, minute, twenty_four_hour_time
end

Instance Attribute Details

#hourObject

Returns the value of attribute hour.



9
10
11
# File 'lib/bwa/messages/set_time.rb', line 9

def hour
  @hour
end

#minuteObject

Returns the value of attribute minute.



9
10
11
# File 'lib/bwa/messages/set_time.rb', line 9

def minute
  @minute
end

#twenty_four_hour_timeObject

Returns the value of attribute twenty_four_hour_time.



9
10
11
# File 'lib/bwa/messages/set_time.rb', line 9

def twenty_four_hour_time
  @twenty_four_hour_time
end

Instance Method Details

#inspectObject



28
29
30
# File 'lib/bwa/messages/set_time.rb', line 28

def inspect
  "#<BWA::Messages::SetTime #{Status.format_time(hour, minute, twenty_four_hour_time: twenty_four_hour_time)}>"
end

#parse(data) ⇒ Object



16
17
18
19
20
# File 'lib/bwa/messages/set_time.rb', line 16

def parse(data)
  self.hour = data[0].ord & 0x7f
  self.minute = data[1].ord
  self.twenty_four_hour_time = !!(data[0].ord & 0x80)
end

#serializeObject



22
23
24
25
26
# File 'lib/bwa/messages/set_time.rb', line 22

def serialize
  hour_encoded = hour
  hour_encoded |= 0x80 if twenty_four_hour_time
  super("#{hour_encoded.chr}#{minute.chr}")
end