Skip to content

Commit

Permalink
add pcan config ui
Browse files Browse the repository at this point in the history
  • Loading branch information
HubertD committed Jan 21, 2016
1 parent 27f6039 commit eb926c9
Show file tree
Hide file tree
Showing 7 changed files with 226 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/driver/PeakCanDriver/PeakCanDriver.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#include "PeakCanDriver.h"
#include "PeakCanInterface.h"
#include "PeakCanSetupPage.h"

#include <windows.h>
#include "pcan-basic-api/Include/PCANBasic.h"

PeakCanDriver::PeakCanDriver(Backend &backend)
: CanDriver(backend)
: CanDriver(backend),
setupPage(new PeakCanSetupPage(0))
{
QObject::connect(&backend, SIGNAL(onSetupDialogCreated(SetupDialog&)), setupPage, SLOT(onSetupDialogCreated(SetupDialog&)));
}

QString PeakCanDriver::getName()
Expand Down
2 changes: 2 additions & 0 deletions src/driver/PeakCanDriver/PeakCanDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <driver/CanDriver.h>

class PeakCanInterface;
class PeakCanSetupPage;

class PeakCanDriver : public CanDriver
{
Expand All @@ -16,6 +17,7 @@ class PeakCanDriver : public CanDriver

private:
PeakCanInterface *createOrUpdateInterface(uint32_t hnd);
PeakCanSetupPage *setupPage;

};

Expand Down
9 changes: 7 additions & 2 deletions src/driver/PeakCanDriver/PeakCanDriver.pri
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
SOURCES += \
$$PWD/PeakCanDriver.cpp \
$$PWD/PeakCanInterface.cpp
$$PWD/PeakCanInterface.cpp \
$$PWD/PeakCanSetupPage.cpp

win32:LIBS += -L$$PWD/pcan-basic-api/Win32/VC_LIB/ -lPCANBasic
win32:INCLUDEPATH += $$PWD/pcan-basic-api/Win32/VC_LIB
win32:DEPENDPATH += $$PWD/pcan-basic-api/Win32/VC_LIB

HEADERS += \
$$PWD/PeakCanInterface.h
$$PWD/PeakCanInterface.h \
$$PWD/PeakCanSetupPage.h

FORMS += \
$$PWD/PeakCanSetupPage.ui
7 changes: 6 additions & 1 deletion src/driver/PeakCanDriver/PeakCanInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ QList<int> PeakCanInterface::getAvailableFdBitrates()

void PeakCanInterface::open()
{
if (CAN_Initialize(_handle, PCAN_BAUD_500K)==PCAN_ERROR_OK) {
uint32_t bitrate_adapt = PCAN_PARAMETER_ON;
if (CAN_SetValue(_handle, PCAN_BITRATE_ADAPTING, &bitrate_adapt, sizeof(bitrate_adapt))!=PCAN_ERROR_OK) {
Backend::instance().logMessage(log_level_error, QString("could not set bitrate adapt parameter for CAN channel: %1").arg(getName()));
}

if (CAN_Initialize(_handle, PCAN_BAUD_500K)==PCAN_ERROR_OK) { // TODO check if bitrate could not be changed...
Backend::instance().logMessage(log_level_info, QString("CAN channel %1 initialized").arg(getName()));
} else {
Backend::instance().logMessage(log_level_error, QString("could not initialize CAN channel: %1").arg(getName()));
Expand Down
79 changes: 79 additions & 0 deletions src/driver/PeakCanDriver/PeakCanSetupPage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include "PeakCanSetupPage.h"
#include "ui_PeakCanSetupPage.h"

#include <Backend.h>
#include <model/MeasurementInterface.h>
#include <window/SetupDialog/SetupDialog.h>
#include "PeakCanInterface.h"

PeakCanSetupPage::PeakCanSetupPage(QWidget *parent) :
QWidget(parent),
ui(new Ui::PeakCanSetupPage),
_mi(0),
_enable_ui_updates(true)
{
ui->setupUi(this);

connect(ui->cbListenOnly, SIGNAL(stateChanged(int)), this, SLOT(updateUI()));
connect(ui->cbAutoRestart, SIGNAL(stateChanged(int)), this, SLOT(updateUI()));
connect(ui->cbBitrate, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
}

PeakCanSetupPage::~PeakCanSetupPage()
{
delete ui;
}

void PeakCanSetupPage::onSetupDialogCreated(SetupDialog &dlg)
{
dlg.addPage(this);
connect(&dlg, SIGNAL(onShowInterfacePage(SetupDialog&,MeasurementInterface*)), this, SLOT(onShowInterfacePage(SetupDialog&,MeasurementInterface*)));
}

void PeakCanSetupPage::onShowInterfacePage(SetupDialog &dlg, MeasurementInterface *mi)
{
PeakCanInterface *pci = 0;
if (mi && (backend().getDriverName(mi->canInterface()) == "PCAN")) {
_mi = mi;
pci = (PeakCanInterface*)backend().getInterfaceById(_mi->canInterface());
} else {
return;
}

_enable_ui_updates = false;

ui->laDriver->setText(backend().getDriverName(_mi->canInterface()));
ui->laInterfaceName->setText(backend().getInterfaceName(_mi->canInterface()));

ui->cbListenOnly->setChecked(_mi->isListenOnlyMode());
ui->cbAutoRestart->setChecked(_mi->doAutoRestart());

ui->cbBitrate->clear();
foreach (int br, pci->getAvailableBitrates()) {
ui->cbBitrate->addItem(QString::number(br));
}
ui->cbBitrate->setCurrentText(QString::number(_mi->bitrate()));

_enable_ui_updates = true;

dlg.displayPage(this);
updateUI();
}

void PeakCanSetupPage::updateUI()
{
PeakCanInterface *pci = (PeakCanInterface*)backend().getInterfaceById(_mi->canInterface());

if ((!_enable_ui_updates) || (pci==0)) {
return;
}

_mi->setListenOnlyMode(ui->cbListenOnly->isChecked());
_mi->setAutoRestart(ui->cbAutoRestart->isChecked());
_mi->setBitrate(ui->cbBitrate->currentText().toInt());
}

Backend &PeakCanSetupPage::backend()
{
return Backend::instance();
}
37 changes: 37 additions & 0 deletions src/driver/PeakCanDriver/PeakCanSetupPage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef PEAKCANSETUPPAGE_H
#define PEAKCANSETUPPAGE_H

#include <QWidget>

namespace Ui {
class PeakCanSetupPage;
}

class Backend;
class SetupDialog;
class MeasurementInterface;

class PeakCanSetupPage : public QWidget
{
Q_OBJECT

public:
explicit PeakCanSetupPage(QWidget *parent);
~PeakCanSetupPage();

public slots:
void onSetupDialogCreated(SetupDialog &dlg);
void onShowInterfacePage(SetupDialog &dlg, MeasurementInterface *mi);

private slots:
void updateUI();

private:
Ui::PeakCanSetupPage *ui;
MeasurementInterface *_mi;
bool _enable_ui_updates;

Backend &backend();
};

#endif // PEAKCANSETUPPAGE_H
90 changes: 90 additions & 0 deletions src/driver/PeakCanDriver/PeakCanSetupPage.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PeakCanSetupPage</class>
<widget class="QWidget" name="PeakCanSetupPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>876</width>
<height>549</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Driver:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="laDriver">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Interface:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="laInterfaceName">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_26">
<property name="text">
<string>Bitrate:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="cbBitrate"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="laOptions">
<property name="text">
<string>Options:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="topMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>15</number>
</property>
<item>
<widget class="QCheckBox" name="cbListenOnly">
<property name="text">
<string>Listen only</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbAutoRestart">
<property name="text">
<string>Automatic restart after bus off condition</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

0 comments on commit eb926c9

Please sign in to comment.