Merge pull request #59 from canpadawan/WIP2
CANConManager and example of usage for javascript
This commit is contained in:
+4
-2
@@ -54,7 +54,8 @@ SOURCES += main.cpp\
|
|||||||
connections/canconnection.cpp \
|
connections/canconnection.cpp \
|
||||||
connections/socketcan.cpp \
|
connections/socketcan.cpp \
|
||||||
connections/canconfactory.cpp \
|
connections/canconfactory.cpp \
|
||||||
connections/gvretserial.cpp
|
connections/gvretserial.cpp \
|
||||||
|
connections/canconmanager.cpp
|
||||||
|
|
||||||
HEADERS += mainwindow.h \
|
HEADERS += mainwindow.h \
|
||||||
can_structs.h \
|
can_structs.h \
|
||||||
@@ -97,7 +98,8 @@ HEADERS += mainwindow.h \
|
|||||||
connections/socketcan.h \
|
connections/socketcan.h \
|
||||||
connections/canconconst.h \
|
connections/canconconst.h \
|
||||||
connections/canconfactory.h \
|
connections/canconfactory.h \
|
||||||
connections/gvretserial.h
|
connections/gvretserial.h \
|
||||||
|
connections/canconmanager.h
|
||||||
|
|
||||||
FORMS += mainwindow.ui \
|
FORMS += mainwindow.ui \
|
||||||
graphingwindow.ui \
|
graphingwindow.ui \
|
||||||
|
|||||||
+26
-17
@@ -24,44 +24,53 @@ bool CANBus::operator==(const CANBus& bus) const{
|
|||||||
active == bus.active;
|
active == bus.active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CANBus::setSpeed(int newSpeed){
|
||||||
void CANBus::setSpeed(int newSpeed)
|
|
||||||
{
|
|
||||||
speed = newSpeed;
|
speed = newSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CANBus::setListenOnly(bool mode)
|
void CANBus::setListenOnly(bool mode){
|
||||||
{
|
|
||||||
listenOnly = mode;
|
listenOnly = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CANBus::setSingleWire(bool mode)
|
void CANBus::setSingleWire(bool mode){
|
||||||
{
|
|
||||||
singleWire = mode;
|
singleWire = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CANBus::setEnabled(bool mode)
|
void CANBus::setEnabled(bool mode){
|
||||||
{
|
|
||||||
active = mode;
|
active = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CANBus::getSpeed()
|
int CANBus::getSpeed(){
|
||||||
{
|
|
||||||
return speed;
|
return speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CANBus::isListenOnly()
|
bool CANBus::isListenOnly(){
|
||||||
{
|
|
||||||
return listenOnly;
|
return listenOnly;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CANBus::isSingleWire()
|
bool CANBus::isSingleWire(){
|
||||||
{
|
|
||||||
return singleWire;
|
return singleWire;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CANBus::isActive()
|
bool CANBus::isActive(){
|
||||||
{
|
|
||||||
return active;
|
return active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QDataStream& operator<<( QDataStream & pStream, const CANBus& pCanBus )
|
||||||
|
{
|
||||||
|
pStream << pCanBus.speed;
|
||||||
|
pStream << pCanBus.listenOnly;
|
||||||
|
pStream << pCanBus.singleWire;
|
||||||
|
pStream << pCanBus.active;
|
||||||
|
return pStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDataStream & operator>>(QDataStream & pStream, CANBus& pCanBus)
|
||||||
|
{
|
||||||
|
pStream >> pCanBus.speed;
|
||||||
|
pStream >> pCanBus.listenOnly;
|
||||||
|
pStream >> pCanBus.singleWire;
|
||||||
|
pStream >> pCanBus.active;
|
||||||
|
return pStream;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#ifndef CANBus_H
|
#ifndef CANBus_H
|
||||||
#define CANBus_H
|
#define CANBus_H
|
||||||
|
#include <QDataStream>
|
||||||
|
|
||||||
class CANBus
|
class CANBus
|
||||||
{
|
{
|
||||||
@@ -8,7 +8,8 @@ public:
|
|||||||
CANBus();
|
CANBus();
|
||||||
CANBus(const CANBus&);
|
CANBus(const CANBus&);
|
||||||
bool operator==(const CANBus&) const;
|
bool operator==(const CANBus&) const;
|
||||||
virtual ~CANBus(){}; /*TODO: remove connection from CANBus and add CANBus as an element of CANConnection */
|
virtual ~CANBus(){};
|
||||||
|
|
||||||
int speed;
|
int speed;
|
||||||
bool listenOnly;
|
bool listenOnly;
|
||||||
bool singleWire;
|
bool singleWire;
|
||||||
@@ -25,4 +26,9 @@ public:
|
|||||||
bool isActive();
|
bool isActive();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
QDataStream& operator<<( QDataStream & pStream, const CANBus& pCanBus );
|
||||||
|
QDataStream & operator>>(QDataStream & pStream, CANBus& pCanBus);
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(CANBus);
|
||||||
|
|
||||||
#endif // CANBus_H
|
#endif // CANBus_H
|
||||||
|
|||||||
+44
-23
@@ -1,11 +1,16 @@
|
|||||||
#include "connections/canconnection.h"
|
|
||||||
#include "canconnectionmodel.h"
|
#include "canconnectionmodel.h"
|
||||||
|
#include "connections/canconnection.h"
|
||||||
|
#include "connections/canconmanager.h"
|
||||||
|
|
||||||
CANConnectionModel::CANConnectionModel(QObject *parent)
|
CANConnectionModel::CANConnectionModel(QObject *parent)
|
||||||
: QAbstractTableModel(parent)
|
: QAbstractTableModel(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CANConnectionModel::~CANConnectionModel()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariant CANConnectionModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant CANConnectionModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
@@ -52,17 +57,20 @@ QVariant CANConnectionModel::headerData(int section, Qt::Orientation orientation
|
|||||||
|
|
||||||
int CANConnectionModel::columnCount(const QModelIndex &parent) const
|
int CANConnectionModel::columnCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(parent);
|
||||||
return 7;
|
return 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int CANConnectionModel::rowCount(const QModelIndex &parent) const {
|
int CANConnectionModel::rowCount(const QModelIndex &parent) const
|
||||||
int rows=0;
|
{
|
||||||
QList<CANConnection*>::const_iterator iter;
|
Q_UNUSED(parent);
|
||||||
|
|
||||||
for (iter = mConns.begin() ; iter != mConns.end() ; ++iter) {
|
int rows=0;
|
||||||
rows+=(*iter)->getNumBuses();
|
QList<CANConnection*>& conns = CANConManager::getInstance()->getConnections();
|
||||||
}
|
|
||||||
|
foreach(const CANConnection* conn_p, conns)
|
||||||
|
rows+=conn_p->getNumBuses();
|
||||||
|
|
||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
@@ -124,49 +132,62 @@ QVariant CANConnectionModel::data(const QModelIndex &index, int role) const
|
|||||||
|
|
||||||
void CANConnectionModel::add(CANConnection* pConn_p)
|
void CANConnectionModel::add(CANConnection* pConn_p)
|
||||||
{
|
{
|
||||||
|
CANConManager* manager = CANConManager::getInstance();
|
||||||
|
|
||||||
|
connect(pConn_p, SIGNAL(notify()), manager, SLOT(refreshCanList()));
|
||||||
|
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
mConns.append(pConn_p);
|
manager->getConnections().append(pConn_p);
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CANConnectionModel::remove(CANConnection* pConn_p)
|
void CANConnectionModel::remove(CANConnection* pConn_p)
|
||||||
{
|
{
|
||||||
|
CANConManager* manager = CANConManager::getInstance();
|
||||||
|
|
||||||
|
disconnect(pConn_p, 0, manager, 0);
|
||||||
|
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
mConns.removeOne(pConn_p);
|
manager->getConnections().removeOne(pConn_p);
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QList<CANConnection*>& CANConnectionModel::getConnections()
|
|
||||||
{
|
|
||||||
return mConns;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
CANConnection* CANConnectionModel::getAtIdx(int pIdx, int& pBusId) const
|
CANConnection* CANConnectionModel::getAtIdx(int pIdx, int& pBusId) const
|
||||||
{
|
{
|
||||||
if (pIdx < 0)
|
if (pIdx < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
int i=0;
|
int i=0;
|
||||||
QList<CANConnection*>::const_iterator iter = mConns.begin();
|
QList<CANConnection*>& conns = CANConManager::getInstance()->getConnections();
|
||||||
|
|
||||||
for (iter = mConns.begin() ; iter != mConns.end() ; ++iter) {
|
foreach(CANConnection* conn_p, conns)
|
||||||
if( i <= pIdx && pIdx < i+(*iter)->getNumBuses() ) {
|
{
|
||||||
|
if( i <= pIdx && pIdx < i+conn_p->getNumBuses() ) {
|
||||||
pBusId = pIdx - i;
|
pBusId = pIdx - i;
|
||||||
return (*iter);
|
return conn_p;
|
||||||
}
|
}
|
||||||
|
|
||||||
i+= (*iter)->getNumBuses();
|
i+= conn_p->getNumBuses();
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CANConnectionModel::refreshView()
|
void CANConnectionModel::refresh(int pIndex)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
QModelIndex begin;
|
||||||
endResetModel();
|
QModelIndex end;
|
||||||
|
|
||||||
|
if(pIndex>=0) {
|
||||||
|
begin = createIndex(pIndex, 0);
|
||||||
|
end = createIndex(pIndex, columnCount()-1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
begin = createIndex(0, 0);
|
||||||
|
end = createIndex(rowCount()-1, columnCount()-1);
|
||||||
|
}
|
||||||
|
dataChanged(begin, end, QVector<int>(Qt::DisplayRole));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,25 +15,19 @@ class CANConnectionModel : public QAbstractTableModel
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CANConnectionModel(QObject *parent = 0);
|
explicit CANConnectionModel(QObject *parent = 0);
|
||||||
|
virtual ~CANConnectionModel();
|
||||||
|
|
||||||
// Header:
|
// from abstractmodel:
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
|
||||||
void add(CANConnection* pConn_p);
|
void add(CANConnection* pConn_p);
|
||||||
void remove(CANConnection* pConn_p);
|
void remove(CANConnection* pConn_p);
|
||||||
|
|
||||||
QList<CANConnection*>& getConnections();
|
|
||||||
CANConnection* getAtIdx(int, int&) const;
|
CANConnection* getAtIdx(int, int&) const;
|
||||||
void refreshView();
|
void refresh(int pIndex=-1);
|
||||||
|
|
||||||
private:
|
|
||||||
QList<CANConnection*> mConns;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CANCONNECTIONMODEL_H
|
#endif // CANCONNECTIONMODEL_H
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ public:
|
|||||||
void setFilter(uint32_t id, uint32_t mask, int bus);
|
void setFilter(uint32_t id, uint32_t mask, int bus);
|
||||||
bool checkFilter(uint32_t id, int bus);
|
bool checkFilter(uint32_t id, int bus);
|
||||||
|
|
||||||
private:
|
public:
|
||||||
uint32_t ID;
|
uint32_t ID;
|
||||||
uint32_t mask;
|
uint32_t mask;
|
||||||
int bus;
|
int bus;
|
||||||
|
|||||||
+17
-24
@@ -282,7 +282,7 @@ QVariant CANFrameModel::headerData(int section, Qt::Orientation orientation,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CANFrameModel::addFrame(CANFrame& frame, bool autoRefresh = false)
|
void CANFrameModel::addFrame(const CANFrame& frame, bool autoRefresh = false)
|
||||||
{
|
{
|
||||||
/*TODO: remove mutex */
|
/*TODO: remove mutex */
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
@@ -346,6 +346,15 @@ void CANFrameModel::addFrame(CANFrame& frame, bool autoRefresh = false)
|
|||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CANFrameModel::addFrames(const CANConnection*, const QVector<CANFrame>& pFrames)
|
||||||
|
{
|
||||||
|
foreach(const CANFrame& frame, pFrames)
|
||||||
|
{
|
||||||
|
addFrame(frame);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CANFrameModel::sendRefresh()
|
void CANFrameModel::sendRefresh()
|
||||||
{
|
{
|
||||||
qDebug() << "Sending mass refresh";
|
qDebug() << "Sending mass refresh";
|
||||||
@@ -377,38 +386,22 @@ void CANFrameModel::sendRefresh(int pos)
|
|||||||
//issue a refresh for the last num entries in the model.
|
//issue a refresh for the last num entries in the model.
|
||||||
//used by the serial worker to do batch updates so it doesn't
|
//used by the serial worker to do batch updates so it doesn't
|
||||||
//have to send thousands of messages per second
|
//have to send thousands of messages per second
|
||||||
void CANFrameModel::sendBulkRefresh(int num)
|
int CANFrameModel::sendBulkRefresh()
|
||||||
{
|
{
|
||||||
//yes, num was sent to us by the serial worker but we actually have a better idea
|
int num = filteredFrames.count() - lastUpdateNumFrames;
|
||||||
//of how many by tracking the number we last knew about as opposed to how many rows there
|
if (num <= 0) return 0;
|
||||||
//are now.
|
|
||||||
num = filteredFrames.count() - lastUpdateNumFrames;
|
|
||||||
|
|
||||||
if (num < 0) return;
|
if (num == 0 && !overwriteDups) return 0;
|
||||||
|
if (filteredFrames.count() == 0) return 0;
|
||||||
//qDebug() << "Num: " << num;
|
|
||||||
|
|
||||||
if (num == 0 && !overwriteDups) return;
|
|
||||||
if (filteredFrames.count() == 0) return;
|
|
||||||
|
|
||||||
lastUpdateNumFrames += num; //done this way to avoid asking for filteredFrames.count() again
|
lastUpdateNumFrames += num; //done this way to avoid asking for filteredFrames.count() again
|
||||||
|
|
||||||
qDebug() << "Bulk refresh of " << num;
|
qDebug() << "Bulk refresh of " << num;
|
||||||
|
|
||||||
if (!overwriteDups)
|
|
||||||
{
|
|
||||||
//if (num > filteredFrames.count()) num = filteredFrames.count();
|
|
||||||
//qDebug() << "From " << (filteredFrames.count() - num) << " to " << (filteredFrames.count() - 1);
|
|
||||||
//beginInsertRows(QModelIndex(), filteredFrames.count() - num, filteredFrames.count() - 1);
|
|
||||||
//endInsertRows();
|
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
|
||||||
else
|
return num;
|
||||||
{
|
|
||||||
beginResetModel();
|
|
||||||
endResetModel();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CANFrameModel::clearFrames()
|
void CANFrameModel::clearFrames()
|
||||||
|
|||||||
+4
-2
@@ -8,6 +8,7 @@
|
|||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include "can_structs.h"
|
#include "can_structs.h"
|
||||||
#include "dbchandler.h"
|
#include "dbchandler.h"
|
||||||
|
#include "connections/canconnection.h"
|
||||||
|
|
||||||
class CANFrameModel: public QAbstractTableModel
|
class CANFrameModel: public QAbstractTableModel
|
||||||
{
|
{
|
||||||
@@ -25,7 +26,7 @@ public:
|
|||||||
|
|
||||||
void sendRefresh();
|
void sendRefresh();
|
||||||
void sendRefresh(int);
|
void sendRefresh(int);
|
||||||
void sendBulkRefresh(int);
|
int sendBulkRefresh();
|
||||||
void clearFrames();
|
void clearFrames();
|
||||||
void setDBCHandler(DBCHandler *);
|
void setDBCHandler(DBCHandler *);
|
||||||
void setInterpetMode(bool);
|
void setInterpetMode(bool);
|
||||||
@@ -46,7 +47,8 @@ public:
|
|||||||
const QMap<int, bool> *getFiltersReference() const; //this neither
|
const QMap<int, bool> *getFiltersReference() const; //this neither
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void addFrame(CANFrame&, bool);
|
void addFrame(const CANFrame&, bool);
|
||||||
|
void addFrames(const CANConnection*, const QVector<CANFrame>&);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void updatedFiltersList();
|
void updatedFiltersList();
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
#include "canconmanager.h"
|
||||||
|
|
||||||
|
|
||||||
|
CANConManager* CANConManager::mInstance = NULL;
|
||||||
|
|
||||||
|
CANConManager* CANConManager::getInstance()
|
||||||
|
{
|
||||||
|
if(!mInstance)
|
||||||
|
mInstance = new CANConManager();
|
||||||
|
|
||||||
|
return mInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CANConManager::CANConManager(QObject *parent): QObject(parent)
|
||||||
|
{
|
||||||
|
connect(&mTimer, SIGNAL(timeout()), this, SLOT(refreshCanList()));
|
||||||
|
mTimer.setInterval(500); /*tick twice a second */
|
||||||
|
mTimer.setSingleShot(false);
|
||||||
|
mTimer.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CANConManager::~CANConManager()
|
||||||
|
{
|
||||||
|
mTimer.stop();
|
||||||
|
mInstance = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CANConManager::add(CANConnection* pConn_p)
|
||||||
|
{
|
||||||
|
connect(pConn_p, SIGNAL(notify()), this, SLOT(refreshCanList()));
|
||||||
|
mConns.append(pConn_p);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CANConManager::remove(CANConnection* pConn_p)
|
||||||
|
{
|
||||||
|
disconnect(pConn_p, 0, this, 0);
|
||||||
|
mConns.removeOne(pConn_p);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CANConManager::refreshCanList()
|
||||||
|
{
|
||||||
|
QObject* sender_p = QObject::sender();
|
||||||
|
|
||||||
|
if( sender_p != &mTimer)
|
||||||
|
{
|
||||||
|
/* if we are not the sender, the signal is coming from a connection */
|
||||||
|
/* refresh only the given connection */
|
||||||
|
if(mConns.contains((CANConnection*) sender_p))
|
||||||
|
refreshConnection((CANConnection*)sender_p);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (CANConnection* conn_p, mConns)
|
||||||
|
refreshConnection((CANConnection*)conn_p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QList<CANConnection*>& CANConManager::getConnections()
|
||||||
|
{
|
||||||
|
return mConns;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CANConnection* CANConManager::getByName(const QString& pName) const
|
||||||
|
{
|
||||||
|
foreach(CANConnection* conn_p, mConns)
|
||||||
|
{
|
||||||
|
if(conn_p->getPort() == pName)
|
||||||
|
return conn_p;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CANConManager::refreshConnection(CANConnection* pConn_p)
|
||||||
|
{
|
||||||
|
CANFrame* frame_p = NULL;
|
||||||
|
QVector<CANFrame> frames;
|
||||||
|
|
||||||
|
while( (frame_p = pConn_p->getQueue().peek() ) ) {
|
||||||
|
frames.append(*frame_p);
|
||||||
|
pConn_p->getQueue().dequeue();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(frames.size())
|
||||||
|
emit framesReceived(pConn_p, frames);
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
#ifndef CANCONMANAGER_H
|
||||||
|
#define CANCONMANAGER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
#include "canconnection.h"
|
||||||
|
|
||||||
|
class CANConManager : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
static CANConManager* getInstance();
|
||||||
|
virtual ~CANConManager();
|
||||||
|
|
||||||
|
void add(CANConnection* pConn_p);
|
||||||
|
void remove(CANConnection* pConn_p);
|
||||||
|
QList<CANConnection*>& getConnections();
|
||||||
|
|
||||||
|
CANConnection* getByName(const QString& pName) const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void framesReceived(CANConnection* pConn_p, QVector<CANFrame>& pFrames);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void refreshCanList();
|
||||||
|
|
||||||
|
private:
|
||||||
|
explicit CANConManager(QObject *parent = 0);
|
||||||
|
void refreshConnection(CANConnection* pConn_p);
|
||||||
|
|
||||||
|
static CANConManager* mInstance;
|
||||||
|
QList<CANConnection*> mConns;
|
||||||
|
QTimer mTimer;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CANCONNECTIONMODEL_H
|
||||||
|
|
||||||
@@ -191,7 +191,7 @@ bool CANConnection::sendFrames(const QList<CANFrame>& pFrames)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int CANConnection::getNumBuses() {
|
int CANConnection::getNumBuses() const{
|
||||||
return mNumBuses;
|
return mNumBuses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public:
|
|||||||
* @brief getNumBuses
|
* @brief getNumBuses
|
||||||
* @return returns the number of buses of the device
|
* @return returns the number of buses of the device
|
||||||
*/
|
*/
|
||||||
int getNumBuses();
|
int getNumBuses() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief getPort
|
* @brief getPort
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ void SocketCan::errorReceived(QCanBusDevice::CanBusError error) const
|
|||||||
|
|
||||||
void SocketCan::framesWritten(qint64 count)
|
void SocketCan::framesWritten(qint64 count)
|
||||||
{
|
{
|
||||||
qDebug() << "Number of frames written:" << count;
|
//qDebug() << "Number of frames written:" << count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SocketCan::framesReceived()
|
void SocketCan::framesReceived()
|
||||||
|
|||||||
+184
-237
@@ -4,29 +4,26 @@
|
|||||||
#include "connectionwindow.h"
|
#include "connectionwindow.h"
|
||||||
#include "ui_connectionwindow.h"
|
#include "ui_connectionwindow.h"
|
||||||
#include "connections/canconfactory.h"
|
#include "connections/canconfactory.h"
|
||||||
|
#include "connections/canconmanager.h"
|
||||||
#define FALSE 0
|
#include "canbus.h"
|
||||||
#define TRUE 1
|
|
||||||
|
|
||||||
|
|
||||||
ConnectionWindow::ConnectionWindow(CANFrameModel *cModel, QWidget *parent) :
|
|
||||||
|
ConnectionWindow::ConnectionWindow(QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::ConnectionWindow),
|
ui(new Ui::ConnectionWindow)
|
||||||
mRefreshReqOngoing(FALSE)
|
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
settings = new QSettings();
|
QSettings settings;
|
||||||
|
|
||||||
qRegisterMetaType<CANBus>("CANBus");
|
qRegisterMetaType<CANBus>("CANBus");
|
||||||
qRegisterMetaType<const CANFrame *>("const CANFrame *");
|
qRegisterMetaType<const CANFrame *>("const CANFrame *");
|
||||||
qRegisterMetaType<const QList<CANFrame> *>("const QList<CANFrame> *");
|
qRegisterMetaType<const QList<CANFrame> *>("const QList<CANFrame> *");
|
||||||
|
|
||||||
connModel = new CANConnectionModel();
|
|
||||||
|
connModel = new CANConnectionModel(this);
|
||||||
ui->tableConnections->setModel(connModel);
|
ui->tableConnections->setModel(connModel);
|
||||||
|
|
||||||
canModel = cModel;
|
|
||||||
|
|
||||||
ui->tableConnections->setColumnWidth(0, 50);
|
ui->tableConnections->setColumnWidth(0, 50);
|
||||||
ui->tableConnections->setColumnWidth(1, 110);
|
ui->tableConnections->setColumnWidth(1, 110);
|
||||||
ui->tableConnections->setColumnWidth(2, 110);
|
ui->tableConnections->setColumnWidth(2, 110);
|
||||||
@@ -35,14 +32,7 @@ ConnectionWindow::ConnectionWindow(CANFrameModel *cModel, QWidget *parent) :
|
|||||||
ui->tableConnections->setColumnWidth(5, 75);
|
ui->tableConnections->setColumnWidth(5, 75);
|
||||||
ui->tableConnections->setColumnWidth(6, 75);
|
ui->tableConnections->setColumnWidth(6, 75);
|
||||||
ui->tableConnections->setColumnWidth(7, 75);
|
ui->tableConnections->setColumnWidth(7, 75);
|
||||||
|
ui->ckSingleWire->setChecked(settings.value("Main/SingleWireMode", false).toBool());
|
||||||
int temp = settings->value("Main/DefaultConnectionType", 0).toInt();
|
|
||||||
|
|
||||||
//currentPortName = settings->value("Main/DefaultConnectionPort", "").toString();
|
|
||||||
|
|
||||||
//currentSpeed1 = -1;
|
|
||||||
|
|
||||||
ui->ckSingleWire->setChecked(settings->value("Main/SingleWireMode", false).toBool());
|
|
||||||
|
|
||||||
ui->cbSpeed->addItem(tr("<Default>"));
|
ui->cbSpeed->addItem(tr("<Default>"));
|
||||||
ui->cbSpeed->addItem(tr("125000"));
|
ui->cbSpeed->addItem(tr("125000"));
|
||||||
@@ -51,114 +41,90 @@ ConnectionWindow::ConnectionWindow(CANFrameModel *cModel, QWidget *parent) :
|
|||||||
ui->cbSpeed->addItem(tr("1000000"));
|
ui->cbSpeed->addItem(tr("1000000"));
|
||||||
ui->cbSpeed->addItem(tr("33333"));
|
ui->cbSpeed->addItem(tr("33333"));
|
||||||
|
|
||||||
#ifdef Q_OS_LINUX
|
/* load connection configuration */
|
||||||
ui->rbSocketCAN->setEnabled(isSocketCanAvailable());
|
loadConnections();
|
||||||
#endif
|
|
||||||
|
|
||||||
|
ui->rbSocketCAN->setEnabled(isSocketCanAvailable());
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
ui->rbKvaser->setEnabled(true);
|
ui->rbKvaser->setEnabled(true);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
connect(ui->btnOK, &QAbstractButton::clicked, this, &ConnectionWindow::handleOKButton);
|
connect(ui->btnOK, &QAbstractButton::clicked, this, &ConnectionWindow::handleOKButton);
|
||||||
connect(ui->rbGVRET, &QAbstractButton::toggled, this, &ConnectionWindow::handleConnTypeChanged);
|
connect(ui->rbGVRET, &QAbstractButton::clicked, this, &ConnectionWindow::handleConnTypeChanged);
|
||||||
connect(ui->rbKvaser, &QAbstractButton::toggled, this, &ConnectionWindow::handleConnTypeChanged);
|
connect(ui->rbKvaser, &QAbstractButton::clicked, this, &ConnectionWindow::handleConnTypeChanged);
|
||||||
connect(ui->rbSocketCAN, &QAbstractButton::toggled, this, &ConnectionWindow::handleConnTypeChanged);
|
connect(ui->rbSocketCAN, &QAbstractButton::clicked, this, &ConnectionWindow::handleConnTypeChanged);
|
||||||
connect(ui->btnRevert, &QPushButton::clicked, this, &ConnectionWindow::handleRevert);
|
connect(ui->btnRevert, &QPushButton::clicked, this, &ConnectionWindow::handleRevert);
|
||||||
connect(ui->tableConnections->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ConnectionWindow::handleConnSelectionChanged);
|
connect(ui->tableConnections->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &ConnectionWindow::currentRowChanged);
|
||||||
connect(connModel, &QAbstractItemModel::modelReset, this, &ConnectionWindow::handleConnSelectionChanged);
|
|
||||||
connect(ui->btnNewConn, &QPushButton::clicked, this, &ConnectionWindow::handleNewConn);
|
connect(ui->btnNewConn, &QPushButton::clicked, this, &ConnectionWindow::handleNewConn);
|
||||||
connect(ui->btnActivateAll, &QPushButton::clicked, this, &ConnectionWindow::handleEnableAll);
|
connect(ui->btnActivateAll, &QPushButton::clicked, this, &ConnectionWindow::handleEnableAll);
|
||||||
connect(ui->btnDeactivateAll, &QPushButton::clicked, this, &ConnectionWindow::handleDisableAll);
|
connect(ui->btnDeactivateAll, &QPushButton::clicked, this, &ConnectionWindow::handleDisableAll);
|
||||||
connect(ui->btnRemoveBus, &QPushButton::clicked, this, &ConnectionWindow::handleRemoveConn);
|
connect(ui->btnRemoveBus, &QPushButton::clicked, this, &ConnectionWindow::handleRemoveConn);
|
||||||
|
|
||||||
|
|
||||||
qDebug() << "Serial worker thread starting";
|
|
||||||
|
|
||||||
connect(&mTicker, SIGNAL(timeout()), this, SLOT(refreshCanList()));
|
|
||||||
/* tick frequency has a huge impact on performances */
|
|
||||||
/* TODO: make this configurable and part of the connection constructor to let connection configure the length of the queue */
|
|
||||||
mTicker.setInterval(500); /*tick twice a second */
|
|
||||||
mTicker.setSingleShot(false);
|
|
||||||
mTicker.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionWindow::~ConnectionWindow()
|
ConnectionWindow::~ConnectionWindow()
|
||||||
{
|
{
|
||||||
QList<CANConnection*>& conns = connModel->getConnections();
|
QList<CANConnection*>& conns = CANConManager::getInstance()->getConnections();
|
||||||
CANConnection* conn_p;
|
CANConnection* conn_p;
|
||||||
|
|
||||||
|
/* save configuration */
|
||||||
|
saveConnections();
|
||||||
|
|
||||||
/* delete connections */
|
/* delete connections */
|
||||||
while(!conns.isEmpty()) {
|
while(!conns.isEmpty())
|
||||||
|
{
|
||||||
conn_p = conns.takeFirst();
|
conn_p = conns.takeFirst();
|
||||||
conn_p->stop();
|
conn_p->stop();
|
||||||
delete conn_p;
|
delete conn_p;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete connModel;
|
|
||||||
|
|
||||||
mTicker.stop();
|
|
||||||
delete settings;
|
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ConnectionWindow::showEvent(QShowEvent* event)
|
void ConnectionWindow::showEvent(QShowEvent* event)
|
||||||
{
|
{
|
||||||
QDialog::showEvent(event);
|
QDialog::showEvent(event);
|
||||||
qDebug() << "Show connectionwindow";
|
qDebug() << "Show connectionwindow";
|
||||||
handleConnTypeChanged();
|
ui->tableConnections->selectRow(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionWindow::refreshCanList() {
|
|
||||||
|
|
||||||
QList<CANConnection*>& conns = connModel->getConnections();
|
|
||||||
CANFrame* frame_p = NULL;
|
|
||||||
|
|
||||||
foreach (CANConnection* conn_p, conns)
|
|
||||||
{
|
|
||||||
while( (frame_p = conn_p->getQueue().peek() ) ) {
|
|
||||||
canModel->addFrame(*frame_p, true);
|
|
||||||
conn_p->getQueue().dequeue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* erase flag (this should be done before we start dequeuing...) */
|
|
||||||
mRefreshReqOngoing.store(FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConnectionWindow::handleNewConn()
|
|
||||||
{
|
|
||||||
ui->tableConnections->selectionModel()->clearSelection();
|
|
||||||
ui->tableConnections->selectionModel()->clearCurrentIndex();
|
|
||||||
handleConnSelectionChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConnectionWindow::setSuspendAll(bool pSuspend)
|
void ConnectionWindow::setSuspendAll(bool pSuspend)
|
||||||
{
|
{
|
||||||
qDebug() << "setSuspendAll";
|
QList<CANConnection*>& conns = CANConManager::getInstance()->getConnections();
|
||||||
|
|
||||||
QList<CANConnection*>::iterator iter;
|
foreach(CANConnection* conn_p, conns)
|
||||||
QList<CANConnection*>& conns = connModel->getConnections();
|
conn_p->suspend(pSuspend);
|
||||||
|
|
||||||
for (iter = conns.begin(); iter != conns.end(); ++iter)
|
connModel->refresh();
|
||||||
(*iter)->suspend(pSuspend);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ConnectionWindow::setActiveAll(bool pActive)
|
void ConnectionWindow::setActiveAll(bool pActive)
|
||||||
{
|
{
|
||||||
QList<CANConnection*>::iterator iter;
|
|
||||||
QList<CANConnection*>& conns = connModel->getConnections();
|
|
||||||
CANBus bus;
|
CANBus bus;
|
||||||
|
QList<CANConnection*>& conns = CANConManager::getInstance()->getConnections();
|
||||||
|
|
||||||
for (iter = conns.begin(); iter != conns.end(); ++iter) {
|
foreach(CANConnection* conn_p, conns)
|
||||||
for(int i=0 ; i<(*iter)->getNumBuses() ; i++) {
|
{
|
||||||
if( (*iter)->getBusSettings(i, bus) ) {
|
for(int i=0 ; i<conn_p->getNumBuses() ; i++) {
|
||||||
|
if( conn_p->getBusSettings(i, bus) ) {
|
||||||
bus.active = pActive;
|
bus.active = pActive;
|
||||||
(*iter)->setBusSettings(i, bus);
|
conn_p->setBusSettings(i, bus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connModel->refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ConnectionWindow::handleNewConn()
|
||||||
|
{
|
||||||
|
ui->tableConnections->setCurrentIndex(QModelIndex());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ConnectionWindow::handleEnableAll()
|
void ConnectionWindow::handleEnableAll()
|
||||||
{
|
{
|
||||||
setActiveAll(true);
|
setActiveAll(true);
|
||||||
@@ -180,8 +146,10 @@ void ConnectionWindow::handleConnTypeChanged()
|
|||||||
/* status */
|
/* status */
|
||||||
void ConnectionWindow::connectionStatus(CANCon::status pStatus)
|
void ConnectionWindow::connectionStatus(CANCon::status pStatus)
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(pStatus);
|
||||||
|
|
||||||
qDebug() << "Connectionstatus changed";
|
qDebug() << "Connectionstatus changed";
|
||||||
connModel->refreshView();
|
connModel->refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -193,6 +161,7 @@ void ConnectionWindow::handleOKButton()
|
|||||||
|
|
||||||
if (whichRow > -1)
|
if (whichRow > -1)
|
||||||
{
|
{
|
||||||
|
/* set information for selected connection */
|
||||||
int busId;
|
int busId;
|
||||||
CANBus bus;
|
CANBus bus;
|
||||||
bool ret;
|
bool ret;
|
||||||
@@ -219,78 +188,15 @@ void ConnectionWindow::handleOKButton()
|
|||||||
/* update bus settings */
|
/* update bus settings */
|
||||||
conn_p->setBusSettings(busId, bus);
|
conn_p->setBusSettings(busId, bus);
|
||||||
|
|
||||||
connModel->refreshView();
|
connModel->refresh(whichRow);
|
||||||
}
|
}
|
||||||
else //new connection
|
else if( ! CANConManager::getInstance()->getByName(getPortName()) )
|
||||||
{
|
{
|
||||||
#if 0
|
|
||||||
if (ui->rbGVRET->isChecked())
|
|
||||||
{
|
|
||||||
|
|
||||||
SerialWorker *serial = new SerialWorker(canModel, connModel->rowCount());
|
|
||||||
connect(serial, SIGNAL(busStatus(int,int,int)), this, SLOT(receiveBusStatus(int,int,int)));
|
|
||||||
connect(serial, SIGNAL(connectionSuccess(CANConnection*)), this, SLOT(connectionSuccess(CANConnection*)));
|
|
||||||
CANConnectionContainer* container = new CANConnectionContainer(serial);
|
|
||||||
|
|
||||||
|
|
||||||
qDebug() << "Setup initial connection object";
|
|
||||||
|
|
||||||
CANBus bus;
|
|
||||||
bus.active = ui->ckEnabled->isChecked();
|
|
||||||
bus.busNum = serial->getBusBase();
|
|
||||||
bus.container = container;
|
|
||||||
bus.listenOnly = ui->ckListenOnly->isChecked();
|
|
||||||
bus.singleWire = ui->ckSingleWire->isChecked();
|
|
||||||
|
|
||||||
if (ui->cbSpeed->currentIndex() < 1) bus.speed = 0; //default speed
|
|
||||||
else if (ui->cbSpeed->currentIndex() == 1)
|
|
||||||
{
|
|
||||||
bus.speed = 0;
|
|
||||||
bus.active = false;
|
|
||||||
}
|
|
||||||
else bus.speed = ui->cbSpeed->currentText().toInt();
|
|
||||||
|
|
||||||
connModel->addBus(bus);
|
|
||||||
|
|
||||||
int numBuses = serial->getNumBuses();
|
|
||||||
for (int i = 1; i < numBuses; i++)
|
|
||||||
{
|
|
||||||
bus.active = false;
|
|
||||||
bus.listenOnly = false;
|
|
||||||
bus.singleWire = false;
|
|
||||||
bus.speed = 250000;
|
|
||||||
bus.busNum = serial->getBusBase() + i;
|
|
||||||
bus.container = container;
|
|
||||||
connModel->addBus(bus);
|
|
||||||
qDebug() << "Added bus " << bus.busNum;
|
|
||||||
}
|
|
||||||
|
|
||||||
//call through signal/slot interface without using connect
|
|
||||||
QMetaObject::invokeMethod(serial, "updatePortName",
|
|
||||||
Qt::QueuedConnection,
|
|
||||||
Q_ARG(QString, ui->cbPort->currentText()));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* create connection */
|
/* create connection */
|
||||||
conn_p = CanConFactory::create(getConnectionType(), getPortName());
|
conn_p = create(getConnectionType(), getPortName());
|
||||||
if(!conn_p)
|
if(!conn_p)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* connect signal */
|
|
||||||
connect(conn_p, SIGNAL(status(CANCon::status)),
|
|
||||||
this, SLOT(connectionStatus(CANCon::status)));
|
|
||||||
|
|
||||||
//conn_p->setCallback(std::bind(&ConnectionWindow::callback, this, std::placeholders::_1));
|
|
||||||
|
|
||||||
/*TODO add return value and checks */
|
|
||||||
conn_p->start();
|
|
||||||
/*{
|
|
||||||
QVector<CANFlt> flters;
|
|
||||||
flters.append({0x305, 0xFFFF, true});
|
|
||||||
conn_p->setFilters(0, flters, false);
|
|
||||||
connect(conn_p, SIGNAL(notify()), this, SLOT(refreshCanList()));
|
|
||||||
}*/
|
|
||||||
|
|
||||||
for (int i=0 ; i<conn_p->getNumBuses() ; i++) {
|
for (int i=0 ; i<conn_p->getNumBuses() ; i++) {
|
||||||
/* set bus configuration */
|
/* set bus configuration */
|
||||||
CANBus bus;
|
CANBus bus;
|
||||||
@@ -311,45 +217,28 @@ void ConnectionWindow::handleOKButton()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ConnectionWindow::receiveBusStatus(int bus, int speed, int status)
|
|
||||||
{
|
|
||||||
#if 0
|
|
||||||
qDebug() << "bus " << bus << " speed " << speed << " status " << status;
|
|
||||||
CANBus *busRef = connModel->getBus(bus);
|
|
||||||
if (status & 40) busRef->setSpeed(speed);
|
|
||||||
if (status & 8) //update enabled status
|
|
||||||
{
|
|
||||||
busRef->setEnabled((status & 1)?true:false);
|
|
||||||
}
|
|
||||||
if (status & 0x10) //update single wire status
|
|
||||||
{
|
|
||||||
busRef->setSingleWire((status & 2)?true:false);
|
|
||||||
}
|
|
||||||
if (status & 0x20) //update listen only status
|
|
||||||
{
|
|
||||||
busRef->setListenOnly((status & 4)?true:false);
|
|
||||||
}
|
|
||||||
connModel->refreshView();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConnectionWindow::handleConnSelectionChanged()
|
void ConnectionWindow::currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
||||||
{
|
{
|
||||||
int selIdx = ui->tableConnections->selectionModel()->currentIndex().row();
|
Q_UNUSED(previous);
|
||||||
|
|
||||||
|
int selIdx = current.row();
|
||||||
|
|
||||||
|
/* enable / diable connection type */
|
||||||
|
ui->stPort->setEnabled(selIdx==-1);
|
||||||
|
ui->gbType->setEnabled(selIdx==-1);
|
||||||
|
ui->lPort->setEnabled(selIdx==-1);
|
||||||
|
|
||||||
|
/* set parameters */
|
||||||
if (selIdx == -1)
|
if (selIdx == -1)
|
||||||
{
|
{
|
||||||
ui->btnOK->setText(tr("Create New Connection"));
|
ui->btnOK->setText(tr("Create New Connection"));
|
||||||
|
ui->rbGVRET->setChecked(true);
|
||||||
ui->cbPort->setEnabled(true);
|
|
||||||
ui->rbGVRET->setEnabled(true);
|
|
||||||
ui->rbKvaser->setEnabled(true);
|
|
||||||
ui->rbSocketCAN->setEnabled(true);
|
|
||||||
ui->cbSpeed->setEnabled(false);
|
|
||||||
|
|
||||||
ui->cbPort->setCurrentIndex(0);
|
|
||||||
ui->ckListenOnly->setChecked(false);
|
ui->ckListenOnly->setChecked(false);
|
||||||
ui->ckSingleWire->setChecked(false);
|
ui->ckSingleWire->setChecked(false);
|
||||||
ui->ckEnabled->setChecked(true);
|
ui->ckEnabled->setChecked(false);
|
||||||
|
setSpeed(0);
|
||||||
|
setPortName(CANCon::GVRET_SERIAL, "");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -362,25 +251,11 @@ void ConnectionWindow::handleConnSelectionChanged()
|
|||||||
if(!ret) return;
|
if(!ret) return;
|
||||||
|
|
||||||
ui->btnOK->setText(tr("Update Connection Settings"));
|
ui->btnOK->setText(tr("Update Connection Settings"));
|
||||||
|
|
||||||
ui->cbPort->setEnabled(false);
|
|
||||||
ui->rbGVRET->setEnabled(false);
|
|
||||||
ui->rbKvaser->setEnabled(false);
|
|
||||||
ui->rbSocketCAN->setEnabled(false);
|
|
||||||
ui->cbSpeed->setEnabled(true);
|
|
||||||
|
|
||||||
switch(conn_p->getType()) {
|
|
||||||
case CANCon::GVRET_SERIAL: ui->rbGVRET->setChecked(true); break;
|
|
||||||
case CANCon::KVASER: ui->rbKvaser->setChecked(true); break;
|
|
||||||
case CANCon::SOCKETCAN: ui->rbSocketCAN->setChecked(true); break;
|
|
||||||
default: {}
|
|
||||||
}
|
|
||||||
|
|
||||||
ui->ckListenOnly->setChecked(bus.isListenOnly());
|
ui->ckListenOnly->setChecked(bus.isListenOnly());
|
||||||
ui->ckSingleWire->setChecked(bus.isSingleWire());
|
ui->ckSingleWire->setChecked(bus.isSingleWire());
|
||||||
ui->ckEnabled->setChecked(bus.isActive());
|
ui->ckEnabled->setChecked(bus.isActive());
|
||||||
int speed = bus.getSpeed();
|
setSpeed(bus.getSpeed());
|
||||||
setSpeed(speed);
|
setPortName(conn_p->getType(), conn_p->getPort());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -394,48 +269,69 @@ void ConnectionWindow::selectSerial()
|
|||||||
ports = QSerialPortInfo::availablePorts();
|
ports = QSerialPortInfo::availablePorts();
|
||||||
|
|
||||||
for (int i = 0; i < ports.count(); i++)
|
for (int i = 0; i < ports.count(); i++)
|
||||||
{
|
|
||||||
ui->cbPort->addItem(ports[i].portName());
|
ui->cbPort->addItem(ports[i].portName());
|
||||||
//if (currentPortName == ports[i].portName()) ui->cbPort->setCurrentIndex(i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionWindow::selectKvaser()
|
void ConnectionWindow::selectKvaser()
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN
|
|
||||||
/* set combobox page visible */
|
/* set combobox page visible */
|
||||||
ui->stPort->setCurrentWidget(ui->cbPage);
|
ui->stPort->setCurrentWidget(ui->cbPage);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionWindow::selectSocketCan()
|
void ConnectionWindow::selectSocketCan()
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_LINUX
|
|
||||||
/* set edit text page visible */
|
/* set edit text page visible */
|
||||||
ui->stPort->setCurrentWidget(ui->etPage);
|
ui->stPort->setCurrentWidget(ui->etPage);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionWindow::setSpeed(int speed0)
|
void ConnectionWindow::setSpeed(int speed0)
|
||||||
{
|
{
|
||||||
bool found = false;
|
|
||||||
|
|
||||||
qDebug() << "Set Speed " << speed0;
|
|
||||||
|
|
||||||
for (int i = 0; i < ui->cbSpeed->count(); i++)
|
for (int i = 0; i < ui->cbSpeed->count(); i++)
|
||||||
{
|
{
|
||||||
if (ui->cbSpeed->itemText(i).toInt() == speed0)
|
if (ui->cbSpeed->itemText(i).toInt() == speed0)
|
||||||
{
|
{
|
||||||
ui->cbSpeed->setCurrentIndex(i);
|
ui->cbSpeed->setCurrentIndex(i);
|
||||||
found = true;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found)
|
|
||||||
{
|
/* add custom speed */
|
||||||
ui->cbSpeed->addItem(QString::number(speed0));
|
ui->cbSpeed->addItem(QString::number(speed0));
|
||||||
ui->cbSpeed->setCurrentIndex(ui->cbSpeed->count() - 1);
|
ui->cbSpeed->setCurrentIndex(ui->cbSpeed->count() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConnectionWindow::setPortName(CANCon::type pType, QString pPortName)
|
||||||
|
{
|
||||||
|
switch(pType)
|
||||||
|
{
|
||||||
|
case CANCon::GVRET_SERIAL:
|
||||||
|
ui->rbGVRET->setChecked(true); break;
|
||||||
|
case CANCon::KVASER:
|
||||||
|
ui->rbKvaser->setChecked(true); break;
|
||||||
|
case CANCon::SOCKETCAN:
|
||||||
|
ui->rbSocketCAN->setChecked(true); break;
|
||||||
|
default: {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* refresh names whenever needed */
|
||||||
|
handleConnTypeChanged();
|
||||||
|
|
||||||
|
switch(pType)
|
||||||
|
{
|
||||||
|
case CANCon::GVRET_SERIAL:
|
||||||
|
{
|
||||||
|
int idx = ui->cbPort->findText(pPortName);
|
||||||
|
if( idx<0 ) idx=0;
|
||||||
|
ui->cbPort->setCurrentIndex(idx);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CANCon::SOCKETCAN:
|
||||||
|
{
|
||||||
|
ui->lePort->setText(pPortName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -445,17 +341,12 @@ int ConnectionWindow::getSpeed()
|
|||||||
switch (ui->cbSpeed->currentIndex())
|
switch (ui->cbSpeed->currentIndex())
|
||||||
{
|
{
|
||||||
case -1:
|
case -1:
|
||||||
return -1;
|
|
||||||
break;
|
|
||||||
case 0:
|
case 0:
|
||||||
return -1;
|
return -1;
|
||||||
break;
|
|
||||||
case 1:
|
case 1:
|
||||||
return 0;
|
return 0;
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return (ui->cbSpeed->currentText().toInt());
|
return (ui->cbSpeed->currentText().toInt());
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -507,12 +398,15 @@ void ConnectionWindow::handleRemoveConn()
|
|||||||
CANConnection* conn_p = connModel->getAtIdx(selIdx, busId);
|
CANConnection* conn_p = connModel->getAtIdx(selIdx, busId);
|
||||||
if(!conn_p) return;
|
if(!conn_p) return;
|
||||||
|
|
||||||
/* remove connection from model */
|
/* remove connection from model & manager */
|
||||||
connModel->remove(conn_p);
|
connModel->remove(conn_p);
|
||||||
|
|
||||||
/* stop and delete connection */
|
/* stop and delete connection */
|
||||||
conn_p->stop();
|
conn_p->stop();
|
||||||
delete conn_p;
|
delete conn_p;
|
||||||
|
|
||||||
|
/* select first connection in list */
|
||||||
|
ui->tableConnections->selectRow(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionWindow::handleRevert()
|
void ConnectionWindow::handleRevert()
|
||||||
@@ -520,37 +414,90 @@ void ConnectionWindow::handleRevert()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionWindow::sendFrame(const CANFrame *frame)
|
|
||||||
{
|
|
||||||
#if 0
|
|
||||||
CANBus *bus = connModel->getBus(frame->bus);
|
|
||||||
if (bus == NULL) return;
|
|
||||||
QMetaObject::invokeMethod(bus->getContainer()->getRef(), "sendFrame",
|
|
||||||
Qt::QueuedConnection,
|
|
||||||
Q_ARG(const CANFrame *, frame));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConnectionWindow::sendFrameBatch(const QList<CANFrame> *frames)
|
|
||||||
{
|
|
||||||
#if 0
|
|
||||||
if (frames->count() == 0) return;
|
|
||||||
CANBus *bus = connModel->getBus(frames->at(0).bus);
|
|
||||||
if (bus == NULL) return;
|
|
||||||
QMetaObject::invokeMethod(bus->getContainer()->getRef(), "sendFrameBatch",
|
|
||||||
Qt::QueuedConnection,
|
|
||||||
Q_ARG(const QList<CANFrame> *, frames));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ConnectionWindow::isSocketCanAvailable()
|
bool ConnectionWindow::isSocketCanAvailable()
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_LINUX
|
#ifdef Q_OS_LINUX
|
||||||
foreach (const QByteArray &backend, QCanBus::instance()->plugins()) {
|
foreach (const QByteArray &backend, QCanBus::instance()->plugins()) {
|
||||||
if (backend == "socketcan") {
|
if (backend == "socketcan")
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CANConnection* ConnectionWindow::create(CANCon::type pTye, QString pPortName)
|
||||||
|
{
|
||||||
|
CANConnection* conn_p;
|
||||||
|
|
||||||
|
/* create connection */
|
||||||
|
conn_p = CanConFactory::create(pTye, pPortName);
|
||||||
|
if(conn_p)
|
||||||
|
{
|
||||||
|
/* connect signal */
|
||||||
|
connect(conn_p, SIGNAL(status(CANCon::status)),
|
||||||
|
this, SLOT(connectionStatus(CANCon::status)));
|
||||||
|
|
||||||
|
/*TODO add return value and checks */
|
||||||
|
conn_p->start();
|
||||||
|
}
|
||||||
|
return conn_p;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ConnectionWindow::loadConnections()
|
||||||
|
{
|
||||||
|
qRegisterMetaTypeStreamOperators<QVector<QString>>();
|
||||||
|
qRegisterMetaTypeStreamOperators<QVector<int>>();
|
||||||
|
qRegisterMetaTypeStreamOperators<CANBus>();
|
||||||
|
qRegisterMetaTypeStreamOperators<QList<CANBus>>();
|
||||||
|
|
||||||
|
QSettings settings;
|
||||||
|
|
||||||
|
/* fill connection list */
|
||||||
|
QVector<QString> portNames = settings.value("connections/portNames").value<QVector<QString>>();
|
||||||
|
QVector<int> devTypes = settings.value("connections/types").value<QVector<int>>();
|
||||||
|
QList<CANBus> busses = settings.value("connections/busses").value<QList<CANBus>>();
|
||||||
|
|
||||||
|
|
||||||
|
for(int i=0 ; i<portNames.count() ; i++)
|
||||||
|
{
|
||||||
|
CANConnection* conn_p = create((CANCon::type)devTypes[i], portNames[i]);
|
||||||
|
if(conn_p)
|
||||||
|
{
|
||||||
|
for(int j=0 ; j<conn_p->getNumBuses() ; j++)
|
||||||
|
conn_p->setBusSettings(j, busses.takeFirst());
|
||||||
|
}
|
||||||
|
/* add connection to model */
|
||||||
|
connModel->add(conn_p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConnectionWindow::saveConnections()
|
||||||
|
{
|
||||||
|
QList<CANConnection*>& conns = CANConManager::getInstance()->getConnections();
|
||||||
|
|
||||||
|
QSettings settings;
|
||||||
|
QVector<QString> portNames;
|
||||||
|
QVector<int> devTypes;
|
||||||
|
QList<CANBus> busses;
|
||||||
|
|
||||||
|
/* save connections */
|
||||||
|
foreach(CANConnection* conn_p, conns)
|
||||||
|
{
|
||||||
|
portNames.append(conn_p->getPort());
|
||||||
|
devTypes.append(conn_p->getType());
|
||||||
|
|
||||||
|
for(int i=0 ; i<conn_p->getNumBuses() ; i++)
|
||||||
|
{
|
||||||
|
CANBus bus;
|
||||||
|
conn_p->getBusSettings(i, bus);
|
||||||
|
busses.append(bus);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
settings.setValue("connections/portNames", QVariant::fromValue(portNames));
|
||||||
|
settings.setValue("connections/types", QVariant::fromValue(devTypes));
|
||||||
|
settings.setValue("connections/busses", QVariant::fromValue(busses));
|
||||||
|
}
|
||||||
|
|||||||
+13
-15
@@ -8,8 +8,9 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QItemSelection>
|
||||||
#include "canconnectionmodel.h"
|
#include "canconnectionmodel.h"
|
||||||
#include "canframemodel.h"
|
#include "connections/canconnection.h"
|
||||||
|
|
||||||
|
|
||||||
class CANConnectionModel;
|
class CANConnectionModel;
|
||||||
@@ -24,11 +25,10 @@ class ConnectionWindow : public QDialog
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ConnectionWindow(CANFrameModel *canModel, QWidget *parent = 0);
|
explicit ConnectionWindow(QWidget *parent = 0);
|
||||||
~ConnectionWindow();
|
~ConnectionWindow();
|
||||||
void showEvent(QShowEvent *);
|
void showEvent(QShowEvent *);
|
||||||
int getSpeed();
|
|
||||||
QString getPortName(); //name of port to connect to
|
|
||||||
CANCon::type getConnectionType();
|
CANCon::type getConnectionType();
|
||||||
bool getSWMode();
|
bool getSWMode();
|
||||||
|
|
||||||
@@ -39,40 +39,38 @@ signals:
|
|||||||
public slots:
|
public slots:
|
||||||
void setSpeed(int speed0);
|
void setSpeed(int speed0);
|
||||||
void setSWMode(bool mode);
|
void setSWMode(bool mode);
|
||||||
void sendFrame(const CANFrame *);
|
|
||||||
void sendFrameBatch(const QList<CANFrame> *);
|
|
||||||
void setSuspendAll(bool);
|
|
||||||
|
|
||||||
|
void setSuspendAll(bool pSuspend);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void handleOKButton();
|
void handleOKButton();
|
||||||
void handleConnTypeChanged();
|
void handleConnTypeChanged();
|
||||||
void handleConnSelectionChanged();
|
void currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||||
void handleRemoveConn();
|
void handleRemoveConn();
|
||||||
void handleEnableAll();
|
void handleEnableAll();
|
||||||
void handleDisableAll();
|
void handleDisableAll();
|
||||||
void handleRevert();
|
void handleRevert();
|
||||||
void handleNewConn();
|
void handleNewConn();
|
||||||
void receiveBusStatus(int bus, int speed, int status);
|
|
||||||
void connectionStatus(CANCon::status);
|
void connectionStatus(CANCon::status);
|
||||||
|
|
||||||
void refreshCanList();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ConnectionWindow *ui;
|
Ui::ConnectionWindow *ui;
|
||||||
QList<QSerialPortInfo> ports;
|
QList<QSerialPortInfo> ports;
|
||||||
QSettings *settings;
|
QSettings *settings;
|
||||||
CANConnectionModel *connModel;
|
CANConnectionModel *connModel;
|
||||||
CANFrameModel *canModel;
|
|
||||||
QTimer mTicker;
|
|
||||||
|
|
||||||
QAtomicInt mRefreshReqOngoing;
|
|
||||||
|
|
||||||
void selectSerial();
|
void selectSerial();
|
||||||
void selectKvaser();
|
void selectKvaser();
|
||||||
void selectSocketCan();
|
void selectSocketCan();
|
||||||
bool isSocketCanAvailable();
|
bool isSocketCanAvailable();
|
||||||
|
int getSpeed();
|
||||||
|
QString getPortName();
|
||||||
|
void setPortName(CANCon::type pType, QString pPortName);
|
||||||
|
|
||||||
void setActiveAll(bool pActive);
|
void setActiveAll(bool pActive);
|
||||||
|
CANConnection* create(CANCon::type pTye, QString pPortName);
|
||||||
|
void loadConnections();
|
||||||
|
void saveConnections();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONNECTIONWINDOW_H
|
#endif // CONNECTIONWINDOW_H
|
||||||
|
|||||||
+2
-2
@@ -74,7 +74,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="groupBox">
|
<widget class="QGroupBox" name="gbType">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Connection Type</string>
|
<string>Connection Type</string>
|
||||||
</property>
|
</property>
|
||||||
@@ -116,7 +116,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="lPort">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
|
|||||||
+15
-36
@@ -4,7 +4,7 @@
|
|||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QtSerialPort/QSerialPortInfo>
|
#include <QtSerialPort/QSerialPortInfo>
|
||||||
#include "canframemodel.h"
|
#include "connections/canconmanager.h"
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
#include "serialworker.h"
|
#include "serialworker.h"
|
||||||
|
|
||||||
@@ -62,28 +62,6 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
ui->canFramesView->setColumnWidth(6, 275);
|
ui->canFramesView->setColumnWidth(6, 275);
|
||||||
QHeaderView *HorzHdr = ui->canFramesView->horizontalHeader();
|
QHeaderView *HorzHdr = ui->canFramesView->horizontalHeader();
|
||||||
HorzHdr->setStretchLastSection(true); //causes the data column to automatically fill the tableview
|
HorzHdr->setStretchLastSection(true); //causes the data column to automatically fill the tableview
|
||||||
//enabling the below line kills performance in every way imaginable. Left here as a warning. Do not do this.
|
|
||||||
//ui->canFramesView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
|
||||||
|
|
||||||
/*
|
|
||||||
worker = new SerialWorker(model);
|
|
||||||
worker->moveToThread(&serialWorkerThread);
|
|
||||||
connect(&serialWorkerThread, &QThread::finished, worker, &QObject::deleteLater);
|
|
||||||
connect(&serialWorkerThread, &QThread::started, worker, &SerialWorker::run); //setup timers within the proper thread
|
|
||||||
connect(this, &MainWindow::sendSerialPort, worker, &SerialWorker::setSerialPort, Qt::QueuedConnection);
|
|
||||||
connect(worker, &SerialWorker::frameUpdateRapid, this, &MainWindow::gotFrames, Qt::QueuedConnection);
|
|
||||||
connect(this, &MainWindow::updateBaudRates, worker, &SerialWorker::updateBaudRates, Qt::QueuedConnection);
|
|
||||||
connect(this, &MainWindow::sendCANFrame, worker, &SerialWorker::sendFrame, Qt::QueuedConnection);
|
|
||||||
connect(worker, &SerialWorker::connectionSuccess, this, &MainWindow::connectionSucceeded, Qt::QueuedConnection);
|
|
||||||
connect(worker, &SerialWorker::connectionFailure, this, &MainWindow::connectionFailed, Qt::QueuedConnection);
|
|
||||||
connect(worker, &SerialWorker::deviceInfo, this, &MainWindow::gotDeviceInfo, Qt::QueuedConnection);
|
|
||||||
connect(this, &MainWindow::closeSerialPort, worker, &SerialWorker::closeSerialPort, Qt::QueuedConnection);
|
|
||||||
connect(this, &MainWindow::startFrameCapturing, worker, &SerialWorker::startFrameCapture);
|
|
||||||
connect(this, &MainWindow::stopFrameCapturing, worker, &SerialWorker::stopFrameCapture);
|
|
||||||
connect(this, &MainWindow::settingsUpdated, worker, &SerialWorker::readSettings);
|
|
||||||
serialWorkerThread.start();
|
|
||||||
serialWorkerThread.setPriority(QThread::HighPriority);
|
|
||||||
*/
|
|
||||||
|
|
||||||
graphingWindow = NULL;
|
graphingWindow = NULL;
|
||||||
frameInfoWindow = NULL;
|
frameInfoWindow = NULL;
|
||||||
@@ -146,6 +124,8 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
connect(ui->actionUDS_Scanner, &QAction::triggered, this, &MainWindow::showUDSScanWindow);
|
connect(ui->actionUDS_Scanner, &QAction::triggered, this, &MainWindow::showUDSScanWindow);
|
||||||
connect(ui->actionISO_TP_Decoder, &QAction::triggered, this, &MainWindow::showISOInterpreterWindow);
|
connect(ui->actionISO_TP_Decoder, &QAction::triggered, this, &MainWindow::showISOInterpreterWindow);
|
||||||
|
|
||||||
|
connect(CANConManager::getInstance(), &CANConManager::framesReceived, model, &CANFrameModel::addFrames);
|
||||||
|
|
||||||
lbStatusConnected.setText(tr("Not connected"));
|
lbStatusConnected.setText(tr("Not connected"));
|
||||||
updateFileStatus();
|
updateFileStatus();
|
||||||
lbStatusDatabase.setText(tr("No DBC database loaded"));
|
lbStatusDatabase.setText(tr("No DBC database loaded"));
|
||||||
@@ -179,8 +159,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
model->clearFrames();
|
model->clearFrames();
|
||||||
|
|
||||||
//Automatically create the connection window so it can be updated even if we never opened it.
|
//Automatically create the connection window so it can be updated even if we never opened it.
|
||||||
connectionWindow = new ConnectionWindow(model);
|
connectionWindow = new ConnectionWindow();
|
||||||
connect(connectionWindow, SIGNAL(updateConnectionSettings(QString,QString,int,int)), this, SLOT(updateConnectionSettings(QString,QString,int,int)));
|
|
||||||
connect(this, SIGNAL(suspendCapturing(bool)), connectionWindow, SLOT(setSuspendAll(bool)));
|
connect(this, SIGNAL(suspendCapturing(bool)), connectionWindow, SLOT(setSuspendAll(bool)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -479,20 +458,21 @@ void MainWindow::filterClearAll()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::tickGUIUpdate()
|
void MainWindow::tickGUIUpdate()
|
||||||
|
{
|
||||||
|
rxFrames = model->sendBulkRefresh();
|
||||||
|
if(rxFrames>0)
|
||||||
{
|
{
|
||||||
int elapsed = elapsedTime->elapsed();
|
int elapsed = elapsedTime->elapsed();
|
||||||
if(elapsed) {
|
if(elapsed) {
|
||||||
framesPerSec += rxFrames * 1000 / elapsed - (framesPerSec / 4);
|
framesPerSec = rxFrames * 1000 / elapsed;
|
||||||
elapsedTime->restart();
|
elapsedTime->restart();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
framesPerSec = 0;
|
framesPerSec = 0;
|
||||||
|
|
||||||
model->sendBulkRefresh(rxFrames);
|
|
||||||
|
|
||||||
ui->lbNumFrames->setText(QString::number(model->rowCount()));
|
ui->lbNumFrames->setText(QString::number(model->rowCount()));
|
||||||
if (ui->cbAutoScroll->isChecked()) ui->canFramesView->scrollToBottom();
|
if (ui->cbAutoScroll->isChecked()) ui->canFramesView->scrollToBottom();
|
||||||
ui->lbFPS->setText(QString::number(framesPerSec / 4));
|
ui->lbFPS->setText(QString::number(framesPerSec));
|
||||||
if (rxFrames > 0)
|
if (rxFrames > 0)
|
||||||
{
|
{
|
||||||
bDirty = true;
|
bDirty = true;
|
||||||
@@ -503,6 +483,7 @@ void MainWindow::tickGUIUpdate()
|
|||||||
|
|
||||||
rxFrames = 0;
|
rxFrames = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::gotFrames(int framesSinceLastUpdate)
|
void MainWindow::gotFrames(int framesSinceLastUpdate)
|
||||||
{
|
{
|
||||||
@@ -867,7 +848,7 @@ void MainWindow::showFrameSenderWindow()
|
|||||||
else
|
else
|
||||||
frameSenderWindow = new FrameSenderWindow(model->getFilteredListReference());
|
frameSenderWindow = new FrameSenderWindow(model->getFilteredListReference());
|
||||||
|
|
||||||
connect(frameSenderWindow, &FrameSenderWindow::sendCANFrame, connectionWindow, &ConnectionWindow::sendFrame);
|
//connect(frameSenderWindow, &FrameSenderWindow::sendCANFrame, connectionWindow, &ConnectionWindow::sendFrame);
|
||||||
}
|
}
|
||||||
frameSenderWindow->show();
|
frameSenderWindow->show();
|
||||||
}
|
}
|
||||||
@@ -881,8 +862,8 @@ void MainWindow::showPlaybackWindow()
|
|||||||
else
|
else
|
||||||
playbackWindow = new FramePlaybackWindow(model->getFilteredListReference());
|
playbackWindow = new FramePlaybackWindow(model->getFilteredListReference());
|
||||||
|
|
||||||
connect(playbackWindow, SIGNAL(sendCANFrame(const CANFrame*)), connectionWindow, SLOT(sendFrame(const CANFrame*)), Qt::QueuedConnection);
|
//connect(playbackWindow, SIGNAL(sendCANFrame(const CANFrame*)), connectionWindow, SLOT(sendFrame(const CANFrame*)), Qt::QueuedConnection);
|
||||||
connect(playbackWindow, SIGNAL(sendFrameBatch(const QList<CANFrame>*)), connectionWindow, SLOT(sendFrameBatch(const QList<CANFrame>*)), Qt::QueuedConnection);
|
//connect(playbackWindow, SIGNAL(sendFrameBatch(const QList<CANFrame>*)), connectionWindow, SLOT(sendFrameBatch(const QList<CANFrame>*)), Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
playbackWindow->show();
|
playbackWindow->show();
|
||||||
}
|
}
|
||||||
@@ -892,7 +873,7 @@ void MainWindow::showFirmwareUploaderWindow()
|
|||||||
if (!firmwareUploaderWindow)
|
if (!firmwareUploaderWindow)
|
||||||
{
|
{
|
||||||
firmwareUploaderWindow = new FirmwareUploaderWindow(model->getListReference());
|
firmwareUploaderWindow = new FirmwareUploaderWindow(model->getListReference());
|
||||||
connect(firmwareUploaderWindow, SIGNAL(sendCANFrame(const CANFrame*)), connectionWindow, SLOT(sendFrame(const CANFrame*)));
|
//connect(firmwareUploaderWindow, SIGNAL(sendCANFrame(const CANFrame*)), connectionWindow, SLOT(sendFrame(const CANFrame*)));
|
||||||
//connect(worker, SIGNAL(gotTargettedFrame(int)), firmwareUploaderWindow, SLOT(gotTargettedFrame(int)));
|
//connect(worker, SIGNAL(gotTargettedFrame(int)), firmwareUploaderWindow, SLOT(gotTargettedFrame(int)));
|
||||||
}
|
}
|
||||||
firmwareUploaderWindow->show();
|
firmwareUploaderWindow->show();
|
||||||
@@ -942,7 +923,6 @@ void MainWindow::showScriptingWindow()
|
|||||||
if (!scriptingWindow)
|
if (!scriptingWindow)
|
||||||
{
|
{
|
||||||
scriptingWindow = new ScriptingWindow(model->getListReference());
|
scriptingWindow = new ScriptingWindow(model->getListReference());
|
||||||
connect(scriptingWindow, &ScriptingWindow::sendCANFrame, connectionWindow, &ConnectionWindow::sendFrame);
|
|
||||||
}
|
}
|
||||||
scriptingWindow->show();
|
scriptingWindow->show();
|
||||||
}
|
}
|
||||||
@@ -995,8 +975,7 @@ void MainWindow::showConnectionSettingsWindow()
|
|||||||
{
|
{
|
||||||
if (!connectionWindow)
|
if (!connectionWindow)
|
||||||
{
|
{
|
||||||
connectionWindow = new ConnectionWindow(model);
|
connectionWindow = new ConnectionWindow();
|
||||||
connect(connectionWindow, SIGNAL(updateConnectionSettings(QString,QString,int,int)), this, SLOT(updateConnectionSettings(QString,QString,int,int)));
|
|
||||||
}
|
}
|
||||||
connectionWindow->show();
|
connectionWindow->show();
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -103,6 +103,9 @@
|
|||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Suspend Capturing</string>
|
<string>Suspend Capturing</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@@ -197,7 +200,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>800</width>
|
<width>800</width>
|
||||||
<height>27</height>
|
<height>19</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menu_RE_Tools">
|
<widget class="QMenu" name="menu_RE_Tools">
|
||||||
|
|||||||
+36
-9
@@ -1,14 +1,12 @@
|
|||||||
#include "scriptcontainer.h"
|
|
||||||
|
|
||||||
#include <QJSValueIterator>
|
#include <QJSValueIterator>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
ScriptContainer::ScriptContainer()
|
#include "scriptcontainer.h"
|
||||||
{
|
#include "connections/canconmanager.h"
|
||||||
fileName = QString();
|
|
||||||
filePath = QString();
|
|
||||||
scriptText = QString();
|
|
||||||
|
|
||||||
|
ScriptContainer::ScriptContainer(QString& pConName):
|
||||||
|
mConName(pConName)
|
||||||
|
{
|
||||||
connect(&timer, SIGNAL(timeout()), this, SLOT(tick()));
|
connect(&timer, SIGNAL(timeout()), this, SLOT(tick()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,6 +66,25 @@ void ScriptContainer::setFilter(QJSValue id, QJSValue mask, QJSValue bus)
|
|||||||
CANFilter filter;
|
CANFilter filter;
|
||||||
filter.setFilter(idVal, maskVal, busVal);
|
filter.setFilter(idVal, maskVal, busVal);
|
||||||
filters.append(filter);
|
filters.append(filter);
|
||||||
|
|
||||||
|
qDebug() << "FIXME setFilter";
|
||||||
|
CANConnection* conn_p = CANConManager::getInstance()->getByName(mConName);
|
||||||
|
if(conn_p)
|
||||||
|
{
|
||||||
|
for(int i=0 ; i<conn_p->getNumBuses() ; i++)
|
||||||
|
{
|
||||||
|
QVector<CANFlt> fltrs;
|
||||||
|
foreach(const CANFilter& flt, filters)
|
||||||
|
{
|
||||||
|
if(flt.bus==i) {
|
||||||
|
fltrs.append({flt.ID, flt.mask, true});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(fltrs.size())
|
||||||
|
conn_p->setFilters(i, fltrs, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptContainer::setTickInterval(QJSValue interval)
|
void ScriptContainer::setTickInterval(QJSValue interval)
|
||||||
@@ -86,6 +103,14 @@ void ScriptContainer::clearFilters()
|
|||||||
{
|
{
|
||||||
qDebug() << "Called clear filters";
|
qDebug() << "Called clear filters";
|
||||||
filters.clear();
|
filters.clear();
|
||||||
|
|
||||||
|
qDebug() << "FIXME clearFilters";
|
||||||
|
CANConnection* conn_p = CANConManager::getInstance()->getByName(mConName);
|
||||||
|
if(conn_p)
|
||||||
|
{
|
||||||
|
for(int i=0 ; i<conn_p->getNumBuses() ; i++)
|
||||||
|
conn_p->setFilters(i, QVector<CANFlt>(), false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptContainer::sendFrame(QJSValue bus, QJSValue id, QJSValue length, QJSValue data)
|
void ScriptContainer::sendFrame(QJSValue bus, QJSValue id, QJSValue length, QJSValue data)
|
||||||
@@ -109,8 +134,10 @@ void ScriptContainer::sendFrame(QJSValue bus, QJSValue id, QJSValue length, QJSV
|
|||||||
|
|
||||||
if (frame.ID > 0x7FF) frame.extended = true;
|
if (frame.ID > 0x7FF) frame.extended = true;
|
||||||
|
|
||||||
//qDebug() << "Sending frame from script";
|
qDebug() << "sending frame from script";
|
||||||
emit sendCANFrame(&frame);
|
CANConnection* conn_p = CANConManager::getInstance()->getByName(mConName);
|
||||||
|
if(conn_p)
|
||||||
|
conn_p->sendFrame(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptContainer::gotFrame(const CANFrame &frame)
|
void ScriptContainer::gotFrame(const CANFrame &frame)
|
||||||
|
|||||||
+2
-1
@@ -13,12 +13,13 @@ class ScriptContainer : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ScriptContainer();
|
ScriptContainer(QString&);
|
||||||
void gotFrame(const CANFrame &frame);
|
void gotFrame(const CANFrame &frame);
|
||||||
|
|
||||||
QString fileName;
|
QString fileName;
|
||||||
QString filePath;
|
QString filePath;
|
||||||
QString scriptText;
|
QString scriptText;
|
||||||
|
QString mConName;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void compileScript();
|
void compileScript();
|
||||||
|
|||||||
+27
-20
@@ -3,9 +3,10 @@
|
|||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
#include <QSettings>
|
||||||
#include <Qsci/qscilexerjavascript.h>
|
#include <Qsci/qscilexerjavascript.h>
|
||||||
|
|
||||||
#include "mainwindow.h"
|
#include "connections/canconmanager.h"
|
||||||
|
|
||||||
ScriptingWindow::ScriptingWindow(const QVector<CANFrame> *frames, QWidget *parent) :
|
ScriptingWindow::ScriptingWindow(const QVector<CANFrame> *frames, QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
@@ -23,7 +24,8 @@ ScriptingWindow::ScriptingWindow(const QVector<CANFrame> *frames, QWidget *paren
|
|||||||
connect(ui->btnRemoveScript, &QAbstractButton::pressed, this, &ScriptingWindow::deleteCurrentScript);
|
connect(ui->btnRemoveScript, &QAbstractButton::pressed, this, &ScriptingWindow::deleteCurrentScript);
|
||||||
connect(ui->btnRevertScript, &QAbstractButton::pressed, this, &ScriptingWindow::revertScript);
|
connect(ui->btnRevertScript, &QAbstractButton::pressed, this, &ScriptingWindow::revertScript);
|
||||||
connect(ui->btnSaveScript, &QAbstractButton::pressed, this, &ScriptingWindow::saveScript);
|
connect(ui->btnSaveScript, &QAbstractButton::pressed, this, &ScriptingWindow::saveScript);
|
||||||
connect(MainWindow::getReference(), &MainWindow::framesUpdated, this, &ScriptingWindow::updatedFrames);
|
|
||||||
|
connect(CANConManager::getInstance(), &CANConManager::framesReceived, this, &ScriptingWindow::newFrames);
|
||||||
|
|
||||||
ui->txtScriptSource->setLexer(new QsciLexerJavaScript(ui->txtScriptSource));
|
ui->txtScriptSource->setLexer(new QsciLexerJavaScript(ui->txtScriptSource));
|
||||||
}
|
}
|
||||||
@@ -33,27 +35,22 @@ ScriptingWindow::~ScriptingWindow()
|
|||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptingWindow::updatedFrames(int numFrames)
|
|
||||||
|
void ScriptingWindow::newFrames(const CANConnection* pConn, const QVector<CANFrame>& pFrames)
|
||||||
{
|
{
|
||||||
CANFrame thisFrame;
|
/*FIXME: name of the probe and bus should be checked */
|
||||||
//-1 means all frames deleted and -2 means a full refresh, neither of which we care about here.
|
Q_UNUSED(pConn);
|
||||||
if (numFrames > 0)
|
|
||||||
{
|
|
||||||
if (numFrames > modelFrames->count()) return;
|
|
||||||
qDebug() << "Got frames into script window: " << numFrames;
|
|
||||||
//for every new frame pass it on to each script container. The container will determine if it needs to actually
|
|
||||||
//notify the script and do that if applicable.
|
|
||||||
for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++)
|
|
||||||
{
|
|
||||||
thisFrame = modelFrames->at(i);
|
|
||||||
for (int j = 0; j < scripts.length(); j++)
|
for (int j = 0; j < scripts.length(); j++)
|
||||||
{
|
{
|
||||||
scripts[j]->gotFrame(thisFrame);
|
foreach(const CANFrame& frame, pFrames)
|
||||||
}
|
{
|
||||||
|
scripts[j]->gotFrame(frame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ScriptingWindow::closeEvent(QCloseEvent *event)
|
void ScriptingWindow::closeEvent(QCloseEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event);
|
Q_UNUSED(event);
|
||||||
@@ -115,13 +112,19 @@ void ScriptingWindow::loadNewScript()
|
|||||||
QStringList fileList = filename.split('/');
|
QStringList fileList = filename.split('/');
|
||||||
QString justFileName = fileList[fileList.length() - 1];
|
QString justFileName = fileList[fileList.length() - 1];
|
||||||
ui->listLoadedScripts->addItem(justFileName);
|
ui->listLoadedScripts->addItem(justFileName);
|
||||||
container = new ScriptContainer();
|
/* get the first connection in the list for now */
|
||||||
|
qDebug() << "FIXME: connection is always the first in list";
|
||||||
|
QString portName;
|
||||||
|
QList<CANConnection*> list = CANConManager::getInstance()->getConnections();
|
||||||
|
if(!list.isEmpty())
|
||||||
|
portName = list.first()->getPort();
|
||||||
|
|
||||||
|
container = new ScriptContainer(portName);
|
||||||
container->fileName = justFileName;
|
container->fileName = justFileName;
|
||||||
container->filePath = filename;
|
container->filePath = filename;
|
||||||
container->scriptText = contents;
|
container->scriptText = contents;
|
||||||
container->setErrorWidget(ui->listErrors);
|
container->setErrorWidget(ui->listErrors);
|
||||||
container->compileScript();
|
container->compileScript();
|
||||||
connect(container, &ScriptContainer::sendCANFrame, this, &ScriptingWindow::sendCANFrame);
|
|
||||||
scripts.append(container);
|
scripts.append(container);
|
||||||
currentScript = container;
|
currentScript = container;
|
||||||
ui->txtScriptSource->setText(container->scriptText);
|
ui->txtScriptSource->setText(container->scriptText);
|
||||||
@@ -135,13 +138,17 @@ void ScriptingWindow::createNewScript()
|
|||||||
{
|
{
|
||||||
ScriptContainer *container;
|
ScriptContainer *container;
|
||||||
|
|
||||||
container = new ScriptContainer();
|
QString portName;
|
||||||
|
QList<CANConnection*> list = CANConManager::getInstance()->getConnections();
|
||||||
|
if(!list.isEmpty())
|
||||||
|
portName = list.first()->getPort();
|
||||||
|
|
||||||
|
container = new ScriptContainer(portName);
|
||||||
|
|
||||||
container->fileName = "UNNAMED_" + QString::number((qrand() % 10000)) + ".js";
|
container->fileName = "UNNAMED_" + QString::number((qrand() % 10000)) + ".js";
|
||||||
container->filePath = QString();
|
container->filePath = QString();
|
||||||
container->scriptText = QString();
|
container->scriptText = QString();
|
||||||
container->setErrorWidget(ui->listErrors);
|
container->setErrorWidget(ui->listErrors);
|
||||||
connect(container, &ScriptContainer::sendCANFrame, this, &ScriptingWindow::sendCANFrame);
|
|
||||||
scripts.append(container);
|
scripts.append(container);
|
||||||
ui->listLoadedScripts->addItem(container->fileName);
|
ui->listLoadedScripts->addItem(container->fileName);
|
||||||
currentScript = container;
|
currentScript = container;
|
||||||
|
|||||||
+2
-6
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "can_structs.h"
|
#include "can_structs.h"
|
||||||
#include "scriptcontainer.h"
|
#include "scriptcontainer.h"
|
||||||
|
#include "connections/canconnection.h"
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QJSEngine>
|
#include <QJSEngine>
|
||||||
@@ -28,12 +29,7 @@ private slots:
|
|||||||
void saveScript();
|
void saveScript();
|
||||||
void revertScript();
|
void revertScript();
|
||||||
void recompileScript();
|
void recompileScript();
|
||||||
void updatedFrames(int);
|
void newFrames(const CANConnection*, const QVector<CANFrame>&);
|
||||||
|
|
||||||
public slots:
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void sendCANFrame(const CANFrame *);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void closeEvent(QCloseEvent *event);
|
void closeEvent(QCloseEvent *event);
|
||||||
|
|||||||
Reference in New Issue
Block a user