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/socketcan.cpp \
|
||||
connections/canconfactory.cpp \
|
||||
connections/gvretserial.cpp
|
||||
connections/gvretserial.cpp \
|
||||
connections/canconmanager.cpp
|
||||
|
||||
HEADERS += mainwindow.h \
|
||||
can_structs.h \
|
||||
@@ -97,7 +98,8 @@ HEADERS += mainwindow.h \
|
||||
connections/socketcan.h \
|
||||
connections/canconconst.h \
|
||||
connections/canconfactory.h \
|
||||
connections/gvretserial.h
|
||||
connections/gvretserial.h \
|
||||
connections/canconmanager.h
|
||||
|
||||
FORMS += mainwindow.ui \
|
||||
graphingwindow.ui \
|
||||
|
||||
+30
-21
@@ -3,10 +3,10 @@
|
||||
|
||||
CANBus::CANBus()
|
||||
{
|
||||
speed = 250000;
|
||||
listenOnly = false;
|
||||
singleWire = false;
|
||||
active = false;
|
||||
speed = 250000;
|
||||
listenOnly = false;
|
||||
singleWire = false;
|
||||
active = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,44 +24,53 @@ bool CANBus::operator==(const CANBus& bus) const{
|
||||
active == bus.active;
|
||||
}
|
||||
|
||||
|
||||
void CANBus::setSpeed(int newSpeed)
|
||||
{
|
||||
void CANBus::setSpeed(int newSpeed){
|
||||
speed = newSpeed;
|
||||
}
|
||||
|
||||
void CANBus::setListenOnly(bool mode)
|
||||
{
|
||||
void CANBus::setListenOnly(bool mode){
|
||||
listenOnly = mode;
|
||||
}
|
||||
|
||||
void CANBus::setSingleWire(bool mode)
|
||||
{
|
||||
void CANBus::setSingleWire(bool mode){
|
||||
singleWire = mode;
|
||||
}
|
||||
|
||||
void CANBus::setEnabled(bool mode)
|
||||
{
|
||||
void CANBus::setEnabled(bool mode){
|
||||
active = mode;
|
||||
}
|
||||
|
||||
int CANBus::getSpeed()
|
||||
{
|
||||
int CANBus::getSpeed(){
|
||||
return speed;
|
||||
}
|
||||
|
||||
bool CANBus::isListenOnly()
|
||||
{
|
||||
bool CANBus::isListenOnly(){
|
||||
return listenOnly;
|
||||
}
|
||||
|
||||
bool CANBus::isSingleWire()
|
||||
{
|
||||
bool CANBus::isSingleWire(){
|
||||
return singleWire;
|
||||
}
|
||||
|
||||
bool CANBus::isActive()
|
||||
{
|
||||
bool CANBus::isActive(){
|
||||
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
|
||||
#define CANBus_H
|
||||
|
||||
#include <QDataStream>
|
||||
|
||||
class CANBus
|
||||
{
|
||||
@@ -8,7 +8,8 @@ public:
|
||||
CANBus();
|
||||
CANBus(const CANBus&);
|
||||
bool operator==(const CANBus&) const;
|
||||
virtual ~CANBus(){}; /*TODO: remove connection from CANBus and add CANBus as an element of CANConnection */
|
||||
virtual ~CANBus(){};
|
||||
|
||||
int speed;
|
||||
bool listenOnly;
|
||||
bool singleWire;
|
||||
@@ -25,4 +26,9 @@ public:
|
||||
bool isActive();
|
||||
};
|
||||
|
||||
QDataStream& operator<<( QDataStream & pStream, const CANBus& pCanBus );
|
||||
QDataStream & operator>>(QDataStream & pStream, CANBus& pCanBus);
|
||||
|
||||
Q_DECLARE_METATYPE(CANBus);
|
||||
|
||||
#endif // CANBus_H
|
||||
|
||||
+44
-23
@@ -1,11 +1,16 @@
|
||||
#include "connections/canconnection.h"
|
||||
#include "canconnectionmodel.h"
|
||||
#include "connections/canconnection.h"
|
||||
#include "connections/canconmanager.h"
|
||||
|
||||
CANConnectionModel::CANConnectionModel(QObject *parent)
|
||||
: QAbstractTableModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
CANConnectionModel::~CANConnectionModel()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return 7;
|
||||
}
|
||||
|
||||
|
||||
int CANConnectionModel::rowCount(const QModelIndex &parent) const {
|
||||
int rows=0;
|
||||
QList<CANConnection*>::const_iterator iter;
|
||||
int CANConnectionModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
|
||||
for (iter = mConns.begin() ; iter != mConns.end() ; ++iter) {
|
||||
rows+=(*iter)->getNumBuses();
|
||||
}
|
||||
int rows=0;
|
||||
QList<CANConnection*>& conns = CANConManager::getInstance()->getConnections();
|
||||
|
||||
foreach(const CANConnection* conn_p, conns)
|
||||
rows+=conn_p->getNumBuses();
|
||||
|
||||
return rows;
|
||||
}
|
||||
@@ -124,49 +132,62 @@ QVariant CANConnectionModel::data(const QModelIndex &index, int role) const
|
||||
|
||||
void CANConnectionModel::add(CANConnection* pConn_p)
|
||||
{
|
||||
CANConManager* manager = CANConManager::getInstance();
|
||||
|
||||
connect(pConn_p, SIGNAL(notify()), manager, SLOT(refreshCanList()));
|
||||
|
||||
beginResetModel();
|
||||
mConns.append(pConn_p);
|
||||
manager->getConnections().append(pConn_p);
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
|
||||
void CANConnectionModel::remove(CANConnection* pConn_p)
|
||||
{
|
||||
CANConManager* manager = CANConManager::getInstance();
|
||||
|
||||
disconnect(pConn_p, 0, manager, 0);
|
||||
|
||||
beginResetModel();
|
||||
mConns.removeOne(pConn_p);
|
||||
manager->getConnections().removeOne(pConn_p);
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
|
||||
QList<CANConnection*>& CANConnectionModel::getConnections()
|
||||
{
|
||||
return mConns;
|
||||
}
|
||||
|
||||
|
||||
CANConnection* CANConnectionModel::getAtIdx(int pIdx, int& pBusId) const
|
||||
{
|
||||
if (pIdx < 0)
|
||||
return NULL;
|
||||
|
||||
int i=0;
|
||||
QList<CANConnection*>::const_iterator iter = mConns.begin();
|
||||
QList<CANConnection*>& conns = CANConManager::getInstance()->getConnections();
|
||||
|
||||
for (iter = mConns.begin() ; iter != mConns.end() ; ++iter) {
|
||||
if( i <= pIdx && pIdx < i+(*iter)->getNumBuses() ) {
|
||||
foreach(CANConnection* conn_p, conns)
|
||||
{
|
||||
if( i <= pIdx && pIdx < i+conn_p->getNumBuses() ) {
|
||||
pBusId = pIdx - i;
|
||||
return (*iter);
|
||||
return conn_p;
|
||||
}
|
||||
|
||||
i+= (*iter)->getNumBuses();
|
||||
i+= conn_p->getNumBuses();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void CANConnectionModel::refreshView()
|
||||
void CANConnectionModel::refresh(int pIndex)
|
||||
{
|
||||
beginResetModel();
|
||||
endResetModel();
|
||||
QModelIndex begin;
|
||||
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:
|
||||
explicit CANConnectionModel(QObject *parent = 0);
|
||||
virtual ~CANConnectionModel();
|
||||
|
||||
// Header:
|
||||
// from abstractmodel:
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
void add(CANConnection* pConn_p);
|
||||
void remove(CANConnection* pConn_p);
|
||||
|
||||
QList<CANConnection*>& getConnections();
|
||||
CANConnection* getAtIdx(int, int&) const;
|
||||
void refreshView();
|
||||
|
||||
private:
|
||||
QList<CANConnection*> mConns;
|
||||
void refresh(int pIndex=-1);
|
||||
};
|
||||
|
||||
#endif // CANCONNECTIONMODEL_H
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ public:
|
||||
void setFilter(uint32_t id, uint32_t mask, int bus);
|
||||
bool checkFilter(uint32_t id, int bus);
|
||||
|
||||
private:
|
||||
public:
|
||||
uint32_t ID;
|
||||
uint32_t mask;
|
||||
int bus;
|
||||
|
||||
+19
-26
@@ -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 */
|
||||
mutex.lock();
|
||||
@@ -346,6 +346,15 @@ void CANFrameModel::addFrame(CANFrame& frame, bool autoRefresh = false)
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
void CANFrameModel::addFrames(const CANConnection*, const QVector<CANFrame>& pFrames)
|
||||
{
|
||||
foreach(const CANFrame& frame, pFrames)
|
||||
{
|
||||
addFrame(frame);
|
||||
}
|
||||
}
|
||||
|
||||
void CANFrameModel::sendRefresh()
|
||||
{
|
||||
qDebug() << "Sending mass refresh";
|
||||
@@ -377,38 +386,22 @@ void CANFrameModel::sendRefresh(int pos)
|
||||
//issue a refresh for the last num entries in the model.
|
||||
//used by the serial worker to do batch updates so it doesn't
|
||||
//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
|
||||
//of how many by tracking the number we last knew about as opposed to how many rows there
|
||||
//are now.
|
||||
num = filteredFrames.count() - lastUpdateNumFrames;
|
||||
int num = filteredFrames.count() - lastUpdateNumFrames;
|
||||
if (num <= 0) return 0;
|
||||
|
||||
if (num < 0) return;
|
||||
|
||||
//qDebug() << "Num: " << num;
|
||||
|
||||
if (num == 0 && !overwriteDups) return;
|
||||
if (filteredFrames.count() == 0) return;
|
||||
if (num == 0 && !overwriteDups) return 0;
|
||||
if (filteredFrames.count() == 0) return 0;
|
||||
|
||||
lastUpdateNumFrames += num; //done this way to avoid asking for filteredFrames.count() again
|
||||
|
||||
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();
|
||||
endResetModel();
|
||||
}
|
||||
else
|
||||
{
|
||||
beginResetModel();
|
||||
endResetModel();
|
||||
}
|
||||
beginResetModel();
|
||||
endResetModel();
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
void CANFrameModel::clearFrames()
|
||||
|
||||
+4
-2
@@ -8,6 +8,7 @@
|
||||
#include <QMutex>
|
||||
#include "can_structs.h"
|
||||
#include "dbchandler.h"
|
||||
#include "connections/canconnection.h"
|
||||
|
||||
class CANFrameModel: public QAbstractTableModel
|
||||
{
|
||||
@@ -25,7 +26,7 @@ public:
|
||||
|
||||
void sendRefresh();
|
||||
void sendRefresh(int);
|
||||
void sendBulkRefresh(int);
|
||||
int sendBulkRefresh();
|
||||
void clearFrames();
|
||||
void setDBCHandler(DBCHandler *);
|
||||
void setInterpetMode(bool);
|
||||
@@ -46,7 +47,8 @@ public:
|
||||
const QMap<int, bool> *getFiltersReference() const; //this neither
|
||||
|
||||
public slots:
|
||||
void addFrame(CANFrame&, bool);
|
||||
void addFrame(const CANFrame&, bool);
|
||||
void addFrames(const CANConnection*, const QVector<CANFrame>&);
|
||||
|
||||
signals:
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
* @brief getNumBuses
|
||||
* @return returns the number of buses of the device
|
||||
*/
|
||||
int getNumBuses();
|
||||
int getNumBuses() const;
|
||||
|
||||
/**
|
||||
* @brief getPort
|
||||
|
||||
@@ -147,7 +147,7 @@ void SocketCan::errorReceived(QCanBusDevice::CanBusError error) const
|
||||
|
||||
void SocketCan::framesWritten(qint64 count)
|
||||
{
|
||||
qDebug() << "Number of frames written:" << count;
|
||||
//qDebug() << "Number of frames written:" << count;
|
||||
}
|
||||
|
||||
void SocketCan::framesReceived()
|
||||
|
||||
+192
-245
@@ -4,29 +4,26 @@
|
||||
#include "connectionwindow.h"
|
||||
#include "ui_connectionwindow.h"
|
||||
#include "connections/canconfactory.h"
|
||||
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
#include "connections/canconmanager.h"
|
||||
#include "canbus.h"
|
||||
|
||||
|
||||
ConnectionWindow::ConnectionWindow(CANFrameModel *cModel, QWidget *parent) :
|
||||
|
||||
ConnectionWindow::ConnectionWindow(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::ConnectionWindow),
|
||||
mRefreshReqOngoing(FALSE)
|
||||
ui(new Ui::ConnectionWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
settings = new QSettings();
|
||||
QSettings settings;
|
||||
|
||||
qRegisterMetaType<CANBus>("CANBus");
|
||||
qRegisterMetaType<const CANFrame *>("const CANFrame *");
|
||||
qRegisterMetaType<const QList<CANFrame> *>("const QList<CANFrame> *");
|
||||
|
||||
connModel = new CANConnectionModel();
|
||||
|
||||
connModel = new CANConnectionModel(this);
|
||||
ui->tableConnections->setModel(connModel);
|
||||
|
||||
canModel = cModel;
|
||||
|
||||
ui->tableConnections->setColumnWidth(0, 50);
|
||||
ui->tableConnections->setColumnWidth(1, 110);
|
||||
ui->tableConnections->setColumnWidth(2, 110);
|
||||
@@ -35,14 +32,7 @@ ConnectionWindow::ConnectionWindow(CANFrameModel *cModel, QWidget *parent) :
|
||||
ui->tableConnections->setColumnWidth(5, 75);
|
||||
ui->tableConnections->setColumnWidth(6, 75);
|
||||
ui->tableConnections->setColumnWidth(7, 75);
|
||||
|
||||
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->ckSingleWire->setChecked(settings.value("Main/SingleWireMode", false).toBool());
|
||||
|
||||
ui->cbSpeed->addItem(tr("<Default>"));
|
||||
ui->cbSpeed->addItem(tr("125000"));
|
||||
@@ -51,114 +41,90 @@ ConnectionWindow::ConnectionWindow(CANFrameModel *cModel, QWidget *parent) :
|
||||
ui->cbSpeed->addItem(tr("1000000"));
|
||||
ui->cbSpeed->addItem(tr("33333"));
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
ui->rbSocketCAN->setEnabled(isSocketCanAvailable());
|
||||
#endif
|
||||
/* load connection configuration */
|
||||
loadConnections();
|
||||
|
||||
ui->rbSocketCAN->setEnabled(isSocketCanAvailable());
|
||||
#ifdef Q_OS_WIN
|
||||
ui->rbKvaser->setEnabled(true);
|
||||
#endif
|
||||
|
||||
connect(ui->btnOK, &QAbstractButton::clicked, this, &ConnectionWindow::handleOKButton);
|
||||
connect(ui->rbGVRET, &QAbstractButton::toggled, this, &ConnectionWindow::handleConnTypeChanged);
|
||||
connect(ui->rbKvaser, &QAbstractButton::toggled, this, &ConnectionWindow::handleConnTypeChanged);
|
||||
connect(ui->rbSocketCAN, &QAbstractButton::toggled, this, &ConnectionWindow::handleConnTypeChanged);
|
||||
connect(ui->rbGVRET, &QAbstractButton::clicked, this, &ConnectionWindow::handleConnTypeChanged);
|
||||
connect(ui->rbKvaser, &QAbstractButton::clicked, this, &ConnectionWindow::handleConnTypeChanged);
|
||||
connect(ui->rbSocketCAN, &QAbstractButton::clicked, this, &ConnectionWindow::handleConnTypeChanged);
|
||||
connect(ui->btnRevert, &QPushButton::clicked, this, &ConnectionWindow::handleRevert);
|
||||
connect(ui->tableConnections->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ConnectionWindow::handleConnSelectionChanged);
|
||||
connect(connModel, &QAbstractItemModel::modelReset, this, &ConnectionWindow::handleConnSelectionChanged);
|
||||
connect(ui->tableConnections->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &ConnectionWindow::currentRowChanged);
|
||||
connect(ui->btnNewConn, &QPushButton::clicked, this, &ConnectionWindow::handleNewConn);
|
||||
connect(ui->btnActivateAll, &QPushButton::clicked, this, &ConnectionWindow::handleEnableAll);
|
||||
connect(ui->btnDeactivateAll, &QPushButton::clicked, this, &ConnectionWindow::handleDisableAll);
|
||||
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()
|
||||
{
|
||||
QList<CANConnection*>& conns = connModel->getConnections();
|
||||
QList<CANConnection*>& conns = CANConManager::getInstance()->getConnections();
|
||||
CANConnection* conn_p;
|
||||
|
||||
/* save configuration */
|
||||
saveConnections();
|
||||
|
||||
/* delete connections */
|
||||
while(!conns.isEmpty()) {
|
||||
while(!conns.isEmpty())
|
||||
{
|
||||
conn_p = conns.takeFirst();
|
||||
conn_p->stop();
|
||||
delete conn_p;
|
||||
}
|
||||
|
||||
delete connModel;
|
||||
|
||||
mTicker.stop();
|
||||
delete settings;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
void ConnectionWindow::showEvent(QShowEvent* event)
|
||||
{
|
||||
QDialog::showEvent(event);
|
||||
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)
|
||||
{
|
||||
qDebug() << "setSuspendAll";
|
||||
QList<CANConnection*>& conns = CANConManager::getInstance()->getConnections();
|
||||
|
||||
QList<CANConnection*>::iterator iter;
|
||||
QList<CANConnection*>& conns = connModel->getConnections();
|
||||
foreach(CANConnection* conn_p, conns)
|
||||
conn_p->suspend(pSuspend);
|
||||
|
||||
for (iter = conns.begin(); iter != conns.end(); ++iter)
|
||||
(*iter)->suspend(pSuspend);
|
||||
connModel->refresh();
|
||||
}
|
||||
|
||||
|
||||
void ConnectionWindow::setActiveAll(bool pActive)
|
||||
{
|
||||
QList<CANConnection*>::iterator iter;
|
||||
QList<CANConnection*>& conns = connModel->getConnections();
|
||||
CANBus bus;
|
||||
QList<CANConnection*>& conns = CANConManager::getInstance()->getConnections();
|
||||
|
||||
for (iter = conns.begin(); iter != conns.end(); ++iter) {
|
||||
for(int i=0 ; i<(*iter)->getNumBuses() ; i++) {
|
||||
if( (*iter)->getBusSettings(i, bus) ) {
|
||||
foreach(CANConnection* conn_p, conns)
|
||||
{
|
||||
for(int i=0 ; i<conn_p->getNumBuses() ; i++) {
|
||||
if( conn_p->getBusSettings(i, bus) ) {
|
||||
bus.active = pActive;
|
||||
(*iter)->setBusSettings(i, bus);
|
||||
conn_p->setBusSettings(i, bus);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
connModel->refresh();
|
||||
}
|
||||
|
||||
|
||||
void ConnectionWindow::handleNewConn()
|
||||
{
|
||||
ui->tableConnections->setCurrentIndex(QModelIndex());
|
||||
}
|
||||
|
||||
|
||||
void ConnectionWindow::handleEnableAll()
|
||||
{
|
||||
setActiveAll(true);
|
||||
@@ -180,8 +146,10 @@ void ConnectionWindow::handleConnTypeChanged()
|
||||
/* status */
|
||||
void ConnectionWindow::connectionStatus(CANCon::status pStatus)
|
||||
{
|
||||
Q_UNUSED(pStatus);
|
||||
|
||||
qDebug() << "Connectionstatus changed";
|
||||
connModel->refreshView();
|
||||
connModel->refresh();
|
||||
}
|
||||
|
||||
|
||||
@@ -193,6 +161,7 @@ void ConnectionWindow::handleOKButton()
|
||||
|
||||
if (whichRow > -1)
|
||||
{
|
||||
/* set information for selected connection */
|
||||
int busId;
|
||||
CANBus bus;
|
||||
bool ret;
|
||||
@@ -219,78 +188,15 @@ void ConnectionWindow::handleOKButton()
|
||||
/* update bus settings */
|
||||
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 */
|
||||
conn_p = CanConFactory::create(getConnectionType(), getPortName());
|
||||
conn_p = create(getConnectionType(), getPortName());
|
||||
if(!conn_p)
|
||||
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++) {
|
||||
/* set bus configuration */
|
||||
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)
|
||||
{
|
||||
ui->btnOK->setText(tr("Create New Connection"));
|
||||
|
||||
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->rbGVRET->setChecked(true);
|
||||
ui->ckListenOnly->setChecked(false);
|
||||
ui->ckSingleWire->setChecked(false);
|
||||
ui->ckEnabled->setChecked(true);
|
||||
ui->ckEnabled->setChecked(false);
|
||||
setSpeed(0);
|
||||
setPortName(CANCon::GVRET_SERIAL, "");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -362,25 +251,11 @@ void ConnectionWindow::handleConnSelectionChanged()
|
||||
if(!ret) return;
|
||||
|
||||
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->ckSingleWire->setChecked(bus.isSingleWire());
|
||||
ui->ckEnabled->setChecked(bus.isActive());
|
||||
int speed = bus.getSpeed();
|
||||
setSpeed(speed);
|
||||
setSpeed(bus.getSpeed());
|
||||
setPortName(conn_p->getType(), conn_p->getPort());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -394,48 +269,69 @@ void ConnectionWindow::selectSerial()
|
||||
ports = QSerialPortInfo::availablePorts();
|
||||
|
||||
for (int i = 0; i < ports.count(); i++)
|
||||
{
|
||||
ui->cbPort->addItem(ports[i].portName());
|
||||
//if (currentPortName == ports[i].portName()) ui->cbPort->setCurrentIndex(i);
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectionWindow::selectKvaser()
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
/* set combobox page visible */
|
||||
ui->stPort->setCurrentWidget(ui->cbPage);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ConnectionWindow::selectSocketCan()
|
||||
{
|
||||
#ifdef Q_OS_LINUX
|
||||
/* set edit text page visible */
|
||||
ui->stPort->setCurrentWidget(ui->etPage);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ConnectionWindow::setSpeed(int speed0)
|
||||
{
|
||||
bool found = false;
|
||||
|
||||
qDebug() << "Set Speed " << speed0;
|
||||
|
||||
for (int i = 0; i < ui->cbSpeed->count(); i++)
|
||||
{
|
||||
if (ui->cbSpeed->itemText(i).toInt() == speed0)
|
||||
{
|
||||
ui->cbSpeed->setCurrentIndex(i);
|
||||
found = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
|
||||
/* add custom speed */
|
||||
ui->cbSpeed->addItem(QString::number(speed0));
|
||||
ui->cbSpeed->setCurrentIndex(ui->cbSpeed->count() - 1);
|
||||
}
|
||||
|
||||
void ConnectionWindow::setPortName(CANCon::type pType, QString pPortName)
|
||||
{
|
||||
switch(pType)
|
||||
{
|
||||
ui->cbSpeed->addItem(QString::number(speed0));
|
||||
ui->cbSpeed->setCurrentIndex(ui->cbSpeed->count() - 1);
|
||||
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: {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -444,18 +340,13 @@ int ConnectionWindow::getSpeed()
|
||||
{
|
||||
switch (ui->cbSpeed->currentIndex())
|
||||
{
|
||||
case -1:
|
||||
return -1;
|
||||
break;
|
||||
case 0:
|
||||
return -1;
|
||||
break;
|
||||
case 1:
|
||||
return 0;
|
||||
break;
|
||||
default:
|
||||
return (ui->cbSpeed->currentText().toInt());
|
||||
break;
|
||||
case -1:
|
||||
case 0:
|
||||
return -1;
|
||||
case 1:
|
||||
return 0;
|
||||
default:
|
||||
return (ui->cbSpeed->currentText().toInt());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,12 +398,15 @@ void ConnectionWindow::handleRemoveConn()
|
||||
CANConnection* conn_p = connModel->getAtIdx(selIdx, busId);
|
||||
if(!conn_p) return;
|
||||
|
||||
/* remove connection from model */
|
||||
/* remove connection from model & manager */
|
||||
connModel->remove(conn_p);
|
||||
|
||||
/* stop and delete connection */
|
||||
conn_p->stop();
|
||||
delete conn_p;
|
||||
|
||||
/* select first connection in list */
|
||||
ui->tableConnections->selectRow(0);
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
#ifdef Q_OS_LINUX
|
||||
foreach (const QByteArray &backend, QCanBus::instance()->plugins()) {
|
||||
if (backend == "socketcan") {
|
||||
if (backend == "socketcan")
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
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 <QSettings>
|
||||
#include <QTimer>
|
||||
#include <QItemSelection>
|
||||
#include "canconnectionmodel.h"
|
||||
#include "canframemodel.h"
|
||||
#include "connections/canconnection.h"
|
||||
|
||||
|
||||
class CANConnectionModel;
|
||||
@@ -24,11 +25,10 @@ class ConnectionWindow : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ConnectionWindow(CANFrameModel *canModel, QWidget *parent = 0);
|
||||
explicit ConnectionWindow(QWidget *parent = 0);
|
||||
~ConnectionWindow();
|
||||
void showEvent(QShowEvent *);
|
||||
int getSpeed();
|
||||
QString getPortName(); //name of port to connect to
|
||||
|
||||
CANCon::type getConnectionType();
|
||||
bool getSWMode();
|
||||
|
||||
@@ -39,40 +39,38 @@ signals:
|
||||
public slots:
|
||||
void setSpeed(int speed0);
|
||||
void setSWMode(bool mode);
|
||||
void sendFrame(const CANFrame *);
|
||||
void sendFrameBatch(const QList<CANFrame> *);
|
||||
void setSuspendAll(bool);
|
||||
|
||||
void setSuspendAll(bool pSuspend);
|
||||
|
||||
private slots:
|
||||
void handleOKButton();
|
||||
void handleConnTypeChanged();
|
||||
void handleConnSelectionChanged();
|
||||
void currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||
void handleRemoveConn();
|
||||
void handleEnableAll();
|
||||
void handleDisableAll();
|
||||
void handleRevert();
|
||||
void handleNewConn();
|
||||
void receiveBusStatus(int bus, int speed, int status);
|
||||
void connectionStatus(CANCon::status);
|
||||
|
||||
void refreshCanList();
|
||||
|
||||
private:
|
||||
Ui::ConnectionWindow *ui;
|
||||
QList<QSerialPortInfo> ports;
|
||||
QSettings *settings;
|
||||
CANConnectionModel *connModel;
|
||||
CANFrameModel *canModel;
|
||||
QTimer mTicker;
|
||||
|
||||
QAtomicInt mRefreshReqOngoing;
|
||||
|
||||
void selectSerial();
|
||||
void selectKvaser();
|
||||
void selectSocketCan();
|
||||
bool isSocketCanAvailable();
|
||||
int getSpeed();
|
||||
QString getPortName();
|
||||
void setPortName(CANCon::type pType, QString pPortName);
|
||||
|
||||
void setActiveAll(bool pActive);
|
||||
CANConnection* create(CANCon::type pTye, QString pPortName);
|
||||
void loadConnections();
|
||||
void saveConnections();
|
||||
};
|
||||
|
||||
#endif // CONNECTIONWINDOW_H
|
||||
|
||||
+2
-2
@@ -74,7 +74,7 @@
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<widget class="QGroupBox" name="gbType">
|
||||
<property name="title">
|
||||
<string>Connection Type</string>
|
||||
</property>
|
||||
@@ -116,7 +116,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<widget class="QLabel" name="lPort">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
|
||||
+31
-52
@@ -4,7 +4,7 @@
|
||||
#include <QDateTime>
|
||||
#include <QFileDialog>
|
||||
#include <QtSerialPort/QSerialPortInfo>
|
||||
#include "canframemodel.h"
|
||||
#include "connections/canconmanager.h"
|
||||
#include "utility.h"
|
||||
#include "serialworker.h"
|
||||
|
||||
@@ -62,28 +62,6 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
ui->canFramesView->setColumnWidth(6, 275);
|
||||
QHeaderView *HorzHdr = ui->canFramesView->horizontalHeader();
|
||||
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;
|
||||
frameInfoWindow = NULL;
|
||||
@@ -146,6 +124,8 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
connect(ui->actionUDS_Scanner, &QAction::triggered, this, &MainWindow::showUDSScanWindow);
|
||||
connect(ui->actionISO_TP_Decoder, &QAction::triggered, this, &MainWindow::showISOInterpreterWindow);
|
||||
|
||||
connect(CANConManager::getInstance(), &CANConManager::framesReceived, model, &CANFrameModel::addFrames);
|
||||
|
||||
lbStatusConnected.setText(tr("Not connected"));
|
||||
updateFileStatus();
|
||||
lbStatusDatabase.setText(tr("No DBC database loaded"));
|
||||
@@ -179,8 +159,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
model->clearFrames();
|
||||
|
||||
//Automatically create the connection window so it can be updated even if we never opened it.
|
||||
connectionWindow = new ConnectionWindow(model);
|
||||
connect(connectionWindow, SIGNAL(updateConnectionSettings(QString,QString,int,int)), this, SLOT(updateConnectionSettings(QString,QString,int,int)));
|
||||
connectionWindow = new ConnectionWindow();
|
||||
connect(this, SIGNAL(suspendCapturing(bool)), connectionWindow, SLOT(setSuspendAll(bool)));
|
||||
}
|
||||
|
||||
@@ -480,28 +459,30 @@ void MainWindow::filterClearAll()
|
||||
|
||||
void MainWindow::tickGUIUpdate()
|
||||
{
|
||||
int elapsed = elapsedTime->elapsed();
|
||||
if(elapsed) {
|
||||
framesPerSec += rxFrames * 1000 / elapsed - (framesPerSec / 4);
|
||||
elapsedTime->restart();
|
||||
}
|
||||
else
|
||||
framesPerSec = 0;
|
||||
|
||||
model->sendBulkRefresh(rxFrames);
|
||||
|
||||
ui->lbNumFrames->setText(QString::number(model->rowCount()));
|
||||
if (ui->cbAutoScroll->isChecked()) ui->canFramesView->scrollToBottom();
|
||||
ui->lbFPS->setText(QString::number(framesPerSec / 4));
|
||||
if (rxFrames > 0)
|
||||
rxFrames = model->sendBulkRefresh();
|
||||
if(rxFrames>0)
|
||||
{
|
||||
bDirty = true;
|
||||
emit framesUpdated(rxFrames); //anyone care that frames were updated?
|
||||
int elapsed = elapsedTime->elapsed();
|
||||
if(elapsed) {
|
||||
framesPerSec = rxFrames * 1000 / elapsed;
|
||||
elapsedTime->restart();
|
||||
}
|
||||
else
|
||||
framesPerSec = 0;
|
||||
|
||||
ui->lbNumFrames->setText(QString::number(model->rowCount()));
|
||||
if (ui->cbAutoScroll->isChecked()) ui->canFramesView->scrollToBottom();
|
||||
ui->lbFPS->setText(QString::number(framesPerSec));
|
||||
if (rxFrames > 0)
|
||||
{
|
||||
bDirty = true;
|
||||
emit framesUpdated(rxFrames); //anyone care that frames were updated?
|
||||
}
|
||||
|
||||
if (model->needsFilterRefresh()) updateFilterList();
|
||||
|
||||
rxFrames = 0;
|
||||
}
|
||||
|
||||
if (model->needsFilterRefresh()) updateFilterList();
|
||||
|
||||
rxFrames = 0;
|
||||
}
|
||||
|
||||
void MainWindow::gotFrames(int framesSinceLastUpdate)
|
||||
@@ -867,7 +848,7 @@ void MainWindow::showFrameSenderWindow()
|
||||
else
|
||||
frameSenderWindow = new FrameSenderWindow(model->getFilteredListReference());
|
||||
|
||||
connect(frameSenderWindow, &FrameSenderWindow::sendCANFrame, connectionWindow, &ConnectionWindow::sendFrame);
|
||||
//connect(frameSenderWindow, &FrameSenderWindow::sendCANFrame, connectionWindow, &ConnectionWindow::sendFrame);
|
||||
}
|
||||
frameSenderWindow->show();
|
||||
}
|
||||
@@ -881,8 +862,8 @@ void MainWindow::showPlaybackWindow()
|
||||
else
|
||||
playbackWindow = new FramePlaybackWindow(model->getFilteredListReference());
|
||||
|
||||
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(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);
|
||||
}
|
||||
playbackWindow->show();
|
||||
}
|
||||
@@ -892,7 +873,7 @@ void MainWindow::showFirmwareUploaderWindow()
|
||||
if (!firmwareUploaderWindow)
|
||||
{
|
||||
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)));
|
||||
}
|
||||
firmwareUploaderWindow->show();
|
||||
@@ -942,7 +923,6 @@ void MainWindow::showScriptingWindow()
|
||||
if (!scriptingWindow)
|
||||
{
|
||||
scriptingWindow = new ScriptingWindow(model->getListReference());
|
||||
connect(scriptingWindow, &ScriptingWindow::sendCANFrame, connectionWindow, &ConnectionWindow::sendFrame);
|
||||
}
|
||||
scriptingWindow->show();
|
||||
}
|
||||
@@ -995,8 +975,7 @@ void MainWindow::showConnectionSettingsWindow()
|
||||
{
|
||||
if (!connectionWindow)
|
||||
{
|
||||
connectionWindow = new ConnectionWindow(model);
|
||||
connect(connectionWindow, SIGNAL(updateConnectionSettings(QString,QString,int,int)), this, SLOT(updateConnectionSettings(QString,QString,int,int)));
|
||||
connectionWindow = new ConnectionWindow();
|
||||
}
|
||||
connectionWindow->show();
|
||||
}
|
||||
|
||||
+4
-1
@@ -103,6 +103,9 @@
|
||||
<property name="text">
|
||||
<string>Suspend Capturing</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@@ -197,7 +200,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>27</height>
|
||||
<height>19</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menu_RE_Tools">
|
||||
|
||||
+36
-9
@@ -1,14 +1,12 @@
|
||||
#include "scriptcontainer.h"
|
||||
|
||||
#include <QJSValueIterator>
|
||||
#include <QDebug>
|
||||
|
||||
ScriptContainer::ScriptContainer()
|
||||
{
|
||||
fileName = QString();
|
||||
filePath = QString();
|
||||
scriptText = QString();
|
||||
#include "scriptcontainer.h"
|
||||
#include "connections/canconmanager.h"
|
||||
|
||||
ScriptContainer::ScriptContainer(QString& pConName):
|
||||
mConName(pConName)
|
||||
{
|
||||
connect(&timer, SIGNAL(timeout()), this, SLOT(tick()));
|
||||
}
|
||||
|
||||
@@ -68,6 +66,25 @@ void ScriptContainer::setFilter(QJSValue id, QJSValue mask, QJSValue bus)
|
||||
CANFilter filter;
|
||||
filter.setFilter(idVal, maskVal, busVal);
|
||||
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)
|
||||
@@ -86,6 +103,14 @@ void ScriptContainer::clearFilters()
|
||||
{
|
||||
qDebug() << "Called clear filters";
|
||||
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)
|
||||
@@ -109,8 +134,10 @@ void ScriptContainer::sendFrame(QJSValue bus, QJSValue id, QJSValue length, QJSV
|
||||
|
||||
if (frame.ID > 0x7FF) frame.extended = true;
|
||||
|
||||
//qDebug() << "Sending frame from script";
|
||||
emit sendCANFrame(&frame);
|
||||
qDebug() << "sending frame from script";
|
||||
CANConnection* conn_p = CANConManager::getInstance()->getByName(mConName);
|
||||
if(conn_p)
|
||||
conn_p->sendFrame(frame);
|
||||
}
|
||||
|
||||
void ScriptContainer::gotFrame(const CANFrame &frame)
|
||||
|
||||
+2
-1
@@ -13,12 +13,13 @@ class ScriptContainer : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ScriptContainer();
|
||||
ScriptContainer(QString&);
|
||||
void gotFrame(const CANFrame &frame);
|
||||
|
||||
QString fileName;
|
||||
QString filePath;
|
||||
QString scriptText;
|
||||
QString mConName;
|
||||
|
||||
public slots:
|
||||
void compileScript();
|
||||
|
||||
+27
-20
@@ -3,9 +3,10 @@
|
||||
|
||||
#include <QFile>
|
||||
#include <QFileDialog>
|
||||
#include <QSettings>
|
||||
#include <Qsci/qscilexerjavascript.h>
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "connections/canconmanager.h"
|
||||
|
||||
ScriptingWindow::ScriptingWindow(const QVector<CANFrame> *frames, QWidget *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->btnRevertScript, &QAbstractButton::pressed, this, &ScriptingWindow::revertScript);
|
||||
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));
|
||||
}
|
||||
@@ -33,27 +35,22 @@ ScriptingWindow::~ScriptingWindow()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ScriptingWindow::updatedFrames(int numFrames)
|
||||
|
||||
void ScriptingWindow::newFrames(const CANConnection* pConn, const QVector<CANFrame>& pFrames)
|
||||
{
|
||||
CANFrame thisFrame;
|
||||
//-1 means all frames deleted and -2 means a full refresh, neither of which we care about here.
|
||||
if (numFrames > 0)
|
||||
/*FIXME: name of the probe and bus should be checked */
|
||||
Q_UNUSED(pConn);
|
||||
|
||||
for (int j = 0; j < scripts.length(); j++)
|
||||
{
|
||||
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++)
|
||||
foreach(const CANFrame& frame, pFrames)
|
||||
{
|
||||
thisFrame = modelFrames->at(i);
|
||||
for (int j = 0; j < scripts.length(); j++)
|
||||
{
|
||||
scripts[j]->gotFrame(thisFrame);
|
||||
}
|
||||
scripts[j]->gotFrame(frame);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ScriptingWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
@@ -115,13 +112,19 @@ void ScriptingWindow::loadNewScript()
|
||||
QStringList fileList = filename.split('/');
|
||||
QString justFileName = fileList[fileList.length() - 1];
|
||||
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->filePath = filename;
|
||||
container->scriptText = contents;
|
||||
container->setErrorWidget(ui->listErrors);
|
||||
container->compileScript();
|
||||
connect(container, &ScriptContainer::sendCANFrame, this, &ScriptingWindow::sendCANFrame);
|
||||
scripts.append(container);
|
||||
currentScript = container;
|
||||
ui->txtScriptSource->setText(container->scriptText);
|
||||
@@ -135,13 +138,17 @@ void ScriptingWindow::createNewScript()
|
||||
{
|
||||
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->filePath = QString();
|
||||
container->scriptText = QString();
|
||||
container->setErrorWidget(ui->listErrors);
|
||||
connect(container, &ScriptContainer::sendCANFrame, this, &ScriptingWindow::sendCANFrame);
|
||||
scripts.append(container);
|
||||
ui->listLoadedScripts->addItem(container->fileName);
|
||||
currentScript = container;
|
||||
|
||||
+2
-6
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "can_structs.h"
|
||||
#include "scriptcontainer.h"
|
||||
#include "connections/canconnection.h"
|
||||
|
||||
#include <QDialog>
|
||||
#include <QJSEngine>
|
||||
@@ -28,12 +29,7 @@ private slots:
|
||||
void saveScript();
|
||||
void revertScript();
|
||||
void recompileScript();
|
||||
void updatedFrames(int);
|
||||
|
||||
public slots:
|
||||
|
||||
signals:
|
||||
void sendCANFrame(const CANFrame *);
|
||||
void newFrames(const CANConnection*, const QVector<CANFrame>&);
|
||||
|
||||
private:
|
||||
void closeEvent(QCloseEvent *event);
|
||||
|
||||
Reference in New Issue
Block a user