-
Notifications
You must be signed in to change notification settings - Fork 74
/
PTimport.m
75 lines (63 loc) · 2.56 KB
/
PTimport.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
function [DAT newFileName] = PTimport(csvFname, BBLFileName)
%% [DAT newFileName] = PTimport(filename, BBLFileName)
% Imports log data in multiple formats (fw=selected firmware/logfile type). Default is .csv, but if using .bbl or .bfl files,
% ----------------------------------------------------------------------------------
% "THE BEER-WARE LICENSE" (Revision 42):
% <[email protected]> wrote this file. As long as you retain this notice you
% can do whatever you want with this stuff. If we meet some day, and you think
% this stuff is worth it, you can buy me a beer in return. -Brian White
% ----------------------------------------------------------------------------------
newFileName=csvFname;
try % speed things up a bit with this method
hdr=detectImportOptions(csvFname);
T=readtable(csvFname, 'HeaderLines', 2);
T.Properties.VariableNames=hdr.VariableNames;
catch
T=readtable(csvFname);
end
delete(csvFname);% we r done with this-dont wanna leave junk on main directory
% get header info from .bbl/.bfl file directly
a=strfind(BBLFileName,'.');
fid = fopen(BBLFileName, 'r');
c = textscan(fid, '%s', 'Delimiter','\n','CollectOutput',1); %c2 = native2unicode(c)
fclose(fid);
logStartPoints=[];
logEndPoints=[];
a=strfind(c{1},'Firmware version');
if isempty(find(cellfun(@(a)~isempty(a)&&a>0,a)))
a=strfind(c{1},'Firmware revision');
logStartPoints=find(cellfun(@(a)~isempty(a)&&a>0,a));
else
a=strfind(c{1},'Firmware version');
logStartPoints=find(cellfun(@(a)~isempty(a)&&a>0,a));
end
endStr={'throttle_boost_cutoff'; 'debug_mode' ; 'motor_pwm_rate' ; 'use_unsynced_pwm' ; 'gyro_32khz_hardware_lpf' ; 'gyro_hardware_lpf' ; 'yaw_deadband' ; 'deadband' ; 'pidsum_limit_yaw' ; 'pidsum_limit' ; 'energyCumulative (mAh)'; 'looptime'};% strings not in all revisions, try a few
m=1; a=strfind(c{1},endStr{m});
while isempty(find(cellfun(@(a)~isempty(a)&&a>0,a)))
a=strfind(c{1},endStr{m});
m=m+1;
end
logEndPoints = find(cellfun(@(a)~isempty(a)&&a>0,a));
relevantLogNum=str2num(csvFname(end-5:end-4));
s=c{1}(logStartPoints(relevantLogNum):logEndPoints(relevantLogNum));
n=1;
for m=1:size(s,1)
if size(strsplit(char(s(m)),':'),2)==2
SetupInfo(n,:)=(strsplit(char(s(m)),':'));
a=char(SetupInfo(n,1));
if strcmp(a(1:2),'H ')
SetupInfo(n,1)={a(3:end)};
end
n=n+1;
end
end
%
DAT.T=T;
DAT.mainFname=BBLFileName;
DAT.csvFname=csvFname;
DAT.SetupInfo=SetupInfo;
try
DAT.blackbox_decode_results=result;
catch
end
end