]>
Commit | Line | Data |
---|---|---|
81740aa5 | 1 | local cmds = require('commands') |
2 | local getopt = require('getopt') | |
3 | local bin = require('bin') | |
4 | local utils = require('utils') | |
81740aa5 | 5 | |
6 | example =[[ | |
13d77ef9 | 7 | 1. script run test_t55x7_psk |
8 | 2. script run test_t55x7_psk -o | |
81740aa5 | 9 | |
10 | ]] | |
11 | author = "Iceman" | |
13d77ef9 | 12 | usage = "script run test_t55x7_psk" |
81740aa5 | 13 | desc =[[ |
14 | This script will program a T55x7 TAG with the configuration: block 0x00 data 0x00088040 | |
15 | The outlined procedure is as following: | |
16 | ||
17 | "lf t55xx write 0 00088040" | |
18 | "lf read" | |
19 | "data samples" | |
20 | "data pskdet" | |
21 | "data psknrz" | |
22 | "data pskindala" | |
23 | "data psknrzraw" | |
24 | ||
25 | Loop OUTER: | |
26 | change the configuretion block 0 with: | |
27 | -xxxx8xxx = PSK RF/2 with Manchester modulation | |
28 | -xxxx1xxx = PSK RF/2 with PSK1 modulation (phase change when input changes) | |
29 | -xxxx2xxx = PSK RF/2 with PSk2 modulation (phase change on bitclk if input high) | |
30 | -xxxx3xxx = PSK RF/2 with PSk3 modulation (phase change on rising edge of input) | |
31 | Loop INNER | |
32 | for each outer configuration, also do | |
33 | XXXXX0XX = PSK RF/2 | |
34 | XXXXX4XX = PSK RF/4 | |
35 | XXXXX8XX = PSK RF/8 | |
36 | ||
37 | In all 12 individual test for the PSK demod | |
38 | ||
39 | Arguments: | |
40 | -h : this help | |
81740aa5 | 41 | ]] |
42 | ||
43 | local TIMEOUT = 2000 -- Shouldn't take longer than 2 seconds | |
44 | local DEBUG = true -- the debug flag | |
81740aa5 | 45 | |
13d77ef9 | 46 | -- local procedurecmds = { |
47 | -- [1] = '%s%s%s%s', | |
48 | -- [2] = 'lf read', | |
49 | -- --[3] = '', | |
50 | -- [3] = 'data samples', | |
51 | -- [4] = 'data pskdetectclock', | |
52 | -- [5] = 'data psknrzrawdemod', | |
53 | -- [6] = 'data pskindalademod', | |
54 | -- } | |
55 | ||
56 | -- --BLOCK 0 = 00 08 80 40 PSK | |
57 | -- ----------- | |
58 | -- 08------- bitrate | |
59 | -- 8----- modulation PSK1 | |
60 | -- 0---- PSK ClockRate | |
61 | -- 40 max 2 blocks | |
62 | ||
81740aa5 | 63 | local procedurecmds = { |
13d77ef9 | 64 | [1] = '00%02X%X%X40', |
65 | [2] = 'lf t55xx detect', | |
81740aa5 | 66 | --[3] = '', |
13d77ef9 | 67 | [3] = 'lf t55xx info', |
81740aa5 | 68 | } |
81740aa5 | 69 | --- |
70 | -- A debug printout-function | |
71 | function dbg(args) | |
72 | if not DEBUG then | |
73 | return | |
74 | end | |
75 | ||
76 | if type(args) == "table" then | |
77 | local i = 1 | |
78 | while args[i] do | |
79 | dbg(args[i]) | |
80 | i = i+1 | |
81 | end | |
82 | else | |
83 | print("###", args) | |
84 | end | |
85 | end | |
86 | --- | |
87 | -- This is only meant to be used when errors occur | |
88 | function oops(err) | |
89 | print("ERROR: ",err) | |
90 | end | |
91 | --- | |
92 | -- Usage help | |
93 | function help() | |
94 | print(desc) | |
95 | print("Example usage") | |
96 | print(example) | |
97 | end | |
98 | -- | |
99 | -- Exit message | |
100 | function ExitMsg(msg) | |
101 | print( string.rep('--',20) ) | |
102 | print( string.rep('--',20) ) | |
103 | print(msg) | |
104 | print() | |
105 | end | |
106 | ||
13d77ef9 | 107 | function test(modulation) |
108 | local bitrate | |
109 | local clockrate | |
110 | for bitrate = 0x0, 0x1d, 0x4 do | |
111 | ||
112 | for clockrate = 0,8,4 do | |
81740aa5 | 113 | local cmd = procedurecmds[_] |
13d77ef9 | 114 | |
115 | if #cmd == 0 then | |
116 | ||
81740aa5 | 117 | elseif _ == 1 then |
118 | ||
119 | dbg("Writing to T55x7 TAG") | |
13d77ef9 | 120 | |
121 | local config = cmd:format(bitrate, modulation, clockrate) | |
122 | dbg(('lf t55xx write 0 %s'):format(config)) | |
81740aa5 | 123 | |
13d77ef9 | 124 | config = tonumber(config,16) |
125 | local writecommand = Command:new{cmd = cmds.CMD_T55XX_WRITE_BLOCK, arg1 = config ,arg2 = 0, arg3 = 0} | |
81740aa5 | 126 | local err = core.SendCommand(writecommand:getBytes()) |
127 | if err then return oops(err) end | |
128 | local response = core.WaitForResponseTimeout(cmds.CMD_ACK,TIMEOUT) | |
81740aa5 | 129 | else |
130 | dbg(cmd) | |
131 | core.console( cmd ) | |
132 | end | |
133 | end | |
81740aa5 | 134 | end |
135 | print( string.rep('--',20) ) | |
81740aa5 | 136 | end |
137 | ||
138 | local function main(args) | |
139 | ||
140 | print( string.rep('--',20) ) | |
141 | print( string.rep('--',20) ) | |
142 | ||
81740aa5 | 143 | -- Arguments for the script |
13d77ef9 | 144 | for o, arg in getopt.getopt(args, 'h') do |
81740aa5 | 145 | if o == "h" then return help() end |
81740aa5 | 146 | end |
147 | ||
148 | core.clearCommandBuffer() | |
149 | ||
13d77ef9 | 150 | test(1) --PSK1 |
151 | -- test(2) --PSK2 | |
152 | -- test(3) --PSK3 | |
81740aa5 | 153 | |
154 | print( string.rep('--',20) ) | |
155 | end | |
156 | main(args) |