-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpackets.h
More file actions
63 lines (51 loc) · 2 KB
/
packets.h
File metadata and controls
63 lines (51 loc) · 2 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
#ifndef PACKETS_H
#define PACKETS_H
#include <QByteArray>
namespace Packets {
// AACP Control Command - OWNS_CONNECTION
namespace OwnsConnection {
static const QByteArray HEADER = QByteArray::fromHex("040004000900");
static QByteArray createCommand(quint8 identifier, quint8 data1) {
QByteArray packet = HEADER;
packet.append(static_cast<char>(identifier));
packet.append(static_cast<char>(data1));
packet.append(static_cast<char>(0x00));
packet.append(static_cast<char>(0x00));
packet.append(static_cast<char>(0x00));
return packet;
}
static const QByteArray CLAIM = createCommand(0x06, 0x01);
static const QByteArray RELEASE = createCommand(0x06, 0x00);
}
// TiPi Protocol - Audio Source (tells which device is playing)
namespace AudioSource {
static const QByteArray HEADER = QByteArray::fromHex("040004000E");
enum Type : quint8 {
NONE = 0x00,
CALL = 0x01,
MEDIA = 0x02
};
struct Info {
QByteArray deviceMac;
Type type;
bool isValid;
};
inline Info parse(const QByteArray &data) {
Info info{QByteArray(), NONE, false};
// Format: 04 00 04 00 0E [1 byte] [6 bytes MAC] [1 byte type]
if (data.size() >= 13 && data.startsWith(HEADER)) {
info.deviceMac = data.mid(6, 6);
info.type = static_cast<Type>(static_cast<quint8>(data.at(12)));
info.isValid = true;
}
return info;
}
}
// Connection handshake packets
namespace Connection {
static const QByteArray HANDSHAKE = QByteArray::fromHex("00000400010002000000000000000000");
static const QByteArray REQUEST_NOTIFICATIONS = QByteArray::fromHex("040004000f00ffffffffff");
static const QByteArray FEATURES_ACK = QByteArray::fromHex("040004002b00");
}
}
#endif // PACKETS_H