nfc 2.1.0 → 3.0.0

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: dc2c9944d61cd728376a5378a2a0cfb715915016
4
+ data.tar.gz: ba8a58d9b55211a2898d03a3b37445b5000a9bae
5
+ SHA512:
6
+ metadata.gz: b69c386aac1fde6be05e7f9cfe59d3e6ad4b06a8b73e49ef5391e99d755735fd5aa811b53917a00ceb3be2d2e5c7eb1362acdc7e1b49db468a6b656c5abbd5d3
7
+ data.tar.gz: 48841e7078653b6abc9e8604bf96ae821cdd0fe3432ffeb07e6d13cecfcd3486464afbd3d72294b101a9aa473099933a626d284fa1a842932d0f7ba0caacdb62
@@ -4,17 +4,16 @@ Manifest.txt
4
4
  README.rdoc
5
5
  Rakefile
6
6
  bin/nfc
7
+ ext/nfc/context.c
7
8
  ext/nfc/extconf.rb
8
9
  ext/nfc/nfc.c
9
10
  ext/nfc/nfc.h
10
11
  ext/nfc/nfc_device.c
11
- ext/nfc/nfc_device.h
12
12
  ext/nfc/nfc_felica.c
13
- ext/nfc/nfc_felica.h
14
13
  ext/nfc/nfc_iso14443a.c
15
- ext/nfc/nfc_iso14443a.h
16
14
  lib/nfc.rb
17
15
  lib/nfc/device.rb
18
16
  lib/nfc/felica.rb
19
17
  lib/nfc/iso14443a.rb
20
- test/test_nfc.rb
18
+ test/test_context.rb
19
+ test/test_device.rb
@@ -16,24 +16,20 @@ lets you read RFID tags.
16
16
 
17
17
  require 'nfc'
18
18
 
19
- # Read your tag and print the info.
20
- p NFC.instance.find
19
+ # Create a new context
20
+ ctx = NFC::Context.new
21
21
 
22
- # NFC#find will return immidiately, which means you should have a tag
23
- # sitting on the reader when running it. If you'd like it to block until
24
- # it detects a tag, give find a block like so:
22
+ # Open the first available USB device
23
+ dev = ctx.open nil
25
24
 
26
- NFC.instance.find do |tag|
27
- p tag
28
- end
25
+ # Block until a tag is available, then print tag info
26
+ p dev.select
29
27
 
30
28
  # You can even run in an infinite loop if you'd like to continually find
31
29
  # tags:
32
30
 
33
31
  loop do
34
- NFC.instance.find do |tag|
35
- p tag
36
- end
32
+ p dev.select
37
33
  end
38
34
 
39
35
  == REQUIREMENTS:
@@ -44,21 +40,21 @@ lets you read RFID tags.
44
40
  == INSTALL:
45
41
 
46
42
  First install libnfc[http://libnfc.org/].
47
- I installed libnfc via MacPorts[http://www.macports.org/] like this:
43
+ I installed libnfc via homebrew:
48
44
 
49
- $ sudo port install libnfc
45
+ $ brew install libnfc
50
46
 
51
47
  The install the gem:
52
48
 
53
49
  $ sudo gem install nfc
54
50
 
55
- NOTE!!!! The nfc gem requires libnfc version 1.5.0 or greater!
51
+ NOTE!!!! The nfc gem requires libnfc version 1.7.0 or greater!
56
52
 
57
53
  == LICENSE:
58
54
 
59
55
  (The MIT License)
60
56
 
61
- Copyright (c) 2009-2011 Aaron Patterson
57
+ Copyright (c) 2009-2013 Aaron Patterson
62
58
 
63
59
  Permission is hereby granted, free of charge, to any person obtaining
64
60
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -7,6 +7,7 @@ require "rake/extensiontask"
7
7
 
8
8
  Hoe.plugin :debugging
9
9
  Hoe.plugin :git
10
+ Hoe.plugin :minitest
10
11
 
11
12
  HOE = Hoe.spec('nfc') do
12
13
  developer('Aaron Patterson', 'aaron@tenderlovemaking.com')
@@ -20,4 +21,9 @@ RET = Rake::ExtensionTask.new("nfc", HOE.spec) do |ext|
20
21
  ext.lib_dir = File.join('lib', 'nfc')
21
22
  end
22
23
 
24
+ task :kill do
25
+ pid = `sudo launchctl list | grep pcscd`[/^\d+/]
26
+ `sudo kill #{pid}` if pid
27
+ end
28
+
23
29
  # vim: syntax=Ruby
@@ -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
+ }
@@ -1,21 +1,15 @@
1
- ENV['RC_ARCHS'] = '' if RUBY_PLATFORM =~ /darwin/
2
-
3
1
  # :stopdoc:
4
2
 
5
3
  require 'mkmf'
6
4
 
7
- LIBDIR = Config::CONFIG['libdir']
8
- INCLUDEDIR = Config::CONFIG['includedir']
9
- HEADER_DIRS = [ '/usr/local/include', INCLUDEDIR, '/usr/include', ]
10
- LIB_DIRS = [ '/usr/local/lib', LIBDIR, '/usr/lib', ]
11
-
12
- nfc_dirs = dir_config('nfc', HEADER_DIRS, LIB_DIRS)
5
+ dir_config 'libnfc'
6
+ pkg_config 'libnfc'
13
7
 
14
8
  unless find_header('nfc/nfc.h')
15
9
  abort "libnfc is missing. please install libnfc: http://libnfc.org/"
16
10
  end
17
11
 
18
- unless find_library('nfc', 'nfc_connect')
12
+ unless find_library('nfc', 'nfc_init')
19
13
  abort "libnfc is missing. please install libnfc: http://libnfc.org/"
20
14
  end
21
15
 
@@ -1,12 +1,15 @@
1
1
  #include <nfc.h>
2
2
 
3
- VALUE cNfc;
3
+ VALUE mNfc;
4
4
 
5
5
  void Init_nfc()
6
6
  {
7
- cNfc = rb_define_class("NFC", rb_cObject);
7
+ mNfc = rb_define_module("NFC");
8
8
 
9
+ init_context();
9
10
  init_device();
10
11
  init_iso14443a();
12
+ /*
11
13
  init_felica();
14
+ */
12
15
  }
@@ -4,10 +4,14 @@
4
4
  #include <ruby.h>
5
5
  #include <nfc/nfc.h>
6
6
 
7
- extern VALUE cNfc;
7
+ extern VALUE mNfc;
8
+ extern VALUE cNfcISO14443A;
9
+ extern VALUE cNfcFelica;
10
+ extern VALUE cNfcDevice;
8
11
 
9
- #include <nfc_device.h>
10
- #include <nfc_iso14443a.h>
11
- #include <nfc_felica.h>
12
+ void init_context();
13
+ void init_device();
14
+ void init_iso14443a();
15
+ void init_felica();
12
16
 
13
17
  #endif
@@ -1,91 +1,75 @@
1
- #include <nfc_device.h>
1
+ #include <nfc.h>
2
2
 
3
- static byte_t abtFelica[5] = { 0x00, 0xff, 0xff, 0x00, 0x00 };
3
+ VALUE cNfcDevice;
4
4
 
5
5
  /*
6
6
  * call-seq:
7
- * connect
7
+ * select_passive_target(tag)
8
8
  *
9
- * Connect to the NFC device
9
+ * Select the +tag+ type from the device
10
10
  */
11
- static VALUE connect(VALUE klass)
11
+ static VALUE select_passive_target(VALUE self, VALUE tag)
12
12
  {
13
- nfc_device_t * dev = nfc_connect(NULL);
14
- if(!dev)
15
- rb_raise(rb_eRuntimeError, "could not find NFC device");
13
+ nfc_device * dev;
14
+ nfc_modulation * mod;
15
+ nfc_target * ti;
16
16
 
17
- if(!nfc_initiator_init(dev))
18
- rb_raise(rb_eRuntimeError, "oh snap, could not init");
17
+ Data_Get_Struct(self, nfc_device, dev);
18
+ Data_Get_Struct(tag, nfc_modulation, mod);
19
19
 
20
- return Data_Wrap_Struct(klass, 0, 0, dev);
21
- }
20
+ ti = (nfc_target *)xmalloc(sizeof(nfc_target));
22
21
 
23
- /*
24
- * call-seq:
25
- * disconnect
26
- *
27
- * Disconnect from the NFC device
28
- */
29
- static VALUE disconnect(VALUE self)
30
- {
31
- nfc_device_t * dev;
32
- Data_Get_Struct(self, nfc_device_t, dev);
33
- nfc_disconnect(dev);
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
+ }
34
35
 
35
- return self;
36
+ return Qfalse;
36
37
  }
37
38
 
38
39
  /*
39
40
  * call-seq:
40
- * configure(option, value)
41
+ * poll_target(tag, ms)
41
42
  *
42
- * Configure the Device with +option+ and +value+
43
+ * Poll the +tag+ type from the device
43
44
  */
44
- static VALUE configure(VALUE self, VALUE option, VALUE flag)
45
+ static VALUE poll_target(VALUE self, VALUE tag, VALUE ms)
45
46
  {
46
- nfc_device_t * dev;
47
- Data_Get_Struct(self, nfc_device_t, dev);
48
-
49
- nfc_configure(
50
- dev,
51
- (const nfc_device_option_t)NUM2INT(option),
52
- (const bool)NUM2INT(flag)
53
- );
47
+ nfc_device * dev;
48
+ nfc_modulation * mod;
49
+ nfc_target * ti;
50
+ int code;
54
51
 
55
- return self;
56
- }
57
-
58
- /*
59
- * call-seq:
60
- * select(tag)
61
- *
62
- * Select the +tag+ type from the device
63
- */
64
- static VALUE dev_select(VALUE self, VALUE tag)
65
- {
66
- nfc_device_t * dev;
67
- nfc_modulation_t * mod;
68
- nfc_target_t * ti;
52
+ Data_Get_Struct(self, nfc_device, dev);
53
+ Data_Get_Struct(tag, nfc_modulation, mod);
69
54
 
70
- Data_Get_Struct(self, nfc_device_t, dev);
71
- Data_Get_Struct(tag, nfc_modulation_t, mod);
55
+ ti = (nfc_target *)xmalloc(sizeof(nfc_target));
72
56
 
73
- ti = (nfc_target_t *)calloc(1, sizeof(nfc_target_t));
57
+ code = nfc_initiator_poll_target(dev, mod, 1, 0, 1, ti);
74
58
 
75
- if (nfc_initiator_select_passive_target(dev, *mod, NULL, 0, ti) ) {
59
+ if (code > 0) {
76
60
  switch(mod->nmt) {
77
61
  case NMT_ISO14443A:
78
- return Data_Wrap_Struct(cNfcISO14443A, 0, free, ti);
62
+ return Data_Wrap_Struct(cNfcISO14443A, 0, xfree, ti);
79
63
  break;
80
64
  case NMT_FELICA:
81
- return Data_Wrap_Struct(cNfcFelica, 0, free, ti);
65
+ return Data_Wrap_Struct(cNfcFelica, 0, xfree, ti);
82
66
  break;
83
67
  default:
84
68
  rb_raise(rb_eRuntimeError, "untested type: %d", mod->nmt);
85
69
  }
86
70
  }
87
71
 
88
- return Qfalse;
72
+ return INT2NUM(code);
89
73
  }
90
74
 
91
75
  /*
@@ -96,10 +80,10 @@ static VALUE dev_select(VALUE self, VALUE tag)
96
80
  */
97
81
  static VALUE name(VALUE self)
98
82
  {
99
- nfc_device_t * dev;
100
- Data_Get_Struct(self, nfc_device_t, dev);
83
+ nfc_device * dev;
84
+ Data_Get_Struct(self, nfc_device, dev);
101
85
 
102
- return rb_str_new2(dev->acName);
86
+ return rb_str_new2(nfc_device_get_name(dev));
103
87
  }
104
88
 
105
89
  /*
@@ -110,8 +94,8 @@ static VALUE name(VALUE self)
110
94
  */
111
95
  static VALUE dev_deselect(VALUE self)
112
96
  {
113
- nfc_device_t * dev;
114
- Data_Get_Struct(self, nfc_device_t, dev);
97
+ nfc_device * dev;
98
+ Data_Get_Struct(self, nfc_device, dev);
115
99
 
116
100
  nfc_initiator_deselect_target(dev);
117
101
 
@@ -120,9 +104,9 @@ static VALUE dev_deselect(VALUE self)
120
104
 
121
105
  static VALUE mod_initialize(VALUE self, VALUE type, VALUE baud)
122
106
  {
123
- nfc_modulation_t * mod;
107
+ nfc_modulation * mod;
124
108
 
125
- Data_Get_Struct(self, nfc_modulation_t, mod);
109
+ Data_Get_Struct(self, nfc_modulation, mod);
126
110
  mod->nmt = NUM2INT(type);
127
111
  mod->nbr = NUM2INT(baud);
128
112
 
@@ -131,42 +115,54 @@ static VALUE mod_initialize(VALUE self, VALUE type, VALUE baud)
131
115
 
132
116
  static VALUE mod_alloc(VALUE klass)
133
117
  {
134
- nfc_modulation_t * modulation;
118
+ nfc_modulation * modulation;
135
119
 
136
- modulation = xcalloc(1, sizeof(nfc_modulation_t));
120
+ modulation = xcalloc(1, sizeof(nfc_modulation));
137
121
 
138
122
  return Data_Wrap_Struct(klass, NULL, xfree, modulation);
139
123
  }
140
124
 
141
125
  static VALUE mod_nmt(VALUE self)
142
126
  {
143
- nfc_modulation_t * mod;
127
+ nfc_modulation * mod;
144
128
 
145
- Data_Get_Struct(self, nfc_modulation_t, mod);
129
+ Data_Get_Struct(self, nfc_modulation, mod);
146
130
 
147
131
  return INT2NUM(mod->nmt);
148
132
  }
149
133
 
150
134
  static VALUE mod_nbr(VALUE self)
151
135
  {
152
- nfc_modulation_t * mod;
136
+ nfc_modulation * mod;
153
137
 
154
- Data_Get_Struct(self, nfc_modulation_t, mod);
138
+ Data_Get_Struct(self, nfc_modulation, mod);
155
139
 
156
140
  return INT2NUM(mod->nbr);
157
141
  }
158
142
 
143
+ static VALUE initiator_init(VALUE self)
144
+ {
145
+ nfc_device * dev;
146
+ int err;
147
+
148
+ Data_Get_Struct(self, nfc_device, dev);
149
+
150
+ err = nfc_initiator_init(dev);
151
+ if (0 == err)
152
+ return Qtrue;
153
+
154
+ return INT2NUM(err);
155
+ }
156
+
159
157
  void init_device()
160
158
  {
161
159
  VALUE cNfcModulation;
162
- VALUE cNfcDevice = rb_define_class_under(cNfc, "Device", rb_cObject);
163
-
164
- rb_define_singleton_method(cNfcDevice, "connect", connect, 0);
165
- rb_define_method(cNfcDevice, "disconnect", disconnect, 0);
166
- rb_define_method(cNfcDevice, "configure", configure, 2);
167
- rb_define_method(cNfcDevice, "select", dev_select, 1);
168
- rb_define_method(cNfcDevice, "deselect", dev_deselect, 0);
160
+ cNfcDevice = rb_define_class_under(mNfc, "Device", rb_cObject);
161
+ rb_define_method(cNfcDevice, "initiator_init", initiator_init, 0);
162
+ rb_define_method(cNfcDevice, "select_passive_target", select_passive_target, 1);
163
+ rb_define_method(cNfcDevice, "poll_target", poll_target, 1);
169
164
  rb_define_method(cNfcDevice, "name", name, 0);
165
+ rb_define_method(cNfcDevice, "deselect", dev_deselect, 0);
170
166
 
171
167
  cNfcModulation = rb_define_class_under(cNfcDevice, "Modulation", rb_cObject);
172
168
 
@@ -1,4 +1,4 @@
1
- #include <nfc_felica.h>
1
+ #include <nfc.h>
2
2
 
3
3
  VALUE cNfcFelica;
4
4
 
@@ -12,47 +12,47 @@ VALUE cNfcFelica;
12
12
 
13
13
  static VALUE szLen(VALUE self)
14
14
  {
15
- nfc_felica_info_t * tag;
16
- Data_Get_Struct(self, nfc_felica_info_t, tag);
15
+ nfc_felica_info * tag;
16
+ Data_Get_Struct(self, nfc_felica_info, tag);
17
17
 
18
18
  return INT2NUM(tag->szLen);
19
19
  }
20
20
 
21
21
  static VALUE btResCode(VALUE self)
22
22
  {
23
- nfc_felica_info_t * tag;
24
- Data_Get_Struct(self, nfc_felica_info_t, tag);
23
+ nfc_felica_info * tag;
24
+ Data_Get_Struct(self, nfc_felica_info, tag);
25
25
 
26
26
  return INT2NUM(tag->btResCode);
27
27
  }
28
28
 
29
29
  static VALUE abtId(VALUE self)
30
30
  {
31
- nfc_felica_info_t * tag;
32
- Data_Get_Struct(self, nfc_felica_info_t, tag);
31
+ nfc_felica_info * tag;
32
+ Data_Get_Struct(self, nfc_felica_info, tag);
33
33
 
34
34
  return rb_str_new(tag->abtId, 8 );
35
35
  }
36
36
 
37
37
  static VALUE abtPad(VALUE self)
38
38
  {
39
- nfc_felica_info_t * tag;
40
- Data_Get_Struct(self, nfc_felica_info_t, tag);
39
+ nfc_felica_info * tag;
40
+ Data_Get_Struct(self, nfc_felica_info, tag);
41
41
 
42
42
  return rb_str_new(tag->abtPad, 8 );
43
43
  }
44
44
 
45
45
  static VALUE abtSysCode(VALUE self)
46
46
  {
47
- nfc_felica_info_t * tag;
48
- Data_Get_Struct(self, nfc_felica_info_t, tag);
47
+ nfc_felica_info * tag;
48
+ Data_Get_Struct(self, nfc_felica_info, tag);
49
49
 
50
50
  return rb_str_new(tag->abtSysCode, 2 );
51
51
  }
52
52
 
53
53
  void init_felica()
54
54
  {
55
- cNfcFelica = rb_define_class_under(cNfc, "Felica", rb_cObject);
55
+ cNfcFelica = rb_define_class_under(mNfc, "Felica", rb_cObject);
56
56
 
57
57
  rb_define_method(cNfcFelica, "szLen", szLen, 0);
58
58
  rb_define_method(cNfcFelica, "btResCode", btResCode, 0);
@@ -1,4 +1,4 @@
1
- #include <nfc_iso14443a.h>
1
+ #include <nfc.h>
2
2
 
3
3
  VALUE cNfcISO14443A;
4
4
 
@@ -10,10 +10,10 @@ VALUE cNfcISO14443A;
10
10
  */
11
11
  static VALUE szUidLen(VALUE self)
12
12
  {
13
- nfc_iso14443a_info_t * tag;
14
- Data_Get_Struct(self, nfc_iso14443a_info_t, tag);
13
+ nfc_target * tag;
14
+ Data_Get_Struct(self, nfc_target, tag);
15
15
 
16
- return INT2NUM(tag->szUidLen);
16
+ return INT2NUM(tag->nti.nai.szUidLen);
17
17
  }
18
18
 
19
19
  /*
@@ -24,10 +24,10 @@ static VALUE szUidLen(VALUE self)
24
24
  */
25
25
  static VALUE szAtsLen(VALUE self)
26
26
  {
27
- nfc_iso14443a_info_t * tag;
28
- Data_Get_Struct(self, nfc_iso14443a_info_t, tag);
27
+ nfc_target * tag;
28
+ Data_Get_Struct(self, nfc_target, tag);
29
29
 
30
- return INT2NUM(tag->szAtsLen);
30
+ return INT2NUM(tag->nti.nai.szAtsLen);
31
31
  }
32
32
 
33
33
  /*
@@ -38,10 +38,10 @@ static VALUE szAtsLen(VALUE self)
38
38
  */
39
39
  static VALUE abtUid(VALUE self)
40
40
  {
41
- nfc_iso14443a_info_t * tag;
42
- Data_Get_Struct(self, nfc_iso14443a_info_t, tag);
41
+ nfc_target * tag;
42
+ Data_Get_Struct(self, nfc_target, tag);
43
43
 
44
- return rb_str_new(tag->abtUid, tag->szUidLen);
44
+ return rb_str_new((const char *)tag->nti.nai.abtUid, tag->nti.nai.szUidLen);
45
45
  }
46
46
 
47
47
  /*
@@ -52,10 +52,10 @@ static VALUE abtUid(VALUE self)
52
52
  */
53
53
  static VALUE abtAts(VALUE self)
54
54
  {
55
- nfc_iso14443a_info_t * tag;
56
- Data_Get_Struct(self, nfc_iso14443a_info_t, tag);
55
+ nfc_target * tag;
56
+ Data_Get_Struct(self, nfc_target, tag);
57
57
 
58
- return rb_str_new(tag->abtAts, tag->szAtsLen);
58
+ return rb_str_new((const char *)tag->nti.nai.abtAts, tag->nti.nai.szAtsLen);
59
59
  }
60
60
 
61
61
  /*
@@ -66,10 +66,10 @@ static VALUE abtAts(VALUE self)
66
66
  */
67
67
  static VALUE abtAtqa(VALUE self)
68
68
  {
69
- nfc_iso14443a_info_t * tag;
70
- Data_Get_Struct(self, nfc_iso14443a_info_t, tag);
69
+ nfc_target * tag;
70
+ Data_Get_Struct(self, nfc_target, tag);
71
71
 
72
- return rb_str_new(tag->abtAtqa, 2);
72
+ return rb_str_new((const char *)tag->nti.nai.abtAtqa, 2);
73
73
  }
74
74
 
75
75
  /*
@@ -80,15 +80,15 @@ static VALUE abtAtqa(VALUE self)
80
80
  */
81
81
  static VALUE btSak(VALUE self)
82
82
  {
83
- nfc_iso14443a_info_t * tag;
84
- Data_Get_Struct(self, nfc_iso14443a_info_t, tag);
83
+ nfc_target * tag;
84
+ Data_Get_Struct(self, nfc_target, tag);
85
85
 
86
- return INT2NUM(tag->btSak);
86
+ return INT2NUM(tag->nti.nai.btSak);
87
87
  }
88
88
 
89
89
  void init_iso14443a()
90
90
  {
91
- cNfcISO14443A = rb_define_class_under(cNfc, "ISO14443A", rb_cObject);
91
+ cNfcISO14443A = rb_define_class_under(mNfc, "ISO14443A", rb_cObject);
92
92
 
93
93
  rb_define_method(cNfcISO14443A, "szUidLen", szUidLen, 0);
94
94
  rb_define_method(cNfcISO14443A, "szAtsLen", szAtsLen, 0);
data/lib/nfc.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'singleton'
2
1
  require 'thread'
3
2
  require 'nfc/nfc'
4
3
  require 'nfc/device'
@@ -7,101 +6,7 @@ require 'nfc/felica'
7
6
 
8
7
  ###
9
8
  # NFC is a class for dealing with Near Field Communication systems. This
10
- # library will read RFID tags from an RFID reader. You should start by reading
11
- # NFC#find
12
- class NFC
13
- VERSION = '2.1.0'
14
-
15
- include Singleton
16
-
17
- ###
18
- # Create a new NFC class. This is private, do this instead:
19
- # NFC.instance
20
- def initialize
21
- @device = nil
22
- @mutex = Mutex.new
23
- end
24
-
25
- ###
26
- # Deactivate the detection field
27
- def deactivate_field
28
- device.configure Device::DCO_ACTIVATE_FIELD, 0
29
- end
30
-
31
- ###
32
- # Activate the detection field
33
- def activate_field
34
- device.configure Device::DCO_ACTIVATE_FIELD, 1
35
- end
36
-
37
- ###
38
- # Do CRC checks
39
- def crc= value
40
- device.configure Device::DCO_HANDLE_CRC, value ? 1 : 0
41
- end
42
-
43
- ###
44
- # Parity checks
45
- def parity= v
46
- device.configure Device::DCO_HANDLE_PARITY, v ? 1 : 0
47
- end
48
-
49
- ###
50
- # Get the device
51
- def device
52
- @device ||= NFC::Device.connect
53
- end
54
-
55
- ###
56
- # Block until a passive tag is detected
57
- def infinite_list_passive= v
58
- device.configure Device::DCO_INFINITE_LIST_PASSIVE, v ? 1 : 0
59
- end
60
-
61
- ###
62
- # Select a tag
63
- def select
64
- device.select Device::IM_ISO14443A_106
65
- end
66
- alias :detect :select
67
-
68
- ###
69
- # Deselect a tag
70
- def deselect
71
- device.deselect
72
- end
73
-
74
- # Read your tag and print the info.
75
- #
76
- # p NFC.instance.find
77
- #
78
- # NFC#find will return immidiately, which means you should have a tag
79
- # sitting on the reader when running it. If you'd like it to block until
80
- # it detects a tag, give find a block like so:
81
- #
82
- # NFC.instance.find do |tag|
83
- # p tag
84
- # end
85
- #
86
- # You can even run in an infinite loop if you'd like to continually find
87
- # tags:
88
- #
89
- # loop do
90
- # NFC.instance.find do |tag|
91
- # p tag
92
- # end
93
- # end
94
- def find
95
- @mutex.lock
96
- deactivate_field
97
- self.infinite_list_passive = block_given?
98
- self.crc = true
99
- self.parity = true
100
- activate_field
101
- tag = detect
102
- deselect
103
- @mutex.unlock
104
- yield tag if block_given?
105
- tag
106
- end
9
+ # library will read RFID tags from an RFID reader.
10
+ module NFC
11
+ VERSION = '3.0.0'
107
12
  end
@@ -1,4 +1,4 @@
1
- class NFC
1
+ module NFC
2
2
  class Device
3
3
  DCO_HANDLE_CRC = 0x00
4
4
  DCO_HANDLE_PARITY = 0x01
@@ -7,5 +7,10 @@ class NFC
7
7
 
8
8
  IM_ISO14443A_106 = Modulation.new Modulation::NMT_ISO14443A,
9
9
  Modulation::NBR_106
10
+
11
+ # Find a tag, blocks until there is a tag available
12
+ def select
13
+ select_passive_target NFC::Device::IM_ISO14443A_106
14
+ end
10
15
  end
11
16
  end
@@ -1,4 +1,4 @@
1
- class NFC
1
+ module NFC
2
2
  class Felica
3
3
 
4
4
  def uid
@@ -1,4 +1,4 @@
1
- class NFC
1
+ module NFC
2
2
  class ISO14443A
3
3
  ###
4
4
  # Get the unique ID for this tag
@@ -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 CHANGED
@@ -1,33 +1,61 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nfc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
5
- prerelease:
4
+ version: 3.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Aaron Patterson
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2011-05-28 00:00:00.000000000 Z
11
+ date: 2013-08-19 00:00:00.000000000 Z
13
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.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
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'
14
41
  - !ruby/object:Gem::Dependency
15
42
  name: hoe
16
- requirement: &2153398480 !ruby/object:Gem::Requirement
17
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
18
44
  requirements:
19
- - - ! '>='
45
+ - - ~>
20
46
  - !ruby/object:Gem::Version
21
- version: 2.9.4
47
+ version: '3.6'
22
48
  type: :development
23
49
  prerelease: false
24
- version_requirements: *2153398480
25
- description: ! 'NFC is a ruby wrapper for the Near Field Communication library. The
26
- Near
27
-
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.6'
55
+ description: |-
56
+ NFC is a ruby wrapper for the Near Field Communication library. The Near
28
57
  Field Communication library works with many USB RFID readers, so this gem
29
-
30
- lets you read RFID tags.'
58
+ lets you read RFID tags.
31
59
  email:
32
60
  - aaron@tenderlovemaking.com
33
61
  executables:
@@ -35,8 +63,8 @@ executables:
35
63
  extensions:
36
64
  - ext/nfc/extconf.rb
37
65
  extra_rdoc_files:
38
- - Manifest.txt
39
66
  - CHANGELOG.rdoc
67
+ - Manifest.txt
40
68
  - README.rdoc
41
69
  files:
42
70
  - .autotest
@@ -45,23 +73,23 @@ files:
45
73
  - README.rdoc
46
74
  - Rakefile
47
75
  - bin/nfc
76
+ - ext/nfc/context.c
48
77
  - ext/nfc/extconf.rb
49
78
  - ext/nfc/nfc.c
50
79
  - ext/nfc/nfc.h
51
80
  - ext/nfc/nfc_device.c
52
- - ext/nfc/nfc_device.h
53
81
  - ext/nfc/nfc_felica.c
54
- - ext/nfc/nfc_felica.h
55
82
  - ext/nfc/nfc_iso14443a.c
56
- - ext/nfc/nfc_iso14443a.h
57
83
  - lib/nfc.rb
58
84
  - lib/nfc/device.rb
59
85
  - lib/nfc/felica.rb
60
86
  - lib/nfc/iso14443a.rb
61
- - test/test_nfc.rb
87
+ - test/test_context.rb
88
+ - test/test_device.rb
62
89
  - .gemtest
63
90
  homepage: http://seattlerb.rubyforge.org
64
91
  licenses: []
92
+ metadata: {}
65
93
  post_install_message:
66
94
  rdoc_options:
67
95
  - --main
@@ -69,22 +97,21 @@ rdoc_options:
69
97
  require_paths:
70
98
  - lib
71
99
  required_ruby_version: !ruby/object:Gem::Requirement
72
- none: false
73
100
  requirements:
74
- - - ! '>='
101
+ - - '>='
75
102
  - !ruby/object:Gem::Version
76
103
  version: '0'
77
104
  required_rubygems_version: !ruby/object:Gem::Requirement
78
- none: false
79
105
  requirements:
80
- - - ! '>='
106
+ - - '>='
81
107
  - !ruby/object:Gem::Version
82
108
  version: '0'
83
109
  requirements: []
84
110
  rubyforge_project: nfc
85
- rubygems_version: 1.8.2
111
+ rubygems_version: 2.0.2
86
112
  signing_key:
87
- specification_version: 3
113
+ specification_version: 4
88
114
  summary: NFC is a ruby wrapper for the Near Field Communication library
89
115
  test_files:
90
- - test/test_nfc.rb
116
+ - test/test_context.rb
117
+ - test/test_device.rb
@@ -1,8 +0,0 @@
1
- #ifndef NFC_DEVICE_H
2
- #define NFC_DEVICE_H
3
-
4
- #include <nfc.h>
5
-
6
- void init_device();
7
-
8
- #endif
@@ -1,10 +0,0 @@
1
- #ifndef NFC_Felica
2
- #define NFC_Felica
3
-
4
- #include <nfc.h>
5
-
6
- extern VALUE cNfcFelica;
7
-
8
- void init_felica();
9
-
10
- #endif
@@ -1,10 +0,0 @@
1
- #ifndef NFC_ISO14443A
2
- #define NFC_ISO14443A
3
-
4
- #include <nfc.h>
5
-
6
- extern VALUE cNfcISO14443A;
7
-
8
- void init_iso14443a();
9
-
10
- #endif
@@ -1,35 +0,0 @@
1
- require "test/unit"
2
- require "nfc"
3
-
4
- class TestNFC < Test::Unit::TestCase
5
- def setup
6
- @nfc = NFC.instance
7
- end
8
-
9
- def test_connect
10
- assert_not_nil @nfc.device
11
- end
12
-
13
- def test_deactivate_field
14
- @nfc.deactivate_field
15
- end
16
-
17
- def test_activate_field
18
- @nfc.activate_field
19
- end
20
-
21
- def test_crc=
22
- @nfc.crc = true
23
- @nfc.crc = false
24
- end
25
-
26
- def test_parity=
27
- @nfc.parity = true
28
- @nfc.parity = false
29
- end
30
-
31
- def test_infinite_list_passive=
32
- @nfc.infinite_list_passive = true
33
- @nfc.infinite_list_passive = false
34
- end
35
- end