Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

getting inspect to work properly

  • Loading branch information...
commit 785272fea5d8a41d3e946718eb95a6567e51d70e 1 parent e9e9b82
Aaron Patterson authored
Showing with 40 additions and 3 deletions.
  1. +18 −0 ext/nfc/nfc_iso14443a.c
  2. +0 −1  lib/nfc.rb
  3. +22 −2 lib/nfc/iso14443a.rb
18 ext/nfc/nfc_iso14443a.c
View
@@ -34,13 +34,31 @@ static VALUE abtAts(VALUE self)
return rb_str_new(tag->abtAts, tag->uiAtsLen);
}
+static VALUE abtAtqa(VALUE self)
+{
+ tag_info_iso14443a * tag;
+ Data_Get_Struct(self, tag_info_iso14443a, tag);
+
+ return rb_str_new(tag->abtAtqa, 2);
+}
+
+static VALUE btSak(VALUE self)
+{
+ tag_info_iso14443a * tag;
+ Data_Get_Struct(self, tag_info_iso14443a, tag);
+
+ return INT2NUM(tag->btSak);
+}
+
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, "btSak", btSak, 0);
rb_define_private_method(cNfcISO14443A, "abtUid", abtUid, 0);
rb_define_private_method(cNfcISO14443A, "abtAts", abtAts, 0);
+ rb_define_private_method(cNfcISO14443A, "abtAtqa", abtAtqa, 0);
}
1  lib/nfc.rb
View
@@ -55,7 +55,6 @@ def find
activate_field
tag = poll_mifare
deselect
- disconnect
@mutex.unlock
yield tag if block_given?
tag
24 lib/nfc/iso14443a.rb
View
@@ -1,11 +1,31 @@
class NFC
class ISO14443A
def uid
- abtUid.unpack('C*')
+ abtUid.unpack 'C*'
end
def ats
- abtAts.unpack('C*')
+ abtAts.unpack 'C*'
+ end
+
+ def atqa
+ abtAtqa.unpack 'C*'
+ end
+
+ def inspect
+ uid = sprintf((['%02x'] * uiUidLen).join(' '), *self.uid)
+
+ string_ary =
+ [ "(NFC) ISO14443A Tag",
+ " ATQA (SENS_RES): #{sprintf("%02x %02x", *atqa)}",
+ " UID (NFCID1): #{uid}",
+ " SAK (SEL_RES): #{sprintf("%02x", btSak)}"
+ ]
+ if uiAtsLen > 0
+ ats = sprintf((['%02x'] * uiAtsLen).join(' '), *self.ats)
+ string_ary << " ATS (ATR): #{ats}"
+ end
+ string_ary.join "\n"
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.