forked from stremlau/Artnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Artnet.h
executable file
·154 lines (130 loc) · 3.66 KB
/
Artnet.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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*The MIT License (MIT)
Copyright (c) 2014 Nathanaël Lécaudé
https://github.com/natcl/Artnet, http://forum.pjrc.com/threads/24688-Artnet-to-OctoWS2811
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef ARTNET_H
#define ARTNET_H
#include <Arduino.h>
#include <WiFiUdp.h>
// UDP specific
#define ART_NET_PORT 6454
// Opcodes
#define ART_POLL 0x2000
#define ART_POLL_REPLY 0x2100
#define ART_DMX 0x5000
// Buffers
#define MAX_BUFFER_ARTNET 530
// Packet
#define ART_NET_ID "Art-Net\0"
#define ART_DMX_START 18
struct artnet_reply_s {
uint8_t id[8];
uint16_t opCode;
uint8_t ip[4];
uint16_t port;
uint8_t verH;
uint8_t ver;
uint8_t subH;
uint8_t sub;
uint8_t oemH;
uint8_t oem;
uint8_t ubea;
uint8_t status;
uint8_t etsaman[2];
uint8_t shortname[18];
uint8_t longname[64];
uint8_t nodereport[64];
uint8_t numbportsH;
uint8_t numbports;
uint8_t porttypes[4];//max of 4 ports per node
uint8_t goodinput[4];
uint8_t goodoutput[4];
uint8_t swin[4];
uint8_t swout[4];
uint8_t swvideo;
uint8_t swmacro;
uint8_t swremote;
uint8_t sp1;
uint8_t sp2;
uint8_t sp3;
uint8_t style;
uint8_t mac[6];
uint8_t bindip[4];
uint8_t bindindex;
uint8_t status2;
uint8_t filler[26];
} __attribute__((packed));
class Artnet
{
public:
Artnet();
void begin();
void setBroadcast(byte bc[]);
uint16_t read();
void printPacketHeader();
void printPacketContent();
// Return a pointer to the start of the DMX data
inline uint8_t* getDmxFrame(void)
{
return artnetPacket + ART_DMX_START;
}
inline uint16_t getOpcode(void)
{
return opcode;
}
inline uint8_t getSequence(void)
{
return sequence;
}
inline uint16_t getUniverse(void)
{
return incomingUniverse;
}
inline uint16_t getLength(void)
{
return dmxDataLength;
}
inline void setArtDmxCallback(void (*fptr)(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data))
{
artDmxCallback = fptr;
}
void setNet(uint8_t n);
void setSubnet(uint8_t n);
void setUniverseA(uint8_t u);
void setNumUniverses(uint8_t num);
uint16_t send(uint16_t outgoingUniverse, uint8_t* data, uint16_t data_length, IPAddress destIp);
private:
uint8_t node_ip_address[4];
uint8_t id[8];
WiFiUDP Udp;
struct artnet_reply_s ArtPollReply;
uint8_t artnetPacket[MAX_BUFFER_ARTNET];
uint16_t packetSize;
IPAddress broadcast;
uint16_t opcode;
uint8_t sequence;
uint16_t incomingUniverse;
uint16_t dmxDataLength;
uint8_t subNet;
uint8_t net;
uint8_t numUniverses;
uint8_t universe_a;
void (*artDmxCallback)(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data);
static const char artnetId[];
};
#endif