Class: Escalator::Protocol::Mitsubishi::QDevice

Inherits:
Object
  • Object
show all
Defined in:
lib/escalator/protocol/mitsubishi/qdevice.rb

Constant Summary collapse

SUFFIXES =
%w(SM SD X Y M L F V B D W TS TC TN SS SC SN CS CC CN SB SW S DX DY Z R ZR)
SUFFIX_CODES =
[0x91, 0xa9, 0x9c, 0x9d, 0x90, 0x92, 0x93, 0x94, 0xa0, 0xa8, 0xb4, 0xc1, 0xc0, 0xc2, 0xc7, 0xc6, 0xc8, 0xc4, 0xc3, 0xc5, 0xa1, 0xb5, 0x98, 0xa2, 0xa3, 0xcc ,0xaf, 0xb0]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a, b = nil) ⇒ QDevice

Returns a new instance of QDevice.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/escalator/protocol/mitsubishi/qdevice.rb', line 35

def initialize a, b = nil
  case a
  when Array
    case a.size
    when 4
      @suffix = suffix_for_code(a[3])
      @number = ((a[2] << 8 | a[1]) << 8) | a[0]
    end
  when String
    if b
      @suffix = a.upcase
      @number = b
    else
      if a.length == 12
        @suffix = [a[0,2].to_i(16), a[2,2].to_i(16)].pack "c*"
        @suffix.strip!
        @number = a[4,8].to_i(16)
      elsif /(X|Y)(.+)/i =~ a
        @suffix = $1.upcase
        @number = $2.to_i(p_adic_number)
      else
        /(M|L|S|B|F|T|C|D|W|R)(.+)/i =~ a
        @suffix = $1.upcase
        @number = $2.to_i(p_adic_number)
      end
    end
  end
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



30
31
32
# File 'lib/escalator/protocol/mitsubishi/qdevice.rb', line 30

def number
  @number
end

#suffixObject (readonly)

Returns the value of attribute suffix.



30
31
32
# File 'lib/escalator/protocol/mitsubishi/qdevice.rb', line 30

def suffix
  @suffix
end

Instance Method Details

#+(value) ⇒ Object



102
103
104
# File 'lib/escalator/protocol/mitsubishi/qdevice.rb', line 102

def + value
  self.class.new self.suffix, self.number + value
end

#-(value) ⇒ Object



106
107
108
# File 'lib/escalator/protocol/mitsubishi/qdevice.rb', line 106

def - value
  self.class.new self.suffix, [self.number - value, 0].max
end

#bit_device?Boolean

Returns:

  • (Boolean)


82
83
84
85
86
87
88
89
90
# File 'lib/escalator/protocol/mitsubishi/qdevice.rb', line 82

def bit_device?
  case @suffix
  when "SM", "X", "Y", "M", "L", "F", "V", "B",
       "TS", "TC", "SS", "SC","CS", "CC", "SB", "S", "DX", "DY"
    true
  else
    false
  end
end

#nameObject



73
74
75
# File 'lib/escalator/protocol/mitsubishi/qdevice.rb', line 73

def name
  @suffix + @number.to_s(p_adic_number).upcase
end

#next_deviceObject



77
78
79
80
# File 'lib/escalator/protocol/mitsubishi/qdevice.rb', line 77

def next_device
  d = self.class.new @suffix, @number + 1
  d
end

#p_adic_numberObject



64
65
66
67
68
69
70
71
# File 'lib/escalator/protocol/mitsubishi/qdevice.rb', line 64

def p_adic_number
  case @suffix
  when "X", "Y", "B", "W", "SB", "SW", "DX", "DY", "ZR"
    16
  else
    10
  end
end

#suffix_codeObject



97
98
99
100
# File 'lib/escalator/protocol/mitsubishi/qdevice.rb', line 97

def suffix_code
  index = SUFFIXES.index suffix
  index ? SUFFIX_CODES[index] : 0
end

#suffix_for_code(code) ⇒ Object



92
93
94
95
# File 'lib/escalator/protocol/mitsubishi/qdevice.rb', line 92

def suffix_for_code code
  index = SUFFIX_CODES.index code
  index ? SUFFIXES[index] : nil
end