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{
|
||||
return speed == bus.speed &&
|
||||
listenOnly == bus.listenOnly &&
|
||||
singleWire == bus.singleWire &&
|
||||
active == bus.active &&
|
||||
canFD == bus.canFD;
|
||||
canFD == bus.canFD &&
|
||||
dataRate == bus.dataRate;
|
||||
}
|
||||
|
||||
void CANBus::setSpeed(int newSpeed){
|
||||
@@ -55,11 +47,11 @@ void CANBus::setCanFD(bool mode){
|
||||
canFD = mode;
|
||||
}
|
||||
|
||||
int CANBus::getSpeed(){
|
||||
int CANBus::getSpeed() const {
|
||||
return speed;
|
||||
}
|
||||
|
||||
int CANBus::getDataRate(){
|
||||
int CANBus::getDataRate() const {
|
||||
return dataRate;
|
||||
}
|
||||
|
||||
@@ -68,29 +60,30 @@ void CANBus::setDataRate(int newSpeed){
|
||||
dataRate = newSpeed;
|
||||
}
|
||||
|
||||
bool CANBus::isListenOnly(){
|
||||
bool CANBus::isListenOnly() const {
|
||||
return listenOnly;
|
||||
}
|
||||
|
||||
bool CANBus::isSingleWire(){
|
||||
bool CANBus::isSingleWire() const {
|
||||
return singleWire;
|
||||
}
|
||||
|
||||
bool CANBus::isActive(){
|
||||
bool CANBus::isActive() const {
|
||||
return active;
|
||||
}
|
||||
|
||||
bool CANBus::isCanFD(){
|
||||
bool CANBus::isCanFD() const {
|
||||
return canFD;
|
||||
}
|
||||
|
||||
|
||||
QDataStream& operator<<( QDataStream & pStream, const CANBus& pCanBus )
|
||||
QDataStream& operator<<(QDataStream & pStream, const CANBus& pCanBus)
|
||||
{
|
||||
pStream << pCanBus.speed;
|
||||
pStream << pCanBus.listenOnly;
|
||||
pStream << pCanBus.singleWire;
|
||||
pStream << pCanBus.active;
|
||||
// FIXME CANFD settings missing
|
||||
return pStream;
|
||||
}
|
||||
|
||||
|
||||
+17
-16
@@ -5,13 +5,6 @@
|
||||
|
||||
class CANBus
|
||||
{
|
||||
public:
|
||||
CANBus();
|
||||
CANBus(const CANBus&);
|
||||
bool operator==(const CANBus&) const;
|
||||
CANBus& operator=(const CANBus& other) = default;
|
||||
//virtual ~CANBus(){}
|
||||
|
||||
int speed;
|
||||
bool listenOnly;
|
||||
bool singleWire;
|
||||
@@ -19,28 +12,36 @@ public:
|
||||
bool canFD;
|
||||
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 setListenOnly(bool); //bool for whether to only listen
|
||||
void setSingleWire(bool); //bool for whether to use single wire mode
|
||||
void setActive(bool); //whether this bus should be enabled or not.
|
||||
void setCanFD(bool); // enable or disable CANFD support
|
||||
int getSpeed();
|
||||
int getDataRate();
|
||||
void setDataRate(int newSpeed);
|
||||
bool isListenOnly();
|
||||
bool isSingleWire();
|
||||
bool isActive();
|
||||
bool isCanFD();
|
||||
|
||||
int getSpeed() const;
|
||||
int getDataRate() const;
|
||||
bool isListenOnly() const;
|
||||
bool isSingleWire() const;
|
||||
bool isActive() const;
|
||||
bool isCanFD() const;
|
||||
};
|
||||
|
||||
QDataStream& operator<<( QDataStream & pStream, const CANBus& pCanBus );
|
||||
QDataStream & operator>>(QDataStream & pStream, CANBus& pCanBus);
|
||||
QDataStream& operator<<(QDataStream & pStream, const CANBus& pCanBus);
|
||||
QDataStream& operator>>(QDataStream & pStream, CANBus& pCanBus);
|
||||
|
||||
Q_DECLARE_METATYPE(CANBus);
|
||||
|
||||
struct BusData {
|
||||
CANBus mBus;
|
||||
bool mConfigured;
|
||||
bool mConfigured = {};
|
||||
QVector<CANFltObserver> mTargettedFrames;
|
||||
};
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ void SerialBusConnection::piSetBusSettings(int pBusIdx, CANBus bus)
|
||||
setBusConfig(0, bus);
|
||||
|
||||
/* if bus is not active we are done */
|
||||
if(!bus.active)
|
||||
if(!bus.isActive())
|
||||
return;
|
||||
|
||||
/* 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.
|
||||
//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::CanFdKey, bus.canFD);
|
||||
mDev_p->setConfigurationParameter(QCanBusDevice::BitRateKey, bus.getSpeed());
|
||||
mDev_p->setConfigurationParameter(QCanBusDevice::CanFdKey, bus.isCanFD());
|
||||
|
||||
if(bus.listenOnly)
|
||||
if(bus.isListenOnly())
|
||||
sbusconfig |= EN_SILENT_MODE;
|
||||
mDev_p->setConfigurationParameter(QCanBusDevice::UserKey, sbusconfig);
|
||||
|
||||
@@ -188,6 +188,7 @@ void SerialBusConnection::framesReceived()
|
||||
|
||||
/* check frame */
|
||||
//if (recFrame.payload().length() <= 8) {
|
||||
if (true) {
|
||||
CANFrame* frame_p = getQueue().get();
|
||||
if(frame_p) {
|
||||
frame_p->setPayload(recFrame.payload());
|
||||
@@ -206,7 +207,7 @@ void SerialBusConnection::framesReceived()
|
||||
frame_p->setTimeStamp(recFrame.timeStamp());
|
||||
frame_p->setFrameType(recFrame.frameType());
|
||||
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();
|
||||
|
||||
if (useSystemTime) {
|
||||
@@ -218,11 +219,9 @@ void SerialBusConnection::framesReceived()
|
||||
|
||||
/* enqueue frame */
|
||||
getQueue().queue();
|
||||
//}
|
||||
#if 0
|
||||
}
|
||||
else
|
||||
qDebug() << "can't get a frame, ERROR";
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user