Class: BWA::Messages::Status

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

Constant Summary collapse

MESSAGE_TYPE =
"\xaf\x13".force_encoding(Encoding::ASCII_8BIT)
MESSAGE_LENGTH =

additional features have been added in later versions

24..28

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, parse

Constructor Details

#initializeStatus

Returns a new instance of Status.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bwa/messages/status.rb', line 24

def initialize
  @src = 0xff
  self.priming = false
  self.heating_mode = :ready
  @temperature_scale = :fahrenheit
  self.twenty_four_hour_time = false
  self.filter = Array.new(2, false)
  self.heating = false
  self.temperature_range = :high
  self.hour = self.minute = 0
  self.circ_pump = false
  self.pumps = Array.new(6, 0)
  self.lights = Array.new(2, false)
  self.mister = false
  self.aux = Array.new(2, false)
  self.set_temperature = 100
end

Instance Attribute Details

#auxObject

Returns the value of attribute aux.



4
5
6
# File 'lib/bwa/messages/status.rb', line 4

def aux
  @aux
end

#blowerObject

Returns the value of attribute blower.



4
5
6
# File 'lib/bwa/messages/status.rb', line 4

def blower
  @blower
end

#circ_pumpObject

Returns the value of attribute circ_pump.



4
5
6
# File 'lib/bwa/messages/status.rb', line 4

def circ_pump
  @circ_pump
end

#current_temperatureObject

Returns the value of attribute current_temperature.



4
5
6
# File 'lib/bwa/messages/status.rb', line 4

def current_temperature
  @current_temperature
end

#filterObject

Returns the value of attribute filter.



4
5
6
# File 'lib/bwa/messages/status.rb', line 4

def filter
  @filter
end

#heatingObject

Returns the value of attribute heating.



4
5
6
# File 'lib/bwa/messages/status.rb', line 4

def heating
  @heating
end

#heating_modeObject

Returns the value of attribute heating_mode.



4
5
6
# File 'lib/bwa/messages/status.rb', line 4

def heating_mode
  @heating_mode
end

#hourObject

Returns the value of attribute hour.



4
5
6
# File 'lib/bwa/messages/status.rb', line 4

def hour
  @hour
end

#lightsObject

Returns the value of attribute lights.



4
5
6
# File 'lib/bwa/messages/status.rb', line 4

def lights
  @lights
end

#minuteObject

Returns the value of attribute minute.



4
5
6
# File 'lib/bwa/messages/status.rb', line 4

def minute
  @minute
end

#misterObject

Returns the value of attribute mister.



4
5
6
# File 'lib/bwa/messages/status.rb', line 4

def mister
  @mister
end

#primingObject

Returns the value of attribute priming.



4
5
6
# File 'lib/bwa/messages/status.rb', line 4

def priming
  @priming
end

#pumpsObject

Returns the value of attribute pumps.



4
5
6
# File 'lib/bwa/messages/status.rb', line 4

def pumps
  @pumps
end

#set_temperatureObject

Returns the value of attribute set_temperature.



4
5
6
# File 'lib/bwa/messages/status.rb', line 4

def set_temperature
  @set_temperature
end

#temperature_rangeObject

Returns the value of attribute temperature_range.



4
5
6
# File 'lib/bwa/messages/status.rb', line 4

def temperature_range
  @temperature_range
end

#temperature_scaleObject

Returns the value of attribute temperature_scale.



4
5
6
# File 'lib/bwa/messages/status.rb', line 4

def temperature_scale
  @temperature_scale
end

#twenty_four_hour_timeObject

Returns the value of attribute twenty_four_hour_time.



4
5
6
# File 'lib/bwa/messages/status.rb', line 4

def twenty_four_hour_time
  @twenty_four_hour_time
end

Instance Method Details

#inspectObject



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/bwa/messages/status.rb', line 153

def inspect
  result = "#<BWA::Messages::Status "
  items = []

  items << "priming" if priming
  items << self.class.format_time(hour, minute, twenty_four_hour_time)
  items << "#{current_temperature || '--'}/#{set_temperature}ยบ#{temperature_scale.to_s[0].upcase}"
  items << "filter=#{filter.inspect}"
  items << heating_mode
  items << "heating" if heating
  items << temperature_range
  items << "circ_pump" if circ_pump
  items << "blower" if blower
  items << "pumps=#{pumps.inspect}"
  items << "lights=#{lights.inspect}"
  items << "aux=#{aux.inspect}"
  items << "mister" if mister

  result << items.join(' ') << ">"
end

#parse(data) ⇒ Object



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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/bwa/messages/status.rb', line 42

def parse(data)
  flags = data[1].ord
  self.priming = (flags & 0x01 == 0x01)
  flags = data[5].ord
  self.heating_mode = case flags & 0x03
                        when 0x00; :ready
                        when 0x01; :rest
                        when 0x02; :ready_in_rest
                      end
  flags = data[9].ord
  self.temperature_scale = (flags & 0x01 == 0x01) ? :celsius : :fahrenheit
  self.twenty_four_hour_time = (flags & 0x02 == 0x02)
  filter[0] = (flags & 0x04 != 0)
  filter[1] = (flags & 0x08 != 0)
  flags = data[10].ord
  self.heating = (flags & 0x30 != 0)
  self.temperature_range = (flags & 0x04 == 0x04) ? :high : :low
  flags = data[11].ord
  pumps[0] = flags & 0x03
  pumps[1] = (flags >> 2) & 0x03
  pumps[2] = (flags >> 4) & 0x03
  pumps[3] = (flags >> 6) & 0x03
  flags = data[12].ord
  pumps[4] = flags & 0x03
  pumps[5] = (flags >> 2) & 0x03

  flags = data[13].ord
  self.circ_pump = (flags & 0x02 == 0x02)
  self.blower = (flags & 0x0C == 0x0C)
  flags = data[14].ord
  lights[0] = (flags & 0x03 != 0)
  lights[1] = ((flags >> 2) & 0x03 != 0)
  flags = data[15].ord
  self.mister = (flags & 0x01 == 0x01)
  aux[0] = (flags & 0x08 != 0)
  aux[1] = (flags & 0x10 != 0)
  self.hour = data[3].ord
  self.minute = data[4].ord
  self.current_temperature = data[2].ord
  self.current_temperature = nil if self.current_temperature == 0xff
  self.set_temperature = data[20].ord
  if temperature_scale == :celsius
    self.current_temperature /= 2.0
    self.set_temperature /= 2.0
  end
end

#serializeObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/bwa/messages/status.rb', line 89

def serialize
  data = "\x00" * 24
  data[1] = (priming ? 0x01 : 0x00).chr
  data[5] = (case heating_mode
               when :ready; 0x00
               when :rest; 0x01
               when :ready_in_rest; 0x02
             end).chr
  flags = 0
  flags |= 0x01 if temperature_scale == :celsius
  flags |= 0x02 if twenty_four_hour_time
  data[9] = flags.chr
  flags = 0
  flags |= 0x30 if heating
  flags |= 0x04 if temperature_range == :high
  data[10] = flags.chr
  flags = 0
  flags |= pump1
  flags |= pump2 * 4
  data[11] = flags.chr
  flags = 0
  flags |= 0x02 if circ_pump
  data[13] = flags.chr
  flags = 0
  flags |= 0x03 if light1
  data[14] = flags.chr
  data[3] = hour.chr
  data[4] = minute.chr
  if temperature_scale == :celsius
    data[2] = (current_temperature ? (current_temperature * 2).to_i : 0xff).chr
    data[20] = (set_temperature * 2).to_i.chr
  else
    data[2] = (current_temperature&.to_i || 0xff).chr
    data[20] = set_temperature.to_i.chr
  end

  super(data)
end