da_funk 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.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.yardopts +12 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +21 -0
- data/README.md +108 -0
- data/README_GUIDE.md +52 -0
- data/RELEASE_NOTES.md +23 -0
- data/Rakefile +69 -0
- data/da_funk.gemspec +31 -0
- data/ext/da_funk/Makefile +5 -0
- data/ext/da_funk/extconf.rb +8 -0
- data/guides/sample_input_output.rb +14 -0
- data/guides/sample_message_iso8583.rb +14 -0
- data/guides/sample_network_gprs.rb +26 -0
- data/guides/sample_read_magnect_card.rb +8 -0
- data/guides/sample_socket.rb +29 -0
- data/guides/sample_transaction.rb +23 -0
- data/guides/sample_transaction_download_application.rb +9 -0
- data/guides/sample_transaction_download_file.rb +6 -0
- data/guides/sample_transaction_download_parameter_file.rb +18 -0
- data/guides/sample_transaction_iso8583.rb +222 -0
- data/imgs/daft-punk-da-funk.jpg +0 -0
- data/lib/da_funk/rake_task.rb +129 -0
- data/lib/da_funk/test.rb +87 -0
- data/lib/da_funk.rb +39 -0
- data/lib/device/application.rb +41 -0
- data/lib/device/audio.rb +17 -0
- data/lib/device/crypto.rb +52 -0
- data/lib/device/display.rb +47 -0
- data/lib/device/helper.rb +161 -0
- data/lib/device/io.rb +86 -0
- data/lib/device/magnetic.rb +79 -0
- data/lib/device/network.rb +192 -0
- data/lib/device/notification.rb +116 -0
- data/lib/device/notification_callback.rb +47 -0
- data/lib/device/notification_event.rb +29 -0
- data/lib/device/params_dat.rb +119 -0
- data/lib/device/printer.rb +35 -0
- data/lib/device/runtime.rb +22 -0
- data/lib/device/setting.rb +63 -0
- data/lib/device/support.rb +28 -0
- data/lib/device/system.rb +61 -0
- data/lib/device/transaction/download.rb +268 -0
- data/lib/device/transaction/emv.rb +45 -0
- data/lib/device/transaction/iso.rb +75 -0
- data/lib/device/version.rb +11 -0
- data/lib/device/walk.rb +8 -0
- data/lib/device.rb +28 -0
- data/lib/ext/kernel.rb +9 -0
- data/lib/file_db.rb +47 -0
- data/lib/iso8583/bitmap.rb +114 -0
- data/lib/iso8583/codec.rb +197 -0
- data/lib/iso8583/exception.rb +4 -0
- data/lib/iso8583/field.rb +90 -0
- data/lib/iso8583/fields.rb +171 -0
- data/lib/iso8583/message.rb +455 -0
- data/lib/iso8583/util.rb +91 -0
- data/lib/iso8583/version.rb +6 -0
- data/lib/serfx/commands.rb +191 -0
- data/lib/serfx/connection.rb +160 -0
- data/lib/serfx/exceptions.rb +5 -0
- data/lib/serfx/response.rb +28 -0
- data/lib/serfx.rb +27 -0
- data/lib/version.rb +5 -0
- data/lib/zip.rb +29 -0
- data/test/integration/getc_test.rb +6 -0
- data/test/integration/mrb_eval_test.rb +36 -0
- data/test/integration/notification_test.rb +20 -0
- data/test/integration/params_dat_test.rb +11 -0
- data/test/test_helper.rb +18 -0
- data/test/unit/device/display_test.rb +43 -0
- data/test/unit/device/helper_test.rb +61 -0
- data/test/unit/device/notification_callback_test.rb +6 -0
- data/test/unit/device/notification_event_test.rb +73 -0
- data/test/unit/device/notification_test.rb +21 -0
- data/utils/command_line_platform.rb +67 -0
- data/utils/test_run.rb +3 -0
- metadata +177 -0
@@ -0,0 +1,222 @@
|
|
1
|
+
require '../lib/iso8583'
|
2
|
+
require 'socket'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
module Guide
|
6
|
+
class TransactMessage < Device::Transaction::Iso
|
7
|
+
mti_format AN, :length => 4
|
8
|
+
|
9
|
+
# MTI
|
10
|
+
mti "0100", "Authorization request"
|
11
|
+
mti "0110", "Issuer Response"
|
12
|
+
mti "0120", "Authorization Advice"
|
13
|
+
mti "0121", "Authorisation Advice Repeat"
|
14
|
+
mti "0130", "Issuer Response to Authorization Advice"
|
15
|
+
mti "0200", "Acquirer Financial Request"
|
16
|
+
mti "0210", "Issuer Response to Financial Request"
|
17
|
+
mti "0220", "Acquirer Financial Advice"
|
18
|
+
mti "0221", "Acquirer Financial Advice repeat"
|
19
|
+
mti "0230", "Issuer Response to Financial Advice"
|
20
|
+
mti "0320", "Batch Upload"
|
21
|
+
mti "0330", "Batch Upload Response"
|
22
|
+
mti "0400", "Acquirer Reversal Request"
|
23
|
+
mti "0420", "Acquirer Reversal Advice"
|
24
|
+
mti "0421", "Acquirer Reversal Advice Repeat Message"
|
25
|
+
mti "0430", "Issuer Reversal Response"
|
26
|
+
mti "0500", "Batch Settlement request"
|
27
|
+
mti "0510", "Batch Settlement response"
|
28
|
+
mti "0800", "Network Management Request"
|
29
|
+
mti "0810", "Network Management Response"
|
30
|
+
mti "0820", "Network Management Advice"
|
31
|
+
|
32
|
+
# ISO-defined data elements
|
33
|
+
bmp 2, "Primary Account Number (PAN)", LLVAR_N, :max => 19
|
34
|
+
bmp 3, "Processing Code", N, :length => 6
|
35
|
+
bmp 4, "Amount (Transaction)", N, :length => 12
|
36
|
+
bmp 5, "Amount, settlement" , N, :length => 12
|
37
|
+
bmp 6, "Amount, Cardholder Billing" , N, :length => 12
|
38
|
+
bmp 7, "Date and Time, Transmission" , MMDDhhmmss
|
39
|
+
bmp 8, "Amount, cardholder billing fee" , N, :length => 8
|
40
|
+
bmp 9, "Conversion rate, settlement" , N, :length => 8
|
41
|
+
bmp 10, "Conversion Rate, Cardholder Billing", N, :length => 8
|
42
|
+
bmp 11, "System Trace Audit Number (STAN)", ANS, :length => 6
|
43
|
+
bmp 12, "Time, local transaction (hhmmss)", Hhmmss
|
44
|
+
bmp 13, "Date, local transaction (MMDD)", MMDD
|
45
|
+
bmp 14, "Date, Expiration", N, :length => 4
|
46
|
+
bmp 15, "Date, Expiration", N, :length => 4
|
47
|
+
bmp 16, "Date, conversion", N, :length => 4
|
48
|
+
bmp 17, "Date, capture", N, :length => 4
|
49
|
+
bmp 18, "Merchant type", N, :length => 4
|
50
|
+
bmp 19, "Acquiring institution country code", N, :length => 3
|
51
|
+
bmp 20, "PAN extended, country code", N, :length => 3
|
52
|
+
bmp 21, "Forwarding institution. country code", N, :length => 3
|
53
|
+
bmp 22, "POS Data Code", AN, :length => 12
|
54
|
+
bmp 23, "Card Sequence Number", N, :length => 3
|
55
|
+
bmp 24, "Function Code", N, :length => 3
|
56
|
+
bmp 25, "Message Reason Code", N, :length => 4
|
57
|
+
bmp 26, "Card Acceptor Business Code", N, :length => 4
|
58
|
+
bmp 27, "Authorizing identification response length", N, :length => 1
|
59
|
+
bmp 28, "Amount, transaction fee", N, :length => 8
|
60
|
+
bmp 29, "Amount, settlement fee", N, :length => 8
|
61
|
+
bmp 30, "Amount, transaction processing fee", N, :length => 8
|
62
|
+
bmp 31, "Amount, settlement processing fee", N, :length => 8
|
63
|
+
bmp 32, "Acquiring Institution Identification Code", LLVAR_N, :max => 11
|
64
|
+
bmp 33, "Forwarding institution identification code", LLVAR_N, :max => 11
|
65
|
+
bmp 34, "Primary account number, extended", LLVAR_N, :max => 28
|
66
|
+
bmp 35, "Track 2 Data", LLVAR_Z, :max => 37
|
67
|
+
bmp 36, "Track 3 Data", LLVAR_N, :max => 104
|
68
|
+
bmp 37, "Retrieval Reference Number", ANP, :length => 12
|
69
|
+
bmp 38, "Approval Code", ANP, :length => 6
|
70
|
+
bmp 39, "Action Code", N, :length => 2
|
71
|
+
bmp 40, "Action Code", AN, :length => 3
|
72
|
+
bmp 41, "Card Acceptor Terminal Identification", ANS, :length => 8
|
73
|
+
bmp 42, "Card Acceptor Identification Code", ANS, :length => 15
|
74
|
+
bmp 43, "Card Acceptor Name/Location", ANS, :length => 40
|
75
|
+
bmp 44, "Additional response data", LLVAR_AN, :max => 25
|
76
|
+
bmp 45, "Track 1 data", LLVAR_AN, :max => 76
|
77
|
+
bmp 46, "Additional data - private", LLVAR_AN, :max => 999
|
78
|
+
bmp 47, "Additional data - private", LLVAR_AN, :max => 999
|
79
|
+
bmp 48, "Additional data - private", LLLVAR_AN, :max => 22
|
80
|
+
bmp 49, "Currency Code, Transaction", N, :length => 3
|
81
|
+
bmp 50, "Currency Code, Settlement", N, :length => 3
|
82
|
+
bmp 51, "Currency Code, Cardholder Billing", N, :length => 3
|
83
|
+
bmp 52, "Personal Identification Number (PIN) Data", B, :length => 8
|
84
|
+
bmp 53, "Security Related Control Information", N, :length => 16
|
85
|
+
bmp 54, "Amounts, Additional", LLLVAR_ANS, :max => 120
|
86
|
+
bmp 55, "Integrated Circuit Card (ICC)", LLLVAR_B, :max => 255
|
87
|
+
bmp 56, "Original Data Elements", LLVAR_N, :max => 35
|
88
|
+
bmp 57, "Reserved national", LLLVAR_ANS, :max => 999
|
89
|
+
bmp 58, "Authorizing Agent Institution ID Code", LLVAR_N, :max => 11
|
90
|
+
bmp 59, "Additional Data - Private", LLLVAR_ANS, :max => 67
|
91
|
+
bmp 60, "Reserved national", LLLVAR_N, :max => 999
|
92
|
+
bmp 61, "Reserved private", LLLVAR_ANS, :max => 999
|
93
|
+
bmp 62, "Reserved private", LLLVAR_ANS, :max => 999
|
94
|
+
bmp 63, "Additional Data - Private", LLLVAR_ANS, :max => 67
|
95
|
+
bmp 64, "Message Authentication Code (MAC) Field", B, :length => 8
|
96
|
+
bmp 65, "Bitmap, extended", N, :length => 1
|
97
|
+
bmp 66, "Settlement code", N, :length => 1
|
98
|
+
bmp 67, "Extended payment code", N, :length => 2
|
99
|
+
bmp 68, "Receiving institution country code", N, :length => 3
|
100
|
+
bmp 69, "Settlement institution country code", N, :length => 3
|
101
|
+
bmp 70, "Network management information code", AN, :length => 3
|
102
|
+
bmp 71, "Message number", N, :length => 4
|
103
|
+
bmp 72, "Message number, last", N, :length => 4
|
104
|
+
bmp 73, "Date, action (YYMMDD)", YYMMDD
|
105
|
+
bmp 74, "Credits, number", N, :length => 10
|
106
|
+
bmp 75, "Credits, reversal number", N, :length => 10
|
107
|
+
bmp 76, "Debits, number", N, :length => 10
|
108
|
+
bmp 77, "Debits, reversal number", N, :length => 10
|
109
|
+
bmp 78, "Transfer number", N, :length => 10
|
110
|
+
bmp 79, "Transfer, reversal number", N, :length => 10
|
111
|
+
bmp 80, "Inquiries number", N, :length => 10
|
112
|
+
bmp 81, "Authorizations, number", N, :length => 10
|
113
|
+
bmp 82, "Credits, processing fee amount", N, :length => 12
|
114
|
+
bmp 83, "Credits, transaction fee amount", N, :length => 12
|
115
|
+
bmp 84, "Debits, processing fee amount", N, :length => 12
|
116
|
+
bmp 85, "Debits, transaction fee amount", N, :length => 12
|
117
|
+
bmp 86, "Credits, amount", N, :length => 16
|
118
|
+
bmp 87, "Credits, reversal amount", N, :length => 16
|
119
|
+
bmp 88, "Debits, amount", N, :length => 16
|
120
|
+
bmp 89, "Debits, reversal amount", N, :length => 16
|
121
|
+
bmp 90, "Original data elements", N, :length => 42
|
122
|
+
bmp 91, "File update code", AN, :length => 1
|
123
|
+
bmp 92, "File security code", AN, :length => 2
|
124
|
+
bmp 93, "Response indicator", AN, :length => 5
|
125
|
+
bmp 94, "Service indicator", AN, :length => 7
|
126
|
+
bmp 95, "Replacement amounts", AN, :length => 42
|
127
|
+
bmp 96, "Message security code", B, :length => 8
|
128
|
+
bmp 97, "Amount, net settlement", AN, :length => 16
|
129
|
+
bmp 98, "Payee", ANS, :length => 25
|
130
|
+
bmp 99, "Settlement institution identification code", LLVAR_N, :max => 11
|
131
|
+
bmp 100, "Receiving institution identification code", LLVAR_N, :max => 11
|
132
|
+
bmp 101, "File name", LLVAR_ANS, :max => 17
|
133
|
+
bmp 102, "Account identification 1", LLVAR_ANS, :max => 28
|
134
|
+
bmp 103, "Account identification 2", LLVAR_ANS, :max => 28
|
135
|
+
bmp 104, "Transaction description", LLLVAR_ANS, :max => 100
|
136
|
+
bmp 105, "Reserved for ISO use", LLLVAR_ANS, :max => 999
|
137
|
+
bmp 106, "Reserved for ISO use", LLLVAR_ANS, :max => 999
|
138
|
+
bmp 107, "Reserved for ISO use", LLLVAR_ANS, :max => 999
|
139
|
+
bmp 108, "Reserved for ISO use", LLLVAR_ANS, :max => 999
|
140
|
+
bmp 109, "Reserved for ISO use", LLLVAR_ANS, :max => 999
|
141
|
+
bmp 110, "Reserved for ISO use", LLLVAR_ANS, :max => 999
|
142
|
+
bmp 111, "Reserved for ISO use", LLLVAR_ANS, :max => 999
|
143
|
+
bmp 112, "Reserved for national use", LLLVAR_ANS, :max => 999
|
144
|
+
bmp 113, "Reserved for national use", LLLVAR_ANS, :max => 999
|
145
|
+
bmp 114, "Reserved for national use", LLLVAR_ANS, :max => 999
|
146
|
+
bmp 115, "Reserved for national use", LLLVAR_ANS, :max => 999
|
147
|
+
bmp 116, "Reserved for national use", LLLVAR_ANS, :max => 999
|
148
|
+
bmp 117, "Reserved for national use", LLLVAR_ANS, :max => 999
|
149
|
+
bmp 118, "Reserved for national use", LLLVAR_ANS, :max => 999
|
150
|
+
bmp 119, "Reserved for national use", LLLVAR_ANS, :max => 999
|
151
|
+
bmp 120, "Reserved for private use", LLLVAR_ANS, :max => 999
|
152
|
+
bmp 121, "Reserved for private use", LLLVAR_ANS, :max => 999
|
153
|
+
bmp 122, "Reserved for private use", LLLVAR_ANS, :max => 999
|
154
|
+
bmp 123, "Reserved for private use", LLLVAR_ANS, :max => 999
|
155
|
+
bmp 124, "Reserved for private use", LLLVAR_ANS, :max => 999
|
156
|
+
bmp 125, "Reserved for private use", LLLVAR_ANS, :max => 999
|
157
|
+
bmp 126, "Reserved for private use", LLLVAR_ANS, :max => 999
|
158
|
+
bmp 127, "Reserved for private use", LLLVAR_ANS, :max => 999
|
159
|
+
bmp 128, "Message authentication code", B, :length => 64
|
160
|
+
|
161
|
+
def self.send_message (iso8583message)
|
162
|
+
serial_terminal = "0000115030462365"
|
163
|
+
|
164
|
+
puts "TCP #{(socket = TCPSocket.new('switch.cloudwalk.io', 31415)).inspect}"
|
165
|
+
|
166
|
+
handshake = "#{serial_terminal};maxtraprivatelabel.posxml;0002;3.64"
|
167
|
+
|
168
|
+
socket.write handshake.insert(0, handshake.size.chr)
|
169
|
+
@message = socket.read(3)
|
170
|
+
|
171
|
+
puts "Company Name #{@message}"
|
172
|
+
|
173
|
+
if (@message != "err" && @message)
|
174
|
+
msgSend = iso8583message.to_b
|
175
|
+
socket.write(msgSend)
|
176
|
+
|
177
|
+
# Receive message length
|
178
|
+
msg = socket.recv(2)
|
179
|
+
|
180
|
+
# Receive message
|
181
|
+
buf = socket.recv(msg.unpack("s>").first)
|
182
|
+
end
|
183
|
+
|
184
|
+
socket.close
|
185
|
+
|
186
|
+
return buf
|
187
|
+
end
|
188
|
+
|
189
|
+
def self.call
|
190
|
+
# Create ISO8583 message and set fields
|
191
|
+
date_time = DateTime.now
|
192
|
+
message = self.new
|
193
|
+
|
194
|
+
message.mti = "0800" # MTI
|
195
|
+
message[7] = date_time.strftime "%m%d%H%M%S" # Bit 7
|
196
|
+
message[11] = "000023" # Bit 11
|
197
|
+
message[12] = date_time.strftime "%H%M%S" # Bit 12
|
198
|
+
message[13] = date_time.strftime "%m%d" # Bit 13
|
199
|
+
message[41] = "00000002" # Bit 41
|
200
|
+
message[42] = "72010003" # Bit 42
|
201
|
+
message[60] = "09" # Bit 60
|
202
|
+
message[61] = "APPKS" # Bit 61
|
203
|
+
message[70] = "001" # Bit 70
|
204
|
+
|
205
|
+
# Print ISO8583 Message
|
206
|
+
puts "Message ISO8583: " + message.to_b
|
207
|
+
puts "=" * 100
|
208
|
+
puts message.to_s
|
209
|
+
|
210
|
+
# Try send ISO8583 Message
|
211
|
+
puts "=" * 100
|
212
|
+
bufRecv = self.send_send(message)
|
213
|
+
# bufRecv = "08008238000000C000180400000000000000071103041000002303041007110000000272010003 00209005APPKS001"
|
214
|
+
puts "Buffer Received: " + bufRecv
|
215
|
+
|
216
|
+
# Parse message
|
217
|
+
msgRecv = self.parse bufRecv
|
218
|
+
puts "=" * 100
|
219
|
+
p msgRecv
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
Binary file
|
@@ -0,0 +1,129 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require 'rake/tasklib'
|
5
|
+
require 'fileutils'
|
6
|
+
require 'bundler/setup'
|
7
|
+
|
8
|
+
module DaFunk
|
9
|
+
class RakeTask < ::Rake::TaskLib
|
10
|
+
include ::Rake::DSL if defined?(::Rake::DSL)
|
11
|
+
|
12
|
+
attr_accessor :name, :libs, :tests, :tests_unit, :tests_integration, :root_path, :main_out, :test_out, :resources, :mrbc, :mruby, :out_path, :resources_out
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
yield self if block_given?
|
16
|
+
|
17
|
+
@libs ||= FileList['lib/**/*.rb']
|
18
|
+
@tests ||= FileList['test/**/*test.rb']
|
19
|
+
@tests_integration ||= FileList['test/integration/**/*test.rb']
|
20
|
+
@tests_unit ||= FileList['test/unit/**/*test.rb']
|
21
|
+
@root_path ||= File.expand_path("./")
|
22
|
+
@name ||= File.basename(root_path)
|
23
|
+
@out_path ||= File.join(root_path, "out", @name)
|
24
|
+
@main_out ||= File.join(out_path, "main.mrb")
|
25
|
+
@test_out ||= File.join(out_path, "test.mrb")
|
26
|
+
@resources ||= FileList['resources/**/*']
|
27
|
+
@resources_out ||= @resources.pathmap("%{resources,#{out_path}}p")
|
28
|
+
@mruby ||= "cloudwalk run"
|
29
|
+
@mrbc = get_mrbc_bin(@mrbc)
|
30
|
+
|
31
|
+
define
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_mrbc_bin(from_user)
|
35
|
+
if (! system("type mrbc > /dev/null 2>&1 ")) && from_user
|
36
|
+
from_user
|
37
|
+
elsif system("type mrbc > /dev/null 2>&1 ")
|
38
|
+
"env mrbc"
|
39
|
+
elsif ENV["MRBC"]
|
40
|
+
ENV["MRBC"]
|
41
|
+
elsif system("type cloudwalk > /dev/null 2>&1 ")
|
42
|
+
"env cloudwalk compile"
|
43
|
+
else
|
44
|
+
puts "$MRBC isn't set or mrbc/cloudwalk isn't on $PATH"
|
45
|
+
exit 0
|
46
|
+
end
|
47
|
+
|
48
|
+
# right!
|
49
|
+
#if ENV["MRBC"].nil? && from_user
|
50
|
+
#from_user
|
51
|
+
#elsif ENV["MRBC"]
|
52
|
+
#ENV["MRBC"]
|
53
|
+
#elsif system("type mrbc > /dev/null 2>&1 ")
|
54
|
+
#"env mrbc"
|
55
|
+
#elsif system("type cloudwalk > /dev/null 2>&1 ")
|
56
|
+
#"env cloudwalk compile"
|
57
|
+
#else
|
58
|
+
#puts "$MRBC isn't set or mrbc/cloudwalk isn't on $PATH"
|
59
|
+
#exit 0
|
60
|
+
#end
|
61
|
+
end
|
62
|
+
|
63
|
+
def execute_tests(files)
|
64
|
+
all_files = FileList["test/test_helper.rb"] + libs + files + [File.join(File.dirname(__FILE__), "..", "..", "utils", "command_line_platform.rb")] + [File.join(File.dirname(__FILE__), "..", "..", "utils", "test_run.rb")]
|
65
|
+
if sh("#{mrbc} -g -o #{test_out} #{all_files.uniq}")
|
66
|
+
puts "cd #{File.dirname(out_path)}"
|
67
|
+
FileUtils.cd File.dirname(out_path)
|
68
|
+
sh("#{mruby} #{File.join(out_path, "test.mrb")}")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def define
|
73
|
+
task :resources do
|
74
|
+
FileUtils.rm_rf File.join(root_path, "out")
|
75
|
+
FileUtils.mkdir_p out_path
|
76
|
+
FileUtils.mkdir_p File.join(root_path, "out", "main")
|
77
|
+
FileUtils.mkdir_p File.join(root_path, "out", "shared")
|
78
|
+
|
79
|
+
resources.each_with_index do |file,dest_i|
|
80
|
+
FileUtils.cp(file, resources_out[dest_i]) if File.file?(file)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
desc "Compile app to mrb and process resources"
|
85
|
+
task :build => :resources do
|
86
|
+
FileUtils.mkdir_p out_path
|
87
|
+
|
88
|
+
Bundler.load.specs.each do |gem|
|
89
|
+
sh "cp #{File.join(gem.full_gem_path, "out", gem.name)}.mrb #{out_path}/#{gem.name}.mrb" if File.exists? "#{File.join(gem.full_gem_path, "out", gem.name)}.mrb"
|
90
|
+
end
|
91
|
+
|
92
|
+
sh "#{mrbc} -g -o #{main_out} #{libs} "
|
93
|
+
end
|
94
|
+
|
95
|
+
namespace :test do
|
96
|
+
task :setup => :resources do
|
97
|
+
ENV["RUBY_PLATFORM"] = "mruby"
|
98
|
+
Bundler.load.specs.each do |gem|
|
99
|
+
sh "cp #{File.join(gem.full_gem_path, "out", gem.name)}.mrb #{out_path}/#{gem.name}.mrb" if File.exists? "#{File.join(gem.full_gem_path, "out", gem.name)}.mrb"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
desc "Run unit test on mruby"
|
104
|
+
task :unit => "test:setup" do
|
105
|
+
execute_tests(tests_unit)
|
106
|
+
end
|
107
|
+
|
108
|
+
desc "Run integration test on mruby"
|
109
|
+
task :integration => "test:setup" do
|
110
|
+
execute_tests(tests_integration)
|
111
|
+
end
|
112
|
+
|
113
|
+
desc "Run all test on mruby"
|
114
|
+
task :all => "test:setup" do
|
115
|
+
execute_tests(tests)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
desc "Clobber/Clean"
|
120
|
+
task :clean do
|
121
|
+
FileUtils.mkdir_p File.join(root_path, "out")
|
122
|
+
FileUtils.rm_rf main_out
|
123
|
+
end
|
124
|
+
|
125
|
+
task :default => :build
|
126
|
+
task :test => "test:all"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
data/lib/da_funk/test.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
|
2
|
+
module DaFunk
|
3
|
+
module MRuby
|
4
|
+
def case
|
5
|
+
engine::TestCase
|
6
|
+
end
|
7
|
+
|
8
|
+
def engine
|
9
|
+
MTest::Unit
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
engine.new.run
|
14
|
+
end
|
15
|
+
|
16
|
+
def setup
|
17
|
+
# TODO Scalone check this
|
18
|
+
#libs.each do |file|
|
19
|
+
#p file
|
20
|
+
##require file
|
21
|
+
#end
|
22
|
+
end
|
23
|
+
|
24
|
+
def platform
|
25
|
+
:mruby
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
module CRuby
|
30
|
+
def case
|
31
|
+
engine::TestCase
|
32
|
+
end
|
33
|
+
|
34
|
+
def engine
|
35
|
+
::Test::Unit
|
36
|
+
end
|
37
|
+
|
38
|
+
def run; end
|
39
|
+
|
40
|
+
def setup
|
41
|
+
require 'fileutils'
|
42
|
+
require 'test/unit'
|
43
|
+
|
44
|
+
libs.each do |file|
|
45
|
+
require file
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def platform
|
50
|
+
:cruby
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class Test
|
55
|
+
class << self
|
56
|
+
attr_accessor :root_path, :libs, :tests
|
57
|
+
|
58
|
+
if Object.const_defined?(:MTest)
|
59
|
+
include DaFunk::MRuby
|
60
|
+
else
|
61
|
+
include DaFunk::CRuby
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.mruby?
|
66
|
+
platform == :mruby
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.cruby?
|
70
|
+
platform == :cruby
|
71
|
+
end
|
72
|
+
|
73
|
+
# TODO Scalone Refactor tests/libs for mruby and cruby checking project configuration
|
74
|
+
def self.configure
|
75
|
+
yield self if block_given?
|
76
|
+
|
77
|
+
@root_path ||= File.dirname("./")
|
78
|
+
if self.cruby?
|
79
|
+
@libs ||= FileList[File.join(root_path, 'lib/**/*.rb')]
|
80
|
+
@tests ||= FileList[File.join(root_path, 'test/**/*test.rb')]
|
81
|
+
end
|
82
|
+
|
83
|
+
self.setup
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
data/lib/da_funk.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
unless Object.const_defined?(:MTest)
|
2
|
+
file_path = File.dirname(File.realpath(__FILE__))
|
3
|
+
require file_path + "/device/support.rb"
|
4
|
+
require file_path + "/device/helper.rb"
|
5
|
+
require file_path + "/device/crypto.rb"
|
6
|
+
require file_path + "/device/display.rb"
|
7
|
+
require file_path + "/device/io.rb"
|
8
|
+
require file_path + "/device/network.rb"
|
9
|
+
require file_path + "/device/printer.rb"
|
10
|
+
require file_path + "/device/setting.rb"
|
11
|
+
require file_path + "/device/system.rb"
|
12
|
+
require file_path + "/device/version.rb"
|
13
|
+
require file_path + "/device/walk.rb"
|
14
|
+
require file_path + "/device/params_dat.rb"
|
15
|
+
require file_path + "/device.rb"
|
16
|
+
require file_path + "/file_db.rb"
|
17
|
+
require file_path + "/iso8583/bitmap.rb"
|
18
|
+
require file_path + "/iso8583/codec.rb"
|
19
|
+
require file_path + "/iso8583/exception.rb"
|
20
|
+
require file_path + "/iso8583/field.rb"
|
21
|
+
require file_path + "/iso8583/fields.rb"
|
22
|
+
require file_path + "/iso8583/message.rb"
|
23
|
+
require file_path + "/iso8583/util.rb"
|
24
|
+
require file_path + "/iso8583/version.rb"
|
25
|
+
require file_path + "/version.rb"
|
26
|
+
require file_path + "/device/transaction/download.rb"
|
27
|
+
require file_path + "/device/transaction/emv.rb"
|
28
|
+
require file_path + "/device/transaction/iso.rb"
|
29
|
+
require file_path + "/da_funk/rake_task.rb"
|
30
|
+
require file_path + "/da_funk/test.rb"
|
31
|
+
require file_path + "/../utils/command_line_platform.rb"
|
32
|
+
end
|
33
|
+
|
34
|
+
module DaFunk
|
35
|
+
def self.setup_command_line
|
36
|
+
# TODO Setup the environment to command line
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class Device
|
2
|
+
class Application
|
3
|
+
attr_reader :label, :file_path, :type, :crc, :order, :name
|
4
|
+
|
5
|
+
def initialize(label, file_path, type, crc)
|
6
|
+
@name = label
|
7
|
+
@order, @label = split_label(label)
|
8
|
+
@file_path = file_path
|
9
|
+
@type = type
|
10
|
+
@crc = crc
|
11
|
+
end
|
12
|
+
|
13
|
+
def file
|
14
|
+
@file ||= file_path.gsub("#{Device::Setting.company_name}_", "")
|
15
|
+
end
|
16
|
+
|
17
|
+
def file_no_ext
|
18
|
+
@file_no_ext ||= file.split(".")[0]
|
19
|
+
end
|
20
|
+
|
21
|
+
def zip
|
22
|
+
@zip ||= "#{file_no_ext}.zip"
|
23
|
+
end
|
24
|
+
|
25
|
+
def execute(json = "")
|
26
|
+
Device::Runtime.execute(file_no_ext, json)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def split_label(text)
|
31
|
+
if text == "X"
|
32
|
+
number, text = 0, "X"
|
33
|
+
else
|
34
|
+
number, text = text.to_s.split(" - ")
|
35
|
+
end
|
36
|
+
|
37
|
+
[number.to_i, text.to_s]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
data/lib/device/audio.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
class Device
|
3
|
+
class Audio
|
4
|
+
def self.adapter
|
5
|
+
Device.adapter::Audio
|
6
|
+
end
|
7
|
+
|
8
|
+
# Play beep
|
9
|
+
#
|
10
|
+
# @param tone [Fixnum] 0 to 6
|
11
|
+
# @param miliseconds [Fixnum] beep duration in miliseconds
|
12
|
+
# @return [nil]
|
13
|
+
def self.beep(tone, miliseconds)
|
14
|
+
adapter.beep(tone, miliseconds)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
class Device
|
3
|
+
class Crypto
|
4
|
+
CCITT_16 = [
|
5
|
+
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
|
6
|
+
0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
|
7
|
+
0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
|
8
|
+
0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
|
9
|
+
0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
|
10
|
+
0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
|
11
|
+
0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
|
12
|
+
0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
|
13
|
+
0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
|
14
|
+
0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
|
15
|
+
0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
|
16
|
+
0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
|
17
|
+
0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
|
18
|
+
0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
|
19
|
+
0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
|
20
|
+
0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
|
21
|
+
0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
|
22
|
+
0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
|
23
|
+
0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
|
24
|
+
0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
|
25
|
+
0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
|
26
|
+
0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
|
27
|
+
0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
|
28
|
+
0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
|
29
|
+
0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
|
30
|
+
0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
|
31
|
+
0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
|
32
|
+
0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
|
33
|
+
0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
|
34
|
+
0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
|
35
|
+
0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
|
36
|
+
0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
|
37
|
+
]
|
38
|
+
|
39
|
+
def self.crc16_hex(buf)
|
40
|
+
crc = crc16(buf)
|
41
|
+
# to swap the number just invert the order of the indexes [0..1] and [2..3]
|
42
|
+
#"#{crc.to_s(16).rjust(4,"0")[0..1]}#{crc.to_s(16).rjust(4,"0")[2..3]}".upcase
|
43
|
+
crc.to_s(16).upcase
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.crc16(buf, crc=0)
|
47
|
+
buf.each_byte{|x| crc = ((crc<<8) ^ CCITT_16[(crc>>8) ^ x])&0xffff}
|
48
|
+
crc
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class Device
|
2
|
+
class Display
|
3
|
+
def self.adapter
|
4
|
+
Device.adapter::Display
|
5
|
+
end
|
6
|
+
|
7
|
+
# Display buffer
|
8
|
+
#
|
9
|
+
# @param buf [String] Text to be printed.
|
10
|
+
# @param row [Fixnum] Row to start display.
|
11
|
+
# @param column [Fixnum] Column to start display.
|
12
|
+
# @return [NilClass] nil.
|
13
|
+
def self.print(buf, row = nil, column = nil)
|
14
|
+
if row.nil? && column.nil?
|
15
|
+
adapter.print(buf)
|
16
|
+
else
|
17
|
+
adapter.print_in_line(buf, row, column)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.print_line(buf, row = 0, column = 0)
|
22
|
+
self.print(buf, row, column)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Display bitmap
|
26
|
+
#
|
27
|
+
# @param path [String] path
|
28
|
+
# @param row [Fixnum] Row to start display.
|
29
|
+
# @param column [Fixnum] Column to start display.
|
30
|
+
# @return [NilClass] nil.
|
31
|
+
def self.print_bitmap(path, row = 0, column = 0)
|
32
|
+
raise(File::FileError, path) unless File.exists?(path)
|
33
|
+
adapter.display_bitmap(path, row, column)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Clean display
|
37
|
+
#
|
38
|
+
# @param line [Fixnum] Line to clear
|
39
|
+
def self.clear(line = nil)
|
40
|
+
if line.nil?
|
41
|
+
adapter.clear
|
42
|
+
else
|
43
|
+
adapter.clear_line line
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|