Class: NFC::Device
- Inherits:
-
Object
- Object
- NFC::Device
- Defined in:
- lib/nfc/device.rb,
ext/nfc/nfc_device.c
Defined Under Namespace
Classes: Modulation
Constant Summary collapse
- DCO_HANDLE_CRC =
0x00- DCO_HANDLE_PARITY =
0x01- DCO_ACTIVATE_FIELD =
0x10- DCO_INFINITE_LIST_PASSIVE =
0x20- IM_ISO14443A_106 =
Modulation.new Modulation::NMT_ISO14443A, Modulation::NBR_106
Instance Method Summary collapse
-
#deselect ⇒ Object
Deselect the current tag.
- #initiator_init ⇒ Object
-
#name ⇒ Object
Get the name of the tag reader.
-
#poll_target(tag, ms) ⇒ Object
Poll the
tagtype from the device. -
#select ⇒ Object
Find a tag, blocks until there is a tag available.
-
#select_passive_target(tag) ⇒ Object
Select the
tagtype from the device.
Instance Method Details
#deselect ⇒ Object
Deselect the current tag
95 96 97 98 99 100 101 102 103 |
# File 'ext/nfc/nfc_device.c', line 95
static VALUE dev_deselect(VALUE self)
{
nfc_device * dev;
Data_Get_Struct(self, nfc_device, dev);
nfc_initiator_deselect_target(dev);
return self;
}
|
#initiator_init ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'ext/nfc/nfc_device.c', line 143
static VALUE initiator_init(VALUE self)
{
nfc_device * dev;
int err;
Data_Get_Struct(self, nfc_device, dev);
err = nfc_initiator_init(dev);
if (0 == err)
return Qtrue;
return INT2NUM(err);
}
|
#name ⇒ Object
Get the name of the tag reader
81 82 83 84 85 86 87 |
# File 'ext/nfc/nfc_device.c', line 81
static VALUE name(VALUE self)
{
nfc_device * dev;
Data_Get_Struct(self, nfc_device, dev);
return rb_str_new2(nfc_device_get_name(dev));
}
|
#poll_target(tag, ms) ⇒ Object
Poll the tag type from the device
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'ext/nfc/nfc_device.c', line 45
static VALUE poll_target(VALUE self, VALUE tag, VALUE ms)
{
nfc_device * dev;
nfc_modulation * mod;
nfc_target * ti;
int code;
Data_Get_Struct(self, nfc_device, dev);
Data_Get_Struct(tag, nfc_modulation, mod);
ti = (nfc_target *)xmalloc(sizeof(nfc_target));
code = nfc_initiator_poll_target(dev, mod, 1, 0, 1, ti);
if (code > 0) {
switch(mod->nmt) {
case NMT_ISO14443A:
return Data_Wrap_Struct(cNfcISO14443A, 0, xfree, ti);
break;
case NMT_FELICA:
return Data_Wrap_Struct(cNfcFelica, 0, xfree, ti);
break;
default:
rb_raise(rb_eRuntimeError, "untested type: %d", mod->nmt);
}
}
return INT2NUM(code);
}
|
#select ⇒ Object
Find a tag, blocks until there is a tag available
12 13 14 |
# File 'lib/nfc/device.rb', line 12 def select select_passive_target NFC::Device::IM_ISO14443A_106 end |
#select_passive_target(tag) ⇒ Object
Select the tag type from the device
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'ext/nfc/nfc_device.c', line 11
static VALUE select_passive_target(VALUE self, VALUE tag)
{
nfc_device * dev;
nfc_modulation * mod;
nfc_target * ti;
Data_Get_Struct(self, nfc_device, dev);
Data_Get_Struct(tag, nfc_modulation, mod);
ti = (nfc_target *)xmalloc(sizeof(nfc_target));
if (nfc_initiator_select_passive_target(dev, *mod, NULL, 0, ti) ) {
switch(mod->nmt) {
case NMT_ISO14443A:
return Data_Wrap_Struct(cNfcISO14443A, 0, xfree, ti);
break;
case NMT_FELICA:
/* return Data_Wrap_Struct(cNfcFelica, 0, free, ti); */
return Qnil;
break;
default:
rb_raise(rb_eRuntimeError, "untested type: %d", mod->nmt);
}
}
return Qfalse;
}
|