Skip to content
Browse files

it compiles now with libnfc 1.5

  • Loading branch information...
1 parent 55c5c4e commit 67a7e5d12c4fd750d747168fe059e1d830080866 @tenderlove committed May 27, 2011
Showing with 101 additions and 66 deletions.
  1. +2 −2 README.rdoc
  2. +3 −7 ext/nfc/extconf.rb
  3. +1 −1 ext/nfc/nfc.h
  4. +55 −17 ext/nfc/nfc_device.c
  5. +14 −14 ext/nfc/nfc_felica.c
  6. +24 −24 ext/nfc/nfc_iso14443a.c
  7. +2 −1 lib/nfc/device.rb
View
4 README.rdoc
@@ -52,13 +52,13 @@ The install the gem:
$ sudo gem install nfc
-NOTE!!!! The nfc gem requires libnfc version 1.2.0 or greater!
+NOTE!!!! The nfc gem requires libnfc version 1.5.0 or greater!
== LICENSE:
(The MIT License)
-Copyright (c) 2009 Aaron Patterson
+Copyright (c) 2009-2011 Aaron Patterson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
View
10 ext/nfc/extconf.rb
@@ -37,17 +37,13 @@
'/usr/lib',
]
-nfc_dirs = dir_config('nfc', '/opt/local/include', '/opt/local/lib')
-unless ["", ""] == nfc_dirs
- HEADER_DIRS.unshift nfc_dirs.first
- LIB_DIRS.unshift nfc_dirs[1]
-end
+nfc_dirs = dir_config('nfc', HEADER_DIRS, LIB_DIRS)
-unless find_header('libnfc/libnfc.h', *HEADER_DIRS)
+unless find_header('nfc/nfc.h')
abort "libnfc is missing. please install libnfc: http://libnfc.org/"
end
-unless find_library('nfc', 'nfc_connect', *LIB_DIRS)
+unless find_library('nfc', 'nfc_connect')
abort "libnfc is missing. please install libnfc: http://libnfc.org/"
end
View
2 ext/nfc/nfc.h
@@ -2,7 +2,7 @@
#define NFC_H
#include <ruby.h>
-#include <libnfc/libnfc.h>
+#include <nfc/nfc.h>
extern VALUE cNfc;
View
72 ext/nfc/nfc_device.c
@@ -10,7 +10,7 @@ static byte_t abtFelica[5] = { 0x00, 0xff, 0xff, 0x00, 0x00 };
*/
static VALUE connect(VALUE klass)
{
- dev_info * dev = nfc_connect();
+ nfc_device_t * dev = nfc_connect(NULL);
if(!dev)
rb_raise(rb_eRuntimeError, "could not find NFC device");
@@ -28,8 +28,8 @@ static VALUE connect(VALUE klass)
*/
static VALUE disconnect(VALUE self)
{
- dev_info * dev;
- Data_Get_Struct(self, dev_info, dev);
+ nfc_device_t * dev;
+ Data_Get_Struct(self, nfc_device_t, dev);
nfc_disconnect(dev);
return self;
@@ -43,12 +43,12 @@ static VALUE disconnect(VALUE self)
*/
static VALUE configure(VALUE self, VALUE option, VALUE flag)
{
- dev_info * dev;
- Data_Get_Struct(self, dev_info, dev);
+ nfc_device_t * dev;
+ Data_Get_Struct(self, nfc_device_t, dev);
nfc_configure(
dev,
- (const dev_config_option)NUM2INT(option),
+ (const nfc_device_option_t)NUM2INT(option),
(const bool)NUM2INT(flag)
);
@@ -63,20 +63,23 @@ static VALUE configure(VALUE self, VALUE option, VALUE flag)
*/
static VALUE dev_select(VALUE self, VALUE tag)
{
- dev_info * dev;
- Data_Get_Struct(self, dev_info, dev);
+ nfc_device_t * dev;
+ nfc_modulation_t * mod;
- tag_info * ti = calloc(1, sizeof(tag_info));
+ Data_Get_Struct(self, nfc_device_t, dev);
+ Data_Get_Struct(self, nfc_modulation_t, mod);
- if (nfc_initiator_select_tag(dev, IM_ISO14443A_106, NULL, 0, ti) ) {
+ nfc_target_t * ti = calloc(1, sizeof(nfc_target_t));
+
+ if (nfc_initiator_select_passive_target(dev, *mod, NULL, 0, ti) ) {
return Data_Wrap_Struct(cNfcISO14443A, 0, free, ti);
}
+ /*
if (nfc_initiator_select_tag(dev, IM_FELICA_212, abtFelica, 5, ti) || nfc_initiator_select_tag(dev, IM_FELICA_424, abtFelica, 5, ti)) {
return Data_Wrap_Struct(cNfcFelica, 0, free, ti);
}
-
-
+ */
}
/*
@@ -87,8 +90,8 @@ static VALUE dev_select(VALUE self, VALUE tag)
*/
static VALUE name(VALUE self)
{
- dev_info * dev;
- Data_Get_Struct(self, dev_info, dev);
+ nfc_device_t * dev;
+ Data_Get_Struct(self, nfc_device_t, dev);
return rb_str_new2(dev->acName);
}
@@ -101,14 +104,34 @@ static VALUE name(VALUE self)
*/
static VALUE dev_deselect(VALUE self)
{
- dev_info * dev;
- Data_Get_Struct(self, dev_info, dev);
+ nfc_device_t * dev;
+ Data_Get_Struct(self, nfc_device_t, dev);
+
+ //nfc_initiator_deselect_tag(dev);
+
+ return self;
+}
+
+static VALUE mod_initialize(VALUE self, VALUE type, VALUE baud)
+{
+ nfc_modulation_t * mod;
- nfc_initiator_deselect_tag(dev);
+ Data_Get_Struct(self, nfc_modulation_t, mod);
+ mod->nmt = NUM2INT(type);
+ mod->nbr = NUM2INT(baud);
return self;
}
+static VALUE mod_alloc(VALUE klass)
+{
+ nfc_modulation_t * modulation;
+
+ modulation = xcalloc(1, sizeof(nfc_modulation_t));
+
+ return Data_Wrap_Struct(klass, NULL, xfree, modulation);
+}
+
void init_device()
{
VALUE cNfcDevice = rb_define_class_under(cNfc, "Device", rb_cObject);
@@ -119,4 +142,19 @@ void init_device()
rb_define_method(cNfcDevice, "select", dev_select, 1);
rb_define_method(cNfcDevice, "deselect", dev_deselect, 0);
rb_define_method(cNfcDevice, "name", name, 0);
+
+ VALUE cNfcModulation = rb_define_class_under(cNfcDevice, "Modulation", rb_cObject);
+
+ /* modulation types. */
+ rb_define_const(cNfcModulation, "ISO14443A", INT2NUM(NMT_ISO14443A));
+ rb_define_const(cNfcModulation, "FELICA", INT2NUM(NMT_FELICA));
+
+ /* baud rates */
+ rb_define_const(cNfcModulation, "NBR_UNDEFINED", INT2NUM(NBR_UNDEFINED));
+ rb_define_const(cNfcModulation, "NBR_106", INT2NUM(NBR_106));
+ rb_define_const(cNfcModulation, "NBR_212", INT2NUM(NBR_212));
+
+ rb_define_alloc_func(cNfcModulation, mod_alloc);
+
+ rb_define_method(cNfcModulation, "initialize", mod_initialize, 2);
}
View
28 ext/nfc/nfc_felica.c
@@ -3,49 +3,49 @@
VALUE cNfcFelica;
/*
- * uint32_t uiLen;
+ * size_t szLen;
* byte_t btResCode;
* byte_t abtId[8];
* byte_t abtPad[8];
* byte_t abtSysCode[2];
*/
-static VALUE uiLen(VALUE self)
+static VALUE szLen(VALUE self)
{
- tag_info_felica * tag;
- Data_Get_Struct(self, tag_info_felica, tag);
+ nfc_felica_info_t * tag;
+ Data_Get_Struct(self, nfc_felica_info_t, tag);
- return INT2NUM(tag->uiLen);
+ return INT2NUM(tag->szLen);
}
static VALUE btResCode(VALUE self)
{
- tag_info_felica * tag;
- Data_Get_Struct(self, tag_info_felica, tag);
+ nfc_felica_info_t * tag;
+ Data_Get_Struct(self, nfc_felica_info_t, tag);
return INT2NUM(tag->btResCode);
}
static VALUE abtId(VALUE self)
{
- tag_info_felica * tag;
- Data_Get_Struct(self, tag_info_felica, tag);
+ nfc_felica_info_t * tag;
+ Data_Get_Struct(self, nfc_felica_info_t, tag);
return rb_str_new(tag->abtId, 8 );
}
static VALUE abtPad(VALUE self)
{
- tag_info_felica * tag;
- Data_Get_Struct(self, tag_info_felica, tag);
+ nfc_felica_info_t * tag;
+ Data_Get_Struct(self, nfc_felica_info_t, tag);
return rb_str_new(tag->abtPad, 8 );
}
static VALUE abtSysCode(VALUE self)
{
- tag_info_felica * tag;
- Data_Get_Struct(self, tag_info_felica, tag);
+ nfc_felica_info_t * tag;
+ Data_Get_Struct(self, nfc_felica_info_t, tag);
return rb_str_new(tag->abtSysCode, 2 );
}
@@ -54,7 +54,7 @@ void init_felica()
{
cNfcFelica = rb_define_class_under(cNfc, "Felica", rb_cObject);
- rb_define_method(cNfcFelica, "uiLen", uiLen, 0);
+ rb_define_method(cNfcFelica, "szLen", szLen, 0);
rb_define_method(cNfcFelica, "btResCode", btResCode, 0);
rb_define_method(cNfcFelica, "abtId", abtId, 0);
rb_define_private_method(cNfcFelica, "abtPad", abtPad, 0);
View
48 ext/nfc/nfc_iso14443a.c
@@ -4,30 +4,30 @@ VALUE cNfcISO14443A;
/*
* call-seq:
- * uiUidLen
+ * szUidLen
*
- * Get the uiUidLen
+ * Get the szUidLen
*/
-static VALUE uiUidLen(VALUE self)
+static VALUE szUidLen(VALUE self)
{
- tag_info_iso14443a * tag;
- Data_Get_Struct(self, tag_info_iso14443a, tag);
+ nfc_iso14443a_info_t * tag;
+ Data_Get_Struct(self, nfc_iso14443a_info_t, tag);
- return INT2NUM(tag->uiUidLen);
+ return INT2NUM(tag->szUidLen);
}
/*
* call-seq:
- * uiAtsLen
+ * szAtsLen
*
- * Get the uiAtsLen
+ * Get the szAtsLen
*/
-static VALUE uiAtsLen(VALUE self)
+static VALUE szAtsLen(VALUE self)
{
- tag_info_iso14443a * tag;
- Data_Get_Struct(self, tag_info_iso14443a, tag);
+ nfc_iso14443a_info_t * tag;
+ Data_Get_Struct(self, nfc_iso14443a_info_t, tag);
- return INT2NUM(tag->uiAtsLen);
+ return INT2NUM(tag->szAtsLen);
}
/*
@@ -38,10 +38,10 @@ static VALUE uiAtsLen(VALUE self)
*/
static VALUE abtUid(VALUE self)
{
- tag_info_iso14443a * tag;
- Data_Get_Struct(self, tag_info_iso14443a, tag);
+ nfc_iso14443a_info_t * tag;
+ Data_Get_Struct(self, nfc_iso14443a_info_t, tag);
- return rb_str_new(tag->abtUid, tag->uiUidLen);
+ return rb_str_new(tag->abtUid, tag->szUidLen);
}
/*
@@ -52,10 +52,10 @@ static VALUE abtUid(VALUE self)
*/
static VALUE abtAts(VALUE self)
{
- tag_info_iso14443a * tag;
- Data_Get_Struct(self, tag_info_iso14443a, tag);
+ nfc_iso14443a_info_t * tag;
+ Data_Get_Struct(self, nfc_iso14443a_info_t, tag);
- return rb_str_new(tag->abtAts, tag->uiAtsLen);
+ return rb_str_new(tag->abtAts, tag->szAtsLen);
}
/*
@@ -66,8 +66,8 @@ static VALUE abtAts(VALUE self)
*/
static VALUE abtAtqa(VALUE self)
{
- tag_info_iso14443a * tag;
- Data_Get_Struct(self, tag_info_iso14443a, tag);
+ nfc_iso14443a_info_t * tag;
+ Data_Get_Struct(self, nfc_iso14443a_info_t, tag);
return rb_str_new(tag->abtAtqa, 2);
}
@@ -80,8 +80,8 @@ static VALUE abtAtqa(VALUE self)
*/
static VALUE btSak(VALUE self)
{
- tag_info_iso14443a * tag;
- Data_Get_Struct(self, tag_info_iso14443a, tag);
+ nfc_iso14443a_info_t * tag;
+ Data_Get_Struct(self, nfc_iso14443a_info_t, tag);
return INT2NUM(tag->btSak);
}
@@ -90,8 +90,8 @@ void init_iso14443a()
{
cNfcISO14443A = rb_define_class_under(cNfc, "ISO14443A", rb_cObject);
- rb_define_method(cNfcISO14443A, "uiUidLen", uiUidLen, 0);
- rb_define_method(cNfcISO14443A, "uiAtsLen", uiAtsLen, 0);
+ rb_define_method(cNfcISO14443A, "szUidLen", szUidLen, 0);
+ rb_define_method(cNfcISO14443A, "szAtsLen", szAtsLen, 0);
rb_define_method(cNfcISO14443A, "btSak", btSak, 0);
rb_define_private_method(cNfcISO14443A, "abtUid", abtUid, 0);
View
3 lib/nfc/device.rb
@@ -5,6 +5,7 @@ class Device
DCO_ACTIVATE_FIELD = 0x10
DCO_INFINITE_LIST_PASSIVE = 0x20
- IM_ISO14443A_106 = 0x00
+ IM_ISO14443A_106 = Modulation.new Modulation::ISO14443A,
+ Modulation::NBR_106
end
end

0 comments on commit 67a7e5d

Please sign in to comment.
Something went wrong with that request. Please try again.