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.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.yardopts +12 -0
  4. data/Gemfile +7 -0
  5. data/Gemfile.lock +21 -0
  6. data/README.md +108 -0
  7. data/README_GUIDE.md +52 -0
  8. data/RELEASE_NOTES.md +23 -0
  9. data/Rakefile +69 -0
  10. data/da_funk.gemspec +31 -0
  11. data/ext/da_funk/Makefile +5 -0
  12. data/ext/da_funk/extconf.rb +8 -0
  13. data/guides/sample_input_output.rb +14 -0
  14. data/guides/sample_message_iso8583.rb +14 -0
  15. data/guides/sample_network_gprs.rb +26 -0
  16. data/guides/sample_read_magnect_card.rb +8 -0
  17. data/guides/sample_socket.rb +29 -0
  18. data/guides/sample_transaction.rb +23 -0
  19. data/guides/sample_transaction_download_application.rb +9 -0
  20. data/guides/sample_transaction_download_file.rb +6 -0
  21. data/guides/sample_transaction_download_parameter_file.rb +18 -0
  22. data/guides/sample_transaction_iso8583.rb +222 -0
  23. data/imgs/daft-punk-da-funk.jpg +0 -0
  24. data/lib/da_funk/rake_task.rb +129 -0
  25. data/lib/da_funk/test.rb +87 -0
  26. data/lib/da_funk.rb +39 -0
  27. data/lib/device/application.rb +41 -0
  28. data/lib/device/audio.rb +17 -0
  29. data/lib/device/crypto.rb +52 -0
  30. data/lib/device/display.rb +47 -0
  31. data/lib/device/helper.rb +161 -0
  32. data/lib/device/io.rb +86 -0
  33. data/lib/device/magnetic.rb +79 -0
  34. data/lib/device/network.rb +192 -0
  35. data/lib/device/notification.rb +116 -0
  36. data/lib/device/notification_callback.rb +47 -0
  37. data/lib/device/notification_event.rb +29 -0
  38. data/lib/device/params_dat.rb +119 -0
  39. data/lib/device/printer.rb +35 -0
  40. data/lib/device/runtime.rb +22 -0
  41. data/lib/device/setting.rb +63 -0
  42. data/lib/device/support.rb +28 -0
  43. data/lib/device/system.rb +61 -0
  44. data/lib/device/transaction/download.rb +268 -0
  45. data/lib/device/transaction/emv.rb +45 -0
  46. data/lib/device/transaction/iso.rb +75 -0
  47. data/lib/device/version.rb +11 -0
  48. data/lib/device/walk.rb +8 -0
  49. data/lib/device.rb +28 -0
  50. data/lib/ext/kernel.rb +9 -0
  51. data/lib/file_db.rb +47 -0
  52. data/lib/iso8583/bitmap.rb +114 -0
  53. data/lib/iso8583/codec.rb +197 -0
  54. data/lib/iso8583/exception.rb +4 -0
  55. data/lib/iso8583/field.rb +90 -0
  56. data/lib/iso8583/fields.rb +171 -0
  57. data/lib/iso8583/message.rb +455 -0
  58. data/lib/iso8583/util.rb +91 -0
  59. data/lib/iso8583/version.rb +6 -0
  60. data/lib/serfx/commands.rb +191 -0
  61. data/lib/serfx/connection.rb +160 -0
  62. data/lib/serfx/exceptions.rb +5 -0
  63. data/lib/serfx/response.rb +28 -0
  64. data/lib/serfx.rb +27 -0
  65. data/lib/version.rb +5 -0
  66. data/lib/zip.rb +29 -0
  67. data/test/integration/getc_test.rb +6 -0
  68. data/test/integration/mrb_eval_test.rb +36 -0
  69. data/test/integration/notification_test.rb +20 -0
  70. data/test/integration/params_dat_test.rb +11 -0
  71. data/test/test_helper.rb +18 -0
  72. data/test/unit/device/display_test.rb +43 -0
  73. data/test/unit/device/helper_test.rb +61 -0
  74. data/test/unit/device/notification_callback_test.rb +6 -0
  75. data/test/unit/device/notification_event_test.rb +73 -0
  76. data/test/unit/device/notification_test.rb +21 -0
  77. data/utils/command_line_platform.rb +67 -0
  78. data/utils/test_run.rb +3 -0
  79. metadata +177 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1428a015e59da2c2ba1c5b7db367d3a675d8dc27
4
+ data.tar.gz: 9932163afefdab19e28393464f99aeebbc3a450b
5
+ SHA512:
6
+ metadata.gz: 99b76fb9cf5da0fbdc7e1b9c40fd3e687ef5f650facf6b89b228f0680e3e949e9d5ff06e60e8fbe8be8c12de2898689ba66c4592ee3d10e0ef8d78d355ccf80c
7
+ data.tar.gz: 39ad52f41a43b49e6c6e053a9a0c1c691a4d4755d37414221678bc4be7533c4b75169fe325d90cc42e31eee2c8e9333c4a8ff680ea1e6bc831ada8a4edf5dc12
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ .yardoc/*
2
+ _yardoc/*
3
+ doc/*
4
+ rdoc/*
5
+ .bundle
6
+ coverage/*
7
+ stats
8
+ stats/*
9
+ out/da_funk.mrb
10
+ out/da_funk/*
11
+ out/*
data/.yardopts ADDED
@@ -0,0 +1,12 @@
1
+ --protected
2
+ --no-private
3
+ --readme README_GUIDE.md
4
+ --title 'CloudWalk Ruby API Documentation'
5
+ --charset utf-8
6
+ 'lib/device/**/*.rb'
7
+ 'lib/device.rb'
8
+ 'lib/iso8583/*.rb'
9
+ 'lib/iso8583.rb'
10
+ 'lib/file_db.rb'
11
+ 'guides/*'
12
+ - guides/*
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ group :development do
4
+ gem 'yard'
5
+ end
6
+
7
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,21 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ da_funk (0.4.4)
5
+ bundler (~> 1.7)
6
+ rake (~> 10.4)
7
+ yard (~> 0.8)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ rake (10.4.2)
13
+ yard (0.8.7.6)
14
+
15
+ PLATFORMS
16
+ ruby
17
+ x86-mingw32
18
+
19
+ DEPENDENCIES
20
+ da_funk!
21
+ yard
data/README.md ADDED
@@ -0,0 +1,108 @@
1
+ # DaFunk
2
+
3
+ Walk Framework API, responsible for managed compatibility between implemented devices, and treat deprecated syntax or behaviour.
4
+
5
+ ## Setup
6
+
7
+ 1. Install Ruby 1.9.3 (mruby compatible)
8
+
9
+ 2. Bundle `$ bundle install`
10
+
11
+
12
+ ## Docs (yard)
13
+
14
+ 1. Generate: `$ rake yard`
15
+ 2. Open: `open docs/index.html`
16
+
17
+ ## How to
18
+
19
+ ### Steps
20
+
21
+ 1. Add da_funk as submodule `$ git submodule add git@github.com:cloudwalkio/da_funk.git <path/to/lib/da_funk>`
22
+
23
+ 2. Develop start method in platform abstraction.
24
+
25
+ Start method is responsible for start the runtime in our platform. And should require the da_funk lib(common lib between platforms).
26
+
27
+ class PlatformInterface
28
+ def self.start(file = "./main.mrb")
29
+ begin
30
+ require "./da_funk.mrb"
31
+ require "./platform.mrb"
32
+ require file
33
+
34
+ app = Device::Support.path_to_class file
35
+
36
+ loop do
37
+ app.call
38
+ end
39
+ rescue => @exception
40
+ puts "#{@exception.class}: #{@exception.message}"
41
+ puts "#{@exception.backtrace[0..2].join("\n")}"
42
+ IO.getc
43
+ return nil
44
+ end
45
+ end
46
+ end
47
+
48
+ 3. Develop interface required by DaFunk on PlatformInterface, could be the same file you have start method.
49
+
50
+ class PlatformInterface
51
+ Network = ::Network # Implemented on C
52
+ IO = ::IO # Implemeted on C
53
+
54
+ class Display
55
+ def self.clear
56
+ ::IO.display_clear
57
+ end
58
+
59
+ def self.print_line(buf, row, column)
60
+ # <class created on C or PlatformInterface>._print_line(buf, row, column)
61
+ PlatformInterface._print_line(buf, row, column)
62
+ end
63
+ end
64
+ end
65
+
66
+ 4. Configure Adapter
67
+
68
+ class Device # Class from DaFunk
69
+ self.adapter = PlatformAbstraction
70
+ end
71
+
72
+ 5. Compile da_funk into mrb file `$ rake`.
73
+ 6. Compile platform abstraction into mrb file `$ mrbc -o platform.mrb </path/to/mrblib/**/*/.rb`
74
+ 7. Application file `main.rb`(could be use to test).
75
+
76
+ class Main
77
+ def self.call
78
+ Device::Display.print "Test"
79
+ end
80
+ end
81
+
82
+ Call method should be implemented on applications.
83
+
84
+
85
+ ### Adapter pattern
86
+ Adapter(platform abstraction) should be configured to access by DaFunk Library
87
+
88
+ - [Wiki](http://en.wikipedia.org/wiki/Adapter_pattern)
89
+ - Scheme Image (todo)
90
+
91
+
92
+ ### Platform Interface
93
+
94
+ - Be careful with instance object variable, let't for DaFunk.
95
+ - Prefer class methods to call as interface.
96
+ - Any method defined on platform language, access by PlatformAbstraction, should defined with _<method name>. # Revise this point
97
+
98
+
99
+ ## Contributing
100
+
101
+ 1. Fork it
102
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
103
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
104
+ 4. Push to the branch (`git push origin my-new-feature`)
105
+ 5. Create new Pull Request
106
+
107
+
108
+ ![DaFunk](imgs/daft-punk-da-funk.jpg)
data/README_GUIDE.md ADDED
@@ -0,0 +1,52 @@
1
+ ## Ruby Walk Framework
2
+
3
+ Ruby Walk Framework is a entire new VM for the Walk Platform, in Ruby, a modern and powerful language.
4
+
5
+
6
+ ## Ruby Compatiblity
7
+ Support for Ruby 1.9.3 and ISO/IEC 30170:2012, where specifies the syntax and semantics of the computer programming language Ruby, and the requirements for conforming Ruby processors, strictly conforming Ruby programs.
8
+
9
+ ## Devices
10
+ #### D200
11
+ Alpha support, System, Network, IO, Sockets, Transction::Iso, Transaction::Download and Magnectic Card.
12
+
13
+ #### Browser
14
+ Alpha support, System, Network, IO, Sockets, Transction::Iso, Transaction::Download.
15
+
16
+ #### Verifone
17
+ Comming soon.
18
+
19
+ #### Ingenico
20
+ Comming soon.
21
+
22
+ ## DaFunk API
23
+
24
+ Project responsible for managed compatibility between implemented devices, and treat deprecated syntax or behaviour.
25
+
26
+ ## Getting Started
27
+
28
+ ### D200 Environmet
29
+
30
+ #### Install PC Loader
31
+
32
+ Found in PAX resources, is needed to upload the BIN and main.rb
33
+
34
+ #### Upload Binary
35
+
36
+ Upload as App/Script, download [here](https://dl.dropboxusercontent.com/u/436039/walk/pax/robot_rock-0.4.2.bin).
37
+
38
+ #### Upload main.rb
39
+
40
+ Upload as Para Files, download [here](https://dl.dropboxusercontent.com/u/436039/walk/pax/main.rb)
41
+
42
+ ### Guides/Samples
43
+
44
+ 1. [Input and Output](file.sample_input_output.html)
45
+ 2. [Network](file.sample_network_gprs.html)
46
+ 3. [Sockets](file.sample_sockt.html)
47
+ 4. [Transaction](file.sample_transaction.html)
48
+ 5. [Download File](file.sample_transaction_download_file.html)
49
+ 6. [Applications](file.sample_transaction_download_application.html)
50
+ 7. [Read Magnect Card](file.sample_read_magnect_card.html)
51
+ 8. [ISO8583 Message](file.sample_message_iso8583.html)
52
+ 9. [Download and parse parameter file](file.sample_transaction_download_parameter_file.html)
data/RELEASE_NOTES.md ADDED
@@ -0,0 +1,23 @@
1
+ # DaFunk
2
+
3
+ ### 0.4.4 - 2015-03-27 - Gemspec summary and description.
4
+ - Fix gemspec summary and description.
5
+
6
+ ### 0.4.3 - 2015-03-27 - Refactoring Display interface
7
+ - Support resource configuration in DaFunk RakeTask.
8
+ - Refactoring IO/Display and UI methods.
9
+
10
+ ### 0.4.1 - 2015-03-10 - Small fixes and notifications
11
+ - Implement Serf protocol by serfx port.
12
+ - Support CloudWalk Notifications.
13
+ - Support to execute unit and integration tests.
14
+ - Fix check ssl = "1" to start handshake.
15
+ - Fix verify handshake return to fail handshake.
16
+ - Fix download by SSL, check received packet to increment downloaded size. It is posible to SSL interface return hald of asked size in the midle of process.
17
+ - Support to mruby and mrbc binary configuration at rake task creation.
18
+ - Implement Helper.rjust/ljust.
19
+ - Implement CommandLinePlatform to perform integration tests.
20
+ - Implement Zip class to abstract zip/unzip operations.
21
+ - Implement Magnetic class to abstract magnetic card read.
22
+
23
+ ### 0.3.2 - 2014-12-24 - First stable Version
data/Rakefile ADDED
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'rake/testtask'
4
+ require 'bundler/setup'
5
+
6
+ Bundler.require(:default)
7
+ DA_FUNK_ROOT = File.dirname(File.expand_path(__FILE__))
8
+
9
+ FileUtils.cd DA_FUNK_ROOT
10
+
11
+ FILES = FileList[
12
+ "lib/da_funk.rb",
13
+ "lib/da_funk/test.rb",
14
+ "lib/device.rb",
15
+ "lib/device/audio.rb",
16
+ "lib/device/crypto.rb",
17
+ "lib/device/display.rb",
18
+ "lib/device/helper.rb",
19
+ "lib/device/io.rb",
20
+ "lib/device/network.rb",
21
+ "lib/device/params_dat.rb",
22
+ "lib/device/printer.rb",
23
+ "lib/device/runtime.rb",
24
+ "lib/device/setting.rb",
25
+ "lib/device/support.rb",
26
+ "lib/device/system.rb",
27
+ "lib/device/transaction/download.rb",
28
+ "lib/device/transaction/emv.rb",
29
+ "lib/device/version.rb",
30
+ "lib/device/walk.rb",
31
+ "lib/file_db.rb",
32
+ "lib/iso8583/bitmap.rb",
33
+ "lib/iso8583/codec.rb",
34
+ "lib/iso8583/exception.rb",
35
+ "lib/iso8583/field.rb",
36
+ "lib/iso8583/fields.rb",
37
+ "lib/iso8583/message.rb",
38
+ "lib/iso8583/util.rb",
39
+ "lib/iso8583/version.rb",
40
+ "lib/version.rb",
41
+ "lib/device/transaction/iso.rb",
42
+ "lib/serfx.rb",
43
+ "lib/serfx/commands.rb",
44
+ "lib/serfx/connection.rb",
45
+ "lib/serfx/response.rb",
46
+ "lib/serfx/exceptions.rb",
47
+ "lib/device/notification_event.rb",
48
+ "lib/device/notification_callback.rb",
49
+ "lib/device/notification.rb",
50
+ "lib/device/application.rb",
51
+ "lib/zip.rb",
52
+ "lib/device/magnetic.rb",
53
+ "lib/ext/kernel.rb"
54
+ ]
55
+
56
+ DaFunk::RakeTask.new do |t|
57
+ t.main_out = "./out/da_funk.mrb"
58
+ t.libs = FILES
59
+ end
60
+
61
+ desc "Generate YARD Documentation"
62
+ task :yard do
63
+ Bundler.require(:default, :development)
64
+ sh "yard"
65
+ end
66
+
67
+ task "test:all" => :build
68
+ task "test:unit" => :build
69
+ task "test:integration" => :build
data/da_funk.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ tasks = File.expand_path('../tasks', __FILE__)
6
+ $LOAD_PATH.unshift(tasks) unless $LOAD_PATH.include?(tasks)
7
+
8
+ require 'version.rb'
9
+
10
+ Gem::Specification.new do |spec|
11
+ spec.name = "da_funk"
12
+ spec.version = Device::API_VERSION
13
+ spec.authors = ["Thiago Scalone"]
14
+ spec.email = ["thiago@cloudwalk.io"]
15
+ spec.summary = "MRuby Embedded System Framework"
16
+ spec.description = "DaFunk is a Embedded System Framework optimized for programmer happiness and sustainable productivity. It encourages beautiful code by favoring convention over configuration."
17
+ spec.homepage = "http://github.com/cloudwalkio/da_funk"
18
+ spec.license = "MIT"
19
+
20
+ spec.files = `git ls-files -z`.split("\x0")
21
+ spec.extensions = ["ext/da_funk/extconf.rb"]
22
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
23
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.required_ruby_version = '>= 1.9.3'
27
+
28
+ spec.add_dependency "rake", "~> 10.4"
29
+ spec.add_dependency "bundler", "~> 1.7"
30
+ spec.add_dependency "yard", "~> 0.8"
31
+ end
@@ -0,0 +1,5 @@
1
+ all:
2
+ true
3
+
4
+ install:
5
+ true
@@ -0,0 +1,8 @@
1
+ require 'rake'
2
+ require 'mkmf'
3
+
4
+ rakefile = File.join(File.dirname(File.expand_path(__FILE__)), "..", "..", "Rakefile")
5
+
6
+ if sh "bundle exec rake -f #{rakefile}"
7
+ $makefile_created = true
8
+ end
@@ -0,0 +1,14 @@
1
+ module Guide
2
+ # Input Output Test
3
+ def test_input_output
4
+ # Behaviour similar as c ruby
5
+ # Device::IO.puts same as Kerne.puts(string, row=nil, column=nil)
6
+ # puts is like a print + "\n"
7
+ Device::IO.puts "Display at row 0 column 0", 0, 0
8
+ puts "Pressed any key: ", 1
9
+ # Wait for some key
10
+ key = Device::IO.getc
11
+ # Print key pressed
12
+ print "key Pressed #{key}"
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module Guide
2
+ def test_message_iso
3
+ message = Device::Transaction::Iso.new
4
+ message.mti = 1110
5
+
6
+ message[2] = 474747474747
7
+ message["Processing Code"] = "123456"
8
+ pan = message["Primary Account Number (PAN)"]
9
+
10
+ puts message.pan
11
+ puts message.to_b
12
+ puts message.to_s
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+ module Guide
2
+ # Sample Device::Network
3
+ # Attach on GPRS
4
+ def test_sample_network_attach
5
+ # Initialize hardware with configurations
6
+ Device::Network.init(:gprs, apn: 'claro.com.br', user: 'claro.com.br', pass: 'claro.com.br')
7
+ # Start Attaching process
8
+ Device::Network.connect
9
+
10
+ # Attaching process is unblocking, for this sample let's wait until return something
11
+ iRet = 1
12
+ while(iRet == 1)
13
+ iRet = Device::Network.connected?
14
+ end
15
+ end
16
+
17
+ def test_sample_network_ping
18
+ test_sample_network_attach
19
+ Device::Network.ping("cloudwalk.io", 8000)
20
+ end
21
+
22
+ def test_sample_network_disconnect
23
+ test_sample_network_attach
24
+ puts "Disconnect #{Device::Network.disconnect}"
25
+ end
26
+ end
@@ -0,0 +1,8 @@
1
+ module Guide
2
+ def test_read_magnect_card
3
+ puts "Pass Card..."
4
+ card = Device::IO.read_card(5000)
5
+ puts "Track1 #{card[:track1]} Track2:#{card[:track2]} Track3:#{card[:track2]}"
6
+ end
7
+ end
8
+
@@ -0,0 +1,29 @@
1
+ module Guide
2
+ # Sample Socket
3
+ # Create socket, same syntax as default ruby standard library
4
+ def test_sample_socket
5
+ # Call test_sample_network to attach on GPRS
6
+ test_sample_network_attach
7
+
8
+ # Create TCPSocket
9
+ tcp = TCPSocket.new('cloudwalk.io', 80)
10
+ # print TCPSocket object
11
+ puts tcp.inspect
12
+
13
+ # Send and Recv some data
14
+ puts tcp.send('303132', 0)
15
+ puts "Recv #{tcp.recv(10)} "
16
+ puts "Closed? #{tcp.closed?}"
17
+ puts "Close #{tcp.close} "
18
+ puts "Closed? #{tcp.closed?}"
19
+ end
20
+
21
+ def test_sample_walk_socket
22
+ # Call test_sample_network to attach on GPRS
23
+ test_sample_network_attach
24
+
25
+ # Specific Walk Socket to transact in CloudWalk structure
26
+ Device::Network.walk_socket
27
+ end
28
+ end
29
+
@@ -0,0 +1,23 @@
1
+ module Guide
2
+ def test_transaction_data
3
+ # Open CloudWalk socket
4
+ socket = test_sample_walk_socket
5
+
6
+ # Send any data for registered server in that app
7
+ socket.send("data\n")
8
+
9
+ # Receive some data from server
10
+ puts "Recv Registered Server for this app: #{socket.recv(10).unpack("H*")}"
11
+
12
+ socket.close
13
+ Device::Network.disconnect
14
+ end
15
+
16
+ def test_transaction_iso8583
17
+ # peding test sample
18
+ end
19
+
20
+ def test_transaction_emv
21
+ # peding test sample
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ module Guide
2
+ def test_sample_transaction_download_application
3
+ tcp = test_sample_walk_socket
4
+ if Device::Transaction::Download.request_file("show.rb", "show.mrb")
5
+ load "show.mrb"
6
+ end
7
+ end
8
+ end
9
+
@@ -0,0 +1,6 @@
1
+ module Guide
2
+ def test_transaction_download_file
3
+ test_sample_network_attach
4
+ Device::Transaction::Download.request_file("remote_image_path.jpg", "local_image_path.jpg")
5
+ end
6
+ end
@@ -0,0 +1,18 @@
1
+ module Guide
2
+ def test_transaction_download_parameter_file
3
+ tcp = test_sample_walk_socket
4
+ if Device::Transaction::Download.request_param_file
5
+ file = FileDb.open("params.dat")
6
+ puts file.keys
7
+ file.apps_list
8
+ end
9
+ end
10
+
11
+ def test_transaction_download_and_parse_parameter_file
12
+ apps = test_transaction_download_parameter_file
13
+ apps.split(";").each do |line|
14
+ app = line.split(",")
15
+ puts "Name: #{app[0]}, Ruby File: #{app[1]} Aparece no menu: #{app[2]} CRC: #{app[3]}"
16
+ end
17
+ end
18
+ end