xref: /openwifi/user_space/fast_reg_log/fast_reg_log_analyzer.m (revision 3acd1024f60e301775d392b2d9e881bc8db97bb3)
1% Author: Xianjun Jiao ([email protected]; [email protected])
2% SPDX-FileCopyrightText: 2023 UGent
3% SPDX-License-Identifier: AGPL-3.0-or-later
4
5function fast_reg_log_analyzer(filename_bin, start_idx, end_idx)
6close all;
7
8% if exist('start_idx', 'var')==0 || isempty(start_idx)
9%   start_idx = 1;
10% end
11%
12% if exist('end_idx', 'var')==0 || isempty(end_idx)
13%   end_idx = 65536;
14% end
15
16filename_csv = [filename_bin(1:(end-3)) 'csv'];
17disp(['Human readable fast reg log will be in ' filename_csv]);
18
19fid = fopen(filename_bin);
20if fid == -1
21    disp('fopen failed!');
22    return;
23end
24
25a = fread(fid, inf, 'uint32');
26fclose(fid);
27% a = bitand(uint32(a), uint32(268435455));
28% plot(a(1:2:end)); hold on;
29% plot(a(2:2:end));
30% legend('1', '2');
31
32a = uint32(a);
33tsf = a(2:2:end);
34% plot(tsf);
35state = a(1:2:end);
36
37% find out overflow idx
38overflow_idx = find(diff([0; double(tsf)])<0, 1, 'first');
39% overflow_idx
40if ~isempty(overflow_idx)
41    tsf(overflow_idx:end) = tsf(overflow_idx:end) + (2^32);
42    disp(num2str(overflow_idx));
43end
44
45rssi_correction = 145;
46rssi_half_db = double(bitand(bitshift(state, 0), uint32((2^11)-1)));
47agc_lock = 1 - double(bitand(bitshift(state, -11), uint32(1)));
48demod_is_ongoing = double(bitand(bitshift(state, -12), uint32(1)));
49tx_is_ongoing = double(bitand(bitshift(state, -13), uint32(1)));
50ch_idle = 1 - double(bitand(bitshift(state, -14), uint32(1)));
51iq_rssi_half_db = double(bitand(bitshift(state, -16), uint32((2^9)-1)));
52agc_gain = double(bitand(bitshift(state, -25), uint32((2^7)-1)));
53
54rssi_dbm = (rssi_half_db./2) - rssi_correction;
55
56figure;
57subplot(2,1,1);
58plot(tsf, -rssi_dbm, 'r+-'); hold on;
59plot(tsf, iq_rssi_half_db, 'bo-');
60plot(tsf, agc_gain, 'ks-');
61legend('rssi dbm', 'iq rssi half db', 'agc gain');
62subplot(2,1,2);
63plot(tsf, agc_lock+0); hold on;
64plot(tsf, demod_is_ongoing+2);
65plot(tsf, tx_is_ongoing+4);
66plot(tsf, ch_idle+6);
67
68legend('agc lock', 'demod is ongoing', 'tx is ongoing', 'ch idle');
69
70a=table(tsf, rssi_half_db, rssi_dbm, iq_rssi_half_db, agc_gain, agc_lock, demod_is_ongoing, tx_is_ongoing, ch_idle);
71writetable(a, filename_csv);
72