renamed socketcan class
This commit is contained in:
@@ -9,7 +9,7 @@ CANConnection* CanConFactory::create(type pType, QString pPortName)
|
||||
{
|
||||
switch(pType) {
|
||||
case SOCKETCAN:
|
||||
return new SocketCanConnection(pPortName);
|
||||
return new SocketCan(pPortName);
|
||||
case GVRET_SERIAL:
|
||||
return new GVRetSerial(pPortName);
|
||||
default: {}
|
||||
|
||||
+43
-24
@@ -23,8 +23,11 @@ public:
|
||||
* @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
|
||||
*/
|
||||
CANConnection(QString pPort, CANCon::type pType, int pNumBuses,
|
||||
int pQueueLen, bool pUseThread);
|
||||
CANConnection(QString pPort,
|
||||
CANCon::type pType,
|
||||
int pNumBuses,
|
||||
int pQueueLen,
|
||||
bool pUseThread);
|
||||
/**
|
||||
* @brief CANConnection destructor
|
||||
*/
|
||||
@@ -44,7 +47,7 @@ public:
|
||||
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
|
||||
*/
|
||||
LFQueue<CANFrame>& getQueue();
|
||||
@@ -63,6 +66,7 @@ public:
|
||||
|
||||
|
||||
signals:
|
||||
/*not implemented yet */
|
||||
void error(const QString &);
|
||||
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);
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
void status(CANCon::status pStatus);
|
||||
@@ -82,13 +86,13 @@ signals:
|
||||
public slots:
|
||||
|
||||
/**
|
||||
* @brief start the device, this calls piStarted
|
||||
* @note starts the working thread if required (piStarted in the working thread context)
|
||||
* @brief start the device. This calls piStarted
|
||||
* @note starts the working thread if required (piStarted is called in the working thread context)
|
||||
*/
|
||||
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
|
||||
*/
|
||||
void stop();
|
||||
@@ -113,20 +117,30 @@ public slots:
|
||||
/**
|
||||
* @brief suspends/restarts data capture
|
||||
* @param pSuspend: suspends capture if true else restarts it
|
||||
* @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 this calls piSuspend (in the working thread context if one has been started)
|
||||
* @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 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:
|
||||
|
||||
/**
|
||||
* @brief setStatus
|
||||
* @param pStatus: the status to set
|
||||
* @note multithread safe (can be used while another thread calls @ref getStatus)
|
||||
*/
|
||||
void setStatus(CANCon::status pStatus);
|
||||
|
||||
@@ -134,7 +148,6 @@ protected:
|
||||
* @brief isConfigured
|
||||
* @param pBusId
|
||||
* @return true if bus is configured
|
||||
* @note NOT multithread safe
|
||||
*/
|
||||
bool isConfigured(int pBusId);
|
||||
|
||||
@@ -143,7 +156,6 @@ protected:
|
||||
* @param pBusId
|
||||
* @param pConfigured
|
||||
* @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);
|
||||
|
||||
@@ -152,7 +164,6 @@ protected:
|
||||
* @param pBusId
|
||||
* @param pBus
|
||||
* @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);
|
||||
|
||||
@@ -160,47 +171,46 @@ protected:
|
||||
* @brief setBusConfig
|
||||
* @param pBusId: the index of the bus for which settings have to be set
|
||||
* @param pBus: the settings to set
|
||||
* @note NOT multithread safe
|
||||
*/
|
||||
void setBusConfig(int pBusId, CANBus& pBus);
|
||||
|
||||
/**
|
||||
* @brief isCapSuspended
|
||||
* @return true if the capture is suspended
|
||||
* @note NOT multithread safe
|
||||
*/
|
||||
bool isCapSuspended();
|
||||
|
||||
/**
|
||||
* @brief setCapSuspended
|
||||
* @param pIsSuspended
|
||||
* @note NOT multithread safe
|
||||
*/
|
||||
void setCapSuspended(bool pIsSuspended);
|
||||
|
||||
protected:
|
||||
|
||||
/**************************************************************/
|
||||
/*********** protected interface to implement *******/
|
||||
/**************************************************************/
|
||||
|
||||
/**
|
||||
* @brief start the device
|
||||
* @note start a working thread here if needed
|
||||
* @brief starts the device
|
||||
*/
|
||||
virtual void piStarted() = 0;
|
||||
|
||||
/**
|
||||
* @brief stop the device
|
||||
* @note stop the working thread here if one has been started
|
||||
* @brief stops the device
|
||||
*/
|
||||
virtual void piStop() = 0;
|
||||
|
||||
/**
|
||||
* @brief setBusSettings
|
||||
* @brief piSetBusSettings
|
||||
* @param pBusIdx: the index of the bus for which settings have to be set
|
||||
* @param pBus: the settings to set
|
||||
*/
|
||||
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 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
|
||||
@@ -214,7 +224,16 @@ protected:
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* @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;
|
||||
|
||||
|
||||
|
||||
+19
-19
@@ -10,23 +10,23 @@
|
||||
/**** class definition ****/
|
||||
/***********************************/
|
||||
|
||||
SocketCanConnection::SocketCanConnection(QString portName) :
|
||||
SocketCan::SocketCan(QString portName) :
|
||||
CANConnection(portName, CANCon::SOCKETCAN, 1, 4000, true),
|
||||
mDev_p(NULL),
|
||||
mTimer(this) /*NB: set connection as parent of timer to manage it from working thread */
|
||||
{
|
||||
qDebug() << "SocketCanConnection()";
|
||||
qDebug() << "SocketCan()";
|
||||
}
|
||||
|
||||
|
||||
SocketCanConnection::~SocketCanConnection()
|
||||
SocketCan::~SocketCan()
|
||||
{
|
||||
stop();
|
||||
qDebug() << "~SocketCanConnection()";
|
||||
qDebug() << "~SocketCan()";
|
||||
}
|
||||
|
||||
|
||||
void SocketCanConnection::piStarted()
|
||||
void SocketCan::piStarted()
|
||||
{
|
||||
connect(&mTimer, SIGNAL(timeout()), this, SLOT(testConnection()));
|
||||
mTimer.setInterval(1000);
|
||||
@@ -35,7 +35,7 @@ void SocketCanConnection::piStarted()
|
||||
}
|
||||
|
||||
|
||||
void SocketCanConnection::piSuspend(bool pSuspend)
|
||||
void SocketCan::piSuspend(bool pSuspend)
|
||||
{
|
||||
/* update capSuspended */
|
||||
setCapSuspended(pSuspend);
|
||||
@@ -46,19 +46,19 @@ void SocketCanConnection::piSuspend(bool pSuspend)
|
||||
}
|
||||
|
||||
|
||||
void SocketCanConnection::piStop() {
|
||||
void SocketCan::piStop() {
|
||||
mTimer.stop();
|
||||
disconnectDevice();
|
||||
}
|
||||
|
||||
|
||||
bool SocketCanConnection::piGetBusSettings(int pBusIdx, CANBus& pBus)
|
||||
bool SocketCan::piGetBusSettings(int pBusIdx, CANBus& pBus)
|
||||
{
|
||||
return getBusConfig(pBusIdx, pBus);
|
||||
}
|
||||
|
||||
|
||||
void SocketCanConnection::piSetBusSettings(int pBusIdx, CANBus bus)
|
||||
void SocketCan::piSetBusSettings(int pBusIdx, CANBus bus)
|
||||
{
|
||||
/* sanity checks */
|
||||
if(0 != pBusIdx)
|
||||
@@ -84,9 +84,9 @@ void SocketCanConnection::piSetBusSettings(int pBusIdx, CANBus bus)
|
||||
}
|
||||
|
||||
/* connect slots */
|
||||
connect(mDev_p, &QCanBusDevice::errorOccurred, this, &SocketCanConnection::errorReceived);
|
||||
connect(mDev_p, &QCanBusDevice::framesWritten, this, &SocketCanConnection::framesWritten);
|
||||
connect(mDev_p, &QCanBusDevice::framesReceived, this, &SocketCanConnection::framesReceived);
|
||||
connect(mDev_p, &QCanBusDevice::errorOccurred, this, &SocketCan::errorReceived);
|
||||
connect(mDev_p, &QCanBusDevice::framesWritten, this, &SocketCan::framesWritten);
|
||||
connect(mDev_p, &QCanBusDevice::framesReceived, this, &SocketCan::framesReceived);
|
||||
|
||||
/* set configuration */
|
||||
/*if (p.useConfigurationEnabled) {
|
||||
@@ -102,8 +102,8 @@ void SocketCanConnection::piSetBusSettings(int pBusIdx, CANBus bus)
|
||||
}
|
||||
|
||||
|
||||
void SocketCanConnection::piSendFrame(const CANFrame&) {}
|
||||
void SocketCanConnection::piSendFrameBatch(const QList<CANFrame>&){}
|
||||
void SocketCan::piSendFrame(const CANFrame&) {}
|
||||
void SocketCan::piSendFrameBatch(const QList<CANFrame>&){}
|
||||
|
||||
|
||||
/***********************************/
|
||||
@@ -112,7 +112,7 @@ void SocketCanConnection::piSendFrameBatch(const QList<CANFrame>&){}
|
||||
|
||||
|
||||
/* disconnect device */
|
||||
void SocketCanConnection::disconnectDevice() {
|
||||
void SocketCan::disconnectDevice() {
|
||||
if(mDev_p) {
|
||||
mDev_p->disconnectDevice();
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
|
||||
void SocketCanConnection::framesReceived()
|
||||
void SocketCan::framesReceived()
|
||||
{
|
||||
/* sanity checks */
|
||||
if(!mDev_p)
|
||||
@@ -186,7 +186,7 @@ void SocketCanConnection::framesReceived()
|
||||
}
|
||||
|
||||
|
||||
void SocketCanConnection::testConnection() {
|
||||
void SocketCan::testConnection() {
|
||||
QCanBusDevice* dev_p = QCanBus::instance()->createDevice("socketcan", getPort());
|
||||
|
||||
switch(getStatus())
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef SOCKETCANCONNECTION_H
|
||||
#define SOCKETCANCONNECTION_H
|
||||
#ifndef SocketCan_H
|
||||
#define SocketCan_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QCanBus>
|
||||
@@ -10,13 +10,13 @@
|
||||
#include "canconnection.h"
|
||||
|
||||
|
||||
class SocketCanConnection : public CANConnection
|
||||
class SocketCan : public CANConnection
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SocketCanConnection(QString portName);
|
||||
virtual ~SocketCanConnection();
|
||||
SocketCan(QString portName);
|
||||
virtual ~SocketCan();
|
||||
|
||||
signals:
|
||||
void error(const QString &);
|
||||
@@ -54,4 +54,4 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
#endif // SOCKETCANCONNECTION_H
|
||||
#endif // SocketCan_H
|
||||
|
||||
Reference in New Issue
Block a user