Skip to content
Permalink
Browse files

simplify can timing xml, socketcan timing

  • Loading branch information...
HubertD committed May 19, 2016
1 parent 17ce7a1 commit f671ed1ef9e496d277914d88492871108360bcb0
Showing with 37 additions and 307 deletions.
  1. +21 −203 src/core/MeasurementInterface.cpp
  2. +4 −58 src/core/MeasurementInterface.h
  3. +12 −46 src/driver/SocketCanDriver/SocketCanInterface.cpp
@@ -25,29 +25,18 @@
#include <driver/CanDriver.h>
#include <driver/CanInterface.h>


MeasurementInterface::MeasurementInterface()
: _doConfigure(true),
_isListenOnlyMode(false),
_isOneShotMode(false),
_isTripleSampling(false),
_isCanFD(false),
_isSimpleTiming(true),
_bitrate(500000),
_samplePoint(875),
_isCanFD(false),
_fdBitrate(4000000),
_fdSamplePoint(875),
_tq(125),
_propSeg(6),
_phaseSeg1(7),
_phaseSeg2(2),
_doSetSJW(false),
_sjw(1),
_fdTq(12),
_fdPropSeg(7),
_fdPhaseSeg1(2),
_fdPhaseSeg2(1),
_doSetFdSJW(false),
_fdSjw(1),

_isListenOnlyMode(false),
_isOneShotMode(false),
_isTripleSampling(false),
_doAutoRestart(false),
_autoRestartMs(100)
{
@@ -59,85 +48,44 @@ bool MeasurementInterface::loadXML(Backend &backend, QDomElement &el)
(void) backend;

_doConfigure = el.attribute("configure", "0").toInt() != 0;

_bitrate = el.attribute("bitrate", "500000").toInt();
_samplePoint = el.attribute("sample-point", "875").toInt();
_isCanFD = el.attribute("can-fd", "0").toInt() != 0;
_fdBitrate = el.attribute("bitrate-fd", "500000").toInt();
_fdSamplePoint = el.attribute("sample-point-fd", "875").toInt();

_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";
_doAutoRestart = el.attribute("auto-restart", "0").toInt() != 0;
_autoRestartMs = el.attribute("auto-restart-time", "100").toInt();

QDomElement simpleTimingNode = el.firstChildElement("timing-bitrate");
_bitrate = simpleTimingNode.attribute("bitrate", "500000").toInt();
_samplePoint = simpleTimingNode.attribute("sample-point", "0").toInt();
_fdBitrate = simpleTimingNode.attribute("bitrate-fd", "500000").toInt();
_fdSamplePoint = simpleTimingNode.attribute("sample-point-fd", "0").toInt();

QDomElement advTimingNode = el.firstChildElement("timing-registers");

QDomElement advTimingCan = advTimingNode.firstChildElement("can");
_tq = advTimingCan.attribute("tq", "0").toInt();
_propSeg = advTimingCan.attribute("prop-seg", "0").toInt();
_phaseSeg1 = advTimingCan.attribute("phase-seg1", "0").toInt();
_phaseSeg2 = advTimingCan.attribute("phase-seg2", "0").toInt();
_doSetSJW = advTimingCan.attribute("set-sjw", "0").toInt() != 0;
_sjw = advTimingCan.attribute("sjw", "1").toInt();

QDomElement advTimingCanFd = advTimingNode.firstChildElement("can-fd");
_fdTq = advTimingCanFd.attribute("tq", "0").toInt();
_fdPropSeg = advTimingCanFd.attribute("prop-seg", "0").toInt();
_fdPhaseSeg1 = advTimingCanFd.attribute("phase-seg1", "0").toInt();
_fdPhaseSeg2 = advTimingCanFd.attribute("phase-seg2", "0").toInt();
_doSetFdSJW = advTimingCanFd.attribute("set-sjw", "0").toInt() != 0;
_fdSjw = advTimingCanFd.attribute("sjw", "1").toInt();

return true;
}

bool MeasurementInterface::saveXML(Backend &backend, QDomDocument &xml, QDomElement &root)
{
(void) xml;

root.setAttribute("type", "can");
root.setAttribute("driver", backend.getDriverName(_canif));
root.setAttribute("name", backend.getInterfaceName(_canif));

root.setAttribute("configure", _doConfigure ? 1 : 0);

root.setAttribute("bitrate", _bitrate);
root.setAttribute("sample-point", _samplePoint);
root.setAttribute("can-fd", _isCanFD ? 1 : 0);
root.setAttribute("bitrate-fd", _fdBitrate);
root.setAttribute("sample-point-fd", _fdSamplePoint);

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");
root.setAttribute("auto-restart", _doAutoRestart ? 1 : 0);
root.setAttribute("auto-restart-time", _autoRestartMs);

QDomElement simpleTimingNode = xml.createElement("timing-bitrate");
simpleTimingNode.setAttribute("bitrate", _bitrate);
simpleTimingNode.setAttribute("sample-point", _samplePoint);
simpleTimingNode.setAttribute("bitrate-fd", _fdBitrate);
simpleTimingNode.setAttribute("sample-point-fd", _fdSamplePoint);
root.appendChild(simpleTimingNode);

QDomElement advTimingNode = xml.createElement("timing-registers");
QDomElement advTimingCan = xml.createElement("can");
advTimingCan.setAttribute("tq", _tq);
advTimingCan.setAttribute("prop-seg", _propSeg);
advTimingCan.setAttribute("phase-seg1", _phaseSeg1);
advTimingCan.setAttribute("phase-seg2", _phaseSeg2);
advTimingCan.setAttribute("set-sjw", _doSetSJW ? 1 : 0);
advTimingCan.setAttribute("sjw", _sjw);
advTimingNode.appendChild(advTimingCan);

QDomElement advTimingCanFd = xml.createElement("can-fd");
advTimingCanFd.setAttribute("tq", _fdTq);
advTimingCanFd.setAttribute("prop-seg", _fdPropSeg);
advTimingCanFd.setAttribute("phase-seg1", _fdPhaseSeg1);
advTimingCanFd.setAttribute("phase-seg2", _fdPhaseSeg2);
advTimingCanFd.setAttribute("set-sjw", _doSetFdSJW ? 1 : 0);
advTimingCanFd.setAttribute("sjw", _fdSjw);
advTimingNode.appendChild(advTimingCanFd);

root.appendChild(advTimingNode);

return true;
}

@@ -216,16 +164,6 @@ void MeasurementInterface::setCanFD(bool isCanFD)
_isCanFD = isCanFD;
}

bool MeasurementInterface::isSimpleTiming() const
{
return _isSimpleTiming;
}

void MeasurementInterface::setSimpleTiming(bool isSimpleTiming)
{
_isSimpleTiming = isSimpleTiming;
}

int MeasurementInterface::samplePoint() const
{
return _samplePoint;
@@ -256,126 +194,6 @@ void MeasurementInterface::setFdSamplePoint(unsigned fdSamplePoint)
_fdSamplePoint = fdSamplePoint;
}

int MeasurementInterface::tq() const
{
return _tq;
}

void MeasurementInterface::setTq(int tq)
{
_tq = tq;
}

int MeasurementInterface::propSeg() const
{
return _propSeg;
}

void MeasurementInterface::setPropSeg(int propSeg)
{
_propSeg = propSeg;
}

int MeasurementInterface::phaseSeg1() const
{
return _phaseSeg1;
}

void MeasurementInterface::setPhaseSeg1(int phaseSeg1)
{
_phaseSeg1 = phaseSeg1;
}

int MeasurementInterface::phaseSeg2() const
{
return _phaseSeg2;
}

void MeasurementInterface::setPhaseSeg2(int phaseSeg2)
{
_phaseSeg2 = phaseSeg2;
}

bool MeasurementInterface::doSetSJW() const
{
return _doSetSJW;
}

void MeasurementInterface::setDoSetSJW(bool doSetSJW)
{
_doSetSJW = doSetSJW;
}

int MeasurementInterface::SJW() const
{
return _sjw;
}

void MeasurementInterface::setSJW(int sjw)
{
_sjw = sjw;
}

int MeasurementInterface::fdTq() const
{
return _fdTq;
}

void MeasurementInterface::setFdTq(int fdTq)
{
_fdTq = fdTq;
}

int MeasurementInterface::fdPropSeg() const
{
return _fdPropSeg;
}

void MeasurementInterface::setFdPropSeg(int fdPropSeg)
{
_fdPropSeg = fdPropSeg;
}

int MeasurementInterface::fdPhaseSeg1() const
{
return _fdPhaseSeg1;
}

void MeasurementInterface::setFdPhaseSeg1(int fdPhaseSeg1)
{
_fdPhaseSeg1 = fdPhaseSeg1;
}

int MeasurementInterface::fdPhaseSeg2() const
{
return _fdPhaseSeg2;
}

void MeasurementInterface::setFdPhaseSeg2(int fdPhaseSeg2)
{
_fdPhaseSeg2 = fdPhaseSeg2;
}

bool MeasurementInterface::doSetFdSJW() const
{
return _doSetFdSJW;
}

void MeasurementInterface::setDoSetFdSJW(bool doSetFdSJW)
{
_doSetFdSJW = doSetFdSJW;
}

int MeasurementInterface::fdSJW() const
{
return _fdSjw;
}

void MeasurementInterface::setFdSJW(int fdSjw)
{
_fdSjw = fdSjw;
}

bool MeasurementInterface::doAutoRestart() const
{
return _doAutoRestart;
@@ -54,9 +54,6 @@ class MeasurementInterface
bool isCanFD() const;
void setCanFD(bool isCanFD);

bool isSimpleTiming() const;
void setSimpleTiming(bool isSimpleTiming);

unsigned bitrate() const;
void setBitrate(unsigned bitrate);

@@ -69,42 +66,6 @@ class MeasurementInterface
unsigned fdSamplePoint() const;
void setFdSamplePoint(unsigned fdSamplePoint);

int tq() const;
void setTq(int tq);

int propSeg() const;
void setPropSeg(int propSeg);

int phaseSeg1() const;
void setPhaseSeg1(int phaseSeg1);

int phaseSeg2() const;
void setPhaseSeg2(int phaseSeg2);

bool doSetSJW() const;
void setDoSetSJW(bool doSetSJW);

int SJW() const;
void setSJW(int SJW);

int fdTq() const;
void setFdTq(int fdTq);

int fdPropSeg() const;
void setFdPropSeg(int fdPropSeg);

int fdPhaseSeg1() const;
void setFdPhaseSeg1(int fdPhaseSeg1);

int fdPhaseSeg2() const;
void setFdPhaseSeg2(int fdPhaseSeg2);

bool doSetFdSJW() const;
void setDoSetFdSJW(bool doSetFdSJW);

int fdSJW() const;
void setFdSJW(int fdSJW);

bool doAutoRestart() const;
void setAutoRestart(bool doAutoRestart);

@@ -115,32 +76,17 @@ class MeasurementInterface
CanInterfaceId _canif;

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

bool _isSimpleTiming;
unsigned _bitrate;
unsigned _samplePoint;

bool _isCanFD;
unsigned _fdBitrate;
unsigned _fdSamplePoint;

int _tq;
int _propSeg;
int _phaseSeg1;
int _phaseSeg2;
bool _doSetSJW;
int _sjw;

int _fdTq;
int _fdPropSeg;
int _fdPhaseSeg1;
int _fdPhaseSeg2;
bool _doSetFdSJW;
int _fdSjw;

bool _isListenOnlyMode;
bool _isOneShotMode;
bool _isTripleSampling;
bool _doAutoRestart;
int _autoRestartMs;
};

0 comments on commit f671ed1

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