Added error handling for no-card case and when proximity check is not supported.

This commit is contained in:
Dom 2018-05-11 10:36:50 +01:00
commit a73d6e9b39

View file

@ -45,7 +45,9 @@ function sendRaw(rawdata, crc, power)
--unpack the first 4 parts of the result as longs, and the last as an extremely long string to later be cut down based on arg1, the number of bytes returned --unpack the first 4 parts of the result as longs, and the last as an extremely long string to later be cut down based on arg1, the number of bytes returned
local count,cmd,arg1,arg2,arg3,data = bin.unpack('LLLLH512',result) local count,cmd,arg1,arg2,arg3,data = bin.unpack('LLLLH512',result)
returned_bytes = string.sub(data, 1, arg1 * 2) returned_bytes = string.sub(data, 1, arg1 * 2)
print(("<recvd>: %s"):format(returned_bytes)) -- need to multiply by 2 because the hex digits are actually two bytes when they are strings if returned_bytes ~= "" then
print(("<recvd>: %s"):format(returned_bytes)) -- need to multiply by 2 because the hex digits are actually two bytes when they are strings
end
return returned_bytes return returned_bytes
else else
err = "Error sending the card raw data." err = "Error sending the card raw data."
@ -189,6 +191,10 @@ function proximityCheck()
--PreparePC-- --PreparePC--
commandString = PREPAREPC commandString = PREPAREPC
response = sendRaw(commandString, true, true) response = sendRaw(commandString, true, true)
if(response == "") then
print("ERROR: This card does not support the Proximity Check command.")
return
end
OPT = string.sub(response, 5, 6) OPT = string.sub(response, 5, 6)
if(tonumber(OPT) == 1) then if(tonumber(OPT) == 1) then
pps_present = true pps_present = true
@ -255,17 +261,19 @@ end
function main(args) function main(args)
-- Initialize the card using the already-present read14a library -- Initialize the card using the already-present read14a library
info,err = lib14a.read14443a(true, false) info,err = lib14a.read14443a(true, false)
--Perform PPS (Protocol and Parameter Selection) check to finish the ISO 14443-4 protocol. --Perform RATS and PPS (Protocol and Parameter Selection) check to finish the ISO 14443-4 protocol.
response = sendRaw("e050", true, true) response = sendRaw("e050", true, true)
if(response == nil) then if(response == "") then
err = "No response from RATS" print("No response from RATS.")
end end
response = sendRaw("D01100", true, true) response = sendRaw("D01100", true, true)
if(response == nil) then if(response == "") then
err = "No response from PPS check" print("No response from PPS check.")
end end
if err then if err then
oops(err) oops(err)
sendRaw(POWEROFF, false, false)
return
else else
print(("Connected to card with a UID of %s."):format(info.uid)) print(("Connected to card with a UID of %s."):format(info.uid))
end end