-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathartNetPacket.cpp
70 lines (63 loc) · 1.32 KB
/
artNetPacket.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 "artNetPacket.h"
artNetPacket::artNetPacket()
{
data = new byte[512];
pIndex = 0;
hasChanged = 0;
}
void artNetPacket::parseArtNetPacket(char *packetBuffer)
{
//header
pIndex=0;
for(pCnt=0; pCnt<7; pCnt++)
{
header[pCnt] = packetBuffer[pIndex];
pIndex++;
}
//opcode
pIndex++;
for(pCnt=0; pCnt<2; pCnt++)
{
opcode[pCnt] = packetBuffer[pIndex];
pIndex++;
}
//Protocol Version
for(pCnt=0; pCnt<2; pCnt++)
{
protocolVersion[pCnt] = packetBuffer[pIndex];
pIndex++;
}
//sequence
sequence = packetBuffer[pIndex];
pIndex++;
//physical
physical = packetBuffer[pIndex];
pIndex++;
//universe
for(pCnt=0; pCnt<2; pCnt++)
{
universe[pCnt] = packetBuffer[pIndex];
pIndex++;
}
//datalengsth
for(pCnt=0; pCnt<2; pCnt++)
{
dataLength[pCnt] = packetBuffer[pIndex];
pIndex++;
}
//data
for(pCnt=0; pCnt<512; pCnt++)
{
if(data[pCnt]!=packetBuffer[pIndex] && hasChanged==0){hasChanged=1;}
data[pCnt] = packetBuffer[pIndex];
pIndex++;
}
}
byte artNetPacket::dumpData(short int index)
{
return data[index];
}
short unsigned int artNetPacket::scaleInput(unsigned short int index, unsigned short int minOutput, unsigned short int maxOutput)
{
return ((((float)dumpData(index))/256)* ((float)(maxOutput-minOutput))) +minOutput;
}