Skip to content
Permalink
Browse files

use new CanTiming class

as a generic way to describe timings including bitrates and sample points
  • Loading branch information...
HubertD committed May 16, 2016
1 parent 27d3b7a commit 6e7a5022a180a5382868d7fffda9d188650741e0
@@ -35,17 +35,19 @@ CanDriver* CanInterface::getDriver() {
return _driver;
}

QList<int> CanInterface::getAvailableBitrates()
QList<CanTiming> CanInterface::getAvailableBitrates()
{
QList<int> retval;
retval << 88300 << 100000 << 125000 << 250000 << 500000 << 1000000;
return retval;
}

QList<int> CanInterface::getAvailableFdBitrates()
{
QList<int> retval;
retval << 1000000 << 2000000 << 4000000 << 8000000 << 16000000;
QList<CanTiming> retval;
retval << CanTiming(0, 10000, 0, 0.875) \
<< CanTiming(1, 20000, 0, 0.875) \
<< CanTiming(2, 50000, 0, 0.875) \
<< CanTiming(3, 83333, 0, 0.875) \
<< CanTiming(4, 100000, 0, 0.875) \
<< CanTiming(5, 125000, 0, 0.875) \
<< CanTiming(6, 250000, 0, 0.875) \
<< CanTiming(7, 500000, 0, 0.875) \
<< CanTiming(8, 800000, 0, 0.875) \
<< CanTiming(9, 1000000, 0, 0.875);
return retval;
}

@@ -24,6 +24,7 @@
#include <QString>
#include <stdint.h>
#include "CanDriver.h"
#include "CanTiming.h"

class CanMessage;
class MeasurementInterface;
@@ -49,8 +50,7 @@ class CanInterface {

virtual int getBitrate() = 0;

virtual QList<int> getAvailableBitrates();
virtual QList<int> getAvailableFdBitrates();
virtual QList<CanTiming> getAvailableBitrates();

virtual void open();
virtual void close();
@@ -0,0 +1,44 @@
#include "CanTiming.h"

CanTiming::CanTiming(unsigned id, unsigned bitrate, uint32_t bitrate_fd, float samplePoint)
: _id(id),
_bitrate(bitrate),
_bitrate_fd(bitrate_fd),
_samplePoint(samplePoint)
{
}

unsigned CanTiming::getId()
{
return _id;
}

unsigned CanTiming::getBitrate()
{
return _bitrate;
}

unsigned CanTiming::getBitrateFD()
{
return _bitrate_fd;
}

bool CanTiming::isCanFD()
{
return _bitrate_fd != 0;
}

float CanTiming::getSamplePoint()
{
return _samplePoint;
}

QString CanTiming::getTitle()
{
QString format = isCanFD() ? "%1/%3(FD) kBit/s, sample point %2%" : "%1 kBit/s, sample point %2";
return format.arg(
QString::number(getBitrate()/1000, 'f', 2),
QString::number(getSamplePoint()*100, 'f', 1),
QString::number(getBitrateFD()/1000, 'f', 2)
);
}
@@ -0,0 +1,36 @@
#ifndef CANTIMING_H
#define CANTIMING_H

#include <QString>

class CanTiming
{
public:
/*!
* \brief CanTiming generic CAN timing description
* \param id internal id to identify this timing for the corresponding CAN driver
* \param bitrate bitrate in bits per second, e.g. 500000
* \param bitrate_fd bitrate for the FD part, or zero this is not a CanFD timing
* \param samplePoint sample point, e.g. 0.875
*/
CanTiming(unsigned id, unsigned bitrate, uint32_t bitrate_fd, float samplePoint);
unsigned getId();
unsigned getBitrate();
unsigned getBitrateFD();
bool isCanFD();
float getSamplePoint();

/*!
* \brief getTitle get a brief one-line description of this timing
* \return description, e.g. "500kBit/s, sample point 87.5%"
*/
QString getTitle();

private:
unsigned _id;
unsigned _bitrate;
unsigned _bitrate_fd;
float _samplePoint;
};

#endif // CANTIMING_H
@@ -33,17 +33,9 @@ int CandleApiInterface::getBitrate()
return _bitrate;
}

QList<int> CandleApiInterface::getAvailableBitrates()
QList<CanTiming> CandleApiInterface::getAvailableBitrates()
{
QList<int> retval;
retval << 10000 << 20000 << 50000 << 83333 << 100000 << 125000 << 250000 << 500000 << 800000 << 1000000;
return retval;
}

QList<int> CandleApiInterface::getAvailableFdBitrates()
{
QList<int> retval;
return retval;
return CanInterface::getAvailableBitrates();
}

//! sync device time with host time
@@ -19,8 +19,7 @@ class CandleApiInterface : public CanInterface

virtual int getBitrate();

virtual QList<int> getAvailableBitrates();
virtual QList<int> getAvailableFdBitrates();
virtual QList<CanTiming> getAvailableBitrates();

virtual void open();
virtual void close();
@@ -43,8 +43,8 @@ void CandleApiSetupPage::onShowInterfacePage(SetupDialog &dlg, MeasurementInterf
//ui->cbAutoRestart->setChecked(_mi->doAutoRestart());

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

@@ -110,16 +110,9 @@ QString PeakCanInterface::getErrorText(uint32_t status_code)
}
}

QList<int> PeakCanInterface::getAvailableBitrates()
QList<CanTiming> PeakCanInterface::getAvailableBitrates()
{
QList<int> retval;
retval << 5000 << 10000 << 20000 << 33333 << 47619 << 50000 << 83333 << 95238 << 100000 << 125000 << 250000 << 500000 << 800000 << 1000000;
return retval;
}

QList<int> PeakCanInterface::getAvailableFdBitrates()
{
return CanInterface::getAvailableFdBitrates();
return CanInterface::getAvailableBitrates();
}

void PeakCanInterface::open()
@@ -18,8 +18,7 @@ class PeakCanInterface : public CanInterface

virtual int getBitrate();

virtual QList<int> getAvailableBitrates();
virtual QList<int> getAvailableFdBitrates();
virtual QList<CanTiming> getAvailableBitrates();

virtual void open();
virtual void close();
@@ -49,8 +49,8 @@ void PeakCanSetupPage::onShowInterfacePage(SetupDialog &dlg, MeasurementInterfac
ui->cbAutoRestart->setChecked(_mi->doAutoRestart());

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

@@ -1,9 +1,11 @@
SOURCES += \
$$PWD/CanInterface.cpp \
$$PWD/CanListener.cpp \
$$PWD/CanDriver.cpp

HEADERS += \
$$PWD/CanInterface.h \
$$PWD/CanListener.h \
$$PWD/CanDriver.h
SOURCES += \
$$PWD/CanInterface.cpp \
$$PWD/CanListener.cpp \
$$PWD/CanDriver.cpp \
$$PWD/CanTiming.cpp

HEADERS += \
$$PWD/CanInterface.h \
$$PWD/CanListener.h \
$$PWD/CanDriver.h \
$$PWD/CanTiming.h

0 comments on commit 6e7a502

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