--- Want to do both connect and send raw, so we should AND the two commands
--- ISO14A_COMMAND.ISO14A_RAW(8) and ISO14A_CONNECT (1). However, we don't have a
--- bitlib yet, so we'll do it manually, 1 & 8 == 9
--- ISO14A_NO_DISCONNECT = 2 ==> 11
-
-print(string.len(rawdata))
-local command = Command:new{cmd = cmds.CMD_READER_ISO_14443a,
- arg1 = 3, -- Connect (1) and don't disconnect (2)
- arg2 = 0-- string.len(rawdata),
- --data = rawdata
- }
-local mf_auth = Command:new{cmd = cmds.CMD_READER_ISO_14443a,
- arg1 = 6, -- Send raw
- arg2 = string.len(rawdata),
+--- Picks out and displays the data read from a tag
+-- Specifically, takes a usb packet, converts to a Command
+-- (as in commands.lua), takes the data-array and
+-- reads the number of bytes specified in arg1 (arg0 in c-struct)
+-- and displays the data
+-- @param usbpacket the data received from the device
+function showdata(usbpacket)
+ local cmd_response = Command.parse(usbpacket)
+ local len = tonumber(cmd_response.arg1) *2
+ --print("data length:",len)
+ local data = string.sub(tostring(cmd_response.data), 0, len);
+ print("<< ",data)
+ --print("----------------")
+end
+
+
+
+function sendRaw(rawdata, options)
+ print(">> ", rawdata)
+
+ local flags = lib14a.ISO14A_COMMAND.ISO14A_NO_DISCONNECT + lib14a.ISO14A_COMMAND.ISO14A_RAW
+
+ local command = Command:new{cmd = cmds.CMD_READER_ISO_14443a,
+ arg1 = flags, -- Send raw
+ -- arg2 contains the length, which is half the length
+ -- of the ASCII-string rawdata
+ arg2 = string.len(rawdata)/2,