1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-10 18:24:11 +01:00

Merge branch 'next' into amorale/OP-1294_fix_stacks_heap_cc

This commit is contained in:
Alessio Morale 2014-04-07 23:37:40 +02:00
commit 21bec9ade8
3 changed files with 49 additions and 36 deletions

View File

@ -723,7 +723,7 @@ $(OPFW_RESOURCE): $(FW_TARGETS)
# If opfw_resource or all firmware are requested, GCS should depend on the resource # If opfw_resource or all firmware are requested, GCS should depend on the resource
ifneq ($(strip $(filter opfw_resource all all_fw all_flight,$(MAKECMDGOALS))),) ifneq ($(strip $(filter opfw_resource all all_fw all_flight,$(MAKECMDGOALS))),)
$(eval openpilotgcs: $(OPFW_RESOURCE)) $(eval openpilotgcs_qmake: $(OPFW_RESOURCE))
endif endif
# Packaging targets: package, clean_package # Packaging targets: package, clean_package

View File

@ -59,59 +59,78 @@ $(INSTANTIATIONCODE)
fid = fopen(logfile); fid = fopen(logfile);
buffer=fread(fid,Inf,'uchar=>uchar'); buffer=fread(fid,Inf,'uchar=>uint8');
fseek(fid, 0, 'bof'); fseek(fid, 0, 'bof');
bufferlen = size(buffer);
bufferIdx=1;
correctMsgByte=hex2dec('20'); correctMsgByte=hex2dec('20');
correctTimestampedByte=hex2dec('A0'); correctTimestampedByte=hex2dec('A0');
correctSyncByte=hex2dec('3C'); correctSyncByte=hex2dec('3C');
unknownObjIDList=zeros(1,2); unknownObjIDList=zeros(1,2);
headerLen = 1 + 1 + 2 + 4 + 2; % sync type len id inst
% Parse log file, entry by entry timestampLen = 4;
% prebuf = buffer(1:12); crcLen = 1;
oplHeaderLen = 8 + 4;
last_print = -1e10; last_print = -1e10;
bufferIdx=1;
headerIdx=oplHeaderLen + 1;
startTime=clock; startTime=clock;
while (1) while (1)
if (feof(fid)); break; end
try try
%% Read message header %% Read message header
% get sync field (0x3C, 1 byte) % get sync field (0x3C, 1 byte)
sync = fread(fid, 1, 'uint8'); if (bufferlen < headerIdx + 12); break; end
sync = buffer(headerIdx);
% printf('%x ', sync);
headerIdx += 1;
if sync ~= correctSyncByte if sync ~= correctSyncByte
prebuf = [prebuf(2:end); sync];
wrongSyncByte = wrongSyncByte + 1; wrongSyncByte = wrongSyncByte + 1;
continue continue
end end
% get msg type (quint8 1 byte ) should be 0x20, ignore the rest? % printf('\n %u:',headerIdx - 1);
msgType = fread(fid, 1, 'uint8'); % get the opl timestamp and datablock size
if msgType ~= correctMsgByte && msgType ~= hex2dec('A0') oplTimestamp = typecast(uint8(buffer(headerIdx - 1 - 8 - 4:headerIdx - 1 - 8 - 1)), 'uint32');
wrongMessageByte = wrongMessageByte + 1; oplSize = typecast(uint8(buffer(headerIdx - 1 - 8:headerIdx - 1 - 1)), 'uint64');
% get msg type (quint8 1 byte ) should be 0x20/0xA0, ignore the rest
msgType = buffer(headerIdx);
headerIdx += 1;
if msgType ~= correctMsgByte && msgType ~= correctTimestampedByte
% fixme: it should read the whole message payload instead of skipping and blindly searching for next sync byte.
fprintf('\nSkipping message type: %x \n', msgType);
continue continue
end end
% get msg size (quint16 2 bytes) excludes crc, include msg header and data payload % get msg size (quint16 2 bytes) excludes crc, include msg header and data payload
msgSize = fread(fid, 1, 'uint16'); msgSize = uint32(typecast(buffer(headerIdx:headerIdx + 1), 'uint16'));
headerIdx += 2;
% get obj id (quint32 4 bytes) % get obj id (quint32 4 bytes)
objID = fread(fid, 1, 'uint32'); objID = typecast(uint8(buffer(headerIdx:headerIdx + 3)), 'uint32');
headerIdx += 4;
% get instance id (quint16 2 bytes)
instID = typecast(uint8(buffer(headerIdx:headerIdx + 1)), 'uint16');
% printf('Id %x type %x size %u Inst %x ', objID, msgType, msgSize, instID);
headerIdx += 2;
% get timestamp if needed (quint32 4 bytes)
if msgType == correctMsgByte if msgType == correctMsgByte
%% Process header if we are aligned datasize = msgSize - headerLen;
timestamp = typecast(uint8(prebuf(1:4)), 'uint32');
datasize = typecast(uint8(prebuf(5:12)), 'uint64');
elseif msgType == correctTimestampedByte elseif msgType == correctTimestampedByte
timestamp = fread(fid,1,'uint16'); timestamp = typecast(uint8(buffer(headerIdx:headerIdx + 3)), 'uint32');
end % printf('ts %u');
headerIdx += 4;
if (isempty(objID)) %End of file datasize = msgSize - headerLen - timestampLen;
break;
end end
% printf('\n');
bufferIdx = headerIdx;
headerIdx += datasize + crcLen + oplHeaderLen;
%% Read object %% Read object
@ -125,9 +144,7 @@ $(SWITCHCODE)
unknownObjIDList(unknownObjIDListIdx,2)=unknownObjIDList(unknownObjIDListIdx,2)+1; unknownObjIDList(unknownObjIDListIdx,2)=unknownObjIDList(unknownObjIDListIdx,2)+1;
end end
datasize = typecast(buffer(datasizeBufferIdx + 4:datasizeBufferIdx + 12-1), 'uint64'); msgBytesLeft = msgSize - 1 - 1 - 2 - 4;
msgBytesLeft = datasize - 1 - 1 - 2 - 4;
if msgBytesLeft > 255 if msgBytesLeft > 255
msgBytesLeft = 0; msgBytesLeft = 0;
end end

View File

@ -122,9 +122,6 @@ bool UAVObjectGeneratorMatlab::process_object(ObjectInfo *info, int numBytes)
matlabSwitchCode.append("\t\t\t" + tableIdxName + " = " + tableIdxName + " + 1;\n"); matlabSwitchCode.append("\t\t\t" + tableIdxName + " = " + tableIdxName + " + 1;\n");
matlabSwitchCode.append("\t\t\t" + objectTableName + "FidIdx(" + tableIdxName + ") = bufferIdx; %#ok<*AGROW>\n"); matlabSwitchCode.append("\t\t\t" + objectTableName + "FidIdx(" + tableIdxName + ") = bufferIdx; %#ok<*AGROW>\n");
matlabSwitchCode.append("\t\t\tbufferIdx=bufferIdx + " + objectTableName.toUpper() + "_NUMBYTES+1; %+1 is for CRC\n"); matlabSwitchCode.append("\t\t\tbufferIdx=bufferIdx + " + objectTableName.toUpper() + "_NUMBYTES+1; %+1 is for CRC\n");
if (!info->isSingleInst) {
matlabSwitchCode.append("\t\t\tbufferIdx = bufferIdx + 2; %An extra two bytes for the instance ID\n");
}
matlabSwitchCode.append("\t\t\tif " + tableIdxName + " >= length(" + objectTableName + "FidIdx) %Check to see if pre-allocated memory is exhausted\n"); matlabSwitchCode.append("\t\t\tif " + tableIdxName + " >= length(" + objectTableName + "FidIdx) %Check to see if pre-allocated memory is exhausted\n");
matlabSwitchCode.append("\t\t\t\t" + objectTableName + "FidIdx(" + tableIdxName + "*2) = 0;\n"); matlabSwitchCode.append("\t\t\t\t" + objectTableName + "FidIdx(" + tableIdxName + "*2) = 0;\n");
matlabSwitchCode.append("\t\t\tend\n"); matlabSwitchCode.append("\t\t\tend\n");
@ -145,16 +142,15 @@ bool UAVObjectGeneratorMatlab::process_object(ObjectInfo *info, int numBytes)
// Add timestamp // Add timestamp
allocationFields.append("\t" + objectName + ".timestamp = " + allocationFields.append("\t" + objectName + ".timestamp = " +
"double(typecast(buffer(mcolon(" + objectName + "FidIdx " "double(typecast(buffer(mcolon(" + objectName + "FidIdx "
"- 20, " + objectName + "FidIdx + 4-1 -20)), 'uint32'))';\n"); "- headerLen - oplHeaderLen, " + objectName + "FidIdx + 3 - headerLen - oplHeaderLen)), 'uint32'))';\n");
int currentIdx = 0; int currentIdx = 0;
// Add Instance ID, if necessary // Add Instance ID, if necessary
if (!info->isSingleInst) { if (!info->isSingleInst) {
allocationFields.append("\t" + objectName + ".instanceID = " + allocationFields.append("\t" + objectName + ".instanceID = " +
"double(typecast(buffer(mcolon(" + objectName + "FidIdx " "double(typecast(buffer(mcolon(" + objectName + "FidIdx - 2"
", " + objectName + "FidIdx + 2-1)), 'uint16'))';\n"); ", " + objectName + "FidIdx - 2 + 1)), 'uint16'))';\n");
currentIdx += 2;
} }
for (int n = 0; n < info->fields.length(); ++n) { for (int n = 0; n < info->fields.length(); ++n) {