2015-01-21 04:29:55 +08:00
|
|
|
local cmds = require('commands')
|
|
|
|
local getopt = require('getopt')
|
|
|
|
local bin = require('bin')
|
|
|
|
local utils = require('utils')
|
2020-04-05 18:56:35 +08:00
|
|
|
local ansicolors = require('ansicolors')
|
2015-01-21 04:29:55 +08:00
|
|
|
|
2019-04-29 01:26:26 +08:00
|
|
|
copyright = ''
|
|
|
|
author = 'Iceman'
|
2020-05-09 00:12:39 +08:00
|
|
|
version = 'v1.0.3'
|
2019-04-29 01:26:26 +08:00
|
|
|
desc = [[
|
2015-01-21 04:29:55 +08:00
|
|
|
This script will program a T55x7 TAG with the configuration: block 0x00 data 0x00088040
|
|
|
|
The outlined procedure is as following:
|
|
|
|
|
2017-07-31 21:26:53 +08:00
|
|
|
"lf t55xx write b 0 d 00088040"
|
|
|
|
"lf t55xx detect"
|
|
|
|
"lf t55xx info"
|
2015-01-21 04:29:55 +08:00
|
|
|
|
|
|
|
Loop OUTER:
|
2019-03-09 17:34:43 +08:00
|
|
|
change the configuretion block 0 with:
|
2015-01-21 04:29:55 +08:00
|
|
|
-xxxx8xxx = PSK RF/2 with Manchester modulation
|
|
|
|
-xxxx1xxx = PSK RF/2 with PSK1 modulation (phase change when input changes)
|
|
|
|
-xxxx2xxx = PSK RF/2 with PSk2 modulation (phase change on bitclk if input high)
|
|
|
|
-xxxx3xxx = PSK RF/2 with PSk3 modulation (phase change on rising edge of input)
|
2019-03-09 17:34:43 +08:00
|
|
|
Loop INNER
|
|
|
|
for each outer configuration, also do
|
|
|
|
XXXXX0XX = PSK RF/2
|
|
|
|
XXXXX4XX = PSK RF/4
|
|
|
|
XXXXX8XX = PSK RF/8
|
2015-01-21 04:29:55 +08:00
|
|
|
|
|
|
|
In all 12 individual test for the PSK demod
|
2019-04-29 01:26:26 +08:00
|
|
|
]]
|
|
|
|
example = [[
|
|
|
|
1. script run test_t55x7_psk
|
|
|
|
]]
|
|
|
|
usage = [[
|
2020-04-05 18:56:35 +08:00
|
|
|
script run test_t55x7_psk [-h]
|
|
|
|
]]
|
|
|
|
arguments = [[
|
2019-03-09 17:34:43 +08:00
|
|
|
-h : this help
|
2015-01-21 04:29:55 +08:00
|
|
|
]]
|
|
|
|
|
|
|
|
local DEBUG = true -- the debug flag
|
2019-05-13 22:51:26 +08:00
|
|
|
local TIMEOUT = 1500
|
2015-03-24 04:29:50 +08:00
|
|
|
|
2015-03-23 03:28:48 +08:00
|
|
|
-- --BLOCK 0 = 00 08 80 40 PSK
|
2015-03-24 04:29:50 +08:00
|
|
|
-- -----------
|
2019-03-09 17:34:43 +08:00
|
|
|
-- 08------- bitrate
|
|
|
|
-- 8----- modulation PSK1
|
|
|
|
-- 0---- PSK ClockRate
|
|
|
|
-- 40 max 2 blocks
|
2015-03-23 03:28:48 +08:00
|
|
|
|
2015-01-21 04:29:55 +08:00
|
|
|
local procedurecmds = {
|
2019-03-09 17:34:43 +08:00
|
|
|
[1] = '00%02X%X%X40',
|
|
|
|
[2] = 'lf t55xx detect',
|
|
|
|
[3] = 'lf t55xx info',
|
2015-01-21 04:29:55 +08:00
|
|
|
}
|
2019-03-09 17:34:43 +08:00
|
|
|
---
|
2015-01-21 04:29:55 +08:00
|
|
|
-- A debug printout-function
|
2017-07-31 21:26:53 +08:00
|
|
|
local function dbg(args)
|
2019-04-29 01:26:26 +08:00
|
|
|
if not DEBUG then return end
|
|
|
|
if type(args) == 'table' then
|
2019-03-09 17:34:43 +08:00
|
|
|
local i = 1
|
|
|
|
while args[i] do
|
|
|
|
dbg(args[i])
|
|
|
|
i = i+1
|
|
|
|
end
|
|
|
|
else
|
2019-04-29 01:26:26 +08:00
|
|
|
print('###', args)
|
2019-03-09 17:34:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
---
|
2015-01-21 04:29:55 +08:00
|
|
|
-- This is only meant to be used when errors occur
|
2017-07-31 21:26:53 +08:00
|
|
|
local function oops(err)
|
2019-04-29 01:26:26 +08:00
|
|
|
print('ERROR:', err)
|
|
|
|
core.clearCommandBuffer()
|
|
|
|
return nil, err
|
2015-01-21 04:29:55 +08:00
|
|
|
end
|
2019-03-09 17:34:43 +08:00
|
|
|
---
|
2015-01-21 04:29:55 +08:00
|
|
|
-- Usage help
|
2017-07-31 21:26:53 +08:00
|
|
|
local function help()
|
2019-04-29 01:26:26 +08:00
|
|
|
print(copyright)
|
|
|
|
print(author)
|
|
|
|
print(version)
|
2019-03-09 17:34:43 +08:00
|
|
|
print(desc)
|
2020-04-05 18:56:35 +08:00
|
|
|
print(ansicolors.cyan..'Usage'..ansicolors.reset)
|
2019-04-29 01:26:26 +08:00
|
|
|
print(usage)
|
2020-04-05 18:56:35 +08:00
|
|
|
print(ansicolors.cyan..'Arguments'..ansicolors.reset)
|
|
|
|
print(arguments)
|
|
|
|
print(ansicolors.cyan..'Example usage'..ansicolors.reset)
|
|
|
|
print(example)
|
2015-01-21 04:29:55 +08:00
|
|
|
end
|
|
|
|
--
|
|
|
|
-- Exit message
|
2017-07-31 21:26:53 +08:00
|
|
|
local function ExitMsg(msg)
|
2019-03-09 17:34:43 +08:00
|
|
|
print( string.rep('--',20) )
|
|
|
|
print( string.rep('--',20) )
|
|
|
|
print(msg)
|
|
|
|
print()
|
2015-01-21 04:29:55 +08:00
|
|
|
end
|
|
|
|
|
2017-07-31 21:26:53 +08:00
|
|
|
local function test(modulation)
|
2019-03-09 17:34:43 +08:00
|
|
|
local bitrate
|
|
|
|
local clockrate
|
2019-05-13 22:51:26 +08:00
|
|
|
local password = '00000000'
|
2019-04-29 01:26:26 +08:00
|
|
|
local block = '00'
|
2019-05-13 22:51:26 +08:00
|
|
|
local flags = '00'
|
2019-03-09 17:34:43 +08:00
|
|
|
for bitrate = 0x0, 0x1d, 0x4 do
|
|
|
|
|
|
|
|
for clockrate = 0,8,4 do
|
|
|
|
|
|
|
|
for _ = 1, #procedurecmds do
|
|
|
|
local cmd = procedurecmds[_]
|
|
|
|
|
|
|
|
if #cmd == 0 then
|
|
|
|
|
|
|
|
elseif _ == 1 then
|
|
|
|
|
2019-04-29 01:26:26 +08:00
|
|
|
dbg('Writing to T55x7 TAG')
|
2019-03-09 17:34:43 +08:00
|
|
|
|
|
|
|
local config = cmd:format(bitrate, modulation, clockrate)
|
2019-04-29 01:26:26 +08:00
|
|
|
dbg(('lf t55xx write b 0 d %s'):format(config))
|
|
|
|
|
2019-05-13 22:51:26 +08:00
|
|
|
local data = ('%s%s%s%s'):format(utils.SwapEndiannessStr(config, 32), password, block, flags)
|
|
|
|
|
2019-08-04 01:17:00 +08:00
|
|
|
local wc = Command:newNG{cmd = cmds.CMD_LF_T55XX_WRITEBL, data = data}
|
2019-05-13 22:51:26 +08:00
|
|
|
local response, err = wc:sendNG(false, TIMEOUT)
|
2019-04-29 01:26:26 +08:00
|
|
|
if not response then return oops(err) end
|
2019-03-09 17:34:43 +08:00
|
|
|
else
|
|
|
|
dbg(cmd)
|
|
|
|
core.console( cmd )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
core.clearCommandBuffer()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
print( string.rep('--',20) )
|
2015-01-21 04:29:55 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
local function main(args)
|
|
|
|
|
2019-03-09 17:34:43 +08:00
|
|
|
print( string.rep('--',20) )
|
|
|
|
print( string.rep('--',20) )
|
|
|
|
|
|
|
|
-- Arguments for the script
|
|
|
|
for o, arg in getopt.getopt(args, 'h') do
|
2019-04-29 01:26:26 +08:00
|
|
|
if o == 'h' then return help() end
|
2019-03-09 17:34:43 +08:00
|
|
|
end
|
2015-01-21 04:29:55 +08:00
|
|
|
|
2019-03-09 17:34:43 +08:00
|
|
|
core.clearCommandBuffer()
|
2015-01-21 04:29:55 +08:00
|
|
|
|
2019-03-09 17:34:43 +08:00
|
|
|
test(1) -- PSK1
|
|
|
|
--test(2) -- PSK2
|
|
|
|
--test(3) -- PSK3
|
2015-01-21 04:29:55 +08:00
|
|
|
|
2019-03-09 17:34:43 +08:00
|
|
|
print( string.rep('--',20) )
|
2015-01-21 04:29:55 +08:00
|
|
|
end
|
|
|
|
main(args)
|
2015-03-24 04:29:50 +08:00
|
|
|
|
2019-03-09 17:34:43 +08:00
|
|
|
-- Where it iterates over
|
2015-03-24 04:29:50 +08:00
|
|
|
-- xxxx8xxx = PSK RF/2 with Manchester modulation
|
|
|
|
-- xxxx1xxx = PSK RF/2 with PSK1 modulation (phase change when input changes)
|
|
|
|
-- xxxx2xxx = PSK RF/2 with PSk2 modulation (phase change on bitclk if input high)
|
|
|
|
-- xxxx3xxx = PSK RF/2 with PSk3 modulation (phase change on rising edge of input)
|
|
|
|
|
|
|
|
-- XXXXX0XX = PSK RF/2
|
|
|
|
-- XXXXX4XX = PSK RF/4
|
|
|
|
-- XXXXX8XX = PSK RF/8
|