1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-13 20:48:42 +01:00
LibrePilot/ground/openpilotgcs/src/plugins/uavobjects/uavobjecttemplate.m
2011-11-09 12:49:50 -06:00

68 lines
1.4 KiB
Matlab

function [] = OPLogConvert()
%% Define indices and arrays of structures to hold data
% THIS FILE IS AUTOMATICALLY GENERATED.
$(ALLOCATIONCODE)
%% Open log file
% [FileName,PathName,FilterIndex] = uigetfile('*.opl');
FileName='OP-2011-10-22_22-27-09.opl';
PathName='/Users/kenz/Movies/brisk_videos/rover_test_1/';
FilterIndex=1;
logfile = fullfile(PathName,FileName);
fid = fopen(logfile);
% Parse log file, entry by entry
while (1)
%% Read logging header
timestamp = fread(fid, 1, 'uint32');
if (feof(fid)); break; end
datasize = fread(fid, 1, 'int64');
%% Read message header
% get sync field (0x3C, 1 byte)
sync = fread(fid, 1, 'uint8');
if sync ~= hex2dec('3C')
disp ('Wrong sync byte');
return
end
% get msg type (quint8 1 byte ) should be 0x20, ignore the rest?
msgType = fread(fid, 1, 'uint8');
if msgType ~= hex2dec('20')
disp ('Wrong msgType');
return
end
% get msg size (quint16 2 bytes) excludes crc, include msg header and data payload
msgSize = fread(fid, 1, 'uint16');
% get obj id (quint32 4 bytes)
objID = fread(fid, 1, 'uint32');
%% Read object
switch objID
$(SWITCHCODE)
otherwise
disp(['Unknown object ID: 0x' dec2hex(objID)]);
msgBytesLeft = datasize - 1 - 1 - 2 - 4;
fread(fid, msgBytesLeft, 'uint8');
end
end
%% Clean Up and Save mat file
fclose(fid);
matfile = strrep(logfile,'opl','mat');
save(matfile $(SAVEOBJECTSCODE));
%% Object reading functions
$(FUNCTIONSCODE)