Skip to content

Commit

Permalink
Merge pull request #723 from esaulenka/fix/MinorFixes
Browse files Browse the repository at this point in the history
Several minor fixes
  • Loading branch information
collin80 authored Jan 26, 2024
2 parents e7fe84a + f634cd9 commit bae885d
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 160 deletions.
27 changes: 10 additions & 17 deletions connections/canbus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
33 changes: 17 additions & 16 deletions connections/canbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,43 @@

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;
bool active; //is this bus turned on?
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;
};

Expand Down
2 changes: 1 addition & 1 deletion connections/canconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ CANConnection::CANConnection(QString pPort,
int pQueueLen,
bool pUseThread) :
mNumBuses(pNumBuses),
mSerialSpeed(pSerialSpeed),
mQueue(),
mPort(pPort),
mDriver(pDriver),
mType(pType),
mSerialSpeed(pSerialSpeed),
mIsCapSuspended(false),
mStatus(CANCon::NOT_CONNECTED),
mStarted(false),
Expand Down
15 changes: 7 additions & 8 deletions connections/serialbusconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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);

Expand Down Expand Up @@ -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());
Expand All @@ -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) {
Expand All @@ -218,11 +219,9 @@ void SerialBusConnection::framesReceived()

/* enqueue frame */
getQueue().queue();
//}
#if 0
}
else
qDebug() << "can't get a frame, ERROR";
#endif
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions connections/socketcand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ void SocketCANd::connectDevice()
void SocketCANd::deviceConnected(int busNum)
{
sendDebug("Opening CAN on Kayak Device!");
const char* openCanCmd = ("< open " + hostCanIDs[busNum] + " >").toStdString().c_str();
sendStringToTCP(openCanCmd, busNum);
QString openCanCmd("< open " % hostCanIDs[busNum] % " >");
sendStringToTCP(openCanCmd.toUtf8().data(), busNum);

QCoreApplication::processEvents();
}
Expand Down Expand Up @@ -383,8 +383,6 @@ void SocketCANd::procRXData(QString data, int busNum)
mTimer.stop();
mTimer.start();
}
QByteArray output;

switch (rx_state.at(busNum))
{
case IDLE:
Expand Down
2 changes: 0 additions & 2 deletions framesenderwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1054,8 +1054,6 @@ void FrameSenderWindow::processCellChange(int line, int col)
}
break;
case ST_COLS::SENDTAB_COL_DATA: //Data bytes
for (int i = 0; i < 8; i++) sendingData[line].payload().data()[i] = 0;

#if QT_VERSION >= QT_VERSION_CHECK( 5, 14, 0 )
tokens = ui->tableSender->item(line, ST_COLS::SENDTAB_COL_DATA)->text().split(" ", Qt::SkipEmptyParts);
#else
Expand Down
10 changes: 6 additions & 4 deletions re/dbccomparatorwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ void DBCComparatorWindow::calculateDetails()

ui->treeDetails->addTopLevelItem(msgDiffRoot);

QTreeWidgetItem *msgItem;
QTreeWidgetItem *sigTemp;
QTreeWidgetItem *msgItem {};
QTreeWidgetItem *sigTemp {};

for (int i = 0; i < firstDBC->messageHandler->getCount(); i++)
{
Expand Down Expand Up @@ -257,7 +257,8 @@ void DBCComparatorWindow::calculateDetails()
msgItem->setText(0, msgName + " (" + Utility::formatCANID(thisMsg->ID) + ")");
sigDiffTwo->addChild(msgItem);
}
msgItem->addChild(missingSigItem);
if (msgItem)
msgItem->addChild(missingSigItem);
}
else //signal exists on both sides. See if it as changed position or length
{
Expand Down Expand Up @@ -301,7 +302,8 @@ void DBCComparatorWindow::calculateDetails()
sigTemp->setText(0, msgName + " (" + Utility::formatCANID(thisMsg->ID) + ")");
sigModifiedRoot->addChild(sigTemp);
}
sigTemp->addChild(sigItem);
if (sigTemp)
sigTemp->addChild(sigItem);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion re/flowviewwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ void FlowViewWindow::updatePosition(bool forward)
int maxVal = qMin(chunk * 8 + 8, frameCache.at(currentPosition).payload().length());
for (int i = chunk * 8; i < maxVal; i++)
{
unsigned char thisByte = static_cast<unsigned char>(frameCache.at(currentPosition).payload().data()[i]);
unsigned char thisByte = static_cast<unsigned char>(frameCache.at(currentPosition).payload()[i]);
cngByte = currBytes[i] ^ thisByte;
changedBits |= (uint64_t)cngByte << (8ull * (i & 7));
}
Expand Down
Loading

0 comments on commit bae885d

Please sign in to comment.