61 lines
2.3 KiB
C++
61 lines
2.3 KiB
C++
#ifndef CANCONNECTION_H
|
|
#define CANCONNECTION_H
|
|
|
|
#include <Qt>
|
|
#include <QObject>
|
|
#include "can_structs.h"
|
|
#include "canbus.h"
|
|
#include "canframemodel.h"
|
|
|
|
|
|
//Gentle reminder, CANConnection objects run in their own thread (each one, different thread)
|
|
//so, for the love of God, do not try to access them directly.
|
|
//Use the signal/slots system to do indirect calls.
|
|
//Please and thank you.
|
|
class CANConnection : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
CANConnection(CANFrameModel *, int);
|
|
virtual int getNumBuses();
|
|
int getBusBase();
|
|
virtual QString getConnTypeName();
|
|
QString getConnPortName();
|
|
|
|
signals:
|
|
void error(const QString &);
|
|
void frameUpdateRapid(int);
|
|
void frameUpdate(int);
|
|
void connectionSuccess(CANConnection *);
|
|
void connectionFailure(CANConnection *);
|
|
void deviceInfo(int, int); //First param = driver version (or version of whatever you want), second param a status byte
|
|
|
|
//bus number, bus speed, status (bit 0 = enabled, 1 = single wire, 2 = listen only)
|
|
//3 = Use value stored for enabled, 4 = use value passed for single wire, 5 = use value passed for listen only
|
|
//6 = use value passed for speed. This allows bus status to be updated but set that some things aren't really
|
|
//being passed. Just set for things that really are being updated.
|
|
void busStatus(int, int, int);
|
|
|
|
public slots:
|
|
virtual void run();
|
|
virtual void sendFrame(const CANFrame *);
|
|
virtual void sendFrameBatch(const QList<CANFrame> *);
|
|
virtual void updatePortName(QString); //string version of the port to connect to. This base doesnt know a thing about this value
|
|
virtual void stopFrameCapture(int); //pass bus number
|
|
virtual void startFrameCapture(int); //pass bus number. Only if stopped. Defaults to started anyway
|
|
/* this is not safe to use pointers with QueuedConnection */
|
|
virtual void updateBusSettings(CANBus); //reference to the bus that changed.
|
|
|
|
protected:
|
|
bool quit;
|
|
int numBuses;
|
|
int busBase; //first bus this class is supposed to handle
|
|
QString portName; //for easy access later on
|
|
QString connType; //what kind of connection this is (socketcan, kvaser, etc)
|
|
bool isConnected; //is the whole device connected? (Is the code connected to the device itself)
|
|
CANFrameModel *model;
|
|
};
|
|
|
|
#endif // CANCONNECTION_H
|