From 7192e11f38c095fa7edb09d9954121eaf490c9c6 Mon Sep 17 00:00:00 2001 From: canpadawan Date: Wed, 15 Jun 2016 18:21:41 +0200 Subject: [PATCH] removed old socketcanconnection --- socketcanconnection.cpp | 157 ---------------------------------------- socketcanconnection.h | 44 ----------- 2 files changed, 201 deletions(-) delete mode 100644 socketcanconnection.cpp delete mode 100644 socketcanconnection.h diff --git a/socketcanconnection.cpp b/socketcanconnection.cpp deleted file mode 100644 index c39c7c0..0000000 --- a/socketcanconnection.cpp +++ /dev/null @@ -1,157 +0,0 @@ -#include -#include -#include - - -#include "canframemodel.h" -#include "canconnection.h" -#include "socketcanconnection.h" - -/***********************************/ -/**** nested class ****/ -/***********************************/ - - -BUSConfig::BUSConfig():isConfigured(false){} - -void BUSConfig::reset() { - isConfigured = false; -} - -bool BUSConfig::operator==(CANBus& bus) { - return isConfigured && speed == bus.speed && - listenOnly == bus.listenOnly && active == bus.active; -} - -void BUSConfig::operator=(CANBus& bus) { - isConfigured = true; - speed = bus.speed; - listenOnly = bus.listenOnly; - active = bus.active; -} - - - -/***********************************/ -/**** class definition ****/ -/***********************************/ - -SocketCanConnection::SocketCanConnection(CANFrameModel *model, int base) : CANConnection(model, base), mDev_p(NULL) -{ - qDebug() << "SocketCanConnection()"; - qRegisterMetaType("CANFrame"); -} - -SocketCanConnection::~SocketCanConnection() -{ - qDebug() << "~SocketCanConnection()"; - /* stop device */ -} - -void SocketCanConnection::updateBusSettings(CANBus bus) -{ - qDebug()<<"updateBusSettings"; - - if(mConf == bus) return; - - /* disconnect device if we have one connected */ - if(mDev_p) disconnect(); - - /* if bus is not active we are done */ - if(!bus.active) return; - - /* create device */ - mDev_p = QCanBus::instance()->createDevice("socketcan", portName); - if (!mDev_p) { - qDebug() << "can't create device"; - return; - } - - /* connect slots */ - connect(mDev_p, &QCanBusDevice::errorOccurred, this, &SocketCanConnection::errorReceived); - connect(mDev_p, &QCanBusDevice::framesReceived, this, &SocketCanConnection::framesReceived); - connect(mDev_p, &QCanBusDevice::framesWritten, this, &SocketCanConnection::framesWritten); - - /* set configuration */ - /*if (p.useConfigurationEnabled) { - foreach (const SettingsDialog::ConfigurationItem &item, p.configurations) - mDev->setConfigurationParameter(item.first, item.second); - }*/ - - /* connect device */ - if (!mDev_p->connectDevice()) { - disconnect(); - qDebug() << "can't connect device"; - } -} - - -/***********************************/ -/**** private methods ****/ -/***********************************/ - - -/* connect device */ -void SocketCanConnection::disconnect() { - if(mDev_p) { - mDev_p->disconnectDevice(); - delete mDev_p; - mDev_p = Q_NULLPTR; - } -} - - -void SocketCanConnection::errorReceived(QCanBusDevice::CanBusError error) const -{ - switch (error) { - case QCanBusDevice::ReadError: - case QCanBusDevice::WriteError: - case QCanBusDevice::ConnectionError: - case QCanBusDevice::ConfigurationError: - case QCanBusDevice::UnknownError: - qWarning() << mDev_p->errorString(); - default: - break; - } -} - -void SocketCanConnection::framesWritten(qint64 count) -{ - qDebug() << "Number of frames written:" << count; -} - -void SocketCanConnection::framesReceived() -{ - /* sanity checks */ - if(!mDev_p) return; - - /* read frame */ - while(true) - { - const QCanBusFrame recFrame = mDev_p->readFrame(); - /* exit case */ - if(!recFrame.isValid()) return; - - if(!recFrame.payload().isEmpty() && - recFrame.payload().length()<=8) - { - CANFrame frame; - frame.len = recFrame.payload().length(); - frame.bus = 0; - memcpy(frame.data, recFrame.payload().data(), frame.len); - frame.extended = false; - frame.ID = recFrame.frameId(); - frame.isReceived = true; - frame.timestamp = recFrame.timeStamp().microSeconds(); - - /* send frame */ - QMetaObject::invokeMethod(model, "addFrame", - Qt::QueuedConnection, - Q_ARG(CANFrame, frame), - Q_ARG(bool, false)); - } - else { - qDebug() << "invalid frame"; - } - } -} diff --git a/socketcanconnection.h b/socketcanconnection.h deleted file mode 100644 index 18f5251..0000000 --- a/socketcanconnection.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef SOCKETCANCONNECTION_H -#define SOCKETCANCONNECTION_H - -#include -#include - -#include "canframemodel.h" -#include "canconnection.h" - -class BUSConfig { -public: - BUSConfig(); - void reset(); - bool operator ==(CANBus&); - void operator =(CANBus&); - bool isConfigured; - int speed; - bool listenOnly; - bool active; -}; - - -class SocketCanConnection : public CANConnection -{ - Q_OBJECT - -public: - SocketCanConnection(CANFrameModel *, int); - virtual ~SocketCanConnection() override; - -public slots: - virtual void updateBusSettings(CANBus) override; - -private: - void errorReceived(QCanBusDevice::CanBusError error) const; - void framesWritten(qint64 count); - void framesReceived(); - void disconnect(); - - QCanBusDevice* mDev_p; - BUSConfig mConf; -}; - -#endif // SOCKETCANCONNECTION_H