forked from rstephan/ArtnetWifi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArtnetWifi.h
More file actions
122 lines (100 loc) · 2.98 KB
/
ArtnetWifi.h
File metadata and controls
122 lines (100 loc) · 2.98 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
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
/*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
Copyright (c) 2016 Stephan Ruloff
https://github.com/rstephan
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_WIFI_H
#define ARTNET_WIFI_H
#include <Arduino.h>
#include <WiFiUdp.h>
// UDP specific
#define ART_NET_PORT 6454
// Opcodes
#define ART_POLL 0x2000
#define ART_DMX 0x5000
// Buffers
#define MAX_BUFFER_ARTNET 530
// Packet
#define ART_NET_ID "Art-Net"
#define ART_DMX_START 18
class ArtnetWifi
{
public:
ArtnetWifi();
void begin(String hostname = "");
uint16_t read(void);
/* returns 1 for Ok, or 0 on problem */
int write(void);
int write(IPAddress ip);
void setByte(uint16_t pos, uint8_t value);
void printPacketHeader(void);
void printPacketContent(void);
// 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 void setUniverse(uint16_t universe)
{
outgoingUniverse = universe;
}
inline void setPhisical(uint8_t port)
{
phisical = port;
}
inline uint16_t getLength(void)
{
return dmxDataLength;
}
inline void setLength(uint16_t len)
{
dmxDataLength = len;
}
inline void setArtDmxCallback(void (*fptr)(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data))
{
artDmxCallback = fptr;
}
private:
uint16_t makePacket(void);
WiFiUDP Udp;
String host;
uint8_t artnetPacket[MAX_BUFFER_ARTNET];
uint16_t packetSize;
uint16_t opcode;
uint8_t sequence;
uint8_t phisical;
uint16_t incomingUniverse;
uint16_t outgoingUniverse;
uint16_t dmxDataLength;
void (*artDmxCallback)(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data);
static const char artnetId[];
};
#endif