Created
January 13, 2017 19:34
-
-
Save lexszero/8725f66fb136380e65957dcb0225e485 to your computer and use it in GitHub Desktop.
/tmp/artnet.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "application.h" | |
#include "settings.h" | |
#define ARTNET_PORT ((uint16_t)0x1936) | |
enum { | |
OpPoll = 0x2000, | |
OpPollReply = 0x2100, | |
OpDiagData = 0x2300, | |
OpCommand = 0x2400, | |
OpOutput = 0x5000, | |
OpNzs = 0x5100, | |
OpSync = 0x5200, | |
OpAddress = 0x6000, | |
OpInput = 0x7000, | |
OpVideoSetup = 0xa010, | |
OpVideoPalette = 0xa020, | |
OpVideoData = 0xa040, | |
OpIpProg = 0xf800, | |
OpIpProgReply = 0xf900, | |
OpTimeSync = 0x9800, | |
OpTrigger = 0x9900, | |
}; | |
static void on_receive(UdpConnection &conn, char *data, int size, IPAddress remoteIP, uint16_t remotePort) | |
{ | |
if (strncmp(data, "Art-Net", 8) != 0) { | |
Serial.println("artnet: bad header\n"); | |
return; | |
} | |
data += 8; | |
uint16_t op = data[0] | (data[1] << 8); | |
data += 2; | |
switch (op) { | |
case OpOutput: { | |
int i; | |
uint8_t seq = data[2]; | |
uint16_t universe = data[4] | (data[5] << 8); | |
uint16_t len = data[7] | (data[6] << 8); | |
data += 8; | |
/*if (dmx_seq >= seq && seq != 0) | |
return;*/ | |
//dmx_seq = seq; | |
Serial.printf("artnet: seq=%d, universe=%d, len=%d\n", seq, universe, len); | |
LedGroup *grp = NULL; | |
for (int i = 0; i < Settings.LedGroups.size(); i++) { | |
if (universe == Settings.LedGroups[i].ArtNetUniverse) | |
break; | |
} | |
if (i = Settings.LedGroups.size()) | |
return; | |
else | |
grp = &Settings.LedGroups[i]; | |
for (int i = 0; i < grp->Count; i++) { | |
if (grp->ArtNetStart + i >= len) | |
break; | |
grp->SetChan(i, data[grp->ArtNetStart + i]); | |
} | |
pwm->Push(); | |
break; | |
} | |
case OpPoll: { | |
Serial.println("artnet: poll"); | |
// TODO: decode request and send ArtPollReply | |
break; | |
} | |
default: | |
Serial.printf("artnet: unsupported opcode 0x%04x\n", op); | |
} | |
} | |
static UdpConnection artnet(on_receive); | |
void artnet_start(void) | |
{ | |
artnet.listen(ARTNET_PORT); | |
Serial.printf("artnet: listen at %s:%d, start\n", WifiStation.getIP().toString().c_str(), ARTNET_PORT); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment