MCPcopy Create free account
hub / github.com/collin80/SavvyCAN / loadCANHackerFile

Method loadCANHackerFile

framefileio.cpp:729–794  ·  view source on GitHub ↗

CANHacker trace format Time ID DLC Data Comment 00.000 00004000 8 36 47 19 43 01 00 00 80

Source from the content-addressed store, hash-verified

727// Time ID DLC Data Comment
728// 00.000 00004000 8 36 47 19 43 01 00 00 80
729bool FrameFileIO::loadCANHackerFile(QString filename, QVector<CANFrame>* frames)
730{
731 QFile *inFile = new QFile(filename);
732 CANFrame thisFrame;
733 QByteArray line;
734 int lineCounter = 0;
735 bool foundErrors = false;
736
737 if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
738 {
739 delete inFile;
740 return false;
741 }
742
743 line = inFile->readLine().toUpper(); //read out the header first and discard it.
744
745 while (!inFile->atEnd()) {
746 lineCounter++;
747 if (lineCounter > 100)
748 {
749 qApp->processEvents();
750 lineCounter = 0;
751 }
752 line = inFile->readLine().simplified();
753 if (line.length() > 2)
754 {
755 QList<QByteArray> tokens = line.split(' ');
756 int multiplier;
757 if (tokens.length() > 3)
758 {
759 int idxOfDecimal = tokens[0].indexOf('.');
760 if (idxOfDecimal > -1) {
761 //int decimalPlaces = tokens[0].length() - tokens[0].indexOf('.') - 1;
762 //the result of the above is the # of digits after the decimal.
763 //This program deals in microsecond so turn the value into microseconds
764 multiplier = 1000000; //turn the decimal into full microseconds
765 }
766 else
767 {
768 multiplier = 1; //special case. Assume no decimal means microseconds
769 }
770 //qDebug() << "decimal places " << decimalPlaces;
771 thisFrame.timestamp = (int64_t)(tokens[0].toDouble() * multiplier);
772 thisFrame.ID = tokens[1].toInt(nullptr, 16);
773 thisFrame.extended = (thisFrame.ID > 0x7FF);
774 thisFrame.isReceived = true;
775 thisFrame.remote = false;
776 thisFrame.bus = 0;
777 thisFrame.len = tokens[2].toInt(nullptr, 16);
778 for (unsigned int d = 0; d < thisFrame.len; d++)
779 {
780 if (tokens[d + 3] != "")
781 {
782 thisFrame.data[d] = tokens[d + 3].toInt(nullptr, 16);
783 }
784 else thisFrame.data[d] = 0;
785 }
786 frames->append(thisFrame);

Callers

nothing calls this directly

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected