renamed socketcan class
This commit is contained in:
@@ -9,7 +9,7 @@ CANConnection* CanConFactory::create(type pType, QString pPortName)
|
|||||||
{
|
{
|
||||||
switch(pType) {
|
switch(pType) {
|
||||||
case SOCKETCAN:
|
case SOCKETCAN:
|
||||||
return new SocketCanConnection(pPortName);
|
return new SocketCan(pPortName);
|
||||||
case GVRET_SERIAL:
|
case GVRET_SERIAL:
|
||||||
return new GVRetSerial(pPortName);
|
return new GVRetSerial(pPortName);
|
||||||
default: {}
|
default: {}
|
||||||
|
|||||||
+43
-24
@@ -23,8 +23,11 @@ public:
|
|||||||
* @param pQueueLen: the length of the lock free queue to use
|
* @param pQueueLen: the length of the lock free queue to use
|
||||||
* @param pUseThread: if set to true, object will be execute in a dedicated thread
|
* @param pUseThread: if set to true, object will be execute in a dedicated thread
|
||||||
*/
|
*/
|
||||||
CANConnection(QString pPort, CANCon::type pType, int pNumBuses,
|
CANConnection(QString pPort,
|
||||||
int pQueueLen, bool pUseThread);
|
CANCon::type pType,
|
||||||
|
int pNumBuses,
|
||||||
|
int pQueueLen,
|
||||||
|
bool pUseThread);
|
||||||
/**
|
/**
|
||||||
* @brief CANConnection destructor
|
* @brief CANConnection destructor
|
||||||
*/
|
*/
|
||||||
@@ -44,7 +47,7 @@ public:
|
|||||||
QString getPort();
|
QString getPort();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief getQueue is call by reader to get a reference on the queue to monitor
|
* @brief getQueue
|
||||||
* @return the lock free queue of the device
|
* @return the lock free queue of the device
|
||||||
*/
|
*/
|
||||||
LFQueue<CANFrame>& getQueue();
|
LFQueue<CANFrame>& getQueue();
|
||||||
@@ -63,6 +66,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
/*not implemented yet */
|
||||||
void error(const QString &);
|
void error(const QString &);
|
||||||
void deviceInfo(int, int); //First param = driver version (or version of whatever you want), second param a status byte
|
void deviceInfo(int, int); //First param = driver version (or version of whatever you want), second param a status byte
|
||||||
|
|
||||||
@@ -73,7 +77,7 @@ signals:
|
|||||||
void busStatus(int, int, int);
|
void busStatus(int, int, int);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief event sent when the CANCon::status of the connection changes (connected->not_connected or the other way round)
|
* @brief event emitted when the CANCon::status of the connection changes (connected->not_connected or the other way round)
|
||||||
* @param pStatus: the new status of the device
|
* @param pStatus: the new status of the device
|
||||||
*/
|
*/
|
||||||
void status(CANCon::status pStatus);
|
void status(CANCon::status pStatus);
|
||||||
@@ -82,13 +86,13 @@ signals:
|
|||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief start the device, this calls piStarted
|
* @brief start the device. This calls piStarted
|
||||||
* @note starts the working thread if required (piStarted in the working thread context)
|
* @note starts the working thread if required (piStarted is called in the working thread context)
|
||||||
*/
|
*/
|
||||||
void start();
|
void start();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief stop the device, this calls piStop
|
* @brief stop the device. This calls piStop
|
||||||
* @note if a working thread is used, piStop is called before exiting the working thread
|
* @note if a working thread is used, piStop is called before exiting the working thread
|
||||||
*/
|
*/
|
||||||
void stop();
|
void stop();
|
||||||
@@ -113,20 +117,30 @@ public slots:
|
|||||||
/**
|
/**
|
||||||
* @brief suspends/restarts data capture
|
* @brief suspends/restarts data capture
|
||||||
* @param pSuspend: suspends capture if true else restarts it
|
* @param pSuspend: suspends capture if true else restarts it
|
||||||
* @note this calls piSuspend in the working thread context (if one has been started)
|
* @note this calls piSuspend (in the working thread context if one has been started)
|
||||||
* @note the caller will not access the queue when capture is suspended, so it is safe for callee to flush the queue
|
* @note the caller shall not access the queue when capture is suspended, it is then safe for callee to flush the queue
|
||||||
*/
|
*/
|
||||||
void suspend(bool pSuspend);
|
void suspend(bool pSuspend);
|
||||||
|
|
||||||
void sendFrame(const CANFrame&);
|
/**
|
||||||
void sendFrameBatch(const QList<CANFrame>&);
|
* @brief provides device with the frame to send
|
||||||
|
* @param pFrame: the frame to send
|
||||||
|
* @note this calls piSendFrame (in the working thread context if one has been started)
|
||||||
|
*/
|
||||||
|
void sendFrame(const CANFrame& pFrame);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief provides device with a list of frames to send
|
||||||
|
* @param pFrame: the list of frames to send
|
||||||
|
* @note this calls piSendFrameBatch (in the working thread context if one has been started)
|
||||||
|
*/
|
||||||
|
void sendFrameBatch(const QList<CANFrame>& pFrames);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief setStatus
|
* @brief setStatus
|
||||||
* @param pStatus: the status to set
|
* @param pStatus: the status to set
|
||||||
* @note multithread safe (can be used while another thread calls @ref getStatus)
|
|
||||||
*/
|
*/
|
||||||
void setStatus(CANCon::status pStatus);
|
void setStatus(CANCon::status pStatus);
|
||||||
|
|
||||||
@@ -134,7 +148,6 @@ protected:
|
|||||||
* @brief isConfigured
|
* @brief isConfigured
|
||||||
* @param pBusId
|
* @param pBusId
|
||||||
* @return true if bus is configured
|
* @return true if bus is configured
|
||||||
* @note NOT multithread safe
|
|
||||||
*/
|
*/
|
||||||
bool isConfigured(int pBusId);
|
bool isConfigured(int pBusId);
|
||||||
|
|
||||||
@@ -143,7 +156,6 @@ protected:
|
|||||||
* @param pBusId
|
* @param pBusId
|
||||||
* @param pConfigured
|
* @param pConfigured
|
||||||
* @note it is not necessary to call this function to set pBusId configured, it is enough to call @ref setBusConfig
|
* @note it is not necessary to call this function to set pBusId configured, it is enough to call @ref setBusConfig
|
||||||
* @note NOT multithread safe
|
|
||||||
*/
|
*/
|
||||||
void setConfigured(int pBusId, bool pConfigured);
|
void setConfigured(int pBusId, bool pConfigured);
|
||||||
|
|
||||||
@@ -152,7 +164,6 @@ protected:
|
|||||||
* @param pBusId
|
* @param pBusId
|
||||||
* @param pBus
|
* @param pBus
|
||||||
* @return true if operation succeeds, false if pBusIdx is invalid or bus has not been configured yet
|
* @return true if operation succeeds, false if pBusIdx is invalid or bus has not been configured yet
|
||||||
* @note NOT multithread safe
|
|
||||||
*/
|
*/
|
||||||
bool getBusConfig(int pBusId, CANBus& pBus);
|
bool getBusConfig(int pBusId, CANBus& pBus);
|
||||||
|
|
||||||
@@ -160,47 +171,46 @@ protected:
|
|||||||
* @brief setBusConfig
|
* @brief setBusConfig
|
||||||
* @param pBusId: the index of the bus for which settings have to be set
|
* @param pBusId: the index of the bus for which settings have to be set
|
||||||
* @param pBus: the settings to set
|
* @param pBus: the settings to set
|
||||||
* @note NOT multithread safe
|
|
||||||
*/
|
*/
|
||||||
void setBusConfig(int pBusId, CANBus& pBus);
|
void setBusConfig(int pBusId, CANBus& pBus);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief isCapSuspended
|
* @brief isCapSuspended
|
||||||
* @return true if the capture is suspended
|
* @return true if the capture is suspended
|
||||||
* @note NOT multithread safe
|
|
||||||
*/
|
*/
|
||||||
bool isCapSuspended();
|
bool isCapSuspended();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief setCapSuspended
|
* @brief setCapSuspended
|
||||||
* @param pIsSuspended
|
* @param pIsSuspended
|
||||||
* @note NOT multithread safe
|
|
||||||
*/
|
*/
|
||||||
void setCapSuspended(bool pIsSuspended);
|
void setCapSuspended(bool pIsSuspended);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
/**************************************************************/
|
||||||
|
/*********** protected interface to implement *******/
|
||||||
|
/**************************************************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief start the device
|
* @brief starts the device
|
||||||
* @note start a working thread here if needed
|
|
||||||
*/
|
*/
|
||||||
virtual void piStarted() = 0;
|
virtual void piStarted() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief stop the device
|
* @brief stops the device
|
||||||
* @note stop the working thread here if one has been started
|
|
||||||
*/
|
*/
|
||||||
virtual void piStop() = 0;
|
virtual void piStop() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief setBusSettings
|
* @brief piSetBusSettings
|
||||||
* @param pBusIdx: the index of the bus for which settings have to be set
|
* @param pBusIdx: the index of the bus for which settings have to be set
|
||||||
* @param pBus: the settings to set
|
* @param pBus: the settings to set
|
||||||
*/
|
*/
|
||||||
virtual void piSetBusSettings(int pBusIdx, CANBus pBus) = 0;
|
virtual void piSetBusSettings(int pBusIdx, CANBus pBus) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief getBusSettings
|
* @brief piGetBusSettings
|
||||||
* @param pBusIdx: the index of the bus for which settings have to be retrieved
|
* @param pBusIdx: the index of the bus for which settings have to be retrieved
|
||||||
* @param pBus: the CANBus struct to fill with information
|
* @param pBus: the CANBus struct to fill with information
|
||||||
* @return true if operation succeeds, false if pBusIdx is invalid or bus has not been configured yet
|
* @return true if operation succeeds, false if pBusIdx is invalid or bus has not been configured yet
|
||||||
@@ -214,7 +224,16 @@ protected:
|
|||||||
*/
|
*/
|
||||||
virtual void piSuspend(bool pSuspend) = 0;
|
virtual void piSuspend(bool pSuspend) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief provides device with the frame to send
|
||||||
|
* @param pFrame: the frame to send
|
||||||
|
*/
|
||||||
virtual void piSendFrame(const CANFrame&) = 0;
|
virtual void piSendFrame(const CANFrame&) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief provides device with a list of frames to send
|
||||||
|
* @param pFrame: the list of frames to send
|
||||||
|
*/
|
||||||
virtual void piSendFrameBatch(const QList<CANFrame>&) = 0;
|
virtual void piSendFrameBatch(const QList<CANFrame>&) = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+19
-19
@@ -10,23 +10,23 @@
|
|||||||
/**** class definition ****/
|
/**** class definition ****/
|
||||||
/***********************************/
|
/***********************************/
|
||||||
|
|
||||||
SocketCanConnection::SocketCanConnection(QString portName) :
|
SocketCan::SocketCan(QString portName) :
|
||||||
CANConnection(portName, CANCon::SOCKETCAN, 1, 4000, true),
|
CANConnection(portName, CANCon::SOCKETCAN, 1, 4000, true),
|
||||||
mDev_p(NULL),
|
mDev_p(NULL),
|
||||||
mTimer(this) /*NB: set connection as parent of timer to manage it from working thread */
|
mTimer(this) /*NB: set connection as parent of timer to manage it from working thread */
|
||||||
{
|
{
|
||||||
qDebug() << "SocketCanConnection()";
|
qDebug() << "SocketCan()";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SocketCanConnection::~SocketCanConnection()
|
SocketCan::~SocketCan()
|
||||||
{
|
{
|
||||||
stop();
|
stop();
|
||||||
qDebug() << "~SocketCanConnection()";
|
qDebug() << "~SocketCan()";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SocketCanConnection::piStarted()
|
void SocketCan::piStarted()
|
||||||
{
|
{
|
||||||
connect(&mTimer, SIGNAL(timeout()), this, SLOT(testConnection()));
|
connect(&mTimer, SIGNAL(timeout()), this, SLOT(testConnection()));
|
||||||
mTimer.setInterval(1000);
|
mTimer.setInterval(1000);
|
||||||
@@ -35,7 +35,7 @@ void SocketCanConnection::piStarted()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SocketCanConnection::piSuspend(bool pSuspend)
|
void SocketCan::piSuspend(bool pSuspend)
|
||||||
{
|
{
|
||||||
/* update capSuspended */
|
/* update capSuspended */
|
||||||
setCapSuspended(pSuspend);
|
setCapSuspended(pSuspend);
|
||||||
@@ -46,19 +46,19 @@ void SocketCanConnection::piSuspend(bool pSuspend)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SocketCanConnection::piStop() {
|
void SocketCan::piStop() {
|
||||||
mTimer.stop();
|
mTimer.stop();
|
||||||
disconnectDevice();
|
disconnectDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool SocketCanConnection::piGetBusSettings(int pBusIdx, CANBus& pBus)
|
bool SocketCan::piGetBusSettings(int pBusIdx, CANBus& pBus)
|
||||||
{
|
{
|
||||||
return getBusConfig(pBusIdx, pBus);
|
return getBusConfig(pBusIdx, pBus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SocketCanConnection::piSetBusSettings(int pBusIdx, CANBus bus)
|
void SocketCan::piSetBusSettings(int pBusIdx, CANBus bus)
|
||||||
{
|
{
|
||||||
/* sanity checks */
|
/* sanity checks */
|
||||||
if(0 != pBusIdx)
|
if(0 != pBusIdx)
|
||||||
@@ -84,9 +84,9 @@ void SocketCanConnection::piSetBusSettings(int pBusIdx, CANBus bus)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* connect slots */
|
/* connect slots */
|
||||||
connect(mDev_p, &QCanBusDevice::errorOccurred, this, &SocketCanConnection::errorReceived);
|
connect(mDev_p, &QCanBusDevice::errorOccurred, this, &SocketCan::errorReceived);
|
||||||
connect(mDev_p, &QCanBusDevice::framesWritten, this, &SocketCanConnection::framesWritten);
|
connect(mDev_p, &QCanBusDevice::framesWritten, this, &SocketCan::framesWritten);
|
||||||
connect(mDev_p, &QCanBusDevice::framesReceived, this, &SocketCanConnection::framesReceived);
|
connect(mDev_p, &QCanBusDevice::framesReceived, this, &SocketCan::framesReceived);
|
||||||
|
|
||||||
/* set configuration */
|
/* set configuration */
|
||||||
/*if (p.useConfigurationEnabled) {
|
/*if (p.useConfigurationEnabled) {
|
||||||
@@ -102,8 +102,8 @@ void SocketCanConnection::piSetBusSettings(int pBusIdx, CANBus bus)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SocketCanConnection::piSendFrame(const CANFrame&) {}
|
void SocketCan::piSendFrame(const CANFrame&) {}
|
||||||
void SocketCanConnection::piSendFrameBatch(const QList<CANFrame>&){}
|
void SocketCan::piSendFrameBatch(const QList<CANFrame>&){}
|
||||||
|
|
||||||
|
|
||||||
/***********************************/
|
/***********************************/
|
||||||
@@ -112,7 +112,7 @@ void SocketCanConnection::piSendFrameBatch(const QList<CANFrame>&){}
|
|||||||
|
|
||||||
|
|
||||||
/* disconnect device */
|
/* disconnect device */
|
||||||
void SocketCanConnection::disconnectDevice() {
|
void SocketCan::disconnectDevice() {
|
||||||
if(mDev_p) {
|
if(mDev_p) {
|
||||||
mDev_p->disconnectDevice();
|
mDev_p->disconnectDevice();
|
||||||
delete mDev_p;
|
delete mDev_p;
|
||||||
@@ -121,7 +121,7 @@ void SocketCanConnection::disconnectDevice() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SocketCanConnection::errorReceived(QCanBusDevice::CanBusError error) const
|
void SocketCan::errorReceived(QCanBusDevice::CanBusError error) const
|
||||||
{
|
{
|
||||||
switch (error) {
|
switch (error) {
|
||||||
case QCanBusDevice::ReadError:
|
case QCanBusDevice::ReadError:
|
||||||
@@ -135,12 +135,12 @@ void SocketCanConnection::errorReceived(QCanBusDevice::CanBusError error) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SocketCanConnection::framesWritten(qint64 count)
|
void SocketCan::framesWritten(qint64 count)
|
||||||
{
|
{
|
||||||
qDebug() << "Number of frames written:" << count;
|
qDebug() << "Number of frames written:" << count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SocketCanConnection::framesReceived()
|
void SocketCan::framesReceived()
|
||||||
{
|
{
|
||||||
/* sanity checks */
|
/* sanity checks */
|
||||||
if(!mDev_p)
|
if(!mDev_p)
|
||||||
@@ -186,7 +186,7 @@ void SocketCanConnection::framesReceived()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SocketCanConnection::testConnection() {
|
void SocketCan::testConnection() {
|
||||||
QCanBusDevice* dev_p = QCanBus::instance()->createDevice("socketcan", getPort());
|
QCanBusDevice* dev_p = QCanBus::instance()->createDevice("socketcan", getPort());
|
||||||
|
|
||||||
switch(getStatus())
|
switch(getStatus())
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef SOCKETCANCONNECTION_H
|
#ifndef SocketCan_H
|
||||||
#define SOCKETCANCONNECTION_H
|
#define SocketCan_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QCanBus>
|
#include <QCanBus>
|
||||||
@@ -10,13 +10,13 @@
|
|||||||
#include "canconnection.h"
|
#include "canconnection.h"
|
||||||
|
|
||||||
|
|
||||||
class SocketCanConnection : public CANConnection
|
class SocketCan : public CANConnection
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SocketCanConnection(QString portName);
|
SocketCan(QString portName);
|
||||||
virtual ~SocketCanConnection();
|
virtual ~SocketCan();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void error(const QString &);
|
void error(const QString &);
|
||||||
@@ -54,4 +54,4 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // SOCKETCANCONNECTION_H
|
#endif // SocketCan_H
|
||||||
|
|||||||
Reference in New Issue
Block a user