Class: NFC::Tag
- Inherits:
-
Object
- Object
- NFC::Tag
- Defined in:
- lib/ruby-nfc/tags/tag.rb
Direct Known Subclasses
Class Method Summary collapse
-
.match?(target) ⇒ Boolean
Matches any NFC tag.
Instance Method Summary collapse
- #connect(&block) ⇒ Object
- #disconnect ⇒ Object
-
#initialize(target, reader) ⇒ Tag
constructor
A new instance of Tag.
- #present? ⇒ Boolean
- #processed! ⇒ Object
- #processed? ⇒ Boolean
- #to_s ⇒ Object
- #uid ⇒ Object
- #uid_hex ⇒ Object
Constructor Details
#initialize(target, reader) ⇒ Tag
Returns a new instance of Tag.
3 4 5 6 7 |
# File 'lib/ruby-nfc/tags/tag.rb', line 3 def initialize(target, reader) @target = target @reader = reader @processed = false end |
Class Method Details
.match?(target) ⇒ Boolean
Matches any NFC tag
58 59 60 |
# File 'lib/ruby-nfc/tags/tag.rb', line 58 def self.match?(target) true end |
Instance Method Details
#connect(&block) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/ruby-nfc/tags/tag.rb', line 9 def connect(&block) if block_given? begin self.instance_eval(&block) ensure disconnect end end end |
#disconnect ⇒ Object
42 |
# File 'lib/ruby-nfc/tags/tag.rb', line 42 def disconnect; end |
#present? ⇒ Boolean
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ruby-nfc/tags/tag.rb', line 27 def present? modulation = LibNFC::Modulation.new modulation[:nmt] = :NMT_ISO14443A modulation[:nbr] = :NBR_106 ptr = FFI::MemoryPointer.new(:char, @target[:nti][:nai][:szUidLen]) ptr.put_bytes(0, uid) res = LibNFC.nfc_initiator_select_passive_target(@reader.ptr, modulation, ptr, @target[:nti][:nai][:szUidLen], FFI::Pointer::NULL) return res >= 1 end |
#processed! ⇒ Object
19 20 21 |
# File 'lib/ruby-nfc/tags/tag.rb', line 19 def processed! @target.processed! end |
#processed? ⇒ Boolean
23 24 25 |
# File 'lib/ruby-nfc/tags/tag.rb', line 23 def processed? @target.processed? end |
#to_s ⇒ Object
53 54 55 |
# File 'lib/ruby-nfc/tags/tag.rb', line 53 def to_s uid_hex end |
#uid ⇒ Object
44 45 46 47 |
# File 'lib/ruby-nfc/tags/tag.rb', line 44 def uid uid_size = @target[:nti][:nai][:szUidLen] @target[:nti][:nai][:abtUid].to_s[0...uid_size] end |
#uid_hex ⇒ Object
49 50 51 |
# File 'lib/ruby-nfc/tags/tag.rb', line 49 def uid_hex uid.unpack('H*').pop end |