From 39da1be089969df21beff839d323cbe827ac5c80 Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Thu, 21 May 2015 21:31:56 -0400 Subject: [PATCH] Add version # to window title, additional work on DBC stuff, removed a bunch of debug messages, removed more references to baud. --- canframemodel.cpp | 30 ++++++++++++++++++++++++++++++ canframemodel.h | 7 +++++++ dbchandler.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ dbchandler.h | 13 ++++++++++--- mainwindow.cpp | 14 ++++++++++---- mainwindow.h | 2 ++ mainwindow.ui | 18 ++++++++++++++++-- serialworker.cpp | 8 +++++--- 8 files changed, 121 insertions(+), 12 deletions(-) diff --git a/canframemodel.cpp b/canframemodel.cpp index b7c47a1..b5c7cc8 100644 --- a/canframemodel.cpp +++ b/canframemodel.cpp @@ -14,6 +14,24 @@ CANFrameModel::CANFrameModel(QObject *parent) : QAbstractTableModel(parent) { frames.reserve(100000); //ask for at least 100,000 entries. This gives good performance up to this limit + dbcHandler = NULL; + interpretFrames = false; + overwriteDups = false; +} + +void CANFrameModel::setDBCHandler(DBCHandler *handler) +{ + dbcHandler = handler; +} + +void CANFrameModel::setInterpetMode(bool mode) +{ + interpretFrames = mode; +} + +void CANFrameModel::setOverwriteMode(bool mode) +{ + overwriteDups = mode; } QVariant CANFrameModel::data(const QModelIndex &index, int role) const @@ -51,6 +69,18 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const tempString.append(QString::number(thisFrame.data[i], 16).toUpper().rightJustified(2,'0')); tempString.append(" "); } + //now, if we're supposed to interpret the data and the DBC handler is loaded then use it + if (dbcHandler != NULL) + { + DBC_MESSAGE *msg = dbcHandler->findMsgByID(thisFrame.ID); + if (msg != NULL) + { + for (int j = 0; j < msg->msgSignals.length(); j++) + { + + } + } + } return tempString; break; default: diff --git a/canframemodel.h b/canframemodel.h index b50ef67..bea2174 100644 --- a/canframemodel.h +++ b/canframemodel.h @@ -4,6 +4,7 @@ #include #include #include "can_structs.h" +#include "dbchandler.h" class CANFrameModel: public QAbstractTableModel { @@ -22,11 +23,17 @@ public: void sendRefresh(); void sendRefresh(int); void clearFrames(); + void setDBCHandler(DBCHandler *); + void setInterpetMode(bool); + void setOverwriteMode(bool); QList *getListReference(); private: QList frames; + DBCHandler *dbcHandler; + bool interpretFrames; //should we use the dbcHandler? + bool overwriteDups; //should we display all frames or only the newest for each ID? }; diff --git a/dbchandler.cpp b/dbchandler.cpp index dbdb24b..239640a 100644 --- a/dbchandler.cpp +++ b/dbchandler.cpp @@ -318,3 +318,44 @@ void DBCHandler::listDebugging() } } } + + +//DBC files use what I'd consider a completely stupid way to count bits. The lowest bit +//in a byte is 7 while the highest is 0. So, the counting for a byte goes like this: +//0 1 2 3 4 5 6 7. That only makes sense if you write it out like that. In reality bits are stored +//7 6 5 4 3 2 1 0. So, plan accordingly. It's confusing when you're used to bit 7 being the highest, not lowest +//But, bytes are still in order. Byte 0 is the first byte, byte 7 would be the last byte in a frame. +//So, the lowest bit of the last byte is 63. The upshot is that, if you took all the bytes in a canbus +//frame and started labeling from left to right you would really number 0 to 63 in complete order. It's +//just that computers don't store data like that. Have I mentioned that already? Screw Vector. Go away on a CANoe. +//0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Vector bit ordering +//7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 Bitwise ordering within bytes +//0 1 2 3 Byte ordering +//For intel format invert the starting bit within a byte. +//Otherwise, iterate over the bytes that it encompasses and +void DBCHandler::processSignal(CANFrame *frame, DBC_SIGNAL *sig) +{ + int startBit, endBit, startByte, endByte, bitWithinByteStart, bitWithinByteEnd; + + startBit = sig->startBit; + startByte = startBit / 8; + bitWithinByteStart = startBit % 8; + if (sig->intelByteOrder) + { + bitWithinByteStart = 7 - bitWithinByteStart; + startBit = (startByte * 8) + bitWithinByteStart; + } + + endBit = startBit + sig->signalSize - 1; + endByte = endBit / 8; + bitWithinByteEnd = endBit % 8; + + if (sig->intelByteOrder) //little endian - startBit is least sig. bit + { + + } + else //motorola / big endian - startBit is most sig. bit + { + + } +} diff --git a/dbchandler.h b/dbchandler.h index fa858e3..90b125e 100644 --- a/dbchandler.h +++ b/dbchandler.h @@ -3,6 +3,12 @@ #include #include "dbc_classes.h" +#include "can_structs.h" + +/* + * For ease of quick testing and development this is all run together. + * It should be decoupled once the functionality is confirmed. +*/ class DBCHandler : public QObject { @@ -11,6 +17,10 @@ public: explicit DBCHandler(QObject *parent = 0); void loadDBCFile(QString); void listDebugging(); + void processSignal(CANFrame *frame, DBC_SIGNAL *sig); + DBC_NODE *findNodeByName(QString name); + DBC_MESSAGE *findMsgByID(int id); + DBC_SIGNAL *findSignalByName(DBC_MESSAGE *msg, QString name); signals: @@ -20,9 +30,6 @@ private: QList dbc_nodes; QList dbc_messages; - DBC_NODE *findNodeByName(QString name); - DBC_MESSAGE *findMsgByID(int id); - DBC_SIGNAL *findSignalByName(DBC_MESSAGE *msg, QString name); }; #endif // DBCHANDLER_H diff --git a/mainwindow.cpp b/mainwindow.cpp index ed86259..7bba85e 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -28,6 +28,8 @@ MainWindow::MainWindow(QWidget *parent) : { ui->setupUi(this); + this->setWindowTitle("Savvy CAN V" + QString::number(VERSION)); + model = new CANFrameModel(); ui->canFramesView->setModel(model); @@ -39,7 +41,9 @@ MainWindow::MainWindow(QWidget *parent) : ui->canFramesView->setColumnWidth(2, 40); ui->canFramesView->setColumnWidth(3, 40); ui->canFramesView->setColumnWidth(4, 40); - ui->canFramesView->setColumnWidth(5, 300); + ui->canFramesView->setColumnWidth(5, 275); + QHeaderView *HorzHdr = ui->canFramesView->horizontalHeader(); + HorzHdr->setStretchLastSection(true); //causes the data column to automatically fill the tableview ports = QSerialPortInfo::availablePorts(); @@ -80,6 +84,8 @@ MainWindow::MainWindow(QWidget *parent) : frameSenderWindow = NULL; dbcHandler = new DBCHandler; + model->setDBCHandler(dbcHandler); + connect(ui->btnConnect, SIGNAL(clicked(bool)), this, SLOT(connButtonPress())); connect(ui->actionOpen_Log_File, SIGNAL(triggered(bool)), this, SLOT(handleLoadFile())); connect(ui->actionGraph_Dta, SIGNAL(triggered(bool)), this, SLOT(showGraphingWindow())); @@ -120,10 +126,10 @@ MainWindow::~MainWindow() void MainWindow::updateBaudLabel(int baud0, int baud1) { QString labelText; - labelText = tr("Baud 0: "); + labelText = tr("CAN 0 Speed: "); if (baud0 > 0) labelText += QString::number(baud0 / 1000.0) + "kbps"; else labelText += tr("disabled"); - labelText += tr(" Baud 1: "); + labelText += tr(" CAN 1 Speed: "); if (baud1 > 0) labelText += QString::number(baud1 / 1000.0) + "kbps"; else labelText += tr("disabled"); lbStatusBauds.setText(labelText); @@ -131,7 +137,7 @@ void MainWindow::updateBaudLabel(int baud0, int baud1) void MainWindow::gotFrame(CANFrame *frame) { - qDebug() << "got frame from serial side. ID was " << frame->ID; + //qDebug() << "got frame from serial side. ID was " << frame->ID; addFrameToDisplay(*frame, true); ui->lbNumFrames->setText(QString::number(model->rowCount())); } diff --git a/mainwindow.h b/mainwindow.h index 7727c4e..caffb26 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -13,6 +13,8 @@ #include "framesenderwindow.h" #include "dbchandler.h" +#define VERSION 100 + namespace Ui { class MainWindow; } diff --git a/mainwindow.ui b/mainwindow.ui index 9048e52..cc84b91 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -168,6 +168,13 @@ + + + + Clear Frames + + + @@ -176,9 +183,16 @@ - + - Clear Frames + Interpret Frames + + + + + + + Overwrite Mode diff --git a/serialworker.cpp b/serialworker.cpp index 61d768e..b4c680e 100644 --- a/serialworker.cpp +++ b/serialworker.cpp @@ -77,7 +77,7 @@ void SerialWorker::readSerialData() { QByteArray data = serial->readAll(); unsigned char c; - qDebug() << (tr("Got data from serial. Len = %0").arg(data.length())); + //qDebug() << (tr("Got data from serial. Len = %0").arg(data.length())); for (int i = 0; i < data.length(); i++) { c = data.at(i); @@ -91,7 +91,9 @@ void SerialWorker::sendFrame(const CANFrame *frame, int bus = 0) int c; int ID; - qDebug() << "Sending out frame with id " << frame->ID; + if (!connected) return; + + //qDebug() << "Sending out frame with id " << frame->ID; ID = frame->ID; if (frame->extended) ID |= 1 << 31; @@ -223,7 +225,7 @@ void SerialWorker::procRXChar(unsigned char c) { rx_state = IDLE; rx_step = 0; - qDebug() << "emit from serial handler to main form id: " << buildFrame->ID; + //qDebug() << "emit from serial handler to main form id: " << buildFrame->ID; emit receivedFrame(buildFrame); buildFrame = new CANFrame; }