-
Notifications
You must be signed in to change notification settings - Fork 2
/
WifiDataCollector.h
105 lines (75 loc) · 1.99 KB
/
WifiDataCollector.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef WifiDataCollector_H
#define WifiDataCollector_H
#include <QtGui>
#include <iostream>
#include <stdio.h>
typedef QHash<QString,QString> QStringHash;
class WifiDataResult
{
public:
WifiDataResult()
: essid("")
, mac("")
, dbm(-999)
, chan(0.0)
, value(0.0)
, valid(false)
{}
QString essid;
QString mac;
int dbm;
double chan;
double value;
QStringHash rawData;
bool valid;
QString toString() const;
void loadRawData(QStringHash rawData);
};
QDebug operator<<(QDebug dbg, const WifiDataResult &result);
class WifiDataCollector : public QObject
{
Q_OBJECT
public:
WifiDataCollector();
~WifiDataCollector();
QList<WifiDataResult> scanResults();
bool auditIwlistBinary();
static QString findWlanIf();
static QStringList findWlanInterfaces();
// If empty (default), uses first wlan device found
void setWlanDevice(QString dev="");
// Set data textfile to load data from a file instead of read it live (mainly for debugging/testing)
void setDataTextfile(QString file);
QString dataTextfile() { return m_dataTextfile; }
// Converts dBm in the range of [-100,-40] to a range of [0,1]
// dBm range used subject to change if needed in later revisions.
static double dbmToPercent(int dbm);
public slots:
void startScan(int numScans=3, bool continuous=true);
void stopScan();
signals:
void scanStarted();
void scanProgress(double progress);
void scanFinished(QList<WifiDataResult>);
protected slots:
void scanWifi();
protected:
void updateScanInterval();
QThread m_scanThread;
int m_numScans;
int m_scanNum; // 0-m_numScans
bool m_continuousMode;
QTimer m_scanTimer;
QMutex m_resultsMutex;
QList<WifiDataResult> m_scanResults;
QList<QList<WifiDataResult> > m_resultBuffer;
QString getIwlistOutput(QString interface = "");
WifiDataResult parseRawBlock(QString buffer);
QString readTextFile(QString file);
QString m_dataTextfile;
QString m_wlanDevice;
bool m_scanProcessStarted;
//QProcess m_scanProcess;
FILE *m_scanPipe;
};
#endif