Class: Aurora::MockABC

Inherits:
Object
  • Object
show all
Defined in:
lib/aurora/mock_abc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registers, ignore_missing_registers: false) ⇒ MockABC

Returns a new instance of MockABC.



7
8
9
10
# File 'lib/aurora/mock_abc.rb', line 7

def initialize(registers, ignore_missing_registers: false)
  @ignore_missing_registers = ignore_missing_registers
  @registers = registers
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/aurora/mock_abc.rb', line 5

def logger
  @logger
end

Instance Method Details

#[](*register) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/aurora/mock_abc.rb', line 20

def [](*register)
  if register.length == 1
    case register.first
    when Integer
      missing_register(register.first) unless @registers.key?(register.first)
      @registers[register.first]
    when Range
      registers = register.first.to_a
      registers.each do |i|
        missing_register(i) unless @registers.key?(i)
      end
      @registers.values_at(*registers)
    else
      raise ArgumentError, "Not implemented yet #{register.inspect}"
    end
  else
    read_multiple_holding_registers(*register)
  end
end

#holding_registersObject



16
17
18
# File 'lib/aurora/mock_abc.rb', line 16

def holding_registers
  self
end

#read_multiple_holding_registers(*queries) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/aurora/mock_abc.rb', line 40

def read_multiple_holding_registers(*queries)
  result = {}
  queries.each do |query|
    Array(query).each do |i|
      unless @registers.key?(i)
        missing_register(i)
        next
      end

      result[i] = @registers[i]
    end
  end
  result
end

#read_retries=(_) ⇒ Object



14
# File 'lib/aurora/mock_abc.rb', line 14

def read_retries=(_); end

#read_retry_timeout=(_) ⇒ Object



12
# File 'lib/aurora/mock_abc.rb', line 12

def read_retry_timeout=(_); end

#write_holding_register(addr, value) ⇒ Object Also known as: []=



55
56
57
# File 'lib/aurora/mock_abc.rb', line 55

def write_holding_register(addr, value)
  @registers[addr] = value
end