Added debugging lines to BLF Handler, fixed a glitch in loading (well, kludged it)

This commit is contained in:
Collin Kidder
2018-05-20 19:52:27 -04:00
parent 31618e87d1
commit fb73cc1ffa
2 changed files with 40 additions and 13 deletions
+31 -4
View File
@@ -9,7 +9,6 @@ BLFHandler::BLFHandler()
}
/*
Written while peeking at source code here:
https://python-can.readthedocs.io/en/latest/_modules/can/io/blf.html
@@ -36,28 +35,44 @@ bool BLFHandler::loadBLF(QString filename, QVector<CANFrame>* frames)
inFile->read((char *)&header, sizeof(header));
if (qFromLittleEndian(header.sig) == 0x47474F4C)
{
qDebug() << "Proper BLF file header token";
}
else return false;
while (!inFile->atEnd())
{
qDebug() << "Position within file: " << inFile->pos();
inFile->read((char *)&objHeader, sizeof(objHeader));
if (qFromLittleEndian(objHeader.sig) == 0x4A424F4C)
{
int readSize = objHeader.objSize - sizeof(BLF_OBJ_HEADER);
qDebug() << "Proper object header token. Read Size: " << readSize;
fileData = inFile->read(readSize);
junk = inFile->read(readSize % 4); //file is padded so sizes must always end up on even multiple of 4
//qDebug() << "Fudge bytes in readSize: " << (readSize % 4);
if (objHeader.objType == BLF_CONTAINER)
{
qDebug() << "Object is a container. Uncompressing it";
fileData.prepend(objHeader.uncompSize & 0xFF);
fileData.prepend((objHeader.uncompSize >> 8) & 0xFF);
fileData.prepend((objHeader.uncompSize >> 16) & 0xFF);
fileData.prepend((objHeader.uncompSize >> 24) & 0xFF);
uncompressedData += qUncompress(fileData);
qDebug() << "Uncompressed size: " << uncompressedData.count();
pos = 0;
while (pos + sizeof(BLF_OBJ_HEADER) < uncompressedData.count())
bool foundHeader = false;
//first skip forward to find a header signature - usually not necessary
while ( (int)(pos + sizeof(BLF_OBJ_HEADER)) < uncompressedData.count())
{
memcpy(&obj.header, uncompressedData.mid(pos, sizeof(BLF_OBJ_HEADER)).constData(), sizeof(BLF_OBJ_HEADER));
int32_t *headerSig = (int32_t *)(uncompressedData.constData() + pos);
if (*headerSig == 0x4A424F4C) break;
pos += 4;
}
//then process all the objects
while ( (int)(pos + sizeof(BLF_OBJ_HEADER)) < uncompressedData.count())
{
memcpy(&obj.header, (uncompressedData.constData() + pos), sizeof(BLF_OBJ_HEADER));
qDebug() << "Pos: " << pos << " Type: " << obj.header.objType << "Obj Size: " << obj.header.objSize;
if (qFromLittleEndian(objHeader.sig) == 0x4A424F4C)
{
fileData = uncompressedData.mid(pos + sizeof(BLF_OBJ_HEADER), obj.header.objSize - sizeof(BLF_OBJ_HEADER));
@@ -70,14 +85,26 @@ bool BLFHandler::loadBLF(QString filename, QVector<CANFrame>* frames)
frame.ID = canObject.id & 0x1FFFFFFFull;
frame.isReceived = true;
frame.len = canObject.dlc;
frame.timestamp = obj.header.uncompSize / 1000000.0; //uncompsize field also used for timestamp oddly enough
frame.timestamp = obj.header.uncompSize / 100000.0; //uncompsize field also used for timestamp oddly enough
for (int i = 0; i < 8; i++) frame.data[i] = canObject.data[i];
frames->append(frame);
}
else
{
//qDebug() << "Not a can frame! ObjType: " << obj.header.objType;
if (obj.header.objType > 0xFFFF)
return false;
}
pos += obj.header.objSize + (obj.header.objSize % 4);
}
else
{
qDebug() << "Unexpected object header signature, aborting";
return false;
}
}
uncompressedData.remove(0, pos);
qDebug() << "After removing used data uncompressedData is now this big: " << uncompressedData.count();
}
}
else return false;
+9 -9
View File
@@ -37,15 +37,15 @@ struct BLF_FILE_HEADER
struct BLF_OBJ_HEADER
{
uint32_t sig;
uint16_t headerSize;
uint16_t headerVersion;
uint32_t objSize;
uint32_t objType;
uint32_t flags;
uint16_t nothing;
uint16_t objVer;
uint64_t uncompSize;
uint32_t sig; //0 offset from start
uint16_t headerSize; //4
uint16_t headerVersion; //6
uint32_t objSize; //8
uint32_t objType; //12
uint32_t flags; //16
uint16_t nothing; //20
uint16_t objVer; //22
uint64_t uncompSize; //24
}; //32 bytes
struct BLF_OBJECT