Skip to content

Instantly share code, notes, and snippets.

@modjo756
Last active July 7, 2016 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save modjo756/37fe8b3ec20a11146f0dce6e9c0e626b to your computer and use it in GitHub Desktop.
Save modjo756/37fe8b3ec20a11146f0dce6e9c0e626b to your computer and use it in GitHub Desktop.
class for use can on neo boards
#ifndef QCAN_H
#define QCAN_H
#include <QObject>
#include <QtSerialBus>
typedef struct //CAN message struct
{
quint16 i_length; // --> size of packet
QTime neoTime; //time of comming frame
quint64 i_timesStamp; //timestamp of the CAN trame in us
quint8 i_channel; //can channel
quint8 i_dlc; //data lenght max 8 bytes
quint32 i_id; //bit 0-28 ID - bit 29 0 - bit 30 RTR - bit 31 1 for Extended trame 0 for std
char data[8]; //8x8 bytes
}structCan;
class QCan : public QObject
{
Q_OBJECT
public:
explicit QCan(QObject *parent = 0);
~QCan();
signals:
void data(structCan frame);
public slots:
void connectDevice(QString device, int bitrates, bool loopBack, bool listenMode);
void disconnectDevice(QString device);
private slots:
void checkMessages();
void receiveError(QCanBusDevice::CanBusError error) const;
private:
//methods
void interpretError(const QCanBusFrame &);
bool canShellOpen(QString &device, int rates);
bool canShellClose(QString &device);
//members
QCanBusDevice *m_canDevice;
structCan m_sCan;
};
#endif // QCAN_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment