smartware 0.4.3 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,10 +32,9 @@ module Smartware
32
32
 
33
33
  def query
34
34
  begin
35
- @sp.write QUERY
36
- magic, paper_status, user_status, recoverable, unrecoverable = read_response(6).unpack("nC*")
35
+ paper_status, user_status, recoverable, unrecoverable = do_query
37
36
 
38
- raise "invalid magic: #{magic.to_s 16}" if magic != 0x100F
37
+ raise "no response to query" if paper_status.nil?
39
38
 
40
39
  if unrecoverable != 0
41
40
  @status = :error
@@ -59,45 +58,71 @@ module Smartware
59
58
  end
60
59
 
61
60
  @sp.write MODEL_QUERY
62
- printer_model, = read_response(1).unpack("C*")
61
+ printer_model = read_response(1)
62
+ raise "no response to model query" if printer_model.nil?
63
+
64
+ printer_model, = printer_model.unpack("C*")
63
65
 
64
66
  @sp.write VERSION_QUERY
65
67
  printer_version = read_response(4)
68
+ raise "no response to version querty" if printer_version.nil?
66
69
 
67
70
  @model = "ESC/POS Printer #{printer_model.to_s 16}"
68
- @version = "ROM #{printer_version}"
71
+ @version = "ROM #{printer_version.inspect}"
69
72
 
70
73
  rescue => e
71
74
  Smartware::Logging.logger.warn "Printer communication error: #{e}"
72
75
  e.backtrace.each { |line| Smartware::Logging.logger.warn line }
73
76
 
74
- @buf = ""
75
-
76
77
  @error = Interface::Printer::COMMUNICATION_ERROR
77
78
  @status = :error
78
79
  end
79
80
  end
80
81
 
81
82
  def print(data)
83
+ start = Time.now
84
+
85
+ data.force_encoding('BINARY')
86
+
82
87
  begin
83
- @sp.write data
88
+ data.split(/(\n)/, -1).each do |line|
89
+ @sp.write line
90
+
91
+ loop do
92
+ now = Time.now
93
+ # timeout exceeded
94
+ return if now - start > 10
84
95
 
85
- start = Time.now
96
+ status = do_query
97
+ next if status.nil?
98
+
99
+ paper_status, user_status, recoverable, unrecoverable = status
100
+
101
+ # Unrecoverable error or out of paper
102
+ return if unrecoverable != 0 || (paper_status & 1) != 0
103
+
104
+ # No error - continue printing
105
+ break if (recoverable == 0) && ((user_status & 3) == 0)
106
+ end
107
+ end
86
108
 
87
109
  loop do
88
110
  now = Time.now
89
- break if now - start > 30
111
+ # timeout exceeded
112
+ return if now - start > 10
90
113
 
91
- @sp.write QUERY
92
- magic, paper_status, user_status, recoverable, unrecoverable = read_response(6).unpack("nC*")
114
+ status = do_query
115
+ next if status.nil?
93
116
 
94
- raise "invalid magic: #{magic.to_s 16}" if magic != 0x100F
117
+ paper_status, user_status, recoverable, unrecoverable = status
95
118
 
96
119
  # paper not in motion
97
120
  break if (user_status & 8) == 0
98
121
  end
122
+
99
123
  rescue => e
100
- Smartware::Logging.logger.warn "Printer communication error: #{e}"
124
+ Smartware::Logging.logger.error "Printer communication error: #{e}"
125
+ e.backtrace.each { |line| Smartware::Logging.logger.error line }
101
126
  end
102
127
  end
103
128
 
@@ -107,8 +132,25 @@ module Smartware
107
132
 
108
133
  private
109
134
 
110
- def read_response(bytes)
135
+ def do_query
136
+ # flush driver buffer
137
+ read_response(65536, 0)
138
+ @buf.clear
139
+
140
+ @sp.write QUERY
141
+ response = read_response(6).unpack("nC*")
142
+ return nil if response.nil?
143
+
144
+ magic, *rest = response
145
+ raise "invalid magic: #{magic.to_s 16}. Response: #{response}, buffer: #{@buf}" if magic != 0x100F
146
+
147
+ rest
148
+ end
149
+
150
+ def read_response(bytes, timeout = 1.0)
111
151
  while @buf.length < bytes
152
+ return nil if IO.select([ @sp ], [], [], timeout).nil?
153
+
112
154
  @buf << @sp.sysread(128)
113
155
  end
114
156
 
@@ -53,7 +53,7 @@ module Smartware
53
53
  Smartware::Logging.logger.info "Cash acceptor monitor started"
54
54
  end
55
55
 
56
- def open_session(limit_min, limit_max)
56
+ def open(limit_min = nil, limit_max = nil)
57
57
  @banknotes.clear
58
58
 
59
59
  if limit_min.nil? || limit_max.nil?
@@ -80,7 +80,7 @@ module Smartware
80
80
  end
81
81
  end
82
82
 
83
- def close_session
83
+ def close
84
84
  Smartware::Logging.logger.debug "Session closed"
85
85
 
86
86
  EventMachine.schedule do
@@ -94,7 +94,7 @@ module Smartware
94
94
  @banknotes
95
95
  end
96
96
 
97
- def cashsum
97
+ def sum
98
98
  self.banknotes.inject(0) do |result, (key, value)|
99
99
  result + key.to_i * value.to_i
100
100
  end
@@ -115,7 +115,7 @@ module Smartware
115
115
  end
116
116
 
117
117
  def escrow(banknote)
118
- limit_satisfied?(self.cashsum + banknote.value)
118
+ limit_satisfied?(self.sum + banknote.value)
119
119
  end
120
120
 
121
121
  def stacked(banknote)
@@ -139,7 +139,7 @@ module Smartware
139
139
  update_status :model, @device.model
140
140
  update_status :version, @device.version
141
141
  update_status :casette, error != DROP_CASETTE_OUT_OF_POSITION
142
- update_status :cashsum, cashsum
142
+ update_status :cashsum, sum
143
143
  end
144
144
 
145
145
  def device_open
@@ -0,0 +1,90 @@
1
+ module Smartware
2
+ module Interface
3
+ class PinPad < Interface
4
+ class PinPadError < RuntimeError; end
5
+
6
+ # Error codes
7
+ DEVICE_NOT_READY = 1
8
+ DEVICE_ERROR = 2
9
+
10
+ # Input modes
11
+ INPUT_PLAINTEXT = 1
12
+ INPUT_PIN = 2
13
+
14
+ # Pin block formats
15
+ ASCII = 0
16
+ ISO9564_0 = 1
17
+ ISO9564_1 = 2
18
+ ISO9564_3 = 3
19
+ IBM3624 = 4
20
+
21
+ def self.safe_proxy(*methods)
22
+ methods.each do |method|
23
+ class_eval <<-END
24
+ def #{method}(*args)
25
+ result = @device.#{method}(*args)
26
+ update_status :error, nil
27
+ result
28
+ rescue PinPadError => e
29
+ Logging.logger.error "Pin pad command failed: #\{e}"
30
+ update_status :error, DEVICE_ERROR
31
+ nil
32
+ end
33
+ END
34
+ end
35
+ end
36
+
37
+ safe_proxy :wipe, :restart, :start_input, :stop_input
38
+ safe_proxy :load_working_keys, :get_pin
39
+
40
+ def initialize(config, service)
41
+ super
42
+
43
+ device_not_ready
44
+
45
+ @device.imk_source = method :imk_source
46
+ @device.post_configuration = method :post_configuration
47
+ @device.device_ready = method :device_ready
48
+ @device.device_not_ready = method :device_not_ready
49
+ @device.input_event = method :input_event
50
+
51
+ end
52
+
53
+ protected
54
+
55
+ def imk_source
56
+ imk = "000000000000000000000000000000000000000000000000"
57
+ tmk = "12345678" + "\x00" * 16
58
+
59
+ [ imk, tmk ]
60
+ end
61
+
62
+ def post_configuration
63
+ Logging.logger.debug "post configuration"
64
+ end
65
+
66
+ def device_not_ready
67
+ update_status :error, DEVICE_NOT_READY
68
+ update_status :in_input, false
69
+ end
70
+
71
+ def device_ready
72
+ update_status :error, nil
73
+ update_status :model, @device.model
74
+ update_status :version, @device.version
75
+ end
76
+
77
+ def input_event(event, data = nil)
78
+ publish_event :input, event, data
79
+
80
+ case event
81
+ when :start
82
+ update_status :in_input, true
83
+
84
+ when :accept, :cancel
85
+ update_status :in_input, false
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -1,3 +1,3 @@
1
1
  module Smartware
2
- VERSION = "0.4.3"
2
+ VERSION = "0.4.4"
3
3
  end
data/smartware.gemspec CHANGED
@@ -6,11 +6,11 @@ require 'smartware/version'
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "smartware"
8
8
  gem.version = Smartware::VERSION
9
- gem.authors = ["Evgeni Sudarchikov", "Boris Staal"]
10
- gem.email = ["e.sudarchikov@roundlake.ru", "boris@roundlake.ru"]
9
+ gem.authors = ["Evgeni Sudarchikov", "Boris Staal", 'Sergey Gridasov']
10
+ gem.email = ["e.sudarchikov@roundlake.ru", "boris@roundlake.ru", 'grindars@gmail.com']
11
11
  gem.description = %q{Smartware is the Smartkiosk hardware control daemon}
12
12
  gem.summary = gem.description
13
- gem.homepage = "https://github.com/roundlake/smartware"
13
+ gem.homepage = "https://github.com/smartkiosk/smartware"
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartware
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Evgeni Sudarchikov
9
9
  - Boris Staal
10
+ - Sergey Gridasov
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2013-02-01 00:00:00.000000000 Z
14
+ date: 2013-02-12 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: smartkiosk-common
@@ -144,10 +145,12 @@ description: Smartware is the Smartkiosk hardware control daemon
144
145
  email:
145
146
  - e.sudarchikov@roundlake.ru
146
147
  - boris@roundlake.ru
148
+ - grindars@gmail.com
147
149
  executables:
148
150
  - smartware
149
151
  - smartware-monitor
150
152
  - smartware-ppp-helper
153
+ - smartware-readepp
151
154
  extensions: []
152
155
  extra_rdoc_files: []
153
156
  files:
@@ -159,13 +162,10 @@ files:
159
162
  - bin/smartware
160
163
  - bin/smartware-monitor
161
164
  - bin/smartware-ppp-helper
165
+ - bin/smartware-readepp
162
166
  - config/smartware.yml.sample
163
167
  - lib/smartware.rb
164
- - lib/smartware/clients/card_reader.rb
165
- - lib/smartware/clients/cash_acceptor.rb
166
- - lib/smartware/clients/modem.rb
167
- - lib/smartware/clients/printer.rb
168
- - lib/smartware/clients/watchdog.rb
168
+ - lib/smartware/client.rb
169
169
  - lib/smartware/connection_monitor.rb
170
170
  - lib/smartware/drivers/card_reader/dummy.rb
171
171
  - lib/smartware/drivers/card_reader/ict3_k5.rb
@@ -174,8 +174,10 @@ files:
174
174
  - lib/smartware/drivers/common/ccnet_connection.rb
175
175
  - lib/smartware/drivers/common/command_based_device.rb
176
176
  - lib/smartware/drivers/common/sankyo_connection.rb
177
+ - lib/smartware/drivers/common/szzt_connection.rb
177
178
  - lib/smartware/drivers/modem/dummy.rb
178
179
  - lib/smartware/drivers/modem/standard.rb
180
+ - lib/smartware/drivers/pin_pad/zt588.rb
179
181
  - lib/smartware/drivers/printer/dummy.rb
180
182
  - lib/smartware/drivers/printer/esc_pos.rb
181
183
  - lib/smartware/drivers/watchdog/dummy.rb
@@ -184,6 +186,7 @@ files:
184
186
  - lib/smartware/interfaces/cash_acceptor.rb
185
187
  - lib/smartware/interfaces/interface.rb
186
188
  - lib/smartware/interfaces/modem.rb
189
+ - lib/smartware/interfaces/pin_pad.rb
187
190
  - lib/smartware/interfaces/printer.rb
188
191
  - lib/smartware/interfaces/watchdog.rb
189
192
  - lib/smartware/logging.rb
@@ -193,7 +196,7 @@ files:
193
196
  - lib/smartware/service.rb
194
197
  - lib/smartware/version.rb
195
198
  - smartware.gemspec
196
- homepage: https://github.com/roundlake/smartware
199
+ homepage: https://github.com/smartkiosk/smartware
197
200
  licenses: []
198
201
  post_install_message:
199
202
  rdoc_options: []
@@ -1,41 +0,0 @@
1
- require 'drb'
2
-
3
- module Smartware
4
- module Client
5
-
6
- module CardReader
7
-
8
- DRb.start_service
9
- @device = DRbObject.new_with_uri('druby://localhost:6004')
10
-
11
-
12
- def self.status
13
- @device.status
14
- end
15
-
16
- def self.error
17
- @device.error
18
- end
19
-
20
- def self.model
21
- @device.model
22
- end
23
-
24
- def self.version
25
- @device.version
26
- end
27
-
28
- def self.open
29
- @device.open
30
- end
31
-
32
- def self.close
33
- @device.close
34
- end
35
-
36
- def self.card_inserted
37
- @device.card_inserted
38
- end
39
- end
40
- end
41
- end
@@ -1,52 +0,0 @@
1
- require 'drb'
2
-
3
- module Smartware
4
- module Client
5
-
6
- module CashAcceptor
7
-
8
- DRb.start_service
9
- @device = DRbObject.new_with_uri('druby://localhost:6001')
10
-
11
- def self.open(limit_min = nil, limit_max = nil)
12
- @device.open_session(limit_min, limit_max)
13
- end
14
-
15
- def self.close
16
- @device.close_session
17
- end
18
-
19
- def self.status
20
- @device.status
21
- end
22
-
23
- def self.error
24
- @device.error
25
- end
26
-
27
- def self.model
28
- @device.model
29
- end
30
-
31
- def self.version
32
- @device.version
33
- end
34
-
35
- def self.banknotes
36
- @device.banknotes
37
- end
38
-
39
- def self.sum
40
- @device.cashsum
41
- end
42
-
43
- def self.insert_casette
44
- @device.insert_casette
45
- end
46
-
47
- def self.eject_casette
48
- @device.eject_casette
49
- end
50
- end
51
- end
52
- end