Generic tracing; removed iso14a_XX-functions, removed traceLen as global varible
[legacy-proxmark3.git] / client / scripts / tracetest.lua
blobe4a9215cb0a74bb0c877c0f636c4097a1031c721
1 local cmds = require('commands')
2 local getopt = require('getopt')
3 local bin = require('bin')
4 local utils = require('utils')
5 local dumplib = require('html_dumplib')
7 example =[[
8 1. script run tracetest
9 2. script run tracetest -o
12 author = "Iceman"
13 usage = "script run tracetest -o <filename>"
14 desc =[[
15 This script will load several traces files in ../traces/ folder and do
16 "data load"
17 "lf search"
19 Arguments:
20 -h : this help
21 -o : logfile name
24 local TIMEOUT = 2000 -- Shouldn't take longer than 2 seconds
25 local DEBUG = true -- the debug flag
26 ---
27 -- A debug printout-function
28 function dbg(args)
29 if not DEBUG then
30 return
31 end
33 if type(args) == "table" then
34 local i = 1
35 while result[i] do
36 dbg(result[i])
37 i = i+1
38 end
39 else
40 print("###", args)
41 end
42 end
43 ---
44 -- This is only meant to be used when errors occur
45 function oops(err)
46 print("ERROR: ",err)
47 end
48 ---
49 -- Usage help
50 function help()
51 print(desc)
52 print("Example usage")
53 print(example)
54 end
56 -- Exit message
57 function ExitMsg(msg)
58 print( string.rep('--',20) )
59 print( string.rep('--',20) )
60 print(msg)
61 print()
62 end
65 local function main(args)
67 print( string.rep('--',20) )
68 print( string.rep('--',20) )
70 local cmdDataLoad = 'data load %s';
71 local tracesEM = "find '../traces/' -iname 'em*.pm3' -type f"
72 local tracesMOD = "find '../traces/' -iname 'm*.pm3' -type f"
74 local outputTemplate = os.date("testtest_%Y-%m-%d_%H%M%S")
76 -- Arguments for the script
77 for o, arg in getopt.getopt(args, 'ho:') do
78 if o == "h" then return help() end
79 if o == "o" then outputTemplate = arg end
80 end
82 core.clearCommandBuffer()
84 local files = {}
86 -- Find a set of traces staring with EM
87 local p = assert( io.popen(tracesEM))
88 for file in p:lines() do
89 table.insert(files, file)
90 end
91 p.close();
93 -- Find a set of traces staring with MOD
94 p = assert( io.popen(tracesMOD) )
95 for file in p:lines() do
96 table.insert(files, file)
97 end
98 p.close();
100 local cmdLFSEARCH = "lf search 1"
102 -- main loop
103 io.write('Starting to test traces > ')
104 for _,file in pairs(files) do
106 local x = "data load "..file
107 dbg(x)
108 core.console(x)
110 dbg(cmdLFSEARCH)
111 core.console(cmdLFSEARCH)
113 core.clearCommandBuffer()
115 if core.ukbhit() then
116 print("aborted by user")
117 break
120 io.write('\n')
122 -- Write dump to files
123 if not DEBUG then
124 local bar = dumplib.SaveAsText(emldata, outputTemplate..'.txt')
125 print(("Wrote output to: %s"):format(bar))
128 -- Show info
129 print( string.rep('--',20) )
132 main(args)