From e14c1aaf2157ebb18970e26674d787843a481514 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sat, 10 Oct 2020 09:24:47 +0200 Subject: [PATCH] more options --- client/luascripts/lf_em_tearoff.lua | 52 ++++++++++++++++++----------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/client/luascripts/lf_em_tearoff.lua b/client/luascripts/lf_em_tearoff.lua index 6d44f1ee4..c9b0d85f7 100644 --- a/client/luascripts/lf_em_tearoff.lua +++ b/client/luascripts/lf_em_tearoff.lua @@ -11,7 +11,7 @@ example = [[ 1. script run tearoff -n 2 -s 200 -e 400 -a 5 ]] usage = [[ -script run tearoff [-h] [-n ] [-a ] [-p ] [-s ] [-e ] +script run tearoff [-h] [-n ] [-a ] [-p ] [-s ] [-e ] [-r ] [-w ] ]] arguments = [[ -h This help @@ -20,6 +20,8 @@ arguments = [[ -p (optional) use a password -s inital start delay -e end delay, must be larger than start delay + -r 4 hex bytes value to be read + -w 4 hex bytes value to be written end ]] @@ -59,18 +61,21 @@ local function main(args) core.em4x05_read(addr, password) --]] - local n, addr, password, sd, ed + local n, addr, password, sd, ed, wr_value, rd_value - for o, a in getopt.getopt(args, 'he:s:a:p:n:') do + for o, a in getopt.getopt(args, 'he:s:a:p:n:r:w:') do if o == 'h' then return help() end if o == 'n' then n = a end if o == 'a' then addr = a end if o == 'p' then password = a end if o == 'e' then ed = tonumber(a) end if o == 's' then sd = tonumber(a) end + if o == 'w' then wr_value = a end + if o == 'r' then rd_value = a end end - + rd_value = rd_value or 'FFFFFFFF' + wr_value = wr_value or 'FFFFFFFF' addr = addr or 5 password = password or '' n = n or 2 @@ -81,6 +86,14 @@ local function main(args) password = '' end + if #wr_value ~= 8 then + wr_value = 'FFFFFFFF' + end + + if #rd_value ~= 8 then + rd_value = 'FFFFFFFF' + end + if sd > ed then return oops('start delay cant be larger than end delay', sd, ed) end @@ -91,8 +104,9 @@ local function main(args) print('target pwd', password) end print('target stepping', n) - print('target delay') - print('', sd, ed) + print('target delay', sd ,ed) + print('read value', rd_value) + print('write value', wr_value) local res_tear = 0 local res_nowrite = 0 @@ -100,6 +114,8 @@ local function main(args) local set_tearoff_delay = 'hw tearoff --delay %d' local enable_tearoff = 'hw tearoff --on' + local wr_template = 'lf em 4x05_write %s %s %s' + for step = sd, ed, n do io.flush() @@ -109,23 +125,25 @@ local function main(args) end core.clearCommandBuffer() + c = wr_template:format(addr, wr_value, password) + core.console(c) local c = set_tearoff_delay:format(step) core.console(c); core.console(enable_tearoff) - if #password == 8 then - c = ('lf em 4x05_write %s ffffffff %s'):format(addr, password) - else - c = ('lf em 4x05_write %s ffffffff'):format(addr) - end + + c = wr_template:format(addr, wr_value, password) core.console(c) + local word, err = core.em4x05_read(addr, password) if err then return oops(err) end - if word ~= 0xFFFFFFFF then - if word ~= 0 then + local wordstr = ('%08X'):format(word) + + if wordstr ~= wr_value then + if wordstr ~= rd_value then print((ansicolors.red..'TEAR OFF occured:'..ansicolors.reset..' %08X'):format(word)) res_tear = res_tear + 1 else @@ -135,13 +153,7 @@ local function main(args) else print((ansicolors.green..'Good write occured:'..ansicolors.reset..' %08X'):format(word)) end - - if password then - c = ('lf em 4x05_write %s 00000000 %s'):format(addr, password) - else - c = ('lf em 4x05_write %s 00000000'):format(addr) - end - core.console(c) + if res_tear == 5 then print(('No of no writes %d'):format(res_nowrite))