-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.rb
More file actions
executable file
·113 lines (98 loc) · 3.12 KB
/
Copy pathhandler.rb
File metadata and controls
executable file
·113 lines (98 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/home/tom/.rvm/rubies/ruby-2.0.0-p481/bin/ruby
require 'logger'
require 'base64'
require 'rubygems'
require 'ffi-rzmq'
dir = File.dirname(__FILE__)
file = File.open("#{dir}/log/suwappu.log", File::WRONLY | File::APPEND)
ASSETS_DIR = "/mnt/Data/Assets"
@logger = Logger.new(file)
@logger.level = Logger::INFO
def analyze_uri(uri)
command_and_uri = uri.split(/\/\//)[1]
i = command_and_uri.index(/\//)
command = command_and_uri[0..i-1]
i = (command_and_uri.length - i - 1)*-1
argument = command_and_uri[i..-1]
case command
when 'print'
uri = "http://#{argument}"
print_barcode download(uri)
when 'storage'
checkpoint, device, slot = argument.split('/')
storage_slot device,slot
when 'picture'
print_barcode argument,argument
#take_picture argument
when 'scan'
scan argument
else
puts "Command #{command} not found!"
end
end
def event_completed(command,argument)
@logger.info "Event suwappu_handler##{command}_completed called"
end
def download(uri)
file_name = "barcode-#{Time.now.to_i}.pdf"
@logger.info "Downloading #{uri} --> /home/tom/Code/suwappu/suwappu_protocol_handler/tmp/documents/#{file_name}"
cmnd = "curl #{uri} -o '/home/tom/Code/suwappu/suwappu_protocol_handler/tmp/documents/#{file_name}'"
@logger.info cmnd
system cmnd
file_name
end
def print_barcode(barcode,label)
#cmnd = "lpr -P 'Zebra-LP2824' /home/tom/Code/suwappu/suwappu_protocol_handler/tmp/documents/#{local_doc}"
system "touch /tmp/1"
ctx = ZMQ::Context.new()
socket = ctx.socket(ZMQ::PUB)
socket.bind('tcp://tcp://10.0.0.6:6001')
socket.bind("ipc://pubz.ipc")
system "touch /tmp/2"
sleep 1.5 # HACK : To make sure the connection is setup
puts "Printing #{barcode} with label #{label}"
socket.send_string("#{barcode};#{label}")
puts "Printed"
socket.close
system "touch /tmp/3"
#@logger.info cmnd
#system cmnd
#event_completed('print_barcode',{file: local_doc})
end
def zmq_pub(address,filter,msg)
end
def storage_slot(device,slot)
cmnd = "lcdoctl -d 'Dacal DC-300:#{device}' -e #{slot}"
@logger.info "Storage :: Slot #{slot} @ #{device}"
@logger.info cmnd
system cmnd
system "sleep 10; lcdoctl -d 'Dacal DC-300:#{device}' -i #{slot}"
end
def take_picture(swap_number)
cmnd = "streamer -o /tmp/#{swap_number}.jpeg && scp /tmp/#{swap_number}.jpeg deployer@inventorycontrol:/u/apps/inventorycontrol/shared/suwappu_pictures/"
@logger.info "take_picture"
@logger.info cmnd
system cmnd
event_completed('take_picture',{swap_number: swap_number,file: "file:///tmp/#{swap_number}.jpeg"})
end
def scan(uuid)
scanner = 'hpaio:/net/HP_Color_LaserJet_2840?ip=192.168.11.31'
file = "#{ASSETS_DIR}/#{uuid}"
cmnd = "scanimage -d #{scanner} -l 0 -t 0 -x 215 -y 297 --resolution=300 > #{file}.pnm"
@logger.info "scan"
@logger.info cmnd
system cmnd
#cmnd = "pnmtops #{file}.pnm > #{file}.ps"
#@logger.info cmnd
#system cmnd
#cmnd = "ps2pdf #{file}.ps #{file}.pdf"
#@logger.info cmnd
#system cmnd
imgBase64 = Base64.encode64(open("#{file}.pnm") { |io| io.read })
event_completed('scan',{uuid: uuid,file: "#{file}.pnm"})
"#{file}.pnm"
end
argument = ARGV[0]
puts argument
puts analyze_uri(argument)
@logger.close