-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqartnetpoll.cpp
70 lines (60 loc) · 1.58 KB
/
qartnetpoll.cpp
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
#include "qartnetpoll.h"
#include <QDebug>
QArtNetPoll::QArtNetPoll(QObject *parent)
: QObject(parent)
{
memcpy(m_poll.id, ARTNET_STRING, ARTNET_STRING_SIZE);
m_poll.opCode = ARTNET_POLL;
m_poll.verH = (ARTNET_VERSION >> 8) & 0xff;
m_poll.ver = ARTNET_VERSION & 0xff;
m_poll.prio = 0;
enableVlc(false);
enableUnicast(false);
setSendDiagnostics(true);
setReplyAlways(true);
}
QArtNetPoll::QArtNetPoll(QObject *parent, QByteArray dgram)
: QObject(parent)
{
memcpy(m_poll.id,
dgram.left(ARTNET_STRING_SIZE).toStdString().c_str(),
ARTNET_STRING_SIZE);
m_poll.opCode = dgram.mid(8, 2).toInt(0, 16);
m_poll.verH = (dgram.mid(11, 2).toInt(0, 16) >> 8) & 0xff;
m_poll.ver = (dgram.mid(11, 2).toInt(0, 16) & 0xff);
m_poll.ttm = dgram.mid(13, 1).toInt(0, 16);
m_poll.prio = dgram.mid(14, 1).toInt(0, 16);
qDebug() << "Code " << m_poll.opCode;
}
void QArtNetPoll::enableVlc(bool vlc)
{
if(vlc)
m_poll.ttm &= ~DISABLE_VLC;
else
m_poll.ttm |= DISABLE_VLC;
}
void QArtNetPoll::enableUnicast(bool unicast)
{
if(unicast)
m_poll.ttm |= UNICAST;
else
m_poll.ttm &= ~UNICAST;
}
void QArtNetPoll::setSendDiagnostics(bool diag)
{
if(diag)
m_poll.ttm |= SEND_DIAG;
else
m_poll.ttm &= ~SEND_DIAG;
}
void QArtNetPoll::setReplyAlways(bool reply)
{
if(reply)
m_poll.ttm |= ALWAYS;
else
m_poll.ttm &= ~ALWAYS;
}
QByteArray QArtNetPoll::toDatagram()
{
return QByteArray(reinterpret_cast<const char *>(&m_poll), sizeof(artnet_poll_t));
}