diff --git a/can_structs.h b/can_structs.h index b45034e..d9fa1c5 100644 --- a/can_structs.h +++ b/can_structs.h @@ -11,7 +11,7 @@ public: int bus; bool extended; bool isReceived; //did we receive this or send it? - int len; + uint32_t len; unsigned char data[8]; uint64_t timestamp; }; diff --git a/canframemodel.cpp b/canframemodel.cpp index 02fc0cf..f1a3b64 100644 --- a/canframemodel.cpp +++ b/canframemodel.cpp @@ -207,7 +207,7 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const return QString::number(thisFrame.len); break; case 6: //data - for (int i = 0; i < thisFrame.len; i++) + for (unsigned int i = 0; i < thisFrame.len; i++) { tempString.append(Utility::formatNumber(thisFrame.data[i])); tempString.append(" "); diff --git a/filecomparatorwindow.cpp b/filecomparatorwindow.cpp index 83f120e..c7aeea2 100644 --- a/filecomparatorwindow.cpp +++ b/filecomparatorwindow.cpp @@ -112,7 +112,7 @@ void FileComparatorWindow::calculateDetails() CANFrame frame = interestedFrames.at(x); if (interestedIDs.contains(frame.ID)) //if we saw this ID before then add to the QList in there { - for (int y = 0; y < frame.len; y++) + for (unsigned int y = 0; y < frame.len; y++) { interestedIDs[frame.ID].values[y][frame.data[y]]++; tmp = frame.data[y]; @@ -137,7 +137,7 @@ void FileComparatorWindow::calculateDetails() } } //memset(newData->values, 0, 256 * 8); - for (int y = 0; y < frame.len; y++) + for (unsigned int y = 0; y < frame.len; y++) { newData->values[y][frame.data[y]] = 1; tmp = frame.data[y]; @@ -177,7 +177,7 @@ void FileComparatorWindow::calculateDetails() } } //memset(newData->values, 0, 256 * 8); - for (int y = 0; y < frame.len; y++) + for (unsigned int y = 0; y < frame.len; y++) { newData->values[y][frame.data[y]] = 1; tmp = frame.data[y]; diff --git a/framefileio.cpp b/framefileio.cpp index 2e96149..94c612d 100644 --- a/framefileio.cpp +++ b/framefileio.cpp @@ -322,7 +322,7 @@ bool FrameFileIO::loadCRTDFile(QString filename, QVector* frames) else thisFrame.isReceived = true; thisFrame.bus = 0; thisFrame.len = tokens.length() - 3; - for (int d = 0; d < thisFrame.len; d++) + for (unsigned int d = 0; d < thisFrame.len; d++) { if (tokens[d + 3] != "") { @@ -379,7 +379,7 @@ bool FrameFileIO::saveCRTDFile(QString filename, const QVector* frames outFile->write(QString::number(frames->at(c).ID, 16).toUpper().rightJustified(8, '0').toUtf8()); outFile->putChar(' '); - for (int temp = 0; temp < frames->at(c).len; temp++) + for (unsigned int temp = 0; temp < frames->at(c).len; temp++) { outFile->write(QString::number(frames->at(c).data[temp], 16).toUpper().rightJustified(2, '0').toUtf8()); outFile->putChar(' '); @@ -446,9 +446,9 @@ bool FrameFileIO::loadNativeCSVFile(QString filename, QVector* frames) { thisFrame.isReceived = true; thisFrame.bus = tokens[3].toInt(); - thisFrame.len = tokens[4].toInt(); + thisFrame.len = tokens[4].toUInt(); for (int c = 0; c < 8; c++) thisFrame.data[c] = 0; - for (int d = 0; d < thisFrame.len; d++) + for (unsigned int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = tokens[5 + d].toInt(NULL, 16); } else if (fileVersion == 2) @@ -456,10 +456,10 @@ bool FrameFileIO::loadNativeCSVFile(QString filename, QVector* frames) if (tokens[3].at(0) == 'R') thisFrame.isReceived = true; else thisFrame.isReceived = false; thisFrame.bus = tokens[4].toInt(); - thisFrame.len = tokens[5].toInt(); - if (thisFrame.len + 6 > tokens.length()) thisFrame.len = tokens.length() - 6; + thisFrame.len = tokens[5].toUInt(); + if (thisFrame.len + 6 > (unsigned int) tokens.length()) thisFrame.len = tokens.length() - 6; for (int c = 0; c < 8; c++) thisFrame.data[c] = 0; - for (int d = 0; d < thisFrame.len; d++) + for (unsigned int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = tokens[6 + d].toInt(NULL, 16); } @@ -570,7 +570,7 @@ bool FrameFileIO::loadGenericCSVFile(QString filename, QVector* frames QList dataTok = tokens[1].split(' '); thisFrame.len = dataTok.length(); if (thisFrame.len > 8) thisFrame.len = 8; - for (int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = dataTok[d].toInt(NULL, 16); + for (unsigned int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = dataTok[d].toInt(NULL, 16); frames->append(thisFrame); } @@ -608,7 +608,7 @@ bool FrameFileIO::saveGenericCSVFile(QString filename, const QVector* outFile->write(QString::number(frames->at(c).ID, 16).toUpper().rightJustified(8, '0').toUtf8()); outFile->putChar(44); - for (int temp = 0; temp < frames->at(c).len; temp++) + for (unsigned int temp = 0; temp < frames->at(c).len; temp++) { outFile->write(QString::number(frames->at(c).data[temp], 16).toUpper().rightJustified(2, '0').toUtf8()); outFile->putChar(' '); @@ -696,10 +696,9 @@ bool FrameFileIO::loadLogFile(QString filename, QVector* frames) if (tokens[4] == "s") thisFrame.extended = false; else thisFrame.extended = true; thisFrame.bus = tokens[2].toInt() - 1; - thisFrame.len = tokens[5].toInt(); + thisFrame.len = tokens[5].toUInt(); if (thisFrame.len > 8) thisFrame.len = 8; - if (thisFrame.len < 0) thisFrame.len = 0; - for (int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = tokens[d + 6].toInt(NULL, 16); + for (unsigned int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = tokens[d + 6].toInt(NULL, 16); frames->append(thisFrame); } else foundErrors = true; @@ -759,7 +758,7 @@ bool FrameFileIO::saveLogFile(QString filename, const QVector* frames) else outFile->write(" s "); outFile->write(QString::number(frames->at(c).len).toUtf8() + " "); - for (int temp = 0; temp < frames->at(c).len; temp++) + for (unsigned int temp = 0; temp < frames->at(c).len; temp++) { outFile->write(QString::number(frames->at(c).data[temp], 16).toUpper().rightJustified(2, '0').toUtf8()); outFile->putChar(' '); @@ -836,7 +835,7 @@ bool FrameFileIO::loadIXXATFile(QString filename, QVector* frames) QStringList dataToks = unQuote(tokens[4]).simplified().split(' '); thisFrame.len = dataToks.length(); - for (int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = dataToks[d].toInt(NULL, 16); + for (unsigned int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = dataToks[d].toInt(NULL, 16); frames->append(thisFrame); } else foundErrors = true; @@ -889,7 +888,7 @@ bool FrameFileIO::saveIXXATFile(QString filename, const QVector* frame else outFile->write(",\"Std\""); outFile->write(",\"\",\""); - for (int temp = 0; temp < frames->at(c).len; temp++) + for (unsigned int temp = 0; temp < frames->at(c).len; temp++) { outFile->write(QString::number(frames->at(c).data[temp], 16).toUpper().rightJustified(2, '0').toUtf8()); outFile->putChar(' '); @@ -952,7 +951,7 @@ bool FrameFileIO::loadCANDOFile(QString filename, QVector* frames) if (thisFrame.len <= 8 && thisFrame.ID <= 0x7FF) { - for (int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = (unsigned char)data[4 + d]; + for (unsigned int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = (unsigned char)data[4 + d]; frames->append(thisFrame); } else foundErrors = true; @@ -1008,7 +1007,7 @@ bool FrameFileIO::saveCANDOFile(QString filename, const QVector* frame data[1] = (char)(ms & 0xFF); data[2] = (char)(id & 0xFF); data[3] = (char)((id >> 8) + (thisFrame.len << 4)); - for (int d = 0; d < thisFrame.len; d++) data[4 + d] = (char)thisFrame.data[d]; + for (unsigned int d = 0; d < thisFrame.len; d++) data[4 + d] = (char)thisFrame.data[d]; outFile->write(data); } } @@ -1074,11 +1073,10 @@ bool FrameFileIO::loadMicrochipFile(QString filename, QVector* frames) if (thisFrame.ID <= 0x7FF) thisFrame.extended = false; else thisFrame.extended = true; thisFrame.bus = 0; - thisFrame.len = tokens[3].toInt(); + thisFrame.len = tokens[3].toUInt(); if (thisFrame.len > 8) thisFrame.len = 8; - if (thisFrame.len < 0) thisFrame.len = 0; - if (thisFrame.len + 4 > tokens.length()) thisFrame.len = tokens.length() - 4; - for (int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = (unsigned char)Utility::ParseStringToNum(tokens[4 + d]); + if (thisFrame.len + 4 > (unsigned int) tokens.length()) thisFrame.len = tokens.length() - 4; + for (unsigned int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = (unsigned char)Utility::ParseStringToNum(tokens[4 + d]); frames->append(thisFrame); } else foundErrors = true; @@ -1140,7 +1138,7 @@ bool FrameFileIO::saveMicrochipFile(QString filename, const QVector* f outFile->write("0x" + QString::number(frames->at(c).ID, 16).toUpper().rightJustified(8, '0').toUtf8() + ";"); outFile->write(QString::number(frames->at(c).len).toUtf8() + ";"); - for (int temp = 0; temp < frames->at(c).len; temp++) + for (unsigned int temp = 0; temp < frames->at(c).len; temp++) { outFile->write("0x" + QString::number(frames->at(c).data[temp], 16).toUpper().rightJustified(2, '0').toUtf8()); outFile->putChar(';'); @@ -1233,12 +1231,11 @@ bool FrameFileIO::loadTraceFile(QString filename, QVector* frames) if (thisFrame.ID <= 0x7FF) thisFrame.extended = false; else thisFrame.extended = true; thisFrame.bus = 0; - thisFrame.len = tokens[3].toInt(); - if (thisFrame.len < 0) thisFrame.len = 0; + thisFrame.len = tokens[3].toUInt(); if (thisFrame.len > 8) thisFrame.len = 8; QList dataToks = tokens[4].split(' '); - if (thisFrame.len > dataToks.length()) thisFrame.len = dataToks.length(); - for (int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = (unsigned char)dataToks[d].toInt(NULL, 16); + if (thisFrame.len > (unsigned int) dataToks.length()) thisFrame.len = (unsigned int) dataToks.length(); + for (unsigned int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = (unsigned char)dataToks[d].toInt(NULL, 16); frames->append(thisFrame); } else foundErrors = true; @@ -1325,7 +1322,7 @@ bool FrameFileIO::saveTraceFile(QString filename, const QVector * fram outFile->write(QString::number(frames->at(c).len).toUtf8() + "\t"); - for (int temp = 0; temp < frames->at(c).len; temp++) + for (unsigned int temp = 0; temp < frames->at(c).len; temp++) { outFile->write(QString::number(frames->at(c).data[temp], 16).toUpper().rightJustified(2, '0').toUtf8()); outFile->putChar(' '); diff --git a/scriptcontainer.cpp b/scriptcontainer.cpp index 9e14e2d..84b7280 100644 --- a/scriptcontainer.cpp +++ b/scriptcontainer.cpp @@ -93,13 +93,12 @@ void ScriptContainer::sendFrame(QJSValue bus, QJSValue id, QJSValue length, QJSV CANFrame frame; frame.extended = false; frame.ID = id.toInt(); - frame.len = length.toInt(); - if (frame.len < 0) frame.len = 0; + frame.len = length.toUInt(); if (frame.len > 8) frame.len = 8; if (!data.isArray()) qDebug() << "data isn't an array"; - for (int i = 0; i < frame.len; i++) + for (unsigned int i = 0; i < frame.len; i++) { frame.data[i] = (uint8_t)data.property(i).toInt(); } @@ -125,7 +124,7 @@ void ScriptContainer::gotFrame(const CANFrame &frame) QJSValueList args; args << frame.bus << frame.ID << frame.len; QJSValue dataBytes = scriptEngine.newArray(frame.len); - for (int j = 0; j < frame.len; j++) dataBytes.setProperty(j, QJSValue(frame.data[j])); + for (unsigned int j = 0; j < frame.len; j++) dataBytes.setProperty(j, QJSValue(frame.data[j])); args.append(dataBytes); gotFrameFunction.call(args); return; //as soon as one filter matches we jump out