First implementation
This commit is contained in:
109
cpp/window/CanStatusWindow/CanStatusWindow.cpp
Normal file
109
cpp/window/CanStatusWindow/CanStatusWindow.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2016 Hubert Denkmair <hubert@denkmair.de>
|
||||
|
||||
This file is part of cangaroo.
|
||||
|
||||
cangaroo is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
cangaroo is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with cangaroo. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include "CanStatusWindow.h"
|
||||
#include "ui_CanStatusWindow.h"
|
||||
|
||||
#include <QStringList>
|
||||
#include <QTimer>
|
||||
#include <core/Backend.h>
|
||||
#include <core/MeasurementSetup.h>
|
||||
#include <core/MeasurementNetwork.h>
|
||||
#include <core/MeasurementInterface.h>
|
||||
|
||||
CanStatusWindow::CanStatusWindow(QWidget *parent, Backend &backend) :
|
||||
ConfigurableWidget(parent),
|
||||
ui(new Ui::CanStatusWindow),
|
||||
_backend(backend),
|
||||
_timer(new QTimer(this))
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->treeWidget->setHeaderLabels(QStringList()
|
||||
<< "Driver" << "Interface" << "State"
|
||||
<< "Rx Frames" << "Rx Errors" << "Rx Overrun"
|
||||
<< "Tx Frames" << "Tx Errors" << "Tx Dropped"
|
||||
<< "# Warning" << "# Passive" << "# Bus Off" << " #Restarts"
|
||||
);
|
||||
ui->treeWidget->setColumnWidth(0, 80);
|
||||
ui->treeWidget->setColumnWidth(1, 70);
|
||||
|
||||
connect(&backend, SIGNAL(beginMeasurement()), this, SLOT(beginMeasurement()));
|
||||
connect(&backend, SIGNAL(endMeasurement()), this, SLOT(endMeasurement()));
|
||||
connect(_timer, SIGNAL(timeout()), this, SLOT(update()));
|
||||
}
|
||||
|
||||
CanStatusWindow::~CanStatusWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void CanStatusWindow::beginMeasurement()
|
||||
{
|
||||
ui->treeWidget->clear();
|
||||
foreach (CanInterfaceId ifid, backend().getInterfaceList()) {
|
||||
CanInterface *intf = backend().getInterfaceById(ifid);
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem(ui->treeWidget);
|
||||
item->setData(0, Qt::UserRole, QVariant::fromValue((void*)intf));
|
||||
item->setText(column_driver, intf->getDriver()->getName());
|
||||
item->setText(column_interface, intf->getName());
|
||||
|
||||
item->setTextAlignment(column_driver, Qt::AlignLeft);
|
||||
item->setTextAlignment(column_interface, Qt::AlignLeft);
|
||||
item->setTextAlignment(column_state, Qt::AlignCenter);
|
||||
for (int i=column_rx_frames; i<column_count; i++) {
|
||||
item->setTextAlignment(i, Qt::AlignRight);
|
||||
}
|
||||
|
||||
ui->treeWidget->addTopLevelItem(item);
|
||||
}
|
||||
update();
|
||||
_timer->start(100);
|
||||
}
|
||||
|
||||
void CanStatusWindow::endMeasurement()
|
||||
{
|
||||
_timer->stop();
|
||||
}
|
||||
|
||||
void CanStatusWindow::update()
|
||||
{
|
||||
for (QTreeWidgetItemIterator it(ui->treeWidget); *it; ++it) {
|
||||
QTreeWidgetItem *item = *it;
|
||||
CanInterface *intf = (CanInterface *)item->data(0, Qt::UserRole).value<void *>();
|
||||
if (intf) {
|
||||
intf->updateStatistics();
|
||||
item->setText(column_state, intf->getStateText());
|
||||
item->setText(column_rx_frames, QString().number(intf->getNumRxFrames()));
|
||||
item->setText(column_rx_errors, QString().number(intf->getNumRxErrors()));
|
||||
item->setText(column_rx_overrun, QString().number(intf->getNumRxOverruns()));
|
||||
item->setText(column_tx_frames, QString().number(intf->getNumTxFrames()));
|
||||
item->setText(column_tx_errors, QString().number(intf->getNumTxErrors()));
|
||||
item->setText(column_tx_dropped, QString().number(intf->getNumTxDropped()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Backend &CanStatusWindow::backend()
|
||||
{
|
||||
return _backend;
|
||||
}
|
||||
70
cpp/window/CanStatusWindow/CanStatusWindow.h
Normal file
70
cpp/window/CanStatusWindow/CanStatusWindow.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2016 Hubert Denkmair <hubert@denkmair.de>
|
||||
|
||||
This file is part of cangaroo.
|
||||
|
||||
cangaroo is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
cangaroo is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with cangaroo. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <core/ConfigurableWidget.h>
|
||||
|
||||
namespace Ui {
|
||||
class CanStatusWindow;
|
||||
}
|
||||
|
||||
class Backend;
|
||||
class QTimer;
|
||||
|
||||
class CanStatusWindow : public ConfigurableWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum {
|
||||
column_driver,
|
||||
column_interface,
|
||||
column_state,
|
||||
column_rx_frames,
|
||||
column_rx_errors,
|
||||
column_rx_overrun,
|
||||
column_tx_frames,
|
||||
column_tx_errors,
|
||||
column_tx_dropped,
|
||||
column_num_warning,
|
||||
column_num_passive,
|
||||
column_num_busoff,
|
||||
column_num_restarts,
|
||||
column_count
|
||||
};
|
||||
|
||||
public:
|
||||
explicit CanStatusWindow(QWidget *parent, Backend &backend);
|
||||
~CanStatusWindow();
|
||||
|
||||
private slots:
|
||||
void beginMeasurement();
|
||||
void endMeasurement();
|
||||
void update();
|
||||
|
||||
private:
|
||||
Ui::CanStatusWindow *ui;
|
||||
Backend &_backend;
|
||||
|
||||
Backend &backend();
|
||||
QTimer *_timer;
|
||||
};
|
||||
8
cpp/window/CanStatusWindow/CanStatusWindow.pri
Normal file
8
cpp/window/CanStatusWindow/CanStatusWindow.pri
Normal file
@@ -0,0 +1,8 @@
|
||||
SOURCES += \
|
||||
$$PWD/CanStatusWindow.cpp \
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/CanStatusWindow.h \
|
||||
|
||||
FORMS += \
|
||||
$$PWD/CanStatusWindow.ui \
|
||||
114
cpp/window/CanStatusWindow/CanStatusWindow.ui
Normal file
114
cpp/window/CanStatusWindow/CanStatusWindow.ui
Normal file
@@ -0,0 +1,114 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CanStatusWindow</class>
|
||||
<widget class="QWidget" name="CanStatusWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>756</width>
|
||||
<height>459</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Can Status</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTreeWidget" name="treeWidget">
|
||||
<property name="indentation">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="itemsExpandable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="columnCount">
|
||||
<number>13</number>
|
||||
</property>
|
||||
<attribute name="headerDefaultSectionSize">
|
||||
<number>80</number>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">1</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">2</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">3</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">4</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">5</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">6</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">7</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">8</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">9</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">10</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">11</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">12</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">13</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user