refactoring NG

This commit is contained in:
iceman1001 2019-05-07 22:59:29 +02:00
commit 3c533db308
2 changed files with 20 additions and 29 deletions

View file

@ -108,9 +108,16 @@ local function waitFor14443b()
return nil, 'Aborted by user' return nil, 'Aborted by user'
end end
---
-- turns on the HF field.
local function connect14443b()
local c = Command:newMIX{cmd = cmds.CMD_ISO_14443B_COMMAND, arg1 = ISO14B_COMMAND.ISO14B_CONNECT}
return c.sendMIX(true)
end
---
-- Sends an instruction to do nothing, only disconnect -- Sends an instruction to do nothing, only disconnect
local function disconnect14443b() local function disconnect14443b()
local c = Command:newMIX{cmd = cmds.CMD_READER_ISO_14443b} local c = Command:newMIX{cmd = cmds.CMD_ISO_14443B_COMMAND, arg1 = ISO14B_COMMAND.ISO14B_DISCONNECT}
-- We can ignore the response here, no ACK is returned for this command -- We can ignore the response here, no ACK is returned for this command
-- Check /armsrc/iso14443b.c, ReaderIso14443b() for details -- Check /armsrc/iso14443b.c, ReaderIso14443b() for details
return c.sendMIX(true) return c.sendMIX(true)
@ -120,6 +127,7 @@ local library = {
read = read14443b, read = read14443b,
waitFor14443b = waitFor14443b, waitFor14443b = waitFor14443b,
parse1443b = parse1443b, parse1443b = parse1443b,
connect = connect14443b,
disconnect = disconnect14443b, disconnect = disconnect14443b,
ISO14B_COMMAND = ISO14B_COMMAND, ISO14B_COMMAND = ISO14B_COMMAND,
} }

View file

@ -28,21 +28,6 @@ Check there for details about data format and how commands are interpreted on th
device-side. device-side.
]] ]]
---
--
local function calypso_switch_on_field()
local flags = lib14b.ISO14B_COMMAND.ISO14B_CONNECT
local c = Command:new{cmd = cmds.CMD_ISO_14443B_COMMAND, arg1 = flags}
return lib14b.sendToDevice(c, true)
end
---
-- Disconnect (poweroff) the antenna forcing a disconnect of a 14b tag.
local function calypso_switch_off_field()
local flags = lib14b.ISO14B_COMMAND.ISO14B_DISCONNECT
local c = Command:new{cmd = cmds.CMD_ISO_14443B_COMMAND, arg1 = flags}
return lib14b.sendToDevice(c, true)
end
local function calypso_parse(result) local function calypso_parse(result)
local r = Command.parse(result) local r = Command.parse(result)
local len = r.arg2 * 2 local len = r.arg2 * 2
@ -71,7 +56,7 @@ end
-- This is only meant to be used when errors occur -- This is only meant to be used when errors occur
local function oops(err) local function oops(err)
print('ERROR: ', err) print('ERROR: ', err)
calypso_switch_off_field() lib14b.disconnect()
return nil, err return nil, err
end end
--- ---
@ -128,15 +113,13 @@ local function calypso_send_cmd_raw(data, ignoreresponse )
data = data or "00" data = data or "00"
command = Command:new{cmd = cmds.CMD_ISO_14443B_COMMAND, command = Command:newMIX{
cmd = cmds.CMD_ISO_14443B_COMMAND,
arg1 = flags, arg1 = flags,
arg2 = #data/2, -- LEN of data, half the length of the ASCII-string hex string arg2 = #data/2, -- LEN of data, half the length of the ASCII-string hex string
arg3 = 0,
data = data} -- data bytes (commands etc) data = data} -- data bytes (commands etc)
result, err = lib14b.sendToDevice(command, false)
if ignoreresponse then return response, err end
result, err = command:sendMIX(ignoreresponse)
if result then if result then
local r = calypso_parse(result) local r = calypso_parse(result)
return r, nil return r, nil
@ -228,7 +211,7 @@ function main(args)
if o == 'b' then bytes = a end if o == 'b' then bytes = a end
end end
calypso_switch_on_field() lib14b.connect()
-- Select 14b tag. -- Select 14b tag.
card, err = lib14b.waitFor14443b() card, err = lib14b.waitFor14443b()
@ -264,7 +247,7 @@ function main(args)
print('<< no answer') print('<< no answer')
end end
end end
calypso_switch_off_field() lib14b.disconnect()
end end
--- ---
-- a simple selftest function, tries to convert -- a simple selftest function, tries to convert