tamashii-nfc 3.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8551114bb64654d4d9a8dc7a3c7b32a7cb5542c4
4
+ data.tar.gz: 0d39c47ea8c9fa93162492c5015b00ec05c09237
5
+ SHA512:
6
+ metadata.gz: 179ee7cab286a63039e12565a80fc9d9dc36f76f7ccf2fcbf0f677c4706e646532af803c27314b378ec4c95c9739415204a5ede500573d2454558af04d0ea427
7
+ data.tar.gz: 838923205132b08841b5523d860f3984762ec46fe544ea9ec93c9f89a7442deb37fcdfabf38f6db5f707ccd2d77a6e7016186a7f94080043d4e0d4705d384bc8
@@ -0,0 +1,23 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'autotest/restart'
4
+
5
+ # Autotest.add_hook :initialize do |at|
6
+ # at.extra_files << "../some/external/dependency.rb"
7
+ #
8
+ # at.libs << ":../some/external"
9
+ #
10
+ # at.add_exception 'vendor'
11
+ #
12
+ # at.add_mapping(/dependency.rb/) do |f, _|
13
+ # at.files_matching(/test_.*rb$/)
14
+ # end
15
+ #
16
+ # %w(TestA TestB).each do |klass|
17
+ # at.extra_class_map[klass] = "test/test_misc.rb"
18
+ # end
19
+ # end
20
+
21
+ # Autotest.add_hook :run_command do |at|
22
+ # system "rake build"
23
+ # end
@@ -0,0 +1,25 @@
1
+ === 2.1.0 / 2011-05-27
2
+
3
+ * 1 Enhancement
4
+
5
+ * Moved to libnfc version 1.5.x
6
+
7
+ === 2.0.1 / 2009-09-19
8
+
9
+ * 1 Bugfix
10
+
11
+ * Raising an exception when a reader cannot be found.
12
+
13
+ === 2.0.0 / 2009-08-07
14
+
15
+ * 2 major enhancements
16
+
17
+ * Switched from FFI to a C backend
18
+ * Now depends on libnfc 1.2.x
19
+
20
+ === 1.0.0 / 2009-06-01
21
+
22
+ * 1 major enhancement
23
+
24
+ * Birthday!
25
+
@@ -0,0 +1,19 @@
1
+ .autotest
2
+ CHANGELOG.rdoc
3
+ Manifest.txt
4
+ README.rdoc
5
+ Rakefile
6
+ bin/nfc
7
+ ext/nfc/context.c
8
+ ext/nfc/extconf.rb
9
+ ext/nfc/nfc.c
10
+ ext/nfc/nfc.h
11
+ ext/nfc/nfc_device.c
12
+ ext/nfc/nfc_felica.c
13
+ ext/nfc/nfc_iso14443a.c
14
+ lib/nfc.rb
15
+ lib/nfc/device.rb
16
+ lib/nfc/felica.rb
17
+ lib/nfc/iso14443a.rb
18
+ test/test_context.rb
19
+ test/test_device.rb
@@ -0,0 +1,76 @@
1
+ = NFC
2
+
3
+ * http://seattlerb.rubyforge.org
4
+
5
+ == DESCRIPTION:
6
+
7
+ NFC is a ruby wrapper for the Near Field Communication library. The Near
8
+ Field Communication library works with many USB RFID readers, so this gem
9
+ lets you read RFID tags.
10
+
11
+ == FEATURES/PROBLEMS:
12
+
13
+ * Only supports ISO1443A (MIFARE) tags right now.
14
+
15
+ == SYNOPSIS:
16
+
17
+ require 'nfc'
18
+
19
+ # Create a new context
20
+ ctx = NFC::Context.new
21
+
22
+ # Open the first available USB device
23
+ dev = ctx.open nil
24
+
25
+ # Block until a tag is available, then print tag info
26
+ p dev.select
27
+
28
+ # You can even run in an infinite loop if you'd like to continually find
29
+ # tags:
30
+
31
+ loop do
32
+ p dev.select
33
+ end
34
+
35
+ == REQUIREMENTS:
36
+
37
+ * A USB RFID reader. I'm using the touchatag[http://touchatag.com].
38
+ * libnfc
39
+
40
+ == INSTALL:
41
+
42
+ First install libnfc[http://libnfc.org/].
43
+ I installed libnfc via homebrew:
44
+
45
+ $ brew install libnfc
46
+
47
+ The install the gem:
48
+
49
+ $ sudo gem install nfc
50
+
51
+ NOTE!!!! The nfc gem requires libnfc version 1.7.0 or greater!
52
+
53
+ == LICENSE:
54
+
55
+ (The MIT License)
56
+
57
+ Copyright (c) 2009-2013 Aaron Patterson
58
+
59
+ Permission is hereby granted, free of charge, to any person obtaining
60
+ a copy of this software and associated documentation files (the
61
+ 'Software'), to deal in the Software without restriction, including
62
+ without limitation the rights to use, copy, modify, merge, publish,
63
+ distribute, sublicense, and/or sell copies of the Software, and to
64
+ permit persons to whom the Software is furnished to do so, subject to
65
+ the following conditions:
66
+
67
+ The above copyright notice and this permission notice shall be
68
+ included in all copies or substantial portions of the Software.
69
+
70
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
71
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
72
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
73
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
74
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
75
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
76
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ gem 'rake-compiler', '>= 0.4.1'
6
+ require "rake/extensiontask"
7
+
8
+ Hoe.plugin :debugging
9
+ Hoe.plugin :git
10
+ Hoe.plugin :minitest
11
+
12
+ HOE = Hoe.spec('tamashii-nfc') do
13
+ developer('Aaron Patterson', 'aaron@tenderlovemaking.com')
14
+ self.readme_file = 'README.rdoc'
15
+ self.history_file = 'CHANGELOG.rdoc'
16
+ self.extra_rdoc_files = FileList['*.rdoc']
17
+ self.spec_extras = { :extensions => ["ext/nfc/extconf.rb"] }
18
+ end
19
+
20
+ RET = Rake::ExtensionTask.new("tamashii-nfc", HOE.spec) do |ext|
21
+ ext.lib_dir = File.join('lib', 'nfc')
22
+ end
23
+
24
+ task :kill do
25
+ pid = `sudo launchctl list | grep pcscd`[/^\d+/]
26
+ `sudo kill #{pid}` if pid
27
+ end
28
+
29
+ # vim: syntax=Ruby
data/bin/nfc ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'nfc'
5
+ nfc = NFC.instance
6
+
7
+ puts "Connected to NFC reader: #{nfc.device.name}"
8
+ puts
9
+ nfc.find do |tag|
10
+ p tag
11
+ end
@@ -0,0 +1,61 @@
1
+ #include <nfc.h>
2
+
3
+ static VALUE allocate(VALUE klass) {
4
+ nfc_context * context;
5
+ nfc_init(&context);
6
+ return Data_Wrap_Struct(klass, NULL, nfc_exit, context);
7
+ }
8
+
9
+ static VALUE open_dev(VALUE self, VALUE name)
10
+ {
11
+ nfc_context * ctx;
12
+ nfc_device * dev;
13
+ VALUE device;
14
+
15
+ Data_Get_Struct(self, nfc_context, ctx);
16
+
17
+ if (NIL_P(name)) {
18
+ dev = nfc_open(ctx, NULL);
19
+ } else {
20
+ dev = nfc_open(ctx, StringValuePtr(name));
21
+ }
22
+
23
+ if (NULL == dev)
24
+ rb_raise(rb_eRuntimeError, "Unable to open the device");
25
+
26
+ if(nfc_initiator_init(dev) < 0)
27
+ rb_raise(rb_eRuntimeError, "Could not initialize device");
28
+
29
+ device = Data_Wrap_Struct(cNfcDevice, 0, nfc_close, dev);
30
+ rb_iv_set(device, "@context", self);
31
+ return device;
32
+ }
33
+
34
+ static VALUE devices(VALUE self, VALUE len)
35
+ {
36
+ nfc_context *ctx;
37
+ nfc_connstring * strs;
38
+ size_t found, i;
39
+ VALUE devs;
40
+
41
+ Data_Get_Struct(self, nfc_context, ctx);
42
+
43
+ strs = malloc(sizeof(nfc_connstring) * len);
44
+
45
+ found = nfc_list_devices(ctx, strs, 10);
46
+ devs = rb_ary_new2(found);
47
+ for (i = 0; i < found; i++) {
48
+ rb_ary_push(devs, rb_str_new2(strs[i]));
49
+ }
50
+ free(strs);
51
+ return devs;
52
+ }
53
+
54
+ void init_context()
55
+ {
56
+ VALUE cContext = rb_define_class_under(mNfc, "Context", rb_cObject);
57
+ rb_define_alloc_func(cContext, allocate);
58
+
59
+ rb_define_method(cContext, "devices", devices, 1);
60
+ rb_define_method(cContext, "open", open_dev, 1);
61
+ }
@@ -0,0 +1,18 @@
1
+ # :stopdoc:
2
+
3
+ require 'mkmf'
4
+
5
+ dir_config 'libnfc'
6
+ pkg_config 'libnfc'
7
+
8
+ unless find_header('nfc/nfc.h')
9
+ abort "libnfc is missing. please install libnfc: http://libnfc.org/"
10
+ end
11
+
12
+ unless find_library('nfc', 'nfc_init')
13
+ abort "libnfc is missing. please install libnfc: http://libnfc.org/"
14
+ end
15
+
16
+ create_makefile('nfc/nfc')
17
+
18
+ # :startdoc:
@@ -0,0 +1,13 @@
1
+ #include <nfc.h>
2
+
3
+ VALUE mNfc;
4
+
5
+ void Init_nfc()
6
+ {
7
+ mNfc = rb_define_module("NFC");
8
+
9
+ init_context();
10
+ init_device();
11
+ init_iso14443a();
12
+ init_felica();
13
+ }
@@ -0,0 +1,17 @@
1
+ #ifndef NFC_H
2
+ #define NFC_H
3
+
4
+ #include <ruby.h>
5
+ #include <nfc/nfc.h>
6
+
7
+ extern VALUE mNfc;
8
+ extern VALUE cNfcISO14443A;
9
+ extern VALUE cNfcFelica;
10
+ extern VALUE cNfcDevice;
11
+
12
+ void init_context();
13
+ void init_device();
14
+ void init_iso14443a();
15
+ void init_felica();
16
+
17
+ #endif
@@ -0,0 +1,203 @@
1
+ #include <nfc.h>
2
+
3
+ VALUE cNfcDevice;
4
+
5
+ /*
6
+ * call-seq:
7
+ * select_passive_target(tag)
8
+ *
9
+ * Select the +tag+ type from the device
10
+ */
11
+ static VALUE select_passive_target(VALUE self, VALUE tag)
12
+ {
13
+ nfc_device * dev;
14
+ nfc_modulation * mod;
15
+ nfc_target * ti;
16
+
17
+ Data_Get_Struct(self, nfc_device, dev);
18
+ Data_Get_Struct(tag, nfc_modulation, mod);
19
+
20
+ ti = (nfc_target *)xmalloc(sizeof(nfc_target));
21
+
22
+ if (nfc_initiator_select_passive_target(dev, *mod, NULL, 0, ti) ) {
23
+ switch(mod->nmt) {
24
+ case NMT_ISO14443A:
25
+ return Data_Wrap_Struct(cNfcISO14443A, 0, xfree, ti);
26
+ break;
27
+ case NMT_FELICA:
28
+ /* return Data_Wrap_Struct(cNfcFelica, 0, free, ti); */
29
+ return Qnil;
30
+ break;
31
+ default:
32
+ rb_raise(rb_eRuntimeError, "untested type: %d", mod->nmt);
33
+ }
34
+ }else {
35
+ xfree(ti);
36
+ }
37
+
38
+ return Qfalse;
39
+ }
40
+
41
+ /*
42
+ * call-seq:
43
+ * poll_target(tag, ms)
44
+ *
45
+ * Poll the +tag+ type from the device
46
+ */
47
+ static VALUE poll_target(VALUE self, VALUE tag, VALUE poll_nr, VALUE ms)
48
+ {
49
+ nfc_device * dev;
50
+ nfc_modulation * mod;
51
+ nfc_target * ti;
52
+ int code;
53
+ int ms_c, poll_nr_c;
54
+ Data_Get_Struct(self, nfc_device, dev);
55
+ Data_Get_Struct(tag, nfc_modulation, mod);
56
+
57
+ ms_c = FIX2INT(ms);
58
+ poll_nr_c = FIX2INT(poll_nr);
59
+
60
+ ti = (nfc_target *)xmalloc(sizeof(nfc_target));
61
+
62
+ code = nfc_initiator_poll_target(dev, mod, 1, poll_nr_c, ms_c, ti);
63
+
64
+ if (code > 0) {
65
+ switch(mod->nmt) {
66
+ case NMT_ISO14443A:
67
+ return Data_Wrap_Struct(cNfcISO14443A, 0, xfree, ti);
68
+ break;
69
+ case NMT_FELICA:
70
+ return Data_Wrap_Struct(cNfcFelica, 0, xfree, ti);
71
+ break;
72
+ default:
73
+ rb_raise(rb_eRuntimeError, "untested type: %d", mod->nmt);
74
+ }
75
+ }else {
76
+ xfree(ti);
77
+ }
78
+
79
+ return INT2NUM(code);
80
+ }
81
+
82
+ /*
83
+ * call-seq:
84
+ * name
85
+ *
86
+ * Get the name of the tag reader
87
+ */
88
+ static VALUE name(VALUE self)
89
+ {
90
+ nfc_device * dev;
91
+ Data_Get_Struct(self, nfc_device, dev);
92
+
93
+ return rb_str_new2(nfc_device_get_name(dev));
94
+ }
95
+
96
+ /*
97
+ * call-seq:
98
+ * deselect
99
+ *
100
+ * Deselect the current tag
101
+ */
102
+ static VALUE dev_deselect(VALUE self)
103
+ {
104
+ nfc_device * dev;
105
+ Data_Get_Struct(self, nfc_device, dev);
106
+
107
+ nfc_initiator_deselect_target(dev);
108
+
109
+ return self;
110
+ }
111
+
112
+ static VALUE mod_initialize(VALUE self, VALUE type, VALUE baud)
113
+ {
114
+ nfc_modulation * mod;
115
+
116
+ Data_Get_Struct(self, nfc_modulation, mod);
117
+ mod->nmt = NUM2INT(type);
118
+ mod->nbr = NUM2INT(baud);
119
+
120
+ return self;
121
+ }
122
+
123
+ static VALUE mod_alloc(VALUE klass)
124
+ {
125
+ nfc_modulation * modulation;
126
+
127
+ modulation = xcalloc(1, sizeof(nfc_modulation));
128
+
129
+ return Data_Wrap_Struct(klass, NULL, xfree, modulation);
130
+ }
131
+
132
+ static VALUE mod_nmt(VALUE self)
133
+ {
134
+ nfc_modulation * mod;
135
+
136
+ Data_Get_Struct(self, nfc_modulation, mod);
137
+
138
+ return INT2NUM(mod->nmt);
139
+ }
140
+
141
+ static VALUE mod_nbr(VALUE self)
142
+ {
143
+ nfc_modulation * mod;
144
+
145
+ Data_Get_Struct(self, nfc_modulation, mod);
146
+
147
+ return INT2NUM(mod->nbr);
148
+ }
149
+
150
+ static VALUE initiator_init(VALUE self)
151
+ {
152
+ nfc_device * dev;
153
+ int err;
154
+
155
+ Data_Get_Struct(self, nfc_device, dev);
156
+
157
+ err = nfc_initiator_init(dev);
158
+ if (0 == err)
159
+ return Qtrue;
160
+
161
+ return INT2NUM(err);
162
+ }
163
+
164
+ static VALUE close_dev(VALUE self)
165
+ {
166
+ nfc_device * dev;
167
+ int err;
168
+
169
+ Data_Get_Struct(self, nfc_device, dev);
170
+ nfc_close(dev);
171
+ DATA_PTR(self) = 0;
172
+
173
+ return Qnil;
174
+ }
175
+
176
+ void init_device()
177
+ {
178
+ VALUE cNfcModulation;
179
+ cNfcDevice = rb_define_class_under(mNfc, "Device", rb_cObject);
180
+ rb_define_method(cNfcDevice, "initiator_init", initiator_init, 0);
181
+ rb_define_method(cNfcDevice, "select_passive_target", select_passive_target, 1);
182
+ rb_define_method(cNfcDevice, "poll_target", poll_target, 3);
183
+ rb_define_method(cNfcDevice, "name", name, 0);
184
+ rb_define_method(cNfcDevice, "deselect", dev_deselect, 0);
185
+ rb_define_method(cNfcDevice, "close", close_dev ,0);
186
+
187
+ cNfcModulation = rb_define_class_under(cNfcDevice, "Modulation", rb_cObject);
188
+
189
+ /* modulation types. */
190
+ rb_define_const(cNfcModulation, "NMT_ISO14443A", INT2NUM(NMT_ISO14443A));
191
+ rb_define_const(cNfcModulation, "NMT_FELICA", INT2NUM(NMT_FELICA));
192
+
193
+ /* baud rates */
194
+ rb_define_const(cNfcModulation, "NBR_UNDEFINED", INT2NUM(NBR_UNDEFINED));
195
+ rb_define_const(cNfcModulation, "NBR_106", INT2NUM(NBR_106));
196
+ rb_define_const(cNfcModulation, "NBR_212", INT2NUM(NBR_212));
197
+
198
+ rb_define_alloc_func(cNfcModulation, mod_alloc);
199
+
200
+ rb_define_method(cNfcModulation, "initialize", mod_initialize, 2);
201
+ rb_define_method(cNfcModulation, "nmt", mod_nmt, 0);
202
+ rb_define_method(cNfcModulation, "nbr", mod_nbr, 0);
203
+ }
@@ -0,0 +1,62 @@
1
+ #include <nfc.h>
2
+
3
+ VALUE cNfcFelica;
4
+
5
+ /*
6
+ * size_t szLen;
7
+ * byte_t btResCode;
8
+ * byte_t abtId[8];
9
+ * byte_t abtPad[8];
10
+ * byte_t abtSysCode[2];
11
+ */
12
+
13
+ static VALUE szLen(VALUE self)
14
+ {
15
+ nfc_felica_info * tag;
16
+ Data_Get_Struct(self, nfc_felica_info, tag);
17
+
18
+ return INT2NUM(tag->szLen);
19
+ }
20
+
21
+ static VALUE btResCode(VALUE self)
22
+ {
23
+ nfc_felica_info * tag;
24
+ Data_Get_Struct(self, nfc_felica_info, tag);
25
+
26
+ return INT2NUM(tag->btResCode);
27
+ }
28
+
29
+ static VALUE abtId(VALUE self)
30
+ {
31
+ nfc_felica_info * tag;
32
+ Data_Get_Struct(self, nfc_felica_info, tag);
33
+
34
+ return rb_str_new(tag->abtId, 8 );
35
+ }
36
+
37
+ static VALUE abtPad(VALUE self)
38
+ {
39
+ nfc_felica_info * tag;
40
+ Data_Get_Struct(self, nfc_felica_info, tag);
41
+
42
+ return rb_str_new(tag->abtPad, 8 );
43
+ }
44
+
45
+ static VALUE abtSysCode(VALUE self)
46
+ {
47
+ nfc_felica_info * tag;
48
+ Data_Get_Struct(self, nfc_felica_info, tag);
49
+
50
+ return rb_str_new(tag->abtSysCode, 2 );
51
+ }
52
+
53
+ void init_felica()
54
+ {
55
+ cNfcFelica = rb_define_class_under(mNfc, "Felica", rb_cObject);
56
+
57
+ rb_define_method(cNfcFelica, "szLen", szLen, 0);
58
+ rb_define_method(cNfcFelica, "btResCode", btResCode, 0);
59
+ rb_define_method(cNfcFelica, "abtId", abtId, 0);
60
+ rb_define_private_method(cNfcFelica, "abtPad", abtPad, 0);
61
+ rb_define_private_method(cNfcFelica, "abtSysCode", abtSysCode, 0);
62
+ }
@@ -0,0 +1,100 @@
1
+ #include <nfc.h>
2
+
3
+ VALUE cNfcISO14443A;
4
+
5
+ /*
6
+ * call-seq:
7
+ * szUidLen
8
+ *
9
+ * Get the szUidLen
10
+ */
11
+ static VALUE szUidLen(VALUE self)
12
+ {
13
+ nfc_target * tag;
14
+ Data_Get_Struct(self, nfc_target, tag);
15
+
16
+ return INT2NUM(tag->nti.nai.szUidLen);
17
+ }
18
+
19
+ /*
20
+ * call-seq:
21
+ * szAtsLen
22
+ *
23
+ * Get the szAtsLen
24
+ */
25
+ static VALUE szAtsLen(VALUE self)
26
+ {
27
+ nfc_target * tag;
28
+ Data_Get_Struct(self, nfc_target, tag);
29
+
30
+ return INT2NUM(tag->nti.nai.szAtsLen);
31
+ }
32
+
33
+ /*
34
+ * call-seq:
35
+ * abtUid
36
+ *
37
+ * Get the abtUid
38
+ */
39
+ static VALUE abtUid(VALUE self)
40
+ {
41
+ nfc_target * tag;
42
+ Data_Get_Struct(self, nfc_target, tag);
43
+
44
+ return rb_str_new((const char *)tag->nti.nai.abtUid, tag->nti.nai.szUidLen);
45
+ }
46
+
47
+ /*
48
+ * call-seq:
49
+ * abtAts
50
+ *
51
+ * Get the abtAts
52
+ */
53
+ static VALUE abtAts(VALUE self)
54
+ {
55
+ nfc_target * tag;
56
+ Data_Get_Struct(self, nfc_target, tag);
57
+
58
+ return rb_str_new((const char *)tag->nti.nai.abtAts, tag->nti.nai.szAtsLen);
59
+ }
60
+
61
+ /*
62
+ * call-seq:
63
+ * abtAtqa
64
+ *
65
+ * Get the abtAtqa
66
+ */
67
+ static VALUE abtAtqa(VALUE self)
68
+ {
69
+ nfc_target * tag;
70
+ Data_Get_Struct(self, nfc_target, tag);
71
+
72
+ return rb_str_new((const char *)tag->nti.nai.abtAtqa, 2);
73
+ }
74
+
75
+ /*
76
+ * call-seq:
77
+ * btSak
78
+ *
79
+ * Get the btSak
80
+ */
81
+ static VALUE btSak(VALUE self)
82
+ {
83
+ nfc_target * tag;
84
+ Data_Get_Struct(self, nfc_target, tag);
85
+
86
+ return INT2NUM(tag->nti.nai.btSak);
87
+ }
88
+
89
+ void init_iso14443a()
90
+ {
91
+ cNfcISO14443A = rb_define_class_under(mNfc, "ISO14443A", rb_cObject);
92
+
93
+ rb_define_method(cNfcISO14443A, "szUidLen", szUidLen, 0);
94
+ rb_define_method(cNfcISO14443A, "szAtsLen", szAtsLen, 0);
95
+ rb_define_method(cNfcISO14443A, "btSak", btSak, 0);
96
+
97
+ rb_define_private_method(cNfcISO14443A, "abtUid", abtUid, 0);
98
+ rb_define_private_method(cNfcISO14443A, "abtAts", abtAts, 0);
99
+ rb_define_private_method(cNfcISO14443A, "abtAtqa", abtAtqa, 0);
100
+ }
@@ -0,0 +1,12 @@
1
+ require 'thread'
2
+ require 'nfc/nfc'
3
+ require 'nfc/device'
4
+ require 'nfc/iso14443a'
5
+ require 'nfc/felica'
6
+
7
+ ###
8
+ # NFC is a class for dealing with Near Field Communication systems. This
9
+ # library will read RFID tags from an RFID reader.
10
+ module NFC
11
+ VERSION = '3.1.2'
12
+ end
@@ -0,0 +1,23 @@
1
+ module NFC
2
+ class Device
3
+ DCO_HANDLE_CRC = 0x00
4
+ DCO_HANDLE_PARITY = 0x01
5
+ DCO_ACTIVATE_FIELD = 0x10
6
+ DCO_INFINITE_LIST_PASSIVE = 0x20
7
+
8
+ IM_ISO14443A_106 = Modulation.new Modulation::NMT_ISO14443A,
9
+ Modulation::NBR_106
10
+ IM_FELICA = Modulation.new Modulation::NMT_FELICA,
11
+ Modulation::NBR_212
12
+
13
+ # Find a tag, blocks until there is a tag available
14
+ def select type = :mfrc
15
+ select_passive_target NFC::Device::IM_ISO14443A_106 if type == :mfrc
16
+ select_passive_target NFC::Device::IM_FELICA if type == :felica
17
+ end
18
+ def poll type = :mfrc, poll_nr = 1, ms = 1
19
+ poll_target NFC::Device::IM_ISO14443A_106, poll_nr,ms if type == :mfrc
20
+ poll_target NFC::Device::IM_FELICA, poll_nr,ms if type == :felica
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,34 @@
1
+ module NFC
2
+ class Felica
3
+
4
+ def uid
5
+ abtId.unpack 'C*'
6
+ end
7
+
8
+ def pad
9
+ abtPad.unpack 'C*'
10
+ end
11
+
12
+ def sys_code
13
+ abtSysCode.unpack 'C*'
14
+ end
15
+
16
+ def to_s join_string = ''
17
+ sprintf((['%02x'] * 8 ).join(join_string), * uid).upcase
18
+ end
19
+
20
+ def inspect
21
+ # 78 printf("The following (NFC) Felica tag was found:\n\n");
22
+ # 79 printf("%18s","ID (NFCID2): "); print_hex(ti.tif.abtId,8);
23
+ # 80 printf("%18s","Parameter (PAD): "); print_hex(ti.tif.abtPad,8);
24
+ pad = sprintf( (['%02x'] * 8 ).join(' '), *self.pad)
25
+ string_ary = [
26
+ "(NFC) Felica Tag",
27
+ "ID (NFCID2): #{to_s ' '}",
28
+ "Parameter(PAD): #{pad}"
29
+ ]
30
+ string_ary.join "\n"
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,43 @@
1
+ module NFC
2
+ class ISO14443A
3
+ ###
4
+ # Get the unique ID for this tag
5
+ def uid
6
+ abtUid.unpack 'C*'
7
+ end
8
+
9
+ ###
10
+ # Get the ATS for this tag
11
+ def ats
12
+ abtAts.unpack 'C*'
13
+ end
14
+
15
+ ###
16
+ # Get the atqa
17
+ def atqa
18
+ abtAtqa.unpack 'C*'
19
+ end
20
+
21
+ ###
22
+ # Get the UID as a hex string
23
+ def to_s join_string = ''
24
+ sprintf((['%02x'] * szUidLen).join(join_string), * uid).upcase
25
+ end
26
+
27
+ ###
28
+ # Inspect this tag
29
+ def inspect
30
+ string_ary =
31
+ [ "(NFC) ISO14443A Tag",
32
+ " ATQA (SENS_RES): #{sprintf("%02x %02x", *atqa)}",
33
+ " UID (NFCID1): #{to_s ' '}",
34
+ " SAK (SEL_RES): #{sprintf("%02x", btSak)}"
35
+ ]
36
+ if szAtsLen > 0
37
+ ats = sprintf((['%02x'] * szAtsLen).join(' '), *self.ats)
38
+ string_ary << " ATS (ATR): #{ats}"
39
+ end
40
+ string_ary.join "\n"
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,22 @@
1
+ require "minitest/autorun"
2
+ require "nfc"
3
+
4
+ module NFC
5
+ class TestContext < Minitest::Test
6
+ def test_init
7
+ assert NFC::Context.new
8
+ end
9
+
10
+ def test_list_devices
11
+ ctx = NFC::Context.new
12
+ assert ctx.devices(1)
13
+ end
14
+
15
+ def test_open
16
+ ctx = NFC::Context.new
17
+ devs = ctx.devices(1)
18
+ skip "no devs attached" unless devs.length > 0
19
+ dev = ctx.open nil
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ require "minitest/autorun"
2
+ require "nfc"
3
+
4
+ module NFC
5
+ class TestDevice < Minitest::Test
6
+ def test_initiator_init
7
+ ctx = NFC::Context.new
8
+ devs = ctx.devices(1)
9
+ skip "no devs attached" unless devs.length > 0
10
+ dev = ctx.open nil
11
+ dev.initiator_init
12
+ dev.select_passive_target Device::IM_ISO14443A_106
13
+ end
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tamashii-nfc
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Patterson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: hoe
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.16'
55
+ description: |-
56
+ NFC is a ruby wrapper for the Near Field Communication library. The Near
57
+ Field Communication library works with many USB RFID readers, so this gem
58
+ lets you read RFID tags.
59
+ email:
60
+ - aaron@tenderlovemaking.com
61
+ executables:
62
+ - nfc
63
+ extensions:
64
+ - ext/nfc/extconf.rb
65
+ extra_rdoc_files:
66
+ - CHANGELOG.rdoc
67
+ - Manifest.txt
68
+ - README.rdoc
69
+ files:
70
+ - ".autotest"
71
+ - CHANGELOG.rdoc
72
+ - Manifest.txt
73
+ - README.rdoc
74
+ - Rakefile
75
+ - bin/nfc
76
+ - ext/nfc/context.c
77
+ - ext/nfc/extconf.rb
78
+ - ext/nfc/nfc.c
79
+ - ext/nfc/nfc.h
80
+ - ext/nfc/nfc_device.c
81
+ - ext/nfc/nfc_felica.c
82
+ - ext/nfc/nfc_iso14443a.c
83
+ - lib/nfc.rb
84
+ - lib/nfc/device.rb
85
+ - lib/nfc/felica.rb
86
+ - lib/nfc/iso14443a.rb
87
+ - test/test_context.rb
88
+ - test/test_device.rb
89
+ homepage: http://seattlerb.rubyforge.org
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options:
95
+ - "--main"
96
+ - README.rdoc
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.5.1
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: NFC is a ruby wrapper for the Near Field Communication library
115
+ test_files: []