Add ASCII representation to main window
This commit is contained in:
+21
-4
@@ -40,7 +40,7 @@ int CANFrameModel::totalFrameCount()
|
|||||||
int CANFrameModel::columnCount(const QModelIndex &index) const
|
int CANFrameModel::columnCount(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(index);
|
Q_UNUSED(index);
|
||||||
return 7;
|
return 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
CANFrameModel::CANFrameModel(QObject *parent)
|
CANFrameModel::CANFrameModel(QObject *parent)
|
||||||
@@ -222,7 +222,8 @@ enum class Column {
|
|||||||
Direction = 3, ///< Whether the frame was transmitted or received
|
Direction = 3, ///< Whether the frame was transmitted or received
|
||||||
Bus = 4, ///< The bus where the frame was transmitted or received
|
Bus = 4, ///< The bus where the frame was transmitted or received
|
||||||
Length = 5, ///< The frames payload data length
|
Length = 5, ///< The frames payload data length
|
||||||
Data = 6 ///< The frames payload data
|
ASCII = 6, ///< The payload interpreted as ASCII characters
|
||||||
|
Data = 7 ///< The frames payload data
|
||||||
};
|
};
|
||||||
|
|
||||||
QVariant CANFrameModel::data(const QModelIndex &index, int role) const
|
QVariant CANFrameModel::data(const QModelIndex &index, int role) const
|
||||||
@@ -282,13 +283,27 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const
|
|||||||
return QString::number(thisFrame.bus);
|
return QString::number(thisFrame.bus);
|
||||||
case Column::Length:
|
case Column::Length:
|
||||||
return QString::number(thisFrame.len);
|
return QString::number(thisFrame.len);
|
||||||
case Column::Data:
|
case Column::ASCII:
|
||||||
dLen = thisFrame.len;
|
dLen = thisFrame.len;
|
||||||
if (dLen < 0) dLen = 0;
|
if (dLen < 0) dLen = 0;
|
||||||
if (dLen > 8) dLen = 8;
|
if (dLen > 8) dLen = 8;
|
||||||
for (int i = 0; i < dLen; i++)
|
for (int i = 0; i < dLen; i++)
|
||||||
{
|
{
|
||||||
tempString.append(Utility::formatNumber(thisFrame.data[i]));
|
quint8 byt = thisFrame.data[i];
|
||||||
|
if (byt < 0x20) byt = 0x2E; //A dot
|
||||||
|
if (byt > 0x7E) byt = 0x2E;
|
||||||
|
tempString.append(QString::fromUtf8((char *)&byt, 1));
|
||||||
|
}
|
||||||
|
return tempString;
|
||||||
|
case Column::Data:
|
||||||
|
dLen = thisFrame.len;
|
||||||
|
if (dLen < 0) dLen = 0;
|
||||||
|
if (dLen > 8) dLen = 8;
|
||||||
|
//if (useHexMode) tempString.append("0x ");
|
||||||
|
for (int i = 0; i < dLen; i++)
|
||||||
|
{
|
||||||
|
if (useHexMode) tempString.append( QString::number(thisFrame.data[i], 16).toUpper().rightJustified(2, '0'));
|
||||||
|
else tempString.append(QString::number(thisFrame.data[i], 10));
|
||||||
tempString.append(" ");
|
tempString.append(" ");
|
||||||
}
|
}
|
||||||
//now, if we're supposed to interpret the data and the DBC handler is loaded then use it
|
//now, if we're supposed to interpret the data and the DBC handler is loaded then use it
|
||||||
@@ -339,6 +354,8 @@ QVariant CANFrameModel::headerData(int section, Qt::Orientation orientation,
|
|||||||
return QString(tr("Bus"));
|
return QString(tr("Bus"));
|
||||||
case Column::Length:
|
case Column::Length:
|
||||||
return QString(tr("Len"));
|
return QString(tr("Len"));
|
||||||
|
case Column::ASCII:
|
||||||
|
return QString(tr("ASCII"));
|
||||||
case Column::Data:
|
case Column::Data:
|
||||||
return QString(tr("Data"));
|
return QString(tr("Data"));
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-7
@@ -50,13 +50,14 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
|
|
||||||
readSettings();
|
readSettings();
|
||||||
|
|
||||||
ui->canFramesView->setColumnWidth(0, 150);
|
ui->canFramesView->setColumnWidth(0, 150); //time stamp
|
||||||
ui->canFramesView->setColumnWidth(1, 70);
|
ui->canFramesView->setColumnWidth(1, 70); //frame ID
|
||||||
ui->canFramesView->setColumnWidth(2, 40);
|
ui->canFramesView->setColumnWidth(2, 40); //extended
|
||||||
ui->canFramesView->setColumnWidth(3, 40);
|
ui->canFramesView->setColumnWidth(3, 40); //direction
|
||||||
ui->canFramesView->setColumnWidth(4, 40);
|
ui->canFramesView->setColumnWidth(4, 40); //bus
|
||||||
ui->canFramesView->setColumnWidth(5, 40);
|
ui->canFramesView->setColumnWidth(5, 40); //length
|
||||||
ui->canFramesView->setColumnWidth(6, 225);
|
ui->canFramesView->setColumnWidth(6, 50); //ascii
|
||||||
|
ui->canFramesView->setColumnWidth(7, 225); //data
|
||||||
QHeaderView *HorzHdr = ui->canFramesView->horizontalHeader();
|
QHeaderView *HorzHdr = ui->canFramesView->horizontalHeader();
|
||||||
HorzHdr->setStretchLastSection(true); //causes the data column to automatically fill the tableview
|
HorzHdr->setStretchLastSection(true); //causes the data column to automatically fill the tableview
|
||||||
connect(HorzHdr, SIGNAL(sectionClicked(int)), this, SLOT(headerClicked(int)));
|
connect(HorzHdr, SIGNAL(sectionClicked(int)), this, SLOT(headerClicked(int)));
|
||||||
|
|||||||
Reference in New Issue
Block a user