-
Notifications
You must be signed in to change notification settings - Fork 0
/
packet_receiver.h
45 lines (33 loc) · 1.01 KB
/
packet_receiver.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
#ifndef PACKETRECEIVER_H
#define PACKETRECEIVER_H
#include <QObject>
#include <boost/asio.hpp>
#include "network_packet.h"
#ifndef BUFFER_SIZE
#define BUFFER_SIZE 34000
#endif
class PacketReceiver : public QObject
{
Q_OBJECT
public:
explicit PacketReceiver(QObject *parent = nullptr);
virtual ~PacketReceiver();
void start();
void stop();
void setReceiverCallback(std::function<void(NetworkPacket *)> callback);
void bind(int port);
protected:
void socketCallback(const boost::system::error_code& error, std::size_t numberOfBytes);
void waitForNextPacket();
private:
int Port {-1};
uint64_t FakeManufacturerMACAddress {0};
unsigned char RXBuffer[BUFFER_SIZE] = {0};
std::string LocalListeningAddress {"::"};
boost::asio::io_service IOService;
boost::asio::ip::udp::endpoint SenderEndpoint;
boost::asio::ip::udp::socket Socket;
std::unique_ptr<std::thread> Thread;
std::function<void(NetworkPacket *)> ReceiverCallback;
};
#endif // PACKETRECEIVER_H