-
Notifications
You must be signed in to change notification settings - Fork 3
/
canthread.h
66 lines (51 loc) · 1.97 KB
/
canthread.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* written 2009, 2010 by Jannis Achstetter
* contact: [email protected]
*
* developed at Hochschule Aschaffenburg
* licensed under the terms of the General Public
* License (GPL) version 3.0
*/
#ifndef CANTHREAD_H
#define CANTHREAD_H
#include <QThread>
#include <poll.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <unistd.h>
#include <sys/time.h>
#include <linux/can.h>
#include <linux/can/raw.h>
#include "canlogfile.h"
/*!
* Holds the thread's internal status (packet counters, byte counters, error counters)
*/
struct threadstatus {
quint64 incounter; //!< packets coming in
quint64 outcounter; //!< packets going out
quint64 inbcounter; //!< bytes coming in
quint64 outbcounter; //!< bytes going out
};
/*!
* Thread to fetch the packets from one interface, put them to the mainthread and send packets.
*/
class canthread: public QThread {
Q_OBJECT
public:
canthread(); //!< Constructor, initialising the thread as stopped
void stop(); //!< Stop the thread
void setifname(QString ifnametobeset); //!< Set the name of the interface to use
void sendmsg(canpacket sendpacket); //!< Send away one packet
signals:
void dataarrived(canpacket mypacket); //!< We have new data fetched
void statusChanged(threadstatus mystatus); //!< The status has changed
public slots:
void setfilter(QStringList hwfilter); //!< Set the CAN hardware filters for the socket
protected:
void run(); //!< Start the thread and enter it's main loop
private:
volatile bool stopped; //!< Keep our status here internally
QString ifname; //!< Name of network interface to be used
int sockfd; //!< File descriptor of the socket we are working with
struct threadstatus mystatus; //!< Status of this thread
};
#endif // CANTHREAD_H