phidget_rfid 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4bd085dc7bff0f4795a65b3b782dfb73425f836d
4
+ data.tar.gz: 13a7a824e52d5cf517b1c9ca79ec9ecf83f87fc3
5
+ SHA512:
6
+ metadata.gz: bc6543af66cf7bbbca5c4d7904c637f2ce1c03e35c0062d2190789b6d5b4becf38434b7c5fea69ec1fc23f0792541cb3d30bba18d5a7d1671f6d5827278bf0a1
7
+ data.tar.gz: 0a89a8eeb24ff464ec5dbae77654085f136b4bbbcb31062091d512d86cd0dfef0df1d116dc8fa722a8eb1c177c2b9be921406d936d497c2bf66da7eedff99ee8
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in phidget_rfid.gemspec
4
+ gemspec
5
+
6
+ gem 'highline'
7
+ gem 'cli-console'
8
+ gem 'phidgets-ffi'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Luis Fontes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # PhidgetRfid
2
+
3
+ This is a simple ruby program to work with the Phidget RFID in the console
4
+
5
+ ## Installation:
6
+
7
+ gem install phitdget_rfid
8
+
9
+
10
+ ## Usage:
11
+ ```
12
+ phitdget_rfid
13
+ ```
14
+
15
+ And then you can use the help command
16
+
17
+ ```
18
+ RFID> help
19
+ ------------------------------
20
+ read - Read RFID tag
21
+ write - Write into the RFID tag
22
+ protocol - Display RFID Tag
23
+ device - Display RFID Reader info
24
+ clear - Clear Console
25
+ log - RFID Log
26
+ help - Help
27
+ exit - Exit from program
28
+ You can type "help <command>" for more info
29
+ ------------------------------
30
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/phidget_rfid ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #require "bundler/setup"
4
+ module PhidgetRfid
5
+
6
+ require 'highline'
7
+ require 'cli-console'
8
+ require "phidget_rfid"
9
+ require 'phidget_rfid/commands'
10
+
11
+ # You can add fixtures and/or initialization code here to make experimenting
12
+ # with your gem easier. You can also use a different console, if you like.
13
+
14
+ # (If you use this, don't forget to add pry to your Gemfile!)
15
+ # require "pry"
16
+ # Pry.start
17
+
18
+ #require "irb"
19
+ #IRB.start
20
+
21
+ Dir.chdir(File.dirname(__FILE__))
22
+
23
+ rfid = RfidHandler.new
24
+ io = HighLine.new
25
+ console = CLI::Console.new(io)
26
+ commands = Commands.new(rfid)
27
+
28
+
29
+ console.addCommand('read', commands.method(:read), 'Read RFID tag')
30
+ console.addCommand('write', commands.method(:write), 'Write into the RFID tag')
31
+ console.addCommand('protocol', commands.method(:protocol), 'Display RFID Tag')
32
+ console.addCommand('device', commands.method(:device), 'Display RFID Reader info')
33
+ console.addCommand('clear', commands.method(:clear), 'Clear Console')
34
+ console.addCommand('log', commands.method(:log), 'RFID Log')
35
+ console.addHelpCommand('help', 'Help')
36
+ console.addExitCommand('exit', 'Exit from program')
37
+ #console.addAlias('quit', 'exit')
38
+
39
+ console.start("%s> ",["RFID"])
40
+ end
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ require 'phidgets-ffi'
2
+ require 'phidget_rfid/rfid_handler'
3
+
4
+ module PhidgetRfid
5
+
6
+ end
@@ -0,0 +1,69 @@
1
+ module PhidgetRfid
2
+ class Commands
3
+
4
+ #Dir.chdir(params[0]) unless params.empty?
5
+
6
+
7
+ private
8
+ extend CLI::Task
9
+
10
+ @rfid
11
+
12
+ public
13
+
14
+ def initialize (rfid)
15
+ @rfid = rfid
16
+ end
17
+
18
+
19
+ usage 'Usage: read'
20
+ desc 'Reads the value from the connected RFID tag'
21
+
22
+ def read(params)
23
+ puts @rfid.read
24
+ end
25
+
26
+
27
+
28
+ usage 'Usage: write "string to write" <protocol> <lock>'
29
+ desc 'Writes the provided text into the RFID tag. Protocols: EM4100, ISO11785_FDX_B, PhidgetTAG, 1'
30
+
31
+ def write(params)
32
+ puts @rfid.write params[0] unless params.empty?
33
+ end
34
+
35
+
36
+
37
+ usage 'Usage: protocol'
38
+ desc 'Displays the current tag protocol'
39
+
40
+ def protocol(params)
41
+ puts @rfid.protocol
42
+ end
43
+
44
+
45
+
46
+ usage 'Usage: clear'
47
+ desc 'Clears the console'
48
+
49
+ def clear(params)
50
+ system "clear" or system "cls"
51
+ end
52
+
53
+ usage 'Usage: device'
54
+ desc 'Displays: reader id, serial number and state, Antenna and Led state. Library API version'
55
+
56
+ def device(params)
57
+ puts @rfid.device
58
+ end
59
+
60
+ usage 'Usage: log'
61
+ desc 'Shows the event log'
62
+
63
+ def log(params)
64
+ puts @rfid.log
65
+ end
66
+
67
+
68
+ end
69
+ end
@@ -0,0 +1,83 @@
1
+ module PhidgetRfid
2
+ class RfidHandler
3
+ @rfid
4
+ @prompt
5
+ @time
6
+ attr_accessor :log
7
+
8
+ def initialize()
9
+ @rfid = Phidgets::RFID.new
10
+ @time = Time.new
11
+ @prompt = "at #{@time.strftime("%Y-%m-%d %H:%M:%S")} \033[0m"
12
+ @log = ""
13
+
14
+ @rfid.on_detach do |device, obj|
15
+ @log.append "\n#{device.attributes.inspect} removed"
16
+ end
17
+
18
+ @rfid.on_attach do |device, obj|
19
+ @rfid.antenna = true
20
+ @rfid.led = false
21
+ end
22
+
23
+ @rfid.on_error do |device, obj, code, description|
24
+ @log << "\033[31m\nError #{code}: #{description} #{@prompt}"
25
+ end
26
+
27
+ @rfid.on_tag do |device, tag, obj|
28
+ @rfid.led = true
29
+ @log << "\n\033[32m[+] #{protocol} tag detected #{@prompt}"
30
+ end
31
+
32
+ @rfid.on_tag_lost do |device, tag, obj|
33
+ @rfid.led = false
34
+ @log << "\n\033[33m[-] #{protocol} tag removed #{@prompt}"
35
+ end
36
+
37
+
38
+ end
39
+
40
+ def protocol
41
+ if(@rfid.attached?)
42
+ @rfid.last_tag_protocol
43
+ end
44
+ end
45
+
46
+ def read
47
+ if(@rfid.attached?)
48
+ @rfid.last_tag
49
+ end
50
+ end
51
+
52
+ def write(value, protocol = @rfid.last_tag_protocol, lock = false)
53
+ if(@rfid.attached?)
54
+ p = protocol.to_sym
55
+
56
+ if lock
57
+ puts "Data: #{value}"
58
+ puts "Protocol: #{p}"
59
+ puts "Are you sure you want to lock the RFID Tag? This will make it read-only (y/N)"
60
+ r = gets.chomp
61
+ @rfid.write value, p, true if r == "y"
62
+
63
+ end
64
+
65
+ end
66
+ end
67
+
68
+ def device
69
+ puts "Library Version: #{Phidgets::FFI.library_version}"
70
+ puts "Class: #{device.device_class}"
71
+ puts "Id: #{device.id}"
72
+ puts "Serial number: #{device.serial_number}"
73
+ puts "# Digital Outputs: #{device.outputs.size}"
74
+ end
75
+
76
+
77
+
78
+ end
79
+
80
+ end
81
+
82
+
83
+
@@ -0,0 +1,3 @@
1
+ module PhidgetRfid
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'phidget_rfid/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "phidget_rfid"
8
+ spec.version = PhidgetRfid::VERSION
9
+ spec.authors = ["Luis Fontes"]
10
+ spec.email = ["mail.fontes@gmail.com"]
11
+
12
+ spec.summary = %q{PHIDGET RFID wrapper}
13
+ spec.description = %q{A simple console app to work with PHIDGET RFID.}
14
+ spec.homepage = "https://github.com/luisfontes19/phidget_rfid"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org/"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "bin"
27
+ spec.executables = 'phidget_rfid'
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec"
33
+ spec.add_runtime_dependency "highline"
34
+ spec.add_runtime_dependency "cli-console"
35
+ spec.add_runtime_dependency "phidgets-ffi"
36
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: phidget_rfid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Luis Fontes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: highline
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: cli-console
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: phidgets-ffi
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: A simple console app to work with PHIDGET RFID.
98
+ email:
99
+ - mail.fontes@gmail.com
100
+ executables:
101
+ - phidget_rfid
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/phidget_rfid
113
+ - bin/setup
114
+ - lib/phidget_rfid.rb
115
+ - lib/phidget_rfid/commands.rb
116
+ - lib/phidget_rfid/rfid_handler.rb
117
+ - lib/phidget_rfid/version.rb
118
+ - phidget_rfid.gemspec
119
+ homepage: https://github.com/luisfontes19/phidget_rfid
120
+ licenses:
121
+ - MIT
122
+ metadata:
123
+ allowed_push_host: https://rubygems.org/
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.6.7
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: PHIDGET RFID wrapper
144
+ test_files: []