mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
Patch from Kenn for the matlab processing function to fix issue with multiple
isntance objects
This commit is contained in:
parent
813ac65159
commit
6fd2426a90
@ -1,58 +1,65 @@
|
|||||||
function [] = OPLogConvert()
|
function [] = OPLogConvert()
|
||||||
%% Define indices and arrays of structures to hold data
|
%% Define indices and arrays of structures to hold data
|
||||||
|
% THIS FILE IS AUTOMATICALLY GENERATED.
|
||||||
$(ALLOCATIONCODE)
|
$(ALLOCATIONCODE)
|
||||||
|
|
||||||
%% Open file
|
%% Open log file
|
||||||
%fid = fopen('log.opl');
|
% [FileName,PathName,FilterIndex] = uigetfile('*.opl');
|
||||||
[FileName,PathName,FilterIndex] = uigetfile('*.opl');
|
|
||||||
logfile = strcat(PathName,FileName);
|
FileName='OP-2011-10-22_22-27-09.opl';
|
||||||
fid = fopen(logfile);
|
PathName='/Users/kenz/Movies/brisk_videos/rover_test_1/';
|
||||||
|
FilterIndex=1;
|
||||||
while (1)
|
|
||||||
%% Read logging header
|
|
||||||
timestamp = fread(fid, 1, 'uint32');
|
logfile = fullfile(PathName,FileName);
|
||||||
if (feof(fid)); break; end
|
fid = fopen(logfile);
|
||||||
datasize = fread(fid, 1, 'int64');
|
|
||||||
|
% Parse log file, entry by entry
|
||||||
|
while (1)
|
||||||
%% Read message header
|
%% Read logging header
|
||||||
% get sync field (0x3C, 1 byte)
|
timestamp = fread(fid, 1, 'uint32');
|
||||||
sync = fread(fid, 1, 'uint8');
|
if (feof(fid)); break; end
|
||||||
if sync ~= hex2dec('3C')
|
datasize = fread(fid, 1, 'int64');
|
||||||
disp ('Wrong sync byte');
|
|
||||||
return
|
|
||||||
end
|
%% Read message header
|
||||||
% get msg type (quint8 1 byte ) should be 0x20, ignore the rest?
|
% get sync field (0x3C, 1 byte)
|
||||||
msgType = fread(fid, 1, 'uint8');
|
sync = fread(fid, 1, 'uint8');
|
||||||
if msgType ~= hex2dec('20')
|
if sync ~= hex2dec('3C')
|
||||||
disp ('Wrong msgType');
|
disp ('Wrong sync byte');
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
% get msg size (quint16 2 bytes) excludes crc, include msg header and data payload
|
% get msg type (quint8 1 byte ) should be 0x20, ignore the rest?
|
||||||
msgSize = fread(fid, 1, 'uint16');
|
msgType = fread(fid, 1, 'uint8');
|
||||||
% get obj id (quint32 4 bytes)
|
if msgType ~= hex2dec('20')
|
||||||
objID = fread(fid, 1, 'uint32');
|
disp ('Wrong msgType');
|
||||||
|
return
|
||||||
|
end
|
||||||
%% Read object
|
% get msg size (quint16 2 bytes) excludes crc, include msg header and data payload
|
||||||
switch objID
|
msgSize = fread(fid, 1, 'uint16');
|
||||||
$(SWITCHCODE)
|
% get obj id (quint32 4 bytes)
|
||||||
otherwise
|
objID = fread(fid, 1, 'uint32');
|
||||||
disp('Unknown object ID');
|
|
||||||
msgBytesLeft = datasize - 1 - 1 - 2 - 4;
|
|
||||||
fread(fid, msgBytesLeft, 'uint8');
|
%% Read object
|
||||||
end
|
switch objID
|
||||||
|
$(SWITCHCODE)
|
||||||
end
|
otherwise
|
||||||
|
disp(['Unknown object ID: 0x' dec2hex(objID)]);
|
||||||
%% Clean Up and Save mat file
|
msgBytesLeft = datasize - 1 - 1 - 2 - 4;
|
||||||
fclose(fid);
|
fread(fid, msgBytesLeft, 'uint8');
|
||||||
|
end
|
||||||
matfile = strrep(logfile,'opl','mat');
|
|
||||||
save(matfile $(SAVEOBJECTSCODE));
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
%% Clean Up and Save mat file
|
||||||
|
fclose(fid);
|
||||||
|
|
||||||
|
matfile = strrep(logfile,'opl','mat');
|
||||||
|
save(matfile $(SAVEOBJECTSCODE));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%% Object reading functions
|
%% Object reading functions
|
||||||
$(FUNCTIONSCODE)
|
$(FUNCTIONSCODE)
|
||||||
|
@ -50,7 +50,7 @@ bool UAVObjectGeneratorMatlab::generate(UAVObjectParser* parser,QString template
|
|||||||
}
|
}
|
||||||
|
|
||||||
matlabCodeTemplate.replace( QString("$(ALLOCATIONCODE)"), matlabAllocationCode);
|
matlabCodeTemplate.replace( QString("$(ALLOCATIONCODE)"), matlabAllocationCode);
|
||||||
matlabCodeTemplate.replace( QString("$(SWITCHCODE)"), matlabSwithCode);
|
matlabCodeTemplate.replace( QString("$(SWITCHCODE)"), matlabSwitchCode);
|
||||||
matlabCodeTemplate.replace( QString("$(SAVEOBJECTSCODE)"), matlabSaveObjectsCode);
|
matlabCodeTemplate.replace( QString("$(SAVEOBJECTSCODE)"), matlabSaveObjectsCode);
|
||||||
matlabCodeTemplate.replace( QString("$(FUNCTIONSCODE)"), matlabFunctionsCode);
|
matlabCodeTemplate.replace( QString("$(FUNCTIONSCODE)"), matlabFunctionsCode);
|
||||||
|
|
||||||
@ -71,6 +71,7 @@ bool UAVObjectGeneratorMatlab::process_object(ObjectInfo* info)
|
|||||||
if (info == NULL)
|
if (info == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
//Declare variables
|
||||||
QString objectName(info->name);
|
QString objectName(info->name);
|
||||||
// QString objectTableName(objectName + "Objects");
|
// QString objectTableName(objectName + "Objects");
|
||||||
QString objectTableName(objectName);
|
QString objectTableName(objectName);
|
||||||
@ -80,39 +81,71 @@ bool UAVObjectGeneratorMatlab::process_object(ObjectInfo* info)
|
|||||||
QString objectID(QString().setNum(info->id));
|
QString objectID(QString().setNum(info->id));
|
||||||
QString isSingleInst = boolTo01String( info->isSingleInst );
|
QString isSingleInst = boolTo01String( info->isSingleInst );
|
||||||
|
|
||||||
// Generate allocation code (will replace the $(ALLOCATIONCODE) tag)
|
|
||||||
matlabAllocationCode.append("\n " + tableIdxName + " = 1;\n");
|
//===================================================================//
|
||||||
matlabAllocationCode.append(" " + objectTableName + ".timestamp = 0;\n");
|
// Generate allocation code (will replace the $(ALLOCATIONCODE) tag) //
|
||||||
QString type;
|
//===================================================================//
|
||||||
QString allocfields;
|
// matlabSwitchCode.append("\t\tcase " + objectID + "\n");
|
||||||
for (int n = 0; n < info->fields.length(); ++n) {
|
matlabAllocationCode.append("\n\t" + tableIdxName + " = 1;\n");
|
||||||
// Determine type
|
QString type;
|
||||||
type = fieldTypeStrMatlab[info->fields[n]->type];
|
QString allocfields;
|
||||||
// Append field
|
if (0){
|
||||||
if ( info->fields[n]->numElements > 1 )
|
matlabAllocationCode.append("\t" + objectTableName + ".timestamp = 0;\n");
|
||||||
allocfields.append(" " + objectTableName + "(1)." + info->fields[n]->name + " = zeros(1," + QString::number(info->fields[n]->numElements, 10) + ");\n");
|
for (int n = 0; n < info->fields.length(); ++n) {
|
||||||
else
|
// Determine type
|
||||||
allocfields.append(" " + objectTableName + "(1)." + info->fields[n]->name + " = 0;\n");
|
type = fieldTypeStrMatlab[info->fields[n]->type];
|
||||||
}
|
// Append field
|
||||||
|
if ( info->fields[n]->numElements > 1 )
|
||||||
|
allocfields.append("\t" + objectTableName + "(1)." + info->fields[n]->name + " = zeros(1," + QString::number(info->fields[n]->numElements, 10) + ");\n");
|
||||||
|
else
|
||||||
|
allocfields.append("\t" + objectTableName + "(1)." + info->fields[n]->name + " = 0;\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
matlabAllocationCode.append("\t" + objectTableName + "=struct('timestamp', 0");
|
||||||
|
for (int n = 0; n < info->fields.length(); ++n) {
|
||||||
|
// Determine type
|
||||||
|
type = fieldTypeStrMatlab[info->fields[n]->type];
|
||||||
|
// Append field
|
||||||
|
if ( info->fields[n]->numElements > 1 )
|
||||||
|
allocfields.append(",...\n\t\t '" + info->fields[n]->name + "', zeros(1," + QString::number(info->fields[n]->numElements, 10) + ")");
|
||||||
|
else
|
||||||
|
allocfields.append(",...\n\t\t '" + info->fields[n]->name + "', 0");
|
||||||
|
}
|
||||||
|
allocfields.append(");\n");
|
||||||
|
}
|
||||||
matlabAllocationCode.append(allocfields);
|
matlabAllocationCode.append(allocfields);
|
||||||
|
matlabAllocationCode.append("\t" + objectTableName.toUpper() + "_OBJID=" + objectID + ";\n");
|
||||||
|
|
||||||
// Generate 'swith:' code (will replace the $(SWITCHCODE) tag)
|
|
||||||
matlabSwithCode.append(" case " + objectID + "\n");
|
|
||||||
matlabSwithCode.append(" " + objectTableName + "(" + tableIdxName +") = " + functionCall + ";\n");
|
|
||||||
matlabSwithCode.append(" " + tableIdxName + " = " + tableIdxName +" + 1;\n");
|
|
||||||
|
|
||||||
// Generate objects saving code code (will replace the $(SAVEOBJECTSCODE) tag)
|
//=============================================================//
|
||||||
|
// Generate 'Switch:' code (will replace the $(SWITCHCODE) tag) //
|
||||||
|
//=============================================================//
|
||||||
|
matlabSwitchCode.append("\t\tcase " + objectTableName.toUpper() + "_OBJID\n");
|
||||||
|
matlabSwitchCode.append("\t\t\t" + objectTableName + "(" + tableIdxName +") = " + functionCall + ";\n");
|
||||||
|
matlabSwitchCode.append("\t\t\t" + tableIdxName + " = " + tableIdxName +" + 1;\n");
|
||||||
|
|
||||||
|
|
||||||
|
//=============================================================================//
|
||||||
|
// Generate objects saving code code (will replace the $(SAVEOBJECTSCODE) tag) //
|
||||||
|
//=============================================================================//
|
||||||
matlabSaveObjectsCode.append(",'"+objectTableName+"'");
|
matlabSaveObjectsCode.append(",'"+objectTableName+"'");
|
||||||
|
|
||||||
// Generate functions code (will replace the $(FUNCTIONSCODE) tag)
|
matlabFunctionsCode.append("%%\n% " + objectName + " read function\n");
|
||||||
|
|
||||||
|
|
||||||
|
//=================================================================//
|
||||||
|
// Generate functions code (will replace the $(FUNCTIONSCODE) tag) //
|
||||||
|
//=================================================================//
|
||||||
|
//Generate function description comment
|
||||||
matlabFunctionsCode.append("function [" + objectName + "] = " + functionCall + "\n");
|
matlabFunctionsCode.append("function [" + objectName + "] = " + functionCall + "\n");
|
||||||
matlabFunctionsCode.append(" if " + isSingleInst + "\n");
|
matlabFunctionsCode.append("\tif " + isSingleInst + "\n");
|
||||||
matlabFunctionsCode.append(" headerSize = 8;\n");
|
matlabFunctionsCode.append("\t\theaderSize = 8;\n");
|
||||||
matlabFunctionsCode.append(" else\n");
|
matlabFunctionsCode.append("\telse\n");
|
||||||
matlabFunctionsCode.append(" " + objectName + ".instanceID = fread(fid, 1, 'uint16');\n");
|
matlabFunctionsCode.append("\t\t" + objectName + ".instanceID = fread(fid, 1, 'uint16');\n");
|
||||||
matlabFunctionsCode.append(" headerSize = 10;\n");
|
matlabFunctionsCode.append("\t\theaderSize = 10;\n");
|
||||||
matlabFunctionsCode.append(" end\n\n");
|
matlabFunctionsCode.append("\tend\n\n");
|
||||||
matlabFunctionsCode.append(" " + objectName + ".timestamp = timestamp;\n");
|
matlabFunctionsCode.append("\t" + objectName + ".timestamp = timestamp;\n");
|
||||||
|
|
||||||
// Generate functions code, actual fields of the object
|
// Generate functions code, actual fields of the object
|
||||||
QString funcfields;
|
QString funcfields;
|
||||||
@ -122,16 +155,16 @@ bool UAVObjectGeneratorMatlab::process_object(ObjectInfo* info)
|
|||||||
type = fieldTypeStrMatlab[info->fields[n]->type];
|
type = fieldTypeStrMatlab[info->fields[n]->type];
|
||||||
// Append field
|
// Append field
|
||||||
if ( info->fields[n]->numElements > 1 )
|
if ( info->fields[n]->numElements > 1 )
|
||||||
funcfields.append(" " + objectName + "." + info->fields[n]->name + " = double(fread(fid, " + QString::number(info->fields[n]->numElements, 10) + ", '" + type + "'));\n");
|
funcfields.append("\t" + objectName + "." + info->fields[n]->name + " = double(fread(fid, " + QString::number(info->fields[n]->numElements, 10) + ", '" + type + "'));\n");
|
||||||
else
|
else
|
||||||
funcfields.append(" " + objectName + "." + info->fields[n]->name + " = double(fread(fid, 1, '" + type + "'));\n");
|
funcfields.append("\t" + objectName + "." + info->fields[n]->name + " = double(fread(fid, 1, '" + type + "'));\n");
|
||||||
}
|
}
|
||||||
matlabFunctionsCode.append(funcfields);
|
matlabFunctionsCode.append(funcfields);
|
||||||
|
|
||||||
matlabFunctionsCode.append(" % read CRC\n");
|
matlabFunctionsCode.append("\t% read CRC\n");
|
||||||
matlabFunctionsCode.append(" fread(fid, 1, 'uint8');\n");
|
matlabFunctionsCode.append("\tfread(fid, 1, 'uint8');\n");
|
||||||
|
|
||||||
matlabFunctionsCode.append("end\n\n");
|
matlabFunctionsCode.append("\n\n");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
bool process_object(ObjectInfo* info);
|
bool process_object(ObjectInfo* info);
|
||||||
QString matlabAllocationCode;
|
QString matlabAllocationCode;
|
||||||
QString matlabSwithCode;
|
QString matlabSwitchCode;
|
||||||
QString matlabSaveObjectsCode;
|
QString matlabSaveObjectsCode;
|
||||||
QString matlabFunctionsCode;
|
QString matlabFunctionsCode;
|
||||||
QStringList fieldTypeStrMatlab;
|
QStringList fieldTypeStrMatlab;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user