|
dRonin
adbada4
dRonin GCS
|
Go to the source code of this file.
Functions | |
| fprintf ('\n\n ***dRonin log parser ***\n\n') | |
| else | error ('Your technical computing program does not support file choosers.Please input the file name in the argument. ') end elseif nargin >0 logfile |
| if nargin && | strcmp (class(varargin{2}),'char') |
| elseif nargin && | strcmp (class(varargin{2}),'logical') |
| end end if | ~strcmpi (outputType,'mat')&&~strcmpi(outputType |
| end end if csv | error ('Incorrect file format specified.Second argument must be ''mat''or ''csv''.') |
| end (INSTANTIATIONCODE) fid | |
| fgetl (fid) | |
| Read third line if | strcmp (gitLogfileHash, uavoImporterHash) |
| end if | strcmp (uavoLogfileHash, UAVO_HASH) |
| fprintf ([str1 str2 str3 str4 str5]) | |
| end for as it was simply a dummy placeholder | disp (['Unknown object ID:0x'dec2hex(unknownObjIDList(i, 1), 8) 'appeared 'int2str(unknownObjIDList(i, 2)) 'times.']) |
| end Clean Up and Save mat file | fclose (fid) |
| Prune | vectors (CLEANUPCODE)%%Perform typecasting on vectors $(ALLOCATIONCODE)%%Save data to file if strcmpi(outputType |
| save (matfile $(SAVEOBJECTSCODE)) | |
| else (EXPORTCSVCODE) end fprintf('%d records in%0.2f seconds.\n' | |
| etime (clock, startTime)) | |
| function | OPLog2csv (structIn, structName, logfile)%Get each field name from the structure fieldNames |
| if | isempty (structIn.(fieldNames{1})) |
| Write to csv | dlmwrite (csvfile, headerOut, '') |
| dlmwrite (csvfile, matOut, '-append') | |
| 'Inputs must be vectors, i.e just one column wide.' | inStart () |
Variables | |
| function [] | |
| UAVO_HASH = '${UAVOSHA1TXT}' | |
| outputType ='mat' | |
| Default output is a mat file | checkCRC = false |
| wrongSyncByte =0 | |
| wrongMessageByte =0 | |
| lastWrongSyncByte =0 | |
| lastWrongMessageByte =0 | |
| str1 =[] | |
| str2 =[] | |
| str3 =[] | |
| str4 =[] | |
| str5 =[] | |
| multipleInstanceLookup = zeros(0,2) | |
| overo = false | |
| global | crc_table |
| if | nargin |
| logfile =fullfile(PathName, FileName) | |
| Read first line | gitLogfileHash = fgetl(fid) |
| Read second line | uavoLogfileHash = fgetl(fid) |
| end | buffer =fread(fid,Inf,'uchar=>uchar') |
| bufferIdx =1 | |
| correctMsgByte =hex2dec('20') | |
| correctSyncByte =hex2dec('3C') | |
| unknownObjIDList =zeros(1,2) | |
| Parse log | file |
| Parse log entry by entry | prebuf = buffer(1:12) |
| last_print = -1e10 | |
| startTime =clock | |
| if overo | instanceIdOffset = -2 |
| timestampWraparound = 2^16 | |
| end | timestampAccumulator = 0 |
| lastTimestamp = 0 | |
| buffer_len = length(buffer) | |
| while bufferIdx< (buffer_len-20)%%Read message header%get sync field(0x3C, 1 byte) if~overo sync=buffer(bufferIdx+12);else sync=buffer(bufferIdx);end if sync~=correctSyncByte bufferIdx=bufferIdx+1;if~overo||sync~=255 wrongSyncByte=wrongSyncByte+1;end continue end if~overo%For GCS logging the format is as follows%4 bytes timestamp(milliseconds)%8 bytes data size%UAVTalk packet(always without timestamped packets)%Sync val(0x3c)%Message type(1 byte)%Length(2 bytes)%Object ID(4 bytes)%Instance ID(optional, 2 bytes)%Data(variable length)%Checksum(1 byte)%Process header, if we are aligned datasizeBufferIdx=bufferIdx;%Just grab the index.We'll do a typecast later, if necessary datasizeLength=4;msgType=buffer(bufferIdx+13);%get msg type(quint8 1 byte) should be 0x20, ignore the rest?objID=typecast(buffer(bufferIdx+16:bufferIdx+16+4-1), 'uint32');%get obj id(quint32 4 bytes) timestamp=double(typecast(buffer(bufferIdx:bufferIdx+4-1),'uint32'));%Advance buffer past header to where data is(or instance ID) bufferIdx=bufferIdx+20;else%For Overo logging the format is%UAVTalk packet(with timestamped packet)%Sync val(0x3c)%Message type(1 byte, adds 0x80)%Length(2 bytes)%Object ID(4 bytes)%Instance ID(optional, 2 bytes)%Timestamp(2 bytes)%Data(variable length)%Checksum(1 byte)%Process header for overo datasizeBufferIdx=bufferIdx+2;datasizeLength=2;msgType=buffer(bufferIdx+1)-128;objID=typecast(buffer(bufferIdx+4:bufferIdx+4+4-1), 'uint32');singleInstance=multipleInstanceLookup(multipleInstanceLookup(:, 1)==objID, 2);if singleInstance timestamp=double(typecast(buffer(bufferIdx+8:bufferIdx+10-1),'uint16'));else timestamp=double(typecast(buffer(bufferIdx+12:bufferIdx+14-1),'uint16'));end%Advance buffer past header to where data is.In the case of a%multiple instance object this will be where the timstamp is but%the parsing code will advance by two more.bufferIdx=bufferIdx+10;end if timestamp< lastTimestamp timestampAccumulator=timestampAccumulator+timestampWraparound;end lastTimestamp=timestamp;timestamp=timestamp+timestampAccumulator;%Check that message type is correct if msgType~=correctMsgByte wrongMessageByte=wrongMessageByte+1;continue end if(isempty(objID))%End of file break;end%%Read object try switch objID $(SWITCHCODE) otherwise unknownObjIDListIdx=find(unknownObjIDList(:, 1)==objID, 1, 'first');if isempty(unknownObjIDListIdx) unknownObjIDList=[unknownObjIDList;uint32(objID) 1];%#ok< AGROW > else unknownObjIDList(unknownObjIDListIdx, 2)=unknownObjIDList(unknownObjIDListIdx, 2)+1;end datasize=typecast(buffer(datasizeBufferIdx+4:datasizeBufferIdx+12-1), 'uint64');msgBytesLeft=datasize-1-1-2-4;if msgBytesLeft > 255 msgBytesLeft=0;end bufferIdx=bufferIdx+double(msgBytesLeft);end catch%One of the reads failed-indicates EOF break;end if(wrongSyncByte~=lastWrongSyncByte||wrongMessageByte~=lastWrongMessageByte)||...bufferIdx-last_print > | Every |
| for | i =1:length([str2 str3 str4 str5]) |
| Arbitrary times two so that it is at least as long | estTimeRemaining =(buffer_len-bufferIdx)/(bufferIdx/etime(clock,startTime)) * 2 |
| h =floor(estTimeRemaining/3600) | |
| m =floor((estTimeRemaining-h*3600)/60) | |
| s =ceil(estTimeRemaining-h*3600-m*60) | |
| end Check if at end of file If | not |
| Prune | mat [path, name] =fileparts(logfile) |
| matfile = fullfile(path,[name '.mat']) | |
| Create a text string with the field names | headerOut =sprintf('%s,',fieldNames{:}) |
| Trim off | last |
| Trim off and t Assign the structure arrays to a matrix | matOut =zeros(max(size(structIn.(fieldNames{1}))), length(fieldNames)) |
| end end Create filename by replacing opl by | csv [path, name] = fileparts(logfile) |
| csvDirName =[name '_csv'] | |
| Dummy outputs so the program doens t throw warnings about Directory already exists | csvfile =fullfile(path, csvDirName , [name '.csv']) |
| function | crc |
| end function | out |
| end function found on Matlab s file exchange The two functions return identical | results |
| end function found on Matlab s file exchange The two functions return identical although his is much faster | Unfortunately |
| inFinish =inFinish' | |
| end end | diffIn =diff([inStart; inFinish]) |
| numElements =sum(diffIn)+length(inStart) | |
| idx =1 | |
| else | ( | EXPORTCSVCODE | ) |
| end | ( | INSTANTIATIONCODE | ) |
| else error | ( | 'Your technical computing program does not support file choosers.Please input the file name in the argument. ' | ) |
| end end if csv error | ( | 'Incorrect file format specified.Second argument must be ''mat''or ''csv''.' | ) |
| etime | ( | clock | , |
| startTime | |||
| ) |
| fgetl | ( | fid | ) |
| fprintf | ( | ) |
| if isempty | ( | structIn. | fieldNames{1} | ) |
| save | ( | matfile $ | SAVEOBJECTSCODE | ) |
| if nargin&& strcmp | ( | class(varargin{2}) | , |
| 'char' | |||
| ) |
| elseif nargin&& strcmp | ( | class(varargin{2}) | , |
| 'logical' | |||
| ) |
| Read third line if strcmp | ( | gitLogfileHash | , |
| uavoImporterHash | |||
| ) |
| end if strcmp | ( | uavoLogfileHash | , |
| UAVO_HASH | |||
| ) |
| Prune vectors | ( | CLEANUPCODE | ) |
| end end if ~strcmpi | ( | outputType | , |
| 'mat' | |||
| ) |
| end buffer =fread(fid,Inf,'uchar=>uchar') |
Definition at line 98 of file uavobjecttemplate.m.
| buffer_len = length(buffer) |
Definition at line 125 of file uavobjecttemplate.m.
| end bufferIdx =1 |
Definition at line 101 of file uavobjecttemplate.m.
Definition at line 22 of file uavobjecttemplate.m.
| correctMsgByte =hex2dec('20') |
Definition at line 103 of file uavobjecttemplate.m.
| correctSyncByte =hex2dec('3C') |
Definition at line 104 of file uavobjecttemplate.m.
| crc |
Definition at line 332 of file uavobjecttemplate.m.
| crc_table |
Definition at line 36 of file uavobjecttemplate.m.
Definition at line 323 of file uavobjecttemplate.m.
| csvDirName =[name '_csv'] |
Definition at line 324 of file uavobjecttemplate.m.
| Dummy outputs so the program doens t throw warnings about Directory already exists csvfile =fullfile(path, csvDirName , [name '.csv']) |
Definition at line 326 of file uavobjecttemplate.m.
| Arbitrary times two so that it is at least as long estTimeRemaining =(buffer_len-bufferIdx)/(bufferIdx/etime(clock,startTime)) * 2 |
Definition at line 255 of file uavobjecttemplate.m.
| while bufferIdx< (buffer_len - 20) %% Read message header % get sync field (0x3C, 1 byte) if ~overo sync = buffer(bufferIdx+12); else sync = buffer(bufferIdx); end if sync ~= correctSyncByte bufferIdx=bufferIdx+1; if ~overo || sync ~= 255 wrongSyncByte = wrongSyncByte + 1; end continue end if ~overo % For GCS logging the format is as follows % 4 bytes timestamp (milliseconds) % 8 bytes data size % UAVTalk packet (always without timestamped packets) % Sync val (0x3c) % Message type (1 byte) % Length (2 bytes) % Object ID (4 bytes) % Instance ID (optional, 2 bytes) % Data (variable length) % Checksum (1 byte) % Process header, if we are aligned datasizeBufferIdx = bufferIdx; %Just grab the index. We'll do a typecast later, if necessary datasizeLength = 4; msgType = buffer(bufferIdx+13); % get msg type (quint8 1 byte ) should be 0x20, ignore the rest? objID = typecast(buffer(bufferIdx+16:bufferIdx+ 16+4-1), 'uint32'); % get obj id (quint32 4 bytes) timestamp = double(typecast(buffer(bufferIdx:bufferIdx+4-1),'uint32')); % Advance buffer past header to where data is (or instance ID) bufferIdx=bufferIdx + 20; else % For Overo logging the format is % UAVTalk packet (with timestamped packet) % Sync val (0x3c) % Message type (1 byte, adds 0x80) % Length (2 bytes) % Object ID (4 bytes) % Instance ID (optional, 2 bytes) % Timestamp (2 bytes) % Data (variable length) % Checksum (1 byte) % Process header for overo datasizeBufferIdx = bufferIdx + 2; datasizeLength = 2; msgType = buffer(bufferIdx+1) - 128; objID = typecast(buffer(bufferIdx+4:bufferIdx+ 4+4-1), 'uint32'); singleInstance = multipleInstanceLookup(multipleInstanceLookup(:,1) == objID, 2); if singleInstance timestamp = double(typecast(buffer(bufferIdx+8:bufferIdx+10-1),'uint16')); else timestamp = double(typecast(buffer(bufferIdx+12:bufferIdx+14-1),'uint16')); end % Advance buffer past header to where data is. In the case of a % multiple instance object this will be where the timstamp is but % the parsing code will advance by two more. bufferIdx = bufferIdx + 10; end if timestamp < lastTimestamp timestampAccumulator = timestampAccumulator + timestampWraparound; end lastTimestamp = timestamp; timestamp = timestamp + timestampAccumulator; %Check that message type is correct if msgType ~= correctMsgByte wrongMessageByte = wrongMessageByte + 1; continue end if (isempty(objID)) %End of file break; end %% Read object try switch objID$(SWITCHCODE) otherwise unknownObjIDListIdx=find(unknownObjIDList(:,1)==objID, 1, 'first'); if isempty(unknownObjIDListIdx) unknownObjIDList=[unknownObjIDList; uint32(objID) 1]; %#ok<AGROW> else unknownObjIDList(unknownObjIDListIdx,2)=unknownObjIDList(unknownObjIDListIdx,2)+1; end datasize = typecast(buffer(datasizeBufferIdx + 4:datasizeBufferIdx + 12-1), 'uint64'); msgBytesLeft = datasize - 1 - 1 - 2 - 4; if msgBytesLeft > 255 msgBytesLeft = 0; end bufferIdx=bufferIdx+double(msgBytesLeft); end catch % One of the reads failed - indicates EOF break; end if (wrongSyncByte ~= lastWrongSyncByte || wrongMessageByte~=lastWrongMessageByte ) ||... bufferIdx - last_print > Every |
Definition at line 240 of file uavobjecttemplate.m.
| Parse log file |
Definition at line 107 of file uavobjecttemplate.m.
| function[] |
Definition at line 1 of file uavobjecttemplate.m.
| Read first line gitLogfileHash = fgetl(fid) |
Definition at line 84 of file uavobjecttemplate.m.
| h =floor(estTimeRemaining/3600) |
Definition at line 256 of file uavobjecttemplate.m.
| headerOut =sprintf('%s,',fieldNames{:}) |
Definition at line 309 of file uavobjecttemplate.m.
| idx =1 |
Definition at line 359 of file uavobjecttemplate.m.
| inFinish =inFinish' |
Definition at line 350 of file uavobjecttemplate.m.
| else instanceIdOffset = -2 |
Definition at line 115 of file uavobjecttemplate.m.
| Trim off last |
Definition at line 310 of file uavobjecttemplate.m.
| last_print = -1e10 |
Definition at line 110 of file uavobjecttemplate.m.
| lastTimestamp = 0 |
Definition at line 123 of file uavobjecttemplate.m.
| lastWrongMessageByte =0 |
Definition at line 26 of file uavobjecttemplate.m.
| while bufferIdx< (buffer_len-20)%%Read message header%get sync field(0x3C, 1 byte) if~overo sync=buffer(bufferIdx+12) else sync=buffer(bufferIdx) end if sync~=correctSyncByte bufferIdx=bufferIdx+1 if~overo||sync~=255 wrongSyncByte=wrongSyncByte+1 end continue end if~overo%For GCS logging the format is as follows%4 bytes timestamp(milliseconds)%8 bytes data size%UAVTalk packet(always without timestamped packets)%Sync val(0x3c)%Message type(1 byte)%Length(2 bytes)%Object ID(4 bytes)%Instance ID(optional, 2 bytes)%Data(variable length)%Checksum(1 byte)%Process header, if we are aligned datasizeBufferIdx=bufferIdx%Just grab the index.We'll do a typecast later, if necessary datasizeLength=4 msgType=buffer(bufferIdx+13)%get msg type(quint8 1 byte) should be 0x20, ignore the rest?objID=typecast(buffer(bufferIdx+16:bufferIdx+16+4-1), 'uint32')%get obj id(quint32 4 bytes) timestamp=double(typecast(buffer(bufferIdx:bufferIdx+4-1),'uint32'))%Advance buffer past header to where data is(or instance ID) bufferIdx=bufferIdx+20 else%For Overo logging the format is%UAVTalk packet(with timestamped packet)%Sync val(0x3c)%Message type(1 byte, adds 0x80)%Length(2 bytes)%Object ID(4 bytes)%Instance ID(optional, 2 bytes)%Timestamp(2 bytes)%Data(variable length)%Checksum(1 byte)%Process header for overo datasizeBufferIdx=bufferIdx+2 datasizeLength=2 msgType=buffer(bufferIdx+1)-128 objID=typecast(buffer(bufferIdx+4:bufferIdx+4+4-1), 'uint32') singleInstance=multipleInstanceLookup(multipleInstanceLookup(:, 1)==objID, 2) if singleInstance timestamp=double(typecast(buffer(bufferIdx+8:bufferIdx+10-1),'uint16')) else timestamp=double(typecast(buffer(bufferIdx+12:bufferIdx+14-1),'uint16')) end%Advance buffer past header to where data is.In the case of a%multiple instance object this will be where the timstamp is but%the parsing code will advance by two more.bufferIdx=bufferIdx+10 end if timestamp< lastTimestamp timestampAccumulator=timestampAccumulator+timestampWraparound end lastTimestamp=timestamp timestamp=timestamp+timestampAccumulator%Check that message type is correct if msgType~=correctMsgByte wrongMessageByte=wrongMessageByte+1 continue end if(isempty(objID))%End of file break end%%Read object try switch objID $(SWITCHCODE) otherwise unknownObjIDListIdx=find(unknownObjIDList(:, 1)==objID, 1, 'first') if isempty(unknownObjIDListIdx) unknownObjIDList=[unknownObjIDList uint32(objID) 1]%#ok< AGROW > else unknownObjIDList(unknownObjIDListIdx, 2)=unknownObjIDList(unknownObjIDListIdx, 2)+1 end datasize=typecast(buffer(datasizeBufferIdx+4:datasizeBufferIdx+12-1), 'uint64') msgBytesLeft=datasize-1-1-2-4 if msgBytesLeft > 255 msgBytesLeft=0 end bufferIdx=bufferIdx+double(msgBytesLeft) end catch%One of the reads failed-indicates EOF break end if(wrongSyncByte~=lastWrongSyncByte||wrongMessageByte~=lastWrongMessageByte)||...bufferIdx-last_print > bytes show the status update lastWrongSyncByte =0 |
Definition at line 25 of file uavobjecttemplate.m.
| logfile =fullfile(PathName, FileName) |
Definition at line 60 of file uavobjecttemplate.m.
| m =floor((estTimeRemaining-h*3600)/60) |
Definition at line 257 of file uavobjecttemplate.m.
| Prune mat[path, name] =fileparts(logfile) |
Definition at line 292 of file uavobjecttemplate.m.
| matfile = fullfile(path,[name '.mat']) |
Definition at line 293 of file uavobjecttemplate.m.
| matOut =zeros(max(size(structIn.(fieldNames{1}))), length(fieldNames)) |
Definition at line 313 of file uavobjecttemplate.m.
| multipleInstanceLookup = zeros(0,2) |
Definition at line 32 of file uavobjecttemplate.m.
| if nargin |
Definition at line 56 of file uavobjecttemplate.m.
Definition at line 267 of file uavobjecttemplate.m.
Definition at line 355 of file uavobjecttemplate.m.
| out |
Definition at line 339 of file uavobjecttemplate.m.
| outputType ='mat' |
Definition at line 21 of file uavobjecttemplate.m.
| overo = false |
Definition at line 33 of file uavobjecttemplate.m.
| Parse log entry by entry prebuf = buffer(1:12) |
Definition at line 108 of file uavobjecttemplate.m.
Definition at line 339 of file uavobjecttemplate.m.
| s =ceil(estTimeRemaining-h*3600-m*60) |
Definition at line 258 of file uavobjecttemplate.m.
| startTime =clock |
Definition at line 112 of file uavobjecttemplate.m.
| str1 =[] |
Definition at line 27 of file uavobjecttemplate.m.
| end str2 =[] |
Definition at line 28 of file uavobjecttemplate.m.
| str3 =[] |
Definition at line 29 of file uavobjecttemplate.m.
| str4 =[] |
Definition at line 30 of file uavobjecttemplate.m.
| str5 =[] |
Definition at line 31 of file uavobjecttemplate.m.
| end timestampAccumulator = 0 |
Definition at line 122 of file uavobjecttemplate.m.
| timestampWraparound = 2^16 |
Definition at line 116 of file uavobjecttemplate.m.
| UAVO_HASH = '${UAVOSHA1TXT}' |
Definition at line 19 of file uavobjecttemplate.m.
| Read second line uavoLogfileHash = fgetl(fid) |
Definition at line 85 of file uavobjecttemplate.m.
| end function found on Matlab s file exchange The two functions return identical although his is much faster Unfortunately |
Definition at line 339 of file uavobjecttemplate.m.
| unknownObjIDList =zeros(1,2) |
Definition at line 105 of file uavobjecttemplate.m.
| wrongMessageByte =0 |
Definition at line 24 of file uavobjecttemplate.m.
| wrongSyncByte =0 |
Definition at line 23 of file uavobjecttemplate.m.