Attempt to add some basic caching of tag details to tikitag

This commit is contained in:
2009-02-03 00:02:20 +00:00
parent 503ec5bc10
commit 251b68f5aa
2 changed files with 35 additions and 7 deletions

View File

@@ -4,15 +4,39 @@ from smartcard.util import toHexString, toASCIIString
class TikiTag(mifareul.MiFareUltralight):
_tag = None
_uid = None
def get_uid(self):
d = self.read_block(0)
d = d+ self.read_block(1)
uid = toHexString(d).replace(" ", "")[:16]
return toHexString(d).replace(" ", "")[:16]
return uid
def _check_uid(self):
uid = self.get_uid()
if (not self._uid == uid):
self._tag = None
self._uid = uid
return False
else:
return True
def get_tag_url(self):
""" Retreives the tag's URL stored in NDEF format """
self._tag = type2.NFCType2(self.read_tag())
# The tikitag usually has a single NDEF with a single URI record type
# so assumptions can be made here.
self._check_uid()
if not self._tag:
d = self.read_tag()
self._tag = type2.NFCType2(d)
return self._tag.ndefs[0].items[0][1]

14
test.py
View File

@@ -3,6 +3,7 @@ import logging, sys
from pytikitag import reader, tikitag
from pytikitag.nfc import type2
from smartcard.util import toHexString, toASCIIString
import time
log = logging.getLogger('pytikitag.mifareul')
h = logging.StreamHandler(sys.stdout)
@@ -15,9 +16,12 @@ print "Tikitag ID: " + m.get_uid()
print "Manf: " + m.get_manf_ascii() + ", Serial: " + m.get_serial()
print ""
print "Reading Tikitag Data..."
print m.get_tag_url()
#tag = type2.NFCType2(d)
#print tag.ndefs[0].items
#print toHexString(value)
#print toASCIIString(value)
i = 0
try:
while not i == 1:
print m.get_tag_url()
time.sleep(1)
except KeyboardInterrupt:
pass