Skip to content
Permalink
Browse files

working towards a unified interface setup dialog

  • Loading branch information...
HubertD committed May 17, 2016
1 parent 6ac97f2 commit 37e0a5247cfdd025904cae8c9e8d4c3790afeda5
@@ -28,6 +28,7 @@
MeasurementInterface::MeasurementInterface()
: _doConfigure(false),
_isListenOnlyMode(false),
_isOneShotMode(false),
_isTripleSampling(false),
_isCanFD(false),
_isSimpleTiming(true),
@@ -47,7 +48,7 @@ MeasurementInterface::MeasurementInterface()
_fdPhaseSeg2(1),
_doSetFdSJW(false),
_fdSjw(1),
_doAutoRestart(true),
_doAutoRestart(false),
_autoRestartMs(100)
{

@@ -59,6 +60,7 @@ bool MeasurementInterface::loadXML(Backend &backend, QDomElement &el)

_doConfigure = el.attribute("configure", "0").toInt() != 0;
_isListenOnlyMode = el.attribute("listen-only", "0").toInt() != 0;
_isOneShotMode = el.attribute("one-shot", "0").toInt() != 0;
_isTripleSampling = el.attribute("triple-sampling", "0").toInt() != 0;
_isCanFD = el.attribute("can-fd", "0").toInt() != 0;
_isSimpleTiming = el.attribute("timing-mode", "bitrate") == "bitrate";
@@ -101,6 +103,7 @@ bool MeasurementInterface::saveXML(Backend &backend, QDomDocument &xml, QDomElem

root.setAttribute("configure", _doConfigure ? 1 : 0);
root.setAttribute("listen-only", _isListenOnlyMode ? 1 : 0);
root.setAttribute("one-shot", _isOneShotMode ? 1 : 0);
root.setAttribute("triple-sampling", _isTripleSampling ? 1 : 0);
root.setAttribute("can-fd", _isCanFD ? 1 : 0);
root.setAttribute("timing-mode", _isSimpleTiming ? "bitrate" : "registers");
@@ -183,6 +186,16 @@ void MeasurementInterface::setListenOnlyMode(bool isListenOnlyMode)
_isListenOnlyMode = isListenOnlyMode;
}

bool MeasurementInterface::isOneShotMode() const
{
return _isOneShotMode;
}

void MeasurementInterface::setOneShotMode(bool isOneShotMode)
{
_isOneShotMode = isOneShotMode;
}

bool MeasurementInterface::isTripleSampling() const
{
return _isTripleSampling;
@@ -47,6 +47,9 @@ class MeasurementInterface
bool isListenOnlyMode() const;
void setListenOnlyMode(bool isListenOnlyMode);

bool isOneShotMode() const;
void setOneShotMode(bool isOneShotMode);

bool isTripleSampling() const;
void setTripleSampling(bool isTripleSampling);

@@ -112,6 +115,7 @@ class MeasurementInterface

bool _doConfigure;
bool _isListenOnlyMode;
bool _isOneShotMode;
bool _isTripleSampling;
bool _isCanFD;

@@ -33,6 +33,11 @@ float CanTiming::getSamplePoint()
return _samplePoint;
}

QString CanTiming::getSamplePointStr(float samplePoint)
{
return QString::number(100*samplePoint, 'f', 1).append("%");
}

QString CanTiming::getTitle()
{
QString format = isCanFD() ? "%1/%3(FD) kBit/s, sample point %2%" : "%1 kBit/s, sample point %2";
@@ -19,6 +19,7 @@ class CanTiming
unsigned getBitrateFD();
bool isCanFD();
float getSamplePoint();
static QString getSamplePointStr(float samplePoint);

/*!
* \brief getTitle get a brief one-line description of this timing
@@ -23,11 +23,11 @@
#include "api/candle.h"

#include "CandleApiInterface.h"
#include "CandleApiSetupPage.h"
#include <driver/GenericCanSetupPage.h>

CandleApiDriver::CandleApiDriver(Backend &backend)
: CanDriver(backend),
setupPage(new CandleApiSetupPage(0))
setupPage(new GenericCanSetupPage(0))
{
QObject::connect(&backend, SIGNAL(onSetupDialogCreated(SetupDialog&)), setupPage, SLOT(onSetupDialogCreated(SetupDialog&)));
}
@@ -26,7 +26,7 @@
#include "api/candle.h"

class CandleApiInterface;
class CandleApiSetupPage;
class GenericCanSetupPage;

class CandleApiDriver : public CanDriver
{
@@ -37,7 +37,7 @@ class CandleApiDriver : public CanDriver
virtual bool update();

private:
CandleApiSetupPage *setupPage;
GenericCanSetupPage *setupPage;
CandleApiInterface *findInterface(candle_handle dev);

};
@@ -2,7 +2,6 @@ QMAKE_CFLAGS += -std=gnu11

SOURCES += \
$$PWD/CandleApiDriver.cpp \
$$PWD/CandleApiSetupPage.cpp \
$$PWD/CandleApiInterface.cpp \
$$PWD/api/candle.c \
$$PWD/api/candle_ctrl_req.c
@@ -15,11 +14,9 @@ win32: LIBS += -lwinusb
HEADERS += \
$$PWD/api/candle.h \
$$PWD/CandleApiDriver.h \
$$PWD/CandleApiSetupPage.h \
$$PWD/CandleApiInterface.h \
$$PWD/api/candle_ctrl_req.h \
$$PWD/api/candle_defs.h \
$$PWD/api/ch_9.h

FORMS += \
$$PWD/CandleApiSetupPage.ui
FORMS +=
@@ -127,6 +127,9 @@ void CandleApiInterface::open()
if (_settings.isListenOnlyMode()) {
flags |= CANDLE_MODE_LISTEN_ONLY;
}
if (_settings.isOneShotMode()) {
flags |= CANDLE_MODE_ONE_SHOT;
}
if (_settings.isTripleSampling()) {
flags |= CANDLE_MODE_TRIPLE_SAMPLE;
}
@@ -385,7 +385,7 @@ bool __stdcall DLL candle_channel_get_capabilities(candle_handle hdev, uint8_t c
{
// TODO check if info was already read from device; try to do so; throw error...
candle_device_t *dev = (candle_device_t*)hdev;
memcpy(cap, &dev->bt_const, sizeof(candle_capability_t));
memcpy(cap, &dev->bt_const.feature, sizeof(candle_capability_t));
return true;
}

@@ -0,0 +1,135 @@
#include "GenericCanSetupPage.h"
#include "ui_GenericCanSetupPage.h"
#include <core/Backend.h>
#include <driver/CanInterface.h>
#include <core/MeasurementInterface.h>
#include <window/SetupDialog/SetupDialog.h>
#include <QList>
#include <QtAlgorithms>

GenericCanSetupPage::GenericCanSetupPage(QWidget *parent) :
QWidget(parent),
ui(new Ui::GenericCanSetupPage),
_mi(0),
_enable_ui_updates(false)
{
ui->setupUi(this);
connect(ui->cbBitrate, SIGNAL(currentIndexChanged(int)), this, SLOT(saveUiChanges()));
connect(ui->cbSamplePoint, SIGNAL(currentIndexChanged(int)), this, SLOT(saveUiChanges()));
connect(ui->cbBitrateFD, SIGNAL(currentIndexChanged(int)), this, SLOT(saveUiChanges()));
connect(ui->cbSamplePointFD, SIGNAL(currentIndexChanged(int)), this, SLOT(saveUiChanges()));

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

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

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

void GenericCanSetupPage::onShowInterfacePage(SetupDialog &dlg, MeasurementInterface *mi)
{
_mi = mi;
CanInterface *intf = backend().getInterfaceById(_mi->canInterface());
uint32_t caps = intf->getCapabilities();

_enable_ui_updates = false;

ui->laDriver->setText(intf->getDriver()->getName());
ui->laInterface->setText(intf->getName());

fillBitratesList(intf, _mi->bitrate());
fillSamplePointsForBitrate(intf, _mi->bitrate(), _mi->samplePoint());

ui->cbBitrateFD->setEnabled(caps & CanInterface::capability_canfd);
ui->cbSamplePointFD->setEnabled(caps & CanInterface::capability_canfd);

ui->cbListenOnly->setEnabled(caps & CanInterface::capability_listen_only);
ui->cbListenOnly->setChecked(_mi->isListenOnlyMode());

ui->cbOneShot->setEnabled(caps & CanInterface::capability_one_shot);
ui->cbOneShot->setChecked(_mi->isOneShotMode());

ui->cbTripleSampling->setEnabled(caps & CanInterface::capability_triple_sampling);
ui->cbTripleSampling->setChecked(_mi->isTripleSampling());

ui->cbAutoRestart->setEnabled(caps & CanInterface::capability_auto_restart);
ui->cbAutoRestart->setChecked(_mi->doAutoRestart());

dlg.displayPage(this);

_enable_ui_updates = true;
}

void GenericCanSetupPage::saveUiChanges()
{
if (_enable_ui_updates && (_mi!=0)) {
CanInterface *intf = backend().getInterfaceById(_mi->canInterface());

_mi->setListenOnlyMode(ui->cbListenOnly->isChecked());
_mi->setOneShotMode(ui->cbOneShot->isChecked());
_mi->setTripleSampling(ui->cbTripleSampling->isChecked());
_mi->setAutoRestart(ui->cbAutoRestart->isChecked());
_mi->setBitrate(ui->cbBitrate->currentData().toInt());
_mi->setSamplePoint(ui->cbSamplePoint->currentData().toFloat());

_enable_ui_updates = false;
fillSamplePointsForBitrate(
intf,
ui->cbBitrate->currentData().toInt(),
ui->cbSamplePoint->currentData().toFloat()
);
_enable_ui_updates = true;

}
}

void GenericCanSetupPage::fillBitratesList(CanInterface *intf, uint32_t selectedBitrate)
{
QList<uint32_t> bitrates;
foreach (CanTiming t, intf->getAvailableBitrates()) {
if (!bitrates.contains(t.getBitrate())) {
bitrates.append(t.getBitrate());
}
}
qSort(bitrates);

ui->cbBitrate->clear();
foreach (uint32_t br, bitrates) {
ui->cbBitrate->addItem(QString::number(br), br);
}
ui->cbBitrate->setCurrentText(QString::number(selectedBitrate));
}

void GenericCanSetupPage::fillSamplePointsForBitrate(CanInterface *intf, uint32_t selectedBitrate, float selectedSamplePoint)
{
QList<float> samplePoints;
foreach(CanTiming t, intf->getAvailableBitrates()) {
if (t.getBitrate() == selectedBitrate) {
if (!samplePoints.contains(t.getSamplePoint())) {
samplePoints.append(t.getSamplePoint());
}
}
}
qSort(samplePoints);

ui->cbSamplePoint->clear();
foreach (float sp, samplePoints) {
ui->cbSamplePoint->addItem(CanTiming::getSamplePointStr(sp), sp);
}
ui->cbSamplePoint->setCurrentText(CanTiming::getSamplePointStr(selectedSamplePoint));
}

Backend &GenericCanSetupPage::backend()
{
return Backend::instance();
}
@@ -0,0 +1,41 @@
#ifndef GENERICCANSETUPPAGE_H
#define GENERICCANSETUPPAGE_H

#include <QWidget>

namespace Ui {
class GenericCanSetupPage;
}

class CanInterface;
class SetupDialog;
class MeasurementInterface;
class Backend;

class GenericCanSetupPage : public QWidget
{
Q_OBJECT

public:
explicit GenericCanSetupPage(QWidget *parent = 0);
~GenericCanSetupPage();

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

private slots:
void saveUiChanges();

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

void fillBitratesList(CanInterface *intf, uint32_t selectedBitrate);
void fillSamplePointsForBitrate(CanInterface *intf, uint32_t selectedBitrate, float selectedSamplePoint);

Backend &backend();
};

#endif // GENERICCANSETUPPAGE_H

0 comments on commit 37e0a52

Please sign in to comment.
You can’t perform that action at this time.