-
Notifications
You must be signed in to change notification settings - Fork 12
/
BasicNode.ino
74 lines (62 loc) · 2.3 KB
/
BasicNode.ino
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
#include <SPI.h>
#include <Ethernet.h>
#include <ArtNode.h>
#define VERSION_HI 0
#define VERSION_LO 1
////////////////////////////////////////////////////////////
ArtConfig config = {
{0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}, // MAC
{2, 3, 4, 5}, // IP
{255, 0, 0, 0}, // Subnet mask
0x1936, // UDP port
false, // DHCP
0, 0, // Net (0-127) and subnet (0-15)
"ArtNode", // Short name
"ArtNode", // Long name
4, // Number of ports
{PortTypeDmx | PortTypeOutput, PortTypeDmx | PortTypeOutput, PortTypeDmx | PortTypeOutput, PortTypeDmx | PortTypeOutput}, // Port types
{0, 0, 0, 0}, // Port input universes (0-15)
{0, 1, 2, 3}, // Port output universes (0-15)
VERSION_HI,
VERSION_LO
};
////////////////////////////////////////////////////////////
IPAddress gateway(config.ip[0], 0, 0, 1);
EthernetUDP udp;
byte buffer[600];
ArtNode node = ArtNode(config, sizeof(buffer), buffer);
////////////////////////////////////////////////////////////
void setup() {
Ethernet.begin(config.mac, config.ip, gateway, gateway, config.subnet);
udp.begin(config.udpPort);
}
////////////////////////////////////////////////////////////
void loop() {
while (udp.parsePacket()) {
int n = udp.read(buffer, min(udp.available(), sizeof(buffer)));
if (n >= sizeof(ArtHeader) && node.isPacketValid()) {
// Package Op-Code determines type of packet
switch (node.getOpCode()) {
// Poll packet. Send poll reply.
case OpPoll: {
ArtPoll* poll = (ArtPoll*)buffer;
node.createPollReply();
udp.beginPacket(node.broadcastIP(), config.udpPort);
udp.write(buffer, sizeof(ArtPollReply));
udp.endPacket();
} break;
// DMX packet
case OpDmx: {
ArtDmx* dmx = (ArtDmx*)buffer;
int port = node.getPort(dmx->SubUni, dmx->Net);
int len = dmx->getLength();
byte *data = dmx->Data;
if (port >= 0 && port < config.numPorts) {
}
} break;
default:
break;
}
}
}
}