Class: Smartware::Interface::CashAcceptor

Inherits:
Interface
  • Object
show all
Defined in:
lib/smartware/interfaces/cash_acceptor.rb

Defined Under Namespace

Classes: BillType

Constant Summary collapse

DROP_CASETTE_FULL =
1
DROP_CASETTE_OUT_OF_POSITION =
2
VALIDATOR_JAMMED =
3
DROP_CASETTE_JAMMED =
4
CHEATED =
5
PAUSE =
6
BILL_VALIDATOR_FAILURE =
7
STACK_MOTOR_FAILURE =
8
TRANSPORT_MOTOR_SPEED_FAILURE =
9
TRANSPORT_MOTOR_FAILURE =
10
ALIGNING_MOTOR_FAILURE =
11
INITIAL_CASETTE_STATUS_FAILURE =
12
OPTIC_CANAL_FAILURE =
13
MAGNETIC_CANAL_FAILURE =
14
CAPACITANCE_CANAL_FAILURE =
15
COMMUNICATION_ERROR =
16

Instance Attribute Summary

Attributes inherited from Interface

#config

Instance Method Summary collapse

Methods inherited from Interface

#error, #model, #repush_events, #shutdown, #status, #version

Constructor Details

#initialize(config, service) ⇒ CashAcceptor

Returns a new instance of CashAcceptor.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/smartware/interfaces/cash_acceptor.rb', line 36

def initialize(config, service)
  super

  @device.open = method :device_open
  @device.closed = method :device_closed
  @device.escrow = method :escrow
  @device.stacked = method :stacked
  @device.returned = method :returned
  @device.status = method :status_changed

  @limit = nil
  @banknotes = {}
  @banknotes.default = 0

  update_status :casette, false
  update_status :accepting, false

  Smartware::Logging.logger.info "Cash acceptor monitor started"
end

Instance Method Details

#banknotesObject



93
94
95
# File 'lib/smartware/interfaces/cash_acceptor.rb', line 93

def banknotes
  @banknotes
end

#closeObject



83
84
85
86
87
88
89
90
91
# File 'lib/smartware/interfaces/cash_acceptor.rb', line 83

def close
  Smartware::Logging.logger.debug "Session closed"

  EventMachine.schedule do
    @device.enabled_types = 0
  end

  @limit = nil
end

#eject_casetteObject



107
108
109
# File 'lib/smartware/interfaces/cash_acceptor.rb', line 107

def eject_casette
  @device.eject_casette
end

#insert_casetteObject



103
104
105
# File 'lib/smartware/interfaces/cash_acceptor.rb', line 103

def insert_casette
  @device.insert_casette
end

#open(limit_min = nil, limit_max = nil) ⇒ Object



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
# File 'lib/smartware/interfaces/cash_acceptor.rb', line 56

def open(limit_min = nil, limit_max = nil)
  @banknotes.clear

  if limit_min.nil? || limit_max.nil?
    @limit = nil

    Smartware::Logging.logger.debug "Session open, unlimited"
  else
    @limit = limit_min..limit_max

    Smartware::Logging.logger.debug "Session open, limit: #{@limit}"
  end

  EventMachine.schedule do
    types = 0
    @device.bill_types.each_with_index do |type, index|
      next if type.nil?

      if type.country == 'RUS'
        types |= 1 << index
      end
    end

    @device.enabled_types = types
  end
end

#sumObject



97
98
99
100
101
# File 'lib/smartware/interfaces/cash_acceptor.rb', line 97

def sum
  self.banknotes.inject(0) do |result, (key, value)|
    result + key.to_i * value.to_i
  end
end