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(poll_nr = 1, ms = 1) ⇒ Object
-
#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
102 103 104 105 106 107 108 109 110 |
# File 'ext/nfc/nfc_device.c', line 102 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
150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'ext/nfc/nfc_device.c', line 150 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
88 89 90 91 92 93 94 |
# File 'ext/nfc/nfc_device.c', line 88 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(poll_nr = 1, ms = 1) ⇒ Object
15 16 17 |
# File 'lib/nfc/device.rb', line 15 def poll poll_nr = 1, ms = 1 poll_target NFC::Device::IM_ISO14443A_106, poll_nr,ms end |
#poll_target(tag, ms) ⇒ Object
Poll the tag type from the device
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 74 75 76 77 78 79 80 |
# File 'ext/nfc/nfc_device.c', line 47 static VALUE poll_target(VALUE self, VALUE tag, VALUE poll_nr, VALUE ms) { nfc_device * dev; nfc_modulation * mod; nfc_target * ti; int code; int ms_c, poll_nr_c; Data_Get_Struct(self, nfc_device, dev); Data_Get_Struct(tag, nfc_modulation, mod); ms_c = FIX2INT(ms); poll_nr_c = FIX2INT(poll_nr); ti = (nfc_target *)xmalloc(sizeof(nfc_target)); code = nfc_initiator_poll_target(dev, mod, 1, poll_nr_c, ms_c, 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); } }else { xfree(ti); } 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 38 39 |
# 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); } }else { xfree(ti); } return Qfalse; } |