diff --git a/bisectwindow.cpp b/bisectwindow.cpp index 22d3e78..99a27ca 100644 --- a/bisectwindow.cpp +++ b/bisectwindow.cpp @@ -66,7 +66,7 @@ void BisectWindow::refreshIDList() int id; for (int i = 0; i < modelFrames->count(); i++) { - id = modelFrames->at(i).ID; + id = modelFrames->at(i).frameId(); if (!foundID.contains(id)) { foundID.append(id); @@ -129,7 +129,7 @@ void BisectWindow::handleCalculateButton() uint32_t upperID = Utility::ParseStringToNum2(ui->cbIDUpper->currentText()); for (int i = 0; i < modelFrames->count(); i++) { - if (modelFrames->at(i).ID >= lowerID && modelFrames->at(i).ID <= upperID) splitFrames.append(modelFrames->at(i)); + if (modelFrames->at(i).frameId() >= lowerID && modelFrames->at(i).frameId() <= upperID) splitFrames.append(modelFrames->at(i)); } } refreshFrameNumbers(); diff --git a/bus_protocols/isotp_handler.cpp b/bus_protocols/isotp_handler.cpp index db05824..9534b26 100644 --- a/bus_protocols/isotp_handler.cpp +++ b/bus_protocols/isotp_handler.cpp @@ -50,7 +50,7 @@ void ISOTP_HANDLER::setReception(bool mode) void ISOTP_HANDLER::sendISOTPFrame(int bus, int ID, QVector data) { CANFrame frame; - frame.remote = false; + frame.setFrameType(QCanBusFrame::DataFrame); int currByte = 0; int index = 0; if (bus < 0) return; @@ -61,27 +61,28 @@ void ISOTP_HANDLER::sendISOTPFrame(int bus, int ID, QVector data) if (data.length() < 8) { - frame.bus = bus; - frame.ID = ID; - if (ID > 0x7FF) frame.extended = true; - else frame.extended = false; - frame.len = 8; - for (int b = 0; b < 8; b++) frame.data[b] = 0x00; - frame.data[0] = data.length(); - for (int i = 0; i < frame.data[0]; i++) frame.data[i + 1] = data[i]; + frame.bus = bus; + frame.setFrameId(ID); + if (ID > 0x7FF) frame.setExtendedFrameFormat(true); + else frame.setExtendedFrameFormat(false); + QByteArray bytes(8,0); + bytes.resize(8); + bytes[0] = data.length(); + for (int i = 0; i < data.length(); i++) bytes[i + 1] = data[i]; + frame.setPayload(bytes); CANConManager::getInstance()->sendFrame(frame); } else //need to send a multi-part ISO_TP message - Respects timing and frame number based flow control { frame.bus = bus; - frame.ID = ID; - if (ID > 0x7FF) frame.extended = true; - else frame.extended = false; - frame.len = 8; - for (int b = 0; b < 8; b++) frame.data[b] = 0x00; - frame.data[0] = 0x10 + (data.length() / 256); - frame.data[1] = data.length() & 0xFF; - for (int i = 0; i < 6; i++) frame.data[2 + i] = data[currByte++]; + frame.setFrameId(ID); + if (ID > 0x7FF) frame.setExtendedFrameFormat(true); + else frame.setExtendedFrameFormat(false); + QByteArray bytes(8, 0); + bytes[0] = 0x10 + (data.length() / 256); + bytes[1] = data.length() & 0xFF; + for (int i = 0; i < 6; i++) bytes[2 + i] = data[currByte++]; + frame.setPayload(bytes); CANConManager::getInstance()->sendFrame(frame); //Queue up the rest of the frames waitingForFlow = true; @@ -90,13 +91,13 @@ void ISOTP_HANDLER::sendISOTPFrame(int bus, int ID, QVector data) frameTimer.start(); while (currByte < data.length()) { - for (int b = 0; b < 8; b++) frame.data[b] = 0x00; - frame.data[0] = 0x20 + index; + for (int b = 0; b < 8; b++) bytes[b] = 0x00; + bytes[0] = 0x20 + index; index = (index + 1) & 0xF; int bytesToGo = data.length() - currByte; if (bytesToGo > 7) bytesToGo = 7; - for (int i = 0; i < bytesToGo; i++) frame.data[1 + i] = data[currByte++]; - frame.len = 8; + for (int i = 0; i < bytesToGo; i++) bytes[1 + i] = data[currByte++]; + frame.setPayload(bytes); sendingFrames.append(frame); //CANConManager::getInstance()->sendFrame(frame); } @@ -138,7 +139,7 @@ void ISOTP_HANDLER::rapidFrames(const CANConnection* conn, const QVector> 4; - frameLen = frame.data[1] & 0xF; + ID += frame.payload()[0]; + frameType = frame.payload()[1] >> 4; + frameLen = frame.payload()[1] & 0xF; } else { - frameType = frame.data[0] >> 4; - frameLen = frame.data[0] & 0xF; + frameType = frame.payload()[0] >> 4; + frameLen = frame.payload()[0] & 0xF; } switch(frameType) @@ -185,42 +186,42 @@ void ISOTP_HANDLER::processFrame(const CANFrame &frame) if (frameLen > 7) return; msg.bus = frame.bus; - msg.extended = frame.extended; + msg.extended = frame.hasExtendedFrameFormat(); msg.ID = ID; msg.isReceived = frame.isReceived; msg.len = frameLen; msg.data.reserve(frameLen); - msg.timestamp = frame.timestamp; + msg.timestamp = frame.timeStamp().microSeconds(); msg.isMultiframe = false; - if (useExtendedAddressing) for (int j = 0; j < frameLen; j++) msg.data.append(frame.data[j+2]); - else for (int j = 0; j < frameLen; j++) msg.data.append(frame.data[j+1]); + if (useExtendedAddressing) for (int j = 0; j < frameLen; j++) msg.data.append(frame.payload()[j+2]); + else for (int j = 0; j < frameLen; j++) msg.data.append(frame.payload()[j+1]); //qDebug() << "Emitting single frame ISOTP message"; emit newISOMessage(msg); break; case 1: //first frame of a multi-frame message checkNeedFlush(ID); msg.bus = frame.bus; - msg.extended = frame.extended; + msg.extended = frame.hasExtendedFrameFormat(); msg.ID = ID; - msg.timestamp = frame.timestamp; + msg.timestamp = frame.timeStamp().microSeconds(); msg.isReceived = frame.isReceived; msg.isMultiframe = true; frameLen = frameLen << 8; if (useExtendedAddressing) { - frameLen += frame.data[2]; + frameLen += frame.payload()[2]; frameLen = frameLen & 0xFFF; msg.len = frameLen; msg.data.reserve(frameLen); - for (int j = 0; j < 5; j++) msg.data.append(frame.data[3 + j]); + for (int j = 0; j < 5; j++) msg.data.append(frame.payload()[3 + j]); } else { - frameLen += frame.data[1]; + frameLen += frame.payload()[1]; frameLen = frameLen & 0xFFF; msg.len = frameLen; msg.data.reserve(frameLen); - for (int j = 0; j < 6; j++) msg.data.append(frame.data[2 + j]); + for (int j = 0; j < 6; j++) msg.data.append(frame.payload()[2 + j]); } msg.lastSequence = -1; messageBuffer.append(msg); @@ -230,13 +231,13 @@ void ISOTP_HANDLER::processFrame(const CANFrame &frame) { CANFrame outFrame; outFrame.bus = lastSenderBus; - outFrame.extended = false; - outFrame.ID = lastSenderID; - outFrame.len = 8; - for (int b = 0; b < 8; b++) outFrame.data[b] = 0x00; - outFrame.data[0] = 0x30; //flow control, go ahead and send - outFrame.data[1] = 0; //dont ask again about flow control - outFrame.data[2] = 3; //separation time in milliseconds between messages. + outFrame.setExtendedFrameFormat(false); + outFrame.setFrameId(lastSenderID); + QByteArray bytes(8, 0); + bytes[0] = 0x30; //flow control, go ahead and send + bytes[1] = 0; //dont ask again about flow control + bytes[2] = 3; //separation time in milliseconds between messages. + outFrame.setPayload(bytes); CANConManager::getInstance()->sendFrame(outFrame); } break; @@ -257,12 +258,12 @@ void ISOTP_HANDLER::processFrame(const CANFrame &frame) if (useExtendedAddressing) { if (ln > 6) ln = 6; - for (int j = 0; j < ln; j++) pMsg->data.append(frame.data[j+2]); + for (int j = 0; j < ln; j++) pMsg->data.append(frame.payload()[j+2]); } else { if (ln > 7) ln = 7; - for (int j = 0; j < ln; j++) pMsg->data.append(frame.data[j+1]); + for (int j = 0; j < ln; j++) pMsg->data.append(frame.payload()[j+1]); } if (pMsg->len <= pMsg->data.count()) { @@ -276,10 +277,10 @@ void ISOTP_HANDLER::processFrame(const CANFrame &frame) case 0: //continue to send frames but maybe change inter-frame delay waitingForFlow = false; //data[1] contains number of frames to send before waiting for next flow control - framesUntilFlow = frame.data[1]; + framesUntilFlow = frame.payload()[1]; if (framesUntilFlow == 0) framesUntilFlow = -1; //-1 means don't count frames and just keep going //data[2] contains the interframe delay to use (0xF1 through 0xF9 are special through) - if (frame.data[2] < 0xF1) frameTimer.start(frame.data[2]); //set proper delay between frames + if (frame.payload()[2] < (char)0xF1) frameTimer.start(frame.payload()[2]); //set proper delay between frames else frameTimer.start(1); //can't do sub-millisecond sending with this code so just use 1ms timing break; case 1: //wait - do not send any more frames until other side says so @@ -307,14 +308,14 @@ void ISOTP_HANDLER::checkNeedFlush(uint64_t ID) //used to pass by reference but now newISOMessage should pass by value which makes it easier to use cross thread if (messageBuffer[i].ID > 0x600 && messageBuffer[i].ID < 0x630) { - if (messageBuffer[i].len <= messageBuffer[i].data.count()) - { - qDebug() << "Flushing full frame" << QString::number(messageBuffer[i].ID, 16) << " " << messageBuffer[i].len << " " << messageBuffer[i].data.count(); - } - else - { - qDebug() << "Flushing a partial frame " << QString::number(messageBuffer[i].ID, 16) << " " << messageBuffer[i].len << " " << messageBuffer[i].data.count(); - } + if (messageBuffer[i].len <= messageBuffer[i].data.count()) + { + qDebug() << "Flushing full frame" << QString::number(messageBuffer[i].ID, 16) << " " << messageBuffer[i].len << " " << messageBuffer[i].data.count(); + } + else + { + qDebug() << "Flushing a partial frame " << QString::number(messageBuffer[i].ID, 16) << " " << messageBuffer[i].len << " " << messageBuffer[i].data.count(); + } } emit newISOMessage(messageBuffer[i]); messageBuffer.removeAt(i); diff --git a/bus_protocols/isotp_handler.h b/bus_protocols/isotp_handler.h index 611f63a..7cdc16d 100644 --- a/bus_protocols/isotp_handler.h +++ b/bus_protocols/isotp_handler.h @@ -1,5 +1,4 @@ -#ifndef ISOTP_HANDLER_H -#define ISOTP_HANDLER_H +#pragma once #include #include @@ -53,5 +52,3 @@ private: void processFrame(const CANFrame &frame); void checkNeedFlush(uint64_t ID); }; - -#endif // ISOTP_HANDLER_H diff --git a/bus_protocols/isotp_message.h b/bus_protocols/isotp_message.h index f2d4c85..5e59580 100644 --- a/bus_protocols/isotp_message.h +++ b/bus_protocols/isotp_message.h @@ -1,6 +1,9 @@ #ifndef ISOTP_MESSAGE_H #define ISOTP_MESSAGE_H +#include +#include + //the same as the CANFrame struct but with arbitrary data size. class ISOTP_MESSAGE { diff --git a/can_structs.h b/can_structs.h index d0b3063..6b8cdee 100644 --- a/can_structs.h +++ b/can_structs.h @@ -4,35 +4,32 @@ #include #include #include +#include -struct CANFrame +//Now inherits from the built-in CAN frame class from Qt. This should be more future proof and easier to integrate with other code + +struct CANFrame : public QCanBusFrame { public: - uint32_t ID; int bus; - bool extended; - bool remote; bool isReceived; //did we receive this or send it? - int len; - unsigned char data[8]; - uint64_t timestamp; uint64_t timedelta; uint32_t frameCount; //used in overwrite mode friend bool operator<(const CANFrame& l, const CANFrame& r) { - return l.timestamp < r.timestamp; + qint64 lStamp = l.timeStamp().seconds() * 1000000 + l.timeStamp().microSeconds(); + qint64 rStamp = r.timeStamp().seconds() * 1000000 + r.timeStamp().microSeconds(); + return lStamp < rStamp; } CANFrame() { - ID = 0; + setFrameId(0); bus = 0; - extended = false; - remote = false; + setExtendedFrameFormat(false); + setFrameType(QCanBusFrame::DataFrame); isReceived = true; - len = 0; - timestamp = 0; timedelta = 0; frameCount = 1; } diff --git a/connections/canconmanager.cpp b/connections/canconmanager.cpp index 0154c03..9ae1f11 100644 --- a/connections/canconmanager.cpp +++ b/connections/canconmanager.cpp @@ -220,11 +220,11 @@ bool CANConManager::sendFrame(const CANFrame& pFrame) workingFrame.isReceived = false; if (useSystemTime) { - workingFrame.timestamp = (QDateTime::currentMSecsSinceEpoch() * 1000); + workingFrame.setTimeStamp(QCanBusFrame::TimeStamp(0,QDateTime::currentMSecsSinceEpoch() * 1000)); } else { - workingFrame.timestamp = mElapsedTimer.nsecsElapsed() / 1000; + workingFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, mElapsedTimer.nsecsElapsed() / 1000)); //workingFrame.timestamp -= mTimestampBasis; } txFrame = conn->getQueue().get(); diff --git a/connections/gvretserial.cpp b/connections/gvretserial.cpp index 523c3a5..11708a2 100644 --- a/connections/gvretserial.cpp +++ b/connections/gvretserial.cpp @@ -246,11 +246,11 @@ bool GVRetSerial::piSendFrame(const CANFrame& frame) // Doesn't make sense to send an error frame // to an adapter - if (frame.ID & 0x20000000) { + if (frame.frameId() & 0x20000000) { return true; } - ID = frame.ID; - if (frame.extended) ID |= 1 << 31; + ID = frame.frameId(); + if (frame.hasExtendedFrameFormat()) ID |= 1 << 31; buffer[0] = (unsigned char)0xF1; //start of a command over serial buffer[1] = 0; //command ID for sending a CANBUS frame @@ -259,12 +259,12 @@ bool GVRetSerial::piSendFrame(const CANFrame& frame) buffer[4] = (unsigned char)(ID >> 16); buffer[5] = (unsigned char)(ID >> 24); buffer[6] = (unsigned char)((frame.bus) & 3); - buffer[7] = (unsigned char)frame.len; - for (c = 0; c < frame.len; c++) + buffer[7] = (unsigned char)frame.payload().length(); + for (c = 0; c < frame.payload().length(); c++) { - buffer[8 + c] = frame.data[c]; + buffer[8 + c] = frame.payload()[c]; } - buffer[8 + frame.len] = 0; + buffer[8 + frame.payload().length()] = 0; sendToSerial(buffer); @@ -375,18 +375,18 @@ void GVRetSerial::deviceConnected() { sendDebug("Connecting to GVRET Device!"); QByteArray output; - output.append((unsigned char)0xE7); //this puts the device into binary comm mode - output.append((unsigned char)0xE7); + output.append((char)0xE7); //this puts the device into binary comm mode + output.append((char)0xE7); - output.append((unsigned char)0xF1); - output.append((unsigned char)0x0C); //get number of actually implemented buses. Not implemented except on M2RET + output.append((char)0xF1); + output.append((char)0x0C); //get number of actually implemented buses. Not implemented except on M2RET mNumBuses = 2; //the proper number if C/12 is not implemented - output.append((unsigned char)0xF1); //signal we want to issue a command - output.append((unsigned char)0x06); //request canbus stats from the board + output.append((char)0xF1); //signal we want to issue a command + output.append((char)0x06); //request canbus stats from the board - output.append((unsigned char)0xF1); //another command to the GVRET - output.append((unsigned char)0x07); //request device information + output.append((char)0xF1); //another command to the GVRET + output.append((char)0x07); //request device information /*output.append((char)0xF1); output.append((char)0x08); //setting singlewire mode @@ -399,11 +399,11 @@ void GVRetSerial::deviceConnected() output.append((char)0xFF); //signal we don't want single wire mode }*/ - output.append((unsigned char)0xF1); //and another command - output.append((unsigned char)0x01); //Time Sync - Not implemented until 333 but we can try + output.append((char)0xF1); //and another command + output.append((char)0x01); //Time Sync - Not implemented until 333 but we can try - output.append((unsigned char)0xF1); //yet another command - output.append((unsigned char)0x09); //comm validation command + output.append((char)0xF1); //yet another command + output.append((char)0x09); //comm validation command continuousTimeSync = true; @@ -659,57 +659,59 @@ void GVRetSerial::procRXChar(unsigned char c) switch (rx_step) { case 0: - buildFrame.timestamp = c; + buildTimestamp = c; break; case 1: - buildFrame.timestamp |= (uint)(c << 8); + buildTimestamp |= (uint)(c << 8); break; case 2: - buildFrame.timestamp |= (uint)c << 16; + buildTimestamp |= (uint)c << 16; break; case 3: - buildFrame.timestamp |= (uint)c << 24; + buildTimestamp |= (uint)c << 24; - buildFrame.timestamp += timeBasis; + buildTimestamp += timeBasis; if (useSystemTime) { - buildFrame.timestamp = QDateTime::currentMSecsSinceEpoch() * 1000l; + buildTimestamp = QDateTime::currentMSecsSinceEpoch() * 1000l; } + buildFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, buildTimestamp)); break; case 4: - buildFrame.ID = c; + buildId = c; break; case 5: - buildFrame.ID |= c << 8; + buildId |= c << 8; break; case 6: - buildFrame.ID |= c << 16; + buildId |= c << 16; break; case 7: - buildFrame.ID |= c << 24; - if ((buildFrame.ID & 1 << 31) == 1u << 31) + buildId |= c << 24; + if ((buildId & 1 << 31) == 1u << 31) { - buildFrame.ID &= 0x7FFFFFFF; - buildFrame.extended = true; + buildId &= 0x7FFFFFFF; + buildFrame.setExtendedFrameFormat(true); } - else buildFrame.extended = false; + else buildFrame.setExtendedFrameFormat(false); + buildFrame.setFrameId(buildId); break; case 8: - buildFrame.len = c & 0xF; - if (buildFrame.len > 8) buildFrame.len = 8; + buildData.resize(c & 0xF); buildFrame.bus = (c & 0xF0) >> 4; break; default: - if (rx_step < buildFrame.len + 9) + if (rx_step < buildData.length() + 9) { - buildFrame.data[rx_step - 9] = c; + buildData[rx_step - 9] = c; } else { rx_state = IDLE; rx_step = 0; buildFrame.isReceived = true; - + buildFrame.setPayload(buildData); + buildFrame.setFrameType(QCanBusFrame::FrameType::DataFrame); if (!isCapSuspended()) { /* get frame from queue */ @@ -717,8 +719,7 @@ void GVRetSerial::procRXChar(unsigned char c) if(frame_p) { //qDebug() << "GVRET got frame on bus " << frame_p->bus; /* copy frame */ - *frame_p = buildFrame; - frame_p->remote = false; + *frame_p = buildFrame; checkTargettedFrame(buildFrame); /* enqueue frame */ getQueue().queue(); diff --git a/connections/gvretserial.h b/connections/gvretserial.h index dba664f..3df1350 100644 --- a/connections/gvretserial.h +++ b/connections/gvretserial.h @@ -93,6 +93,9 @@ protected: STATE rx_state; uint32_t rx_step; CANFrame buildFrame; + qint64 buildTimestamp; + quint32 buildId; + QByteArray buildData; int can0Baud, can1Baud, swcanBaud, lin1Baud, lin2Baud; bool can0Enabled, can1Enabled, swcanEnabled, lin1Enabled, lin2Enabled; bool can0ListenOnly, can1ListenOnly, swcanListenOnly; diff --git a/connections/serialbusconnection.cpp b/connections/serialbusconnection.cpp index 6fa35f2..72e1e90 100644 --- a/connections/serialbusconnection.cpp +++ b/connections/serialbusconnection.cpp @@ -115,22 +115,11 @@ void SerialBusConnection::piSetBusSettings(int pBusIdx, CANBus bus) bool SerialBusConnection::piSendFrame(const CANFrame& pFrame) { /* sanity checks */ - if(0 != pFrame.bus || pFrame.len>8) + if(0 != pFrame.bus /*|| pFrame.len>8*/) return false; if (!mDev_p) return false; - /* fill frame */ - QCanBusFrame frame; - frame.setExtendedFrameFormat(pFrame.extended); - frame.setFrameId(pFrame.ID); - if (pFrame.remote) { - frame.setFrameType(QCanBusFrame::FrameType::RemoteRequestFrame); - } else { - frame.setFrameType(QCanBusFrame::FrameType::DataFrame); - } - frame.setPayload(QByteArray(reinterpret_cast(pFrame.data), - static_cast(pFrame.len))); - return mDev_p->writeFrame(frame); + return mDev_p->writeFrame(pFrame); } @@ -193,14 +182,16 @@ void SerialBusConnection::framesReceived() if (recFrame.payload().length() <= 8) { CANFrame* frame_p = getQueue().get(); if(frame_p) { - frame_p->len = static_cast(recFrame.payload().length()); - frame_p->bus = 0; + frame_p->setPayload(recFrame.payload()); + frame_p->bus = 0; if (recFrame.frameType() == QCanBusFrame::ErrorFrame) { // Constants defined in include/uapi/linux/can/error.h + //since the whole program uses QCanBusFrame now we can just grab errors directly out of the proper place from now on + /* switch (recFrame.error()) { case QCanBusFrame::TransmissionTimeoutError: - frame_p->ID = 0x20000001; + frame_p->setFrameId(0x20000001); break; case QCanBusFrame::LostArbitrationError: frame_p->ID = 0x20000002; @@ -230,19 +221,21 @@ void SerialBusConnection::framesReceived() break; } frame_p->extended = true; + */ } else { - frame_p->extended = recFrame.hasExtendedFrameFormat(); - frame_p->ID = recFrame.frameId(); - frame_p->remote = (recFrame.frameType() == recFrame.RemoteRequestFrame); - memcpy(frame_p->data, recFrame.payload().data(), frame_p->len); + frame_p->setExtendedFrameFormat(recFrame.hasExtendedFrameFormat()); + frame_p->setFrameId(recFrame.frameId()); + frame_p->setTimeStamp(recFrame.timeStamp()); + frame_p->setFrameType(recFrame.frameType()); + frame_p->setError(recFrame.error()); frame_p->isReceived = true; } frame_p->isReceived = true; if (useSystemTime) { - frame_p->timestamp = QDateTime::currentMSecsSinceEpoch() * 1000ul; + frame_p->setTimeStamp(QCanBusFrame::TimeStamp(0, QDateTime::currentMSecsSinceEpoch() * 1000ul)); } - else frame_p->timestamp = (recFrame.timeStamp().seconds() * 1000000ul + recFrame.timeStamp().microSeconds()) - timeBasis; + else frame_p->setTimeStamp(QCanBusFrame::TimeStamp(0, (recFrame.timeStamp().seconds() * 1000000ul + recFrame.timeStamp().microSeconds()) - timeBasis)); checkTargettedFrame(*frame_p); diff --git a/dbc/dbc_classes.cpp b/dbc/dbc_classes.cpp index f692f7e..003ea52 100644 --- a/dbc/dbc_classes.cpp +++ b/dbc/dbc_classes.cpp @@ -47,7 +47,7 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString, bool o QString buildString; int startByte = startBit / 8; int bytes = signalSize / 8; - for (int x = 0; x < bytes; x++) buildString.append(frame.data[startByte + x]); + for (int x = 0; x < bytes; x++) buildString.append((char)frame.payload()[startByte + x]); outString = buildString; cachedValue = outString; return true; @@ -68,7 +68,7 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString, bool o if (valType == SIGNED_INT) isSigned = true; if (valType == SIGNED_INT || valType == UNSIGNED_INT) { - result = Utility::processIntegerSignal(frame.data, startBit, signalSize, intelByteOrder, isSigned); + result = Utility::processIntegerSignal(frame.payload(), startBit, signalSize, intelByteOrder, isSigned); endResult = ((double)result * factor) + bias; result = (int64_t)endResult; } @@ -79,19 +79,19 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString, bool o //that the bytes that make up the integer are instead treated as having made up //a 32 bit single precision float. That's evil incarnate but it is very fast and small //in terms of new code. - result = Utility::processIntegerSignal(frame.data, startBit, 32, intelByteOrder, false); + result = Utility::processIntegerSignal(frame.payload(), startBit, 32, intelByteOrder, false); endResult = (*((float *)(&result)) * factor) + bias; } else //double precision float { - if ( frame.len < 8 ) + if ( frame.payload().length() < 8 ) { result = 0; return false; } //like the above, this is rotten and evil and wrong in so many ways. Force //calculation of a 64 bit integer and then cast it into a double. - result = Utility::processIntegerSignal(frame.data, 0, 64, intelByteOrder, false); + result = Utility::processIntegerSignal(frame.payload(), 0, 64, intelByteOrder, false); endResult = (*((double *)(&result)) * factor) + bias; } @@ -155,13 +155,13 @@ bool DBC_SIGNAL::processAsInt(const CANFrame &frame, int32_t &outValue) } if (valType == SIGNED_INT) isSigned = true; - if ( static_cast(frame.len * 8) < (startBit + signalSize) ) + if ( static_cast(frame.payload().length() * 8) < (startBit + signalSize) ) { result = 0; return false; } - result = static_cast(Utility::processIntegerSignal(frame.data, startBit, signalSize, intelByteOrder, isSigned)); + result = static_cast(Utility::processIntegerSignal(frame.payload(), startBit, signalSize, intelByteOrder, isSigned)); double endResult = (result * factor) + bias; result = static_cast(endResult); @@ -200,19 +200,19 @@ bool DBC_SIGNAL::processAsDouble(const CANFrame &frame, double &outValue) if (valType == SIGNED_INT) isSigned = true; if (valType == SIGNED_INT || valType == UNSIGNED_INT) { - if ( frame.len*8 < (startBit+signalSize) ) + if ( frame.payload().length() * 8 < (startBit+signalSize) ) { result = 0; return false; } - result = Utility::processIntegerSignal(frame.data, startBit, signalSize, intelByteOrder, isSigned); + result = Utility::processIntegerSignal(frame.payload(), startBit, signalSize, intelByteOrder, isSigned); endResult = ((double)result * factor) + bias; result = (int64_t)endResult; } /*TODO: It should be noted that the below floating point has not even been tested. For shame! Test it!*/ else if (valType == SP_FLOAT) { - if ( frame.len*8 < (startBit+32) ) + if ( frame.payload().length() * 8 < (startBit + 32) ) { result = 0; return false; @@ -222,19 +222,19 @@ bool DBC_SIGNAL::processAsDouble(const CANFrame &frame, double &outValue) //that the bytes that make up the integer are instead treated as having made up //a 32 bit single precision float. That's evil incarnate but it is very fast and small //in terms of new code. - result = Utility::processIntegerSignal(frame.data, startBit, 32, false, false); + result = Utility::processIntegerSignal(frame.payload(), startBit, 32, false, false); endResult = (*((float *)(&result)) * factor) + bias; } else //double precision float { - if ( frame.len < 8 ) + if ( frame.payload().length() < 8 ) { result = 0; return false; } //like the above, this is rotten and evil and wrong in so many ways. Force //calculation of a 64 bit integer and then cast it into a double. - result = Utility::processIntegerSignal(frame.data, 0, 64, false, false); + result = Utility::processIntegerSignal(frame.payload(), 0, 64, false, false); endResult = (*((double *)(&result)) * factor) + bias; } cachedValue = endResult; diff --git a/dbc/dbcmaineditor.cpp b/dbc/dbcmaineditor.cpp index f84b36d..5ae5c1e 100644 --- a/dbc/dbcmaineditor.cpp +++ b/dbc/dbcmaineditor.cpp @@ -294,9 +294,9 @@ void DBCMainEditor::onCellChangedMessage(int row,int col) for (int i = 0; i < referenceFrames->length(); i++) { - if ((uint) referenceFrames->at(i).ID == msgID) + if ((uint) referenceFrames->at(i).frameId() == msgID) { - newMsg.len = referenceFrames->at(i).len; + newMsg.len = referenceFrames->at(i).payload().length(); break; } } diff --git a/re/discretestatewindow.cpp b/re/discretestatewindow.cpp index ddf5f1d..a4a0ba3 100644 --- a/re/discretestatewindow.cpp +++ b/re/discretestatewindow.cpp @@ -140,10 +140,10 @@ void DiscreteStateWindow::updatedFrames(int numFrames) { thisFrame = modelFrames->at(i); - if (!idFilters.contains(thisFrame.ID)) + if (!idFilters.contains(thisFrame.frameId())) { - idFilters.insert(thisFrame.ID, true); - QListWidgetItem* listItem = new QListWidgetItem(Utility::formatCANID(thisFrame.ID, thisFrame.extended), ui->listID); + idFilters.insert(thisFrame.frameId(), true); + QListWidgetItem* listItem = new QListWidgetItem(Utility::formatCANID(thisFrame.frameId(), thisFrame.hasExtendedFrameFormat()), ui->listID); listItem->setFlags(listItem->flags() | Qt::ItemIsUserCheckable); // set checkable flag listItem->setCheckState(Qt::Checked); //default all filters to be set active } @@ -164,11 +164,11 @@ void DiscreteStateWindow::refreshFilterList() for (int i = 0; i < modelFrames->length(); i++) { CANFrame thisFrame = modelFrames->at(i); - id = thisFrame.ID; + id = thisFrame.frameId(); if (!idFilters.contains(id)) { idFilters.insert(id, true); - QListWidgetItem* listItem = new QListWidgetItem(Utility::formatCANID(id, thisFrame.extended), ui->listID); + QListWidgetItem* listItem = new QListWidgetItem(Utility::formatCANID(id, thisFrame.hasExtendedFrameFormat()), ui->listID); listItem->setFlags(listItem->flags() | Qt::ItemIsUserCheckable); // set checkable flag listItem->setCheckState(Qt::Checked); //default all filters to be set active } @@ -359,7 +359,7 @@ void DiscreteStateWindow::calculateResults() frameCache.clear(); for (int i = 0; i < modelFrames->count(); i++) { - if (modelFrames->at(i).ID == (unsigned int)it.key()) frameCache.append(modelFrames->at(i)); + if (modelFrames->at(i).frameId() == (unsigned int)it.key()) frameCache.append(modelFrames->at(i)); } for (int bits = maxBits; bits >= minBits; bits--) { diff --git a/re/filecomparatorwindow.cpp b/re/filecomparatorwindow.cpp index 3efcfea..e565de7 100644 --- a/re/filecomparatorwindow.cpp +++ b/re/filecomparatorwindow.cpp @@ -152,22 +152,22 @@ void FileComparatorWindow::calculateDetails() for (int x = 0; x < interestedFrames.count(); x++) { CANFrame frame = interestedFrames.at(x); - if (interestedIDs.contains(frame.ID)) //if we saw this ID before then add to the QList in there + if (interestedIDs.contains(frame.frameId())) //if we saw this ID before then add to the QList in there { - for (unsigned int y = 0; y < frame.len; y++) + for (unsigned int y = 0; y < frame.payload().length(); y++) { - interestedIDs[frame.ID].values[y][frame.data[y]]++; - tmp = frame.data[y]; + interestedIDs[frame.frameId()].values[y][frame.payload()[y]]++; + tmp = frame.payload()[y]; tmp = tmp << (8 * y); - interestedIDs[frame.ID].bitmap |= tmp; - //qDebug() << "bitmap: " << QString::number(interestedIDs[frame.ID].bitmap, 16); + interestedIDs[frame.frameId()].bitmap |= tmp; + //qDebug() << "bitmap: " << QString::number(interestedIDs[frame.frameId()].bitmap, 16); } } else //never seen this ID before so add one { FrameData *newData = new FrameData(); - newData->ID = frame.ID; - newData->dataLen = frame.len; + newData->ID = frame.frameId(); + newData->dataLen = frame.payload().length(); //it would be possible to implement a constructor for FrameData //that sets the bitmap and values to zero. That would be cleaner and better. newData->bitmap = 0; @@ -179,15 +179,15 @@ void FileComparatorWindow::calculateDetails() } } //memset(newData->values, 0, 256 * 8); - for (unsigned int y = 0; y < frame.len; y++) + for (unsigned int y = 0; y < frame.payload().length(); y++) { - newData->values[y][frame.data[y]] = 1; - tmp = frame.data[y]; + newData->values[y][frame.payload()[y]] = 1; + tmp = frame.payload()[y]; tmp = tmp << (8 * y); newData->bitmap |= tmp; //qDebug() << "bitmap: " << QString::number(newData->bitmap, 16); } - interestedIDs.insert(frame.ID, *newData); + interestedIDs.insert(frame.frameId(), *newData); } } @@ -196,22 +196,22 @@ void FileComparatorWindow::calculateDetails() for (int x = 0; x < referenceFrames.count(); x++) { CANFrame frame = referenceFrames.at(x); - if (referenceIDs.contains(frame.ID)) //if we saw this ID before then add to the QList in there + if (referenceIDs.contains(frame.frameId())) //if we saw this ID before then add to the QList in there { - for (unsigned int y = 0; y < frame.len; y++) + for (unsigned int y = 0; y < frame.payload().length(); y++) { - referenceIDs[frame.ID].values[y][frame.data[y]]++; - tmp = frame.data[y]; + referenceIDs[frame.frameId()].values[y][frame.payload()[y]]++; + tmp = frame.payload()[y]; tmp = tmp << (8 * y); - referenceIDs[frame.ID].bitmap |= tmp; - //qDebug() << "bitmap: " << QString::number(referenceIDs[frame.ID].bitmap, 16); + referenceIDs[frame.frameId()].bitmap |= tmp; + //qDebug() << "bitmap: " << QString::number(referenceIDs[frame.frameId()].bitmap, 16); } } else //never seen this ID before so add one { FrameData *newData = new FrameData(); - newData->ID = frame.ID; - newData->dataLen = frame.len; + newData->ID = frame.frameId(); + newData->dataLen = frame.payload().length(); newData->bitmap = 0; for (int x = 0; x < 8; x++) { @@ -221,15 +221,15 @@ void FileComparatorWindow::calculateDetails() } } //memset(newData->values, 0, 256 * 8); - for (unsigned int y = 0; y < frame.len; y++) + for (unsigned int y = 0; y < frame.payload().length(); y++) { - newData->values[y][frame.data[y]] = 1; - tmp = frame.data[y]; + newData->values[y][frame.payload()[y]] = 1; + tmp = frame.payload()[y]; tmp = tmp << (8 * y); newData->bitmap |= tmp; //qDebug() << "bitmap: " << QString::number(newData->bitmap, 16); } - referenceIDs.insert(frame.ID, *newData); + referenceIDs.insert(frame.frameId(), *newData); } } diff --git a/re/flowviewwindow.cpp b/re/flowviewwindow.cpp index c3ec0c0..dcd627a 100644 --- a/re/flowviewwindow.cpp +++ b/re/flowviewwindow.cpp @@ -250,7 +250,7 @@ void FlowViewWindow::plottableDoubleClick(QCPAbstractPlottable* plottable, QMous int id = 0; //apply transforms to get the X axis value where we double clicked double coord = plottable->keyAxis()->pixelToCoord(event->localPos().x()); - if (frameCache.count() > 0) id = frameCache[0].ID; + if (frameCache.count() > 0) id = frameCache[0].frameId(); if (secondsMode) emit sendCenterTimeID(id, coord); else emit sendCenterTimeID(id, coord / 1000000.0); } @@ -278,7 +278,7 @@ void FlowViewWindow::gotCenterTimeID(int32_t ID, double timestamp) int bestIdx = -1; for (int i = 0; i < frameCache.count(); i++) { - if (frameCache[i].timestamp > t_stamp) + if (frameCache[i].timeStamp().microSeconds() > t_stamp) { bestIdx = i - 1; break; @@ -428,20 +428,20 @@ void FlowViewWindow::updatedFrames(int numFrames) { if (numFrames > modelFrames->count()) return; unsigned int refID; - if (frameCache.count() > 0) refID = frameCache[0].ID; + if (frameCache.count() > 0) refID = frameCache[0].frameId(); else refID = 0; bool needRefresh = false; for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++) { thisFrame = modelFrames->at(i); - if (!foundID.contains(thisFrame.ID)) + if (!foundID.contains(thisFrame.frameId())) { - foundID.append(thisFrame.ID); - FilterUtility::createFilterItem(thisFrame.ID, ui->listFrameID); + foundID.append(thisFrame.frameId()); + FilterUtility::createFilterItem(thisFrame.frameId(), ui->listFrameID); } - if (thisFrame.ID == refID) + if (thisFrame.frameId() == refID) { frameCache.append(thisFrame); @@ -450,18 +450,18 @@ void FlowViewWindow::updatedFrames(int numFrames) if (ui->cbTimeGraph->isChecked()) { if (secondsMode){ - newX[k].append((double)(thisFrame.timestamp) / 1000000.0); + newX[k].append((double)(thisFrame.timeStamp().microSeconds()) / 1000000.0); } else { - newX[k].append(thisFrame.timestamp); + newX[k].append(thisFrame.timeStamp().microSeconds()); } } else { newX[k].append(x[k].count()); } - newY[k].append(thisFrame.data[k]); + newY[k].append(thisFrame.payload()[k]); needRefresh = true; } } @@ -469,7 +469,7 @@ void FlowViewWindow::updatedFrames(int numFrames) if (ui->cbLiveMode->checkState() == Qt::Checked) { currentPosition = frameCache.count() - 1; - memcpy(currBytes, frameCache.at(currentPosition).data, 8); + memcpy(currBytes, frameCache.at(currentPosition).payload(), 8); memcpy(refBytes, currBytes, 8); } @@ -482,7 +482,7 @@ void FlowViewWindow::updatedFrames(int numFrames) } ui->graphView->replot(); updateDataView(); - if (ui->cbSync->checkState() == Qt::Checked) emit sendCenterTimeID(frameCache[currentPosition].ID, frameCache[currentPosition].timestamp / 1000000.0); + if (ui->cbSync->checkState() == Qt::Checked) emit sendCenterTimeID(frameCache[currentPosition].frameId(), frameCache[currentPosition].timeStamp().microSeconds() / 1000000.0); } } updateFrameLabel(); @@ -512,16 +512,16 @@ void FlowViewWindow::createGraph(int byteNum) for (int j = 0; j < numEntries; j++) { - tempVal = frameCache[j].data[byteNum]; + tempVal = frameCache[j].payload()[byteNum]; if (graphByTime) { if (secondsMode){ - x[byteNum][j] = (double)(frameCache[j].timestamp) / 1000000.0; + x[byteNum][j] = (double)(frameCache[j].timeStamp().microSeconds()) / 1000000.0; } else { - x[byteNum][j] = frameCache[j].timestamp; + x[byteNum][j] = frameCache[j].timeStamp().microSeconds(); } } else @@ -551,7 +551,7 @@ void FlowViewWindow::refreshIDList() for (int i = 0; i < modelFrames->count(); i++) { CANFrame thisFrame = modelFrames->at(i); - id = thisFrame.ID; + id = thisFrame.frameId(); if (!foundID.contains(id)) { foundID.append(id); @@ -581,9 +581,9 @@ void FlowViewWindow::changeID(QString newID) for (int x = 0; x < modelFrames->count(); x++) { CANFrame thisFrame = modelFrames->at(x); - if (thisFrame.ID == id) + if (thisFrame.frameId() == id) { - for (int j = thisFrame.len; j < 8; j++) thisFrame.data[j] = 0; + thisFrame.payload().clear(); frameCache.append(thisFrame); } } @@ -600,7 +600,7 @@ void FlowViewWindow::changeID(QString newID) updateGraphLocation(); - memcpy(currBytes, frameCache.at(currentPosition).data, 8); + memcpy(currBytes, frameCache.at(currentPosition).payload(), 8); memcpy(refBytes, currBytes, 8); updateDataView(); @@ -635,7 +635,8 @@ void FlowViewWindow::btnStopClick() playbackActive = false; currentPosition = 0; - memcpy(currBytes, frameCache.at(currentPosition).data, 8); + + memcpy(currBytes, frameCache.at(currentPosition).payload().data_ptr(), 8); memcpy(refBytes, currBytes, 8); updateFrameLabel(); @@ -757,7 +758,7 @@ void FlowViewWindow::updatePosition(bool forward) uint8_t cngByte; for (int i = 0; i < 8; i++) { - cngByte = currBytes[i] ^ frameCache.at(currentPosition).data[i]; + cngByte = currBytes[i] ^ frameCache.at(currentPosition).payload()[i]; changedBits |= (uint64_t)cngByte << (8ull * i); } @@ -771,9 +772,9 @@ void FlowViewWindow::updatePosition(bool forward) playbackTimer->stop(); } - memcpy(currBytes, frameCache.at(currentPosition).data, 8); + memcpy(currBytes, frameCache.at(currentPosition).payload().data(), 8); - if (ui->cbSync->checkState() == Qt::Checked) emit sendCenterTimeID(frameCache[currentPosition].ID, frameCache[currentPosition].timestamp / 1000000.0); + if (ui->cbSync->checkState() == Qt::Checked) emit sendCenterTimeID(frameCache[currentPosition].frameId(), frameCache[currentPosition].timeStamp().microSeconds() / 1000000.0); } void FlowViewWindow::updateGraphLocation() @@ -787,9 +788,9 @@ void FlowViewWindow::updateGraphLocation() { if (secondsMode) { - ui->graphView->xAxis->setRange(frameCache[start].timestamp / 1000000.0, frameCache[end].timestamp / 1000000.0); + ui->graphView->xAxis->setRange(frameCache[start].timeStamp().microSeconds() / 1000000.0, frameCache[end].timeStamp().microSeconds() / 1000000.0); /* - ui->graphView->xAxis->setTickStep((frameCache[end].timestamp - frameCache[start].timestamp)/ 3000000.0); + ui->graphView->xAxis->setTickStep((frameCache[end].timeStamp().microSeconds() - frameCache[start].timeStamp().microSeconds())/ 3000000.0); ui->graphView->xAxis->setSubTickCount(0); ui->graphView->xAxis->setNumberFormat("f"); ui->graphView->xAxis->setNumberPrecision(6); @@ -797,9 +798,9 @@ void FlowViewWindow::updateGraphLocation() } else { - ui->graphView->xAxis->setRange(frameCache[start].timestamp, frameCache[end].timestamp); + ui->graphView->xAxis->setRange(frameCache[start].timeStamp().microSeconds(), frameCache[end].timeStamp().microSeconds()); /* - ui->graphView->xAxis->setTickStep((frameCache[end].timestamp - frameCache[start].timestamp)/ 3.0); + ui->graphView->xAxis->setTickStep((frameCache[end].timeStamp().microSeconds() - frameCache[start].timeStamp().microSeconds())/ 3.0); ui->graphView->xAxis->setSubTickCount(0); ui->graphView->xAxis->setNumberFormat("f"); ui->graphView->xAxis->setNumberPrecision(0); */ diff --git a/re/frameinfowindow.cpp b/re/frameinfowindow.cpp index 894e6f8..3410565 100644 --- a/re/frameinfowindow.cpp +++ b/re/frameinfowindow.cpp @@ -211,14 +211,14 @@ void FrameInfoWindow::updatedFrames(int numFrames) for (int x = modelFrames->count() - numFrames; x < modelFrames->count(); x++) { CANFrame thisFrame = modelFrames->at(x); - int32_t id = static_cast(thisFrame.ID); + int32_t id = static_cast(thisFrame.frameId()); if (!foundID.contains(id)) { foundID.append(id); FilterUtility::createFilterItem(id, ui->listFrameID); } - if (currID == modelFrames->at(x).ID) + if (currID == modelFrames->at(x).frameId()) { thisID = true; break; @@ -275,7 +275,7 @@ void FrameInfoWindow::updateDetailsWindow(QString newID) for (int i = 0; i < modelFrames->count(); i++) { CANFrame thisFrame = modelFrames->at(i); - if (thisFrame.ID == static_cast(targettedID)) frameCache.append(thisFrame); + if (thisFrame.frameId() == static_cast(targettedID)) frameCache.append(thisFrame); } ui->treeDetails->clear(); @@ -285,7 +285,7 @@ void FrameInfoWindow::updateDetailsWindow(QString newID) baseNode = new QTreeWidgetItem(); baseNode->setText(0, QString("ID: ") + newID ); - if (frameCache[0].extended) //if these frames seem to be extended then try for J1939 decoding + if (frameCache[0].hasExtendedFrameFormat()) //if these frames seem to be extended then try for J1939 decoding { // ------- J1939 decoding ---------- J1939ID jid; @@ -367,7 +367,7 @@ void FrameInfoWindow::updateDetailsWindow(QString newID) for (int c = 0; c < 8; c++) { changedBits[c] = 0; - referenceBits[c] = frameCache.at(0).data[c]; + referenceBits[c] = frameCache.at(0).payload()[c]; //qDebug() << referenceBits[c]; } @@ -378,19 +378,19 @@ void FrameInfoWindow::updateDetailsWindow(QString newID) for (int j = 0; j < frameCache.count(); j++) { byteGraphX.append(j); - for (uint32_t bytcnt = 0; bytcnt < frameCache[j].len; bytcnt++) + for (uint32_t bytcnt = 0; bytcnt < frameCache[j].payload().length(); bytcnt++) { - byteGraphY[bytcnt].append(frameCache[j].data[bytcnt]); + byteGraphY[bytcnt].append(frameCache[j].payload()[bytcnt]); } if (j != 0) { //TODO - we try the interval whichever way doesn't go negative. But, we should probably sort the frame list before //starting so that the intervals are all correct. - if (frameCache[j].timestamp > frameCache[j-1].timestamp) - thisInterval = (frameCache[j].timestamp - frameCache[j-1].timestamp); + if (frameCache[j].timeStamp().microSeconds() > frameCache[j-1].timeStamp().microSeconds()) + thisInterval = (frameCache[j].timeStamp().microSeconds() - frameCache[j-1].timeStamp().microSeconds()); else - thisInterval = (frameCache[j-1].timestamp - frameCache[j].timestamp); + thisInterval = (frameCache[j-1].timeStamp().microSeconds() - frameCache[j].timeStamp().microSeconds()); sortedIntervals.push_back(thisInterval); intervalSum += thisInterval; @@ -398,12 +398,12 @@ void FrameInfoWindow::updateDetailsWindow(QString newID) if (thisInterval < minInterval) minInterval = thisInterval; avgInterval += thisInterval; } - thisLen = frameCache.at(j).len; + thisLen = frameCache.at(j).payload().length(); if (thisLen > maxLen) maxLen = thisLen; if (thisLen < minLen) minLen = thisLen; for (int c = 0; c < thisLen; c++) { - unsigned char dat = frameCache.at(j).data[c]; + unsigned char dat = frameCache.at(j).payload()[c]; if (minData[c] > dat) minData[c] = dat; if (maxData[c] < dat) maxData[c] = dat; dataHistogram[dat][c]++; //add one to count for this @@ -600,7 +600,7 @@ void FrameInfoWindow::refreshIDList() for (int i = 0; i < modelFrames->count(); i++) { CANFrame thisFrame = modelFrames->at(i); - id = (int)thisFrame.ID; + id = (int)thisFrame.frameId(); if (!foundID.contains(id)) { foundID.append(id); diff --git a/re/fuzzingwindow.cpp b/re/fuzzingwindow.cpp index 43c60c7..57a5238 100644 --- a/re/fuzzingwindow.cpp +++ b/re/fuzzingwindow.cpp @@ -94,7 +94,7 @@ void FuzzingWindow::updatedFrames(int numFrames) if (numFrames > modelFrames->count()) return; for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++) { - id = modelFrames->at(i).ID; + id = modelFrames->at(i).frameId(); if (!foundIDs.contains(id)) { foundIDs.append(id); @@ -133,17 +133,17 @@ void FuzzingWindow::changedNumDataBytes(int newVal) void FuzzingWindow::timerTriggered() { CANFrame thisFrame; - thisFrame.remote = false; sendingBuffer.clear(); int buses = ui->cbBuses->currentIndex(); for (int count = 0; count < ui->spinBurst->value(); count++) { - thisFrame.ID = currentID; - for (int i = 0; i < 8; i++) thisFrame.data[i] = currentBytes[i]; - if (currentID > 0x7FF) thisFrame.extended = true; - else thisFrame.extended = false; - thisFrame.bus = 0; //hard coded for now. TODO: do not hard code - thisFrame.len = ui->spinBytes->value(); + thisFrame.setFrameId(currentID); + QByteArray bytes(ui->spinBytes->value(), 0); + for (int i = 0; i < bytes.length(); i++) bytes[i] = currentBytes[i]; + thisFrame.setPayload(bytes); + if (currentID > 0x7FF) thisFrame.setExtendedFrameFormat(true); + else thisFrame.setExtendedFrameFormat(false); + thisFrame.bus = 0; //hard coded for now. TODO: do not hard code if (buses < (ui->cbBuses->count() - 1)) { @@ -371,7 +371,7 @@ void FuzzingWindow::refreshIDList() for (int i = 0; i < modelFrames->count(); i++) { CANFrame thisFrame = modelFrames->at(i); - id = thisFrame.ID; + id = thisFrame.frameId(); if (!foundIDs.contains(id)) { foundIDs.append(id); diff --git a/re/graphingwindow.cpp b/re/graphingwindow.cpp index d33d439..6a709ab 100644 --- a/re/graphingwindow.cpp +++ b/re/graphingwindow.cpp @@ -186,7 +186,7 @@ void GraphingWindow::updatedFrames(int numFrames) for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++) { thisFrame = modelFrames->at(i); - if (graphParams[j].ID == thisFrame.ID) + if (graphParams[j].ID == thisFrame.frameId()) { appendToGraph(graphParams[j], thisFrame, x, y); appendedToGraph = true; @@ -1075,15 +1075,15 @@ void GraphingWindow::appendToGraph(GraphParams ¶ms, CANFrame &frame, QVector { params.strideSoFar = 0; int64_t tempVal; //64 bit temp value. - tempVal = Utility::processIntegerSignal(frame.data, params.startBit, params.numBits, params.intelFormat, params.isSigned); //& params.mask; + tempVal = Utility::processIntegerSignal(frame.payload(), params.startBit, params.numBits, params.intelFormat, params.isSigned); //& params.mask; double xVal, yVal; if (secondsMode) { - xVal = ((double)(frame.timestamp) / 1000000.0 - params.xbias); + xVal = ((double)(frame.timeStamp().microSeconds()) / 1000000.0 - params.xbias); } else { - xVal = (frame.timestamp - params.xbias); + xVal = (frame.timeStamp().microSeconds() - params.xbias); } yVal = (tempVal * params.scale) + params.bias; params.x.append(xVal); @@ -1113,7 +1113,7 @@ void GraphingWindow::createGraph(GraphParams ¶ms, bool createGraphParam) for (int i = 0; i < modelFrames->count(); i++) { CANFrame thisFrame = modelFrames->at(i); - if (thisFrame.ID == params.ID && thisFrame.remote == false) frameCache.append(thisFrame); + if (thisFrame.frameId() == params.ID && thisFrame.frameType() == QCanBusFrame::DataFrame) frameCache.append(thisFrame); } //to fix weirdness where a graph that has no data won't be able to be edited, selected, or deleted properly @@ -1122,12 +1122,10 @@ void GraphingWindow::createGraph(GraphParams ¶ms, bool createGraphParam) if (frameCache.count() == 0) { CANFrame dummy; - dummy.ID = params.ID; + dummy.setFrameId(params.ID); dummy.bus = 0; - dummy.len = 8; - dummy.remote = false; - dummy.timestamp = 0; - for (int i = 0; i < 8; i++) dummy.data[i] = 0; + dummy.setPayload(QByteArray(8, 0)); + dummy.setFrameType(QCanBusFrame::DataFrame); frameCache.append(dummy); } @@ -1147,15 +1145,15 @@ void GraphingWindow::createGraph(GraphParams ¶ms, bool createGraphParam) for (int j = 0; j < numEntries; j++) { int k = j * params.stride; - tempVal = Utility::processIntegerSignal(frameCache[k].data, sBit, bits, intelFormat, isSigned); //& params.mask; + tempVal = Utility::processIntegerSignal(frameCache[k].payload(), sBit, bits, intelFormat, isSigned); //& params.mask; //qDebug() << tempVal; if (secondsMode) { - params.x[j] = (frameCache[k].timestamp) / 1000000.0; + params.x[j] = (frameCache[k].timeStamp().microSeconds()) / 1000000.0; } else { - params.x[j] = frameCache[k].timestamp; + params.x[j] = frameCache[k].timeStamp.microSeconds(); } params.y[j] = (tempVal * params.scale) + params.bias; if (params.y[j] < yminval) yminval = params.y[j]; diff --git a/re/rangestatewindow.cpp b/re/rangestatewindow.cpp index e51f264..30ccd44 100644 --- a/re/rangestatewindow.cpp +++ b/re/rangestatewindow.cpp @@ -158,10 +158,10 @@ void RangeStateWindow::updatedFrames(int numFrames) for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++) { thisFrame = modelFrames->at(i); - if (!idFilters.contains(thisFrame.ID)) + if (!idFilters.contains(thisFrame.frameId())) { - idFilters.insert(thisFrame.ID, true); - QListWidgetItem* listItem = new QListWidgetItem(Utility::formatCANID(thisFrame.ID, thisFrame.extended), ui->listFilter); + idFilters.insert(thisFrame.frameId(), true); + QListWidgetItem* listItem = new QListWidgetItem(Utility::formatCANID(thisFrame.frameId(), thisFrame.hasExtendedFrameFormat()), ui->listFilter); listItem->setFlags(listItem->flags() | Qt::ItemIsUserCheckable); // set checkable flag listItem->setCheckState(Qt::Checked); //default all filters to be set active } @@ -178,7 +178,7 @@ void RangeStateWindow::refreshFilterList() for (int i = 0; i < modelFrames->length(); i++) { - id = modelFrames->at(i).ID; + id = modelFrames->at(i).frameId(); if (!idFilters.contains(id)) { idFilters.insert(id, true); @@ -223,7 +223,7 @@ void RangeStateWindow::recalcButton() id = iter.key(); for (int j = 0; j < modelFrames->count(); j++) { - if (modelFrames->at(j).ID == id) frameCache.append(modelFrames->at(j)); + if (modelFrames->at(j).frameId() == id) frameCache.append(modelFrames->at(j)); } //now we've got a list with all the same ID. Time to send it off for processing signalsFactory(); @@ -247,7 +247,7 @@ void RangeStateWindow::signalsFactory() int granularity = ui->spinGranularity->value(); int sigType = ui->cbSignalMode->currentIndex() + 1; int signedType = ui->cbSignedMode->currentIndex() + 1; - int maxBits = frameCache.at(0).len * 8; + int maxBits = frameCache.at(0).payload().length() * 8; int sens = ui->slideSensitivity->value(); for (int sigSize = maxSig; sigSize >= minSig; sigSize -= granularity) @@ -297,7 +297,7 @@ bool RangeStateWindow::processSignal(int startBit, int bitLength, int sensitivit for (i = 0; i < numFrames; i++) { - valu = Utility::processIntegerSignal(frameCache.at(i).data, startBit, bitLength, !bigEndian, isSigned); + valu = Utility::processIntegerSignal(frameCache.at(i).payload(), startBit, bitLength, !bigEndian, isSigned); if (valu < lowestValue) lowestValue = valu; if (valu > highestValue) highestValue = valu; } @@ -316,7 +316,7 @@ bool RangeStateWindow::processSignal(int startBit, int bitLength, int sensitivit return false; //doesn't range enough. for (i = 0; i < numFrames; i++) - scaledVals.append((int)((Utility::processIntegerSignal(frameCache.at(i).data, startBit, bitLength, !bigEndian, isSigned) - lowestValue))); + scaledVals.append((int)((Utility::processIntegerSignal(frameCache.at(i).payload(), startBit, bitLength, !bigEndian, isSigned) - lowestValue))); for (i = 1; i < numFrames; i++) { @@ -365,9 +365,9 @@ bool RangeStateWindow::processSignal(int startBit, int bitLength, int sensitivit { //createGraph(scaledVals); QString temp; - temp = "ID: " + QString::number(frameCache.at(0).ID, 16) + " startBit: " + QString::number(startBit) + " len: " + QString::number(bitLength); + temp = "ID: " + QString::number(frameCache.at(0).frameId(), 16) + " startBit: " + QString::number(startBit) + " len: " + QString::number(bitLength); int64_t foundSig; - foundSig = frameCache.at(0).ID; + foundSig = frameCache.at(0).frameId(); foundSig += (int64_t)startBit << 32; foundSig += (int64_t)bitLength << 40; @@ -474,12 +474,12 @@ void RangeStateWindow::clickedSignalList(int idx) for (int j = 0; j < modelFrames->count(); j++) { - if (modelFrames->at(j).ID == id) frameCache.append(modelFrames->at(j)); + if (modelFrames->at(j).frameId() == id) frameCache.append(modelFrames->at(j)); } int numFrames = frameCache.count(); QVector values; values.reserve(numFrames); - for (int i = 0; i < numFrames; i++) values.append((int)((Utility::processIntegerSignal(frameCache.at(i).data, startBit, bitLength, !isBigEndian, isSigned)))); + for (int i = 0; i < numFrames; i++) values.append((int)((Utility::processIntegerSignal(frameCache.at(i).payload(), startBit, bitLength, !isBigEndian, isSigned)))); createGraph(values); } diff --git a/re/sniffer/snifferitem.cpp b/re/sniffer/snifferitem.cpp index b86462b..2267835 100644 --- a/re/sniffer/snifferitem.cpp +++ b/re/sniffer/snifferitem.cpp @@ -10,11 +10,11 @@ SnifferItem::SnifferItem(const CANFrame& pFrame, quint32 seq): mNotch[i] =0; mMarker.data[i] = 0; mMarker.dataTimestamp[i] = 0; - mCurrent.data[i] = pFrame.data[i]; + mCurrent.data[i] = pFrame.payload()[i]; mCurrent.dataTimestamp[i] = seq; } mLastMarker = mMarker; - mCurrent.len = pFrame.len; + mCurrent.len = pFrame.payload().length(); /* that's dirty */ update(pFrame, seq, false); update(pFrame, seq, false); @@ -115,18 +115,18 @@ void SnifferItem::update(const CANFrame& pFrame, quint32 timeSeq, bool mute) /* copy new value */ for (int i = 0; i < 8; i++) { - maskedData = pFrame.data[i]; + maskedData = pFrame.payload()[i]; if (mute) maskedData &= ~mNotch[i]; maskedCurr = mCurrent.data[i]; if (mute) maskedCurr &= ~mNotch[i]; if (maskedCurr != maskedData) { - mCurrent.data[i] = pFrame.data[i]; + mCurrent.data[i] = pFrame.payload()[i]; mCurrent.dataTimestamp[i] = timeSeq; } } - mCurrent.len = pFrame.len; - mCurrentTime = pFrame.timestamp; + mCurrent.len = pFrame.payload().length(); + mCurrentTime = pFrame.timeStamp().microSeconds(); /* update marker */ //We "OR" our stored marker with the changed bits. diff --git a/re/sniffer/sniffermodel.cpp b/re/sniffer/sniffermodel.cpp index 2fb0b77..667c791 100644 --- a/re/sniffer/sniffermodel.cpp +++ b/re/sniffer/sniffermodel.cpp @@ -300,20 +300,20 @@ void SnifferModel::update(CANConnection*, QVector& pFrames) { foreach(const CANFrame& frame, pFrames) { - if(!mMap.contains(frame.ID)) + if(!mMap.contains(frame.frameId())) { - int index = std::distance(mMap.begin(), mMap.lowerBound(frame.ID)); + int index = std::distance(mMap.begin(), mMap.lowerBound(frame.frameId())); /* add the frame */ beginInsertRows(QModelIndex(), index, index); - mMap[frame.ID] = new SnifferItem(frame, mTimeSequence); - mMap[frame.ID]->update(frame, mTimeSequence, mMuteNotched); + mMap[frame.frameId()] = new SnifferItem(frame, mTimeSequence); + mMap[frame.frameId()]->update(frame, mTimeSequence, mMuteNotched); endInsertRows(); - emit idChange(frame.ID, true); + emit idChange(frame.frameId(), true); } else //updateData - mMap[frame.ID]->update(frame, mTimeSequence, mMuteNotched); + mMap[frame.frameId()]->update(frame, mTimeSequence, mMuteNotched); } } diff --git a/re/temporalgraphwindow.cpp b/re/temporalgraphwindow.cpp index afd4d42..2b3ff4c 100644 --- a/re/temporalgraphwindow.cpp +++ b/re/temporalgraphwindow.cpp @@ -196,13 +196,13 @@ void TemporalGraphWindow::generateGraph() x.reserve(frameCount); y.reserve(frameCount); - xminval = xmaxval = modelFrames->at(0).timestamp / 1000000.0; - yminval = ymaxval = modelFrames->at(0).ID; + xminval = xmaxval = modelFrames->at(0).timeStamp().microSeconds() / 1000000.0; + yminval = ymaxval = modelFrames->at(0).frameId(); for (int i = 0; i < frameCount; i++) { - x.append(modelFrames->at(i).timestamp / 1000000.0); - y.append(modelFrames->at(i).ID); + x.append(modelFrames->at(i).timeStamp().microSeconds() / 1000000.0); + y.append(modelFrames->at(i).frameId()); if (x[i] > xmaxval) xmaxval = x[i]; if (x[i] < xminval) xminval = x[i]; if (y[i] > ymaxval) ymaxval = y[i]; @@ -246,8 +246,8 @@ void TemporalGraphWindow::generateGraph() for (int i = 0; i < frameCount; i++) { - int x = static_cast(((modelFrames->at(i).timestamp / 1000000.0) - xminval) * 4.0); - int y = static_cast(modelFrames->at(i).ID - yminval) / 30; + int x = static_cast(((modelFrames->at(i).timeStamp().microSeconds() / 1000000.0) - xminval) * 4.0); + int y = static_cast(modelFrames->at(i).frameId() - yminval) / 30; double val = colorMap->data()->cell(x, y); double inc; inc = 1 / (val + 1); //logarithmic decay diff --git a/utility.h b/utility.h index e9f8b65..8160aa7 100644 --- a/utility.h +++ b/utility.h @@ -179,7 +179,7 @@ public: return (value1 * (1.0 - samplePoint)) + (value2 * samplePoint); } - static int64_t processIntegerSignal(const uint8_t *data, int startBit, int sigSize, bool littleEndian, bool isSigned) + static int64_t processIntegerSignal(const QByteArray data, int startBit, int sigSize, bool littleEndian, bool isSigned) { int64_t result = 0;