Skip to content

Commit

Permalink
Simple shell for communicating with IsoDep::Tag compatible tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim Chechel committed Oct 15, 2014
1 parent 6ef14df commit 0d44517
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions examples/nfc-apdu-shell.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'ruby-nfc'

WAITING_FOR_TAG = "Waiting for tag..."
PROMPT = "%s < "
OUTPUT = "%s > %s"

puts WAITING_FOR_TAG

NFC::Reader.all[0].poll(IsoDep::Tag) do |tag|
begin
loop do
print PROMPT % uid_hex
apdu = $stdin.readline.gsub(/\s+/, '')
case apdu
when /exit|quit/
puts "Bye!"
exit!
when /^([a-f0-9]{2}){5,128}$/i
response = send_apdu [apdu].pack('H*')
puts OUTPUT % [uid_hex, response]
else
puts "Error: wrong APDU format"
end
end
rescue Exception => e
p e
puts WAITING_FOR_TAG
end
end

0 comments on commit 0d44517

Please sign in to comment.