Access to the CANBus parameters only through setters/getters
Also removed explicit copy constructor, in such trivial cases compiler can create all needed copy/move stubs automatically
This commit is contained in:
+10
-17
@@ -13,21 +13,13 @@ CANBus::CANBus()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CANBus::CANBus(const CANBus& pBus) :
|
|
||||||
speed(pBus.speed),
|
|
||||||
listenOnly(pBus.listenOnly),
|
|
||||||
singleWire(pBus.singleWire),
|
|
||||||
active(pBus.active),
|
|
||||||
canFD(pBus.canFD),
|
|
||||||
dataRate(pBus.dataRate){}
|
|
||||||
|
|
||||||
|
|
||||||
bool CANBus::operator==(const CANBus& bus) const{
|
bool CANBus::operator==(const CANBus& bus) const{
|
||||||
return speed == bus.speed &&
|
return speed == bus.speed &&
|
||||||
listenOnly == bus.listenOnly &&
|
listenOnly == bus.listenOnly &&
|
||||||
singleWire == bus.singleWire &&
|
singleWire == bus.singleWire &&
|
||||||
active == bus.active &&
|
active == bus.active &&
|
||||||
canFD == bus.canFD;
|
canFD == bus.canFD &&
|
||||||
|
dataRate == bus.dataRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CANBus::setSpeed(int newSpeed){
|
void CANBus::setSpeed(int newSpeed){
|
||||||
@@ -55,11 +47,11 @@ void CANBus::setCanFD(bool mode){
|
|||||||
canFD = mode;
|
canFD = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CANBus::getSpeed(){
|
int CANBus::getSpeed() const {
|
||||||
return speed;
|
return speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CANBus::getDataRate(){
|
int CANBus::getDataRate() const {
|
||||||
return dataRate;
|
return dataRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,29 +60,30 @@ void CANBus::setDataRate(int newSpeed){
|
|||||||
dataRate = newSpeed;
|
dataRate = newSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CANBus::isListenOnly(){
|
bool CANBus::isListenOnly() const {
|
||||||
return listenOnly;
|
return listenOnly;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CANBus::isSingleWire(){
|
bool CANBus::isSingleWire() const {
|
||||||
return singleWire;
|
return singleWire;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CANBus::isActive(){
|
bool CANBus::isActive() const {
|
||||||
return active;
|
return active;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CANBus::isCanFD(){
|
bool CANBus::isCanFD() const {
|
||||||
return canFD;
|
return canFD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QDataStream& operator<<( QDataStream & pStream, const CANBus& pCanBus )
|
QDataStream& operator<<(QDataStream & pStream, const CANBus& pCanBus)
|
||||||
{
|
{
|
||||||
pStream << pCanBus.speed;
|
pStream << pCanBus.speed;
|
||||||
pStream << pCanBus.listenOnly;
|
pStream << pCanBus.listenOnly;
|
||||||
pStream << pCanBus.singleWire;
|
pStream << pCanBus.singleWire;
|
||||||
pStream << pCanBus.active;
|
pStream << pCanBus.active;
|
||||||
|
// FIXME CANFD settings missing
|
||||||
return pStream;
|
return pStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+17
-16
@@ -5,13 +5,6 @@
|
|||||||
|
|
||||||
class CANBus
|
class CANBus
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
CANBus();
|
|
||||||
CANBus(const CANBus&);
|
|
||||||
bool operator==(const CANBus&) const;
|
|
||||||
CANBus& operator=(const CANBus& other) = default;
|
|
||||||
//virtual ~CANBus(){}
|
|
||||||
|
|
||||||
int speed;
|
int speed;
|
||||||
bool listenOnly;
|
bool listenOnly;
|
||||||
bool singleWire;
|
bool singleWire;
|
||||||
@@ -19,28 +12,36 @@ public:
|
|||||||
bool canFD;
|
bool canFD;
|
||||||
int dataRate;
|
int dataRate;
|
||||||
|
|
||||||
|
friend QDataStream& operator<<(QDataStream & pStream, const CANBus& pCanBus);
|
||||||
|
friend QDataStream& operator>>(QDataStream & pStream, CANBus& pCanBus);
|
||||||
|
public:
|
||||||
|
CANBus();
|
||||||
|
|
||||||
|
bool operator==(const CANBus&) const;
|
||||||
|
|
||||||
void setSpeed(int); // new speed
|
void setSpeed(int); // new speed
|
||||||
void setListenOnly(bool); //bool for whether to only listen
|
void setListenOnly(bool); //bool for whether to only listen
|
||||||
void setSingleWire(bool); //bool for whether to use single wire mode
|
void setSingleWire(bool); //bool for whether to use single wire mode
|
||||||
void setActive(bool); //whether this bus should be enabled or not.
|
void setActive(bool); //whether this bus should be enabled or not.
|
||||||
void setCanFD(bool); // enable or disable CANFD support
|
void setCanFD(bool); // enable or disable CANFD support
|
||||||
int getSpeed();
|
|
||||||
int getDataRate();
|
|
||||||
void setDataRate(int newSpeed);
|
void setDataRate(int newSpeed);
|
||||||
bool isListenOnly();
|
|
||||||
bool isSingleWire();
|
int getSpeed() const;
|
||||||
bool isActive();
|
int getDataRate() const;
|
||||||
bool isCanFD();
|
bool isListenOnly() const;
|
||||||
|
bool isSingleWire() const;
|
||||||
|
bool isActive() const;
|
||||||
|
bool isCanFD() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
QDataStream& operator<<( QDataStream & pStream, const CANBus& pCanBus );
|
QDataStream& operator<<(QDataStream & pStream, const CANBus& pCanBus);
|
||||||
QDataStream & operator>>(QDataStream & pStream, CANBus& pCanBus);
|
QDataStream& operator>>(QDataStream & pStream, CANBus& pCanBus);
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(CANBus);
|
Q_DECLARE_METATYPE(CANBus);
|
||||||
|
|
||||||
struct BusData {
|
struct BusData {
|
||||||
CANBus mBus;
|
CANBus mBus;
|
||||||
bool mConfigured;
|
bool mConfigured = {};
|
||||||
QVector<CANFltObserver> mTargettedFrames;
|
QVector<CANFltObserver> mTargettedFrames;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ void SerialBusConnection::piSetBusSettings(int pBusIdx, CANBus bus)
|
|||||||
setBusConfig(0, bus);
|
setBusConfig(0, bus);
|
||||||
|
|
||||||
/* if bus is not active we are done */
|
/* if bus is not active we are done */
|
||||||
if(!bus.active)
|
if(!bus.isActive())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* set configuration */
|
/* set configuration */
|
||||||
@@ -105,10 +105,10 @@ void SerialBusConnection::piSetBusSettings(int pBusIdx, CANBus bus)
|
|||||||
|
|
||||||
//You cannot set the speed of a socketcan interface, it has to be set with console commands.
|
//You cannot set the speed of a socketcan interface, it has to be set with console commands.
|
||||||
//But, you can probabaly set the speed of many of the other serialbus devices so go ahead and try
|
//But, you can probabaly set the speed of many of the other serialbus devices so go ahead and try
|
||||||
mDev_p->setConfigurationParameter(QCanBusDevice::BitRateKey, bus.speed);
|
mDev_p->setConfigurationParameter(QCanBusDevice::BitRateKey, bus.getSpeed());
|
||||||
mDev_p->setConfigurationParameter(QCanBusDevice::CanFdKey, bus.canFD);
|
mDev_p->setConfigurationParameter(QCanBusDevice::CanFdKey, bus.isCanFD());
|
||||||
|
|
||||||
if(bus.listenOnly)
|
if(bus.isListenOnly())
|
||||||
sbusconfig |= EN_SILENT_MODE;
|
sbusconfig |= EN_SILENT_MODE;
|
||||||
mDev_p->setConfigurationParameter(QCanBusDevice::UserKey, sbusconfig);
|
mDev_p->setConfigurationParameter(QCanBusDevice::UserKey, sbusconfig);
|
||||||
|
|
||||||
@@ -188,6 +188,7 @@ void SerialBusConnection::framesReceived()
|
|||||||
|
|
||||||
/* check frame */
|
/* check frame */
|
||||||
//if (recFrame.payload().length() <= 8) {
|
//if (recFrame.payload().length() <= 8) {
|
||||||
|
if (true) {
|
||||||
CANFrame* frame_p = getQueue().get();
|
CANFrame* frame_p = getQueue().get();
|
||||||
if(frame_p) {
|
if(frame_p) {
|
||||||
frame_p->setPayload(recFrame.payload());
|
frame_p->setPayload(recFrame.payload());
|
||||||
@@ -206,7 +207,7 @@ void SerialBusConnection::framesReceived()
|
|||||||
frame_p->setTimeStamp(recFrame.timeStamp());
|
frame_p->setTimeStamp(recFrame.timeStamp());
|
||||||
frame_p->setFrameType(recFrame.frameType());
|
frame_p->setFrameType(recFrame.frameType());
|
||||||
frame_p->setError(recFrame.error());
|
frame_p->setError(recFrame.error());
|
||||||
/* If recorded frame has a local echo, it is a Tx message, and thus should not be marked as Rx */
|
/* If recorded frame has a local echo, it is a Tx message, and thus should not be marked as Rx */
|
||||||
frame_p->isReceived = !recFrame.hasLocalEcho();
|
frame_p->isReceived = !recFrame.hasLocalEcho();
|
||||||
|
|
||||||
if (useSystemTime) {
|
if (useSystemTime) {
|
||||||
@@ -218,11 +219,9 @@ void SerialBusConnection::framesReceived()
|
|||||||
|
|
||||||
/* enqueue frame */
|
/* enqueue frame */
|
||||||
getQueue().queue();
|
getQueue().queue();
|
||||||
//}
|
}
|
||||||
#if 0
|
|
||||||
else
|
else
|
||||||
qDebug() << "can't get a frame, ERROR";
|
qDebug() << "can't get a frame, ERROR";
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user