Skip to content

Commit

Permalink
Updated README example so that it actually works
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrayner committed Mar 14, 2016
1 parent fc31683 commit 121b99b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,42 +71,42 @@ p "Available readers: #{readers}"

# The order of tag types in poll arguments defines priority of tag types
readers[0].poll(IsoDep::Tag, Mifare::Classic::Tag, Mifare::Ultralight::Tag) do |tag|
begin
p "Applied #{tag.class.name}: #{tag}"
begin
p "Applied #{tag.class.name}: #{tag}"

case tag
when Mifare::Classic::Tag
if auth(4, :key_a, "FFFFFFFFFFFF")
if tag.auth(4, :key_a, "FFFFFFFFFFFF")
# Mifare::Classic::Tag.read method reads contents of last authenticated
# block
p "Contents of block 0x04: #{tag.read.unpack('H*').pop}"
# Making random 16-byte string
rnd = Array.new(16).map{rand(255)}.pack('C*')
tag.write(rnd)
p "New value: #{rnd.unpack('H*').pop}"
processed!
tag.processed!
else
p "Authentication failed!"
end
when Mifare::Ultralight::Tag
p "Page 1: #{read(1).unpack('H*').pop}"
processed!
p "Page 1: #{tag.read(1).unpack('H*').pop}"
tag.processed!
when IsoDep::Tag
select! ["F75246544101"].pack('H*')
tag.select! ["F75246544101"].pack('H*')
# sending APDU command to tag using send_apdu method
apdu = ['A00D010018B455CAF0F331AF703EFA2E2D744EC7E22AA64076CD19F6D0'].pack('H*')
p send_apdu(apdu)
p tag.send_apdu(apdu)

# sending APDU command with "<<" operator which is alias to send_apdu
response = tag << apdu
p "status word: #{response.sw.to_s(16)} data: #{response.data.unpack('H*').pop}"
processed!
tag.processed!
end
rescue Exception => e
p e
end
end

rescue Exception => e
p e
end
end
```

This example should provide similar output when you apply your tags to the NFC-reader:
Expand Down
27 changes: 14 additions & 13 deletions examples/listen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,39 @@ def p(str)

# The order of tag types in poll arguments defines priority of tag types
readers[0].poll(IsoDep::Tag, Mifare::Classic::Tag, Mifare::Ultralight::Tag) do |tag|
begin
p "Applied #{tag.class.name}: #{tag}"
begin
p "Applied #{tag.class.name}: #{tag}"

case tag
when Mifare::Classic::Tag
if auth(4, :key_a, "FFFFFFFFFFFF")
if tag.auth(4, :key_a, "FFFFFFFFFFFF")
# Mifare::Classic::Tag.read method reads contents of last authenticated
# block
p "Contents of block 0x04: #{tag.read.unpack('H*').pop}"
# Making random 16-byte string
rnd = Array.new(16).map{rand(255)}.pack('C*')
tag.write(rnd)
p "New value: #{rnd.unpack('H*').pop}"
processed!
tag.processed!
else
p "Authentication failed!"
end
when Mifare::Ultralight::Tag
p "Page 1: #{read(1).unpack('H*').pop}"
processed!
p "Page 1: #{tag.read(1).unpack('H*').pop}"
tag.processed!
when IsoDep::Tag
select! ["F75246544101"].pack('H*')
tag.select! ["F75246544101"].pack('H*')
# sending APDU command to tag using send_apdu method
apdu = ['A00D010018B455CAF0F331AF703EFA2E2D744EC7E22AA64076CD19F6D0'].pack('H*')
p send_apdu(apdu)
p tag.send_apdu(apdu)

# sending APDU command with "<<" operator which is alias to send_apdu
response = tag << apdu
p "status word: #{response.sw.to_s(16)} data: #{response.data.unpack('H*').pop}"
processed!
tag.processed!
end
rescue Exception => e
p e
end
end

rescue Exception => e
p e
end
end

0 comments on commit 121b99b

Please sign in to comment.