smartware 0.1.2 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/smartware +8 -1
- data/lib/smartware/clients/cash_acceptor.rb +2 -5
- data/lib/smartware/clients/modem.rb +8 -5
- data/lib/smartware/clients/printer.rb +8 -5
- data/lib/smartware/drivers/modem/standard.rb +74 -0
- data/lib/smartware/interfaces/cash_acceptor.rb +7 -4
- data/lib/smartware/interfaces/modem.rb +8 -4
- data/lib/smartware/interfaces/printer.rb +5 -2
- data/lib/smartware/service.rb +10 -1
- data/lib/smartware/version.rb +1 -1
- metadata +3 -2
data/bin/smartware
CHANGED
@@ -15,10 +15,17 @@ require 'dante'
|
|
15
15
|
|
16
16
|
runner = Dante::Runner.new('smartware')
|
17
17
|
runner.description = "Smartkiosk hardware control daemon"
|
18
|
+
runner.with_options do |opts|
|
19
|
+
opts.on("-c", "--config-file FILE", String, "Hardware config file to use. Sample: --config-file=/path/to/smartware.yml") do |x|
|
20
|
+
options[:config] = x
|
21
|
+
end
|
22
|
+
end
|
18
23
|
|
19
24
|
runner.execute do |opts|
|
25
|
+
abort "You should specify hardware configuration file path(--config-file=/path/to/smartware.yml)" if opts[:config].nil?
|
26
|
+
|
20
27
|
begin
|
21
|
-
Smartware::Service.start
|
28
|
+
Smartware::Service.start(opts[:config])
|
22
29
|
rescue => e
|
23
30
|
raise e if $DEBUG
|
24
31
|
STDERR.puts e.message
|
@@ -5,11 +5,8 @@ module Smartware
|
|
5
5
|
|
6
6
|
module CashAcceptor
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
@device = DRbObject.new_with_uri('druby://localhost:6001')
|
11
|
-
@device.configure!(port, driver)
|
12
|
-
end
|
8
|
+
DRb.start_service
|
9
|
+
@device = DRbObject.new_with_uri('druby://localhost:6001')
|
13
10
|
|
14
11
|
def self.open(limit_min = nil, limit_max = nil)
|
15
12
|
@device.open_session(limit_min, limit_max)
|
@@ -5,11 +5,14 @@ module Smartware
|
|
5
5
|
|
6
6
|
module Modem
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
DRb.start_service
|
9
|
+
@device = DRbObject.new_with_uri('druby://localhost:6002')
|
10
|
+
|
11
|
+
#def self.configure(port, driver)
|
12
|
+
# DRb.start_service
|
13
|
+
# @device = DRbObject.new_with_uri('druby://localhost:6002')
|
14
|
+
# @device.configure!(port, driver)
|
15
|
+
#end
|
13
16
|
|
14
17
|
def self.error
|
15
18
|
@device.error
|
@@ -5,11 +5,14 @@ module Smartware
|
|
5
5
|
|
6
6
|
module Printer
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
DRb.start_service
|
9
|
+
@device = DRbObject.new_with_uri('druby://localhost:6005')
|
10
|
+
|
11
|
+
#def self.configure(port, driver)
|
12
|
+
# DRb.start_service
|
13
|
+
# @device = DRbObject.new_with_uri('druby://localhost:6005')
|
14
|
+
# @device.configure!(port, driver)
|
15
|
+
#end
|
13
16
|
|
14
17
|
def self.error
|
15
18
|
@device.error
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'serialport'
|
3
|
+
|
4
|
+
module Smartware
|
5
|
+
module Driver
|
6
|
+
module Modem
|
7
|
+
|
8
|
+
class Standard
|
9
|
+
|
10
|
+
def initialize(port)
|
11
|
+
# @port Class variable needs for ussd request
|
12
|
+
@port = port
|
13
|
+
@sp = SerialPort.new(@port, 115200, 8, 1, SerialPort::NONE)
|
14
|
+
end
|
15
|
+
|
16
|
+
def error
|
17
|
+
false
|
18
|
+
end
|
19
|
+
|
20
|
+
def model
|
21
|
+
res = send 'ATI' rescue -1
|
22
|
+
return -1 unless res.last == "OK"
|
23
|
+
|
24
|
+
res.shift
|
25
|
+
res.pop
|
26
|
+
res.join(' ')
|
27
|
+
rescue
|
28
|
+
-1
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Returns signal level in dbm
|
33
|
+
#
|
34
|
+
def signal_level
|
35
|
+
res = send 'AT+CSQ'
|
36
|
+
return -1 if res.last != "OK"
|
37
|
+
value = res[1].gsub("+CSQ: ",'').split(',')[0].to_i
|
38
|
+
"#{(-113 + value * 2)} dbm"
|
39
|
+
rescue
|
40
|
+
-1
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Method send ussd to operator and return only valid answer body
|
45
|
+
# Don`t call with method synchronously from app, method waits USSD answer 3 sec,
|
46
|
+
# Use some scheduler and buffer for balance value
|
47
|
+
#
|
48
|
+
def ussd(code="*100#")
|
49
|
+
port = SerialPort.new(@port, 115200, 8, 1, SerialPort::NONE)
|
50
|
+
port.read_timeout = 3000
|
51
|
+
port.write "AT+CUSD=1,\"#{code}\",15\r\n"
|
52
|
+
ussd_body = port.read.split(/[\r\n]+/).last.split(",")[1].gsub('"','') # Get only USSD message body
|
53
|
+
port.close
|
54
|
+
ussd_body.scan(/\w{4}/).map{|i| [i.hex].pack("U") }.join # Encode USSD message from broken ucs2 to utf-8
|
55
|
+
rescue
|
56
|
+
-1
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
def send cmd
|
61
|
+
@sp.write "#{ cmd }\r\n"
|
62
|
+
answer = ''
|
63
|
+
while IO.select [@sp], [], [], 0.25
|
64
|
+
chr = @sp.getc.chr
|
65
|
+
answer << chr
|
66
|
+
end
|
67
|
+
answer.split(/[\r\n]+/)
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -19,10 +19,12 @@ module Smartware
|
|
19
19
|
#
|
20
20
|
# (re)configure device
|
21
21
|
#
|
22
|
-
def self.configure!(port, driver)
|
23
|
-
@device = Smartware::Driver::CashAcceptor.const_get(
|
22
|
+
def self.configure!(port=nil, driver=nil)
|
23
|
+
@device = Smartware::Driver::CashAcceptor.const_get(
|
24
|
+
Smartware::Service.config['cash_acceptor_driver']).new(
|
25
|
+
Smartware::Service.config['cash_acceptor_port'])
|
24
26
|
@session.kill if @session and @session.alive?
|
25
|
-
|
27
|
+
@commands = %w(monitor)
|
26
28
|
@device.cancel_accept
|
27
29
|
@session = self.start_poll!
|
28
30
|
Smartware::Logging.logger.info "Cash acceptor monitor started"
|
@@ -112,7 +114,7 @@ module Smartware
|
|
112
114
|
|
113
115
|
@commands.shift
|
114
116
|
when 'monitor'
|
115
|
-
@status[:error] = @device.error
|
117
|
+
@status[:error] = @device.error || ''
|
116
118
|
@status[:model] = @device.model
|
117
119
|
@status[:cassette] = @device.cassette?
|
118
120
|
@commands.shift
|
@@ -124,6 +126,7 @@ module Smartware
|
|
124
126
|
end
|
125
127
|
end
|
126
128
|
|
129
|
+
self.configure!
|
127
130
|
end
|
128
131
|
end
|
129
132
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'drb'
|
2
|
-
require 'smartware/drivers/modem/
|
2
|
+
require 'smartware/drivers/modem/standard'
|
3
3
|
require 'smartware/drivers/modem/dummy'
|
4
4
|
|
5
5
|
module Smartware
|
@@ -10,11 +10,14 @@ module Smartware
|
|
10
10
|
@configured = false
|
11
11
|
@status = {}
|
12
12
|
|
13
|
-
def self.configure!(port, driver)
|
14
|
-
@device = Smartware::Driver::Modem.const_get(
|
13
|
+
def self.configure!(port=nil, driver=nil)
|
14
|
+
@device = Smartware::Driver::Modem.const_get(
|
15
|
+
Smartware::Service.config['modem_driver']).new(
|
16
|
+
Smartware::Service.config['modem_port'])
|
15
17
|
@session.kill if @session
|
16
18
|
@session = self.poll_status!
|
17
19
|
@configured = true
|
20
|
+
Smartware::Logging.logger.info 'Modem monitor started'
|
18
21
|
@status = {}
|
19
22
|
rescue => e
|
20
23
|
Smartware::Logging.logger.error e.message
|
@@ -70,8 +73,9 @@ module Smartware
|
|
70
73
|
end
|
71
74
|
end
|
72
75
|
end
|
73
|
-
end
|
74
76
|
|
77
|
+
self.configure!
|
78
|
+
end
|
75
79
|
end
|
76
80
|
end
|
77
81
|
|
@@ -11,8 +11,10 @@ module Smartware
|
|
11
11
|
@status = {:error => ''}
|
12
12
|
@queue = []
|
13
13
|
|
14
|
-
def self.configure!(port, driver)
|
15
|
-
@device = Smartware::Driver::Printer.const_get(
|
14
|
+
def self.configure!(port=nil, driver=nil)
|
15
|
+
@device = Smartware::Driver::Printer.const_get(
|
16
|
+
Smartware::Service.config['printer_driver']).new(
|
17
|
+
Smartware::Service.config['printer_port'])
|
16
18
|
@session.kill if @session and @session.alive?
|
17
19
|
@session = self.start_monitor!
|
18
20
|
Smartware::Logging.logger.info 'Printer monitor started'
|
@@ -64,6 +66,7 @@ module Smartware
|
|
64
66
|
end
|
65
67
|
end
|
66
68
|
|
69
|
+
self.configure!
|
67
70
|
end
|
68
71
|
end
|
69
72
|
end
|
data/lib/smartware/service.rb
CHANGED
@@ -1,11 +1,19 @@
|
|
1
1
|
require 'thread'
|
2
|
+
require 'yaml'
|
2
3
|
require 'smartware/logging'
|
3
4
|
|
4
5
|
module Smartware
|
5
6
|
module Service
|
6
|
-
|
7
|
+
|
8
|
+
def self.config
|
9
|
+
@config
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.start(config_file)
|
7
13
|
$stdout.sync = true
|
8
14
|
|
15
|
+
@config = YAML.load File.read(File.expand_path(config_file))
|
16
|
+
|
9
17
|
Smartware::Logging.logger = Logger.new($stdout)
|
10
18
|
Smartware::Logging.logger.info "Smartware started at #{Time.now}"
|
11
19
|
|
@@ -24,6 +32,7 @@ module Smartware
|
|
24
32
|
Smartware::Logging.logger.info "Smartware shutdown at #{Time.now}"
|
25
33
|
exit 0
|
26
34
|
end
|
35
|
+
|
27
36
|
end
|
28
37
|
end
|
29
38
|
|
data/lib/smartware/version.rb
CHANGED
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.1.
|
4
|
+
version: 0.1.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-12-
|
13
|
+
date: 2012-12-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: serialport
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- lib/smartware/drivers/cash_acceptor/ccnet.rb
|
67
67
|
- lib/smartware/drivers/cash_acceptor/dummy.rb
|
68
68
|
- lib/smartware/drivers/modem/dummy.rb
|
69
|
+
- lib/smartware/drivers/modem/standard.rb
|
69
70
|
- lib/smartware/drivers/modem/standart.rb
|
70
71
|
- lib/smartware/drivers/printer/dummy.rb
|
71
72
|
- lib/smartware/drivers/printer/tg24xx.rb
|