smartware 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,4 +14,7 @@ interfaces:
14
14
  - name: Printer
15
15
  uri: druby://localhost:6005
16
16
  driver: Dummy
17
+ - name: UserInterface
18
+ uri: druby://localhost:6007
19
+ driver: Dummy
17
20
  connection_timeout: 60
data/lib/smartware.rb CHANGED
@@ -23,6 +23,7 @@ require 'smartware/interfaces/printer'
23
23
  require 'smartware/interfaces/watchdog'
24
24
  require 'smartware/interfaces/card_reader'
25
25
  require 'smartware/interfaces/pin_pad'
26
+ require 'smartware/interfaces/user_interface'
26
27
  require 'smartware/connection_monitor'
27
28
  require 'smartware/pub_sub_server'
28
29
  require 'smartware/pub_sub_client'
@@ -57,6 +58,10 @@ module Smartware
57
58
  Smartware::Client.instance('druby://localhost:6006')
58
59
  end
59
60
 
61
+ def self.user_interface
62
+ Smartware::Client.instance('druby://localhost:6007')
63
+ end
64
+
60
65
  def self.subscribe(&block)
61
66
  Smartware::PubSubClient.destroy_static_client
62
67
  client = Smartware::PubSubClient.create_static_client
@@ -170,11 +170,13 @@ module Smartware
170
170
  @user_data = info[:user_info]
171
171
  end
172
172
 
173
+ =begin unsafe - enable at your own risk
173
174
  def wipe
174
175
  control MISC, WIPE
175
176
  sleep 3
176
177
  initialize_device true
177
178
  end
179
+ =end
178
180
 
179
181
  def restart
180
182
  control MISC, RESET
@@ -382,7 +384,7 @@ module Smartware
382
384
  if !reload
383
385
  if info[:settings][:blank]
384
386
  Logging.logger.warn "ZT588: IMK not loaded, pinpad unoperational"
385
-
387
+ =begin unsafe - enable at your own risk
386
388
  imk, tmk = @imk_source.call
387
389
 
388
390
  return if imk.nil?
@@ -402,14 +404,24 @@ module Smartware
402
404
  @post_configuration.call
403
405
 
404
406
  restart
407
+ =end
405
408
  else
406
- random = auth AUTH_GET_CHALLENGE, "0000000000000000"
407
- challenge = auth KEY_TMK, random
408
- response = calculate_response challenge, UID
409
- check = calculate_response response, UID
410
- verify = auth AUTH_WITH_TMK, response
411
- raise ZT588Error, "verification failed" if check != verify
412
- Logging.logger.debug "ZT588: authenticated"
409
+ [0x10, 0x20, 0x30].each do |key|
410
+ p key
411
+ begin
412
+ random = auth AUTH_GET_CHALLENGE, "0000000000000000"
413
+ challenge = auth key, random
414
+ response = calculate_response challenge, UID
415
+ check = calculate_response response, UID
416
+ verify = auth AUTH_WITH_TMK, response
417
+ raise ZT588Error, "verification failed" if check != verify
418
+ Logging.logger.debug "ZT588: authenticated"
419
+
420
+ break
421
+ rescue => e
422
+ p e
423
+ end
424
+ end
413
425
 
414
426
  @device_ready.call
415
427
  end
@@ -0,0 +1,28 @@
1
+ require "base64"
2
+
3
+ module Smartware
4
+ module Driver
5
+ module UserInterface
6
+ class Dummy
7
+
8
+ SCREENSHOT = Base64.decode64("R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7")
9
+
10
+ def initialize(config)
11
+
12
+ end
13
+
14
+ def delete_calibration
15
+
16
+ end
17
+
18
+ def restart_ui
19
+
20
+ end
21
+
22
+ def screenshot
23
+ SCREENSHOT
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,94 @@
1
+ require "chunky_png"
2
+ require "oily_png"
3
+
4
+ module Smartware
5
+ module Driver
6
+ module UserInterface
7
+ class X11
8
+ def initialize(config)
9
+ @user = config["user"]
10
+ @display = config["display"]
11
+ end
12
+
13
+ def delete_calibration
14
+ File.delete "/home/#{@user}/.calibration_data" rescue nil
15
+ File.delete "/home/#{@user}/.monitors" rescue nil
16
+ end
17
+
18
+ def restart_ui
19
+ system "pkill", "-U", @user, "xinit"
20
+ end
21
+
22
+ def screenshot
23
+ mine_pipe, xwd_pipe = IO.pipe
24
+ png = nil
25
+
26
+ begin
27
+ pid = Process.spawn({
28
+ "DISPLAY" => @display,
29
+ "XAUTHORITY" => "/home/#{@user}/.Xauthority"
30
+ }, "xwd", "-root", in: :close, out: xwd_pipe)
31
+
32
+ xwd_pipe.close
33
+ xwd_pipe = nil
34
+
35
+
36
+ header_size, file_version,
37
+ pixmap_format, pixmap_depth, pixmap_width, pixmap_height,
38
+ xoffset, byteorder, bitmap_unit, bitmap_bit_order, bitmap_pad,
39
+ bits_per_pixel, bytes_per_line, visual_class,
40
+ red_mask, green_mask, blue_mask, bits_per_rgb,
41
+ number_of_colors, color_map_entires,
42
+ window_width, window_height, window_x, window_y, window_border_width =
43
+ mine_pipe.read(4 * 25).unpack("N*")
44
+
45
+ raise "Only direct color images are supported" if (visual_class != 5 && visual_class != 4)
46
+
47
+ mine_pipe.read((header_size + number_of_colors * 12) - 4 * 25)
48
+
49
+ initial = Array.new pixmap_width, pixmap_height
50
+
51
+ case bits_per_pixel
52
+ when 24
53
+ 0.upto(pixmap_height - 1) do |y|
54
+ line = mine_pipe.read(bytes_per_line)
55
+ .slice(0, bits_per_pixel / 8 * pixmap_width)
56
+
57
+ 0.upto(pixmap_width - 1) do |x|
58
+ initial[y * pixmap_width + x] =
59
+ (line.getbyte(x * 3 + 2) << 24) |
60
+ (line.getbyte(x * 3 + 1) << 16) |
61
+ (line.getbyte(x * 3 + 0) << 8) |
62
+ 0xFF
63
+ end
64
+ end
65
+
66
+ when 32
67
+ 0.upto(pixmap_height - 1) do |y|
68
+ line = mine_pipe.read(bytes_per_line)
69
+ .slice(0, bits_per_pixel / 8 * pixmap_width)
70
+
71
+ 0.upto(pixmap_width - 1) do |x|
72
+ pix, = line.slice(x * 4, 4).unpack("V")
73
+ initial[y * pixmap_width + x] = ((pix & 0xFFFFFF) << 8) | 0xFF
74
+ end
75
+ end
76
+
77
+ else
78
+ raise "Unsupported bpp: #{bits_per_pixel}"
79
+ end
80
+
81
+ png = ChunkyPNG::Image.new pixmap_width, pixmap_height, initial
82
+
83
+ png.to_datastream.to_blob
84
+ rescue => e
85
+ "!error: #{e}"
86
+ ensure
87
+ mine_pipe.close
88
+ xwd_pipe.close unless xwd_pipe.nil?
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,46 @@
1
+ module Smartware
2
+ module Interface
3
+ class UserInterface < Interface
4
+
5
+ def initialize(config, service)
6
+ super
7
+
8
+ update_status :error, nil
9
+ update_status :model, ''
10
+ update_status :version, ''
11
+ update_status :screenshot_pending, false
12
+
13
+ @screenshot_data = nil
14
+ end
15
+
16
+ def delete_calibration
17
+ Logging.logger.info "Deleting calibration data"
18
+ @device.delete_calibration
19
+ end
20
+
21
+ def restart_ui
22
+ Logging.logger.info "Restarting user interface"
23
+ @device.restart_ui
24
+ end
25
+
26
+ def request_screenshot
27
+ Logging.logger.info "Requested screenshot"
28
+
29
+ EventMachine.defer @device.method(:screenshot), ->(data) do
30
+ @screenshot_data = data
31
+ update_status :screenshot_pending, true
32
+ end
33
+
34
+ nil
35
+ end
36
+
37
+ def retrieve_screenshot
38
+ data = @screenshot_data
39
+ @screenshot_data = nil
40
+ update_status :screenshot_pending, false
41
+
42
+ data
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,3 +1,3 @@
1
1
  module Smartware
2
- VERSION = "0.4.4"
2
+ VERSION = "0.4.5"
3
3
  end
data/smartware.gemspec CHANGED
@@ -25,4 +25,6 @@ Gem::Specification.new do |gem|
25
25
  gem.add_dependency 'redcarpet'
26
26
  gem.add_dependency 'digest-crc'
27
27
  gem.add_dependency 'eventmachine'
28
+ gem.add_dependency 'chunky_png'
29
+ gem.add_dependency 'oily_png'
28
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartware
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-02-12 00:00:00.000000000 Z
14
+ date: 2013-02-15 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: smartkiosk-common
@@ -141,6 +141,38 @@ dependencies:
141
141
  - - ! '>='
142
142
  - !ruby/object:Gem::Version
143
143
  version: '0'
144
+ - !ruby/object:Gem::Dependency
145
+ name: chunky_png
146
+ requirement: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ! '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ type: :runtime
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ none: false
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ - !ruby/object:Gem::Dependency
161
+ name: oily_png
162
+ requirement: !ruby/object:Gem::Requirement
163
+ none: false
164
+ requirements:
165
+ - - ! '>='
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ type: :runtime
169
+ prerelease: false
170
+ version_requirements: !ruby/object:Gem::Requirement
171
+ none: false
172
+ requirements:
173
+ - - ! '>='
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
144
176
  description: Smartware is the Smartkiosk hardware control daemon
145
177
  email:
146
178
  - e.sudarchikov@roundlake.ru
@@ -180,6 +212,8 @@ files:
180
212
  - lib/smartware/drivers/pin_pad/zt588.rb
181
213
  - lib/smartware/drivers/printer/dummy.rb
182
214
  - lib/smartware/drivers/printer/esc_pos.rb
215
+ - lib/smartware/drivers/user_interface/dummy.rb
216
+ - lib/smartware/drivers/user_interface/x11.rb
183
217
  - lib/smartware/drivers/watchdog/dummy.rb
184
218
  - lib/smartware/drivers/watchdog/watchdog_daemon.rb
185
219
  - lib/smartware/interfaces/card_reader.rb
@@ -188,6 +222,7 @@ files:
188
222
  - lib/smartware/interfaces/modem.rb
189
223
  - lib/smartware/interfaces/pin_pad.rb
190
224
  - lib/smartware/interfaces/printer.rb
225
+ - lib/smartware/interfaces/user_interface.rb
191
226
  - lib/smartware/interfaces/watchdog.rb
192
227
  - lib/smartware/logging.rb
193
228
  - lib/smartware/process_manager.rb