-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplayer.cpp
More file actions
149 lines (119 loc) · 3.11 KB
/
Copy pathplayer.cpp
File metadata and controls
149 lines (119 loc) · 3.11 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "player.h"
#include <limits>
player::player(){
}
player::player(QString name, QString mac, QString team)
{
sta_name = QString(name);
sta_mac = QString(mac.toUpper()); // Saving MAC addresses always in the same case
sta_team = QString(team);
sta_power = std::numeric_limits<int>::min();
sta_packets = 0;
sta_connected = false;
sta_bandwith = 0;
sta_pkts_sec = 0;
sta_bytes = 0;
}
player::player(QString mac)
{ sta_mac = QString(mac.toUpper()); // Saving MAC addresses always in the same case
sta_power = std::numeric_limits<int>::min();
sta_power = std::numeric_limits<int>::min();
sta_packets = 0;
sta_connected = false;
sta_bandwith = 0;
sta_pkts_sec = 0;
}
void player::update(QDateTime first_seen, QDateTime last_seen, uint packets, int power, uint bytes)
{
// Calculate packets per second rough aproximation
int diff_packets = 0;
int diff_bytes = 0;
//sta_pkts_sec = 0;
//sta_bandwith = 0;
if((sta_last_time_seen.isValid() == true) && (last_seen.isValid() == true))
{
qint64 diff_time_msec = sta_last_time_seen.msecsTo(last_seen);
if(sta_packets < packets)
diff_packets = packets - sta_packets;
else
diff_packets = packets;
if(sta_bytes < bytes)
diff_bytes = bytes - sta_bytes;
else
diff_bytes = bytes;
if(diff_time_msec > 0){
sta_pkts_sec = diff_packets*1000/diff_time_msec;
sta_bandwith = diff_bytes*1000/diff_time_msec;
}
}else
if((first_seen.isValid() == true) && (last_seen.isValid() == true))
{
qint64 diff_time_msec = first_seen.msecsTo(last_seen);
if(diff_time_msec > 0){
sta_pkts_sec = packets*1000/diff_time_msec;
sta_bandwith = bytes*1000/diff_time_msec;
}
}
sta_first_time_seen = first_seen;
sta_last_time_seen = last_seen;
sta_packets = packets;
sta_bytes = bytes;
sta_power = power;
//Evaluate if station is connected
if((sta_last_time_seen.secsTo(QDateTime::currentDateTime()) < CONNECTION_TIMEOUT) == true)
sta_connected = true;
else
sta_connected = false;
}
QString player::name()
{
return sta_name;
}
QDateTime player::firstTimeSeen()
{
return sta_first_time_seen;
}
QDateTime player::lastTimeSeen(){
return sta_last_time_seen;
}
QString player::mac(){
return sta_mac;
}
QString player::team_name(){
return sta_team;
}
void player::connected()
{
sta_connected = true;
}
void player::disconnected()
{
sta_connected = false;
}
bool player::isConnected()
{
return sta_connected;
}
int player::power()
{
return sta_power;
}
uint player::packets()
{
return sta_packets;
}
uint player::throughput(){
return sta_bandwith;
}
void player::clean_stats(){
sta_first_time_seen = QDateTime();
sta_last_time_seen = QDateTime();
sta_power = std::numeric_limits<int>::min();
sta_packets = 0;
sta_bytes = 0;
sta_connected = false;
sta_bandwith = 0;
}
uint player::pkts_second(){
return sta_pkts_sec;
}